]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.3-201210231532.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.3-201210231532.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 6cdadf4..02df425 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index ecf9019..b71d9a1 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 77bd79f..ad4cd27 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 693b744..e684262 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1853 index c3bd834..e81ef02 100644
1854 --- a/arch/arm/mm/fault.c
1855 +++ b/arch/arm/mm/fault.c
1856 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1857 }
1858 #endif
1859
1860 +#ifdef CONFIG_PAX_PAGEEXEC
1861 + if (fsr & FSR_LNX_PF) {
1862 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1863 + do_group_exit(SIGKILL);
1864 + }
1865 +#endif
1866 +
1867 tsk->thread.address = addr;
1868 tsk->thread.error_code = fsr;
1869 tsk->thread.trap_no = 14;
1870 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1871 }
1872 #endif /* CONFIG_MMU */
1873
1874 +#ifdef CONFIG_PAX_PAGEEXEC
1875 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1876 +{
1877 + long i;
1878 +
1879 + printk(KERN_ERR "PAX: bytes at PC: ");
1880 + for (i = 0; i < 20; i++) {
1881 + unsigned char c;
1882 + if (get_user(c, (__force unsigned char __user *)pc+i))
1883 + printk(KERN_CONT "?? ");
1884 + else
1885 + printk(KERN_CONT "%02x ", c);
1886 + }
1887 + printk("\n");
1888 +
1889 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1890 + for (i = -1; i < 20; i++) {
1891 + unsigned long c;
1892 + if (get_user(c, (__force unsigned long __user *)sp+i))
1893 + printk(KERN_CONT "???????? ");
1894 + else
1895 + printk(KERN_CONT "%08lx ", c);
1896 + }
1897 + printk("\n");
1898 +}
1899 +#endif
1900 +
1901 /*
1902 * First Level Translation Fault Handler
1903 *
1904 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1905 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1906 struct siginfo info;
1907
1908 +#ifdef CONFIG_PAX_REFCOUNT
1909 + if (fsr_fs(ifsr) == 2) {
1910 + unsigned int bkpt;
1911 +
1912 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1913 + current->thread.error_code = ifsr;
1914 + current->thread.trap_no = 0;
1915 + pax_report_refcount_overflow(regs);
1916 + fixup_exception(regs);
1917 + return;
1918 + }
1919 + }
1920 +#endif
1921 +
1922 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1923 return;
1924
1925 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1926 index ce8cb19..3ec539d 100644
1927 --- a/arch/arm/mm/mmap.c
1928 +++ b/arch/arm/mm/mmap.c
1929 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1930 if (len > TASK_SIZE)
1931 return -ENOMEM;
1932
1933 +#ifdef CONFIG_PAX_RANDMMAP
1934 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1935 +#endif
1936 +
1937 if (addr) {
1938 if (do_align)
1939 addr = COLOUR_ALIGN(addr, pgoff);
1940 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1941 addr = PAGE_ALIGN(addr);
1942
1943 vma = find_vma(mm, addr);
1944 - if (TASK_SIZE - len >= addr &&
1945 - (!vma || addr + len <= vma->vm_start))
1946 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1947 return addr;
1948 }
1949 if (len > mm->cached_hole_size) {
1950 - start_addr = addr = mm->free_area_cache;
1951 + start_addr = addr = mm->free_area_cache;
1952 } else {
1953 - start_addr = addr = mm->mmap_base;
1954 - mm->cached_hole_size = 0;
1955 + start_addr = addr = mm->mmap_base;
1956 + mm->cached_hole_size = 0;
1957 }
1958
1959 full_search:
1960 @@ -124,14 +127,14 @@ full_search:
1961 * Start a new search - just in case we missed
1962 * some holes.
1963 */
1964 - if (start_addr != TASK_UNMAPPED_BASE) {
1965 - start_addr = addr = TASK_UNMAPPED_BASE;
1966 + if (start_addr != mm->mmap_base) {
1967 + start_addr = addr = mm->mmap_base;
1968 mm->cached_hole_size = 0;
1969 goto full_search;
1970 }
1971 return -ENOMEM;
1972 }
1973 - if (!vma || addr + len <= vma->vm_start) {
1974 + if (check_heap_stack_gap(vma, addr, len)) {
1975 /*
1976 * Remember the place where we stopped the search:
1977 */
1978 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1979
1980 if (mmap_is_legacy()) {
1981 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1982 +
1983 +#ifdef CONFIG_PAX_RANDMMAP
1984 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1985 + mm->mmap_base += mm->delta_mmap;
1986 +#endif
1987 +
1988 mm->get_unmapped_area = arch_get_unmapped_area;
1989 mm->unmap_area = arch_unmap_area;
1990 } else {
1991 mm->mmap_base = mmap_base(random_factor);
1992 +
1993 +#ifdef CONFIG_PAX_RANDMMAP
1994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1995 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1996 +#endif
1997 +
1998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1999 mm->unmap_area = arch_unmap_area_topdown;
2000 }
2001 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2002 index fd556f7..af2e7d2 100644
2003 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2004 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2005 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2006 value in bridge_virt_base */
2007 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2008 const int win);
2009 -};
2010 +} __no_const;
2011
2012 /*
2013 * Information needed to setup one address mapping.
2014 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2015 index f5144cd..71f6d1f 100644
2016 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2017 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2018 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2019 int (*started)(unsigned ch);
2020 int (*flush)(unsigned ch);
2021 int (*stop)(unsigned ch);
2022 -};
2023 +} __no_const;
2024
2025 extern void *samsung_dmadev_get_ops(void);
2026 extern void *s3c_dma_get_ops(void);
2027 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2028 index 5f28cae..3d23723 100644
2029 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2030 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2031 @@ -14,7 +14,7 @@
2032 struct s5p_ehci_platdata {
2033 int (*phy_init)(struct platform_device *pdev, int type);
2034 int (*phy_exit)(struct platform_device *pdev, int type);
2035 -};
2036 +} __no_const;
2037
2038 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2039
2040 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2041 index c3a58a1..78fbf54 100644
2042 --- a/arch/avr32/include/asm/cache.h
2043 +++ b/arch/avr32/include/asm/cache.h
2044 @@ -1,8 +1,10 @@
2045 #ifndef __ASM_AVR32_CACHE_H
2046 #define __ASM_AVR32_CACHE_H
2047
2048 +#include <linux/const.h>
2049 +
2050 #define L1_CACHE_SHIFT 5
2051 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2052 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2053
2054 /*
2055 * Memory returned by kmalloc() may be used for DMA, so we must make
2056 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2057 index 3b3159b..425ea94 100644
2058 --- a/arch/avr32/include/asm/elf.h
2059 +++ b/arch/avr32/include/asm/elf.h
2060 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2061 the loader. We need to make sure that it is out of the way of the program
2062 that it will "exec", and that there is sufficient room for the brk. */
2063
2064 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2065 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2066
2067 +#ifdef CONFIG_PAX_ASLR
2068 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2069 +
2070 +#define PAX_DELTA_MMAP_LEN 15
2071 +#define PAX_DELTA_STACK_LEN 15
2072 +#endif
2073
2074 /* This yields a mask that user programs can use to figure out what
2075 instruction set this CPU supports. This could be done in user space,
2076 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2077 index 479330b..53717a8 100644
2078 --- a/arch/avr32/include/asm/kmap_types.h
2079 +++ b/arch/avr32/include/asm/kmap_types.h
2080 @@ -2,9 +2,9 @@
2081 #define __ASM_AVR32_KMAP_TYPES_H
2082
2083 #ifdef CONFIG_DEBUG_HIGHMEM
2084 -# define KM_TYPE_NR 29
2085 +# define KM_TYPE_NR 30
2086 #else
2087 -# define KM_TYPE_NR 14
2088 +# define KM_TYPE_NR 15
2089 #endif
2090
2091 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2092 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2093 index b92e609..b69c101 100644
2094 --- a/arch/avr32/mm/fault.c
2095 +++ b/arch/avr32/mm/fault.c
2096 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2097
2098 int exception_trace = 1;
2099
2100 +#ifdef CONFIG_PAX_PAGEEXEC
2101 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2102 +{
2103 + unsigned long i;
2104 +
2105 + printk(KERN_ERR "PAX: bytes at PC: ");
2106 + for (i = 0; i < 20; i++) {
2107 + unsigned char c;
2108 + if (get_user(c, (unsigned char *)pc+i))
2109 + printk(KERN_CONT "???????? ");
2110 + else
2111 + printk(KERN_CONT "%02x ", c);
2112 + }
2113 + printk("\n");
2114 +}
2115 +#endif
2116 +
2117 /*
2118 * This routine handles page faults. It determines the address and the
2119 * problem, and then passes it off to one of the appropriate routines.
2120 @@ -173,6 +190,16 @@ bad_area:
2121 up_read(&mm->mmap_sem);
2122
2123 if (user_mode(regs)) {
2124 +
2125 +#ifdef CONFIG_PAX_PAGEEXEC
2126 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2127 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2128 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2129 + do_group_exit(SIGKILL);
2130 + }
2131 + }
2132 +#endif
2133 +
2134 if (exception_trace && printk_ratelimit())
2135 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2136 "sp %08lx ecr %lu\n",
2137 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2138 index 568885a..f8008df 100644
2139 --- a/arch/blackfin/include/asm/cache.h
2140 +++ b/arch/blackfin/include/asm/cache.h
2141 @@ -7,6 +7,7 @@
2142 #ifndef __ARCH_BLACKFIN_CACHE_H
2143 #define __ARCH_BLACKFIN_CACHE_H
2144
2145 +#include <linux/const.h>
2146 #include <linux/linkage.h> /* for asmlinkage */
2147
2148 /*
2149 @@ -14,7 +15,7 @@
2150 * Blackfin loads 32 bytes for cache
2151 */
2152 #define L1_CACHE_SHIFT 5
2153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2154 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2155 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2156
2157 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2158 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2159 index aea2718..3639a60 100644
2160 --- a/arch/cris/include/arch-v10/arch/cache.h
2161 +++ b/arch/cris/include/arch-v10/arch/cache.h
2162 @@ -1,8 +1,9 @@
2163 #ifndef _ASM_ARCH_CACHE_H
2164 #define _ASM_ARCH_CACHE_H
2165
2166 +#include <linux/const.h>
2167 /* Etrax 100LX have 32-byte cache-lines. */
2168 -#define L1_CACHE_BYTES 32
2169 #define L1_CACHE_SHIFT 5
2170 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #endif /* _ASM_ARCH_CACHE_H */
2173 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2174 index 7caf25d..ee65ac5 100644
2175 --- a/arch/cris/include/arch-v32/arch/cache.h
2176 +++ b/arch/cris/include/arch-v32/arch/cache.h
2177 @@ -1,11 +1,12 @@
2178 #ifndef _ASM_CRIS_ARCH_CACHE_H
2179 #define _ASM_CRIS_ARCH_CACHE_H
2180
2181 +#include <linux/const.h>
2182 #include <arch/hwregs/dma.h>
2183
2184 /* A cache-line is 32 bytes. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2190
2191 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2192 index b86329d..6709906 100644
2193 --- a/arch/frv/include/asm/atomic.h
2194 +++ b/arch/frv/include/asm/atomic.h
2195 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2196 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2197 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2198
2199 +#define atomic64_read_unchecked(v) atomic64_read(v)
2200 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2201 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2202 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2203 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2204 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2205 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2206 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2207 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2208 +
2209 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2210 {
2211 int c, old;
2212 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2213 index 2797163..c2a401d 100644
2214 --- a/arch/frv/include/asm/cache.h
2215 +++ b/arch/frv/include/asm/cache.h
2216 @@ -12,10 +12,11 @@
2217 #ifndef __ASM_CACHE_H
2218 #define __ASM_CACHE_H
2219
2220 +#include <linux/const.h>
2221
2222 /* bytes per L1 cache line */
2223 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2224 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2225 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2226
2227 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2228 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2229 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2230 index 43901f2..0d8b865 100644
2231 --- a/arch/frv/include/asm/kmap_types.h
2232 +++ b/arch/frv/include/asm/kmap_types.h
2233 @@ -2,6 +2,6 @@
2234 #ifndef _ASM_KMAP_TYPES_H
2235 #define _ASM_KMAP_TYPES_H
2236
2237 -#define KM_TYPE_NR 17
2238 +#define KM_TYPE_NR 18
2239
2240 #endif
2241 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2242 index 385fd30..6c3d97e 100644
2243 --- a/arch/frv/mm/elf-fdpic.c
2244 +++ b/arch/frv/mm/elf-fdpic.c
2245 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2246 if (addr) {
2247 addr = PAGE_ALIGN(addr);
2248 vma = find_vma(current->mm, addr);
2249 - if (TASK_SIZE - len >= addr &&
2250 - (!vma || addr + len <= vma->vm_start))
2251 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2252 goto success;
2253 }
2254
2255 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2256 for (; vma; vma = vma->vm_next) {
2257 if (addr > limit)
2258 break;
2259 - if (addr + len <= vma->vm_start)
2260 + if (check_heap_stack_gap(vma, addr, len))
2261 goto success;
2262 addr = vma->vm_end;
2263 }
2264 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2265 for (; vma; vma = vma->vm_next) {
2266 if (addr > limit)
2267 break;
2268 - if (addr + len <= vma->vm_start)
2269 + if (check_heap_stack_gap(vma, addr, len))
2270 goto success;
2271 addr = vma->vm_end;
2272 }
2273 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2274 index c635028..6d9445a 100644
2275 --- a/arch/h8300/include/asm/cache.h
2276 +++ b/arch/h8300/include/asm/cache.h
2277 @@ -1,8 +1,10 @@
2278 #ifndef __ARCH_H8300_CACHE_H
2279 #define __ARCH_H8300_CACHE_H
2280
2281 +#include <linux/const.h>
2282 +
2283 /* bytes per L1 cache line */
2284 -#define L1_CACHE_BYTES 4
2285 +#define L1_CACHE_BYTES _AC(4,UL)
2286
2287 /* m68k-elf-gcc 2.95.2 doesn't like these */
2288
2289 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2290 index 0f01de2..d37d309 100644
2291 --- a/arch/hexagon/include/asm/cache.h
2292 +++ b/arch/hexagon/include/asm/cache.h
2293 @@ -21,9 +21,11 @@
2294 #ifndef __ASM_CACHE_H
2295 #define __ASM_CACHE_H
2296
2297 +#include <linux/const.h>
2298 +
2299 /* Bytes per L1 cache line */
2300 -#define L1_CACHE_SHIFT (5)
2301 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2302 +#define L1_CACHE_SHIFT 5
2303 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2304
2305 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2306 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2307 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2308 index 6e6fe18..a6ae668 100644
2309 --- a/arch/ia64/include/asm/atomic.h
2310 +++ b/arch/ia64/include/asm/atomic.h
2311 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2312 #define atomic64_inc(v) atomic64_add(1, (v))
2313 #define atomic64_dec(v) atomic64_sub(1, (v))
2314
2315 +#define atomic64_read_unchecked(v) atomic64_read(v)
2316 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2317 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2318 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2319 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2320 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2321 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2322 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2323 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2324 +
2325 /* Atomic operations are already serializing */
2326 #define smp_mb__before_atomic_dec() barrier()
2327 #define smp_mb__after_atomic_dec() barrier()
2328 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2329 index 988254a..e1ee885 100644
2330 --- a/arch/ia64/include/asm/cache.h
2331 +++ b/arch/ia64/include/asm/cache.h
2332 @@ -1,6 +1,7 @@
2333 #ifndef _ASM_IA64_CACHE_H
2334 #define _ASM_IA64_CACHE_H
2335
2336 +#include <linux/const.h>
2337
2338 /*
2339 * Copyright (C) 1998-2000 Hewlett-Packard Co
2340 @@ -9,7 +10,7 @@
2341
2342 /* Bytes per L1 (data) cache line. */
2343 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2346
2347 #ifdef CONFIG_SMP
2348 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2349 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2350 index b5298eb..67c6e62 100644
2351 --- a/arch/ia64/include/asm/elf.h
2352 +++ b/arch/ia64/include/asm/elf.h
2353 @@ -42,6 +42,13 @@
2354 */
2355 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2356
2357 +#ifdef CONFIG_PAX_ASLR
2358 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2359 +
2360 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2361 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2362 +#endif
2363 +
2364 #define PT_IA_64_UNWIND 0x70000001
2365
2366 /* IA-64 relocations: */
2367 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2368 index 96a8d92..617a1cf 100644
2369 --- a/arch/ia64/include/asm/pgalloc.h
2370 +++ b/arch/ia64/include/asm/pgalloc.h
2371 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2372 pgd_val(*pgd_entry) = __pa(pud);
2373 }
2374
2375 +static inline void
2376 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2377 +{
2378 + pgd_populate(mm, pgd_entry, pud);
2379 +}
2380 +
2381 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2382 {
2383 return quicklist_alloc(0, GFP_KERNEL, NULL);
2384 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2385 pud_val(*pud_entry) = __pa(pmd);
2386 }
2387
2388 +static inline void
2389 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2390 +{
2391 + pud_populate(mm, pud_entry, pmd);
2392 +}
2393 +
2394 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2395 {
2396 return quicklist_alloc(0, GFP_KERNEL, NULL);
2397 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2398 index 815810c..d60bd4c 100644
2399 --- a/arch/ia64/include/asm/pgtable.h
2400 +++ b/arch/ia64/include/asm/pgtable.h
2401 @@ -12,7 +12,7 @@
2402 * David Mosberger-Tang <davidm@hpl.hp.com>
2403 */
2404
2405 -
2406 +#include <linux/const.h>
2407 #include <asm/mman.h>
2408 #include <asm/page.h>
2409 #include <asm/processor.h>
2410 @@ -142,6 +142,17 @@
2411 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2412 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2413 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2414 +
2415 +#ifdef CONFIG_PAX_PAGEEXEC
2416 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2417 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2418 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419 +#else
2420 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2421 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2422 +# define PAGE_COPY_NOEXEC PAGE_COPY
2423 +#endif
2424 +
2425 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2426 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2427 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2428 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2429 index 54ff557..70c88b7 100644
2430 --- a/arch/ia64/include/asm/spinlock.h
2431 +++ b/arch/ia64/include/asm/spinlock.h
2432 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2433 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2434
2435 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2436 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2437 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2438 }
2439
2440 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2441 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2442 index 449c8c0..432a3d2 100644
2443 --- a/arch/ia64/include/asm/uaccess.h
2444 +++ b/arch/ia64/include/asm/uaccess.h
2445 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2446 const void *__cu_from = (from); \
2447 long __cu_len = (n); \
2448 \
2449 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2450 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2451 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2452 __cu_len; \
2453 })
2454 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2455 long __cu_len = (n); \
2456 \
2457 __chk_user_ptr(__cu_from); \
2458 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2459 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2460 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2461 __cu_len; \
2462 })
2463 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2464 index 24603be..948052d 100644
2465 --- a/arch/ia64/kernel/module.c
2466 +++ b/arch/ia64/kernel/module.c
2467 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2468 void
2469 module_free (struct module *mod, void *module_region)
2470 {
2471 - if (mod && mod->arch.init_unw_table &&
2472 - module_region == mod->module_init) {
2473 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2474 unw_remove_unwind_table(mod->arch.init_unw_table);
2475 mod->arch.init_unw_table = NULL;
2476 }
2477 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2478 }
2479
2480 static inline int
2481 +in_init_rx (const struct module *mod, uint64_t addr)
2482 +{
2483 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2484 +}
2485 +
2486 +static inline int
2487 +in_init_rw (const struct module *mod, uint64_t addr)
2488 +{
2489 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2490 +}
2491 +
2492 +static inline int
2493 in_init (const struct module *mod, uint64_t addr)
2494 {
2495 - return addr - (uint64_t) mod->module_init < mod->init_size;
2496 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2497 +}
2498 +
2499 +static inline int
2500 +in_core_rx (const struct module *mod, uint64_t addr)
2501 +{
2502 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2503 +}
2504 +
2505 +static inline int
2506 +in_core_rw (const struct module *mod, uint64_t addr)
2507 +{
2508 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2509 }
2510
2511 static inline int
2512 in_core (const struct module *mod, uint64_t addr)
2513 {
2514 - return addr - (uint64_t) mod->module_core < mod->core_size;
2515 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2516 }
2517
2518 static inline int
2519 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2520 break;
2521
2522 case RV_BDREL:
2523 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2524 + if (in_init_rx(mod, val))
2525 + val -= (uint64_t) mod->module_init_rx;
2526 + else if (in_init_rw(mod, val))
2527 + val -= (uint64_t) mod->module_init_rw;
2528 + else if (in_core_rx(mod, val))
2529 + val -= (uint64_t) mod->module_core_rx;
2530 + else if (in_core_rw(mod, val))
2531 + val -= (uint64_t) mod->module_core_rw;
2532 break;
2533
2534 case RV_LTV:
2535 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2536 * addresses have been selected...
2537 */
2538 uint64_t gp;
2539 - if (mod->core_size > MAX_LTOFF)
2540 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2541 /*
2542 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2543 * at the end of the module.
2544 */
2545 - gp = mod->core_size - MAX_LTOFF / 2;
2546 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2547 else
2548 - gp = mod->core_size / 2;
2549 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2550 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2551 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2552 mod->arch.gp = gp;
2553 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2554 }
2555 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2556 index d9439ef..b9a4303 100644
2557 --- a/arch/ia64/kernel/sys_ia64.c
2558 +++ b/arch/ia64/kernel/sys_ia64.c
2559 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2560 if (REGION_NUMBER(addr) == RGN_HPAGE)
2561 addr = 0;
2562 #endif
2563 +
2564 +#ifdef CONFIG_PAX_RANDMMAP
2565 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2566 + addr = mm->free_area_cache;
2567 + else
2568 +#endif
2569 +
2570 if (!addr)
2571 addr = mm->free_area_cache;
2572
2573 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2575 /* At this point: (!vma || addr < vma->vm_end). */
2576 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2577 - if (start_addr != TASK_UNMAPPED_BASE) {
2578 + if (start_addr != mm->mmap_base) {
2579 /* Start a new search --- just in case we missed some holes. */
2580 - addr = TASK_UNMAPPED_BASE;
2581 + addr = mm->mmap_base;
2582 goto full_search;
2583 }
2584 return -ENOMEM;
2585 }
2586 - if (!vma || addr + len <= vma->vm_start) {
2587 + if (check_heap_stack_gap(vma, addr, len)) {
2588 /* Remember the address where we stopped this search: */
2589 mm->free_area_cache = addr + len;
2590 return addr;
2591 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2592 index 0ccb28f..8992469 100644
2593 --- a/arch/ia64/kernel/vmlinux.lds.S
2594 +++ b/arch/ia64/kernel/vmlinux.lds.S
2595 @@ -198,7 +198,7 @@ SECTIONS {
2596 /* Per-cpu data: */
2597 . = ALIGN(PERCPU_PAGE_SIZE);
2598 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2599 - __phys_per_cpu_start = __per_cpu_load;
2600 + __phys_per_cpu_start = per_cpu_load;
2601 /*
2602 * ensure percpu data fits
2603 * into percpu page size
2604 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2605 index 8443daf..0a01e30 100644
2606 --- a/arch/ia64/mm/fault.c
2607 +++ b/arch/ia64/mm/fault.c
2608 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2609 return pte_present(pte);
2610 }
2611
2612 +#ifdef CONFIG_PAX_PAGEEXEC
2613 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2614 +{
2615 + unsigned long i;
2616 +
2617 + printk(KERN_ERR "PAX: bytes at PC: ");
2618 + for (i = 0; i < 8; i++) {
2619 + unsigned int c;
2620 + if (get_user(c, (unsigned int *)pc+i))
2621 + printk(KERN_CONT "???????? ");
2622 + else
2623 + printk(KERN_CONT "%08x ", c);
2624 + }
2625 + printk("\n");
2626 +}
2627 +#endif
2628 +
2629 # define VM_READ_BIT 0
2630 # define VM_WRITE_BIT 1
2631 # define VM_EXEC_BIT 2
2632 @@ -149,8 +166,21 @@ retry:
2633 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2634 goto bad_area;
2635
2636 - if ((vma->vm_flags & mask) != mask)
2637 + if ((vma->vm_flags & mask) != mask) {
2638 +
2639 +#ifdef CONFIG_PAX_PAGEEXEC
2640 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2641 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2642 + goto bad_area;
2643 +
2644 + up_read(&mm->mmap_sem);
2645 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2646 + do_group_exit(SIGKILL);
2647 + }
2648 +#endif
2649 +
2650 goto bad_area;
2651 + }
2652
2653 /*
2654 * If for any reason at all we couldn't handle the fault, make
2655 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2656 index 5ca674b..e0e1b70 100644
2657 --- a/arch/ia64/mm/hugetlbpage.c
2658 +++ b/arch/ia64/mm/hugetlbpage.c
2659 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2660 /* At this point: (!vmm || addr < vmm->vm_end). */
2661 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2662 return -ENOMEM;
2663 - if (!vmm || (addr + len) <= vmm->vm_start)
2664 + if (check_heap_stack_gap(vmm, addr, len))
2665 return addr;
2666 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2667 }
2668 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2669 index 0eab454..bd794f2 100644
2670 --- a/arch/ia64/mm/init.c
2671 +++ b/arch/ia64/mm/init.c
2672 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2673 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2674 vma->vm_end = vma->vm_start + PAGE_SIZE;
2675 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2676 +
2677 +#ifdef CONFIG_PAX_PAGEEXEC
2678 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2679 + vma->vm_flags &= ~VM_EXEC;
2680 +
2681 +#ifdef CONFIG_PAX_MPROTECT
2682 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2683 + vma->vm_flags &= ~VM_MAYEXEC;
2684 +#endif
2685 +
2686 + }
2687 +#endif
2688 +
2689 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2690 down_write(&current->mm->mmap_sem);
2691 if (insert_vm_struct(current->mm, vma)) {
2692 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2693 index 40b3ee9..8c2c112 100644
2694 --- a/arch/m32r/include/asm/cache.h
2695 +++ b/arch/m32r/include/asm/cache.h
2696 @@ -1,8 +1,10 @@
2697 #ifndef _ASM_M32R_CACHE_H
2698 #define _ASM_M32R_CACHE_H
2699
2700 +#include <linux/const.h>
2701 +
2702 /* L1 cache line size */
2703 #define L1_CACHE_SHIFT 4
2704 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2705 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2706
2707 #endif /* _ASM_M32R_CACHE_H */
2708 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2709 index 82abd15..d95ae5d 100644
2710 --- a/arch/m32r/lib/usercopy.c
2711 +++ b/arch/m32r/lib/usercopy.c
2712 @@ -14,6 +14,9 @@
2713 unsigned long
2714 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2715 {
2716 + if ((long)n < 0)
2717 + return n;
2718 +
2719 prefetch(from);
2720 if (access_ok(VERIFY_WRITE, to, n))
2721 __copy_user(to,from,n);
2722 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2723 unsigned long
2724 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2725 {
2726 + if ((long)n < 0)
2727 + return n;
2728 +
2729 prefetchw(to);
2730 if (access_ok(VERIFY_READ, from, n))
2731 __copy_user_zeroing(to,from,n);
2732 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2733 index 0395c51..5f26031 100644
2734 --- a/arch/m68k/include/asm/cache.h
2735 +++ b/arch/m68k/include/asm/cache.h
2736 @@ -4,9 +4,11 @@
2737 #ifndef __ARCH_M68K_CACHE_H
2738 #define __ARCH_M68K_CACHE_H
2739
2740 +#include <linux/const.h>
2741 +
2742 /* bytes per L1 cache line */
2743 #define L1_CACHE_SHIFT 4
2744 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2745 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2746
2747 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2748
2749 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2750 index 4efe96a..60e8699 100644
2751 --- a/arch/microblaze/include/asm/cache.h
2752 +++ b/arch/microblaze/include/asm/cache.h
2753 @@ -13,11 +13,12 @@
2754 #ifndef _ASM_MICROBLAZE_CACHE_H
2755 #define _ASM_MICROBLAZE_CACHE_H
2756
2757 +#include <linux/const.h>
2758 #include <asm/registers.h>
2759
2760 #define L1_CACHE_SHIFT 5
2761 /* word-granular cache in microblaze */
2762 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2763 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2764
2765 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2766
2767 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2768 index 3f4c5cb..3439c6e 100644
2769 --- a/arch/mips/include/asm/atomic.h
2770 +++ b/arch/mips/include/asm/atomic.h
2771 @@ -21,6 +21,10 @@
2772 #include <asm/cmpxchg.h>
2773 #include <asm/war.h>
2774
2775 +#ifdef CONFIG_GENERIC_ATOMIC64
2776 +#include <asm-generic/atomic64.h>
2777 +#endif
2778 +
2779 #define ATOMIC_INIT(i) { (i) }
2780
2781 /*
2782 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2783 */
2784 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2785
2786 +#define atomic64_read_unchecked(v) atomic64_read(v)
2787 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2788 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2789 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2790 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2791 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2792 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2793 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2794 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2795 +
2796 #endif /* CONFIG_64BIT */
2797
2798 /*
2799 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2800 index b4db69f..8f3b093 100644
2801 --- a/arch/mips/include/asm/cache.h
2802 +++ b/arch/mips/include/asm/cache.h
2803 @@ -9,10 +9,11 @@
2804 #ifndef _ASM_CACHE_H
2805 #define _ASM_CACHE_H
2806
2807 +#include <linux/const.h>
2808 #include <kmalloc.h>
2809
2810 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2811 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2812 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2813
2814 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2815 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2816 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2817 index 455c0ac..ad65fbe 100644
2818 --- a/arch/mips/include/asm/elf.h
2819 +++ b/arch/mips/include/asm/elf.h
2820 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2821 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2822 #endif
2823
2824 +#ifdef CONFIG_PAX_ASLR
2825 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2826 +
2827 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2828 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2829 +#endif
2830 +
2831 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2832 struct linux_binprm;
2833 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2834 int uses_interp);
2835
2836 -struct mm_struct;
2837 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2838 -#define arch_randomize_brk arch_randomize_brk
2839 -
2840 #endif /* _ASM_ELF_H */
2841 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2842 index c1f6afa..38cc6e9 100644
2843 --- a/arch/mips/include/asm/exec.h
2844 +++ b/arch/mips/include/asm/exec.h
2845 @@ -12,6 +12,6 @@
2846 #ifndef _ASM_EXEC_H
2847 #define _ASM_EXEC_H
2848
2849 -extern unsigned long arch_align_stack(unsigned long sp);
2850 +#define arch_align_stack(x) ((x) & ~0xfUL)
2851
2852 #endif /* _ASM_EXEC_H */
2853 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2854 index da9bd7d..91aa7ab 100644
2855 --- a/arch/mips/include/asm/page.h
2856 +++ b/arch/mips/include/asm/page.h
2857 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2858 #ifdef CONFIG_CPU_MIPS32
2859 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2860 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2861 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2862 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2863 #else
2864 typedef struct { unsigned long long pte; } pte_t;
2865 #define pte_val(x) ((x).pte)
2866 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2867 index 881d18b..cea38bc 100644
2868 --- a/arch/mips/include/asm/pgalloc.h
2869 +++ b/arch/mips/include/asm/pgalloc.h
2870 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2871 {
2872 set_pud(pud, __pud((unsigned long)pmd));
2873 }
2874 +
2875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2876 +{
2877 + pud_populate(mm, pud, pmd);
2878 +}
2879 #endif
2880
2881 /*
2882 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2883 index ca97e0e..cd08920 100644
2884 --- a/arch/mips/include/asm/thread_info.h
2885 +++ b/arch/mips/include/asm/thread_info.h
2886 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2887 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2888 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2889 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2890 +/* li takes a 32bit immediate */
2891 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2892 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2893
2894 #ifdef CONFIG_MIPS32_O32
2895 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2897 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2898 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2899 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2900 +
2901 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2902
2903 /* work to do in syscall_trace_leave() */
2904 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2905 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2906
2907 /* work to do on interrupt/exception return */
2908 #define _TIF_WORK_MASK (0x0000ffef & \
2909 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2910 /* work to do on any return to u-space */
2911 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2912 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2913
2914 #endif /* __KERNEL__ */
2915
2916 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2917 index 9fdd8bc..4bd7f1a 100644
2918 --- a/arch/mips/kernel/binfmt_elfn32.c
2919 +++ b/arch/mips/kernel/binfmt_elfn32.c
2920 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2921 #undef ELF_ET_DYN_BASE
2922 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2923
2924 +#ifdef CONFIG_PAX_ASLR
2925 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2926 +
2927 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2928 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2929 +#endif
2930 +
2931 #include <asm/processor.h>
2932 #include <linux/module.h>
2933 #include <linux/elfcore.h>
2934 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2935 index ff44823..97f8906 100644
2936 --- a/arch/mips/kernel/binfmt_elfo32.c
2937 +++ b/arch/mips/kernel/binfmt_elfo32.c
2938 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2939 #undef ELF_ET_DYN_BASE
2940 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2941
2942 +#ifdef CONFIG_PAX_ASLR
2943 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2944 +
2945 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2947 +#endif
2948 +
2949 #include <asm/processor.h>
2950
2951 /*
2952 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2953 index e9a5fd7..378809a 100644
2954 --- a/arch/mips/kernel/process.c
2955 +++ b/arch/mips/kernel/process.c
2956 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2957 out:
2958 return pc;
2959 }
2960 -
2961 -/*
2962 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2963 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2964 - */
2965 -unsigned long arch_align_stack(unsigned long sp)
2966 -{
2967 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2968 - sp -= get_random_int() & ~PAGE_MASK;
2969 -
2970 - return sp & ALMASK;
2971 -}
2972 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2973 index 4812c6d..2069554 100644
2974 --- a/arch/mips/kernel/ptrace.c
2975 +++ b/arch/mips/kernel/ptrace.c
2976 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2977 return arch;
2978 }
2979
2980 +#ifdef CONFIG_GRKERNSEC_SETXID
2981 +extern void gr_delayed_cred_worker(void);
2982 +#endif
2983 +
2984 /*
2985 * Notification of system call entry/exit
2986 * - triggered by current->work.syscall_trace
2987 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2988 /* do the secure computing check first */
2989 secure_computing_strict(regs->regs[2]);
2990
2991 +#ifdef CONFIG_GRKERNSEC_SETXID
2992 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2993 + gr_delayed_cred_worker();
2994 +#endif
2995 +
2996 if (!(current->ptrace & PT_PTRACED))
2997 goto out;
2998
2999 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3000 index a632bc1..0b77c7c 100644
3001 --- a/arch/mips/kernel/scall32-o32.S
3002 +++ b/arch/mips/kernel/scall32-o32.S
3003 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3004
3005 stack_done:
3006 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3007 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3008 + li t1, _TIF_SYSCALL_WORK
3009 and t0, t1
3010 bnez t0, syscall_trace_entry # -> yes
3011
3012 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3013 index 3b5a5e9..e1ee86d 100644
3014 --- a/arch/mips/kernel/scall64-64.S
3015 +++ b/arch/mips/kernel/scall64-64.S
3016 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3017
3018 sd a3, PT_R26(sp) # save a3 for syscall restarting
3019
3020 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3021 + li t1, _TIF_SYSCALL_WORK
3022 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3023 and t0, t1, t0
3024 bnez t0, syscall_trace_entry
3025 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3026 index 6be6f70..1859577 100644
3027 --- a/arch/mips/kernel/scall64-n32.S
3028 +++ b/arch/mips/kernel/scall64-n32.S
3029 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3030
3031 sd a3, PT_R26(sp) # save a3 for syscall restarting
3032
3033 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3034 + li t1, _TIF_SYSCALL_WORK
3035 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3036 and t0, t1, t0
3037 bnez t0, n32_syscall_trace_entry
3038 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3039 index 5422855..74e63a3 100644
3040 --- a/arch/mips/kernel/scall64-o32.S
3041 +++ b/arch/mips/kernel/scall64-o32.S
3042 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3043 PTR 4b, bad_stack
3044 .previous
3045
3046 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3047 + li t1, _TIF_SYSCALL_WORK
3048 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3049 and t0, t1, t0
3050 bnez t0, trace_a_syscall
3051 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3052 index c14f6df..537e729 100644
3053 --- a/arch/mips/mm/fault.c
3054 +++ b/arch/mips/mm/fault.c
3055 @@ -27,6 +27,23 @@
3056 #include <asm/highmem.h> /* For VMALLOC_END */
3057 #include <linux/kdebug.h>
3058
3059 +#ifdef CONFIG_PAX_PAGEEXEC
3060 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3061 +{
3062 + unsigned long i;
3063 +
3064 + printk(KERN_ERR "PAX: bytes at PC: ");
3065 + for (i = 0; i < 5; i++) {
3066 + unsigned int c;
3067 + if (get_user(c, (unsigned int *)pc+i))
3068 + printk(KERN_CONT "???????? ");
3069 + else
3070 + printk(KERN_CONT "%08x ", c);
3071 + }
3072 + printk("\n");
3073 +}
3074 +#endif
3075 +
3076 /*
3077 * This routine handles page faults. It determines the address,
3078 * and the problem, and then passes it off to one of the appropriate
3079 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3080 index 302d779..7d35bf8 100644
3081 --- a/arch/mips/mm/mmap.c
3082 +++ b/arch/mips/mm/mmap.c
3083 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3084 do_color_align = 1;
3085
3086 /* requesting a specific address */
3087 +
3088 +#ifdef CONFIG_PAX_RANDMMAP
3089 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3090 +#endif
3091 +
3092 if (addr) {
3093 if (do_color_align)
3094 addr = COLOUR_ALIGN(addr, pgoff);
3095 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 addr = PAGE_ALIGN(addr);
3097
3098 vma = find_vma(mm, addr);
3099 - if (TASK_SIZE - len >= addr &&
3100 - (!vma || addr + len <= vma->vm_start))
3101 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3102 return addr;
3103 }
3104
3105 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3106 /* At this point: (!vma || addr < vma->vm_end). */
3107 if (TASK_SIZE - len < addr)
3108 return -ENOMEM;
3109 - if (!vma || addr + len <= vma->vm_start)
3110 + if (check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 addr = vma->vm_end;
3113 if (do_color_align)
3114 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* make sure it can fit in the remaining address space */
3116 if (likely(addr > len)) {
3117 vma = find_vma(mm, addr - len);
3118 - if (!vma || addr <= vma->vm_start) {
3119 + if (check_heap_stack_gap(vmm, addr - len, len))
3120 /* cache the address as a hint for next time */
3121 return mm->free_area_cache = addr - len;
3122 }
3123 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 * return with success:
3125 */
3126 vma = find_vma(mm, addr);
3127 - if (likely(!vma || addr + len <= vma->vm_start)) {
3128 + if (check_heap_stack_gap(vmm, addr, len)) {
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr;
3131 }
3132 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3133 mm->unmap_area = arch_unmap_area_topdown;
3134 }
3135 }
3136 -
3137 -static inline unsigned long brk_rnd(void)
3138 -{
3139 - unsigned long rnd = get_random_int();
3140 -
3141 - rnd = rnd << PAGE_SHIFT;
3142 - /* 8MB for 32bit, 256MB for 64bit */
3143 - if (TASK_IS_32BIT_ADDR)
3144 - rnd = rnd & 0x7ffffful;
3145 - else
3146 - rnd = rnd & 0xffffffful;
3147 -
3148 - return rnd;
3149 -}
3150 -
3151 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3152 -{
3153 - unsigned long base = mm->brk;
3154 - unsigned long ret;
3155 -
3156 - ret = PAGE_ALIGN(base + brk_rnd());
3157 -
3158 - if (ret < mm->brk)
3159 - return mm->brk;
3160 -
3161 - return ret;
3162 -}
3163 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3164 index 967d144..db12197 100644
3165 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3166 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3167 @@ -11,12 +11,14 @@
3168 #ifndef _ASM_PROC_CACHE_H
3169 #define _ASM_PROC_CACHE_H
3170
3171 +#include <linux/const.h>
3172 +
3173 /* L1 cache */
3174
3175 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3176 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3177 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3178 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3179 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3180 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3181
3182 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3183 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3184 index bcb5df2..84fabd2 100644
3185 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3186 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3187 @@ -16,13 +16,15 @@
3188 #ifndef _ASM_PROC_CACHE_H
3189 #define _ASM_PROC_CACHE_H
3190
3191 +#include <linux/const.h>
3192 +
3193 /*
3194 * L1 cache
3195 */
3196 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3197 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3198 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3199 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3200 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3201 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3202
3203 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3204 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3205 index 4ce7a01..449202a 100644
3206 --- a/arch/openrisc/include/asm/cache.h
3207 +++ b/arch/openrisc/include/asm/cache.h
3208 @@ -19,11 +19,13 @@
3209 #ifndef __ASM_OPENRISC_CACHE_H
3210 #define __ASM_OPENRISC_CACHE_H
3211
3212 +#include <linux/const.h>
3213 +
3214 /* FIXME: How can we replace these with values from the CPU...
3215 * they shouldn't be hard-coded!
3216 */
3217
3218 -#define L1_CACHE_BYTES 16
3219 #define L1_CACHE_SHIFT 4
3220 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3221
3222 #endif /* __ASM_OPENRISC_CACHE_H */
3223 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3224 index af9cf30..2aae9b2 100644
3225 --- a/arch/parisc/include/asm/atomic.h
3226 +++ b/arch/parisc/include/asm/atomic.h
3227 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3228
3229 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3230
3231 +#define atomic64_read_unchecked(v) atomic64_read(v)
3232 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3233 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3234 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3235 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3236 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3237 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3238 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3239 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3240 +
3241 #endif /* !CONFIG_64BIT */
3242
3243
3244 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3245 index 47f11c7..3420df2 100644
3246 --- a/arch/parisc/include/asm/cache.h
3247 +++ b/arch/parisc/include/asm/cache.h
3248 @@ -5,6 +5,7 @@
3249 #ifndef __ARCH_PARISC_CACHE_H
3250 #define __ARCH_PARISC_CACHE_H
3251
3252 +#include <linux/const.h>
3253
3254 /*
3255 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3256 @@ -15,13 +16,13 @@
3257 * just ruin performance.
3258 */
3259 #ifdef CONFIG_PA20
3260 -#define L1_CACHE_BYTES 64
3261 #define L1_CACHE_SHIFT 6
3262 #else
3263 -#define L1_CACHE_BYTES 32
3264 #define L1_CACHE_SHIFT 5
3265 #endif
3266
3267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3268 +
3269 #ifndef __ASSEMBLY__
3270
3271 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3272 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3273 index 19f6cb1..6c78cf2 100644
3274 --- a/arch/parisc/include/asm/elf.h
3275 +++ b/arch/parisc/include/asm/elf.h
3276 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3277
3278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3279
3280 +#ifdef CONFIG_PAX_ASLR
3281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3282 +
3283 +#define PAX_DELTA_MMAP_LEN 16
3284 +#define PAX_DELTA_STACK_LEN 16
3285 +#endif
3286 +
3287 /* This yields a mask that user programs can use to figure out what
3288 instruction set this CPU supports. This could be done in user space,
3289 but it's not easy, and we've already done it here. */
3290 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3291 index fc987a1..6e068ef 100644
3292 --- a/arch/parisc/include/asm/pgalloc.h
3293 +++ b/arch/parisc/include/asm/pgalloc.h
3294 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3295 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3296 }
3297
3298 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3299 +{
3300 + pgd_populate(mm, pgd, pmd);
3301 +}
3302 +
3303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3304 {
3305 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3306 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3307 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3308 #define pmd_free(mm, x) do { } while (0)
3309 #define pgd_populate(mm, pmd, pte) BUG()
3310 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3311
3312 #endif
3313
3314 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3315 index ee99f23..802b0a1 100644
3316 --- a/arch/parisc/include/asm/pgtable.h
3317 +++ b/arch/parisc/include/asm/pgtable.h
3318 @@ -212,6 +212,17 @@ struct vm_area_struct;
3319 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3320 #define PAGE_COPY PAGE_EXECREAD
3321 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3322 +
3323 +#ifdef CONFIG_PAX_PAGEEXEC
3324 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3325 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3326 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3327 +#else
3328 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3329 +# define PAGE_COPY_NOEXEC PAGE_COPY
3330 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3331 +#endif
3332 +
3333 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3334 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3335 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3336 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3337 index 4ba2c93..f5e3974 100644
3338 --- a/arch/parisc/include/asm/uaccess.h
3339 +++ b/arch/parisc/include/asm/uaccess.h
3340 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3341 const void __user *from,
3342 unsigned long n)
3343 {
3344 - int sz = __compiletime_object_size(to);
3345 + size_t sz = __compiletime_object_size(to);
3346 int ret = -EFAULT;
3347
3348 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3349 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3350 ret = __copy_from_user(to, from, n);
3351 else
3352 copy_from_user_overflow();
3353 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3354 index 5e34ccf..672bc9c 100644
3355 --- a/arch/parisc/kernel/module.c
3356 +++ b/arch/parisc/kernel/module.c
3357 @@ -98,16 +98,38 @@
3358
3359 /* three functions to determine where in the module core
3360 * or init pieces the location is */
3361 +static inline int in_init_rx(struct module *me, void *loc)
3362 +{
3363 + return (loc >= me->module_init_rx &&
3364 + loc < (me->module_init_rx + me->init_size_rx));
3365 +}
3366 +
3367 +static inline int in_init_rw(struct module *me, void *loc)
3368 +{
3369 + return (loc >= me->module_init_rw &&
3370 + loc < (me->module_init_rw + me->init_size_rw));
3371 +}
3372 +
3373 static inline int in_init(struct module *me, void *loc)
3374 {
3375 - return (loc >= me->module_init &&
3376 - loc <= (me->module_init + me->init_size));
3377 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3378 +}
3379 +
3380 +static inline int in_core_rx(struct module *me, void *loc)
3381 +{
3382 + return (loc >= me->module_core_rx &&
3383 + loc < (me->module_core_rx + me->core_size_rx));
3384 +}
3385 +
3386 +static inline int in_core_rw(struct module *me, void *loc)
3387 +{
3388 + return (loc >= me->module_core_rw &&
3389 + loc < (me->module_core_rw + me->core_size_rw));
3390 }
3391
3392 static inline int in_core(struct module *me, void *loc)
3393 {
3394 - return (loc >= me->module_core &&
3395 - loc <= (me->module_core + me->core_size));
3396 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3397 }
3398
3399 static inline int in_local(struct module *me, void *loc)
3400 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3401 }
3402
3403 /* align things a bit */
3404 - me->core_size = ALIGN(me->core_size, 16);
3405 - me->arch.got_offset = me->core_size;
3406 - me->core_size += gots * sizeof(struct got_entry);
3407 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3408 + me->arch.got_offset = me->core_size_rw;
3409 + me->core_size_rw += gots * sizeof(struct got_entry);
3410
3411 - me->core_size = ALIGN(me->core_size, 16);
3412 - me->arch.fdesc_offset = me->core_size;
3413 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3414 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3415 + me->arch.fdesc_offset = me->core_size_rw;
3416 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3417
3418 me->arch.got_max = gots;
3419 me->arch.fdesc_max = fdescs;
3420 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3421
3422 BUG_ON(value == 0);
3423
3424 - got = me->module_core + me->arch.got_offset;
3425 + got = me->module_core_rw + me->arch.got_offset;
3426 for (i = 0; got[i].addr; i++)
3427 if (got[i].addr == value)
3428 goto out;
3429 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430 #ifdef CONFIG_64BIT
3431 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3432 {
3433 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3434 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3435
3436 if (!value) {
3437 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3438 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3439
3440 /* Create new one */
3441 fdesc->addr = value;
3442 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3443 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3444 return (Elf_Addr)fdesc;
3445 }
3446 #endif /* CONFIG_64BIT */
3447 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3448
3449 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3450 end = table + sechdrs[me->arch.unwind_section].sh_size;
3451 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453
3454 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3455 me->arch.unwind_section, table, end, gp);
3456 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3457 index 7426e40..30c8dbe 100644
3458 --- a/arch/parisc/kernel/sys_parisc.c
3459 +++ b/arch/parisc/kernel/sys_parisc.c
3460 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3461 /* At this point: (!vma || addr < vma->vm_end). */
3462 if (TASK_SIZE - len < addr)
3463 return -ENOMEM;
3464 - if (!vma || addr + len <= vma->vm_start)
3465 + if (check_heap_stack_gap(vma, addr, len))
3466 return addr;
3467 addr = vma->vm_end;
3468 }
3469 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473 - if (!vma || addr + len <= vma->vm_start)
3474 + if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3477 if (addr < vma->vm_end) /* handle wraparound */
3478 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3479 if (flags & MAP_FIXED)
3480 return addr;
3481 if (!addr)
3482 - addr = TASK_UNMAPPED_BASE;
3483 + addr = current->mm->mmap_base;
3484
3485 if (filp) {
3486 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3487 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3488 index 45ba99f..8e22c33 100644
3489 --- a/arch/parisc/kernel/traps.c
3490 +++ b/arch/parisc/kernel/traps.c
3491 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3492
3493 down_read(&current->mm->mmap_sem);
3494 vma = find_vma(current->mm,regs->iaoq[0]);
3495 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3496 - && (vma->vm_flags & VM_EXEC)) {
3497 -
3498 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3499 fault_address = regs->iaoq[0];
3500 fault_space = regs->iasq[0];
3501
3502 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3503 index 18162ce..94de376 100644
3504 --- a/arch/parisc/mm/fault.c
3505 +++ b/arch/parisc/mm/fault.c
3506 @@ -15,6 +15,7 @@
3507 #include <linux/sched.h>
3508 #include <linux/interrupt.h>
3509 #include <linux/module.h>
3510 +#include <linux/unistd.h>
3511
3512 #include <asm/uaccess.h>
3513 #include <asm/traps.h>
3514 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3515 static unsigned long
3516 parisc_acctyp(unsigned long code, unsigned int inst)
3517 {
3518 - if (code == 6 || code == 16)
3519 + if (code == 6 || code == 7 || code == 16)
3520 return VM_EXEC;
3521
3522 switch (inst & 0xf0000000) {
3523 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3524 }
3525 #endif
3526
3527 +#ifdef CONFIG_PAX_PAGEEXEC
3528 +/*
3529 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3530 + *
3531 + * returns 1 when task should be killed
3532 + * 2 when rt_sigreturn trampoline was detected
3533 + * 3 when unpatched PLT trampoline was detected
3534 + */
3535 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3536 +{
3537 +
3538 +#ifdef CONFIG_PAX_EMUPLT
3539 + int err;
3540 +
3541 + do { /* PaX: unpatched PLT emulation */
3542 + unsigned int bl, depwi;
3543 +
3544 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3545 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3546 +
3547 + if (err)
3548 + break;
3549 +
3550 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3551 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3552 +
3553 + err = get_user(ldw, (unsigned int *)addr);
3554 + err |= get_user(bv, (unsigned int *)(addr+4));
3555 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3556 +
3557 + if (err)
3558 + break;
3559 +
3560 + if (ldw == 0x0E801096U &&
3561 + bv == 0xEAC0C000U &&
3562 + ldw2 == 0x0E881095U)
3563 + {
3564 + unsigned int resolver, map;
3565 +
3566 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3567 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3568 + if (err)
3569 + break;
3570 +
3571 + regs->gr[20] = instruction_pointer(regs)+8;
3572 + regs->gr[21] = map;
3573 + regs->gr[22] = resolver;
3574 + regs->iaoq[0] = resolver | 3UL;
3575 + regs->iaoq[1] = regs->iaoq[0] + 4;
3576 + return 3;
3577 + }
3578 + }
3579 + } while (0);
3580 +#endif
3581 +
3582 +#ifdef CONFIG_PAX_EMUTRAMP
3583 +
3584 +#ifndef CONFIG_PAX_EMUSIGRT
3585 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3586 + return 1;
3587 +#endif
3588 +
3589 + do { /* PaX: rt_sigreturn emulation */
3590 + unsigned int ldi1, ldi2, bel, nop;
3591 +
3592 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3593 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3594 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3595 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3596 +
3597 + if (err)
3598 + break;
3599 +
3600 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3601 + ldi2 == 0x3414015AU &&
3602 + bel == 0xE4008200U &&
3603 + nop == 0x08000240U)
3604 + {
3605 + regs->gr[25] = (ldi1 & 2) >> 1;
3606 + regs->gr[20] = __NR_rt_sigreturn;
3607 + regs->gr[31] = regs->iaoq[1] + 16;
3608 + regs->sr[0] = regs->iasq[1];
3609 + regs->iaoq[0] = 0x100UL;
3610 + regs->iaoq[1] = regs->iaoq[0] + 4;
3611 + regs->iasq[0] = regs->sr[2];
3612 + regs->iasq[1] = regs->sr[2];
3613 + return 2;
3614 + }
3615 + } while (0);
3616 +#endif
3617 +
3618 + return 1;
3619 +}
3620 +
3621 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3622 +{
3623 + unsigned long i;
3624 +
3625 + printk(KERN_ERR "PAX: bytes at PC: ");
3626 + for (i = 0; i < 5; i++) {
3627 + unsigned int c;
3628 + if (get_user(c, (unsigned int *)pc+i))
3629 + printk(KERN_CONT "???????? ");
3630 + else
3631 + printk(KERN_CONT "%08x ", c);
3632 + }
3633 + printk("\n");
3634 +}
3635 +#endif
3636 +
3637 int fixup_exception(struct pt_regs *regs)
3638 {
3639 const struct exception_table_entry *fix;
3640 @@ -192,8 +303,33 @@ good_area:
3641
3642 acc_type = parisc_acctyp(code,regs->iir);
3643
3644 - if ((vma->vm_flags & acc_type) != acc_type)
3645 + if ((vma->vm_flags & acc_type) != acc_type) {
3646 +
3647 +#ifdef CONFIG_PAX_PAGEEXEC
3648 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3649 + (address & ~3UL) == instruction_pointer(regs))
3650 + {
3651 + up_read(&mm->mmap_sem);
3652 + switch (pax_handle_fetch_fault(regs)) {
3653 +
3654 +#ifdef CONFIG_PAX_EMUPLT
3655 + case 3:
3656 + return;
3657 +#endif
3658 +
3659 +#ifdef CONFIG_PAX_EMUTRAMP
3660 + case 2:
3661 + return;
3662 +#endif
3663 +
3664 + }
3665 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3666 + do_group_exit(SIGKILL);
3667 + }
3668 +#endif
3669 +
3670 goto bad_area;
3671 + }
3672
3673 /*
3674 * If for any reason at all we couldn't handle the fault, make
3675 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3676 index da29032..f76c24c 100644
3677 --- a/arch/powerpc/include/asm/atomic.h
3678 +++ b/arch/powerpc/include/asm/atomic.h
3679 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3680 return t1;
3681 }
3682
3683 +#define atomic64_read_unchecked(v) atomic64_read(v)
3684 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3685 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3686 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3687 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3688 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3689 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3690 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3691 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3692 +
3693 #endif /* __powerpc64__ */
3694
3695 #endif /* __KERNEL__ */
3696 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3697 index 9e495c9..b6878e5 100644
3698 --- a/arch/powerpc/include/asm/cache.h
3699 +++ b/arch/powerpc/include/asm/cache.h
3700 @@ -3,6 +3,7 @@
3701
3702 #ifdef __KERNEL__
3703
3704 +#include <linux/const.h>
3705
3706 /* bytes per L1 cache line */
3707 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3708 @@ -22,7 +23,7 @@
3709 #define L1_CACHE_SHIFT 7
3710 #endif
3711
3712 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3713 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3714
3715 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3716
3717 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3718 index 3bf9cca..e7457d0 100644
3719 --- a/arch/powerpc/include/asm/elf.h
3720 +++ b/arch/powerpc/include/asm/elf.h
3721 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3722 the loader. We need to make sure that it is out of the way of the program
3723 that it will "exec", and that there is sufficient room for the brk. */
3724
3725 -extern unsigned long randomize_et_dyn(unsigned long base);
3726 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3727 +#define ELF_ET_DYN_BASE (0x20000000)
3728 +
3729 +#ifdef CONFIG_PAX_ASLR
3730 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3731 +
3732 +#ifdef __powerpc64__
3733 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3734 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3735 +#else
3736 +#define PAX_DELTA_MMAP_LEN 15
3737 +#define PAX_DELTA_STACK_LEN 15
3738 +#endif
3739 +#endif
3740
3741 /*
3742 * Our registers are always unsigned longs, whether we're a 32 bit
3743 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3744 (0x7ff >> (PAGE_SHIFT - 12)) : \
3745 (0x3ffff >> (PAGE_SHIFT - 12)))
3746
3747 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3748 -#define arch_randomize_brk arch_randomize_brk
3749 -
3750 #endif /* __KERNEL__ */
3751
3752 /*
3753 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3754 index 8196e9c..d83a9f3 100644
3755 --- a/arch/powerpc/include/asm/exec.h
3756 +++ b/arch/powerpc/include/asm/exec.h
3757 @@ -4,6 +4,6 @@
3758 #ifndef _ASM_POWERPC_EXEC_H
3759 #define _ASM_POWERPC_EXEC_H
3760
3761 -extern unsigned long arch_align_stack(unsigned long sp);
3762 +#define arch_align_stack(x) ((x) & ~0xfUL)
3763
3764 #endif /* _ASM_POWERPC_EXEC_H */
3765 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3766 index 5acabbd..7ea14fa 100644
3767 --- a/arch/powerpc/include/asm/kmap_types.h
3768 +++ b/arch/powerpc/include/asm/kmap_types.h
3769 @@ -10,7 +10,7 @@
3770 * 2 of the License, or (at your option) any later version.
3771 */
3772
3773 -#define KM_TYPE_NR 16
3774 +#define KM_TYPE_NR 17
3775
3776 #endif /* __KERNEL__ */
3777 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3778 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3779 index d4a7f64..451de1c 100644
3780 --- a/arch/powerpc/include/asm/mman.h
3781 +++ b/arch/powerpc/include/asm/mman.h
3782 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3783 }
3784 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3785
3786 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3787 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3788 {
3789 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3790 }
3791 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3792 index f072e97..b436dee 100644
3793 --- a/arch/powerpc/include/asm/page.h
3794 +++ b/arch/powerpc/include/asm/page.h
3795 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3796 * and needs to be executable. This means the whole heap ends
3797 * up being executable.
3798 */
3799 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3800 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3801 +#define VM_DATA_DEFAULT_FLAGS32 \
3802 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3803 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3804
3805 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3806 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3807 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3808 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3809 #endif
3810
3811 +#define ktla_ktva(addr) (addr)
3812 +#define ktva_ktla(addr) (addr)
3813 +
3814 /*
3815 * Use the top bit of the higher-level page table entries to indicate whether
3816 * the entries we point to contain hugepages. This works because we know that
3817 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3818 index fed85e6..da5c71b 100644
3819 --- a/arch/powerpc/include/asm/page_64.h
3820 +++ b/arch/powerpc/include/asm/page_64.h
3821 @@ -146,15 +146,18 @@ do { \
3822 * stack by default, so in the absence of a PT_GNU_STACK program header
3823 * we turn execute permission off.
3824 */
3825 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3826 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3827 +#define VM_STACK_DEFAULT_FLAGS32 \
3828 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3829 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3830
3831 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3832 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833
3834 +#ifndef CONFIG_PAX_PAGEEXEC
3835 #define VM_STACK_DEFAULT_FLAGS \
3836 (is_32bit_task() ? \
3837 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3838 +#endif
3839
3840 #include <asm-generic/getorder.h>
3841
3842 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3843 index 292725c..f87ae14 100644
3844 --- a/arch/powerpc/include/asm/pgalloc-64.h
3845 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3846 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3847 #ifndef CONFIG_PPC_64K_PAGES
3848
3849 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3850 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3851
3852 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3853 {
3854 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3855 pud_set(pud, (unsigned long)pmd);
3856 }
3857
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 +
3863 #define pmd_populate(mm, pmd, pte_page) \
3864 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3865 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3866 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867 #else /* CONFIG_PPC_64K_PAGES */
3868
3869 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3870 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3871
3872 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3873 pte_t *pte)
3874 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3875 index 2e0e411..7899c68 100644
3876 --- a/arch/powerpc/include/asm/pgtable.h
3877 +++ b/arch/powerpc/include/asm/pgtable.h
3878 @@ -2,6 +2,7 @@
3879 #define _ASM_POWERPC_PGTABLE_H
3880 #ifdef __KERNEL__
3881
3882 +#include <linux/const.h>
3883 #ifndef __ASSEMBLY__
3884 #include <asm/processor.h> /* For TASK_SIZE */
3885 #include <asm/mmu.h>
3886 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3887 index 4aad413..85d86bf 100644
3888 --- a/arch/powerpc/include/asm/pte-hash32.h
3889 +++ b/arch/powerpc/include/asm/pte-hash32.h
3890 @@ -21,6 +21,7 @@
3891 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3892 #define _PAGE_USER 0x004 /* usermode access allowed */
3893 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3894 +#define _PAGE_EXEC _PAGE_GUARDED
3895 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3896 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3897 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3898 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3899 index 6386086..6982225 100644
3900 --- a/arch/powerpc/include/asm/reg.h
3901 +++ b/arch/powerpc/include/asm/reg.h
3902 @@ -212,6 +212,7 @@
3903 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3904 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3905 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3906 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3907 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3908 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3909 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3910 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3911 index faf9352..ab2ccec 100644
3912 --- a/arch/powerpc/include/asm/thread_info.h
3913 +++ b/arch/powerpc/include/asm/thread_info.h
3914 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3915 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3916 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3917 #define TIF_SINGLESTEP 8 /* singlestepping active */
3918 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3919 #define TIF_SECCOMP 10 /* secure computing */
3920 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3921 #define TIF_NOERROR 12 /* Force successful syscall return */
3922 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3923 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3924 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3925 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3926 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3927
3928 /* as above, but as bit values */
3929 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3930 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3931 #define _TIF_NOERROR (1<<TIF_NOERROR)
3932 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3933 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3934 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3935 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3936 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3937 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3938 + _TIF_GRSEC_SETXID)
3939
3940 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3941 _TIF_NOTIFY_RESUME)
3942 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3943 index 17bb40c..353c98b 100644
3944 --- a/arch/powerpc/include/asm/uaccess.h
3945 +++ b/arch/powerpc/include/asm/uaccess.h
3946 @@ -13,6 +13,8 @@
3947 #define VERIFY_READ 0
3948 #define VERIFY_WRITE 1
3949
3950 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3951 +
3952 /*
3953 * The fs value determines whether argument validity checking should be
3954 * performed or not. If get_fs() == USER_DS, checking is performed, with
3955 @@ -329,52 +331,6 @@ do { \
3956 extern unsigned long __copy_tofrom_user(void __user *to,
3957 const void __user *from, unsigned long size);
3958
3959 -#ifndef __powerpc64__
3960 -
3961 -static inline unsigned long copy_from_user(void *to,
3962 - const void __user *from, unsigned long n)
3963 -{
3964 - unsigned long over;
3965 -
3966 - if (access_ok(VERIFY_READ, from, n))
3967 - return __copy_tofrom_user((__force void __user *)to, from, n);
3968 - if ((unsigned long)from < TASK_SIZE) {
3969 - over = (unsigned long)from + n - TASK_SIZE;
3970 - return __copy_tofrom_user((__force void __user *)to, from,
3971 - n - over) + over;
3972 - }
3973 - return n;
3974 -}
3975 -
3976 -static inline unsigned long copy_to_user(void __user *to,
3977 - const void *from, unsigned long n)
3978 -{
3979 - unsigned long over;
3980 -
3981 - if (access_ok(VERIFY_WRITE, to, n))
3982 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3983 - if ((unsigned long)to < TASK_SIZE) {
3984 - over = (unsigned long)to + n - TASK_SIZE;
3985 - return __copy_tofrom_user(to, (__force void __user *)from,
3986 - n - over) + over;
3987 - }
3988 - return n;
3989 -}
3990 -
3991 -#else /* __powerpc64__ */
3992 -
3993 -#define __copy_in_user(to, from, size) \
3994 - __copy_tofrom_user((to), (from), (size))
3995 -
3996 -extern unsigned long copy_from_user(void *to, const void __user *from,
3997 - unsigned long n);
3998 -extern unsigned long copy_to_user(void __user *to, const void *from,
3999 - unsigned long n);
4000 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4001 - unsigned long n);
4002 -
4003 -#endif /* __powerpc64__ */
4004 -
4005 static inline unsigned long __copy_from_user_inatomic(void *to,
4006 const void __user *from, unsigned long n)
4007 {
4008 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4009 if (ret == 0)
4010 return 0;
4011 }
4012 +
4013 + if (!__builtin_constant_p(n))
4014 + check_object_size(to, n, false);
4015 +
4016 return __copy_tofrom_user((__force void __user *)to, from, n);
4017 }
4018
4019 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4020 if (ret == 0)
4021 return 0;
4022 }
4023 +
4024 + if (!__builtin_constant_p(n))
4025 + check_object_size(from, n, true);
4026 +
4027 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4028 }
4029
4030 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4031 return __copy_to_user_inatomic(to, from, size);
4032 }
4033
4034 +#ifndef __powerpc64__
4035 +
4036 +static inline unsigned long __must_check copy_from_user(void *to,
4037 + const void __user *from, unsigned long n)
4038 +{
4039 + unsigned long over;
4040 +
4041 + if ((long)n < 0)
4042 + return n;
4043 +
4044 + if (access_ok(VERIFY_READ, from, n)) {
4045 + if (!__builtin_constant_p(n))
4046 + check_object_size(to, n, false);
4047 + return __copy_tofrom_user((__force void __user *)to, from, n);
4048 + }
4049 + if ((unsigned long)from < TASK_SIZE) {
4050 + over = (unsigned long)from + n - TASK_SIZE;
4051 + if (!__builtin_constant_p(n - over))
4052 + check_object_size(to, n - over, false);
4053 + return __copy_tofrom_user((__force void __user *)to, from,
4054 + n - over) + over;
4055 + }
4056 + return n;
4057 +}
4058 +
4059 +static inline unsigned long __must_check copy_to_user(void __user *to,
4060 + const void *from, unsigned long n)
4061 +{
4062 + unsigned long over;
4063 +
4064 + if ((long)n < 0)
4065 + return n;
4066 +
4067 + if (access_ok(VERIFY_WRITE, to, n)) {
4068 + if (!__builtin_constant_p(n))
4069 + check_object_size(from, n, true);
4070 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4071 + }
4072 + if ((unsigned long)to < TASK_SIZE) {
4073 + over = (unsigned long)to + n - TASK_SIZE;
4074 + if (!__builtin_constant_p(n))
4075 + check_object_size(from, n - over, true);
4076 + return __copy_tofrom_user(to, (__force void __user *)from,
4077 + n - over) + over;
4078 + }
4079 + return n;
4080 +}
4081 +
4082 +#else /* __powerpc64__ */
4083 +
4084 +#define __copy_in_user(to, from, size) \
4085 + __copy_tofrom_user((to), (from), (size))
4086 +
4087 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4088 +{
4089 + if ((long)n < 0 || n > INT_MAX)
4090 + return n;
4091 +
4092 + if (!__builtin_constant_p(n))
4093 + check_object_size(to, n, false);
4094 +
4095 + if (likely(access_ok(VERIFY_READ, from, n)))
4096 + n = __copy_from_user(to, from, n);
4097 + else
4098 + memset(to, 0, n);
4099 + return n;
4100 +}
4101 +
4102 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4103 +{
4104 + if ((long)n < 0 || n > INT_MAX)
4105 + return n;
4106 +
4107 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4108 + if (!__builtin_constant_p(n))
4109 + check_object_size(from, n, true);
4110 + n = __copy_to_user(to, from, n);
4111 + }
4112 + return n;
4113 +}
4114 +
4115 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4116 + unsigned long n);
4117 +
4118 +#endif /* __powerpc64__ */
4119 +
4120 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4121
4122 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4123 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4124 index 98be7f0..8ef62de 100644
4125 --- a/arch/powerpc/kernel/exceptions-64e.S
4126 +++ b/arch/powerpc/kernel/exceptions-64e.S
4127 @@ -661,6 +661,7 @@ storage_fault_common:
4128 std r14,_DAR(r1)
4129 std r15,_DSISR(r1)
4130 addi r3,r1,STACK_FRAME_OVERHEAD
4131 + bl .save_nvgprs
4132 mr r4,r14
4133 mr r5,r15
4134 ld r14,PACA_EXGEN+EX_R14(r13)
4135 @@ -669,8 +670,7 @@ storage_fault_common:
4136 cmpdi r3,0
4137 bne- 1f
4138 b .ret_from_except_lite
4139 -1: bl .save_nvgprs
4140 - mr r5,r3
4141 +1: mr r5,r3
4142 addi r3,r1,STACK_FRAME_OVERHEAD
4143 ld r4,_DAR(r1)
4144 bl .bad_page_fault
4145 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4146 index 39aa97d..dc916ee 100644
4147 --- a/arch/powerpc/kernel/exceptions-64s.S
4148 +++ b/arch/powerpc/kernel/exceptions-64s.S
4149 @@ -890,10 +890,10 @@ handle_page_fault:
4150 11: ld r4,_DAR(r1)
4151 ld r5,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 bl .do_page_fault
4155 cmpdi r3,0
4156 beq+ 12f
4157 - bl .save_nvgprs
4158 mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 lwz r4,_DAR(r1)
4161 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4162 index 2e3200c..72095ce 100644
4163 --- a/arch/powerpc/kernel/module_32.c
4164 +++ b/arch/powerpc/kernel/module_32.c
4165 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4166 me->arch.core_plt_section = i;
4167 }
4168 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4169 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4170 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4171 return -ENOEXEC;
4172 }
4173
4174 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4175
4176 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4177 /* Init, or core PLT? */
4178 - if (location >= mod->module_core
4179 - && location < mod->module_core + mod->core_size)
4180 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4181 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4182 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4183 - else
4184 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4185 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4186 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4187 + else {
4188 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4189 + return ~0UL;
4190 + }
4191
4192 /* Find this entry, or if that fails, the next avail. entry */
4193 while (entry->jump[0]) {
4194 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4195 index 1a1f2dd..f4d1bb4 100644
4196 --- a/arch/powerpc/kernel/process.c
4197 +++ b/arch/powerpc/kernel/process.c
4198 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4199 * Lookup NIP late so we have the best change of getting the
4200 * above info out without failing
4201 */
4202 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4203 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4204 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4205 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4206 #endif
4207 show_stack(current, (unsigned long *) regs->gpr[1]);
4208 if (!user_mode(regs))
4209 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4210 newsp = stack[0];
4211 ip = stack[STACK_FRAME_LR_SAVE];
4212 if (!firstframe || ip != lr) {
4213 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4214 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4215 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4216 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4217 - printk(" (%pS)",
4218 + printk(" (%pA)",
4219 (void *)current->ret_stack[curr_frame].ret);
4220 curr_frame--;
4221 }
4222 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4223 struct pt_regs *regs = (struct pt_regs *)
4224 (sp + STACK_FRAME_OVERHEAD);
4225 lr = regs->link;
4226 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4227 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4228 regs->trap, (void *)regs->nip, (void *)lr);
4229 firstframe = 1;
4230 }
4231 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4232 mtspr(SPRN_CTRLT, ctrl);
4233 }
4234 #endif /* CONFIG_PPC64 */
4235 -
4236 -unsigned long arch_align_stack(unsigned long sp)
4237 -{
4238 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4239 - sp -= get_random_int() & ~PAGE_MASK;
4240 - return sp & ~0xf;
4241 -}
4242 -
4243 -static inline unsigned long brk_rnd(void)
4244 -{
4245 - unsigned long rnd = 0;
4246 -
4247 - /* 8MB for 32bit, 1GB for 64bit */
4248 - if (is_32bit_task())
4249 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4250 - else
4251 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4252 -
4253 - return rnd << PAGE_SHIFT;
4254 -}
4255 -
4256 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4257 -{
4258 - unsigned long base = mm->brk;
4259 - unsigned long ret;
4260 -
4261 -#ifdef CONFIG_PPC_STD_MMU_64
4262 - /*
4263 - * If we are using 1TB segments and we are allowed to randomise
4264 - * the heap, we can put it above 1TB so it is backed by a 1TB
4265 - * segment. Otherwise the heap will be in the bottom 1TB
4266 - * which always uses 256MB segments and this may result in a
4267 - * performance penalty.
4268 - */
4269 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4270 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4271 -#endif
4272 -
4273 - ret = PAGE_ALIGN(base + brk_rnd());
4274 -
4275 - if (ret < mm->brk)
4276 - return mm->brk;
4277 -
4278 - return ret;
4279 -}
4280 -
4281 -unsigned long randomize_et_dyn(unsigned long base)
4282 -{
4283 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4284 -
4285 - if (ret < base)
4286 - return base;
4287 -
4288 - return ret;
4289 -}
4290 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4291 index c10fc28..c4ef063 100644
4292 --- a/arch/powerpc/kernel/ptrace.c
4293 +++ b/arch/powerpc/kernel/ptrace.c
4294 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4295 return ret;
4296 }
4297
4298 +#ifdef CONFIG_GRKERNSEC_SETXID
4299 +extern void gr_delayed_cred_worker(void);
4300 +#endif
4301 +
4302 /*
4303 * We must return the syscall number to actually look up in the table.
4304 * This can be -1L to skip running any syscall at all.
4305 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4306
4307 secure_computing_strict(regs->gpr[0]);
4308
4309 +#ifdef CONFIG_GRKERNSEC_SETXID
4310 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4311 + gr_delayed_cred_worker();
4312 +#endif
4313 +
4314 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4315 tracehook_report_syscall_entry(regs))
4316 /*
4317 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4318 {
4319 int step;
4320
4321 +#ifdef CONFIG_GRKERNSEC_SETXID
4322 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4323 + gr_delayed_cred_worker();
4324 +#endif
4325 +
4326 audit_syscall_exit(regs);
4327
4328 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4329 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4330 index 8b4c049..dcd6ef3 100644
4331 --- a/arch/powerpc/kernel/signal_32.c
4332 +++ b/arch/powerpc/kernel/signal_32.c
4333 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4334 /* Save user registers on the stack */
4335 frame = &rt_sf->uc.uc_mcontext;
4336 addr = frame;
4337 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4338 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4339 if (save_user_regs(regs, frame, 0, 1))
4340 goto badframe;
4341 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4342 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4343 index d183f87..1867f1a 100644
4344 --- a/arch/powerpc/kernel/signal_64.c
4345 +++ b/arch/powerpc/kernel/signal_64.c
4346 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4347 current->thread.fpscr.val = 0;
4348
4349 /* Set up to return from userspace. */
4350 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4351 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4352 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4353 } else {
4354 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4355 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4356 index ae0843f..f16372c 100644
4357 --- a/arch/powerpc/kernel/traps.c
4358 +++ b/arch/powerpc/kernel/traps.c
4359 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4360 return flags;
4361 }
4362
4363 +extern void gr_handle_kernel_exploit(void);
4364 +
4365 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4366 int signr)
4367 {
4368 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4369 panic("Fatal exception in interrupt");
4370 if (panic_on_oops)
4371 panic("Fatal exception");
4372 +
4373 + gr_handle_kernel_exploit();
4374 +
4375 do_exit(signr);
4376 }
4377
4378 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4379 index b67db22..38825d2 100644
4380 --- a/arch/powerpc/kernel/vdso.c
4381 +++ b/arch/powerpc/kernel/vdso.c
4382 @@ -34,6 +34,7 @@
4383 #include <asm/firmware.h>
4384 #include <asm/vdso.h>
4385 #include <asm/vdso_datapage.h>
4386 +#include <asm/mman.h>
4387
4388 #include "setup.h"
4389
4390 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4391 vdso_base = VDSO32_MBASE;
4392 #endif
4393
4394 - current->mm->context.vdso_base = 0;
4395 + current->mm->context.vdso_base = ~0UL;
4396
4397 /* vDSO has a problem and was disabled, just don't "enable" it for the
4398 * process
4399 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4400 vdso_base = get_unmapped_area(NULL, vdso_base,
4401 (vdso_pages << PAGE_SHIFT) +
4402 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4403 - 0, 0);
4404 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4405 if (IS_ERR_VALUE(vdso_base)) {
4406 rc = vdso_base;
4407 goto fail_mmapsem;
4408 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4409 index 5eea6f3..5d10396 100644
4410 --- a/arch/powerpc/lib/usercopy_64.c
4411 +++ b/arch/powerpc/lib/usercopy_64.c
4412 @@ -9,22 +9,6 @@
4413 #include <linux/module.h>
4414 #include <asm/uaccess.h>
4415
4416 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4417 -{
4418 - if (likely(access_ok(VERIFY_READ, from, n)))
4419 - n = __copy_from_user(to, from, n);
4420 - else
4421 - memset(to, 0, n);
4422 - return n;
4423 -}
4424 -
4425 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4426 -{
4427 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4428 - n = __copy_to_user(to, from, n);
4429 - return n;
4430 -}
4431 -
4432 unsigned long copy_in_user(void __user *to, const void __user *from,
4433 unsigned long n)
4434 {
4435 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4436 return n;
4437 }
4438
4439 -EXPORT_SYMBOL(copy_from_user);
4440 -EXPORT_SYMBOL(copy_to_user);
4441 EXPORT_SYMBOL(copy_in_user);
4442
4443 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4444 index 08ffcf5..a0ab912 100644
4445 --- a/arch/powerpc/mm/fault.c
4446 +++ b/arch/powerpc/mm/fault.c
4447 @@ -32,6 +32,10 @@
4448 #include <linux/perf_event.h>
4449 #include <linux/magic.h>
4450 #include <linux/ratelimit.h>
4451 +#include <linux/slab.h>
4452 +#include <linux/pagemap.h>
4453 +#include <linux/compiler.h>
4454 +#include <linux/unistd.h>
4455
4456 #include <asm/firmware.h>
4457 #include <asm/page.h>
4458 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4459 }
4460 #endif
4461
4462 +#ifdef CONFIG_PAX_PAGEEXEC
4463 +/*
4464 + * PaX: decide what to do with offenders (regs->nip = fault address)
4465 + *
4466 + * returns 1 when task should be killed
4467 + */
4468 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4469 +{
4470 + return 1;
4471 +}
4472 +
4473 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4474 +{
4475 + unsigned long i;
4476 +
4477 + printk(KERN_ERR "PAX: bytes at PC: ");
4478 + for (i = 0; i < 5; i++) {
4479 + unsigned int c;
4480 + if (get_user(c, (unsigned int __user *)pc+i))
4481 + printk(KERN_CONT "???????? ");
4482 + else
4483 + printk(KERN_CONT "%08x ", c);
4484 + }
4485 + printk("\n");
4486 +}
4487 +#endif
4488 +
4489 /*
4490 * Check whether the instruction at regs->nip is a store using
4491 * an update addressing form which will update r1.
4492 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4493 * indicate errors in DSISR but can validly be set in SRR1.
4494 */
4495 if (trap == 0x400)
4496 - error_code &= 0x48200000;
4497 + error_code &= 0x58200000;
4498 else
4499 is_write = error_code & DSISR_ISSTORE;
4500 #else
4501 @@ -366,7 +397,7 @@ good_area:
4502 * "undefined". Of those that can be set, this is the only
4503 * one which seems bad.
4504 */
4505 - if (error_code & 0x10000000)
4506 + if (error_code & DSISR_GUARDED)
4507 /* Guarded storage error. */
4508 goto bad_area;
4509 #endif /* CONFIG_8xx */
4510 @@ -381,7 +412,7 @@ good_area:
4511 * processors use the same I/D cache coherency mechanism
4512 * as embedded.
4513 */
4514 - if (error_code & DSISR_PROTFAULT)
4515 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4516 goto bad_area;
4517 #endif /* CONFIG_PPC_STD_MMU */
4518
4519 @@ -463,6 +494,23 @@ bad_area:
4520 bad_area_nosemaphore:
4521 /* User mode accesses cause a SIGSEGV */
4522 if (user_mode(regs)) {
4523 +
4524 +#ifdef CONFIG_PAX_PAGEEXEC
4525 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4526 +#ifdef CONFIG_PPC_STD_MMU
4527 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4528 +#else
4529 + if (is_exec && regs->nip == address) {
4530 +#endif
4531 + switch (pax_handle_fetch_fault(regs)) {
4532 + }
4533 +
4534 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4535 + do_group_exit(SIGKILL);
4536 + }
4537 + }
4538 +#endif
4539 +
4540 _exception(SIGSEGV, regs, code, address);
4541 return 0;
4542 }
4543 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4544 index 67a42ed..1c7210c 100644
4545 --- a/arch/powerpc/mm/mmap_64.c
4546 +++ b/arch/powerpc/mm/mmap_64.c
4547 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4548 */
4549 if (mmap_is_legacy()) {
4550 mm->mmap_base = TASK_UNMAPPED_BASE;
4551 +
4552 +#ifdef CONFIG_PAX_RANDMMAP
4553 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4554 + mm->mmap_base += mm->delta_mmap;
4555 +#endif
4556 +
4557 mm->get_unmapped_area = arch_get_unmapped_area;
4558 mm->unmap_area = arch_unmap_area;
4559 } else {
4560 mm->mmap_base = mmap_base();
4561 +
4562 +#ifdef CONFIG_PAX_RANDMMAP
4563 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4564 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4565 +#endif
4566 +
4567 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4568 mm->unmap_area = arch_unmap_area_topdown;
4569 }
4570 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4571 index 73709f7..6b90313 100644
4572 --- a/arch/powerpc/mm/slice.c
4573 +++ b/arch/powerpc/mm/slice.c
4574 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4575 if ((mm->task_size - len) < addr)
4576 return 0;
4577 vma = find_vma(mm, addr);
4578 - return (!vma || (addr + len) <= vma->vm_start);
4579 + return check_heap_stack_gap(vma, addr, len);
4580 }
4581
4582 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4583 @@ -256,7 +256,7 @@ full_search:
4584 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4585 continue;
4586 }
4587 - if (!vma || addr + len <= vma->vm_start) {
4588 + if (check_heap_stack_gap(vma, addr, len)) {
4589 /*
4590 * Remember the place where we stopped the search:
4591 */
4592 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4593 }
4594 }
4595
4596 - addr = mm->mmap_base;
4597 - while (addr > len) {
4598 + if (mm->mmap_base < len)
4599 + addr = -ENOMEM;
4600 + else
4601 + addr = mm->mmap_base - len;
4602 +
4603 + while (!IS_ERR_VALUE(addr)) {
4604 /* Go down by chunk size */
4605 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4606 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4607
4608 /* Check for hit with different page size */
4609 mask = slice_range_to_mask(addr, len);
4610 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4611 * return with success:
4612 */
4613 vma = find_vma(mm, addr);
4614 - if (!vma || (addr + len) <= vma->vm_start) {
4615 + if (check_heap_stack_gap(vma, addr, len)) {
4616 /* remember the address as a hint for next time */
4617 if (use_cache)
4618 mm->free_area_cache = addr;
4619 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4620 mm->cached_hole_size = vma->vm_start - addr;
4621
4622 /* try just below the current vma->vm_start */
4623 - addr = vma->vm_start;
4624 + addr = skip_heap_stack_gap(vma, len);
4625 }
4626
4627 /*
4628 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4629 if (fixed && addr > (mm->task_size - len))
4630 return -EINVAL;
4631
4632 +#ifdef CONFIG_PAX_RANDMMAP
4633 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4634 + addr = 0;
4635 +#endif
4636 +
4637 /* If hint, make sure it matches our alignment restrictions */
4638 if (!fixed && addr) {
4639 addr = _ALIGN_UP(addr, 1ul << pshift);
4640 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4641 index c797832..ce575c8 100644
4642 --- a/arch/s390/include/asm/atomic.h
4643 +++ b/arch/s390/include/asm/atomic.h
4644 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4645 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4646 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4647
4648 +#define atomic64_read_unchecked(v) atomic64_read(v)
4649 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4650 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4651 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4652 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4653 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4654 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4655 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4656 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4657 +
4658 #define smp_mb__before_atomic_dec() smp_mb()
4659 #define smp_mb__after_atomic_dec() smp_mb()
4660 #define smp_mb__before_atomic_inc() smp_mb()
4661 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4662 index 4d7ccac..d03d0ad 100644
4663 --- a/arch/s390/include/asm/cache.h
4664 +++ b/arch/s390/include/asm/cache.h
4665 @@ -9,8 +9,10 @@
4666 #ifndef __ARCH_S390_CACHE_H
4667 #define __ARCH_S390_CACHE_H
4668
4669 -#define L1_CACHE_BYTES 256
4670 +#include <linux/const.h>
4671 +
4672 #define L1_CACHE_SHIFT 8
4673 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4674 #define NET_SKB_PAD 32
4675
4676 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4677 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4678 index 9b94a16..63d4034 100644
4679 --- a/arch/s390/include/asm/elf.h
4680 +++ b/arch/s390/include/asm/elf.h
4681 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4682 the loader. We need to make sure that it is out of the way of the program
4683 that it will "exec", and that there is sufficient room for the brk. */
4684
4685 -extern unsigned long randomize_et_dyn(unsigned long base);
4686 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4687 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4688 +
4689 +#ifdef CONFIG_PAX_ASLR
4690 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4691 +
4692 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4693 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4694 +#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. */
4698 @@ -209,7 +215,4 @@ struct linux_binprm;
4699 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4700 int arch_setup_additional_pages(struct linux_binprm *, int);
4701
4702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4703 -#define arch_randomize_brk arch_randomize_brk
4704 -
4705 #endif
4706 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4707 index c4a93d6..4d2a9b4 100644
4708 --- a/arch/s390/include/asm/exec.h
4709 +++ b/arch/s390/include/asm/exec.h
4710 @@ -7,6 +7,6 @@
4711 #ifndef __ASM_EXEC_H
4712 #define __ASM_EXEC_H
4713
4714 -extern unsigned long arch_align_stack(unsigned long sp);
4715 +#define arch_align_stack(x) ((x) & ~0xfUL)
4716
4717 #endif /* __ASM_EXEC_H */
4718 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4719 index a8ab18b..75ddbf0 100644
4720 --- a/arch/s390/include/asm/uaccess.h
4721 +++ b/arch/s390/include/asm/uaccess.h
4722 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4723 copy_to_user(void __user *to, const void *from, unsigned long n)
4724 {
4725 might_fault();
4726 +
4727 + if ((long)n < 0)
4728 + return n;
4729 +
4730 if (access_ok(VERIFY_WRITE, to, n))
4731 n = __copy_to_user(to, from, n);
4732 return n;
4733 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4734 static inline unsigned long __must_check
4735 __copy_from_user(void *to, const void __user *from, unsigned long n)
4736 {
4737 + if ((long)n < 0)
4738 + return n;
4739 +
4740 if (__builtin_constant_p(n) && (n <= 256))
4741 return uaccess.copy_from_user_small(n, from, to);
4742 else
4743 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4744 static inline unsigned long __must_check
4745 copy_from_user(void *to, const void __user *from, unsigned long n)
4746 {
4747 - unsigned int sz = __compiletime_object_size(to);
4748 + size_t sz = __compiletime_object_size(to);
4749
4750 might_fault();
4751 - if (unlikely(sz != -1 && sz < n)) {
4752 +
4753 + if ((long)n < 0)
4754 + return n;
4755 +
4756 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4757 copy_from_user_overflow();
4758 return n;
4759 }
4760 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4761 index 46412b1..e32874f 100644
4762 --- a/arch/s390/kernel/module.c
4763 +++ b/arch/s390/kernel/module.c
4764 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4765
4766 /* Increase core size by size of got & plt and set start
4767 offsets for got and plt. */
4768 - me->core_size = ALIGN(me->core_size, 4);
4769 - me->arch.got_offset = me->core_size;
4770 - me->core_size += me->arch.got_size;
4771 - me->arch.plt_offset = me->core_size;
4772 - me->core_size += me->arch.plt_size;
4773 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4774 + me->arch.got_offset = me->core_size_rw;
4775 + me->core_size_rw += me->arch.got_size;
4776 + me->arch.plt_offset = me->core_size_rx;
4777 + me->core_size_rx += me->arch.plt_size;
4778 return 0;
4779 }
4780
4781 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 if (info->got_initialized == 0) {
4783 Elf_Addr *gotent;
4784
4785 - gotent = me->module_core + me->arch.got_offset +
4786 + gotent = me->module_core_rw + me->arch.got_offset +
4787 info->got_offset;
4788 *gotent = val;
4789 info->got_initialized = 1;
4790 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 else if (r_type == R_390_GOTENT ||
4792 r_type == R_390_GOTPLTENT)
4793 *(unsigned int *) loc =
4794 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4795 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4796 else if (r_type == R_390_GOT64 ||
4797 r_type == R_390_GOTPLT64)
4798 *(unsigned long *) loc = val;
4799 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4801 if (info->plt_initialized == 0) {
4802 unsigned int *ip;
4803 - ip = me->module_core + me->arch.plt_offset +
4804 + ip = me->module_core_rx + me->arch.plt_offset +
4805 info->plt_offset;
4806 #ifndef CONFIG_64BIT
4807 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4808 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 val - loc + 0xffffUL < 0x1ffffeUL) ||
4810 (r_type == R_390_PLT32DBL &&
4811 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4812 - val = (Elf_Addr) me->module_core +
4813 + val = (Elf_Addr) me->module_core_rx +
4814 me->arch.plt_offset +
4815 info->plt_offset;
4816 val += rela->r_addend - loc;
4817 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4818 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4819 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4820 val = val + rela->r_addend -
4821 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4822 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4823 if (r_type == R_390_GOTOFF16)
4824 *(unsigned short *) loc = val;
4825 else if (r_type == R_390_GOTOFF32)
4826 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4827 break;
4828 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4829 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4830 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4831 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4832 rela->r_addend - loc;
4833 if (r_type == R_390_GOTPC)
4834 *(unsigned int *) loc = val;
4835 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4836 index 7331753..dd71de4 100644
4837 --- a/arch/s390/kernel/process.c
4838 +++ b/arch/s390/kernel/process.c
4839 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4840 }
4841 return 0;
4842 }
4843 -
4844 -unsigned long arch_align_stack(unsigned long sp)
4845 -{
4846 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4847 - sp -= get_random_int() & ~PAGE_MASK;
4848 - return sp & ~0xf;
4849 -}
4850 -
4851 -static inline unsigned long brk_rnd(void)
4852 -{
4853 - /* 8MB for 32bit, 1GB for 64bit */
4854 - if (is_32bit_task())
4855 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4856 - else
4857 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4858 -}
4859 -
4860 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4861 -{
4862 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4863 -
4864 - if (ret < mm->brk)
4865 - return mm->brk;
4866 - return ret;
4867 -}
4868 -
4869 -unsigned long randomize_et_dyn(unsigned long base)
4870 -{
4871 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4872 -
4873 - if (!(current->flags & PF_RANDOMIZE))
4874 - return base;
4875 - if (ret < base)
4876 - return base;
4877 - return ret;
4878 -}
4879 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4880 index c59a5ef..3fae59c 100644
4881 --- a/arch/s390/mm/mmap.c
4882 +++ b/arch/s390/mm/mmap.c
4883 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4884 */
4885 if (mmap_is_legacy()) {
4886 mm->mmap_base = TASK_UNMAPPED_BASE;
4887 +
4888 +#ifdef CONFIG_PAX_RANDMMAP
4889 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4890 + mm->mmap_base += mm->delta_mmap;
4891 +#endif
4892 +
4893 mm->get_unmapped_area = arch_get_unmapped_area;
4894 mm->unmap_area = arch_unmap_area;
4895 } else {
4896 mm->mmap_base = mmap_base();
4897 +
4898 +#ifdef CONFIG_PAX_RANDMMAP
4899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4901 +#endif
4902 +
4903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4904 mm->unmap_area = arch_unmap_area_topdown;
4905 }
4906 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4907 */
4908 if (mmap_is_legacy()) {
4909 mm->mmap_base = TASK_UNMAPPED_BASE;
4910 +
4911 +#ifdef CONFIG_PAX_RANDMMAP
4912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4913 + mm->mmap_base += mm->delta_mmap;
4914 +#endif
4915 +
4916 mm->get_unmapped_area = s390_get_unmapped_area;
4917 mm->unmap_area = arch_unmap_area;
4918 } else {
4919 mm->mmap_base = mmap_base();
4920 +
4921 +#ifdef CONFIG_PAX_RANDMMAP
4922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4923 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4924 +#endif
4925 +
4926 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4927 mm->unmap_area = arch_unmap_area_topdown;
4928 }
4929 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4930 index ae3d59f..f65f075 100644
4931 --- a/arch/score/include/asm/cache.h
4932 +++ b/arch/score/include/asm/cache.h
4933 @@ -1,7 +1,9 @@
4934 #ifndef _ASM_SCORE_CACHE_H
4935 #define _ASM_SCORE_CACHE_H
4936
4937 +#include <linux/const.h>
4938 +
4939 #define L1_CACHE_SHIFT 4
4940 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4941 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4942
4943 #endif /* _ASM_SCORE_CACHE_H */
4944 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4945 index f9f3cd5..58ff438 100644
4946 --- a/arch/score/include/asm/exec.h
4947 +++ b/arch/score/include/asm/exec.h
4948 @@ -1,6 +1,6 @@
4949 #ifndef _ASM_SCORE_EXEC_H
4950 #define _ASM_SCORE_EXEC_H
4951
4952 -extern unsigned long arch_align_stack(unsigned long sp);
4953 +#define arch_align_stack(x) (x)
4954
4955 #endif /* _ASM_SCORE_EXEC_H */
4956 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4957 index 637970c..0b6556b 100644
4958 --- a/arch/score/kernel/process.c
4959 +++ b/arch/score/kernel/process.c
4960 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4961
4962 return task_pt_regs(task)->cp0_epc;
4963 }
4964 -
4965 -unsigned long arch_align_stack(unsigned long sp)
4966 -{
4967 - return sp;
4968 -}
4969 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4970 index ef9e555..331bd29 100644
4971 --- a/arch/sh/include/asm/cache.h
4972 +++ b/arch/sh/include/asm/cache.h
4973 @@ -9,10 +9,11 @@
4974 #define __ASM_SH_CACHE_H
4975 #ifdef __KERNEL__
4976
4977 +#include <linux/const.h>
4978 #include <linux/init.h>
4979 #include <cpu/cache.h>
4980
4981 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4985
4986 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4987 index afeb710..d1d1289 100644
4988 --- a/arch/sh/mm/mmap.c
4989 +++ b/arch/sh/mm/mmap.c
4990 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4991 addr = PAGE_ALIGN(addr);
4992
4993 vma = find_vma(mm, addr);
4994 - if (TASK_SIZE - len >= addr &&
4995 - (!vma || addr + len <= vma->vm_start))
4996 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4997 return addr;
4998 }
4999
5000 @@ -106,7 +105,7 @@ full_search:
5001 }
5002 return -ENOMEM;
5003 }
5004 - if (likely(!vma || addr + len <= vma->vm_start)) {
5005 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5006 /*
5007 * Remember the place where we stopped the search:
5008 */
5009 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5010 addr = PAGE_ALIGN(addr);
5011
5012 vma = find_vma(mm, addr);
5013 - if (TASK_SIZE - len >= addr &&
5014 - (!vma || addr + len <= vma->vm_start))
5015 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5016 return addr;
5017 }
5018
5019 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5020 /* make sure it can fit in the remaining address space */
5021 if (likely(addr > len)) {
5022 vma = find_vma(mm, addr-len);
5023 - if (!vma || addr <= vma->vm_start) {
5024 + if (check_heap_stack_gap(vma, addr - len, len)) {
5025 /* remember the address as a hint for next time */
5026 return (mm->free_area_cache = addr-len);
5027 }
5028 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5029 if (unlikely(mm->mmap_base < len))
5030 goto bottomup;
5031
5032 - addr = mm->mmap_base-len;
5033 - if (do_colour_align)
5034 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035 + addr = mm->mmap_base - len;
5036
5037 do {
5038 + if (do_colour_align)
5039 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5040 /*
5041 * Lookup failure means no vma is above this address,
5042 * else if new region fits below vma->vm_start,
5043 * return with success:
5044 */
5045 vma = find_vma(mm, addr);
5046 - if (likely(!vma || addr+len <= vma->vm_start)) {
5047 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5048 /* remember the address as a hint for next time */
5049 return (mm->free_area_cache = addr);
5050 }
5051 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5052 mm->cached_hole_size = vma->vm_start - addr;
5053
5054 /* try just below the current vma->vm_start */
5055 - addr = vma->vm_start-len;
5056 - if (do_colour_align)
5057 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5058 - } while (likely(len < vma->vm_start));
5059 + addr = skip_heap_stack_gap(vma, len);
5060 + } while (!IS_ERR_VALUE(addr));
5061
5062 bottomup:
5063 /*
5064 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5065 index ce35a1c..2e7b8f9 100644
5066 --- a/arch/sparc/include/asm/atomic_64.h
5067 +++ b/arch/sparc/include/asm/atomic_64.h
5068 @@ -14,18 +14,40 @@
5069 #define ATOMIC64_INIT(i) { (i) }
5070
5071 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5072 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5073 +{
5074 + return v->counter;
5075 +}
5076 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5077 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5078 +{
5079 + return v->counter;
5080 +}
5081
5082 #define atomic_set(v, i) (((v)->counter) = i)
5083 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5084 +{
5085 + v->counter = i;
5086 +}
5087 #define atomic64_set(v, i) (((v)->counter) = i)
5088 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5089 +{
5090 + v->counter = i;
5091 +}
5092
5093 extern void atomic_add(int, atomic_t *);
5094 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_add(long, atomic64_t *);
5096 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5097 extern void atomic_sub(int, atomic_t *);
5098 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5099 extern void atomic64_sub(long, atomic64_t *);
5100 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5101
5102 extern int atomic_add_ret(int, atomic_t *);
5103 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5104 extern long atomic64_add_ret(long, atomic64_t *);
5105 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5106 extern int atomic_sub_ret(int, atomic_t *);
5107 extern long atomic64_sub_ret(long, atomic64_t *);
5108
5109 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5110 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5111
5112 #define atomic_inc_return(v) atomic_add_ret(1, v)
5113 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5114 +{
5115 + return atomic_add_ret_unchecked(1, v);
5116 +}
5117 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5118 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5119 +{
5120 + return atomic64_add_ret_unchecked(1, v);
5121 +}
5122
5123 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5124 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5125
5126 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5127 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5128 +{
5129 + return atomic_add_ret_unchecked(i, v);
5130 +}
5131 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5132 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5133 +{
5134 + return atomic64_add_ret_unchecked(i, v);
5135 +}
5136
5137 /*
5138 * atomic_inc_and_test - increment and test
5139 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5140 * other cases.
5141 */
5142 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5143 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5144 +{
5145 + return atomic_inc_return_unchecked(v) == 0;
5146 +}
5147 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5148
5149 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5150 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5152
5153 #define atomic_inc(v) atomic_add(1, v)
5154 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5155 +{
5156 + atomic_add_unchecked(1, v);
5157 +}
5158 #define atomic64_inc(v) atomic64_add(1, v)
5159 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5160 +{
5161 + atomic64_add_unchecked(1, v);
5162 +}
5163
5164 #define atomic_dec(v) atomic_sub(1, v)
5165 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + atomic_sub_unchecked(1, v);
5168 +}
5169 #define atomic64_dec(v) atomic64_sub(1, v)
5170 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5171 +{
5172 + atomic64_sub_unchecked(1, v);
5173 +}
5174
5175 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5176 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5177
5178 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5180 +{
5181 + return cmpxchg(&v->counter, old, new);
5182 +}
5183 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5184 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5185 +{
5186 + return xchg(&v->counter, new);
5187 +}
5188
5189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5190 {
5191 - int c, old;
5192 + int c, old, new;
5193 c = atomic_read(v);
5194 for (;;) {
5195 - if (unlikely(c == (u)))
5196 + if (unlikely(c == u))
5197 break;
5198 - old = atomic_cmpxchg((v), c, c + (a));
5199 +
5200 + asm volatile("addcc %2, %0, %0\n"
5201 +
5202 +#ifdef CONFIG_PAX_REFCOUNT
5203 + "tvs %%icc, 6\n"
5204 +#endif
5205 +
5206 + : "=r" (new)
5207 + : "0" (c), "ir" (a)
5208 + : "cc");
5209 +
5210 + old = atomic_cmpxchg(v, c, new);
5211 if (likely(old == c))
5212 break;
5213 c = old;
5214 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5215 #define atomic64_cmpxchg(v, o, n) \
5216 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5217 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5218 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5219 +{
5220 + return xchg(&v->counter, new);
5221 +}
5222
5223 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5224 {
5225 - long c, old;
5226 + long c, old, new;
5227 c = atomic64_read(v);
5228 for (;;) {
5229 - if (unlikely(c == (u)))
5230 + if (unlikely(c == u))
5231 break;
5232 - old = atomic64_cmpxchg((v), c, c + (a));
5233 +
5234 + asm volatile("addcc %2, %0, %0\n"
5235 +
5236 +#ifdef CONFIG_PAX_REFCOUNT
5237 + "tvs %%xcc, 6\n"
5238 +#endif
5239 +
5240 + : "=r" (new)
5241 + : "0" (c), "ir" (a)
5242 + : "cc");
5243 +
5244 + old = atomic64_cmpxchg(v, c, new);
5245 if (likely(old == c))
5246 break;
5247 c = old;
5248 }
5249 - return c != (u);
5250 + return c != u;
5251 }
5252
5253 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5254 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5255 index 5bb6991..5c2132e 100644
5256 --- a/arch/sparc/include/asm/cache.h
5257 +++ b/arch/sparc/include/asm/cache.h
5258 @@ -7,10 +7,12 @@
5259 #ifndef _SPARC_CACHE_H
5260 #define _SPARC_CACHE_H
5261
5262 +#include <linux/const.h>
5263 +
5264 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5265
5266 #define L1_CACHE_SHIFT 5
5267 -#define L1_CACHE_BYTES 32
5268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5269
5270 #ifdef CONFIG_SPARC32
5271 #define SMP_CACHE_BYTES_SHIFT 5
5272 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5273 index 2d4d755..81b6662 100644
5274 --- a/arch/sparc/include/asm/elf_32.h
5275 +++ b/arch/sparc/include/asm/elf_32.h
5276 @@ -114,6 +114,13 @@ typedef struct {
5277
5278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5279
5280 +#ifdef CONFIG_PAX_ASLR
5281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5282 +
5283 +#define PAX_DELTA_MMAP_LEN 16
5284 +#define PAX_DELTA_STACK_LEN 16
5285 +#endif
5286 +
5287 /* This yields a mask that user programs can use to figure out what
5288 instruction set this cpu supports. This can NOT be done in userspace
5289 on Sparc. */
5290 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5291 index 7df8b7f..4946269 100644
5292 --- a/arch/sparc/include/asm/elf_64.h
5293 +++ b/arch/sparc/include/asm/elf_64.h
5294 @@ -180,6 +180,13 @@ typedef struct {
5295 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5296 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5297
5298 +#ifdef CONFIG_PAX_ASLR
5299 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5300 +
5301 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5302 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5303 +#endif
5304 +
5305 extern unsigned long sparc64_elf_hwcap;
5306 #define ELF_HWCAP sparc64_elf_hwcap
5307
5308 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5309 index 9b1c36d..209298b 100644
5310 --- a/arch/sparc/include/asm/pgalloc_32.h
5311 +++ b/arch/sparc/include/asm/pgalloc_32.h
5312 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5313 }
5314
5315 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5316 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5317
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5319 unsigned long address)
5320 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5321 index 40b2d7a..22a665b 100644
5322 --- a/arch/sparc/include/asm/pgalloc_64.h
5323 +++ b/arch/sparc/include/asm/pgalloc_64.h
5324 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5325 }
5326
5327 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5328 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5329
5330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5331 {
5332 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5333 index 6fc1348..390c50a 100644
5334 --- a/arch/sparc/include/asm/pgtable_32.h
5335 +++ b/arch/sparc/include/asm/pgtable_32.h
5336 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5337 #define PAGE_SHARED SRMMU_PAGE_SHARED
5338 #define PAGE_COPY SRMMU_PAGE_COPY
5339 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5340 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5341 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5342 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5343 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5344
5345 /* Top-level page directory - dummy used by init-mm.
5346 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5347
5348 /* xwr */
5349 #define __P000 PAGE_NONE
5350 -#define __P001 PAGE_READONLY
5351 -#define __P010 PAGE_COPY
5352 -#define __P011 PAGE_COPY
5353 +#define __P001 PAGE_READONLY_NOEXEC
5354 +#define __P010 PAGE_COPY_NOEXEC
5355 +#define __P011 PAGE_COPY_NOEXEC
5356 #define __P100 PAGE_READONLY
5357 #define __P101 PAGE_READONLY
5358 #define __P110 PAGE_COPY
5359 #define __P111 PAGE_COPY
5360
5361 #define __S000 PAGE_NONE
5362 -#define __S001 PAGE_READONLY
5363 -#define __S010 PAGE_SHARED
5364 -#define __S011 PAGE_SHARED
5365 +#define __S001 PAGE_READONLY_NOEXEC
5366 +#define __S010 PAGE_SHARED_NOEXEC
5367 +#define __S011 PAGE_SHARED_NOEXEC
5368 #define __S100 PAGE_READONLY
5369 #define __S101 PAGE_READONLY
5370 #define __S110 PAGE_SHARED
5371 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5372 index 79da178..c2eede8 100644
5373 --- a/arch/sparc/include/asm/pgtsrmmu.h
5374 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5375 @@ -115,6 +115,11 @@
5376 SRMMU_EXEC | SRMMU_REF)
5377 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5378 SRMMU_EXEC | SRMMU_REF)
5379 +
5380 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5381 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5382 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5383 +
5384 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5385 SRMMU_DIRTY | SRMMU_REF)
5386
5387 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5388 index 9689176..63c18ea 100644
5389 --- a/arch/sparc/include/asm/spinlock_64.h
5390 +++ b/arch/sparc/include/asm/spinlock_64.h
5391 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5392
5393 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5394
5395 -static void inline arch_read_lock(arch_rwlock_t *lock)
5396 +static inline void arch_read_lock(arch_rwlock_t *lock)
5397 {
5398 unsigned long tmp1, tmp2;
5399
5400 __asm__ __volatile__ (
5401 "1: ldsw [%2], %0\n"
5402 " brlz,pn %0, 2f\n"
5403 -"4: add %0, 1, %1\n"
5404 +"4: addcc %0, 1, %1\n"
5405 +
5406 +#ifdef CONFIG_PAX_REFCOUNT
5407 +" tvs %%icc, 6\n"
5408 +#endif
5409 +
5410 " cas [%2], %0, %1\n"
5411 " cmp %0, %1\n"
5412 " bne,pn %%icc, 1b\n"
5413 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5414 " .previous"
5415 : "=&r" (tmp1), "=&r" (tmp2)
5416 : "r" (lock)
5417 - : "memory");
5418 + : "memory", "cc");
5419 }
5420
5421 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5422 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5423 {
5424 int tmp1, tmp2;
5425
5426 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5427 "1: ldsw [%2], %0\n"
5428 " brlz,a,pn %0, 2f\n"
5429 " mov 0, %0\n"
5430 -" add %0, 1, %1\n"
5431 +" addcc %0, 1, %1\n"
5432 +
5433 +#ifdef CONFIG_PAX_REFCOUNT
5434 +" tvs %%icc, 6\n"
5435 +#endif
5436 +
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5441 return tmp1;
5442 }
5443
5444 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5445 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5446 {
5447 unsigned long tmp1, tmp2;
5448
5449 __asm__ __volatile__(
5450 "1: lduw [%2], %0\n"
5451 -" sub %0, 1, %1\n"
5452 +" subcc %0, 1, %1\n"
5453 +
5454 +#ifdef CONFIG_PAX_REFCOUNT
5455 +" tvs %%icc, 6\n"
5456 +#endif
5457 +
5458 " cas [%2], %0, %1\n"
5459 " cmp %0, %1\n"
5460 " bne,pn %%xcc, 1b\n"
5461 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 : "memory");
5463 }
5464
5465 -static void inline arch_write_lock(arch_rwlock_t *lock)
5466 +static inline void arch_write_lock(arch_rwlock_t *lock)
5467 {
5468 unsigned long mask, tmp1, tmp2;
5469
5470 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5471 : "memory");
5472 }
5473
5474 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5475 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5476 {
5477 __asm__ __volatile__(
5478 " stw %%g0, [%0]"
5479 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5480 : "memory");
5481 }
5482
5483 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5484 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5485 {
5486 unsigned long mask, tmp1, tmp2, result;
5487
5488 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5489 index e6cd224..3a71793 100644
5490 --- a/arch/sparc/include/asm/thread_info_32.h
5491 +++ b/arch/sparc/include/asm/thread_info_32.h
5492 @@ -49,6 +49,8 @@ struct thread_info {
5493 unsigned long w_saved;
5494
5495 struct restart_block restart_block;
5496 +
5497 + unsigned long lowest_stack;
5498 };
5499
5500 /*
5501 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5502 index cfa8c38..13f30d3 100644
5503 --- a/arch/sparc/include/asm/thread_info_64.h
5504 +++ b/arch/sparc/include/asm/thread_info_64.h
5505 @@ -63,6 +63,8 @@ struct thread_info {
5506 struct pt_regs *kern_una_regs;
5507 unsigned int kern_una_insn;
5508
5509 + unsigned long lowest_stack;
5510 +
5511 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5512 };
5513
5514 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5515 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5516 /* flag bit 6 is available */
5517 #define TIF_32BIT 7 /* 32-bit binary */
5518 -/* flag bit 8 is available */
5519 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5520 #define TIF_SECCOMP 9 /* secure computing */
5521 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5522 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5523 +
5524 /* NOTE: Thread flags >= 12 should be ones we have no interest
5525 * in using in assembly, else we can't use the mask as
5526 * an immediate value in instructions such as andcc.
5527 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5528 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5529 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5530 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5531 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5532
5533 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5534 _TIF_DO_NOTIFY_RESUME_MASK | \
5535 _TIF_NEED_RESCHED)
5536 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5537
5538 +#define _TIF_WORK_SYSCALL \
5539 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5540 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5541 +
5542 +
5543 /*
5544 * Thread-synchronous status.
5545 *
5546 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5547 index 0167d26..9acd8ed 100644
5548 --- a/arch/sparc/include/asm/uaccess.h
5549 +++ b/arch/sparc/include/asm/uaccess.h
5550 @@ -1,5 +1,13 @@
5551 #ifndef ___ASM_SPARC_UACCESS_H
5552 #define ___ASM_SPARC_UACCESS_H
5553 +
5554 +#ifdef __KERNEL__
5555 +#ifndef __ASSEMBLY__
5556 +#include <linux/types.h>
5557 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5558 +#endif
5559 +#endif
5560 +
5561 #if defined(__sparc__) && defined(__arch64__)
5562 #include <asm/uaccess_64.h>
5563 #else
5564 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5565 index 53a28dd..50c38c3 100644
5566 --- a/arch/sparc/include/asm/uaccess_32.h
5567 +++ b/arch/sparc/include/asm/uaccess_32.h
5568 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5569
5570 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5571 {
5572 - if (n && __access_ok((unsigned long) to, n))
5573 + if ((long)n < 0)
5574 + return n;
5575 +
5576 + if (n && __access_ok((unsigned long) to, n)) {
5577 + if (!__builtin_constant_p(n))
5578 + check_object_size(from, n, true);
5579 return __copy_user(to, (__force void __user *) from, n);
5580 - else
5581 + } else
5582 return n;
5583 }
5584
5585 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5586 {
5587 + if ((long)n < 0)
5588 + return n;
5589 +
5590 + if (!__builtin_constant_p(n))
5591 + check_object_size(from, n, true);
5592 +
5593 return __copy_user(to, (__force void __user *) from, n);
5594 }
5595
5596 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5597 {
5598 - if (n && __access_ok((unsigned long) from, n))
5599 + if ((long)n < 0)
5600 + return n;
5601 +
5602 + if (n && __access_ok((unsigned long) from, n)) {
5603 + if (!__builtin_constant_p(n))
5604 + check_object_size(to, n, false);
5605 return __copy_user((__force void __user *) to, from, n);
5606 - else
5607 + } else
5608 return n;
5609 }
5610
5611 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5612 {
5613 + if ((long)n < 0)
5614 + return n;
5615 +
5616 return __copy_user((__force void __user *) to, from, n);
5617 }
5618
5619 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5620 index 7c831d8..d440ca7 100644
5621 --- a/arch/sparc/include/asm/uaccess_64.h
5622 +++ b/arch/sparc/include/asm/uaccess_64.h
5623 @@ -10,6 +10,7 @@
5624 #include <linux/compiler.h>
5625 #include <linux/string.h>
5626 #include <linux/thread_info.h>
5627 +#include <linux/kernel.h>
5628 #include <asm/asi.h>
5629 #include <asm/spitfire.h>
5630 #include <asm-generic/uaccess-unaligned.h>
5631 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5632 static inline unsigned long __must_check
5633 copy_from_user(void *to, const void __user *from, unsigned long size)
5634 {
5635 - unsigned long ret = ___copy_from_user(to, from, size);
5636 + unsigned long ret;
5637
5638 + if ((long)size < 0 || size > INT_MAX)
5639 + return size;
5640 +
5641 + if (!__builtin_constant_p(size))
5642 + check_object_size(to, size, false);
5643 +
5644 + ret = ___copy_from_user(to, from, size);
5645 if (unlikely(ret))
5646 ret = copy_from_user_fixup(to, from, size);
5647
5648 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5649 static inline unsigned long __must_check
5650 copy_to_user(void __user *to, const void *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_to_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(from, size, true);
5660 +
5661 + ret = ___copy_to_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_to_user_fixup(to, from, size);
5664 return ret;
5665 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5666 index 6cf591b..b49e65a 100644
5667 --- a/arch/sparc/kernel/Makefile
5668 +++ b/arch/sparc/kernel/Makefile
5669 @@ -3,7 +3,7 @@
5670 #
5671
5672 asflags-y := -ansi
5673 -ccflags-y := -Werror
5674 +#ccflags-y := -Werror
5675
5676 extra-y := head_$(BITS).o
5677
5678 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5679 index 14006d8..8146238 100644
5680 --- a/arch/sparc/kernel/process_32.c
5681 +++ b/arch/sparc/kernel/process_32.c
5682 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5683
5684 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5685 r->psr, r->pc, r->npc, r->y, print_tainted());
5686 - printk("PC: <%pS>\n", (void *) r->pc);
5687 + printk("PC: <%pA>\n", (void *) r->pc);
5688 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5689 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5690 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5691 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5693 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5694 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5695 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5696
5697 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5698 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5699 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5700 rw = (struct reg_window32 *) fp;
5701 pc = rw->ins[7];
5702 printk("[%08lx : ", pc);
5703 - printk("%pS ] ", (void *) pc);
5704 + printk("%pA ] ", (void *) pc);
5705 fp = rw->ins[6];
5706 } while (++count < 16);
5707 printk("\n");
5708 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5709 index aff0c72..9067b39 100644
5710 --- a/arch/sparc/kernel/process_64.c
5711 +++ b/arch/sparc/kernel/process_64.c
5712 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5713 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5714 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5715 if (regs->tstate & TSTATE_PRIV)
5716 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5717 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5718 }
5719
5720 void show_regs(struct pt_regs *regs)
5721 {
5722 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5723 regs->tpc, regs->tnpc, regs->y, print_tainted());
5724 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5725 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5726 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5727 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5728 regs->u_regs[3]);
5729 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5730 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5731 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5732 regs->u_regs[15]);
5733 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5734 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5735 show_regwindow(regs);
5736 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5737 }
5738 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5739 ((tp && tp->task) ? tp->task->pid : -1));
5740
5741 if (gp->tstate & TSTATE_PRIV) {
5742 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5743 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5744 (void *) gp->tpc,
5745 (void *) gp->o7,
5746 (void *) gp->i7,
5747 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5748 index 484daba..0674139 100644
5749 --- a/arch/sparc/kernel/ptrace_64.c
5750 +++ b/arch/sparc/kernel/ptrace_64.c
5751 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5752 return ret;
5753 }
5754
5755 +#ifdef CONFIG_GRKERNSEC_SETXID
5756 +extern void gr_delayed_cred_worker(void);
5757 +#endif
5758 +
5759 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5760 {
5761 int ret = 0;
5762 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 /* do the secure computing check first */
5764 secure_computing_strict(regs->u_regs[UREG_G1]);
5765
5766 +#ifdef CONFIG_GRKERNSEC_SETXID
5767 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5768 + gr_delayed_cred_worker();
5769 +#endif
5770 +
5771 if (test_thread_flag(TIF_SYSCALL_TRACE))
5772 ret = tracehook_report_syscall_entry(regs);
5773
5774 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5775
5776 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5777 {
5778 +#ifdef CONFIG_GRKERNSEC_SETXID
5779 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5780 + gr_delayed_cred_worker();
5781 +#endif
5782 +
5783 audit_syscall_exit(regs);
5784
5785 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5786 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5787 index 0c9b31b..7cb7aee 100644
5788 --- a/arch/sparc/kernel/sys_sparc_32.c
5789 +++ b/arch/sparc/kernel/sys_sparc_32.c
5790 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5791 if (len > TASK_SIZE - PAGE_SIZE)
5792 return -ENOMEM;
5793 if (!addr)
5794 - addr = TASK_UNMAPPED_BASE;
5795 + addr = current->mm->mmap_base;
5796
5797 if (flags & MAP_SHARED)
5798 addr = COLOUR_ALIGN(addr);
5799 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5800 /* At this point: (!vmm || addr < vmm->vm_end). */
5801 if (TASK_SIZE - PAGE_SIZE - len < addr)
5802 return -ENOMEM;
5803 - if (!vmm || addr + len <= vmm->vm_start)
5804 + if (check_heap_stack_gap(vmm, addr, len))
5805 return addr;
5806 addr = vmm->vm_end;
5807 if (flags & MAP_SHARED)
5808 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5809 index 11c6c96..3ec33e8 100644
5810 --- a/arch/sparc/kernel/sys_sparc_64.c
5811 +++ b/arch/sparc/kernel/sys_sparc_64.c
5812 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 /* We do not accept a shared mapping if it would violate
5814 * cache aliasing constraints.
5815 */
5816 - if ((flags & MAP_SHARED) &&
5817 + if ((filp || (flags & MAP_SHARED)) &&
5818 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5819 return -EINVAL;
5820 return addr;
5821 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 if (filp || (flags & MAP_SHARED))
5823 do_color_align = 1;
5824
5825 +#ifdef CONFIG_PAX_RANDMMAP
5826 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5827 +#endif
5828 +
5829 if (addr) {
5830 if (do_color_align)
5831 addr = COLOUR_ALIGN(addr, pgoff);
5832 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5833 addr = PAGE_ALIGN(addr);
5834
5835 vma = find_vma(mm, addr);
5836 - if (task_size - len >= addr &&
5837 - (!vma || addr + len <= vma->vm_start))
5838 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5839 return addr;
5840 }
5841
5842 if (len > mm->cached_hole_size) {
5843 - start_addr = addr = mm->free_area_cache;
5844 + start_addr = addr = mm->free_area_cache;
5845 } else {
5846 - start_addr = addr = TASK_UNMAPPED_BASE;
5847 + start_addr = addr = mm->mmap_base;
5848 mm->cached_hole_size = 0;
5849 }
5850
5851 @@ -157,14 +160,14 @@ full_search:
5852 vma = find_vma(mm, VA_EXCLUDE_END);
5853 }
5854 if (unlikely(task_size < addr)) {
5855 - if (start_addr != TASK_UNMAPPED_BASE) {
5856 - start_addr = addr = TASK_UNMAPPED_BASE;
5857 + if (start_addr != mm->mmap_base) {
5858 + start_addr = addr = mm->mmap_base;
5859 mm->cached_hole_size = 0;
5860 goto full_search;
5861 }
5862 return -ENOMEM;
5863 }
5864 - if (likely(!vma || addr + len <= vma->vm_start)) {
5865 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5866 /*
5867 * Remember the place where we stopped the search:
5868 */
5869 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5870 /* We do not accept a shared mapping if it would violate
5871 * cache aliasing constraints.
5872 */
5873 - if ((flags & MAP_SHARED) &&
5874 + if ((filp || (flags & MAP_SHARED)) &&
5875 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5876 return -EINVAL;
5877 return addr;
5878 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5879 addr = PAGE_ALIGN(addr);
5880
5881 vma = find_vma(mm, addr);
5882 - if (task_size - len >= addr &&
5883 - (!vma || addr + len <= vma->vm_start))
5884 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5885 return addr;
5886 }
5887
5888 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5889 /* make sure it can fit in the remaining address space */
5890 if (likely(addr > len)) {
5891 vma = find_vma(mm, addr-len);
5892 - if (!vma || addr <= vma->vm_start) {
5893 + if (check_heap_stack_gap(vma, addr - len, len)) {
5894 /* remember the address as a hint for next time */
5895 return (mm->free_area_cache = addr-len);
5896 }
5897 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5898 if (unlikely(mm->mmap_base < len))
5899 goto bottomup;
5900
5901 - addr = mm->mmap_base-len;
5902 - if (do_color_align)
5903 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5904 + addr = mm->mmap_base - len;
5905
5906 do {
5907 + if (do_color_align)
5908 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5909 /*
5910 * Lookup failure means no vma is above this address,
5911 * else if new region fits below vma->vm_start,
5912 * return with success:
5913 */
5914 vma = find_vma(mm, addr);
5915 - if (likely(!vma || addr+len <= vma->vm_start)) {
5916 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5917 /* remember the address as a hint for next time */
5918 return (mm->free_area_cache = addr);
5919 }
5920 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 mm->cached_hole_size = vma->vm_start - addr;
5922
5923 /* try just below the current vma->vm_start */
5924 - addr = vma->vm_start-len;
5925 - if (do_color_align)
5926 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5927 - } while (likely(len < vma->vm_start));
5928 + addr = skip_heap_stack_gap(vma, len);
5929 + } while (!IS_ERR_VALUE(addr));
5930
5931 bottomup:
5932 /*
5933 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5934 gap == RLIM_INFINITY ||
5935 sysctl_legacy_va_layout) {
5936 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5937 +
5938 +#ifdef CONFIG_PAX_RANDMMAP
5939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5940 + mm->mmap_base += mm->delta_mmap;
5941 +#endif
5942 +
5943 mm->get_unmapped_area = arch_get_unmapped_area;
5944 mm->unmap_area = arch_unmap_area;
5945 } else {
5946 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5947 gap = (task_size / 6 * 5);
5948
5949 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5950 +
5951 +#ifdef CONFIG_PAX_RANDMMAP
5952 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5953 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5954 +#endif
5955 +
5956 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5957 mm->unmap_area = arch_unmap_area_topdown;
5958 }
5959 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5960 index 1d7e274..b39c527 100644
5961 --- a/arch/sparc/kernel/syscalls.S
5962 +++ b/arch/sparc/kernel/syscalls.S
5963 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5964 #endif
5965 .align 32
5966 1: ldx [%g6 + TI_FLAGS], %l5
5967 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5968 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5969 be,pt %icc, rtrap
5970 nop
5971 call syscall_trace_leave
5972 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5973
5974 srl %i5, 0, %o5 ! IEU1
5975 srl %i2, 0, %o2 ! IEU0 Group
5976 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5977 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5978 bne,pn %icc, linux_syscall_trace32 ! CTI
5979 mov %i0, %l5 ! IEU1
5980 call %l7 ! CTI Group brk forced
5981 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5982
5983 mov %i3, %o3 ! IEU1
5984 mov %i4, %o4 ! IEU0 Group
5985 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5986 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5987 bne,pn %icc, linux_syscall_trace ! CTI Group
5988 mov %i0, %l5 ! IEU0
5989 2: call %l7 ! CTI Group brk forced
5990 @@ -226,7 +226,7 @@ ret_sys_call:
5991
5992 cmp %o0, -ERESTART_RESTARTBLOCK
5993 bgeu,pn %xcc, 1f
5994 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5995 + andcc %l0, _TIF_WORK_SYSCALL, %l6
5996 80:
5997 /* System call success, clear Carry condition code. */
5998 andn %g3, %g2, %g3
5999 @@ -241,7 +241,7 @@ ret_sys_call:
6000 /* System call failure, set Carry condition code.
6001 * Also, get abs(errno) to return to the process.
6002 */
6003 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6004 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6005 sub %g0, %o0, %o0
6006 or %g3, %g2, %g3
6007 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6008 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6009 index a5785ea..405c5f7 100644
6010 --- a/arch/sparc/kernel/traps_32.c
6011 +++ b/arch/sparc/kernel/traps_32.c
6012 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6013 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6014 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6015
6016 +extern void gr_handle_kernel_exploit(void);
6017 +
6018 void die_if_kernel(char *str, struct pt_regs *regs)
6019 {
6020 static int die_counter;
6021 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6022 count++ < 30 &&
6023 (((unsigned long) rw) >= PAGE_OFFSET) &&
6024 !(((unsigned long) rw) & 0x7)) {
6025 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6026 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6027 (void *) rw->ins[7]);
6028 rw = (struct reg_window32 *)rw->ins[6];
6029 }
6030 }
6031 printk("Instruction DUMP:");
6032 instruction_dump ((unsigned long *) regs->pc);
6033 - if(regs->psr & PSR_PS)
6034 + if(regs->psr & PSR_PS) {
6035 + gr_handle_kernel_exploit();
6036 do_exit(SIGKILL);
6037 + }
6038 do_exit(SIGSEGV);
6039 }
6040
6041 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6042 index 3b05e66..6ea2917 100644
6043 --- a/arch/sparc/kernel/traps_64.c
6044 +++ b/arch/sparc/kernel/traps_64.c
6045 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6046 i + 1,
6047 p->trapstack[i].tstate, p->trapstack[i].tpc,
6048 p->trapstack[i].tnpc, p->trapstack[i].tt);
6049 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6050 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6051 }
6052 }
6053
6054 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6055
6056 lvl -= 0x100;
6057 if (regs->tstate & TSTATE_PRIV) {
6058 +
6059 +#ifdef CONFIG_PAX_REFCOUNT
6060 + if (lvl == 6)
6061 + pax_report_refcount_overflow(regs);
6062 +#endif
6063 +
6064 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6065 die_if_kernel(buffer, regs);
6066 }
6067 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6068 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6069 {
6070 char buffer[32];
6071 -
6072 +
6073 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6074 0, lvl, SIGTRAP) == NOTIFY_STOP)
6075 return;
6076
6077 +#ifdef CONFIG_PAX_REFCOUNT
6078 + if (lvl == 6)
6079 + pax_report_refcount_overflow(regs);
6080 +#endif
6081 +
6082 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6083
6084 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6085 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6086 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6087 printk("%s" "ERROR(%d): ",
6088 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6089 - printk("TPC<%pS>\n", (void *) regs->tpc);
6090 + printk("TPC<%pA>\n", (void *) regs->tpc);
6091 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6092 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6093 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6094 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6095 smp_processor_id(),
6096 (type & 0x1) ? 'I' : 'D',
6097 regs->tpc);
6098 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6100 panic("Irrecoverable Cheetah+ parity error.");
6101 }
6102
6103 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6104 smp_processor_id(),
6105 (type & 0x1) ? 'I' : 'D',
6106 regs->tpc);
6107 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6108 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6109 }
6110
6111 struct sun4v_error_entry {
6112 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6113
6114 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6115 regs->tpc, tl);
6116 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6117 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6118 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6119 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6120 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6121 (void *) regs->u_regs[UREG_I7]);
6122 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6123 "pte[%lx] error[%lx]\n",
6124 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6125
6126 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6127 regs->tpc, tl);
6128 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6129 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6130 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6131 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6132 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6133 (void *) regs->u_regs[UREG_I7]);
6134 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6135 "pte[%lx] error[%lx]\n",
6136 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6137 fp = (unsigned long)sf->fp + STACK_BIAS;
6138 }
6139
6140 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6141 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6142 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6143 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6144 int index = tsk->curr_ret_stack;
6145 if (tsk->ret_stack && index >= graph) {
6146 pc = tsk->ret_stack[index - graph].ret;
6147 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6148 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6149 graph++;
6150 }
6151 }
6152 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6153 return (struct reg_window *) (fp + STACK_BIAS);
6154 }
6155
6156 +extern void gr_handle_kernel_exploit(void);
6157 +
6158 void die_if_kernel(char *str, struct pt_regs *regs)
6159 {
6160 static int die_counter;
6161 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 while (rw &&
6163 count++ < 30 &&
6164 kstack_valid(tp, (unsigned long) rw)) {
6165 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6166 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6167 (void *) rw->ins[7]);
6168
6169 rw = kernel_stack_up(rw);
6170 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6171 }
6172 user_instruction_dump ((unsigned int __user *) regs->tpc);
6173 }
6174 - if (regs->tstate & TSTATE_PRIV)
6175 + if (regs->tstate & TSTATE_PRIV) {
6176 + gr_handle_kernel_exploit();
6177 do_exit(SIGKILL);
6178 + }
6179 do_exit(SIGSEGV);
6180 }
6181 EXPORT_SYMBOL(die_if_kernel);
6182 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6183 index f81d038..e7a4680 100644
6184 --- a/arch/sparc/kernel/unaligned_64.c
6185 +++ b/arch/sparc/kernel/unaligned_64.c
6186 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6187 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6188
6189 if (__ratelimit(&ratelimit)) {
6190 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6191 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6192 regs->tpc, (void *) regs->tpc);
6193 }
6194 }
6195 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6196 index dff4096..bd9a388 100644
6197 --- a/arch/sparc/lib/Makefile
6198 +++ b/arch/sparc/lib/Makefile
6199 @@ -2,7 +2,7 @@
6200 #
6201
6202 asflags-y := -ansi -DST_DIV0=0x02
6203 -ccflags-y := -Werror
6204 +#ccflags-y := -Werror
6205
6206 lib-$(CONFIG_SPARC32) += ashrdi3.o
6207 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6208 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6209 index 4d502da..527c48d 100644
6210 --- a/arch/sparc/lib/atomic_64.S
6211 +++ b/arch/sparc/lib/atomic_64.S
6212 @@ -17,7 +17,12 @@
6213 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6214 BACKOFF_SETUP(%o2)
6215 1: lduw [%o1], %g1
6216 - add %g1, %o0, %g7
6217 + addcc %g1, %o0, %g7
6218 +
6219 +#ifdef CONFIG_PAX_REFCOUNT
6220 + tvs %icc, 6
6221 +#endif
6222 +
6223 cas [%o1], %g1, %g7
6224 cmp %g1, %g7
6225 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6226 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6227 2: BACKOFF_SPIN(%o2, %o3, 1b)
6228 ENDPROC(atomic_add)
6229
6230 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6231 + BACKOFF_SETUP(%o2)
6232 +1: lduw [%o1], %g1
6233 + add %g1, %o0, %g7
6234 + cas [%o1], %g1, %g7
6235 + cmp %g1, %g7
6236 + bne,pn %icc, 2f
6237 + nop
6238 + retl
6239 + nop
6240 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6241 +ENDPROC(atomic_add_unchecked)
6242 +
6243 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6244 BACKOFF_SETUP(%o2)
6245 1: lduw [%o1], %g1
6246 - sub %g1, %o0, %g7
6247 + subcc %g1, %o0, %g7
6248 +
6249 +#ifdef CONFIG_PAX_REFCOUNT
6250 + tvs %icc, 6
6251 +#endif
6252 +
6253 cas [%o1], %g1, %g7
6254 cmp %g1, %g7
6255 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6256 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6257 2: BACKOFF_SPIN(%o2, %o3, 1b)
6258 ENDPROC(atomic_sub)
6259
6260 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6261 + BACKOFF_SETUP(%o2)
6262 +1: lduw [%o1], %g1
6263 + sub %g1, %o0, %g7
6264 + cas [%o1], %g1, %g7
6265 + cmp %g1, %g7
6266 + bne,pn %icc, 2f
6267 + nop
6268 + retl
6269 + nop
6270 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6271 +ENDPROC(atomic_sub_unchecked)
6272 +
6273 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6274 BACKOFF_SETUP(%o2)
6275 1: lduw [%o1], %g1
6276 - add %g1, %o0, %g7
6277 + addcc %g1, %o0, %g7
6278 +
6279 +#ifdef CONFIG_PAX_REFCOUNT
6280 + tvs %icc, 6
6281 +#endif
6282 +
6283 cas [%o1], %g1, %g7
6284 cmp %g1, %g7
6285 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6286 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6287 2: BACKOFF_SPIN(%o2, %o3, 1b)
6288 ENDPROC(atomic_add_ret)
6289
6290 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6291 + BACKOFF_SETUP(%o2)
6292 +1: lduw [%o1], %g1
6293 + addcc %g1, %o0, %g7
6294 + cas [%o1], %g1, %g7
6295 + cmp %g1, %g7
6296 + bne,pn %icc, 2f
6297 + add %g7, %o0, %g7
6298 + sra %g7, 0, %o0
6299 + retl
6300 + nop
6301 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6302 +ENDPROC(atomic_add_ret_unchecked)
6303 +
6304 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6305 BACKOFF_SETUP(%o2)
6306 1: lduw [%o1], %g1
6307 - sub %g1, %o0, %g7
6308 + subcc %g1, %o0, %g7
6309 +
6310 +#ifdef CONFIG_PAX_REFCOUNT
6311 + tvs %icc, 6
6312 +#endif
6313 +
6314 cas [%o1], %g1, %g7
6315 cmp %g1, %g7
6316 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6317 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6318 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6319 BACKOFF_SETUP(%o2)
6320 1: ldx [%o1], %g1
6321 - add %g1, %o0, %g7
6322 + addcc %g1, %o0, %g7
6323 +
6324 +#ifdef CONFIG_PAX_REFCOUNT
6325 + tvs %xcc, 6
6326 +#endif
6327 +
6328 casx [%o1], %g1, %g7
6329 cmp %g1, %g7
6330 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6331 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6332 2: BACKOFF_SPIN(%o2, %o3, 1b)
6333 ENDPROC(atomic64_add)
6334
6335 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6336 + BACKOFF_SETUP(%o2)
6337 +1: ldx [%o1], %g1
6338 + addcc %g1, %o0, %g7
6339 + casx [%o1], %g1, %g7
6340 + cmp %g1, %g7
6341 + bne,pn %xcc, 2f
6342 + nop
6343 + retl
6344 + nop
6345 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6346 +ENDPROC(atomic64_add_unchecked)
6347 +
6348 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6349 BACKOFF_SETUP(%o2)
6350 1: ldx [%o1], %g1
6351 - sub %g1, %o0, %g7
6352 + subcc %g1, %o0, %g7
6353 +
6354 +#ifdef CONFIG_PAX_REFCOUNT
6355 + tvs %xcc, 6
6356 +#endif
6357 +
6358 casx [%o1], %g1, %g7
6359 cmp %g1, %g7
6360 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6361 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6362 2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 ENDPROC(atomic64_sub)
6364
6365 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6366 + BACKOFF_SETUP(%o2)
6367 +1: ldx [%o1], %g1
6368 + subcc %g1, %o0, %g7
6369 + casx [%o1], %g1, %g7
6370 + cmp %g1, %g7
6371 + bne,pn %xcc, 2f
6372 + nop
6373 + retl
6374 + nop
6375 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6376 +ENDPROC(atomic64_sub_unchecked)
6377 +
6378 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6379 BACKOFF_SETUP(%o2)
6380 1: ldx [%o1], %g1
6381 - add %g1, %o0, %g7
6382 + addcc %g1, %o0, %g7
6383 +
6384 +#ifdef CONFIG_PAX_REFCOUNT
6385 + tvs %xcc, 6
6386 +#endif
6387 +
6388 casx [%o1], %g1, %g7
6389 cmp %g1, %g7
6390 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6391 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6392 2: BACKOFF_SPIN(%o2, %o3, 1b)
6393 ENDPROC(atomic64_add_ret)
6394
6395 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6396 + BACKOFF_SETUP(%o2)
6397 +1: ldx [%o1], %g1
6398 + addcc %g1, %o0, %g7
6399 + casx [%o1], %g1, %g7
6400 + cmp %g1, %g7
6401 + bne,pn %xcc, 2f
6402 + add %g7, %o0, %g7
6403 + mov %g7, %o0
6404 + retl
6405 + nop
6406 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6407 +ENDPROC(atomic64_add_ret_unchecked)
6408 +
6409 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6410 BACKOFF_SETUP(%o2)
6411 1: ldx [%o1], %g1
6412 - sub %g1, %o0, %g7
6413 + subcc %g1, %o0, %g7
6414 +
6415 +#ifdef CONFIG_PAX_REFCOUNT
6416 + tvs %xcc, 6
6417 +#endif
6418 +
6419 casx [%o1], %g1, %g7
6420 cmp %g1, %g7
6421 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6422 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6423 index 3b31218..345c609 100644
6424 --- a/arch/sparc/lib/ksyms.c
6425 +++ b/arch/sparc/lib/ksyms.c
6426 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6427
6428 /* Atomic counter implementation. */
6429 EXPORT_SYMBOL(atomic_add);
6430 +EXPORT_SYMBOL(atomic_add_unchecked);
6431 EXPORT_SYMBOL(atomic_add_ret);
6432 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6433 EXPORT_SYMBOL(atomic_sub);
6434 +EXPORT_SYMBOL(atomic_sub_unchecked);
6435 EXPORT_SYMBOL(atomic_sub_ret);
6436 EXPORT_SYMBOL(atomic64_add);
6437 +EXPORT_SYMBOL(atomic64_add_unchecked);
6438 EXPORT_SYMBOL(atomic64_add_ret);
6439 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6440 EXPORT_SYMBOL(atomic64_sub);
6441 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6442 EXPORT_SYMBOL(atomic64_sub_ret);
6443
6444 /* Atomic bit operations. */
6445 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6446 index 30c3ecc..736f015 100644
6447 --- a/arch/sparc/mm/Makefile
6448 +++ b/arch/sparc/mm/Makefile
6449 @@ -2,7 +2,7 @@
6450 #
6451
6452 asflags-y := -ansi
6453 -ccflags-y := -Werror
6454 +#ccflags-y := -Werror
6455
6456 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6457 obj-y += fault_$(BITS).o
6458 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6459 index 77ac917..baf45db 100644
6460 --- a/arch/sparc/mm/fault_32.c
6461 +++ b/arch/sparc/mm/fault_32.c
6462 @@ -21,6 +21,9 @@
6463 #include <linux/perf_event.h>
6464 #include <linux/interrupt.h>
6465 #include <linux/kdebug.h>
6466 +#include <linux/slab.h>
6467 +#include <linux/pagemap.h>
6468 +#include <linux/compiler.h>
6469
6470 #include <asm/page.h>
6471 #include <asm/pgtable.h>
6472 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6473 return safe_compute_effective_address(regs, insn);
6474 }
6475
6476 +#ifdef CONFIG_PAX_PAGEEXEC
6477 +#ifdef CONFIG_PAX_DLRESOLVE
6478 +static void pax_emuplt_close(struct vm_area_struct *vma)
6479 +{
6480 + vma->vm_mm->call_dl_resolve = 0UL;
6481 +}
6482 +
6483 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6484 +{
6485 + unsigned int *kaddr;
6486 +
6487 + vmf->page = alloc_page(GFP_HIGHUSER);
6488 + if (!vmf->page)
6489 + return VM_FAULT_OOM;
6490 +
6491 + kaddr = kmap(vmf->page);
6492 + memset(kaddr, 0, PAGE_SIZE);
6493 + kaddr[0] = 0x9DE3BFA8U; /* save */
6494 + flush_dcache_page(vmf->page);
6495 + kunmap(vmf->page);
6496 + return VM_FAULT_MAJOR;
6497 +}
6498 +
6499 +static const struct vm_operations_struct pax_vm_ops = {
6500 + .close = pax_emuplt_close,
6501 + .fault = pax_emuplt_fault
6502 +};
6503 +
6504 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6505 +{
6506 + int ret;
6507 +
6508 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6509 + vma->vm_mm = current->mm;
6510 + vma->vm_start = addr;
6511 + vma->vm_end = addr + PAGE_SIZE;
6512 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6513 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6514 + vma->vm_ops = &pax_vm_ops;
6515 +
6516 + ret = insert_vm_struct(current->mm, vma);
6517 + if (ret)
6518 + return ret;
6519 +
6520 + ++current->mm->total_vm;
6521 + return 0;
6522 +}
6523 +#endif
6524 +
6525 +/*
6526 + * PaX: decide what to do with offenders (regs->pc = fault address)
6527 + *
6528 + * returns 1 when task should be killed
6529 + * 2 when patched PLT trampoline was detected
6530 + * 3 when unpatched PLT trampoline was detected
6531 + */
6532 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6533 +{
6534 +
6535 +#ifdef CONFIG_PAX_EMUPLT
6536 + int err;
6537 +
6538 + do { /* PaX: patched PLT emulation #1 */
6539 + unsigned int sethi1, sethi2, jmpl;
6540 +
6541 + err = get_user(sethi1, (unsigned int *)regs->pc);
6542 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6543 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6544 +
6545 + if (err)
6546 + break;
6547 +
6548 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6549 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6550 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6551 + {
6552 + unsigned int addr;
6553 +
6554 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6555 + addr = regs->u_regs[UREG_G1];
6556 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6557 + regs->pc = addr;
6558 + regs->npc = addr+4;
6559 + return 2;
6560 + }
6561 + } while (0);
6562 +
6563 + do { /* PaX: patched PLT emulation #2 */
6564 + unsigned int ba;
6565 +
6566 + err = get_user(ba, (unsigned int *)regs->pc);
6567 +
6568 + if (err)
6569 + break;
6570 +
6571 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6572 + unsigned int addr;
6573 +
6574 + if ((ba & 0xFFC00000U) == 0x30800000U)
6575 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6576 + else
6577 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6578 + regs->pc = addr;
6579 + regs->npc = addr+4;
6580 + return 2;
6581 + }
6582 + } while (0);
6583 +
6584 + do { /* PaX: patched PLT emulation #3 */
6585 + unsigned int sethi, bajmpl, nop;
6586 +
6587 + err = get_user(sethi, (unsigned int *)regs->pc);
6588 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6589 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6590 +
6591 + if (err)
6592 + break;
6593 +
6594 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6595 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6596 + nop == 0x01000000U)
6597 + {
6598 + unsigned int addr;
6599 +
6600 + addr = (sethi & 0x003FFFFFU) << 10;
6601 + regs->u_regs[UREG_G1] = addr;
6602 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6604 + else
6605 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: unpatched PLT emulation step 1 */
6613 + unsigned int sethi, ba, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr, save, call;
6627 +
6628 + if ((ba & 0xFFC00000U) == 0x30800000U)
6629 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6630 + else
6631 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6632 +
6633 + err = get_user(save, (unsigned int *)addr);
6634 + err |= get_user(call, (unsigned int *)(addr+4));
6635 + err |= get_user(nop, (unsigned int *)(addr+8));
6636 + if (err)
6637 + break;
6638 +
6639 +#ifdef CONFIG_PAX_DLRESOLVE
6640 + if (save == 0x9DE3BFA8U &&
6641 + (call & 0xC0000000U) == 0x40000000U &&
6642 + nop == 0x01000000U)
6643 + {
6644 + struct vm_area_struct *vma;
6645 + unsigned long call_dl_resolve;
6646 +
6647 + down_read(&current->mm->mmap_sem);
6648 + call_dl_resolve = current->mm->call_dl_resolve;
6649 + up_read(&current->mm->mmap_sem);
6650 + if (likely(call_dl_resolve))
6651 + goto emulate;
6652 +
6653 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6654 +
6655 + down_write(&current->mm->mmap_sem);
6656 + if (current->mm->call_dl_resolve) {
6657 + call_dl_resolve = current->mm->call_dl_resolve;
6658 + up_write(&current->mm->mmap_sem);
6659 + if (vma)
6660 + kmem_cache_free(vm_area_cachep, vma);
6661 + goto emulate;
6662 + }
6663 +
6664 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6665 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6666 + up_write(&current->mm->mmap_sem);
6667 + if (vma)
6668 + kmem_cache_free(vm_area_cachep, vma);
6669 + return 1;
6670 + }
6671 +
6672 + if (pax_insert_vma(vma, call_dl_resolve)) {
6673 + up_write(&current->mm->mmap_sem);
6674 + kmem_cache_free(vm_area_cachep, vma);
6675 + return 1;
6676 + }
6677 +
6678 + current->mm->call_dl_resolve = call_dl_resolve;
6679 + up_write(&current->mm->mmap_sem);
6680 +
6681 +emulate:
6682 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6683 + regs->pc = call_dl_resolve;
6684 + regs->npc = addr+4;
6685 + return 3;
6686 + }
6687 +#endif
6688 +
6689 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6690 + if ((save & 0xFFC00000U) == 0x05000000U &&
6691 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6692 + nop == 0x01000000U)
6693 + {
6694 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6695 + regs->u_regs[UREG_G2] = addr + 4;
6696 + addr = (save & 0x003FFFFFU) << 10;
6697 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6698 + regs->pc = addr;
6699 + regs->npc = addr+4;
6700 + return 3;
6701 + }
6702 + }
6703 + } while (0);
6704 +
6705 + do { /* PaX: unpatched PLT emulation step 2 */
6706 + unsigned int save, call, nop;
6707 +
6708 + err = get_user(save, (unsigned int *)(regs->pc-4));
6709 + err |= get_user(call, (unsigned int *)regs->pc);
6710 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6711 + if (err)
6712 + break;
6713 +
6714 + if (save == 0x9DE3BFA8U &&
6715 + (call & 0xC0000000U) == 0x40000000U &&
6716 + nop == 0x01000000U)
6717 + {
6718 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6719 +
6720 + regs->u_regs[UREG_RETPC] = regs->pc;
6721 + regs->pc = dl_resolve;
6722 + regs->npc = dl_resolve+4;
6723 + return 3;
6724 + }
6725 + } while (0);
6726 +#endif
6727 +
6728 + return 1;
6729 +}
6730 +
6731 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6732 +{
6733 + unsigned long i;
6734 +
6735 + printk(KERN_ERR "PAX: bytes at PC: ");
6736 + for (i = 0; i < 8; i++) {
6737 + unsigned int c;
6738 + if (get_user(c, (unsigned int *)pc+i))
6739 + printk(KERN_CONT "???????? ");
6740 + else
6741 + printk(KERN_CONT "%08x ", c);
6742 + }
6743 + printk("\n");
6744 +}
6745 +#endif
6746 +
6747 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6748 int text_fault)
6749 {
6750 @@ -230,6 +504,24 @@ good_area:
6751 if (!(vma->vm_flags & VM_WRITE))
6752 goto bad_area;
6753 } else {
6754 +
6755 +#ifdef CONFIG_PAX_PAGEEXEC
6756 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6757 + up_read(&mm->mmap_sem);
6758 + switch (pax_handle_fetch_fault(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_EMUPLT
6761 + case 2:
6762 + case 3:
6763 + return;
6764 +#endif
6765 +
6766 + }
6767 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6768 + do_group_exit(SIGKILL);
6769 + }
6770 +#endif
6771 +
6772 /* Allow reads even for write-only mappings */
6773 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6774 goto bad_area;
6775 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6776 index 1fe0429..8dd5dd5 100644
6777 --- a/arch/sparc/mm/fault_64.c
6778 +++ b/arch/sparc/mm/fault_64.c
6779 @@ -21,6 +21,9 @@
6780 #include <linux/kprobes.h>
6781 #include <linux/kdebug.h>
6782 #include <linux/percpu.h>
6783 +#include <linux/slab.h>
6784 +#include <linux/pagemap.h>
6785 +#include <linux/compiler.h>
6786
6787 #include <asm/page.h>
6788 #include <asm/pgtable.h>
6789 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6790 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6791 regs->tpc);
6792 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6793 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6794 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6795 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6796 dump_stack();
6797 unhandled_fault(regs->tpc, current, regs);
6798 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6799 show_regs(regs);
6800 }
6801
6802 +#ifdef CONFIG_PAX_PAGEEXEC
6803 +#ifdef CONFIG_PAX_DLRESOLVE
6804 +static void pax_emuplt_close(struct vm_area_struct *vma)
6805 +{
6806 + vma->vm_mm->call_dl_resolve = 0UL;
6807 +}
6808 +
6809 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6810 +{
6811 + unsigned int *kaddr;
6812 +
6813 + vmf->page = alloc_page(GFP_HIGHUSER);
6814 + if (!vmf->page)
6815 + return VM_FAULT_OOM;
6816 +
6817 + kaddr = kmap(vmf->page);
6818 + memset(kaddr, 0, PAGE_SIZE);
6819 + kaddr[0] = 0x9DE3BFA8U; /* save */
6820 + flush_dcache_page(vmf->page);
6821 + kunmap(vmf->page);
6822 + return VM_FAULT_MAJOR;
6823 +}
6824 +
6825 +static const struct vm_operations_struct pax_vm_ops = {
6826 + .close = pax_emuplt_close,
6827 + .fault = pax_emuplt_fault
6828 +};
6829 +
6830 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6831 +{
6832 + int ret;
6833 +
6834 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6835 + vma->vm_mm = current->mm;
6836 + vma->vm_start = addr;
6837 + vma->vm_end = addr + PAGE_SIZE;
6838 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6839 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6840 + vma->vm_ops = &pax_vm_ops;
6841 +
6842 + ret = insert_vm_struct(current->mm, vma);
6843 + if (ret)
6844 + return ret;
6845 +
6846 + ++current->mm->total_vm;
6847 + return 0;
6848 +}
6849 +#endif
6850 +
6851 +/*
6852 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6853 + *
6854 + * returns 1 when task should be killed
6855 + * 2 when patched PLT trampoline was detected
6856 + * 3 when unpatched PLT trampoline was detected
6857 + */
6858 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6859 +{
6860 +
6861 +#ifdef CONFIG_PAX_EMUPLT
6862 + int err;
6863 +
6864 + do { /* PaX: patched PLT emulation #1 */
6865 + unsigned int sethi1, sethi2, jmpl;
6866 +
6867 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6868 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6869 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6870 +
6871 + if (err)
6872 + break;
6873 +
6874 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6875 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6876 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6877 + {
6878 + unsigned long addr;
6879 +
6880 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6881 + addr = regs->u_regs[UREG_G1];
6882 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6883 +
6884 + if (test_thread_flag(TIF_32BIT))
6885 + addr &= 0xFFFFFFFFUL;
6886 +
6887 + regs->tpc = addr;
6888 + regs->tnpc = addr+4;
6889 + return 2;
6890 + }
6891 + } while (0);
6892 +
6893 + do { /* PaX: patched PLT emulation #2 */
6894 + unsigned int ba;
6895 +
6896 + err = get_user(ba, (unsigned int *)regs->tpc);
6897 +
6898 + if (err)
6899 + break;
6900 +
6901 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6902 + unsigned long addr;
6903 +
6904 + if ((ba & 0xFFC00000U) == 0x30800000U)
6905 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6906 + else
6907 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6908 +
6909 + if (test_thread_flag(TIF_32BIT))
6910 + addr &= 0xFFFFFFFFUL;
6911 +
6912 + regs->tpc = addr;
6913 + regs->tnpc = addr+4;
6914 + return 2;
6915 + }
6916 + } while (0);
6917 +
6918 + do { /* PaX: patched PLT emulation #3 */
6919 + unsigned int sethi, bajmpl, nop;
6920 +
6921 + err = get_user(sethi, (unsigned int *)regs->tpc);
6922 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6923 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6924 +
6925 + if (err)
6926 + break;
6927 +
6928 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6929 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6930 + nop == 0x01000000U)
6931 + {
6932 + unsigned long addr;
6933 +
6934 + addr = (sethi & 0x003FFFFFU) << 10;
6935 + regs->u_regs[UREG_G1] = addr;
6936 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6937 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6938 + else
6939 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6940 +
6941 + if (test_thread_flag(TIF_32BIT))
6942 + addr &= 0xFFFFFFFFUL;
6943 +
6944 + regs->tpc = addr;
6945 + regs->tnpc = addr+4;
6946 + return 2;
6947 + }
6948 + } while (0);
6949 +
6950 + do { /* PaX: patched PLT emulation #4 */
6951 + unsigned int sethi, mov1, call, mov2;
6952 +
6953 + err = get_user(sethi, (unsigned int *)regs->tpc);
6954 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6955 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6956 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6957 +
6958 + if (err)
6959 + break;
6960 +
6961 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6962 + mov1 == 0x8210000FU &&
6963 + (call & 0xC0000000U) == 0x40000000U &&
6964 + mov2 == 0x9E100001U)
6965 + {
6966 + unsigned long addr;
6967 +
6968 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6969 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6970 +
6971 + if (test_thread_flag(TIF_32BIT))
6972 + addr &= 0xFFFFFFFFUL;
6973 +
6974 + regs->tpc = addr;
6975 + regs->tnpc = addr+4;
6976 + return 2;
6977 + }
6978 + } while (0);
6979 +
6980 + do { /* PaX: patched PLT emulation #5 */
6981 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6982 +
6983 + err = get_user(sethi, (unsigned int *)regs->tpc);
6984 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6985 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6986 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6987 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6988 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6989 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6990 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6991 +
6992 + if (err)
6993 + break;
6994 +
6995 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6996 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6997 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6998 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6999 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7000 + sllx == 0x83287020U &&
7001 + jmpl == 0x81C04005U &&
7002 + nop == 0x01000000U)
7003 + {
7004 + unsigned long addr;
7005 +
7006 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7007 + regs->u_regs[UREG_G1] <<= 32;
7008 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7009 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7010 + regs->tpc = addr;
7011 + regs->tnpc = addr+4;
7012 + return 2;
7013 + }
7014 + } while (0);
7015 +
7016 + do { /* PaX: patched PLT emulation #6 */
7017 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7018 +
7019 + err = get_user(sethi, (unsigned int *)regs->tpc);
7020 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7021 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7022 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7023 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7024 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7025 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7026 +
7027 + if (err)
7028 + break;
7029 +
7030 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7031 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7032 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7033 + sllx == 0x83287020U &&
7034 + (or & 0xFFFFE000U) == 0x8A116000U &&
7035 + jmpl == 0x81C04005U &&
7036 + nop == 0x01000000U)
7037 + {
7038 + unsigned long addr;
7039 +
7040 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7041 + regs->u_regs[UREG_G1] <<= 32;
7042 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7043 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7044 + regs->tpc = addr;
7045 + regs->tnpc = addr+4;
7046 + return 2;
7047 + }
7048 + } while (0);
7049 +
7050 + do { /* PaX: unpatched PLT emulation step 1 */
7051 + unsigned int sethi, ba, nop;
7052 +
7053 + err = get_user(sethi, (unsigned int *)regs->tpc);
7054 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7055 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7056 +
7057 + if (err)
7058 + break;
7059 +
7060 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7061 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7062 + nop == 0x01000000U)
7063 + {
7064 + unsigned long addr;
7065 + unsigned int save, call;
7066 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7067 +
7068 + if ((ba & 0xFFC00000U) == 0x30800000U)
7069 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7070 + else
7071 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7072 +
7073 + if (test_thread_flag(TIF_32BIT))
7074 + addr &= 0xFFFFFFFFUL;
7075 +
7076 + err = get_user(save, (unsigned int *)addr);
7077 + err |= get_user(call, (unsigned int *)(addr+4));
7078 + err |= get_user(nop, (unsigned int *)(addr+8));
7079 + if (err)
7080 + break;
7081 +
7082 +#ifdef CONFIG_PAX_DLRESOLVE
7083 + if (save == 0x9DE3BFA8U &&
7084 + (call & 0xC0000000U) == 0x40000000U &&
7085 + nop == 0x01000000U)
7086 + {
7087 + struct vm_area_struct *vma;
7088 + unsigned long call_dl_resolve;
7089 +
7090 + down_read(&current->mm->mmap_sem);
7091 + call_dl_resolve = current->mm->call_dl_resolve;
7092 + up_read(&current->mm->mmap_sem);
7093 + if (likely(call_dl_resolve))
7094 + goto emulate;
7095 +
7096 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7097 +
7098 + down_write(&current->mm->mmap_sem);
7099 + if (current->mm->call_dl_resolve) {
7100 + call_dl_resolve = current->mm->call_dl_resolve;
7101 + up_write(&current->mm->mmap_sem);
7102 + if (vma)
7103 + kmem_cache_free(vm_area_cachep, vma);
7104 + goto emulate;
7105 + }
7106 +
7107 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7108 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7109 + up_write(&current->mm->mmap_sem);
7110 + if (vma)
7111 + kmem_cache_free(vm_area_cachep, vma);
7112 + return 1;
7113 + }
7114 +
7115 + if (pax_insert_vma(vma, call_dl_resolve)) {
7116 + up_write(&current->mm->mmap_sem);
7117 + kmem_cache_free(vm_area_cachep, vma);
7118 + return 1;
7119 + }
7120 +
7121 + current->mm->call_dl_resolve = call_dl_resolve;
7122 + up_write(&current->mm->mmap_sem);
7123 +
7124 +emulate:
7125 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7126 + regs->tpc = call_dl_resolve;
7127 + regs->tnpc = addr+4;
7128 + return 3;
7129 + }
7130 +#endif
7131 +
7132 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7133 + if ((save & 0xFFC00000U) == 0x05000000U &&
7134 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7135 + nop == 0x01000000U)
7136 + {
7137 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7138 + regs->u_regs[UREG_G2] = addr + 4;
7139 + addr = (save & 0x003FFFFFU) << 10;
7140 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7141 +
7142 + if (test_thread_flag(TIF_32BIT))
7143 + addr &= 0xFFFFFFFFUL;
7144 +
7145 + regs->tpc = addr;
7146 + regs->tnpc = addr+4;
7147 + return 3;
7148 + }
7149 +
7150 + /* PaX: 64-bit PLT stub */
7151 + err = get_user(sethi1, (unsigned int *)addr);
7152 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7153 + err |= get_user(or1, (unsigned int *)(addr+8));
7154 + err |= get_user(or2, (unsigned int *)(addr+12));
7155 + err |= get_user(sllx, (unsigned int *)(addr+16));
7156 + err |= get_user(add, (unsigned int *)(addr+20));
7157 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7158 + err |= get_user(nop, (unsigned int *)(addr+28));
7159 + if (err)
7160 + break;
7161 +
7162 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7163 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7164 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7165 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7166 + sllx == 0x89293020U &&
7167 + add == 0x8A010005U &&
7168 + jmpl == 0x89C14000U &&
7169 + nop == 0x01000000U)
7170 + {
7171 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7172 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7173 + regs->u_regs[UREG_G4] <<= 32;
7174 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7175 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7176 + regs->u_regs[UREG_G4] = addr + 24;
7177 + addr = regs->u_regs[UREG_G5];
7178 + regs->tpc = addr;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 + }
7183 + } while (0);
7184 +
7185 +#ifdef CONFIG_PAX_DLRESOLVE
7186 + do { /* PaX: unpatched PLT emulation step 2 */
7187 + unsigned int save, call, nop;
7188 +
7189 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7190 + err |= get_user(call, (unsigned int *)regs->tpc);
7191 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7192 + if (err)
7193 + break;
7194 +
7195 + if (save == 0x9DE3BFA8U &&
7196 + (call & 0xC0000000U) == 0x40000000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7200 +
7201 + if (test_thread_flag(TIF_32BIT))
7202 + dl_resolve &= 0xFFFFFFFFUL;
7203 +
7204 + regs->u_regs[UREG_RETPC] = regs->tpc;
7205 + regs->tpc = dl_resolve;
7206 + regs->tnpc = dl_resolve+4;
7207 + return 3;
7208 + }
7209 + } while (0);
7210 +#endif
7211 +
7212 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7213 + unsigned int sethi, ba, nop;
7214 +
7215 + err = get_user(sethi, (unsigned int *)regs->tpc);
7216 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7217 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7218 +
7219 + if (err)
7220 + break;
7221 +
7222 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7223 + (ba & 0xFFF00000U) == 0x30600000U &&
7224 + nop == 0x01000000U)
7225 + {
7226 + unsigned long addr;
7227 +
7228 + addr = (sethi & 0x003FFFFFU) << 10;
7229 + regs->u_regs[UREG_G1] = addr;
7230 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7231 +
7232 + if (test_thread_flag(TIF_32BIT))
7233 + addr &= 0xFFFFFFFFUL;
7234 +
7235 + regs->tpc = addr;
7236 + regs->tnpc = addr+4;
7237 + return 2;
7238 + }
7239 + } while (0);
7240 +
7241 +#endif
7242 +
7243 + return 1;
7244 +}
7245 +
7246 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7247 +{
7248 + unsigned long i;
7249 +
7250 + printk(KERN_ERR "PAX: bytes at PC: ");
7251 + for (i = 0; i < 8; i++) {
7252 + unsigned int c;
7253 + if (get_user(c, (unsigned int *)pc+i))
7254 + printk(KERN_CONT "???????? ");
7255 + else
7256 + printk(KERN_CONT "%08x ", c);
7257 + }
7258 + printk("\n");
7259 +}
7260 +#endif
7261 +
7262 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7263 {
7264 struct mm_struct *mm = current->mm;
7265 @@ -343,6 +806,29 @@ retry:
7266 if (!vma)
7267 goto bad_area;
7268
7269 +#ifdef CONFIG_PAX_PAGEEXEC
7270 + /* PaX: detect ITLB misses on non-exec pages */
7271 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7272 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7273 + {
7274 + if (address != regs->tpc)
7275 + goto good_area;
7276 +
7277 + up_read(&mm->mmap_sem);
7278 + switch (pax_handle_fetch_fault(regs)) {
7279 +
7280 +#ifdef CONFIG_PAX_EMUPLT
7281 + case 2:
7282 + case 3:
7283 + return;
7284 +#endif
7285 +
7286 + }
7287 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7288 + do_group_exit(SIGKILL);
7289 + }
7290 +#endif
7291 +
7292 /* Pure DTLB misses do not tell us whether the fault causing
7293 * load/store/atomic was a write or not, it only says that there
7294 * was no match. So in such a case we (carefully) read the
7295 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7296 index 07e1453..0a7d9e9 100644
7297 --- a/arch/sparc/mm/hugetlbpage.c
7298 +++ b/arch/sparc/mm/hugetlbpage.c
7299 @@ -67,7 +67,7 @@ full_search:
7300 }
7301 return -ENOMEM;
7302 }
7303 - if (likely(!vma || addr + len <= vma->vm_start)) {
7304 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7305 /*
7306 * Remember the place where we stopped the search:
7307 */
7308 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 /* make sure it can fit in the remaining address space */
7310 if (likely(addr > len)) {
7311 vma = find_vma(mm, addr-len);
7312 - if (!vma || addr <= vma->vm_start) {
7313 + if (check_heap_stack_gap(vma, addr - len, len)) {
7314 /* remember the address as a hint for next time */
7315 return (mm->free_area_cache = addr-len);
7316 }
7317 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 if (unlikely(mm->mmap_base < len))
7319 goto bottomup;
7320
7321 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7322 + addr = mm->mmap_base - len;
7323
7324 do {
7325 + addr &= HPAGE_MASK;
7326 /*
7327 * Lookup failure means no vma is above this address,
7328 * else if new region fits below vma->vm_start,
7329 * return with success:
7330 */
7331 vma = find_vma(mm, addr);
7332 - if (likely(!vma || addr+len <= vma->vm_start)) {
7333 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7334 /* remember the address as a hint for next time */
7335 return (mm->free_area_cache = addr);
7336 }
7337 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7338 mm->cached_hole_size = vma->vm_start - addr;
7339
7340 /* try just below the current vma->vm_start */
7341 - addr = (vma->vm_start-len) & HPAGE_MASK;
7342 - } while (likely(len < vma->vm_start));
7343 + addr = skip_heap_stack_gap(vma, len);
7344 + } while (!IS_ERR_VALUE(addr));
7345
7346 bottomup:
7347 /*
7348 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7349 if (addr) {
7350 addr = ALIGN(addr, HPAGE_SIZE);
7351 vma = find_vma(mm, addr);
7352 - if (task_size - len >= addr &&
7353 - (!vma || addr + len <= vma->vm_start))
7354 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7355 return addr;
7356 }
7357 if (mm->get_unmapped_area == arch_get_unmapped_area)
7358 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7359 index f4500c6..889656c 100644
7360 --- a/arch/tile/include/asm/atomic_64.h
7361 +++ b/arch/tile/include/asm/atomic_64.h
7362 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7363
7364 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7365
7366 +#define atomic64_read_unchecked(v) atomic64_read(v)
7367 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7368 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7369 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7370 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7371 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7372 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7373 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7374 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7375 +
7376 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7377 #define smp_mb__before_atomic_dec() smp_mb()
7378 #define smp_mb__after_atomic_dec() smp_mb()
7379 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7380 index a9a5299..0fce79e 100644
7381 --- a/arch/tile/include/asm/cache.h
7382 +++ b/arch/tile/include/asm/cache.h
7383 @@ -15,11 +15,12 @@
7384 #ifndef _ASM_TILE_CACHE_H
7385 #define _ASM_TILE_CACHE_H
7386
7387 +#include <linux/const.h>
7388 #include <arch/chip.h>
7389
7390 /* bytes per L1 data cache line */
7391 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7392 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7393 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7394
7395 /* bytes per L2 cache line */
7396 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7397 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7398 index 9ab078a..d6635c2 100644
7399 --- a/arch/tile/include/asm/uaccess.h
7400 +++ b/arch/tile/include/asm/uaccess.h
7401 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7402 const void __user *from,
7403 unsigned long n)
7404 {
7405 - int sz = __compiletime_object_size(to);
7406 + size_t sz = __compiletime_object_size(to);
7407
7408 - if (likely(sz == -1 || sz >= n))
7409 + if (likely(sz == (size_t)-1 || sz >= n))
7410 n = _copy_from_user(to, from, n);
7411 else
7412 copy_from_user_overflow();
7413 diff --git a/arch/um/Makefile b/arch/um/Makefile
7414 index 0970910..9f65c40 100644
7415 --- a/arch/um/Makefile
7416 +++ b/arch/um/Makefile
7417 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7420
7421 +ifdef CONSTIFY_PLUGIN
7422 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7423 +endif
7424 +
7425 #This will adjust *FLAGS accordingly to the platform.
7426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7427
7428 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7429 index 19e1bdd..3665b77 100644
7430 --- a/arch/um/include/asm/cache.h
7431 +++ b/arch/um/include/asm/cache.h
7432 @@ -1,6 +1,7 @@
7433 #ifndef __UM_CACHE_H
7434 #define __UM_CACHE_H
7435
7436 +#include <linux/const.h>
7437
7438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7440 @@ -12,6 +13,6 @@
7441 # define L1_CACHE_SHIFT 5
7442 #endif
7443
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 #endif
7448 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7449 index 2e0a6b1..a64d0f5 100644
7450 --- a/arch/um/include/asm/kmap_types.h
7451 +++ b/arch/um/include/asm/kmap_types.h
7452 @@ -8,6 +8,6 @@
7453
7454 /* No more #include "asm/arch/kmap_types.h" ! */
7455
7456 -#define KM_TYPE_NR 14
7457 +#define KM_TYPE_NR 15
7458
7459 #endif
7460 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7461 index 7cfc3ce..cbd1a58 100644
7462 --- a/arch/um/include/asm/page.h
7463 +++ b/arch/um/include/asm/page.h
7464 @@ -14,6 +14,9 @@
7465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7466 #define PAGE_MASK (~(PAGE_SIZE-1))
7467
7468 +#define ktla_ktva(addr) (addr)
7469 +#define ktva_ktla(addr) (addr)
7470 +
7471 #ifndef __ASSEMBLY__
7472
7473 struct page;
7474 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7475 index 0032f92..cd151e0 100644
7476 --- a/arch/um/include/asm/pgtable-3level.h
7477 +++ b/arch/um/include/asm/pgtable-3level.h
7478 @@ -58,6 +58,7 @@
7479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7480 #define pud_populate(mm, pud, pmd) \
7481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7482 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7483
7484 #ifdef CONFIG_64BIT
7485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7486 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7487 index c5f5afa..6abce4b 100644
7488 --- a/arch/um/kernel/process.c
7489 +++ b/arch/um/kernel/process.c
7490 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7491 return 2;
7492 }
7493
7494 -/*
7495 - * Only x86 and x86_64 have an arch_align_stack().
7496 - * All other arches have "#define arch_align_stack(x) (x)"
7497 - * in their asm/system.h
7498 - * As this is included in UML from asm-um/system-generic.h,
7499 - * we can use it to behave as the subarch does.
7500 - */
7501 -#ifndef arch_align_stack
7502 -unsigned long arch_align_stack(unsigned long sp)
7503 -{
7504 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7505 - sp -= get_random_int() % 8192;
7506 - return sp & ~0xf;
7507 -}
7508 -#endif
7509 -
7510 unsigned long get_wchan(struct task_struct *p)
7511 {
7512 unsigned long stack_page, sp, ip;
7513 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7514 index ad8f795..2c7eec6 100644
7515 --- a/arch/unicore32/include/asm/cache.h
7516 +++ b/arch/unicore32/include/asm/cache.h
7517 @@ -12,8 +12,10 @@
7518 #ifndef __UNICORE_CACHE_H__
7519 #define __UNICORE_CACHE_H__
7520
7521 -#define L1_CACHE_SHIFT (5)
7522 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7523 +#include <linux/const.h>
7524 +
7525 +#define L1_CACHE_SHIFT 5
7526 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7527
7528 /*
7529 * Memory returned by kmalloc() may be used for DMA, so we must make
7530 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7531 index 50a1d1f..c26369f 100644
7532 --- a/arch/x86/Kconfig
7533 +++ b/arch/x86/Kconfig
7534 @@ -220,7 +220,7 @@ config X86_HT
7535
7536 config X86_32_LAZY_GS
7537 def_bool y
7538 - depends on X86_32 && !CC_STACKPROTECTOR
7539 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7540
7541 config ARCH_HWEIGHT_CFLAGS
7542 string
7543 @@ -1049,7 +1049,7 @@ choice
7544
7545 config NOHIGHMEM
7546 bool "off"
7547 - depends on !X86_NUMAQ
7548 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7551 However, the address space of 32-bit x86 processors is only 4
7552 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7553
7554 config HIGHMEM4G
7555 bool "4GB"
7556 - depends on !X86_NUMAQ
7557 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7558 ---help---
7559 Select this if you have a 32-bit processor and between 1 and 4
7560 gigabytes of physical RAM.
7561 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7562 hex
7563 default 0xB0000000 if VMSPLIT_3G_OPT
7564 default 0x80000000 if VMSPLIT_2G
7565 - default 0x78000000 if VMSPLIT_2G_OPT
7566 + default 0x70000000 if VMSPLIT_2G_OPT
7567 default 0x40000000 if VMSPLIT_1G
7568 default 0xC0000000
7569 depends on X86_32
7570 @@ -1528,6 +1528,7 @@ config SECCOMP
7571
7572 config CC_STACKPROTECTOR
7573 bool "Enable -fstack-protector buffer overflow detection"
7574 + depends on X86_64 || !PAX_MEMORY_UDEREF
7575 ---help---
7576 This option turns on the -fstack-protector GCC feature. This
7577 feature puts, at the beginning of functions, a canary value on
7578 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7579 config PHYSICAL_START
7580 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7581 default "0x1000000"
7582 + range 0x400000 0x40000000
7583 ---help---
7584 This gives the physical address where the kernel is loaded.
7585
7586 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7587 config PHYSICAL_ALIGN
7588 hex "Alignment value to which kernel should be aligned" if X86_32
7589 default "0x1000000"
7590 + range 0x400000 0x1000000 if PAX_KERNEXEC
7591 range 0x2000 0x1000000
7592 ---help---
7593 This value puts the alignment restrictions on physical address
7594 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7595 Say N if you want to disable CPU hotplug.
7596
7597 config COMPAT_VDSO
7598 - def_bool y
7599 + def_bool n
7600 prompt "Compat VDSO support"
7601 depends on X86_32 || IA32_EMULATION
7602 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7603 ---help---
7604 Map the 32-bit VDSO to the predictable old-style address too.
7605
7606 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7607 index 706e12e..62e4feb 100644
7608 --- a/arch/x86/Kconfig.cpu
7609 +++ b/arch/x86/Kconfig.cpu
7610 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7611
7612 config X86_F00F_BUG
7613 def_bool y
7614 - depends on M586MMX || M586TSC || M586 || M486 || M386
7615 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7616
7617 config X86_INVD_BUG
7618 def_bool y
7619 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7620
7621 config X86_ALIGNMENT_16
7622 def_bool y
7623 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7624 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7625
7626 config X86_INTEL_USERCOPY
7627 def_bool y
7628 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7629 # generates cmov.
7630 config X86_CMOV
7631 def_bool y
7632 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7633 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7634
7635 config X86_MINIMUM_CPU_FAMILY
7636 int
7637 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7638 index b322f12..652d0d9 100644
7639 --- a/arch/x86/Kconfig.debug
7640 +++ b/arch/x86/Kconfig.debug
7641 @@ -84,7 +84,7 @@ config X86_PTDUMP
7642 config DEBUG_RODATA
7643 bool "Write protect kernel read-only data structures"
7644 default y
7645 - depends on DEBUG_KERNEL
7646 + depends on DEBUG_KERNEL && BROKEN
7647 ---help---
7648 Mark the kernel read-only data as write-protected in the pagetables,
7649 in order to catch accidental (and incorrect) writes to such const
7650 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7651
7652 config DEBUG_SET_MODULE_RONX
7653 bool "Set loadable kernel module data as NX and text as RO"
7654 - depends on MODULES
7655 + depends on MODULES && BROKEN
7656 ---help---
7657 This option helps catch unintended modifications to loadable
7658 kernel module's text and read-only data. It also prevents execution
7659 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7660
7661 config DEBUG_STRICT_USER_COPY_CHECKS
7662 bool "Strict copy size checks"
7663 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7664 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7665 ---help---
7666 Enabling this option turns a certain set of sanity checks for user
7667 copy operations into compile time failures.
7668 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7669 index 05afcca..b6ecb51 100644
7670 --- a/arch/x86/Makefile
7671 +++ b/arch/x86/Makefile
7672 @@ -50,6 +50,7 @@ else
7673 UTS_MACHINE := x86_64
7674 CHECKFLAGS += -D__x86_64__ -m64
7675
7676 + biarch := $(call cc-option,-m64)
7677 KBUILD_AFLAGS += -m64
7678 KBUILD_CFLAGS += -m64
7679
7680 @@ -229,3 +230,12 @@ define archhelp
7681 echo ' FDARGS="..." arguments for the booted kernel'
7682 echo ' FDINITRD=file initrd for the booted kernel'
7683 endef
7684 +
7685 +define OLD_LD
7686 +
7687 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7688 +*** Please upgrade your binutils to 2.18 or newer
7689 +endef
7690 +
7691 +archprepare:
7692 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7693 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7694 index f7535be..37db2d1 100644
7695 --- a/arch/x86/boot/Makefile
7696 +++ b/arch/x86/boot/Makefile
7697 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7698 $(call cc-option, -fno-stack-protector) \
7699 $(call cc-option, -mpreferred-stack-boundary=2)
7700 KBUILD_CFLAGS += $(call cc-option, -m32)
7701 +ifdef CONSTIFY_PLUGIN
7702 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7703 +endif
7704 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7705 GCOV_PROFILE := n
7706
7707 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7708 index 878e4b9..20537ab 100644
7709 --- a/arch/x86/boot/bitops.h
7710 +++ b/arch/x86/boot/bitops.h
7711 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712 u8 v;
7713 const u32 *p = (const u32 *)addr;
7714
7715 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7716 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7717 return v;
7718 }
7719
7720 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7721
7722 static inline void set_bit(int nr, void *addr)
7723 {
7724 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7725 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7726 }
7727
7728 #endif /* BOOT_BITOPS_H */
7729 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7730 index 18997e5..83d9c67 100644
7731 --- a/arch/x86/boot/boot.h
7732 +++ b/arch/x86/boot/boot.h
7733 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7734 static inline u16 ds(void)
7735 {
7736 u16 seg;
7737 - asm("movw %%ds,%0" : "=rm" (seg));
7738 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7739 return seg;
7740 }
7741
7742 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7743 static inline int memcmp(const void *s1, const void *s2, size_t len)
7744 {
7745 u8 diff;
7746 - asm("repe; cmpsb; setnz %0"
7747 + asm volatile("repe; cmpsb; setnz %0"
7748 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7749 return diff;
7750 }
7751 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7752 index 8a84501..b2d165f 100644
7753 --- a/arch/x86/boot/compressed/Makefile
7754 +++ b/arch/x86/boot/compressed/Makefile
7755 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7756 KBUILD_CFLAGS += $(cflags-y)
7757 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7758 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7759 +ifdef CONSTIFY_PLUGIN
7760 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7761 +endif
7762
7763 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7764 GCOV_PROFILE := n
7765 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7766 index b3e0227..f2c02d5 100644
7767 --- a/arch/x86/boot/compressed/eboot.c
7768 +++ b/arch/x86/boot/compressed/eboot.c
7769 @@ -142,7 +142,6 @@ again:
7770 *addr = max_addr;
7771 }
7772
7773 -free_pool:
7774 efi_call_phys1(sys_table->boottime->free_pool, map);
7775
7776 fail:
7777 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7778 if (i == map_size / desc_size)
7779 status = EFI_NOT_FOUND;
7780
7781 -free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783 fail:
7784 return status;
7785 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7786 index aa4aaf1..6656f2f 100644
7787 --- a/arch/x86/boot/compressed/head_32.S
7788 +++ b/arch/x86/boot/compressed/head_32.S
7789 @@ -116,7 +116,7 @@ preferred_addr:
7790 notl %eax
7791 andl %eax, %ebx
7792 #else
7793 - movl $LOAD_PHYSICAL_ADDR, %ebx
7794 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7795 #endif
7796
7797 /* Target address to relocate to for decompression */
7798 @@ -202,7 +202,7 @@ relocated:
7799 * and where it was actually loaded.
7800 */
7801 movl %ebp, %ebx
7802 - subl $LOAD_PHYSICAL_ADDR, %ebx
7803 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7804 jz 2f /* Nothing to be done if loaded at compiled addr. */
7805 /*
7806 * Process relocations.
7807 @@ -210,8 +210,7 @@ relocated:
7808
7809 1: subl $4, %edi
7810 movl (%edi), %ecx
7811 - testl %ecx, %ecx
7812 - jz 2f
7813 + jecxz 2f
7814 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7815 jmp 1b
7816 2:
7817 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7818 index 2c4b171..e1fa5b1 100644
7819 --- a/arch/x86/boot/compressed/head_64.S
7820 +++ b/arch/x86/boot/compressed/head_64.S
7821 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7822 notl %eax
7823 andl %eax, %ebx
7824 #else
7825 - movl $LOAD_PHYSICAL_ADDR, %ebx
7826 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830 @@ -273,7 +273,7 @@ preferred_addr:
7831 notq %rax
7832 andq %rax, %rbp
7833 #else
7834 - movq $LOAD_PHYSICAL_ADDR, %rbp
7835 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7836 #endif
7837
7838 /* Target address to relocate to for decompression */
7839 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7840 index 88f7ff6..ed695dd 100644
7841 --- a/arch/x86/boot/compressed/misc.c
7842 +++ b/arch/x86/boot/compressed/misc.c
7843 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7844 case PT_LOAD:
7845 #ifdef CONFIG_RELOCATABLE
7846 dest = output;
7847 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7848 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7849 #else
7850 dest = (void *)(phdr->p_paddr);
7851 #endif
7852 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7853 error("Destination address too large");
7854 #endif
7855 #ifndef CONFIG_RELOCATABLE
7856 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7857 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7858 error("Wrong destination address");
7859 #endif
7860
7861 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7862 index 4d3ff03..e4972ff 100644
7863 --- a/arch/x86/boot/cpucheck.c
7864 +++ b/arch/x86/boot/cpucheck.c
7865 @@ -74,7 +74,7 @@ static int has_fpu(void)
7866 u16 fcw = -1, fsw = -1;
7867 u32 cr0;
7868
7869 - asm("movl %%cr0,%0" : "=r" (cr0));
7870 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7871 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7872 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7873 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7874 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7875 {
7876 u32 f0, f1;
7877
7878 - asm("pushfl ; "
7879 + asm volatile("pushfl ; "
7880 "pushfl ; "
7881 "popl %0 ; "
7882 "movl %0,%1 ; "
7883 @@ -115,7 +115,7 @@ static void get_flags(void)
7884 set_bit(X86_FEATURE_FPU, cpu.flags);
7885
7886 if (has_eflag(X86_EFLAGS_ID)) {
7887 - asm("cpuid"
7888 + asm volatile("cpuid"
7889 : "=a" (max_intel_level),
7890 "=b" (cpu_vendor[0]),
7891 "=d" (cpu_vendor[1]),
7892 @@ -124,7 +124,7 @@ static void get_flags(void)
7893
7894 if (max_intel_level >= 0x00000001 &&
7895 max_intel_level <= 0x0000ffff) {
7896 - asm("cpuid"
7897 + asm volatile("cpuid"
7898 : "=a" (tfms),
7899 "=c" (cpu.flags[4]),
7900 "=d" (cpu.flags[0])
7901 @@ -136,7 +136,7 @@ static void get_flags(void)
7902 cpu.model += ((tfms >> 16) & 0xf) << 4;
7903 }
7904
7905 - asm("cpuid"
7906 + asm volatile("cpuid"
7907 : "=a" (max_amd_level)
7908 : "a" (0x80000000)
7909 : "ebx", "ecx", "edx");
7910 @@ -144,7 +144,7 @@ static void get_flags(void)
7911 if (max_amd_level >= 0x80000001 &&
7912 max_amd_level <= 0x8000ffff) {
7913 u32 eax = 0x80000001;
7914 - asm("cpuid"
7915 + asm volatile("cpuid"
7916 : "+a" (eax),
7917 "=c" (cpu.flags[6]),
7918 "=d" (cpu.flags[1])
7919 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7920 u32 ecx = MSR_K7_HWCR;
7921 u32 eax, edx;
7922
7923 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7924 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7925 eax &= ~(1 << 15);
7926 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7927 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7928
7929 get_flags(); /* Make sure it really did something */
7930 err = check_flags();
7931 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7932 u32 ecx = MSR_VIA_FCR;
7933 u32 eax, edx;
7934
7935 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7936 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7937 eax |= (1<<1)|(1<<7);
7938 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7939 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7940
7941 set_bit(X86_FEATURE_CX8, cpu.flags);
7942 err = check_flags();
7943 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7944 u32 eax, edx;
7945 u32 level = 1;
7946
7947 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7948 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7949 - asm("cpuid"
7950 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7951 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7952 + asm volatile("cpuid"
7953 : "+a" (level), "=d" (cpu.flags[0])
7954 : : "ecx", "ebx");
7955 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7957
7958 err = check_flags();
7959 }
7960 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7961 index b4e15dd..8ac59ce 100644
7962 --- a/arch/x86/boot/header.S
7963 +++ b/arch/x86/boot/header.S
7964 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7965 # single linked list of
7966 # struct setup_data
7967
7968 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7969 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7970
7971 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7972 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7973 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7974 +#else
7975 #define VO_INIT_SIZE (VO__end - VO__text)
7976 +#endif
7977 #if ZO_INIT_SIZE > VO_INIT_SIZE
7978 #define INIT_SIZE ZO_INIT_SIZE
7979 #else
7980 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7981 index db75d07..8e6d0af 100644
7982 --- a/arch/x86/boot/memory.c
7983 +++ b/arch/x86/boot/memory.c
7984 @@ -19,7 +19,7 @@
7985
7986 static int detect_memory_e820(void)
7987 {
7988 - int count = 0;
7989 + unsigned int count = 0;
7990 struct biosregs ireg, oreg;
7991 struct e820entry *desc = boot_params.e820_map;
7992 static struct e820entry buf; /* static so it is zeroed */
7993 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7994 index 11e8c6e..fdbb1ed 100644
7995 --- a/arch/x86/boot/video-vesa.c
7996 +++ b/arch/x86/boot/video-vesa.c
7997 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7998
7999 boot_params.screen_info.vesapm_seg = oreg.es;
8000 boot_params.screen_info.vesapm_off = oreg.di;
8001 + boot_params.screen_info.vesapm_size = oreg.cx;
8002 }
8003
8004 /*
8005 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8006 index 43eda28..5ab5fdb 100644
8007 --- a/arch/x86/boot/video.c
8008 +++ b/arch/x86/boot/video.c
8009 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8010 static unsigned int get_entry(void)
8011 {
8012 char entry_buf[4];
8013 - int i, len = 0;
8014 + unsigned int i, len = 0;
8015 int key;
8016 unsigned int v;
8017
8018 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8019 index 5b577d5..3c1fed4 100644
8020 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8021 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8022 @@ -8,6 +8,8 @@
8023 * including this sentence is retained in full.
8024 */
8025
8026 +#include <asm/alternative-asm.h>
8027 +
8028 .extern crypto_ft_tab
8029 .extern crypto_it_tab
8030 .extern crypto_fl_tab
8031 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8032 je B192; \
8033 leaq 32(r9),r9;
8034
8035 +#define ret pax_force_retaddr 0, 1; ret
8036 +
8037 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8038 movq r1,r2; \
8039 movq r3,r4; \
8040 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8041 index 3470624..201259d 100644
8042 --- a/arch/x86/crypto/aesni-intel_asm.S
8043 +++ b/arch/x86/crypto/aesni-intel_asm.S
8044 @@ -31,6 +31,7 @@
8045
8046 #include <linux/linkage.h>
8047 #include <asm/inst.h>
8048 +#include <asm/alternative-asm.h>
8049
8050 #ifdef __x86_64__
8051 .data
8052 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8053 pop %r14
8054 pop %r13
8055 pop %r12
8056 + pax_force_retaddr 0, 1
8057 ret
8058 +ENDPROC(aesni_gcm_dec)
8059
8060
8061 /*****************************************************************************
8062 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8063 pop %r14
8064 pop %r13
8065 pop %r12
8066 + pax_force_retaddr 0, 1
8067 ret
8068 +ENDPROC(aesni_gcm_enc)
8069
8070 #endif
8071
8072 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8073 pxor %xmm1, %xmm0
8074 movaps %xmm0, (TKEYP)
8075 add $0x10, TKEYP
8076 + pax_force_retaddr_bts
8077 ret
8078
8079 .align 4
8080 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8081 shufps $0b01001110, %xmm2, %xmm1
8082 movaps %xmm1, 0x10(TKEYP)
8083 add $0x20, TKEYP
8084 + pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8089
8090 movaps %xmm0, (TKEYP)
8091 add $0x10, TKEYP
8092 + pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8097 pxor %xmm1, %xmm2
8098 movaps %xmm2, (TKEYP)
8099 add $0x10, TKEYP
8100 + pax_force_retaddr_bts
8101 ret
8102
8103 /*
8104 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8105 #ifndef __x86_64__
8106 popl KEYP
8107 #endif
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_set_key)
8111
8112 /*
8113 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8114 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8115 popl KLEN
8116 popl KEYP
8117 #endif
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_enc)
8121
8122 /*
8123 * _aesni_enc1: internal ABI
8124 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8125 AESENC KEY STATE
8126 movaps 0x70(TKEYP), KEY
8127 AESENCLAST KEY STATE
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8133 AESENCLAST KEY STATE2
8134 AESENCLAST KEY STATE3
8135 AESENCLAST KEY STATE4
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8141 popl KLEN
8142 popl KEYP
8143 #endif
8144 + pax_force_retaddr 0, 1
8145 ret
8146 +ENDPROC(aesni_dec)
8147
8148 /*
8149 * _aesni_dec1: internal ABI
8150 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8151 AESDEC KEY STATE
8152 movaps 0x70(TKEYP), KEY
8153 AESDECLAST KEY STATE
8154 + pax_force_retaddr_bts
8155 ret
8156
8157 /*
8158 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8159 AESDECLAST KEY STATE2
8160 AESDECLAST KEY STATE3
8161 AESDECLAST KEY STATE4
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8167 popl KEYP
8168 popl LEN
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_ecb_enc)
8173
8174 /*
8175 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8176 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8177 popl KEYP
8178 popl LEN
8179 #endif
8180 + pax_force_retaddr 0, 1
8181 ret
8182 +ENDPROC(aesni_ecb_dec)
8183
8184 /*
8185 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8186 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8187 popl LEN
8188 popl IVP
8189 #endif
8190 + pax_force_retaddr 0, 1
8191 ret
8192 +ENDPROC(aesni_cbc_enc)
8193
8194 /*
8195 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8196 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8197 popl LEN
8198 popl IVP
8199 #endif
8200 + pax_force_retaddr 0, 1
8201 ret
8202 +ENDPROC(aesni_cbc_dec)
8203
8204 #ifdef __x86_64__
8205 .align 16
8206 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8207 mov $1, TCTR_LOW
8208 MOVQ_R64_XMM TCTR_LOW INC
8209 MOVQ_R64_XMM CTR TCTR_LOW
8210 + pax_force_retaddr_bts
8211 ret
8212
8213 /*
8214 @@ -2554,6 +2582,7 @@ _aesni_inc:
8215 .Linc_low:
8216 movaps CTR, IV
8217 PSHUFB_XMM BSWAP_MASK IV
8218 + pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8223 .Lctr_enc_ret:
8224 movups IV, (IVP)
8225 .Lctr_enc_just_ret:
8226 + pax_force_retaddr 0, 1
8227 ret
8228 +ENDPROC(aesni_ctr_enc)
8229 #endif
8230 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8231 index 391d245..67f35c2 100644
8232 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8233 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8234 @@ -20,6 +20,8 @@
8235 *
8236 */
8237
8238 +#include <asm/alternative-asm.h>
8239 +
8240 .file "blowfish-x86_64-asm.S"
8241 .text
8242
8243 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8244 jnz __enc_xor;
8245
8246 write_block();
8247 + pax_force_retaddr 0, 1
8248 ret;
8249 __enc_xor:
8250 xor_block();
8251 + pax_force_retaddr 0, 1
8252 ret;
8253
8254 .align 8
8255 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8256
8257 movq %r11, %rbp;
8258
8259 + pax_force_retaddr 0, 1
8260 ret;
8261
8262 /**********************************************************************
8263 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8264
8265 popq %rbx;
8266 popq %rbp;
8267 + pax_force_retaddr 0, 1
8268 ret;
8269
8270 __enc_xor4:
8271 @@ -349,6 +355,7 @@ __enc_xor4:
8272
8273 popq %rbx;
8274 popq %rbp;
8275 + pax_force_retaddr 0, 1
8276 ret;
8277
8278 .align 8
8279 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8280 popq %rbx;
8281 popq %rbp;
8282
8283 + pax_force_retaddr 0, 1
8284 ret;
8285
8286 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8287 index 0b33743..7a56206 100644
8288 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8289 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8290 @@ -20,6 +20,8 @@
8291 *
8292 */
8293
8294 +#include <asm/alternative-asm.h>
8295 +
8296 .file "camellia-x86_64-asm_64.S"
8297 .text
8298
8299 @@ -229,12 +231,14 @@ __enc_done:
8300 enc_outunpack(mov, RT1);
8301
8302 movq RRBP, %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 __enc_xor:
8307 enc_outunpack(xor, RT1);
8308
8309 movq RRBP, %rbp;
8310 + pax_force_retaddr 0, 1
8311 ret;
8312
8313 .global camellia_dec_blk;
8314 @@ -275,6 +279,7 @@ __dec_rounds16:
8315 dec_outunpack();
8316
8317 movq RRBP, %rbp;
8318 + pax_force_retaddr 0, 1
8319 ret;
8320
8321 /**********************************************************************
8322 @@ -468,6 +473,7 @@ __enc2_done:
8323
8324 movq RRBP, %rbp;
8325 popq %rbx;
8326 + pax_force_retaddr 0, 1
8327 ret;
8328
8329 __enc2_xor:
8330 @@ -475,6 +481,7 @@ __enc2_xor:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334 + pax_force_retaddr 0, 1
8335 ret;
8336
8337 .global camellia_dec_blk_2way;
8338 @@ -517,4 +524,5 @@ __dec2_rounds16:
8339
8340 movq RRBP, %rbp;
8341 movq RXOR, %rbx;
8342 + pax_force_retaddr 0, 1
8343 ret;
8344 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8345 index 6214a9b..1f4fc9a 100644
8346 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8347 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8348 @@ -1,3 +1,5 @@
8349 +#include <asm/alternative-asm.h>
8350 +
8351 # enter ECRYPT_encrypt_bytes
8352 .text
8353 .p2align 5
8354 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8355 add %r11,%rsp
8356 mov %rdi,%rax
8357 mov %rsi,%rdx
8358 + pax_force_retaddr 0, 1
8359 ret
8360 # bytesatleast65:
8361 ._bytesatleast65:
8362 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366 + pax_force_retaddr
8367 ret
8368 # enter ECRYPT_ivsetup
8369 .text
8370 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374 + pax_force_retaddr
8375 ret
8376 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8377 index 504106b..4e50951 100644
8378 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8379 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8380 @@ -24,6 +24,8 @@
8381 *
8382 */
8383
8384 +#include <asm/alternative-asm.h>
8385 +
8386 .file "serpent-avx-x86_64-asm_64.S"
8387 .text
8388
8389 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8390 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8391 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8392
8393 + pax_force_retaddr
8394 ret;
8395
8396 __enc_xor8:
8397 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8398 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8399
8400 + pax_force_retaddr
8401 ret;
8402
8403 .align 8
8404 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8405 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8406 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8407
8408 + pax_force_retaddr
8409 ret;
8410 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8411 index 3ee1ff0..cbc568b 100644
8412 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8413 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8414 @@ -24,6 +24,8 @@
8415 *
8416 */
8417
8418 +#include <asm/alternative-asm.h>
8419 +
8420 .file "serpent-sse2-x86_64-asm_64.S"
8421 .text
8422
8423 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8424 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8425 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8426
8427 + pax_force_retaddr
8428 ret;
8429
8430 __enc_xor8:
8431 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8432 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8433
8434 + pax_force_retaddr
8435 ret;
8436
8437 .align 8
8438 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8439 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8440 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8441
8442 + pax_force_retaddr
8443 ret;
8444 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8445 index 49d6987..df66bd4 100644
8446 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8447 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8448 @@ -28,6 +28,8 @@
8449 * (at your option) any later version.
8450 */
8451
8452 +#include <asm/alternative-asm.h>
8453 +
8454 #define CTX %rdi // arg1
8455 #define BUF %rsi // arg2
8456 #define CNT %rdx // arg3
8457 @@ -104,6 +106,7 @@
8458 pop %r12
8459 pop %rbp
8460 pop %rbx
8461 + pax_force_retaddr 0, 1
8462 ret
8463
8464 .size \name, .-\name
8465 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8466 index 35f4557..16b379f 100644
8467 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8468 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8469 @@ -21,6 +21,8 @@
8470 *
8471 */
8472
8473 +#include <asm/alternative-asm.h>
8474 +
8475 .file "twofish-avx-x86_64-asm_64.S"
8476 .text
8477
8478 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8479 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8480 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8481
8482 + pax_force_retaddr
8483 ret;
8484
8485 __enc_xor8:
8486 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8487 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8488
8489 + pax_force_retaddr
8490 ret;
8491
8492 .align 8
8493 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8494 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8495 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8496
8497 + pax_force_retaddr
8498 ret;
8499 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8500 index 5b012a2..36d5364 100644
8501 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8502 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8503 @@ -20,6 +20,8 @@
8504 *
8505 */
8506
8507 +#include <asm/alternative-asm.h>
8508 +
8509 .file "twofish-x86_64-asm-3way.S"
8510 .text
8511
8512 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516 + pax_force_retaddr 0, 1
8517 ret;
8518
8519 __enc_xor3:
8520 @@ -271,6 +274,7 @@ __enc_xor3:
8521 popq %r13;
8522 popq %r14;
8523 popq %r15;
8524 + pax_force_retaddr 0, 1
8525 ret;
8526
8527 .global twofish_dec_blk_3way
8528 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8529 popq %r13;
8530 popq %r14;
8531 popq %r15;
8532 + pax_force_retaddr 0, 1
8533 ret;
8534
8535 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8536 index 7bcf3fc..f53832f 100644
8537 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8538 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8539 @@ -21,6 +21,7 @@
8540 .text
8541
8542 #include <asm/asm-offsets.h>
8543 +#include <asm/alternative-asm.h>
8544
8545 #define a_offset 0
8546 #define b_offset 4
8547 @@ -268,6 +269,7 @@ twofish_enc_blk:
8548
8549 popq R1
8550 movq $1,%rax
8551 + pax_force_retaddr 0, 1
8552 ret
8553
8554 twofish_dec_blk:
8555 @@ -319,4 +321,5 @@ twofish_dec_blk:
8556
8557 popq R1
8558 movq $1,%rax
8559 + pax_force_retaddr 0, 1
8560 ret
8561 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8562 index 07b3a68..bd2a388 100644
8563 --- a/arch/x86/ia32/ia32_aout.c
8564 +++ b/arch/x86/ia32/ia32_aout.c
8565 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8566 unsigned long dump_start, dump_size;
8567 struct user32 dump;
8568
8569 + memset(&dump, 0, sizeof(dump));
8570 +
8571 fs = get_fs();
8572 set_fs(KERNEL_DS);
8573 has_dumped = 1;
8574 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8575 index 673ac9b..7a8c5df 100644
8576 --- a/arch/x86/ia32/ia32_signal.c
8577 +++ b/arch/x86/ia32/ia32_signal.c
8578 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8579 }
8580 seg = get_fs();
8581 set_fs(KERNEL_DS);
8582 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8583 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8584 set_fs(seg);
8585 if (ret >= 0 && uoss_ptr) {
8586 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8587 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8588 */
8589 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 size_t frame_size,
8591 - void **fpstate)
8592 + void __user **fpstate)
8593 {
8594 unsigned long sp;
8595
8596 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597
8598 if (used_math()) {
8599 sp = sp - sig_xstate_ia32_size;
8600 - *fpstate = (struct _fpstate_ia32 *) sp;
8601 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8602 if (save_i387_xstate_ia32(*fpstate) < 0)
8603 return (void __user *) -1L;
8604 }
8605 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8606 sp -= frame_size;
8607 /* Align the stack pointer according to the i386 ABI,
8608 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8609 - sp = ((sp + 4) & -16ul) - 4;
8610 + sp = ((sp - 12) & -16ul) - 4;
8611 return (void __user *) sp;
8612 }
8613
8614 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8615 * These are actually not used anymore, but left because some
8616 * gdb versions depend on them as a marker.
8617 */
8618 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8619 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8620 } put_user_catch(err);
8621
8622 if (err)
8623 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624 0xb8,
8625 __NR_ia32_rt_sigreturn,
8626 0x80cd,
8627 - 0,
8628 + 0
8629 };
8630
8631 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8632 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8633
8634 if (ka->sa.sa_flags & SA_RESTORER)
8635 restorer = ka->sa.sa_restorer;
8636 + else if (current->mm->context.vdso)
8637 + /* Return stub is in 32bit vsyscall page */
8638 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8639 else
8640 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8641 - rt_sigreturn);
8642 + restorer = &frame->retcode;
8643 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8644
8645 /*
8646 * Not actually used anymore, but left because some gdb
8647 * versions need it.
8648 */
8649 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8650 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8651 } put_user_catch(err);
8652
8653 if (err)
8654 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8655 index 20e5f7b..f33c779 100644
8656 --- a/arch/x86/ia32/ia32entry.S
8657 +++ b/arch/x86/ia32/ia32entry.S
8658 @@ -14,8 +14,10 @@
8659 #include <asm/segment.h>
8660 #include <asm/irqflags.h>
8661 #include <asm/asm.h>
8662 +#include <asm/pgtable.h>
8663 #include <linux/linkage.h>
8664 #include <linux/err.h>
8665 +#include <asm/alternative-asm.h>
8666
8667 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8668 #include <linux/elf-em.h>
8669 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8670 ENDPROC(native_irq_enable_sysexit)
8671 #endif
8672
8673 + .macro pax_enter_kernel_user
8674 + pax_set_fptr_mask
8675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8676 + call pax_enter_kernel_user
8677 +#endif
8678 + .endm
8679 +
8680 + .macro pax_exit_kernel_user
8681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8682 + call pax_exit_kernel_user
8683 +#endif
8684 +#ifdef CONFIG_PAX_RANDKSTACK
8685 + pushq %rax
8686 + pushq %r11
8687 + call pax_randomize_kstack
8688 + popq %r11
8689 + popq %rax
8690 +#endif
8691 + .endm
8692 +
8693 +.macro pax_erase_kstack
8694 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8695 + call pax_erase_kstack
8696 +#endif
8697 +.endm
8698 +
8699 /*
8700 * 32bit SYSENTER instruction entry.
8701 *
8702 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8703 CFI_REGISTER rsp,rbp
8704 SWAPGS_UNSAFE_STACK
8705 movq PER_CPU_VAR(kernel_stack), %rsp
8706 - addq $(KERNEL_STACK_OFFSET),%rsp
8707 - /*
8708 - * No need to follow this irqs on/off section: the syscall
8709 - * disabled irqs, here we enable it straight after entry:
8710 - */
8711 - ENABLE_INTERRUPTS(CLBR_NONE)
8712 movl %ebp,%ebp /* zero extension */
8713 pushq_cfi $__USER32_DS
8714 /*CFI_REL_OFFSET ss,0*/
8715 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8716 CFI_REL_OFFSET rsp,0
8717 pushfq_cfi
8718 /*CFI_REL_OFFSET rflags,0*/
8719 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8720 - CFI_REGISTER rip,r10
8721 + orl $X86_EFLAGS_IF,(%rsp)
8722 + GET_THREAD_INFO(%r11)
8723 + movl TI_sysenter_return(%r11), %r11d
8724 + CFI_REGISTER rip,r11
8725 pushq_cfi $__USER32_CS
8726 /*CFI_REL_OFFSET cs,0*/
8727 movl %eax, %eax
8728 - pushq_cfi %r10
8729 + pushq_cfi %r11
8730 CFI_REL_OFFSET rip,0
8731 pushq_cfi %rax
8732 cld
8733 SAVE_ARGS 0,1,0
8734 + pax_enter_kernel_user
8735 +
8736 +#ifdef CONFIG_PAX_RANDKSTACK
8737 + pax_erase_kstack
8738 +#endif
8739 +
8740 + /*
8741 + * No need to follow this irqs on/off section: the syscall
8742 + * disabled irqs, here we enable it straight after entry:
8743 + */
8744 + ENABLE_INTERRUPTS(CLBR_NONE)
8745 /* no need to do an access_ok check here because rbp has been
8746 32bit zero extended */
8747 +
8748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8749 + mov $PAX_USER_SHADOW_BASE,%r11
8750 + add %r11,%rbp
8751 +#endif
8752 +
8753 1: movl (%rbp),%ebp
8754 _ASM_EXTABLE(1b,ia32_badarg)
8755 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8756 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8757 + GET_THREAD_INFO(%r11)
8758 + orl $TS_COMPAT,TI_status(%r11)
8759 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8760 CFI_REMEMBER_STATE
8761 jnz sysenter_tracesys
8762 cmpq $(IA32_NR_syscalls-1),%rax
8763 @@ -159,12 +201,15 @@ sysenter_do_call:
8764 sysenter_dispatch:
8765 call *ia32_sys_call_table(,%rax,8)
8766 movq %rax,RAX-ARGOFFSET(%rsp)
8767 + GET_THREAD_INFO(%r11)
8768 DISABLE_INTERRUPTS(CLBR_NONE)
8769 TRACE_IRQS_OFF
8770 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8771 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8772 jnz sysexit_audit
8773 sysexit_from_sys_call:
8774 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8775 + pax_exit_kernel_user
8776 + pax_erase_kstack
8777 + andl $~TS_COMPAT,TI_status(%r11)
8778 /* clear IF, that popfq doesn't enable interrupts early */
8779 andl $~0x200,EFLAGS-R11(%rsp)
8780 movl RIP-R11(%rsp),%edx /* User %eip */
8781 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8782 movl %eax,%esi /* 2nd arg: syscall number */
8783 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8784 call __audit_syscall_entry
8785 +
8786 + pax_erase_kstack
8787 +
8788 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8789 cmpq $(IA32_NR_syscalls-1),%rax
8790 ja ia32_badsys
8791 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8792 .endm
8793
8794 .macro auditsys_exit exit
8795 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8796 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8797 jnz ia32_ret_from_sys_call
8798 TRACE_IRQS_ON
8799 sti
8800 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8801 1: setbe %al /* 1 if error, 0 if not */
8802 movzbl %al,%edi /* zero-extend that into %edi */
8803 call __audit_syscall_exit
8804 + GET_THREAD_INFO(%r11)
8805 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8806 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8807 cli
8808 TRACE_IRQS_OFF
8809 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810 + testl %edi,TI_flags(%r11)
8811 jz \exit
8812 CLEAR_RREGS -ARGOFFSET
8813 jmp int_with_check
8814 @@ -234,7 +283,7 @@ sysexit_audit:
8815
8816 sysenter_tracesys:
8817 #ifdef CONFIG_AUDITSYSCALL
8818 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8820 jz sysenter_auditsys
8821 #endif
8822 SAVE_REST
8823 @@ -246,6 +295,9 @@ sysenter_tracesys:
8824 RESTORE_REST
8825 cmpq $(IA32_NR_syscalls-1),%rax
8826 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8827 +
8828 + pax_erase_kstack
8829 +
8830 jmp sysenter_do_call
8831 CFI_ENDPROC
8832 ENDPROC(ia32_sysenter_target)
8833 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8834 ENTRY(ia32_cstar_target)
8835 CFI_STARTPROC32 simple
8836 CFI_SIGNAL_FRAME
8837 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8838 + CFI_DEF_CFA rsp,0
8839 CFI_REGISTER rip,rcx
8840 /*CFI_REGISTER rflags,r11*/
8841 SWAPGS_UNSAFE_STACK
8842 movl %esp,%r8d
8843 CFI_REGISTER rsp,r8
8844 movq PER_CPU_VAR(kernel_stack),%rsp
8845 + SAVE_ARGS 8*6,0,0
8846 + pax_enter_kernel_user
8847 +
8848 +#ifdef CONFIG_PAX_RANDKSTACK
8849 + pax_erase_kstack
8850 +#endif
8851 +
8852 /*
8853 * No need to follow this irqs on/off section: the syscall
8854 * disabled irqs and here we enable it straight after entry:
8855 */
8856 ENABLE_INTERRUPTS(CLBR_NONE)
8857 - SAVE_ARGS 8,0,0
8858 movl %eax,%eax /* zero extension */
8859 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8860 movq %rcx,RIP-ARGOFFSET(%rsp)
8861 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8862 /* no need to do an access_ok check here because r8 has been
8863 32bit zero extended */
8864 /* hardware stack frame is complete now */
8865 +
8866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8867 + mov $PAX_USER_SHADOW_BASE,%r11
8868 + add %r11,%r8
8869 +#endif
8870 +
8871 1: movl (%r8),%r9d
8872 _ASM_EXTABLE(1b,ia32_badarg)
8873 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8875 + GET_THREAD_INFO(%r11)
8876 + orl $TS_COMPAT,TI_status(%r11)
8877 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8878 CFI_REMEMBER_STATE
8879 jnz cstar_tracesys
8880 cmpq $IA32_NR_syscalls-1,%rax
8881 @@ -314,12 +379,15 @@ cstar_do_call:
8882 cstar_dispatch:
8883 call *ia32_sys_call_table(,%rax,8)
8884 movq %rax,RAX-ARGOFFSET(%rsp)
8885 + GET_THREAD_INFO(%r11)
8886 DISABLE_INTERRUPTS(CLBR_NONE)
8887 TRACE_IRQS_OFF
8888 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8889 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8890 jnz sysretl_audit
8891 sysretl_from_sys_call:
8892 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8893 + pax_exit_kernel_user
8894 + pax_erase_kstack
8895 + andl $~TS_COMPAT,TI_status(%r11)
8896 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8897 movl RIP-ARGOFFSET(%rsp),%ecx
8898 CFI_REGISTER rip,rcx
8899 @@ -347,7 +415,7 @@ sysretl_audit:
8900
8901 cstar_tracesys:
8902 #ifdef CONFIG_AUDITSYSCALL
8903 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8904 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8905 jz cstar_auditsys
8906 #endif
8907 xchgl %r9d,%ebp
8908 @@ -361,6 +429,9 @@ cstar_tracesys:
8909 xchgl %ebp,%r9d
8910 cmpq $(IA32_NR_syscalls-1),%rax
8911 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8912 +
8913 + pax_erase_kstack
8914 +
8915 jmp cstar_do_call
8916 END(ia32_cstar_target)
8917
8918 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8919 CFI_REL_OFFSET rip,RIP-RIP
8920 PARAVIRT_ADJUST_EXCEPTION_FRAME
8921 SWAPGS
8922 - /*
8923 - * No need to follow this irqs on/off section: the syscall
8924 - * disabled irqs and here we enable it straight after entry:
8925 - */
8926 - ENABLE_INTERRUPTS(CLBR_NONE)
8927 movl %eax,%eax
8928 pushq_cfi %rax
8929 cld
8930 /* note the registers are not zero extended to the sf.
8931 this could be a problem. */
8932 SAVE_ARGS 0,1,0
8933 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8935 + pax_enter_kernel_user
8936 +
8937 +#ifdef CONFIG_PAX_RANDKSTACK
8938 + pax_erase_kstack
8939 +#endif
8940 +
8941 + /*
8942 + * No need to follow this irqs on/off section: the syscall
8943 + * disabled irqs and here we enable it straight after entry:
8944 + */
8945 + ENABLE_INTERRUPTS(CLBR_NONE)
8946 + GET_THREAD_INFO(%r11)
8947 + orl $TS_COMPAT,TI_status(%r11)
8948 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8949 jnz ia32_tracesys
8950 cmpq $(IA32_NR_syscalls-1),%rax
8951 ja ia32_badsys
8952 @@ -436,6 +514,9 @@ ia32_tracesys:
8953 RESTORE_REST
8954 cmpq $(IA32_NR_syscalls-1),%rax
8955 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8956 +
8957 + pax_erase_kstack
8958 +
8959 jmp ia32_do_call
8960 END(ia32_syscall)
8961
8962 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8963 index 4540bec..714d913 100644
8964 --- a/arch/x86/ia32/sys_ia32.c
8965 +++ b/arch/x86/ia32/sys_ia32.c
8966 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8967 */
8968 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8969 {
8970 - typeof(ubuf->st_uid) uid = 0;
8971 - typeof(ubuf->st_gid) gid = 0;
8972 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8973 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8974 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8975 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8976 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8977 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8978 return ret;
8979 }
8980
8981 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8982 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8983 int options)
8984 {
8985 return compat_sys_wait4(pid, stat_addr, options, NULL);
8986 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8991 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8992 set_fs(old_fs);
8993 if (put_compat_timespec(&t, interval))
8994 return -EFAULT;
8995 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8996 mm_segment_t old_fs = get_fs();
8997
8998 set_fs(KERNEL_DS);
8999 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9000 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9001 set_fs(old_fs);
9002 if (!ret) {
9003 switch (_NSIG_WORDS) {
9004 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9005 if (copy_siginfo_from_user32(&info, uinfo))
9006 return -EFAULT;
9007 set_fs(KERNEL_DS);
9008 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9009 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9010 set_fs(old_fs);
9011 return ret;
9012 }
9013 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9014 return -EFAULT;
9015
9016 set_fs(KERNEL_DS);
9017 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9018 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9019 count);
9020 set_fs(old_fs);
9021
9022 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9023 index 952bd01..7692c6f 100644
9024 --- a/arch/x86/include/asm/alternative-asm.h
9025 +++ b/arch/x86/include/asm/alternative-asm.h
9026 @@ -15,6 +15,45 @@
9027 .endm
9028 #endif
9029
9030 +#ifdef KERNEXEC_PLUGIN
9031 + .macro pax_force_retaddr_bts rip=0
9032 + btsq $63,\rip(%rsp)
9033 + .endm
9034 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9035 + .macro pax_force_retaddr rip=0, reload=0
9036 + btsq $63,\rip(%rsp)
9037 + .endm
9038 + .macro pax_force_fptr ptr
9039 + btsq $63,\ptr
9040 + .endm
9041 + .macro pax_set_fptr_mask
9042 + .endm
9043 +#endif
9044 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9045 + .macro pax_force_retaddr rip=0, reload=0
9046 + .if \reload
9047 + pax_set_fptr_mask
9048 + .endif
9049 + orq %r10,\rip(%rsp)
9050 + .endm
9051 + .macro pax_force_fptr ptr
9052 + orq %r10,\ptr
9053 + .endm
9054 + .macro pax_set_fptr_mask
9055 + movabs $0x8000000000000000,%r10
9056 + .endm
9057 +#endif
9058 +#else
9059 + .macro pax_force_retaddr rip=0, reload=0
9060 + .endm
9061 + .macro pax_force_fptr ptr
9062 + .endm
9063 + .macro pax_force_retaddr_bts rip=0
9064 + .endm
9065 + .macro pax_set_fptr_mask
9066 + .endm
9067 +#endif
9068 +
9069 .macro altinstruction_entry orig alt feature orig_len alt_len
9070 .long \orig - .
9071 .long \alt - .
9072 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9073 index 7078068..f58bcda 100644
9074 --- a/arch/x86/include/asm/alternative.h
9075 +++ b/arch/x86/include/asm/alternative.h
9076 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 ".section .discard,\"aw\",@progbits\n" \
9078 DISCARD_ENTRY(1) \
9079 ".previous\n" \
9080 - ".section .altinstr_replacement, \"ax\"\n" \
9081 + ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9083 ".previous"
9084
9085 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9086 DISCARD_ENTRY(1) \
9087 DISCARD_ENTRY(2) \
9088 ".previous\n" \
9089 - ".section .altinstr_replacement, \"ax\"\n" \
9090 + ".section .altinstr_replacement, \"a\"\n" \
9091 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9092 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9093 ".previous"
9094 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9095 index f342612..b3fe911 100644
9096 --- a/arch/x86/include/asm/apic.h
9097 +++ b/arch/x86/include/asm/apic.h
9098 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9099
9100 #ifdef CONFIG_X86_LOCAL_APIC
9101
9102 -extern unsigned int apic_verbosity;
9103 +extern int apic_verbosity;
9104 extern int local_apic_timer_c2_ok;
9105
9106 extern int disable_apic;
9107 @@ -391,7 +391,7 @@ struct apic {
9108 */
9109 int (*x86_32_numa_cpu_node)(int cpu);
9110 #endif
9111 -};
9112 +} __do_const;
9113
9114 /*
9115 * Pointer to the local APIC driver in use on this system (there's
9116 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9117 index 20370c6..a2eb9b0 100644
9118 --- a/arch/x86/include/asm/apm.h
9119 +++ b/arch/x86/include/asm/apm.h
9120 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9121 __asm__ __volatile__(APM_DO_ZERO_SEGS
9122 "pushl %%edi\n\t"
9123 "pushl %%ebp\n\t"
9124 - "lcall *%%cs:apm_bios_entry\n\t"
9125 + "lcall *%%ss:apm_bios_entry\n\t"
9126 "setc %%al\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9130 __asm__ __volatile__(APM_DO_ZERO_SEGS
9131 "pushl %%edi\n\t"
9132 "pushl %%ebp\n\t"
9133 - "lcall *%%cs:apm_bios_entry\n\t"
9134 + "lcall *%%ss:apm_bios_entry\n\t"
9135 "setc %%bl\n\t"
9136 "popl %%ebp\n\t"
9137 "popl %%edi\n\t"
9138 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9139 index 58cb6d4..a4b806c 100644
9140 --- a/arch/x86/include/asm/atomic.h
9141 +++ b/arch/x86/include/asm/atomic.h
9142 @@ -22,7 +22,18 @@
9143 */
9144 static inline int atomic_read(const atomic_t *v)
9145 {
9146 - return (*(volatile int *)&(v)->counter);
9147 + return (*(volatile const int *)&(v)->counter);
9148 +}
9149 +
9150 +/**
9151 + * atomic_read_unchecked - read atomic variable
9152 + * @v: pointer of type atomic_unchecked_t
9153 + *
9154 + * Atomically reads the value of @v.
9155 + */
9156 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9157 +{
9158 + return (*(volatile const int *)&(v)->counter);
9159 }
9160
9161 /**
9162 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9163 }
9164
9165 /**
9166 + * atomic_set_unchecked - set atomic variable
9167 + * @v: pointer of type atomic_unchecked_t
9168 + * @i: required value
9169 + *
9170 + * Atomically sets the value of @v to @i.
9171 + */
9172 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9173 +{
9174 + v->counter = i;
9175 +}
9176 +
9177 +/**
9178 * atomic_add - add integer to atomic variable
9179 * @i: integer value to add
9180 * @v: pointer of type atomic_t
9181 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9182 */
9183 static inline void atomic_add(int i, atomic_t *v)
9184 {
9185 - asm volatile(LOCK_PREFIX "addl %1,%0"
9186 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9187 +
9188 +#ifdef CONFIG_PAX_REFCOUNT
9189 + "jno 0f\n"
9190 + LOCK_PREFIX "subl %1,%0\n"
9191 + "int $4\n0:\n"
9192 + _ASM_EXTABLE(0b, 0b)
9193 +#endif
9194 +
9195 + : "+m" (v->counter)
9196 + : "ir" (i));
9197 +}
9198 +
9199 +/**
9200 + * atomic_add_unchecked - add integer to atomic variable
9201 + * @i: integer value to add
9202 + * @v: pointer of type atomic_unchecked_t
9203 + *
9204 + * Atomically adds @i to @v.
9205 + */
9206 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9207 +{
9208 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9209 : "+m" (v->counter)
9210 : "ir" (i));
9211 }
9212 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9213 */
9214 static inline void atomic_sub(int i, atomic_t *v)
9215 {
9216 - asm volatile(LOCK_PREFIX "subl %1,%0"
9217 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9218 +
9219 +#ifdef CONFIG_PAX_REFCOUNT
9220 + "jno 0f\n"
9221 + LOCK_PREFIX "addl %1,%0\n"
9222 + "int $4\n0:\n"
9223 + _ASM_EXTABLE(0b, 0b)
9224 +#endif
9225 +
9226 + : "+m" (v->counter)
9227 + : "ir" (i));
9228 +}
9229 +
9230 +/**
9231 + * atomic_sub_unchecked - subtract integer from atomic variable
9232 + * @i: integer value to subtract
9233 + * @v: pointer of type atomic_unchecked_t
9234 + *
9235 + * Atomically subtracts @i from @v.
9236 + */
9237 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9238 +{
9239 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9240 : "+m" (v->counter)
9241 : "ir" (i));
9242 }
9243 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9244 {
9245 unsigned char c;
9246
9247 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9248 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9249 +
9250 +#ifdef CONFIG_PAX_REFCOUNT
9251 + "jno 0f\n"
9252 + LOCK_PREFIX "addl %2,%0\n"
9253 + "int $4\n0:\n"
9254 + _ASM_EXTABLE(0b, 0b)
9255 +#endif
9256 +
9257 + "sete %1\n"
9258 : "+m" (v->counter), "=qm" (c)
9259 : "ir" (i) : "memory");
9260 return c;
9261 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9262 */
9263 static inline void atomic_inc(atomic_t *v)
9264 {
9265 - asm volatile(LOCK_PREFIX "incl %0"
9266 + asm volatile(LOCK_PREFIX "incl %0\n"
9267 +
9268 +#ifdef CONFIG_PAX_REFCOUNT
9269 + "jno 0f\n"
9270 + LOCK_PREFIX "decl %0\n"
9271 + "int $4\n0:\n"
9272 + _ASM_EXTABLE(0b, 0b)
9273 +#endif
9274 +
9275 + : "+m" (v->counter));
9276 +}
9277 +
9278 +/**
9279 + * atomic_inc_unchecked - increment atomic variable
9280 + * @v: pointer of type atomic_unchecked_t
9281 + *
9282 + * Atomically increments @v by 1.
9283 + */
9284 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9285 +{
9286 + asm volatile(LOCK_PREFIX "incl %0\n"
9287 : "+m" (v->counter));
9288 }
9289
9290 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9291 */
9292 static inline void atomic_dec(atomic_t *v)
9293 {
9294 - asm volatile(LOCK_PREFIX "decl %0"
9295 + asm volatile(LOCK_PREFIX "decl %0\n"
9296 +
9297 +#ifdef CONFIG_PAX_REFCOUNT
9298 + "jno 0f\n"
9299 + LOCK_PREFIX "incl %0\n"
9300 + "int $4\n0:\n"
9301 + _ASM_EXTABLE(0b, 0b)
9302 +#endif
9303 +
9304 + : "+m" (v->counter));
9305 +}
9306 +
9307 +/**
9308 + * atomic_dec_unchecked - decrement atomic variable
9309 + * @v: pointer of type atomic_unchecked_t
9310 + *
9311 + * Atomically decrements @v by 1.
9312 + */
9313 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9314 +{
9315 + asm volatile(LOCK_PREFIX "decl %0\n"
9316 : "+m" (v->counter));
9317 }
9318
9319 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9320 {
9321 unsigned char c;
9322
9323 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9324 + asm volatile(LOCK_PREFIX "decl %0\n"
9325 +
9326 +#ifdef CONFIG_PAX_REFCOUNT
9327 + "jno 0f\n"
9328 + LOCK_PREFIX "incl %0\n"
9329 + "int $4\n0:\n"
9330 + _ASM_EXTABLE(0b, 0b)
9331 +#endif
9332 +
9333 + "sete %1\n"
9334 : "+m" (v->counter), "=qm" (c)
9335 : : "memory");
9336 return c != 0;
9337 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9338 {
9339 unsigned char c;
9340
9341 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9342 + asm volatile(LOCK_PREFIX "incl %0\n"
9343 +
9344 +#ifdef CONFIG_PAX_REFCOUNT
9345 + "jno 0f\n"
9346 + LOCK_PREFIX "decl %0\n"
9347 + "int $4\n0:\n"
9348 + _ASM_EXTABLE(0b, 0b)
9349 +#endif
9350 +
9351 + "sete %1\n"
9352 + : "+m" (v->counter), "=qm" (c)
9353 + : : "memory");
9354 + return c != 0;
9355 +}
9356 +
9357 +/**
9358 + * atomic_inc_and_test_unchecked - increment and test
9359 + * @v: pointer of type atomic_unchecked_t
9360 + *
9361 + * Atomically increments @v by 1
9362 + * and returns true if the result is zero, or false for all
9363 + * other cases.
9364 + */
9365 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9366 +{
9367 + unsigned char c;
9368 +
9369 + asm volatile(LOCK_PREFIX "incl %0\n"
9370 + "sete %1\n"
9371 : "+m" (v->counter), "=qm" (c)
9372 : : "memory");
9373 return c != 0;
9374 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9375 {
9376 unsigned char c;
9377
9378 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9379 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9380 +
9381 +#ifdef CONFIG_PAX_REFCOUNT
9382 + "jno 0f\n"
9383 + LOCK_PREFIX "subl %2,%0\n"
9384 + "int $4\n0:\n"
9385 + _ASM_EXTABLE(0b, 0b)
9386 +#endif
9387 +
9388 + "sets %1\n"
9389 : "+m" (v->counter), "=qm" (c)
9390 : "ir" (i) : "memory");
9391 return c;
9392 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9393 goto no_xadd;
9394 #endif
9395 /* Modern 486+ processor */
9396 - return i + xadd(&v->counter, i);
9397 + return i + xadd_check_overflow(&v->counter, i);
9398
9399 #ifdef CONFIG_M386
9400 no_xadd: /* Legacy 386 processor */
9401 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9402 }
9403
9404 /**
9405 + * atomic_add_return_unchecked - add integer and return
9406 + * @i: integer value to add
9407 + * @v: pointer of type atomic_unchecked_t
9408 + *
9409 + * Atomically adds @i to @v and returns @i + @v
9410 + */
9411 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9412 +{
9413 +#ifdef CONFIG_M386
9414 + int __i;
9415 + unsigned long flags;
9416 + if (unlikely(boot_cpu_data.x86 <= 3))
9417 + goto no_xadd;
9418 +#endif
9419 + /* Modern 486+ processor */
9420 + return i + xadd(&v->counter, i);
9421 +
9422 +#ifdef CONFIG_M386
9423 +no_xadd: /* Legacy 386 processor */
9424 + raw_local_irq_save(flags);
9425 + __i = atomic_read_unchecked(v);
9426 + atomic_set_unchecked(v, i + __i);
9427 + raw_local_irq_restore(flags);
9428 + return i + __i;
9429 +#endif
9430 +}
9431 +
9432 +/**
9433 * atomic_sub_return - subtract integer and return
9434 * @v: pointer of type atomic_t
9435 * @i: integer value to subtract
9436 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9437 }
9438
9439 #define atomic_inc_return(v) (atomic_add_return(1, v))
9440 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9441 +{
9442 + return atomic_add_return_unchecked(1, v);
9443 +}
9444 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9445
9446 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9447 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9448 return cmpxchg(&v->counter, old, new);
9449 }
9450
9451 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9452 +{
9453 + return cmpxchg(&v->counter, old, new);
9454 +}
9455 +
9456 static inline int atomic_xchg(atomic_t *v, int new)
9457 {
9458 return xchg(&v->counter, new);
9459 }
9460
9461 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9462 +{
9463 + return xchg(&v->counter, new);
9464 +}
9465 +
9466 /**
9467 * __atomic_add_unless - add unless the number is already a given value
9468 * @v: pointer of type atomic_t
9469 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9470 */
9471 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9472 {
9473 - int c, old;
9474 + int c, old, new;
9475 c = atomic_read(v);
9476 for (;;) {
9477 - if (unlikely(c == (u)))
9478 + if (unlikely(c == u))
9479 break;
9480 - old = atomic_cmpxchg((v), c, c + (a));
9481 +
9482 + asm volatile("addl %2,%0\n"
9483 +
9484 +#ifdef CONFIG_PAX_REFCOUNT
9485 + "jno 0f\n"
9486 + "subl %2,%0\n"
9487 + "int $4\n0:\n"
9488 + _ASM_EXTABLE(0b, 0b)
9489 +#endif
9490 +
9491 + : "=r" (new)
9492 + : "0" (c), "ir" (a));
9493 +
9494 + old = atomic_cmpxchg(v, c, new);
9495 if (likely(old == c))
9496 break;
9497 c = old;
9498 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9499 return c;
9500 }
9501
9502 +/**
9503 + * atomic_inc_not_zero_hint - increment if not null
9504 + * @v: pointer of type atomic_t
9505 + * @hint: probable value of the atomic before the increment
9506 + *
9507 + * This version of atomic_inc_not_zero() gives a hint of probable
9508 + * value of the atomic. This helps processor to not read the memory
9509 + * before doing the atomic read/modify/write cycle, lowering
9510 + * number of bus transactions on some arches.
9511 + *
9512 + * Returns: 0 if increment was not done, 1 otherwise.
9513 + */
9514 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9515 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9516 +{
9517 + int val, c = hint, new;
9518 +
9519 + /* sanity test, should be removed by compiler if hint is a constant */
9520 + if (!hint)
9521 + return __atomic_add_unless(v, 1, 0);
9522 +
9523 + do {
9524 + asm volatile("incl %0\n"
9525 +
9526 +#ifdef CONFIG_PAX_REFCOUNT
9527 + "jno 0f\n"
9528 + "decl %0\n"
9529 + "int $4\n0:\n"
9530 + _ASM_EXTABLE(0b, 0b)
9531 +#endif
9532 +
9533 + : "=r" (new)
9534 + : "0" (c));
9535 +
9536 + val = atomic_cmpxchg(v, c, new);
9537 + if (val == c)
9538 + return 1;
9539 + c = val;
9540 + } while (c);
9541 +
9542 + return 0;
9543 +}
9544
9545 /*
9546 * atomic_dec_if_positive - decrement by 1 if old value positive
9547 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9548 #endif
9549
9550 /* These are x86-specific, used by some header files */
9551 -#define atomic_clear_mask(mask, addr) \
9552 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9553 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9554 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9555 +{
9556 + asm volatile(LOCK_PREFIX "andl %1,%0"
9557 + : "+m" (v->counter)
9558 + : "r" (~(mask))
9559 + : "memory");
9560 +}
9561
9562 -#define atomic_set_mask(mask, addr) \
9563 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9564 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9565 - : "memory")
9566 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9567 +{
9568 + asm volatile(LOCK_PREFIX "andl %1,%0"
9569 + : "+m" (v->counter)
9570 + : "r" (~(mask))
9571 + : "memory");
9572 +}
9573 +
9574 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9575 +{
9576 + asm volatile(LOCK_PREFIX "orl %1,%0"
9577 + : "+m" (v->counter)
9578 + : "r" (mask)
9579 + : "memory");
9580 +}
9581 +
9582 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "orl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (mask)
9587 + : "memory");
9588 +}
9589
9590 /* Atomic operations are already serializing on x86 */
9591 #define smp_mb__before_atomic_dec() barrier()
9592 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9593 index b154de7..aadebd8 100644
9594 --- a/arch/x86/include/asm/atomic64_32.h
9595 +++ b/arch/x86/include/asm/atomic64_32.h
9596 @@ -12,6 +12,14 @@ typedef struct {
9597 u64 __aligned(8) counter;
9598 } atomic64_t;
9599
9600 +#ifdef CONFIG_PAX_REFCOUNT
9601 +typedef struct {
9602 + u64 __aligned(8) counter;
9603 +} atomic64_unchecked_t;
9604 +#else
9605 +typedef atomic64_t atomic64_unchecked_t;
9606 +#endif
9607 +
9608 #define ATOMIC64_INIT(val) { (val) }
9609
9610 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9611 @@ -37,21 +45,31 @@ typedef struct {
9612 ATOMIC64_DECL_ONE(sym##_386)
9613
9614 ATOMIC64_DECL_ONE(add_386);
9615 +ATOMIC64_DECL_ONE(add_unchecked_386);
9616 ATOMIC64_DECL_ONE(sub_386);
9617 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9618 ATOMIC64_DECL_ONE(inc_386);
9619 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9620 ATOMIC64_DECL_ONE(dec_386);
9621 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9622 #endif
9623
9624 #define alternative_atomic64(f, out, in...) \
9625 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9626
9627 ATOMIC64_DECL(read);
9628 +ATOMIC64_DECL(read_unchecked);
9629 ATOMIC64_DECL(set);
9630 +ATOMIC64_DECL(set_unchecked);
9631 ATOMIC64_DECL(xchg);
9632 ATOMIC64_DECL(add_return);
9633 +ATOMIC64_DECL(add_return_unchecked);
9634 ATOMIC64_DECL(sub_return);
9635 +ATOMIC64_DECL(sub_return_unchecked);
9636 ATOMIC64_DECL(inc_return);
9637 +ATOMIC64_DECL(inc_return_unchecked);
9638 ATOMIC64_DECL(dec_return);
9639 +ATOMIC64_DECL(dec_return_unchecked);
9640 ATOMIC64_DECL(dec_if_positive);
9641 ATOMIC64_DECL(inc_not_zero);
9642 ATOMIC64_DECL(add_unless);
9643 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9644 }
9645
9646 /**
9647 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9648 + * @p: pointer to type atomic64_unchecked_t
9649 + * @o: expected value
9650 + * @n: new value
9651 + *
9652 + * Atomically sets @v to @n if it was equal to @o and returns
9653 + * the old value.
9654 + */
9655 +
9656 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9657 +{
9658 + return cmpxchg64(&v->counter, o, n);
9659 +}
9660 +
9661 +/**
9662 * atomic64_xchg - xchg atomic64 variable
9663 * @v: pointer to type atomic64_t
9664 * @n: value to assign
9665 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9666 }
9667
9668 /**
9669 + * atomic64_set_unchecked - set atomic64 variable
9670 + * @v: pointer to type atomic64_unchecked_t
9671 + * @n: value to assign
9672 + *
9673 + * Atomically sets the value of @v to @n.
9674 + */
9675 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9676 +{
9677 + unsigned high = (unsigned)(i >> 32);
9678 + unsigned low = (unsigned)i;
9679 + alternative_atomic64(set, /* no output */,
9680 + "S" (v), "b" (low), "c" (high)
9681 + : "eax", "edx", "memory");
9682 +}
9683 +
9684 +/**
9685 * atomic64_read - read atomic64 variable
9686 * @v: pointer to type atomic64_t
9687 *
9688 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9689 }
9690
9691 /**
9692 + * atomic64_read_unchecked - read atomic64 variable
9693 + * @v: pointer to type atomic64_unchecked_t
9694 + *
9695 + * Atomically reads the value of @v and returns it.
9696 + */
9697 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9698 +{
9699 + long long r;
9700 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9701 + return r;
9702 + }
9703 +
9704 +/**
9705 * atomic64_add_return - add and return
9706 * @i: integer value to add
9707 * @v: pointer to type atomic64_t
9708 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9709 return i;
9710 }
9711
9712 +/**
9713 + * atomic64_add_return_unchecked - add and return
9714 + * @i: integer value to add
9715 + * @v: pointer to type atomic64_unchecked_t
9716 + *
9717 + * Atomically adds @i to @v and returns @i + *@v
9718 + */
9719 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9720 +{
9721 + alternative_atomic64(add_return_unchecked,
9722 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9723 + ASM_NO_INPUT_CLOBBER("memory"));
9724 + return i;
9725 +}
9726 +
9727 /*
9728 * Other variants with different arithmetic operators:
9729 */
9730 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9731 return a;
9732 }
9733
9734 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9735 +{
9736 + long long a;
9737 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9738 + "S" (v) : "memory", "ecx");
9739 + return a;
9740 +}
9741 +
9742 static inline long long atomic64_dec_return(atomic64_t *v)
9743 {
9744 long long a;
9745 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9746 }
9747
9748 /**
9749 + * atomic64_add_unchecked - add integer to atomic64 variable
9750 + * @i: integer value to add
9751 + * @v: pointer to type atomic64_unchecked_t
9752 + *
9753 + * Atomically adds @i to @v.
9754 + */
9755 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9756 +{
9757 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9758 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9759 + ASM_NO_INPUT_CLOBBER("memory"));
9760 + return i;
9761 +}
9762 +
9763 +/**
9764 * atomic64_sub - subtract the atomic64 variable
9765 * @i: integer value to subtract
9766 * @v: pointer to type atomic64_t
9767 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9768 index 0e1cbfc..5623683 100644
9769 --- a/arch/x86/include/asm/atomic64_64.h
9770 +++ b/arch/x86/include/asm/atomic64_64.h
9771 @@ -18,7 +18,19 @@
9772 */
9773 static inline long atomic64_read(const atomic64_t *v)
9774 {
9775 - return (*(volatile long *)&(v)->counter);
9776 + return (*(volatile const long *)&(v)->counter);
9777 +}
9778 +
9779 +/**
9780 + * atomic64_read_unchecked - read atomic64 variable
9781 + * @v: pointer of type atomic64_unchecked_t
9782 + *
9783 + * Atomically reads the value of @v.
9784 + * Doesn't imply a read memory barrier.
9785 + */
9786 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9787 +{
9788 + return (*(volatile const long *)&(v)->counter);
9789 }
9790
9791 /**
9792 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9793 }
9794
9795 /**
9796 + * atomic64_set_unchecked - set atomic64 variable
9797 + * @v: pointer to type atomic64_unchecked_t
9798 + * @i: required value
9799 + *
9800 + * Atomically sets the value of @v to @i.
9801 + */
9802 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9803 +{
9804 + v->counter = i;
9805 +}
9806 +
9807 +/**
9808 * atomic64_add - add integer to atomic64 variable
9809 * @i: integer value to add
9810 * @v: pointer to type atomic64_t
9811 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9812 */
9813 static inline void atomic64_add(long i, atomic64_t *v)
9814 {
9815 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9816 +
9817 +#ifdef CONFIG_PAX_REFCOUNT
9818 + "jno 0f\n"
9819 + LOCK_PREFIX "subq %1,%0\n"
9820 + "int $4\n0:\n"
9821 + _ASM_EXTABLE(0b, 0b)
9822 +#endif
9823 +
9824 + : "=m" (v->counter)
9825 + : "er" (i), "m" (v->counter));
9826 +}
9827 +
9828 +/**
9829 + * atomic64_add_unchecked - add integer to atomic64 variable
9830 + * @i: integer value to add
9831 + * @v: pointer to type atomic64_unchecked_t
9832 + *
9833 + * Atomically adds @i to @v.
9834 + */
9835 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9836 +{
9837 asm volatile(LOCK_PREFIX "addq %1,%0"
9838 : "=m" (v->counter)
9839 : "er" (i), "m" (v->counter));
9840 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9841 */
9842 static inline void atomic64_sub(long i, atomic64_t *v)
9843 {
9844 - asm volatile(LOCK_PREFIX "subq %1,%0"
9845 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9846 +
9847 +#ifdef CONFIG_PAX_REFCOUNT
9848 + "jno 0f\n"
9849 + LOCK_PREFIX "addq %1,%0\n"
9850 + "int $4\n0:\n"
9851 + _ASM_EXTABLE(0b, 0b)
9852 +#endif
9853 +
9854 + : "=m" (v->counter)
9855 + : "er" (i), "m" (v->counter));
9856 +}
9857 +
9858 +/**
9859 + * atomic64_sub_unchecked - subtract the atomic64 variable
9860 + * @i: integer value to subtract
9861 + * @v: pointer to type atomic64_unchecked_t
9862 + *
9863 + * Atomically subtracts @i from @v.
9864 + */
9865 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9866 +{
9867 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9868 : "=m" (v->counter)
9869 : "er" (i), "m" (v->counter));
9870 }
9871 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9872 {
9873 unsigned char c;
9874
9875 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9876 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9877 +
9878 +#ifdef CONFIG_PAX_REFCOUNT
9879 + "jno 0f\n"
9880 + LOCK_PREFIX "addq %2,%0\n"
9881 + "int $4\n0:\n"
9882 + _ASM_EXTABLE(0b, 0b)
9883 +#endif
9884 +
9885 + "sete %1\n"
9886 : "=m" (v->counter), "=qm" (c)
9887 : "er" (i), "m" (v->counter) : "memory");
9888 return c;
9889 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9890 */
9891 static inline void atomic64_inc(atomic64_t *v)
9892 {
9893 + asm volatile(LOCK_PREFIX "incq %0\n"
9894 +
9895 +#ifdef CONFIG_PAX_REFCOUNT
9896 + "jno 0f\n"
9897 + LOCK_PREFIX "decq %0\n"
9898 + "int $4\n0:\n"
9899 + _ASM_EXTABLE(0b, 0b)
9900 +#endif
9901 +
9902 + : "=m" (v->counter)
9903 + : "m" (v->counter));
9904 +}
9905 +
9906 +/**
9907 + * atomic64_inc_unchecked - increment atomic64 variable
9908 + * @v: pointer to type atomic64_unchecked_t
9909 + *
9910 + * Atomically increments @v by 1.
9911 + */
9912 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9913 +{
9914 asm volatile(LOCK_PREFIX "incq %0"
9915 : "=m" (v->counter)
9916 : "m" (v->counter));
9917 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9918 */
9919 static inline void atomic64_dec(atomic64_t *v)
9920 {
9921 - asm volatile(LOCK_PREFIX "decq %0"
9922 + asm volatile(LOCK_PREFIX "decq %0\n"
9923 +
9924 +#ifdef CONFIG_PAX_REFCOUNT
9925 + "jno 0f\n"
9926 + LOCK_PREFIX "incq %0\n"
9927 + "int $4\n0:\n"
9928 + _ASM_EXTABLE(0b, 0b)
9929 +#endif
9930 +
9931 + : "=m" (v->counter)
9932 + : "m" (v->counter));
9933 +}
9934 +
9935 +/**
9936 + * atomic64_dec_unchecked - decrement atomic64 variable
9937 + * @v: pointer to type atomic64_t
9938 + *
9939 + * Atomically decrements @v by 1.
9940 + */
9941 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9942 +{
9943 + asm volatile(LOCK_PREFIX "decq %0\n"
9944 : "=m" (v->counter)
9945 : "m" (v->counter));
9946 }
9947 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9948 {
9949 unsigned char c;
9950
9951 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9952 + asm volatile(LOCK_PREFIX "decq %0\n"
9953 +
9954 +#ifdef CONFIG_PAX_REFCOUNT
9955 + "jno 0f\n"
9956 + LOCK_PREFIX "incq %0\n"
9957 + "int $4\n0:\n"
9958 + _ASM_EXTABLE(0b, 0b)
9959 +#endif
9960 +
9961 + "sete %1\n"
9962 : "=m" (v->counter), "=qm" (c)
9963 : "m" (v->counter) : "memory");
9964 return c != 0;
9965 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9966 {
9967 unsigned char c;
9968
9969 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9970 + asm volatile(LOCK_PREFIX "incq %0\n"
9971 +
9972 +#ifdef CONFIG_PAX_REFCOUNT
9973 + "jno 0f\n"
9974 + LOCK_PREFIX "decq %0\n"
9975 + "int $4\n0:\n"
9976 + _ASM_EXTABLE(0b, 0b)
9977 +#endif
9978 +
9979 + "sete %1\n"
9980 : "=m" (v->counter), "=qm" (c)
9981 : "m" (v->counter) : "memory");
9982 return c != 0;
9983 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9984 {
9985 unsigned char c;
9986
9987 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9988 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9989 +
9990 +#ifdef CONFIG_PAX_REFCOUNT
9991 + "jno 0f\n"
9992 + LOCK_PREFIX "subq %2,%0\n"
9993 + "int $4\n0:\n"
9994 + _ASM_EXTABLE(0b, 0b)
9995 +#endif
9996 +
9997 + "sets %1\n"
9998 : "=m" (v->counter), "=qm" (c)
9999 : "er" (i), "m" (v->counter) : "memory");
10000 return c;
10001 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10002 */
10003 static inline long atomic64_add_return(long i, atomic64_t *v)
10004 {
10005 + return i + xadd_check_overflow(&v->counter, i);
10006 +}
10007 +
10008 +/**
10009 + * atomic64_add_return_unchecked - add and return
10010 + * @i: integer value to add
10011 + * @v: pointer to type atomic64_unchecked_t
10012 + *
10013 + * Atomically adds @i to @v and returns @i + @v
10014 + */
10015 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10016 +{
10017 return i + xadd(&v->counter, i);
10018 }
10019
10020 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10021 }
10022
10023 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10024 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10025 +{
10026 + return atomic64_add_return_unchecked(1, v);
10027 +}
10028 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10029
10030 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10031 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10032 return cmpxchg(&v->counter, old, new);
10033 }
10034
10035 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10036 +{
10037 + return cmpxchg(&v->counter, old, new);
10038 +}
10039 +
10040 static inline long atomic64_xchg(atomic64_t *v, long new)
10041 {
10042 return xchg(&v->counter, new);
10043 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10044 */
10045 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10046 {
10047 - long c, old;
10048 + long c, old, new;
10049 c = atomic64_read(v);
10050 for (;;) {
10051 - if (unlikely(c == (u)))
10052 + if (unlikely(c == u))
10053 break;
10054 - old = atomic64_cmpxchg((v), c, c + (a));
10055 +
10056 + asm volatile("add %2,%0\n"
10057 +
10058 +#ifdef CONFIG_PAX_REFCOUNT
10059 + "jno 0f\n"
10060 + "sub %2,%0\n"
10061 + "int $4\n0:\n"
10062 + _ASM_EXTABLE(0b, 0b)
10063 +#endif
10064 +
10065 + : "=r" (new)
10066 + : "0" (c), "ir" (a));
10067 +
10068 + old = atomic64_cmpxchg(v, c, new);
10069 if (likely(old == c))
10070 break;
10071 c = old;
10072 }
10073 - return c != (u);
10074 + return c != u;
10075 }
10076
10077 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10078 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10079 index 72f5009..2f8b9a9 100644
10080 --- a/arch/x86/include/asm/bitops.h
10081 +++ b/arch/x86/include/asm/bitops.h
10082 @@ -40,7 +40,7 @@
10083 * a mask operation on a byte.
10084 */
10085 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10086 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10087 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10088 #define CONST_MASK(nr) (1 << ((nr) & 7))
10089
10090 /**
10091 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10092 index b13fe63..0dab13a 100644
10093 --- a/arch/x86/include/asm/boot.h
10094 +++ b/arch/x86/include/asm/boot.h
10095 @@ -11,10 +11,15 @@
10096 #include <asm/pgtable_types.h>
10097
10098 /* Physical address where kernel should be loaded. */
10099 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10100 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10101 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10102 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10103
10104 +#ifndef __ASSEMBLY__
10105 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10106 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10107 +#endif
10108 +
10109 /* Minimum kernel alignment, as a power of two */
10110 #ifdef CONFIG_X86_64
10111 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10112 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10113 index 48f99f1..d78ebf9 100644
10114 --- a/arch/x86/include/asm/cache.h
10115 +++ b/arch/x86/include/asm/cache.h
10116 @@ -5,12 +5,13 @@
10117
10118 /* L1 cache line size */
10119 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10120 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10121 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10122
10123 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10124 +#define __read_only __attribute__((__section__(".data..read_only")))
10125
10126 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10127 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10128 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10129
10130 #ifdef CONFIG_X86_VSMP
10131 #ifdef CONFIG_SMP
10132 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10133 index 9863ee3..4a1f8e1 100644
10134 --- a/arch/x86/include/asm/cacheflush.h
10135 +++ b/arch/x86/include/asm/cacheflush.h
10136 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10138
10139 if (pg_flags == _PGMT_DEFAULT)
10140 - return -1;
10141 + return ~0UL;
10142 else if (pg_flags == _PGMT_WC)
10143 return _PAGE_CACHE_WC;
10144 else if (pg_flags == _PGMT_UC_MINUS)
10145 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10146 index 46fc474..b02b0f9 100644
10147 --- a/arch/x86/include/asm/checksum_32.h
10148 +++ b/arch/x86/include/asm/checksum_32.h
10149 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10150 int len, __wsum sum,
10151 int *src_err_ptr, int *dst_err_ptr);
10152
10153 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10154 + int len, __wsum sum,
10155 + int *src_err_ptr, int *dst_err_ptr);
10156 +
10157 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10158 + int len, __wsum sum,
10159 + int *src_err_ptr, int *dst_err_ptr);
10160 +
10161 /*
10162 * Note: when you get a NULL pointer exception here this means someone
10163 * passed in an incorrect kernel address to one of these functions.
10164 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10165 int *err_ptr)
10166 {
10167 might_sleep();
10168 - return csum_partial_copy_generic((__force void *)src, dst,
10169 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10170 len, sum, err_ptr, NULL);
10171 }
10172
10173 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10174 {
10175 might_sleep();
10176 if (access_ok(VERIFY_WRITE, dst, len))
10177 - return csum_partial_copy_generic(src, (__force void *)dst,
10178 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10179 len, sum, NULL, err_ptr);
10180
10181 if (len)
10182 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10183 index 99480e5..d81165b 100644
10184 --- a/arch/x86/include/asm/cmpxchg.h
10185 +++ b/arch/x86/include/asm/cmpxchg.h
10186 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10187 __compiletime_error("Bad argument size for cmpxchg");
10188 extern void __xadd_wrong_size(void)
10189 __compiletime_error("Bad argument size for xadd");
10190 +extern void __xadd_check_overflow_wrong_size(void)
10191 + __compiletime_error("Bad argument size for xadd_check_overflow");
10192 extern void __add_wrong_size(void)
10193 __compiletime_error("Bad argument size for add");
10194 +extern void __add_check_overflow_wrong_size(void)
10195 + __compiletime_error("Bad argument size for add_check_overflow");
10196
10197 /*
10198 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10199 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10200 __ret; \
10201 })
10202
10203 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10204 + ({ \
10205 + __typeof__ (*(ptr)) __ret = (arg); \
10206 + switch (sizeof(*(ptr))) { \
10207 + case __X86_CASE_L: \
10208 + asm volatile (lock #op "l %0, %1\n" \
10209 + "jno 0f\n" \
10210 + "mov %0,%1\n" \
10211 + "int $4\n0:\n" \
10212 + _ASM_EXTABLE(0b, 0b) \
10213 + : "+r" (__ret), "+m" (*(ptr)) \
10214 + : : "memory", "cc"); \
10215 + break; \
10216 + case __X86_CASE_Q: \
10217 + asm volatile (lock #op "q %q0, %1\n" \
10218 + "jno 0f\n" \
10219 + "mov %0,%1\n" \
10220 + "int $4\n0:\n" \
10221 + _ASM_EXTABLE(0b, 0b) \
10222 + : "+r" (__ret), "+m" (*(ptr)) \
10223 + : : "memory", "cc"); \
10224 + break; \
10225 + default: \
10226 + __ ## op ## _check_overflow_wrong_size(); \
10227 + } \
10228 + __ret; \
10229 + })
10230 +
10231 /*
10232 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10233 * Since this is generally used to protect other memory information, we
10234 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10235 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10236 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10237
10238 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10239 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10240 +
10241 #define __add(ptr, inc, lock) \
10242 ({ \
10243 __typeof__ (*(ptr)) __ret = (inc); \
10244 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10245 index 6b7ee5f..9d664b3 100644
10246 --- a/arch/x86/include/asm/cpufeature.h
10247 +++ b/arch/x86/include/asm/cpufeature.h
10248 @@ -202,13 +202,14 @@
10249 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10250 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10251 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10252 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10253 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10254 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10255 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10256 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10257 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10258 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10259 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10260 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10261
10262 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10263
10264 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10265 ".section .discard,\"aw\",@progbits\n"
10266 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10267 ".previous\n"
10268 - ".section .altinstr_replacement,\"ax\"\n"
10269 + ".section .altinstr_replacement,\"a\"\n"
10270 "3: movb $1,%0\n"
10271 "4:\n"
10272 ".previous\n"
10273 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10274 index 8bf1c06..f723dfd 100644
10275 --- a/arch/x86/include/asm/desc.h
10276 +++ b/arch/x86/include/asm/desc.h
10277 @@ -4,6 +4,7 @@
10278 #include <asm/desc_defs.h>
10279 #include <asm/ldt.h>
10280 #include <asm/mmu.h>
10281 +#include <asm/pgtable.h>
10282
10283 #include <linux/smp.h>
10284 #include <linux/percpu.h>
10285 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10286
10287 desc->type = (info->read_exec_only ^ 1) << 1;
10288 desc->type |= info->contents << 2;
10289 + desc->type |= info->seg_not_present ^ 1;
10290
10291 desc->s = 1;
10292 desc->dpl = 0x3;
10293 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10294 }
10295
10296 extern struct desc_ptr idt_descr;
10297 -extern gate_desc idt_table[];
10298 extern struct desc_ptr nmi_idt_descr;
10299 -extern gate_desc nmi_idt_table[];
10300 -
10301 -struct gdt_page {
10302 - struct desc_struct gdt[GDT_ENTRIES];
10303 -} __attribute__((aligned(PAGE_SIZE)));
10304 -
10305 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10306 +extern gate_desc idt_table[256];
10307 +extern gate_desc nmi_idt_table[256];
10308
10309 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10310 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10311 {
10312 - return per_cpu(gdt_page, cpu).gdt;
10313 + return cpu_gdt_table[cpu];
10314 }
10315
10316 #ifdef CONFIG_X86_64
10317 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10318 unsigned long base, unsigned dpl, unsigned flags,
10319 unsigned short seg)
10320 {
10321 - gate->a = (seg << 16) | (base & 0xffff);
10322 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10323 + gate->gate.offset_low = base;
10324 + gate->gate.seg = seg;
10325 + gate->gate.reserved = 0;
10326 + gate->gate.type = type;
10327 + gate->gate.s = 0;
10328 + gate->gate.dpl = dpl;
10329 + gate->gate.p = 1;
10330 + gate->gate.offset_high = base >> 16;
10331 }
10332
10333 #endif
10334 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10335
10336 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10337 {
10338 + pax_open_kernel();
10339 memcpy(&idt[entry], gate, sizeof(*gate));
10340 + pax_close_kernel();
10341 }
10342
10343 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10344 {
10345 + pax_open_kernel();
10346 memcpy(&ldt[entry], desc, 8);
10347 + pax_close_kernel();
10348 }
10349
10350 static inline void
10351 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10352 default: size = sizeof(*gdt); break;
10353 }
10354
10355 + pax_open_kernel();
10356 memcpy(&gdt[entry], desc, size);
10357 + pax_close_kernel();
10358 }
10359
10360 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10361 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10362
10363 static inline void native_load_tr_desc(void)
10364 {
10365 + pax_open_kernel();
10366 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10367 + pax_close_kernel();
10368 }
10369
10370 static inline void native_load_gdt(const struct desc_ptr *dtr)
10371 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10372 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10373 unsigned int i;
10374
10375 + pax_open_kernel();
10376 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10377 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10378 + pax_close_kernel();
10379 }
10380
10381 #define _LDT_empty(info) \
10382 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10383 }
10384
10385 #ifdef CONFIG_X86_64
10386 -static inline void set_nmi_gate(int gate, void *addr)
10387 +static inline void set_nmi_gate(int gate, const void *addr)
10388 {
10389 gate_desc s;
10390
10391 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10392 }
10393 #endif
10394
10395 -static inline void _set_gate(int gate, unsigned type, void *addr,
10396 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10397 unsigned dpl, unsigned ist, unsigned seg)
10398 {
10399 gate_desc s;
10400 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10401 * Pentium F0 0F bugfix can have resulted in the mapped
10402 * IDT being write-protected.
10403 */
10404 -static inline void set_intr_gate(unsigned int n, void *addr)
10405 +static inline void set_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10409 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10410 /*
10411 * This routine sets up an interrupt gate at directory privilege level 3.
10412 */
10413 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10414 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10415 {
10416 BUG_ON((unsigned)n > 0xFF);
10417 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10418 }
10419
10420 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10421 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10422 {
10423 BUG_ON((unsigned)n > 0xFF);
10424 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10425 }
10426
10427 -static inline void set_trap_gate(unsigned int n, void *addr)
10428 +static inline void set_trap_gate(unsigned int n, const void *addr)
10429 {
10430 BUG_ON((unsigned)n > 0xFF);
10431 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10432 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10433 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10437 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10438 }
10439
10440 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10441 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10442 {
10443 BUG_ON((unsigned)n > 0xFF);
10444 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10445 }
10446
10447 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10448 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10449 {
10450 BUG_ON((unsigned)n > 0xFF);
10451 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10452 }
10453
10454 +#ifdef CONFIG_X86_32
10455 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10456 +{
10457 + struct desc_struct d;
10458 +
10459 + if (likely(limit))
10460 + limit = (limit - 1UL) >> PAGE_SHIFT;
10461 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10462 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10463 +}
10464 +#endif
10465 +
10466 #endif /* _ASM_X86_DESC_H */
10467 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10468 index 278441f..b95a174 100644
10469 --- a/arch/x86/include/asm/desc_defs.h
10470 +++ b/arch/x86/include/asm/desc_defs.h
10471 @@ -31,6 +31,12 @@ struct desc_struct {
10472 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10473 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10474 };
10475 + struct {
10476 + u16 offset_low;
10477 + u16 seg;
10478 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10479 + unsigned offset_high: 16;
10480 + } gate;
10481 };
10482 } __attribute__((packed));
10483
10484 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10485 index 3778256..c5d4fce 100644
10486 --- a/arch/x86/include/asm/e820.h
10487 +++ b/arch/x86/include/asm/e820.h
10488 @@ -69,7 +69,7 @@ struct e820map {
10489 #define ISA_START_ADDRESS 0xa0000
10490 #define ISA_END_ADDRESS 0x100000
10491
10492 -#define BIOS_BEGIN 0x000a0000
10493 +#define BIOS_BEGIN 0x000c0000
10494 #define BIOS_END 0x00100000
10495
10496 #define BIOS_ROM_BASE 0xffe00000
10497 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10498 index 5939f44..f8845f6 100644
10499 --- a/arch/x86/include/asm/elf.h
10500 +++ b/arch/x86/include/asm/elf.h
10501 @@ -243,7 +243,25 @@ extern int force_personality32;
10502 the loader. We need to make sure that it is out of the way of the program
10503 that it will "exec", and that there is sufficient room for the brk. */
10504
10505 +#ifdef CONFIG_PAX_SEGMEXEC
10506 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10507 +#else
10508 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10509 +#endif
10510 +
10511 +#ifdef CONFIG_PAX_ASLR
10512 +#ifdef CONFIG_X86_32
10513 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10514 +
10515 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10516 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10517 +#else
10518 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10519 +
10520 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10521 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10522 +#endif
10523 +#endif
10524
10525 /* This yields a mask that user programs can use to figure out what
10526 instruction set this CPU supports. This could be done in user space,
10527 @@ -296,16 +314,12 @@ do { \
10528
10529 #define ARCH_DLINFO \
10530 do { \
10531 - if (vdso_enabled) \
10532 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10533 - (unsigned long)current->mm->context.vdso); \
10534 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10535 } while (0)
10536
10537 #define ARCH_DLINFO_X32 \
10538 do { \
10539 - if (vdso_enabled) \
10540 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10541 - (unsigned long)current->mm->context.vdso); \
10542 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10543 } while (0)
10544
10545 #define AT_SYSINFO 32
10546 @@ -320,7 +334,7 @@ else \
10547
10548 #endif /* !CONFIG_X86_32 */
10549
10550 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10551 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10552
10553 #define VDSO_ENTRY \
10554 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10555 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10556 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10557 #define compat_arch_setup_additional_pages syscall32_setup_pages
10558
10559 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10560 -#define arch_randomize_brk arch_randomize_brk
10561 -
10562 /*
10563 * True on X86_32 or when emulating IA32 on X86_64
10564 */
10565 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10566 index 75ce3f4..882e801 100644
10567 --- a/arch/x86/include/asm/emergency-restart.h
10568 +++ b/arch/x86/include/asm/emergency-restart.h
10569 @@ -13,6 +13,6 @@ enum reboot_type {
10570
10571 extern enum reboot_type reboot_type;
10572
10573 -extern void machine_emergency_restart(void);
10574 +extern void machine_emergency_restart(void) __noreturn;
10575
10576 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10577 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10578 index 75f4c6d..ee3eb8f 100644
10579 --- a/arch/x86/include/asm/fpu-internal.h
10580 +++ b/arch/x86/include/asm/fpu-internal.h
10581 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10582 {
10583 int err;
10584
10585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10586 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10587 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10588 +#endif
10589 +
10590 /* See comment in fxsave() below. */
10591 #ifdef CONFIG_AS_FXSAVEQ
10592 asm volatile("1: fxrstorq %[fx]\n\t"
10593 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10594 {
10595 int err;
10596
10597 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10598 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10599 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10600 +#endif
10601 +
10602 /*
10603 * Clear the bytes not touched by the fxsave and reserved
10604 * for the SW usage.
10605 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10606 "emms\n\t" /* clear stack tags */
10607 "fildl %P[addr]", /* set F?P to defined value */
10608 X86_FEATURE_FXSAVE_LEAK,
10609 - [addr] "m" (tsk->thread.fpu.has_fpu));
10610 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10611
10612 return fpu_restore_checking(&tsk->thread.fpu);
10613 }
10614 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10615 index 71ecbcb..bac10b7 100644
10616 --- a/arch/x86/include/asm/futex.h
10617 +++ b/arch/x86/include/asm/futex.h
10618 @@ -11,16 +11,18 @@
10619 #include <asm/processor.h>
10620
10621 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10622 + typecheck(u32 __user *, uaddr); \
10623 asm volatile("1:\t" insn "\n" \
10624 "2:\t.section .fixup,\"ax\"\n" \
10625 "3:\tmov\t%3, %1\n" \
10626 "\tjmp\t2b\n" \
10627 "\t.previous\n" \
10628 _ASM_EXTABLE(1b, 3b) \
10629 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10630 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10631 : "i" (-EFAULT), "0" (oparg), "1" (0))
10632
10633 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10634 + typecheck(u32 __user *, uaddr); \
10635 asm volatile("1:\tmovl %2, %0\n" \
10636 "\tmovl\t%0, %3\n" \
10637 "\t" insn "\n" \
10638 @@ -33,7 +35,7 @@
10639 _ASM_EXTABLE(1b, 4b) \
10640 _ASM_EXTABLE(2b, 4b) \
10641 : "=&a" (oldval), "=&r" (ret), \
10642 - "+m" (*uaddr), "=&r" (tem) \
10643 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10644 : "r" (oparg), "i" (-EFAULT), "1" (0))
10645
10646 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10647 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10648
10649 switch (op) {
10650 case FUTEX_OP_SET:
10651 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10652 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10653 break;
10654 case FUTEX_OP_ADD:
10655 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10656 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10657 uaddr, oparg);
10658 break;
10659 case FUTEX_OP_OR:
10660 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10661 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10662 return -EFAULT;
10663
10664 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10665 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10666 "2:\t.section .fixup, \"ax\"\n"
10667 "3:\tmov %3, %0\n"
10668 "\tjmp 2b\n"
10669 "\t.previous\n"
10670 _ASM_EXTABLE(1b, 3b)
10671 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10672 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10673 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10674 : "memory"
10675 );
10676 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10677 index eb92a6e..b98b2f4 100644
10678 --- a/arch/x86/include/asm/hw_irq.h
10679 +++ b/arch/x86/include/asm/hw_irq.h
10680 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10681 extern void enable_IO_APIC(void);
10682
10683 /* Statistics */
10684 -extern atomic_t irq_err_count;
10685 -extern atomic_t irq_mis_count;
10686 +extern atomic_unchecked_t irq_err_count;
10687 +extern atomic_unchecked_t irq_mis_count;
10688
10689 /* EISA */
10690 extern void eisa_set_level_irq(unsigned int irq);
10691 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10692 index d8e8eef..99f81ae 100644
10693 --- a/arch/x86/include/asm/io.h
10694 +++ b/arch/x86/include/asm/io.h
10695 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10696
10697 #include <linux/vmalloc.h>
10698
10699 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10700 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10701 +{
10702 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10703 +}
10704 +
10705 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10706 +{
10707 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10708 +}
10709 +
10710 /*
10711 * Convert a virtual cached pointer to an uncached pointer
10712 */
10713 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10714 index bba3cf8..06bc8da 100644
10715 --- a/arch/x86/include/asm/irqflags.h
10716 +++ b/arch/x86/include/asm/irqflags.h
10717 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10718 sti; \
10719 sysexit
10720
10721 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10722 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10723 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10724 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10725 +
10726 #else
10727 #define INTERRUPT_RETURN iret
10728 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10729 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10730 index 5478825..839e88c 100644
10731 --- a/arch/x86/include/asm/kprobes.h
10732 +++ b/arch/x86/include/asm/kprobes.h
10733 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10734 #define RELATIVEJUMP_SIZE 5
10735 #define RELATIVECALL_OPCODE 0xe8
10736 #define RELATIVE_ADDR_SIZE 4
10737 -#define MAX_STACK_SIZE 64
10738 -#define MIN_STACK_SIZE(ADDR) \
10739 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10740 - THREAD_SIZE - (unsigned long)(ADDR))) \
10741 - ? (MAX_STACK_SIZE) \
10742 - : (((unsigned long)current_thread_info()) + \
10743 - THREAD_SIZE - (unsigned long)(ADDR)))
10744 +#define MAX_STACK_SIZE 64UL
10745 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10746
10747 #define flush_insn_slot(p) do { } while (0)
10748
10749 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10750 index 09155d6..d2e6df9 100644
10751 --- a/arch/x86/include/asm/kvm_host.h
10752 +++ b/arch/x86/include/asm/kvm_host.h
10753 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10754 int (*check_intercept)(struct kvm_vcpu *vcpu,
10755 struct x86_instruction_info *info,
10756 enum x86_intercept_stage stage);
10757 -};
10758 +} __do_const;
10759
10760 struct kvm_arch_async_pf {
10761 u32 token;
10762 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10763 index c8bed0d..e5721fa 100644
10764 --- a/arch/x86/include/asm/local.h
10765 +++ b/arch/x86/include/asm/local.h
10766 @@ -17,26 +17,58 @@ typedef struct {
10767
10768 static inline void local_inc(local_t *l)
10769 {
10770 - asm volatile(_ASM_INC "%0"
10771 + asm volatile(_ASM_INC "%0\n"
10772 +
10773 +#ifdef CONFIG_PAX_REFCOUNT
10774 + "jno 0f\n"
10775 + _ASM_DEC "%0\n"
10776 + "int $4\n0:\n"
10777 + _ASM_EXTABLE(0b, 0b)
10778 +#endif
10779 +
10780 : "+m" (l->a.counter));
10781 }
10782
10783 static inline void local_dec(local_t *l)
10784 {
10785 - asm volatile(_ASM_DEC "%0"
10786 + asm volatile(_ASM_DEC "%0\n"
10787 +
10788 +#ifdef CONFIG_PAX_REFCOUNT
10789 + "jno 0f\n"
10790 + _ASM_INC "%0\n"
10791 + "int $4\n0:\n"
10792 + _ASM_EXTABLE(0b, 0b)
10793 +#endif
10794 +
10795 : "+m" (l->a.counter));
10796 }
10797
10798 static inline void local_add(long i, local_t *l)
10799 {
10800 - asm volatile(_ASM_ADD "%1,%0"
10801 + asm volatile(_ASM_ADD "%1,%0\n"
10802 +
10803 +#ifdef CONFIG_PAX_REFCOUNT
10804 + "jno 0f\n"
10805 + _ASM_SUB "%1,%0\n"
10806 + "int $4\n0:\n"
10807 + _ASM_EXTABLE(0b, 0b)
10808 +#endif
10809 +
10810 : "+m" (l->a.counter)
10811 : "ir" (i));
10812 }
10813
10814 static inline void local_sub(long i, local_t *l)
10815 {
10816 - asm volatile(_ASM_SUB "%1,%0"
10817 + asm volatile(_ASM_SUB "%1,%0\n"
10818 +
10819 +#ifdef CONFIG_PAX_REFCOUNT
10820 + "jno 0f\n"
10821 + _ASM_ADD "%1,%0\n"
10822 + "int $4\n0:\n"
10823 + _ASM_EXTABLE(0b, 0b)
10824 +#endif
10825 +
10826 : "+m" (l->a.counter)
10827 : "ir" (i));
10828 }
10829 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10830 {
10831 unsigned char c;
10832
10833 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10834 + asm volatile(_ASM_SUB "%2,%0\n"
10835 +
10836 +#ifdef CONFIG_PAX_REFCOUNT
10837 + "jno 0f\n"
10838 + _ASM_ADD "%2,%0\n"
10839 + "int $4\n0:\n"
10840 + _ASM_EXTABLE(0b, 0b)
10841 +#endif
10842 +
10843 + "sete %1\n"
10844 : "+m" (l->a.counter), "=qm" (c)
10845 : "ir" (i) : "memory");
10846 return c;
10847 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10848 {
10849 unsigned char c;
10850
10851 - asm volatile(_ASM_DEC "%0; sete %1"
10852 + asm volatile(_ASM_DEC "%0\n"
10853 +
10854 +#ifdef CONFIG_PAX_REFCOUNT
10855 + "jno 0f\n"
10856 + _ASM_INC "%0\n"
10857 + "int $4\n0:\n"
10858 + _ASM_EXTABLE(0b, 0b)
10859 +#endif
10860 +
10861 + "sete %1\n"
10862 : "+m" (l->a.counter), "=qm" (c)
10863 : : "memory");
10864 return c != 0;
10865 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10866 {
10867 unsigned char c;
10868
10869 - asm volatile(_ASM_INC "%0; sete %1"
10870 + asm volatile(_ASM_INC "%0\n"
10871 +
10872 +#ifdef CONFIG_PAX_REFCOUNT
10873 + "jno 0f\n"
10874 + _ASM_DEC "%0\n"
10875 + "int $4\n0:\n"
10876 + _ASM_EXTABLE(0b, 0b)
10877 +#endif
10878 +
10879 + "sete %1\n"
10880 : "+m" (l->a.counter), "=qm" (c)
10881 : : "memory");
10882 return c != 0;
10883 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10884 {
10885 unsigned char c;
10886
10887 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10888 + asm volatile(_ASM_ADD "%2,%0\n"
10889 +
10890 +#ifdef CONFIG_PAX_REFCOUNT
10891 + "jno 0f\n"
10892 + _ASM_SUB "%2,%0\n"
10893 + "int $4\n0:\n"
10894 + _ASM_EXTABLE(0b, 0b)
10895 +#endif
10896 +
10897 + "sets %1\n"
10898 : "+m" (l->a.counter), "=qm" (c)
10899 : "ir" (i) : "memory");
10900 return c;
10901 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10902 #endif
10903 /* Modern 486+ processor */
10904 __i = i;
10905 - asm volatile(_ASM_XADD "%0, %1;"
10906 + asm volatile(_ASM_XADD "%0, %1\n"
10907 +
10908 +#ifdef CONFIG_PAX_REFCOUNT
10909 + "jno 0f\n"
10910 + _ASM_MOV "%0,%1\n"
10911 + "int $4\n0:\n"
10912 + _ASM_EXTABLE(0b, 0b)
10913 +#endif
10914 +
10915 : "+r" (i), "+m" (l->a.counter)
10916 : : "memory");
10917 return i + __i;
10918 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10919 index 593e51d..fa69c9a 100644
10920 --- a/arch/x86/include/asm/mman.h
10921 +++ b/arch/x86/include/asm/mman.h
10922 @@ -5,4 +5,14 @@
10923
10924 #include <asm-generic/mman.h>
10925
10926 +#ifdef __KERNEL__
10927 +#ifndef __ASSEMBLY__
10928 +#ifdef CONFIG_X86_32
10929 +#define arch_mmap_check i386_mmap_check
10930 +int i386_mmap_check(unsigned long addr, unsigned long len,
10931 + unsigned long flags);
10932 +#endif
10933 +#endif
10934 +#endif
10935 +
10936 #endif /* _ASM_X86_MMAN_H */
10937 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10938 index 5f55e69..e20bfb1 100644
10939 --- a/arch/x86/include/asm/mmu.h
10940 +++ b/arch/x86/include/asm/mmu.h
10941 @@ -9,7 +9,7 @@
10942 * we put the segment information here.
10943 */
10944 typedef struct {
10945 - void *ldt;
10946 + struct desc_struct *ldt;
10947 int size;
10948
10949 #ifdef CONFIG_X86_64
10950 @@ -18,7 +18,19 @@ typedef struct {
10951 #endif
10952
10953 struct mutex lock;
10954 - void *vdso;
10955 + unsigned long vdso;
10956 +
10957 +#ifdef CONFIG_X86_32
10958 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10959 + unsigned long user_cs_base;
10960 + unsigned long user_cs_limit;
10961 +
10962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10963 + cpumask_t cpu_user_cs_mask;
10964 +#endif
10965 +
10966 +#endif
10967 +#endif
10968 } mm_context_t;
10969
10970 #ifdef CONFIG_SMP
10971 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10972 index cdbf367..adb37ac 100644
10973 --- a/arch/x86/include/asm/mmu_context.h
10974 +++ b/arch/x86/include/asm/mmu_context.h
10975 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10976
10977 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10978 {
10979 +
10980 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10981 + unsigned int i;
10982 + pgd_t *pgd;
10983 +
10984 + pax_open_kernel();
10985 + pgd = get_cpu_pgd(smp_processor_id());
10986 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10987 + set_pgd_batched(pgd+i, native_make_pgd(0));
10988 + pax_close_kernel();
10989 +#endif
10990 +
10991 #ifdef CONFIG_SMP
10992 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10993 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10994 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10995 struct task_struct *tsk)
10996 {
10997 unsigned cpu = smp_processor_id();
10998 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10999 + int tlbstate = TLBSTATE_OK;
11000 +#endif
11001
11002 if (likely(prev != next)) {
11003 #ifdef CONFIG_SMP
11004 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11005 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11006 +#endif
11007 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11008 this_cpu_write(cpu_tlbstate.active_mm, next);
11009 #endif
11010 cpumask_set_cpu(cpu, mm_cpumask(next));
11011
11012 /* Re-load page tables */
11013 +#ifdef CONFIG_PAX_PER_CPU_PGD
11014 + pax_open_kernel();
11015 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11016 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11017 + pax_close_kernel();
11018 + load_cr3(get_cpu_pgd(cpu));
11019 +#else
11020 load_cr3(next->pgd);
11021 +#endif
11022
11023 /* stop flush ipis for the previous mm */
11024 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11025 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11026 */
11027 if (unlikely(prev->context.ldt != next->context.ldt))
11028 load_LDT_nolock(&next->context);
11029 - }
11030 +
11031 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11032 + if (!(__supported_pte_mask & _PAGE_NX)) {
11033 + smp_mb__before_clear_bit();
11034 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11035 + smp_mb__after_clear_bit();
11036 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11037 + }
11038 +#endif
11039 +
11040 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11041 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11042 + prev->context.user_cs_limit != next->context.user_cs_limit))
11043 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11044 #ifdef CONFIG_SMP
11045 + else if (unlikely(tlbstate != TLBSTATE_OK))
11046 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11047 +#endif
11048 +#endif
11049 +
11050 + }
11051 else {
11052 +
11053 +#ifdef CONFIG_PAX_PER_CPU_PGD
11054 + pax_open_kernel();
11055 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11056 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11057 + pax_close_kernel();
11058 + load_cr3(get_cpu_pgd(cpu));
11059 +#endif
11060 +
11061 +#ifdef CONFIG_SMP
11062 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11063 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11064
11065 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11066 * tlb flush IPI delivery. We must reload CR3
11067 * to make sure to use no freed page tables.
11068 */
11069 +
11070 +#ifndef CONFIG_PAX_PER_CPU_PGD
11071 load_cr3(next->pgd);
11072 +#endif
11073 +
11074 load_LDT_nolock(&next->context);
11075 +
11076 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11077 + if (!(__supported_pte_mask & _PAGE_NX))
11078 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11079 +#endif
11080 +
11081 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11082 +#ifdef CONFIG_PAX_PAGEEXEC
11083 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11084 +#endif
11085 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11086 +#endif
11087 +
11088 }
11089 +#endif
11090 }
11091 -#endif
11092 }
11093
11094 #define activate_mm(prev, next) \
11095 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11096 index 9eae775..c914fea 100644
11097 --- a/arch/x86/include/asm/module.h
11098 +++ b/arch/x86/include/asm/module.h
11099 @@ -5,6 +5,7 @@
11100
11101 #ifdef CONFIG_X86_64
11102 /* X86_64 does not define MODULE_PROC_FAMILY */
11103 +#define MODULE_PROC_FAMILY ""
11104 #elif defined CONFIG_M386
11105 #define MODULE_PROC_FAMILY "386 "
11106 #elif defined CONFIG_M486
11107 @@ -59,8 +60,20 @@
11108 #error unknown processor family
11109 #endif
11110
11111 -#ifdef CONFIG_X86_32
11112 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11113 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11114 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11115 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11116 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11117 +#else
11118 +#define MODULE_PAX_KERNEXEC ""
11119 #endif
11120
11121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11122 +#define MODULE_PAX_UDEREF "UDEREF "
11123 +#else
11124 +#define MODULE_PAX_UDEREF ""
11125 +#endif
11126 +
11127 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11128 +
11129 #endif /* _ASM_X86_MODULE_H */
11130 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11131 index 320f7bb..e89f8f8 100644
11132 --- a/arch/x86/include/asm/page_64_types.h
11133 +++ b/arch/x86/include/asm/page_64_types.h
11134 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11135
11136 /* duplicated to the one in bootmem.h */
11137 extern unsigned long max_pfn;
11138 -extern unsigned long phys_base;
11139 +extern const unsigned long phys_base;
11140
11141 extern unsigned long __phys_addr(unsigned long);
11142 #define __phys_reloc_hide(x) (x)
11143 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11144 index a0facf3..c017b15 100644
11145 --- a/arch/x86/include/asm/paravirt.h
11146 +++ b/arch/x86/include/asm/paravirt.h
11147 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11148 val);
11149 }
11150
11151 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11152 +{
11153 + pgdval_t val = native_pgd_val(pgd);
11154 +
11155 + if (sizeof(pgdval_t) > sizeof(long))
11156 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11157 + val, (u64)val >> 32);
11158 + else
11159 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11160 + val);
11161 +}
11162 +
11163 static inline void pgd_clear(pgd_t *pgdp)
11164 {
11165 set_pgd(pgdp, __pgd(0));
11166 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11167 pv_mmu_ops.set_fixmap(idx, phys, flags);
11168 }
11169
11170 +#ifdef CONFIG_PAX_KERNEXEC
11171 +static inline unsigned long pax_open_kernel(void)
11172 +{
11173 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11174 +}
11175 +
11176 +static inline unsigned long pax_close_kernel(void)
11177 +{
11178 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11179 +}
11180 +#else
11181 +static inline unsigned long pax_open_kernel(void) { return 0; }
11182 +static inline unsigned long pax_close_kernel(void) { return 0; }
11183 +#endif
11184 +
11185 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11186
11187 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11188 @@ -929,7 +956,7 @@ extern void default_banner(void);
11189
11190 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11191 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11192 -#define PARA_INDIRECT(addr) *%cs:addr
11193 +#define PARA_INDIRECT(addr) *%ss:addr
11194 #endif
11195
11196 #define INTERRUPT_RETURN \
11197 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11198 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11199 CLBR_NONE, \
11200 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11201 +
11202 +#define GET_CR0_INTO_RDI \
11203 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11204 + mov %rax,%rdi
11205 +
11206 +#define SET_RDI_INTO_CR0 \
11207 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11208 +
11209 +#define GET_CR3_INTO_RDI \
11210 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11211 + mov %rax,%rdi
11212 +
11213 +#define SET_RDI_INTO_CR3 \
11214 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11215 +
11216 #endif /* CONFIG_X86_32 */
11217
11218 #endif /* __ASSEMBLY__ */
11219 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11220 index 142236e..6a6b4a6 100644
11221 --- a/arch/x86/include/asm/paravirt_types.h
11222 +++ b/arch/x86/include/asm/paravirt_types.h
11223 @@ -84,20 +84,20 @@ struct pv_init_ops {
11224 */
11225 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11226 unsigned long addr, unsigned len);
11227 -};
11228 +} __no_const;
11229
11230
11231 struct pv_lazy_ops {
11232 /* Set deferred update mode, used for batching operations. */
11233 void (*enter)(void);
11234 void (*leave)(void);
11235 -};
11236 +} __no_const;
11237
11238 struct pv_time_ops {
11239 unsigned long long (*sched_clock)(void);
11240 unsigned long long (*steal_clock)(int cpu);
11241 unsigned long (*get_tsc_khz)(void);
11242 -};
11243 +} __no_const;
11244
11245 struct pv_cpu_ops {
11246 /* hooks for various privileged instructions */
11247 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11248
11249 void (*start_context_switch)(struct task_struct *prev);
11250 void (*end_context_switch)(struct task_struct *next);
11251 -};
11252 +} __no_const;
11253
11254 struct pv_irq_ops {
11255 /*
11256 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11257 unsigned long start_eip,
11258 unsigned long start_esp);
11259 #endif
11260 -};
11261 +} __no_const;
11262
11263 struct pv_mmu_ops {
11264 unsigned long (*read_cr2)(void);
11265 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11266 struct paravirt_callee_save make_pud;
11267
11268 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11269 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11270 #endif /* PAGETABLE_LEVELS == 4 */
11271 #endif /* PAGETABLE_LEVELS >= 3 */
11272
11273 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11274 an mfn. We can tell which is which from the index. */
11275 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11276 phys_addr_t phys, pgprot_t flags);
11277 +
11278 +#ifdef CONFIG_PAX_KERNEXEC
11279 + unsigned long (*pax_open_kernel)(void);
11280 + unsigned long (*pax_close_kernel)(void);
11281 +#endif
11282 +
11283 };
11284
11285 struct arch_spinlock;
11286 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11287 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11288 int (*spin_trylock)(struct arch_spinlock *lock);
11289 void (*spin_unlock)(struct arch_spinlock *lock);
11290 -};
11291 +} __no_const;
11292
11293 /* This contains all the paravirt structures: we get a convenient
11294 * number for each function using the offset which we use to indicate
11295 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11296 index b4389a4..7024269 100644
11297 --- a/arch/x86/include/asm/pgalloc.h
11298 +++ b/arch/x86/include/asm/pgalloc.h
11299 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11300 pmd_t *pmd, pte_t *pte)
11301 {
11302 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11303 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11304 +}
11305 +
11306 +static inline void pmd_populate_user(struct mm_struct *mm,
11307 + pmd_t *pmd, pte_t *pte)
11308 +{
11309 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11310 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11311 }
11312
11313 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11314
11315 #ifdef CONFIG_X86_PAE
11316 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11317 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11318 +{
11319 + pud_populate(mm, pudp, pmd);
11320 +}
11321 #else /* !CONFIG_X86_PAE */
11322 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11323 {
11324 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11325 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11326 }
11327 +
11328 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11329 +{
11330 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11331 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11332 +}
11333 #endif /* CONFIG_X86_PAE */
11334
11335 #if PAGETABLE_LEVELS > 3
11336 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11337 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11338 }
11339
11340 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11341 +{
11342 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11343 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11344 +}
11345 +
11346 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11347 {
11348 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11349 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11350 index f2b489c..4f7e2e5 100644
11351 --- a/arch/x86/include/asm/pgtable-2level.h
11352 +++ b/arch/x86/include/asm/pgtable-2level.h
11353 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11354
11355 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11356 {
11357 + pax_open_kernel();
11358 *pmdp = pmd;
11359 + pax_close_kernel();
11360 }
11361
11362 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11363 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11364 index 4cc9f2b..5fd9226 100644
11365 --- a/arch/x86/include/asm/pgtable-3level.h
11366 +++ b/arch/x86/include/asm/pgtable-3level.h
11367 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11368
11369 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11370 {
11371 + pax_open_kernel();
11372 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11373 + pax_close_kernel();
11374 }
11375
11376 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11377 {
11378 + pax_open_kernel();
11379 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11380 + pax_close_kernel();
11381 }
11382
11383 /*
11384 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11385 index c3520d7..cf742ef 100644
11386 --- a/arch/x86/include/asm/pgtable.h
11387 +++ b/arch/x86/include/asm/pgtable.h
11388 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11389
11390 #ifndef __PAGETABLE_PUD_FOLDED
11391 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11392 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11393 #define pgd_clear(pgd) native_pgd_clear(pgd)
11394 #endif
11395
11396 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11397
11398 #define arch_end_context_switch(prev) do {} while(0)
11399
11400 +#define pax_open_kernel() native_pax_open_kernel()
11401 +#define pax_close_kernel() native_pax_close_kernel()
11402 #endif /* CONFIG_PARAVIRT */
11403
11404 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11405 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11406 +
11407 +#ifdef CONFIG_PAX_KERNEXEC
11408 +static inline unsigned long native_pax_open_kernel(void)
11409 +{
11410 + unsigned long cr0;
11411 +
11412 + preempt_disable();
11413 + barrier();
11414 + cr0 = read_cr0() ^ X86_CR0_WP;
11415 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11416 + write_cr0(cr0);
11417 + return cr0 ^ X86_CR0_WP;
11418 +}
11419 +
11420 +static inline unsigned long native_pax_close_kernel(void)
11421 +{
11422 + unsigned long cr0;
11423 +
11424 + cr0 = read_cr0() ^ X86_CR0_WP;
11425 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11426 + write_cr0(cr0);
11427 + barrier();
11428 + preempt_enable_no_resched();
11429 + return cr0 ^ X86_CR0_WP;
11430 +}
11431 +#else
11432 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11433 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11434 +#endif
11435 +
11436 /*
11437 * The following only work if pte_present() is true.
11438 * Undefined behaviour if not..
11439 */
11440 +static inline int pte_user(pte_t pte)
11441 +{
11442 + return pte_val(pte) & _PAGE_USER;
11443 +}
11444 +
11445 static inline int pte_dirty(pte_t pte)
11446 {
11447 return pte_flags(pte) & _PAGE_DIRTY;
11448 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11449 return pte_clear_flags(pte, _PAGE_RW);
11450 }
11451
11452 +static inline pte_t pte_mkread(pte_t pte)
11453 +{
11454 + return __pte(pte_val(pte) | _PAGE_USER);
11455 +}
11456 +
11457 static inline pte_t pte_mkexec(pte_t pte)
11458 {
11459 - return pte_clear_flags(pte, _PAGE_NX);
11460 +#ifdef CONFIG_X86_PAE
11461 + if (__supported_pte_mask & _PAGE_NX)
11462 + return pte_clear_flags(pte, _PAGE_NX);
11463 + else
11464 +#endif
11465 + return pte_set_flags(pte, _PAGE_USER);
11466 +}
11467 +
11468 +static inline pte_t pte_exprotect(pte_t pte)
11469 +{
11470 +#ifdef CONFIG_X86_PAE
11471 + if (__supported_pte_mask & _PAGE_NX)
11472 + return pte_set_flags(pte, _PAGE_NX);
11473 + else
11474 +#endif
11475 + return pte_clear_flags(pte, _PAGE_USER);
11476 }
11477
11478 static inline pte_t pte_mkdirty(pte_t pte)
11479 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11480 #endif
11481
11482 #ifndef __ASSEMBLY__
11483 +
11484 +#ifdef CONFIG_PAX_PER_CPU_PGD
11485 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11486 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11487 +{
11488 + return cpu_pgd[cpu];
11489 +}
11490 +#endif
11491 +
11492 #include <linux/mm_types.h>
11493
11494 static inline int pte_none(pte_t pte)
11495 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11496
11497 static inline int pgd_bad(pgd_t pgd)
11498 {
11499 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11500 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11501 }
11502
11503 static inline int pgd_none(pgd_t pgd)
11504 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11505 * pgd_offset() returns a (pgd_t *)
11506 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11507 */
11508 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11509 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11510 +
11511 +#ifdef CONFIG_PAX_PER_CPU_PGD
11512 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11513 +#endif
11514 +
11515 /*
11516 * a shortcut which implies the use of the kernel's pgd, instead
11517 * of a process's
11518 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11519 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11520 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11521
11522 +#ifdef CONFIG_X86_32
11523 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11524 +#else
11525 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11526 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11527 +
11528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11529 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11530 +#else
11531 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11532 +#endif
11533 +
11534 +#endif
11535 +
11536 #ifndef __ASSEMBLY__
11537
11538 extern int direct_gbpages;
11539 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11540 * dst and src can be on the same page, but the range must not overlap,
11541 * and must not cross a page boundary.
11542 */
11543 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11544 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11545 {
11546 - memcpy(dst, src, count * sizeof(pgd_t));
11547 + pax_open_kernel();
11548 + while (count--)
11549 + *dst++ = *src++;
11550 + pax_close_kernel();
11551 }
11552
11553 +#ifdef CONFIG_PAX_PER_CPU_PGD
11554 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11555 +#endif
11556 +
11557 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11558 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11559 +#else
11560 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11561 +#endif
11562
11563 #include <asm-generic/pgtable.h>
11564 #endif /* __ASSEMBLY__ */
11565 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11566 index 0c92113..34a77c6 100644
11567 --- a/arch/x86/include/asm/pgtable_32.h
11568 +++ b/arch/x86/include/asm/pgtable_32.h
11569 @@ -25,9 +25,6 @@
11570 struct mm_struct;
11571 struct vm_area_struct;
11572
11573 -extern pgd_t swapper_pg_dir[1024];
11574 -extern pgd_t initial_page_table[1024];
11575 -
11576 static inline void pgtable_cache_init(void) { }
11577 static inline void check_pgt_cache(void) { }
11578 void paging_init(void);
11579 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11580 # include <asm/pgtable-2level.h>
11581 #endif
11582
11583 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11584 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11585 +#ifdef CONFIG_X86_PAE
11586 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11587 +#endif
11588 +
11589 #if defined(CONFIG_HIGHPTE)
11590 #define pte_offset_map(dir, address) \
11591 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11592 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11593 /* Clear a kernel PTE and flush it from the TLB */
11594 #define kpte_clear_flush(ptep, vaddr) \
11595 do { \
11596 + pax_open_kernel(); \
11597 pte_clear(&init_mm, (vaddr), (ptep)); \
11598 + pax_close_kernel(); \
11599 __flush_tlb_one((vaddr)); \
11600 } while (0)
11601
11602 @@ -74,6 +79,9 @@ do { \
11603
11604 #endif /* !__ASSEMBLY__ */
11605
11606 +#define HAVE_ARCH_UNMAPPED_AREA
11607 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11608 +
11609 /*
11610 * kern_addr_valid() is (1) for FLATMEM and (0) for
11611 * SPARSEMEM and DISCONTIGMEM
11612 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11613 index ed5903b..c7fe163 100644
11614 --- a/arch/x86/include/asm/pgtable_32_types.h
11615 +++ b/arch/x86/include/asm/pgtable_32_types.h
11616 @@ -8,7 +8,7 @@
11617 */
11618 #ifdef CONFIG_X86_PAE
11619 # include <asm/pgtable-3level_types.h>
11620 -# define PMD_SIZE (1UL << PMD_SHIFT)
11621 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11622 # define PMD_MASK (~(PMD_SIZE - 1))
11623 #else
11624 # include <asm/pgtable-2level_types.h>
11625 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11626 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11627 #endif
11628
11629 +#ifdef CONFIG_PAX_KERNEXEC
11630 +#ifndef __ASSEMBLY__
11631 +extern unsigned char MODULES_EXEC_VADDR[];
11632 +extern unsigned char MODULES_EXEC_END[];
11633 +#endif
11634 +#include <asm/boot.h>
11635 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11636 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11637 +#else
11638 +#define ktla_ktva(addr) (addr)
11639 +#define ktva_ktla(addr) (addr)
11640 +#endif
11641 +
11642 #define MODULES_VADDR VMALLOC_START
11643 #define MODULES_END VMALLOC_END
11644 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11645 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11646 index 8251be0..4ea8b46 100644
11647 --- a/arch/x86/include/asm/pgtable_64.h
11648 +++ b/arch/x86/include/asm/pgtable_64.h
11649 @@ -16,10 +16,14 @@
11650
11651 extern pud_t level3_kernel_pgt[512];
11652 extern pud_t level3_ident_pgt[512];
11653 +extern pud_t level3_vmalloc_start_pgt[512];
11654 +extern pud_t level3_vmalloc_end_pgt[512];
11655 +extern pud_t level3_vmemmap_pgt[512];
11656 +extern pud_t level2_vmemmap_pgt[512];
11657 extern pmd_t level2_kernel_pgt[512];
11658 extern pmd_t level2_fixmap_pgt[512];
11659 -extern pmd_t level2_ident_pgt[512];
11660 -extern pgd_t init_level4_pgt[];
11661 +extern pmd_t level2_ident_pgt[512*2];
11662 +extern pgd_t init_level4_pgt[512];
11663
11664 #define swapper_pg_dir init_level4_pgt
11665
11666 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11667
11668 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11669 {
11670 + pax_open_kernel();
11671 *pmdp = pmd;
11672 + pax_close_kernel();
11673 }
11674
11675 static inline void native_pmd_clear(pmd_t *pmd)
11676 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11677
11678 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11679 {
11680 + pax_open_kernel();
11681 *pudp = pud;
11682 + pax_close_kernel();
11683 }
11684
11685 static inline void native_pud_clear(pud_t *pud)
11686 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11687
11688 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11689 {
11690 + pax_open_kernel();
11691 + *pgdp = pgd;
11692 + pax_close_kernel();
11693 +}
11694 +
11695 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11696 +{
11697 *pgdp = pgd;
11698 }
11699
11700 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11701 index 766ea16..5b96cb3 100644
11702 --- a/arch/x86/include/asm/pgtable_64_types.h
11703 +++ b/arch/x86/include/asm/pgtable_64_types.h
11704 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11705 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11706 #define MODULES_END _AC(0xffffffffff000000, UL)
11707 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11708 +#define MODULES_EXEC_VADDR MODULES_VADDR
11709 +#define MODULES_EXEC_END MODULES_END
11710 +
11711 +#define ktla_ktva(addr) (addr)
11712 +#define ktva_ktla(addr) (addr)
11713
11714 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11715 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11716 index 013286a..8b42f4f 100644
11717 --- a/arch/x86/include/asm/pgtable_types.h
11718 +++ b/arch/x86/include/asm/pgtable_types.h
11719 @@ -16,13 +16,12 @@
11720 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11721 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11722 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11723 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11724 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11725 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11726 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11727 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11728 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11729 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11730 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11731 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11732 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11733 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11734
11735 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11736 @@ -40,7 +39,6 @@
11737 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11738 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11739 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11740 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11741 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11742 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11743 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11744 @@ -57,8 +55,10 @@
11745
11746 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11747 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11748 -#else
11749 +#elif defined(CONFIG_KMEMCHECK)
11750 #define _PAGE_NX (_AT(pteval_t, 0))
11751 +#else
11752 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11753 #endif
11754
11755 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11756 @@ -96,6 +96,9 @@
11757 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11758 _PAGE_ACCESSED)
11759
11760 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11761 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11762 +
11763 #define __PAGE_KERNEL_EXEC \
11764 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11765 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11766 @@ -106,7 +109,7 @@
11767 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11768 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11769 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11770 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11771 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11772 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11773 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11774 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11775 @@ -168,8 +171,8 @@
11776 * bits are combined, this will alow user to access the high address mapped
11777 * VDSO in the presence of CONFIG_COMPAT_VDSO
11778 */
11779 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11780 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11781 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11782 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11783 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11784 #endif
11785
11786 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11787 {
11788 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11789 }
11790 +#endif
11791
11792 +#if PAGETABLE_LEVELS == 3
11793 +#include <asm-generic/pgtable-nopud.h>
11794 +#endif
11795 +
11796 +#if PAGETABLE_LEVELS == 2
11797 +#include <asm-generic/pgtable-nopmd.h>
11798 +#endif
11799 +
11800 +#ifndef __ASSEMBLY__
11801 #if PAGETABLE_LEVELS > 3
11802 typedef struct { pudval_t pud; } pud_t;
11803
11804 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11805 return pud.pud;
11806 }
11807 #else
11808 -#include <asm-generic/pgtable-nopud.h>
11809 -
11810 static inline pudval_t native_pud_val(pud_t pud)
11811 {
11812 return native_pgd_val(pud.pgd);
11813 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11814 return pmd.pmd;
11815 }
11816 #else
11817 -#include <asm-generic/pgtable-nopmd.h>
11818 -
11819 static inline pmdval_t native_pmd_val(pmd_t pmd)
11820 {
11821 return native_pgd_val(pmd.pud.pgd);
11822 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11823
11824 extern pteval_t __supported_pte_mask;
11825 extern void set_nx(void);
11826 -extern int nx_enabled;
11827
11828 #define pgprot_writecombine pgprot_writecombine
11829 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11830 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11831 index aea1d1d..680cf09 100644
11832 --- a/arch/x86/include/asm/processor-flags.h
11833 +++ b/arch/x86/include/asm/processor-flags.h
11834 @@ -65,6 +65,7 @@
11835 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11836 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11837 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11838 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11839
11840 /*
11841 * x86-64 Task Priority Register, CR8
11842 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11843 index d048cad..45e350f 100644
11844 --- a/arch/x86/include/asm/processor.h
11845 +++ b/arch/x86/include/asm/processor.h
11846 @@ -289,7 +289,7 @@ struct tss_struct {
11847
11848 } ____cacheline_aligned;
11849
11850 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11851 +extern struct tss_struct init_tss[NR_CPUS];
11852
11853 /*
11854 * Save the original ist values for checking stack pointers during debugging
11855 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11856 */
11857 #define TASK_SIZE PAGE_OFFSET
11858 #define TASK_SIZE_MAX TASK_SIZE
11859 +
11860 +#ifdef CONFIG_PAX_SEGMEXEC
11861 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11862 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11863 +#else
11864 #define STACK_TOP TASK_SIZE
11865 -#define STACK_TOP_MAX STACK_TOP
11866 +#endif
11867 +
11868 +#define STACK_TOP_MAX TASK_SIZE
11869
11870 #define INIT_THREAD { \
11871 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .vm86_info = NULL, \
11874 .sysenter_cs = __KERNEL_CS, \
11875 .io_bitmap_ptr = NULL, \
11876 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 */
11878 #define INIT_TSS { \
11879 .x86_tss = { \
11880 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11881 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11882 .ss0 = __KERNEL_DS, \
11883 .ss1 = __KERNEL_CS, \
11884 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11885 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11886 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11887
11888 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11889 -#define KSTK_TOP(info) \
11890 -({ \
11891 - unsigned long *__ptr = (unsigned long *)(info); \
11892 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11893 -})
11894 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11895
11896 /*
11897 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11898 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 #define task_pt_regs(task) \
11900 ({ \
11901 struct pt_regs *__regs__; \
11902 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11903 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11904 __regs__ - 1; \
11905 })
11906
11907 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11908 /*
11909 * User space process size. 47bits minus one guard page.
11910 */
11911 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11912 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11913
11914 /* This decides where the kernel will search for a free chunk of vm
11915 * space during mmap's.
11916 */
11917 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11918 - 0xc0000000 : 0xFFFFe000)
11919 + 0xc0000000 : 0xFFFFf000)
11920
11921 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11922 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11923 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11924 #define STACK_TOP_MAX TASK_SIZE_MAX
11925
11926 #define INIT_THREAD { \
11927 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11928 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11929 }
11930
11931 #define INIT_TSS { \
11932 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11933 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11934 }
11935
11936 /*
11937 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11938 */
11939 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11940
11941 +#ifdef CONFIG_PAX_SEGMEXEC
11942 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11943 +#endif
11944 +
11945 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11946
11947 /* Get/set a process' ability to use the timestamp counter instruction */
11948 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11949 #define cpu_has_amd_erratum(x) (false)
11950 #endif /* CONFIG_CPU_SUP_AMD */
11951
11952 -extern unsigned long arch_align_stack(unsigned long sp);
11953 +#define arch_align_stack(x) ((x) & ~0xfUL)
11954 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11955
11956 void default_idle(void);
11957 bool set_pm_idle_to_default(void);
11958
11959 -void stop_this_cpu(void *dummy);
11960 +void stop_this_cpu(void *dummy) __noreturn;
11961
11962 #endif /* _ASM_X86_PROCESSOR_H */
11963 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11964 index dcfde52..dbfea06 100644
11965 --- a/arch/x86/include/asm/ptrace.h
11966 +++ b/arch/x86/include/asm/ptrace.h
11967 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11968 }
11969
11970 /*
11971 - * user_mode_vm(regs) determines whether a register set came from user mode.
11972 + * user_mode(regs) determines whether a register set came from user mode.
11973 * This is true if V8086 mode was enabled OR if the register set was from
11974 * protected mode with RPL-3 CS value. This tricky test checks that with
11975 * one comparison. Many places in the kernel can bypass this full check
11976 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11977 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11978 + * be used.
11979 */
11980 -static inline int user_mode(struct pt_regs *regs)
11981 +static inline int user_mode_novm(struct pt_regs *regs)
11982 {
11983 #ifdef CONFIG_X86_32
11984 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11985 #else
11986 - return !!(regs->cs & 3);
11987 + return !!(regs->cs & SEGMENT_RPL_MASK);
11988 #endif
11989 }
11990
11991 -static inline int user_mode_vm(struct pt_regs *regs)
11992 +static inline int user_mode(struct pt_regs *regs)
11993 {
11994 #ifdef CONFIG_X86_32
11995 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11996 USER_RPL;
11997 #else
11998 - return user_mode(regs);
11999 + return user_mode_novm(regs);
12000 #endif
12001 }
12002
12003 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12004 #ifdef CONFIG_X86_64
12005 static inline bool user_64bit_mode(struct pt_regs *regs)
12006 {
12007 + unsigned long cs = regs->cs & 0xffff;
12008 #ifndef CONFIG_PARAVIRT
12009 /*
12010 * On non-paravirt systems, this is the only long mode CPL 3
12011 * selector. We do not allow long mode selectors in the LDT.
12012 */
12013 - return regs->cs == __USER_CS;
12014 + return cs == __USER_CS;
12015 #else
12016 /* Headers are too twisted for this to go in paravirt.h. */
12017 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12018 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12019 #endif
12020 }
12021 #endif
12022 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12023 index fe1ec5b..dc5c3fe 100644
12024 --- a/arch/x86/include/asm/realmode.h
12025 +++ b/arch/x86/include/asm/realmode.h
12026 @@ -22,16 +22,14 @@ struct real_mode_header {
12027 #endif
12028 /* APM/BIOS reboot */
12029 u32 machine_real_restart_asm;
12030 -#ifdef CONFIG_X86_64
12031 u32 machine_real_restart_seg;
12032 -#endif
12033 };
12034
12035 /* This must match data at trampoline_32/64.S */
12036 struct trampoline_header {
12037 #ifdef CONFIG_X86_32
12038 u32 start;
12039 - u16 gdt_pad;
12040 + u16 boot_cs;
12041 u16 gdt_limit;
12042 u32 gdt_base;
12043 #else
12044 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12045 index a82c4f1..ac45053 100644
12046 --- a/arch/x86/include/asm/reboot.h
12047 +++ b/arch/x86/include/asm/reboot.h
12048 @@ -6,13 +6,13 @@
12049 struct pt_regs;
12050
12051 struct machine_ops {
12052 - void (*restart)(char *cmd);
12053 - void (*halt)(void);
12054 - void (*power_off)(void);
12055 + void (* __noreturn restart)(char *cmd);
12056 + void (* __noreturn halt)(void);
12057 + void (* __noreturn power_off)(void);
12058 void (*shutdown)(void);
12059 void (*crash_shutdown)(struct pt_regs *);
12060 - void (*emergency_restart)(void);
12061 -};
12062 + void (* __noreturn emergency_restart)(void);
12063 +} __no_const;
12064
12065 extern struct machine_ops machine_ops;
12066
12067 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12068 index 2dbe4a7..ce1db00 100644
12069 --- a/arch/x86/include/asm/rwsem.h
12070 +++ b/arch/x86/include/asm/rwsem.h
12071 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12072 {
12073 asm volatile("# beginning down_read\n\t"
12074 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12075 +
12076 +#ifdef CONFIG_PAX_REFCOUNT
12077 + "jno 0f\n"
12078 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12079 + "int $4\n0:\n"
12080 + _ASM_EXTABLE(0b, 0b)
12081 +#endif
12082 +
12083 /* adds 0x00000001 */
12084 " jns 1f\n"
12085 " call call_rwsem_down_read_failed\n"
12086 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12087 "1:\n\t"
12088 " mov %1,%2\n\t"
12089 " add %3,%2\n\t"
12090 +
12091 +#ifdef CONFIG_PAX_REFCOUNT
12092 + "jno 0f\n"
12093 + "sub %3,%2\n"
12094 + "int $4\n0:\n"
12095 + _ASM_EXTABLE(0b, 0b)
12096 +#endif
12097 +
12098 " jle 2f\n\t"
12099 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12100 " jnz 1b\n\t"
12101 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12102 long tmp;
12103 asm volatile("# beginning down_write\n\t"
12104 LOCK_PREFIX " xadd %1,(%2)\n\t"
12105 +
12106 +#ifdef CONFIG_PAX_REFCOUNT
12107 + "jno 0f\n"
12108 + "mov %1,(%2)\n"
12109 + "int $4\n0:\n"
12110 + _ASM_EXTABLE(0b, 0b)
12111 +#endif
12112 +
12113 /* adds 0xffff0001, returns the old value */
12114 " test %1,%1\n\t"
12115 /* was the count 0 before? */
12116 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12117 long tmp;
12118 asm volatile("# beginning __up_read\n\t"
12119 LOCK_PREFIX " xadd %1,(%2)\n\t"
12120 +
12121 +#ifdef CONFIG_PAX_REFCOUNT
12122 + "jno 0f\n"
12123 + "mov %1,(%2)\n"
12124 + "int $4\n0:\n"
12125 + _ASM_EXTABLE(0b, 0b)
12126 +#endif
12127 +
12128 /* subtracts 1, returns the old value */
12129 " jns 1f\n\t"
12130 " call call_rwsem_wake\n" /* expects old value in %edx */
12131 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12132 long tmp;
12133 asm volatile("# beginning __up_write\n\t"
12134 LOCK_PREFIX " xadd %1,(%2)\n\t"
12135 +
12136 +#ifdef CONFIG_PAX_REFCOUNT
12137 + "jno 0f\n"
12138 + "mov %1,(%2)\n"
12139 + "int $4\n0:\n"
12140 + _ASM_EXTABLE(0b, 0b)
12141 +#endif
12142 +
12143 /* subtracts 0xffff0001, returns the old value */
12144 " jns 1f\n\t"
12145 " call call_rwsem_wake\n" /* expects old value in %edx */
12146 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning __downgrade_write\n\t"
12149 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12150 +
12151 +#ifdef CONFIG_PAX_REFCOUNT
12152 + "jno 0f\n"
12153 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12154 + "int $4\n0:\n"
12155 + _ASM_EXTABLE(0b, 0b)
12156 +#endif
12157 +
12158 /*
12159 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12160 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12161 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12162 */
12163 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12164 {
12165 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12166 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+m" (sem->count)
12176 : "er" (delta));
12177 }
12178 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12179 */
12180 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12181 {
12182 - return delta + xadd(&sem->count, delta);
12183 + return delta + xadd_check_overflow(&sem->count, delta);
12184 }
12185
12186 #endif /* __KERNEL__ */
12187 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12188 index c48a950..c6d7468 100644
12189 --- a/arch/x86/include/asm/segment.h
12190 +++ b/arch/x86/include/asm/segment.h
12191 @@ -64,10 +64,15 @@
12192 * 26 - ESPFIX small SS
12193 * 27 - per-cpu [ offset to per-cpu data area ]
12194 * 28 - stack_canary-20 [ for stack protector ]
12195 - * 29 - unused
12196 - * 30 - unused
12197 + * 29 - PCI BIOS CS
12198 + * 30 - PCI BIOS DS
12199 * 31 - TSS for double fault handler
12200 */
12201 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12202 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12203 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12204 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12205 +
12206 #define GDT_ENTRY_TLS_MIN 6
12207 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12208
12209 @@ -79,6 +84,8 @@
12210
12211 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12212
12213 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12214 +
12215 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12216
12217 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12218 @@ -104,6 +111,12 @@
12219 #define __KERNEL_STACK_CANARY 0
12220 #endif
12221
12222 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12223 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12224 +
12225 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12226 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12227 +
12228 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12229
12230 /*
12231 @@ -141,7 +154,7 @@
12232 */
12233
12234 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12235 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12236 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12237
12238
12239 #else
12240 @@ -165,6 +178,8 @@
12241 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12242 #define __USER32_DS __USER_DS
12243
12244 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12245 +
12246 #define GDT_ENTRY_TSS 8 /* needs two entries */
12247 #define GDT_ENTRY_LDT 10 /* needs two entries */
12248 #define GDT_ENTRY_TLS_MIN 12
12249 @@ -185,6 +200,7 @@
12250 #endif
12251
12252 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12253 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12254 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12255 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12256 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12257 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12258 {
12259 unsigned long __limit;
12260 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12261 - return __limit + 1;
12262 + return __limit;
12263 }
12264
12265 #endif /* !__ASSEMBLY__ */
12266 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12267 index 4f19a15..9e14f27 100644
12268 --- a/arch/x86/include/asm/smp.h
12269 +++ b/arch/x86/include/asm/smp.h
12270 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12271 /* cpus sharing the last level cache: */
12272 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12273 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12274 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12275 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12276
12277 static inline struct cpumask *cpu_sibling_mask(int cpu)
12278 {
12279 @@ -79,7 +79,7 @@ struct smp_ops {
12280
12281 void (*send_call_func_ipi)(const struct cpumask *mask);
12282 void (*send_call_func_single_ipi)(int cpu);
12283 -};
12284 +} __no_const;
12285
12286 /* Globals due to paravirt */
12287 extern void set_cpu_sibling_map(int cpu);
12288 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12289 extern int safe_smp_processor_id(void);
12290
12291 #elif defined(CONFIG_X86_64_SMP)
12292 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12293 -
12294 -#define stack_smp_processor_id() \
12295 -({ \
12296 - struct thread_info *ti; \
12297 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12298 - ti->cpu; \
12299 -})
12300 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12301 +#define stack_smp_processor_id() raw_smp_processor_id()
12302 #define safe_smp_processor_id() smp_processor_id()
12303
12304 #endif
12305 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12306 index 33692ea..350a534 100644
12307 --- a/arch/x86/include/asm/spinlock.h
12308 +++ b/arch/x86/include/asm/spinlock.h
12309 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12310 static inline void arch_read_lock(arch_rwlock_t *rw)
12311 {
12312 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12313 +
12314 +#ifdef CONFIG_PAX_REFCOUNT
12315 + "jno 0f\n"
12316 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12317 + "int $4\n0:\n"
12318 + _ASM_EXTABLE(0b, 0b)
12319 +#endif
12320 +
12321 "jns 1f\n"
12322 "call __read_lock_failed\n\t"
12323 "1:\n"
12324 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12325 static inline void arch_write_lock(arch_rwlock_t *rw)
12326 {
12327 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12328 +
12329 +#ifdef CONFIG_PAX_REFCOUNT
12330 + "jno 0f\n"
12331 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12332 + "int $4\n0:\n"
12333 + _ASM_EXTABLE(0b, 0b)
12334 +#endif
12335 +
12336 "jz 1f\n"
12337 "call __write_lock_failed\n\t"
12338 "1:\n"
12339 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12340
12341 static inline void arch_read_unlock(arch_rwlock_t *rw)
12342 {
12343 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12344 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12345 +
12346 +#ifdef CONFIG_PAX_REFCOUNT
12347 + "jno 0f\n"
12348 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12349 + "int $4\n0:\n"
12350 + _ASM_EXTABLE(0b, 0b)
12351 +#endif
12352 +
12353 :"+m" (rw->lock) : : "memory");
12354 }
12355
12356 static inline void arch_write_unlock(arch_rwlock_t *rw)
12357 {
12358 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12359 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12360 +
12361 +#ifdef CONFIG_PAX_REFCOUNT
12362 + "jno 0f\n"
12363 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12364 + "int $4\n0:\n"
12365 + _ASM_EXTABLE(0b, 0b)
12366 +#endif
12367 +
12368 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12369 }
12370
12371 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12372 index 6a99859..03cb807 100644
12373 --- a/arch/x86/include/asm/stackprotector.h
12374 +++ b/arch/x86/include/asm/stackprotector.h
12375 @@ -47,7 +47,7 @@
12376 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12377 */
12378 #define GDT_STACK_CANARY_INIT \
12379 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12380 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12381
12382 /*
12383 * Initialize the stackprotector canary value.
12384 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12385
12386 static inline void load_stack_canary_segment(void)
12387 {
12388 -#ifdef CONFIG_X86_32
12389 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12390 asm volatile ("mov %0, %%gs" : : "r" (0));
12391 #endif
12392 }
12393 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12394 index 70bbe39..4ae2bd4 100644
12395 --- a/arch/x86/include/asm/stacktrace.h
12396 +++ b/arch/x86/include/asm/stacktrace.h
12397 @@ -11,28 +11,20 @@
12398
12399 extern int kstack_depth_to_print;
12400
12401 -struct thread_info;
12402 +struct task_struct;
12403 struct stacktrace_ops;
12404
12405 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12406 - unsigned long *stack,
12407 - unsigned long bp,
12408 - const struct stacktrace_ops *ops,
12409 - void *data,
12410 - unsigned long *end,
12411 - int *graph);
12412 +typedef unsigned long walk_stack_t(struct task_struct *task,
12413 + void *stack_start,
12414 + unsigned long *stack,
12415 + unsigned long bp,
12416 + const struct stacktrace_ops *ops,
12417 + void *data,
12418 + unsigned long *end,
12419 + int *graph);
12420
12421 -extern unsigned long
12422 -print_context_stack(struct thread_info *tinfo,
12423 - unsigned long *stack, unsigned long bp,
12424 - const struct stacktrace_ops *ops, void *data,
12425 - unsigned long *end, int *graph);
12426 -
12427 -extern unsigned long
12428 -print_context_stack_bp(struct thread_info *tinfo,
12429 - unsigned long *stack, unsigned long bp,
12430 - const struct stacktrace_ops *ops, void *data,
12431 - unsigned long *end, int *graph);
12432 +extern walk_stack_t print_context_stack;
12433 +extern walk_stack_t print_context_stack_bp;
12434
12435 /* Generic stack tracer with callbacks */
12436
12437 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12438 void (*address)(void *data, unsigned long address, int reliable);
12439 /* On negative return stop dumping */
12440 int (*stack)(void *data, char *name);
12441 - walk_stack_t walk_stack;
12442 + walk_stack_t *walk_stack;
12443 };
12444
12445 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12446 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12447 index 4ec45b3..a4f0a8a 100644
12448 --- a/arch/x86/include/asm/switch_to.h
12449 +++ b/arch/x86/include/asm/switch_to.h
12450 @@ -108,7 +108,7 @@ do { \
12451 "call __switch_to\n\t" \
12452 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12453 __switch_canary \
12454 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12455 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12456 "movq %%rax,%%rdi\n\t" \
12457 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12458 "jnz ret_from_fork\n\t" \
12459 @@ -119,7 +119,7 @@ do { \
12460 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12461 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12462 [_tif_fork] "i" (_TIF_FORK), \
12463 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12464 + [thread_info] "m" (current_tinfo), \
12465 [current_task] "m" (current_task) \
12466 __switch_canary_iparam \
12467 : "memory", "cc" __EXTRA_CLOBBER)
12468 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12469 index 3fda9db4..4ca1c61 100644
12470 --- a/arch/x86/include/asm/sys_ia32.h
12471 +++ b/arch/x86/include/asm/sys_ia32.h
12472 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12473 struct old_sigaction32 __user *);
12474 asmlinkage long sys32_alarm(unsigned int);
12475
12476 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12477 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12478 asmlinkage long sys32_sysfs(int, u32, u32);
12479
12480 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12481 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12482 index 89f794f..1422765 100644
12483 --- a/arch/x86/include/asm/thread_info.h
12484 +++ b/arch/x86/include/asm/thread_info.h
12485 @@ -10,6 +10,7 @@
12486 #include <linux/compiler.h>
12487 #include <asm/page.h>
12488 #include <asm/types.h>
12489 +#include <asm/percpu.h>
12490
12491 /*
12492 * low level task data that entry.S needs immediate access to
12493 @@ -24,7 +25,6 @@ struct exec_domain;
12494 #include <linux/atomic.h>
12495
12496 struct thread_info {
12497 - struct task_struct *task; /* main task structure */
12498 struct exec_domain *exec_domain; /* execution domain */
12499 __u32 flags; /* low level flags */
12500 __u32 status; /* thread synchronous flags */
12501 @@ -34,19 +34,13 @@ struct thread_info {
12502 mm_segment_t addr_limit;
12503 struct restart_block restart_block;
12504 void __user *sysenter_return;
12505 -#ifdef CONFIG_X86_32
12506 - unsigned long previous_esp; /* ESP of the previous stack in
12507 - case of nested (IRQ) stacks
12508 - */
12509 - __u8 supervisor_stack[0];
12510 -#endif
12511 + unsigned long lowest_stack;
12512 unsigned int sig_on_uaccess_error:1;
12513 unsigned int uaccess_err:1; /* uaccess failed */
12514 };
12515
12516 -#define INIT_THREAD_INFO(tsk) \
12517 +#define INIT_THREAD_INFO \
12518 { \
12519 - .task = &tsk, \
12520 .exec_domain = &default_exec_domain, \
12521 .flags = 0, \
12522 .cpu = 0, \
12523 @@ -57,7 +51,7 @@ struct thread_info {
12524 }, \
12525 }
12526
12527 -#define init_thread_info (init_thread_union.thread_info)
12528 +#define init_thread_info (init_thread_union.stack)
12529 #define init_stack (init_thread_union.stack)
12530
12531 #else /* !__ASSEMBLY__ */
12532 @@ -98,6 +92,7 @@ struct thread_info {
12533 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12534 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12535 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12536 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12537
12538 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12539 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12540 @@ -122,16 +117,18 @@ struct thread_info {
12541 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12542 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12543 #define _TIF_X32 (1 << TIF_X32)
12544 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12545
12546 /* work to do in syscall_trace_enter() */
12547 #define _TIF_WORK_SYSCALL_ENTRY \
12548 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12549 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12550 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12551 + _TIF_GRSEC_SETXID)
12552
12553 /* work to do in syscall_trace_leave() */
12554 #define _TIF_WORK_SYSCALL_EXIT \
12555 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12556 - _TIF_SYSCALL_TRACEPOINT)
12557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12558
12559 /* work to do on interrupt/exception return */
12560 #define _TIF_WORK_MASK \
12561 @@ -141,7 +138,8 @@ struct thread_info {
12562
12563 /* work to do on any return to user space */
12564 #define _TIF_ALLWORK_MASK \
12565 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12566 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12567 + _TIF_GRSEC_SETXID)
12568
12569 /* Only used for 64 bit */
12570 #define _TIF_DO_NOTIFY_MASK \
12571 @@ -157,45 +155,40 @@ struct thread_info {
12572
12573 #define PREEMPT_ACTIVE 0x10000000
12574
12575 -#ifdef CONFIG_X86_32
12576 -
12577 -#define STACK_WARN (THREAD_SIZE/8)
12578 -/*
12579 - * macros/functions for gaining access to the thread information structure
12580 - *
12581 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12582 - */
12583 -#ifndef __ASSEMBLY__
12584 -
12585 -
12586 -/* how to get the current stack pointer from C */
12587 -register unsigned long current_stack_pointer asm("esp") __used;
12588 -
12589 -/* how to get the thread information struct from C */
12590 -static inline struct thread_info *current_thread_info(void)
12591 -{
12592 - return (struct thread_info *)
12593 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12594 -}
12595 -
12596 -#else /* !__ASSEMBLY__ */
12597 -
12598 +#ifdef __ASSEMBLY__
12599 /* how to get the thread information struct from ASM */
12600 #define GET_THREAD_INFO(reg) \
12601 - movl $-THREAD_SIZE, reg; \
12602 - andl %esp, reg
12603 + mov PER_CPU_VAR(current_tinfo), reg
12604
12605 /* use this one if reg already contains %esp */
12606 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12607 - andl $-THREAD_SIZE, reg
12608 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12609 +#else
12610 +/* how to get the thread information struct from C */
12611 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12612 +
12613 +static __always_inline struct thread_info *current_thread_info(void)
12614 +{
12615 + return this_cpu_read_stable(current_tinfo);
12616 +}
12617 +#endif
12618 +
12619 +#ifdef CONFIG_X86_32
12620 +
12621 +#define STACK_WARN (THREAD_SIZE/8)
12622 +/*
12623 + * macros/functions for gaining access to the thread information structure
12624 + *
12625 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12626 + */
12627 +#ifndef __ASSEMBLY__
12628 +
12629 +/* how to get the current stack pointer from C */
12630 +register unsigned long current_stack_pointer asm("esp") __used;
12631
12632 #endif
12633
12634 #else /* X86_32 */
12635
12636 -#include <asm/percpu.h>
12637 -#define KERNEL_STACK_OFFSET (5*8)
12638 -
12639 /*
12640 * macros/functions for gaining access to the thread information structure
12641 * preempt_count needs to be 1 initially, until the scheduler is functional.
12642 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12643 #ifndef __ASSEMBLY__
12644 DECLARE_PER_CPU(unsigned long, kernel_stack);
12645
12646 -static inline struct thread_info *current_thread_info(void)
12647 -{
12648 - struct thread_info *ti;
12649 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12650 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12651 - return ti;
12652 -}
12653 -
12654 -#else /* !__ASSEMBLY__ */
12655 -
12656 -/* how to get the thread information struct from ASM */
12657 -#define GET_THREAD_INFO(reg) \
12658 - movq PER_CPU_VAR(kernel_stack),reg ; \
12659 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12660 -
12661 -/*
12662 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12663 - * a certain register (to be used in assembler memory operands).
12664 - */
12665 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12666 -
12667 +/* how to get the current stack pointer from C */
12668 +register unsigned long current_stack_pointer asm("rsp") __used;
12669 #endif
12670
12671 #endif /* !X86_32 */
12672 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12673 extern void arch_task_cache_init(void);
12674 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12675 extern void arch_release_task_struct(struct task_struct *tsk);
12676 +
12677 +#define __HAVE_THREAD_FUNCTIONS
12678 +#define task_thread_info(task) (&(task)->tinfo)
12679 +#define task_stack_page(task) ((task)->stack)
12680 +#define setup_thread_stack(p, org) do {} while (0)
12681 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12682 +
12683 #endif
12684 #endif /* _ASM_X86_THREAD_INFO_H */
12685 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12686 index e1f3a17..1ab364d 100644
12687 --- a/arch/x86/include/asm/uaccess.h
12688 +++ b/arch/x86/include/asm/uaccess.h
12689 @@ -7,12 +7,15 @@
12690 #include <linux/compiler.h>
12691 #include <linux/thread_info.h>
12692 #include <linux/string.h>
12693 +#include <linux/sched.h>
12694 #include <asm/asm.h>
12695 #include <asm/page.h>
12696
12697 #define VERIFY_READ 0
12698 #define VERIFY_WRITE 1
12699
12700 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12701 +
12702 /*
12703 * The fs value determines whether argument validity checking should be
12704 * performed or not. If get_fs() == USER_DS, checking is performed, with
12705 @@ -28,7 +31,12 @@
12706
12707 #define get_ds() (KERNEL_DS)
12708 #define get_fs() (current_thread_info()->addr_limit)
12709 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12710 +void __set_fs(mm_segment_t x);
12711 +void set_fs(mm_segment_t x);
12712 +#else
12713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12714 +#endif
12715
12716 #define segment_eq(a, b) ((a).seg == (b).seg)
12717
12718 @@ -76,8 +84,33 @@
12719 * checks that the pointer is in the user space range - after calling
12720 * this function, memory access functions may still return -EFAULT.
12721 */
12722 -#define access_ok(type, addr, size) \
12723 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12724 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12725 +#define access_ok(type, addr, size) \
12726 +({ \
12727 + long __size = size; \
12728 + unsigned long __addr = (unsigned long)addr; \
12729 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12730 + unsigned long __end_ao = __addr + __size - 1; \
12731 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12732 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12733 + while(__addr_ao <= __end_ao) { \
12734 + char __c_ao; \
12735 + __addr_ao += PAGE_SIZE; \
12736 + if (__size > PAGE_SIZE) \
12737 + cond_resched(); \
12738 + if (__get_user(__c_ao, (char __user *)__addr)) \
12739 + break; \
12740 + if (type != VERIFY_WRITE) { \
12741 + __addr = __addr_ao; \
12742 + continue; \
12743 + } \
12744 + if (__put_user(__c_ao, (char __user *)__addr)) \
12745 + break; \
12746 + __addr = __addr_ao; \
12747 + } \
12748 + } \
12749 + __ret_ao; \
12750 +})
12751
12752 /*
12753 * The exception table consists of pairs of addresses relative to the
12754 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12757
12758 -
12759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12760 +#define __copyuser_seg "gs;"
12761 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12762 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12763 +#else
12764 +#define __copyuser_seg
12765 +#define __COPYUSER_SET_ES
12766 +#define __COPYUSER_RESTORE_ES
12767 +#endif
12768
12769 #ifdef CONFIG_X86_32
12770 #define __put_user_asm_u64(x, addr, err, errret) \
12771 - asm volatile("1: movl %%eax,0(%2)\n" \
12772 - "2: movl %%edx,4(%2)\n" \
12773 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12774 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12775 "3:\n" \
12776 ".section .fixup,\"ax\"\n" \
12777 "4: movl %3,%0\n" \
12778 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12779 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12780
12781 #define __put_user_asm_ex_u64(x, addr) \
12782 - asm volatile("1: movl %%eax,0(%1)\n" \
12783 - "2: movl %%edx,4(%1)\n" \
12784 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12785 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12786 "3:\n" \
12787 _ASM_EXTABLE_EX(1b, 2b) \
12788 _ASM_EXTABLE_EX(2b, 3b) \
12789 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12790 __typeof__(*(ptr)) __pu_val; \
12791 __chk_user_ptr(ptr); \
12792 might_fault(); \
12793 - __pu_val = x; \
12794 + __pu_val = (x); \
12795 switch (sizeof(*(ptr))) { \
12796 case 1: \
12797 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12798 @@ -379,7 +420,7 @@ do { \
12799 } while (0)
12800
12801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12802 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12803 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12804 "2:\n" \
12805 ".section .fixup,\"ax\"\n" \
12806 "3: mov %3,%0\n" \
12807 @@ -387,7 +428,7 @@ do { \
12808 " jmp 2b\n" \
12809 ".previous\n" \
12810 _ASM_EXTABLE(1b, 3b) \
12811 - : "=r" (err), ltype(x) \
12812 + : "=r" (err), ltype (x) \
12813 : "m" (__m(addr)), "i" (errret), "0" (err))
12814
12815 #define __get_user_size_ex(x, ptr, size) \
12816 @@ -412,7 +453,7 @@ do { \
12817 } while (0)
12818
12819 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12820 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12821 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12822 "2:\n" \
12823 _ASM_EXTABLE_EX(1b, 2b) \
12824 : ltype(x) : "m" (__m(addr)))
12825 @@ -429,13 +470,24 @@ do { \
12826 int __gu_err; \
12827 unsigned long __gu_val; \
12828 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12829 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12830 + (x) = (__typeof__(*(ptr)))__gu_val; \
12831 __gu_err; \
12832 })
12833
12834 /* FIXME: this hack is definitely wrong -AK */
12835 struct __large_struct { unsigned long buf[100]; };
12836 -#define __m(x) (*(struct __large_struct __user *)(x))
12837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12838 +#define ____m(x) \
12839 +({ \
12840 + unsigned long ____x = (unsigned long)(x); \
12841 + if (____x < PAX_USER_SHADOW_BASE) \
12842 + ____x += PAX_USER_SHADOW_BASE; \
12843 + (void __user *)____x; \
12844 +})
12845 +#else
12846 +#define ____m(x) (x)
12847 +#endif
12848 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12849
12850 /*
12851 * Tell gcc we read from memory instead of writing: this is because
12852 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12853 * aliasing issues.
12854 */
12855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12856 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12857 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12858 "2:\n" \
12859 ".section .fixup,\"ax\"\n" \
12860 "3: mov %3,%0\n" \
12861 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12862 ".previous\n" \
12863 _ASM_EXTABLE(1b, 3b) \
12864 : "=r"(err) \
12865 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12866 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12867
12868 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12869 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12870 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12871 "2:\n" \
12872 _ASM_EXTABLE_EX(1b, 2b) \
12873 : : ltype(x), "m" (__m(addr)))
12874 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12875 * On error, the variable @x is set to zero.
12876 */
12877
12878 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12879 +#define __get_user(x, ptr) get_user((x), (ptr))
12880 +#else
12881 #define __get_user(x, ptr) \
12882 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12883 +#endif
12884
12885 /**
12886 * __put_user: - Write a simple value into user space, with less checking.
12887 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12888 * Returns zero on success, or -EFAULT on error.
12889 */
12890
12891 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12892 +#define __put_user(x, ptr) put_user((x), (ptr))
12893 +#else
12894 #define __put_user(x, ptr) \
12895 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12896 +#endif
12897
12898 #define __get_user_unaligned __get_user
12899 #define __put_user_unaligned __put_user
12900 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12901 #define get_user_ex(x, ptr) do { \
12902 unsigned long __gue_val; \
12903 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12904 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12905 + (x) = (__typeof__(*(ptr)))__gue_val; \
12906 } while (0)
12907
12908 #ifdef CONFIG_X86_WP_WORKS_OK
12909 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12910 index 576e39b..ccd0a39 100644
12911 --- a/arch/x86/include/asm/uaccess_32.h
12912 +++ b/arch/x86/include/asm/uaccess_32.h
12913 @@ -11,15 +11,15 @@
12914 #include <asm/page.h>
12915
12916 unsigned long __must_check __copy_to_user_ll
12917 - (void __user *to, const void *from, unsigned long n);
12918 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll
12920 - (void *to, const void __user *from, unsigned long n);
12921 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922 unsigned long __must_check __copy_from_user_ll_nozero
12923 - (void *to, const void __user *from, unsigned long n);
12924 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12925 unsigned long __must_check __copy_from_user_ll_nocache
12926 - (void *to, const void __user *from, unsigned long n);
12927 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12928 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12929 - (void *to, const void __user *from, unsigned long n);
12930 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12931
12932 /**
12933 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12934 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12935 static __always_inline unsigned long __must_check
12936 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12937 {
12938 + if ((long)n < 0)
12939 + return n;
12940 +
12941 if (__builtin_constant_p(n)) {
12942 unsigned long ret;
12943
12944 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12945 return ret;
12946 }
12947 }
12948 + if (!__builtin_constant_p(n))
12949 + check_object_size(from, n, true);
12950 return __copy_to_user_ll(to, from, n);
12951 }
12952
12953 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12954 __copy_to_user(void __user *to, const void *from, unsigned long n)
12955 {
12956 might_fault();
12957 +
12958 return __copy_to_user_inatomic(to, from, n);
12959 }
12960
12961 static __always_inline unsigned long
12962 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12963 {
12964 + if ((long)n < 0)
12965 + return n;
12966 +
12967 /* Avoid zeroing the tail if the copy fails..
12968 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12969 * but as the zeroing behaviour is only significant when n is not
12970 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12971 __copy_from_user(void *to, const void __user *from, unsigned long n)
12972 {
12973 might_fault();
12974 +
12975 + if ((long)n < 0)
12976 + return n;
12977 +
12978 if (__builtin_constant_p(n)) {
12979 unsigned long ret;
12980
12981 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12982 return ret;
12983 }
12984 }
12985 + if (!__builtin_constant_p(n))
12986 + check_object_size(to, n, false);
12987 return __copy_from_user_ll(to, from, n);
12988 }
12989
12990 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12991 const void __user *from, unsigned long n)
12992 {
12993 might_fault();
12994 +
12995 + if ((long)n < 0)
12996 + return n;
12997 +
12998 if (__builtin_constant_p(n)) {
12999 unsigned long ret;
13000
13001 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13002 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13003 unsigned long n)
13004 {
13005 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13006 + if ((long)n < 0)
13007 + return n;
13008 +
13009 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13010 }
13011
13012 -unsigned long __must_check copy_to_user(void __user *to,
13013 - const void *from, unsigned long n);
13014 -unsigned long __must_check _copy_from_user(void *to,
13015 - const void __user *from,
13016 - unsigned long n);
13017 -
13018 +extern void copy_to_user_overflow(void)
13019 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13020 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13021 +#else
13022 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13023 +#endif
13024 +;
13025
13026 extern void copy_from_user_overflow(void)
13027 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13028 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13029 #endif
13030 ;
13031
13032 -static inline unsigned long __must_check copy_from_user(void *to,
13033 - const void __user *from,
13034 - unsigned long n)
13035 +/**
13036 + * copy_to_user: - Copy a block of data into user space.
13037 + * @to: Destination address, in user space.
13038 + * @from: Source address, in kernel space.
13039 + * @n: Number of bytes to copy.
13040 + *
13041 + * Context: User context only. This function may sleep.
13042 + *
13043 + * Copy data from kernel space to user space.
13044 + *
13045 + * Returns number of bytes that could not be copied.
13046 + * On success, this will be zero.
13047 + */
13048 +static inline unsigned long __must_check
13049 +copy_to_user(void __user *to, const void *from, unsigned long n)
13050 {
13051 - int sz = __compiletime_object_size(to);
13052 + size_t sz = __compiletime_object_size(from);
13053
13054 - if (likely(sz == -1 || sz >= n))
13055 - n = _copy_from_user(to, from, n);
13056 - else
13057 + if (unlikely(sz != (size_t)-1 && sz < n))
13058 + copy_to_user_overflow();
13059 + else if (access_ok(VERIFY_WRITE, to, n))
13060 + n = __copy_to_user(to, from, n);
13061 + return n;
13062 +}
13063 +
13064 +/**
13065 + * copy_from_user: - Copy a block of data from user space.
13066 + * @to: Destination address, in kernel space.
13067 + * @from: Source address, in user space.
13068 + * @n: Number of bytes to copy.
13069 + *
13070 + * Context: User context only. This function may sleep.
13071 + *
13072 + * Copy data from user space to kernel space.
13073 + *
13074 + * Returns number of bytes that could not be copied.
13075 + * On success, this will be zero.
13076 + *
13077 + * If some data could not be copied, this function will pad the copied
13078 + * data to the requested size using zero bytes.
13079 + */
13080 +static inline unsigned long __must_check
13081 +copy_from_user(void *to, const void __user *from, unsigned long n)
13082 +{
13083 + size_t sz = __compiletime_object_size(to);
13084 +
13085 + if (unlikely(sz != (size_t)-1 && sz < n))
13086 copy_from_user_overflow();
13087 -
13088 + else if (access_ok(VERIFY_READ, from, n))
13089 + n = __copy_from_user(to, from, n);
13090 + else if ((long)n > 0) {
13091 + if (!__builtin_constant_p(n))
13092 + check_object_size(to, n, false);
13093 + memset(to, 0, n);
13094 + }
13095 return n;
13096 }
13097
13098 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13099 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13100 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13101 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13102
13103 #endif /* _ASM_X86_UACCESS_32_H */
13104 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13105 index d8def8b..ac7fc15 100644
13106 --- a/arch/x86/include/asm/uaccess_64.h
13107 +++ b/arch/x86/include/asm/uaccess_64.h
13108 @@ -10,6 +10,9 @@
13109 #include <asm/alternative.h>
13110 #include <asm/cpufeature.h>
13111 #include <asm/page.h>
13112 +#include <asm/pgtable.h>
13113 +
13114 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13115
13116 /*
13117 * Copy To/From Userspace
13118 @@ -17,13 +20,13 @@
13119
13120 /* Handles exceptions in both to and from, but doesn't do access_ok */
13121 __must_check unsigned long
13122 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13123 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13124 __must_check unsigned long
13125 -copy_user_generic_string(void *to, const void *from, unsigned len);
13126 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13127 __must_check unsigned long
13128 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13129 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13130
13131 -static __always_inline __must_check unsigned long
13132 +static __always_inline __must_check __size_overflow(3) unsigned long
13133 copy_user_generic(void *to, const void *from, unsigned len)
13134 {
13135 unsigned ret;
13136 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13137 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13138 "=d" (len)),
13139 "1" (to), "2" (from), "3" (len)
13140 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13141 + : "memory", "rcx", "r8", "r9", "r11");
13142 return ret;
13143 }
13144
13145 +static __always_inline __must_check unsigned long
13146 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13147 +static __always_inline __must_check unsigned long
13148 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13149 __must_check unsigned long
13150 -_copy_to_user(void __user *to, const void *from, unsigned len);
13151 -__must_check unsigned long
13152 -_copy_from_user(void *to, const void __user *from, unsigned len);
13153 -__must_check unsigned long
13154 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13155 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13156 +
13157 +extern void copy_to_user_overflow(void)
13158 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13159 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13160 +#else
13161 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13162 +#endif
13163 +;
13164 +
13165 +extern void copy_from_user_overflow(void)
13166 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13167 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13168 +#else
13169 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13170 +#endif
13171 +;
13172
13173 static inline unsigned long __must_check copy_from_user(void *to,
13174 const void __user *from,
13175 unsigned long n)
13176 {
13177 - int sz = __compiletime_object_size(to);
13178 -
13179 might_fault();
13180 - if (likely(sz == -1 || sz >= n))
13181 - n = _copy_from_user(to, from, n);
13182 -#ifdef CONFIG_DEBUG_VM
13183 - else
13184 - WARN(1, "Buffer overflow detected!\n");
13185 -#endif
13186 +
13187 + if (access_ok(VERIFY_READ, from, n))
13188 + n = __copy_from_user(to, from, n);
13189 + else if (n < INT_MAX) {
13190 + if (!__builtin_constant_p(n))
13191 + check_object_size(to, n, false);
13192 + memset(to, 0, n);
13193 + }
13194 return n;
13195 }
13196
13197 static __always_inline __must_check
13198 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13199 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13200 {
13201 might_fault();
13202
13203 - return _copy_to_user(dst, src, size);
13204 + if (access_ok(VERIFY_WRITE, dst, size))
13205 + size = __copy_to_user(dst, src, size);
13206 + return size;
13207 }
13208
13209 static __always_inline __must_check
13210 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13211 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13212 {
13213 - int ret = 0;
13214 + size_t sz = __compiletime_object_size(dst);
13215 + unsigned ret = 0;
13216
13217 might_fault();
13218 - if (!__builtin_constant_p(size))
13219 - return copy_user_generic(dst, (__force void *)src, size);
13220 +
13221 + if (size > INT_MAX)
13222 + return size;
13223 +
13224 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13225 + if (!__access_ok(VERIFY_READ, src, size))
13226 + return size;
13227 +#endif
13228 +
13229 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13230 + copy_from_user_overflow();
13231 + return size;
13232 + }
13233 +
13234 + if (!__builtin_constant_p(size)) {
13235 + check_object_size(dst, size, false);
13236 +
13237 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13238 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13239 + src += PAX_USER_SHADOW_BASE;
13240 +#endif
13241 +
13242 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13243 + }
13244 switch (size) {
13245 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13246 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13247 ret, "b", "b", "=q", 1);
13248 return ret;
13249 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13250 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13251 ret, "w", "w", "=r", 2);
13252 return ret;
13253 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13254 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13255 ret, "l", "k", "=r", 4);
13256 return ret;
13257 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13258 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13259 ret, "q", "", "=r", 8);
13260 return ret;
13261 case 10:
13262 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13263 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13264 ret, "q", "", "=r", 10);
13265 if (unlikely(ret))
13266 return ret;
13267 __get_user_asm(*(u16 *)(8 + (char *)dst),
13268 - (u16 __user *)(8 + (char __user *)src),
13269 + (const u16 __user *)(8 + (const char __user *)src),
13270 ret, "w", "w", "=r", 2);
13271 return ret;
13272 case 16:
13273 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13274 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13275 ret, "q", "", "=r", 16);
13276 if (unlikely(ret))
13277 return ret;
13278 __get_user_asm(*(u64 *)(8 + (char *)dst),
13279 - (u64 __user *)(8 + (char __user *)src),
13280 + (const u64 __user *)(8 + (const char __user *)src),
13281 ret, "q", "", "=r", 8);
13282 return ret;
13283 default:
13284 - return copy_user_generic(dst, (__force void *)src, size);
13285 +
13286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13287 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13288 + src += PAX_USER_SHADOW_BASE;
13289 +#endif
13290 +
13291 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13292 }
13293 }
13294
13295 static __always_inline __must_check
13296 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13297 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13298 {
13299 - int ret = 0;
13300 + size_t sz = __compiletime_object_size(src);
13301 + unsigned ret = 0;
13302
13303 might_fault();
13304 - if (!__builtin_constant_p(size))
13305 - return copy_user_generic((__force void *)dst, src, size);
13306 +
13307 + if (size > INT_MAX)
13308 + return size;
13309 +
13310 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13311 + if (!__access_ok(VERIFY_WRITE, dst, size))
13312 + return size;
13313 +#endif
13314 +
13315 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13316 + copy_to_user_overflow();
13317 + return size;
13318 + }
13319 +
13320 + if (!__builtin_constant_p(size)) {
13321 + check_object_size(src, size, true);
13322 +
13323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13324 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13325 + dst += PAX_USER_SHADOW_BASE;
13326 +#endif
13327 +
13328 + return copy_user_generic((__force_kernel void *)dst, src, size);
13329 + }
13330 switch (size) {
13331 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13332 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13333 ret, "b", "b", "iq", 1);
13334 return ret;
13335 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13336 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13337 ret, "w", "w", "ir", 2);
13338 return ret;
13339 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13340 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13341 ret, "l", "k", "ir", 4);
13342 return ret;
13343 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13344 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13345 ret, "q", "", "er", 8);
13346 return ret;
13347 case 10:
13348 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13349 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13350 ret, "q", "", "er", 10);
13351 if (unlikely(ret))
13352 return ret;
13353 asm("":::"memory");
13354 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13355 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13356 ret, "w", "w", "ir", 2);
13357 return ret;
13358 case 16:
13359 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13360 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13361 ret, "q", "", "er", 16);
13362 if (unlikely(ret))
13363 return ret;
13364 asm("":::"memory");
13365 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13366 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13367 ret, "q", "", "er", 8);
13368 return ret;
13369 default:
13370 - return copy_user_generic((__force void *)dst, src, size);
13371 +
13372 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13373 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374 + dst += PAX_USER_SHADOW_BASE;
13375 +#endif
13376 +
13377 + return copy_user_generic((__force_kernel void *)dst, src, size);
13378 }
13379 }
13380
13381 static __always_inline __must_check
13382 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13383 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13384 {
13385 - int ret = 0;
13386 + unsigned ret = 0;
13387
13388 might_fault();
13389 - if (!__builtin_constant_p(size))
13390 - return copy_user_generic((__force void *)dst,
13391 - (__force void *)src, size);
13392 +
13393 + if (size > INT_MAX)
13394 + return size;
13395 +
13396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13397 + if (!__access_ok(VERIFY_READ, src, size))
13398 + return size;
13399 + if (!__access_ok(VERIFY_WRITE, dst, size))
13400 + return size;
13401 +#endif
13402 +
13403 + if (!__builtin_constant_p(size)) {
13404 +
13405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13406 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13407 + src += PAX_USER_SHADOW_BASE;
13408 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13409 + dst += PAX_USER_SHADOW_BASE;
13410 +#endif
13411 +
13412 + return copy_user_generic((__force_kernel void *)dst,
13413 + (__force_kernel const void *)src, size);
13414 + }
13415 switch (size) {
13416 case 1: {
13417 u8 tmp;
13418 - __get_user_asm(tmp, (u8 __user *)src,
13419 + __get_user_asm(tmp, (const u8 __user *)src,
13420 ret, "b", "b", "=q", 1);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u8 __user *)dst,
13423 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424 }
13425 case 2: {
13426 u16 tmp;
13427 - __get_user_asm(tmp, (u16 __user *)src,
13428 + __get_user_asm(tmp, (const u16 __user *)src,
13429 ret, "w", "w", "=r", 2);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u16 __user *)dst,
13432 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433
13434 case 4: {
13435 u32 tmp;
13436 - __get_user_asm(tmp, (u32 __user *)src,
13437 + __get_user_asm(tmp, (const u32 __user *)src,
13438 ret, "l", "k", "=r", 4);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u32 __user *)dst,
13441 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 }
13443 case 8: {
13444 u64 tmp;
13445 - __get_user_asm(tmp, (u64 __user *)src,
13446 + __get_user_asm(tmp, (const u64 __user *)src,
13447 ret, "q", "", "=r", 8);
13448 if (likely(!ret))
13449 __put_user_asm(tmp, (u64 __user *)dst,
13450 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13451 return ret;
13452 }
13453 default:
13454 - return copy_user_generic((__force void *)dst,
13455 - (__force void *)src, size);
13456 +
13457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13458 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13459 + src += PAX_USER_SHADOW_BASE;
13460 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13461 + dst += PAX_USER_SHADOW_BASE;
13462 +#endif
13463 +
13464 + return copy_user_generic((__force_kernel void *)dst,
13465 + (__force_kernel const void *)src, size);
13466 }
13467 }
13468
13469 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13470 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13471 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13472 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13473
13474 static __must_check __always_inline int
13475 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13476 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13477 {
13478 - return copy_user_generic(dst, (__force const void *)src, size);
13479 + if (size > INT_MAX)
13480 + return size;
13481 +
13482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13483 + if (!__access_ok(VERIFY_READ, src, size))
13484 + return size;
13485 +
13486 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487 + src += PAX_USER_SHADOW_BASE;
13488 +#endif
13489 +
13490 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13491 }
13492
13493 -static __must_check __always_inline int
13494 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13495 +static __must_check __always_inline unsigned long
13496 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13497 {
13498 - return copy_user_generic((__force void *)dst, src, size);
13499 + if (size > INT_MAX)
13500 + return size;
13501 +
13502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13503 + if (!__access_ok(VERIFY_WRITE, dst, size))
13504 + return size;
13505 +
13506 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13507 + dst += PAX_USER_SHADOW_BASE;
13508 +#endif
13509 +
13510 + return copy_user_generic((__force_kernel void *)dst, src, size);
13511 }
13512
13513 -extern long __copy_user_nocache(void *dst, const void __user *src,
13514 - unsigned size, int zerorest);
13515 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13516 + unsigned long size, int zerorest) __size_overflow(3);
13517
13518 -static inline int
13519 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13520 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13521 {
13522 might_sleep();
13523 +
13524 + if (size > INT_MAX)
13525 + return size;
13526 +
13527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13528 + if (!__access_ok(VERIFY_READ, src, size))
13529 + return size;
13530 +#endif
13531 +
13532 return __copy_user_nocache(dst, src, size, 1);
13533 }
13534
13535 -static inline int
13536 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13537 - unsigned size)
13538 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13539 + unsigned long size)
13540 {
13541 + if (size > INT_MAX)
13542 + return size;
13543 +
13544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13545 + if (!__access_ok(VERIFY_READ, src, size))
13546 + return size;
13547 +#endif
13548 +
13549 return __copy_user_nocache(dst, src, size, 0);
13550 }
13551
13552 -unsigned long
13553 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13554 +extern unsigned long
13555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13556
13557 #endif /* _ASM_X86_UACCESS_64_H */
13558 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13559 index bb05228..d763d5b 100644
13560 --- a/arch/x86/include/asm/vdso.h
13561 +++ b/arch/x86/include/asm/vdso.h
13562 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13563 #define VDSO32_SYMBOL(base, name) \
13564 ({ \
13565 extern const char VDSO32_##name[]; \
13566 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13567 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13568 })
13569 #endif
13570
13571 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13572 index 5b238981..77fdd78 100644
13573 --- a/arch/x86/include/asm/word-at-a-time.h
13574 +++ b/arch/x86/include/asm/word-at-a-time.h
13575 @@ -11,7 +11,7 @@
13576 * and shift, for example.
13577 */
13578 struct word_at_a_time {
13579 - const unsigned long one_bits, high_bits;
13580 + unsigned long one_bits, high_bits;
13581 };
13582
13583 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13584 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13585 index 38155f6..e4184ba 100644
13586 --- a/arch/x86/include/asm/x86_init.h
13587 +++ b/arch/x86/include/asm/x86_init.h
13588 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13589 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13590 void (*find_smp_config)(void);
13591 void (*get_smp_config)(unsigned int early);
13592 -};
13593 +} __no_const;
13594
13595 /**
13596 * struct x86_init_resources - platform specific resource related ops
13597 @@ -43,7 +43,7 @@ struct x86_init_resources {
13598 void (*probe_roms)(void);
13599 void (*reserve_resources)(void);
13600 char *(*memory_setup)(void);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_irqs - platform specific interrupt setup
13606 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13607 void (*pre_vector_init)(void);
13608 void (*intr_init)(void);
13609 void (*trap_init)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_oem - oem platform specific customizing functions
13615 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13616 struct x86_init_oem {
13617 void (*arch_setup)(void);
13618 void (*banner)(void);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13624 @@ -77,7 +77,7 @@ struct x86_init_oem {
13625 */
13626 struct x86_init_mapping {
13627 void (*pagetable_reserve)(u64 start, u64 end);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_paging - platform specific paging functions
13633 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13634 struct x86_init_paging {
13635 void (*pagetable_setup_start)(pgd_t *base);
13636 void (*pagetable_setup_done)(pgd_t *base);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_timers - platform specific timer setup
13642 @@ -102,7 +102,7 @@ struct x86_init_timers {
13643 void (*tsc_pre_init)(void);
13644 void (*timer_init)(void);
13645 void (*wallclock_init)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_iommu - platform specific iommu setup
13651 @@ -110,7 +110,7 @@ struct x86_init_timers {
13652 */
13653 struct x86_init_iommu {
13654 int (*iommu_init)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_pci - platform specific pci init functions
13660 @@ -124,7 +124,7 @@ struct x86_init_pci {
13661 int (*init)(void);
13662 void (*init_irq)(void);
13663 void (*fixup_irqs)(void);
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_init_ops - functions for platform specific setup
13669 @@ -140,7 +140,7 @@ struct x86_init_ops {
13670 struct x86_init_timers timers;
13671 struct x86_init_iommu iommu;
13672 struct x86_init_pci pci;
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13678 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13679 void (*setup_percpu_clockev)(void);
13680 void (*early_percpu_clock_init)(void);
13681 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13682 -};
13683 +} __no_const;
13684
13685 /**
13686 * struct x86_platform_ops - platform specific runtime functions
13687 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13688 void (*save_sched_clock_state)(void);
13689 void (*restore_sched_clock_state)(void);
13690 void (*apic_post_init)(void);
13691 -};
13692 +} __no_const;
13693
13694 struct pci_dev;
13695
13696 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13697 void (*teardown_msi_irq)(unsigned int irq);
13698 void (*teardown_msi_irqs)(struct pci_dev *dev);
13699 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13700 -};
13701 +} __no_const;
13702
13703 struct x86_io_apic_ops {
13704 void (*init) (void);
13705 unsigned int (*read) (unsigned int apic, unsigned int reg);
13706 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13707 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13708 -};
13709 +} __no_const;
13710
13711 extern struct x86_init_ops x86_init;
13712 extern struct x86_cpuinit_ops x86_cpuinit;
13713 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13714 index 8a1b6f9..a29c4e4 100644
13715 --- a/arch/x86/include/asm/xsave.h
13716 +++ b/arch/x86/include/asm/xsave.h
13717 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13718 {
13719 int err;
13720
13721 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13722 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13723 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13724 +#endif
13725 +
13726 /*
13727 * Clear the xsave header first, so that reserved fields are
13728 * initialized to zero.
13729 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13730 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13731 {
13732 int err;
13733 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13734 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13735 u32 lmask = mask;
13736 u32 hmask = mask >> 32;
13737
13738 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13739 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13740 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13741 +#endif
13742 +
13743 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13744 "2:\n"
13745 ".section .fixup,\"ax\"\n"
13746 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13747 index 1b8e5a0..354fd59 100644
13748 --- a/arch/x86/kernel/acpi/sleep.c
13749 +++ b/arch/x86/kernel/acpi/sleep.c
13750 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13751 #else /* CONFIG_64BIT */
13752 #ifdef CONFIG_SMP
13753 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13754 +
13755 + pax_open_kernel();
13756 early_gdt_descr.address =
13757 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13758 + pax_close_kernel();
13759 +
13760 initial_gs = per_cpu_offset(smp_processor_id());
13761 #endif
13762 initial_code = (unsigned long)wakeup_long64;
13763 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13764 index 13ab720..95d5442 100644
13765 --- a/arch/x86/kernel/acpi/wakeup_32.S
13766 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13767 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13768 # and restore the stack ... but you need gdt for this to work
13769 movl saved_context_esp, %esp
13770
13771 - movl %cs:saved_magic, %eax
13772 - cmpl $0x12345678, %eax
13773 + cmpl $0x12345678, saved_magic
13774 jne bogus_magic
13775
13776 # jump to place where we left off
13777 - movl saved_eip, %eax
13778 - jmp *%eax
13779 + jmp *(saved_eip)
13780
13781 bogus_magic:
13782 jmp bogus_magic
13783 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13784 index ced4534..3e75d69 100644
13785 --- a/arch/x86/kernel/alternative.c
13786 +++ b/arch/x86/kernel/alternative.c
13787 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13788 */
13789 for (a = start; a < end; a++) {
13790 instr = (u8 *)&a->instr_offset + a->instr_offset;
13791 +
13792 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13793 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13794 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13795 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13796 +#endif
13797 +
13798 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13799 BUG_ON(a->replacementlen > a->instrlen);
13800 BUG_ON(a->instrlen > sizeof(insnbuf));
13801 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13802 for (poff = start; poff < end; poff++) {
13803 u8 *ptr = (u8 *)poff + *poff;
13804
13805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13806 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13808 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13809 +#endif
13810 +
13811 if (!*poff || ptr < text || ptr >= text_end)
13812 continue;
13813 /* turn DS segment override prefix into lock prefix */
13814 - if (*ptr == 0x3e)
13815 + if (*ktla_ktva(ptr) == 0x3e)
13816 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13817 };
13818 mutex_unlock(&text_mutex);
13819 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13820 for (poff = start; poff < end; poff++) {
13821 u8 *ptr = (u8 *)poff + *poff;
13822
13823 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13824 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13825 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13826 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13827 +#endif
13828 +
13829 if (!*poff || ptr < text || ptr >= text_end)
13830 continue;
13831 /* turn lock prefix into DS segment override prefix */
13832 - if (*ptr == 0xf0)
13833 + if (*ktla_ktva(ptr) == 0xf0)
13834 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13835 };
13836 mutex_unlock(&text_mutex);
13837 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13838
13839 BUG_ON(p->len > MAX_PATCH_LEN);
13840 /* prep the buffer with the original instructions */
13841 - memcpy(insnbuf, p->instr, p->len);
13842 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13843 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13844 (unsigned long)p->instr, p->len);
13845
13846 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13847 if (smp_alt_once)
13848 free_init_pages("SMP alternatives",
13849 (unsigned long)__smp_locks,
13850 - (unsigned long)__smp_locks_end);
13851 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13852
13853 restart_nmi();
13854 }
13855 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13856 * instructions. And on the local CPU you need to be protected again NMI or MCE
13857 * handlers seeing an inconsistent instruction while you patch.
13858 */
13859 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13860 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13861 size_t len)
13862 {
13863 unsigned long flags;
13864 local_irq_save(flags);
13865 - memcpy(addr, opcode, len);
13866 +
13867 + pax_open_kernel();
13868 + memcpy(ktla_ktva(addr), opcode, len);
13869 sync_core();
13870 + pax_close_kernel();
13871 +
13872 local_irq_restore(flags);
13873 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13874 that causes hangs on some VIA CPUs. */
13875 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13876 */
13877 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13878 {
13879 - unsigned long flags;
13880 - char *vaddr;
13881 + unsigned char *vaddr = ktla_ktva(addr);
13882 struct page *pages[2];
13883 - int i;
13884 + size_t i;
13885
13886 if (!core_kernel_text((unsigned long)addr)) {
13887 - pages[0] = vmalloc_to_page(addr);
13888 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13889 + pages[0] = vmalloc_to_page(vaddr);
13890 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13891 } else {
13892 - pages[0] = virt_to_page(addr);
13893 + pages[0] = virt_to_page(vaddr);
13894 WARN_ON(!PageReserved(pages[0]));
13895 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13896 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13897 }
13898 BUG_ON(!pages[0]);
13899 - local_irq_save(flags);
13900 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13901 - if (pages[1])
13902 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13903 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13904 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13905 - clear_fixmap(FIX_TEXT_POKE0);
13906 - if (pages[1])
13907 - clear_fixmap(FIX_TEXT_POKE1);
13908 - local_flush_tlb();
13909 - sync_core();
13910 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13911 - that causes hangs on some VIA CPUs. */
13912 + text_poke_early(addr, opcode, len);
13913 for (i = 0; i < len; i++)
13914 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13915 - local_irq_restore(flags);
13916 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13917 return addr;
13918 }
13919
13920 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13921 index 24deb30..94a3426 100644
13922 --- a/arch/x86/kernel/apic/apic.c
13923 +++ b/arch/x86/kernel/apic/apic.c
13924 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13925 /*
13926 * Debug level, exported for io_apic.c
13927 */
13928 -unsigned int apic_verbosity;
13929 +int apic_verbosity;
13930
13931 int pic_mode;
13932
13933 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13934 apic_write(APIC_ESR, 0);
13935 v1 = apic_read(APIC_ESR);
13936 ack_APIC_irq();
13937 - atomic_inc(&irq_err_count);
13938 + atomic_inc_unchecked(&irq_err_count);
13939
13940 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13941 smp_processor_id(), v0 , v1);
13942 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13943 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13944 /* Should happen once for each apic */
13945 WARN_ON((*drv)->eoi_write == eoi_write);
13946 - (*drv)->eoi_write = eoi_write;
13947 + pax_open_kernel();
13948 + *(void **)&(*drv)->eoi_write = eoi_write;
13949 + pax_close_kernel();
13950 }
13951 }
13952
13953 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13954 index c265593..137c4ac 100644
13955 --- a/arch/x86/kernel/apic/io_apic.c
13956 +++ b/arch/x86/kernel/apic/io_apic.c
13957 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13958 }
13959 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13960
13961 -void lock_vector_lock(void)
13962 +void lock_vector_lock(void) __acquires(vector_lock)
13963 {
13964 /* Used to the online set of cpus does not change
13965 * during assign_irq_vector.
13966 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13967 raw_spin_lock(&vector_lock);
13968 }
13969
13970 -void unlock_vector_lock(void)
13971 +void unlock_vector_lock(void) __releases(vector_lock)
13972 {
13973 raw_spin_unlock(&vector_lock);
13974 }
13975 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13976 ack_APIC_irq();
13977 }
13978
13979 -atomic_t irq_mis_count;
13980 +atomic_unchecked_t irq_mis_count;
13981
13982 #ifdef CONFIG_GENERIC_PENDING_IRQ
13983 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13984 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13985 * at the cpu.
13986 */
13987 if (!(v & (1 << (i & 0x1f)))) {
13988 - atomic_inc(&irq_mis_count);
13989 + atomic_inc_unchecked(&irq_mis_count);
13990
13991 eoi_ioapic_irq(irq, cfg);
13992 }
13993 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13994 index d65464e..1035d31 100644
13995 --- a/arch/x86/kernel/apm_32.c
13996 +++ b/arch/x86/kernel/apm_32.c
13997 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13998 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13999 * even though they are called in protected mode.
14000 */
14001 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14002 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14003 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14004
14005 static const char driver_version[] = "1.16ac"; /* no spaces */
14006 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14007 BUG_ON(cpu != 0);
14008 gdt = get_cpu_gdt_table(cpu);
14009 save_desc_40 = gdt[0x40 / 8];
14010 +
14011 + pax_open_kernel();
14012 gdt[0x40 / 8] = bad_bios_desc;
14013 + pax_close_kernel();
14014
14015 apm_irq_save(flags);
14016 APM_DO_SAVE_SEGS;
14017 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14018 &call->esi);
14019 APM_DO_RESTORE_SEGS;
14020 apm_irq_restore(flags);
14021 +
14022 + pax_open_kernel();
14023 gdt[0x40 / 8] = save_desc_40;
14024 + pax_close_kernel();
14025 +
14026 put_cpu();
14027
14028 return call->eax & 0xff;
14029 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14030 BUG_ON(cpu != 0);
14031 gdt = get_cpu_gdt_table(cpu);
14032 save_desc_40 = gdt[0x40 / 8];
14033 +
14034 + pax_open_kernel();
14035 gdt[0x40 / 8] = bad_bios_desc;
14036 + pax_close_kernel();
14037
14038 apm_irq_save(flags);
14039 APM_DO_SAVE_SEGS;
14040 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14041 &call->eax);
14042 APM_DO_RESTORE_SEGS;
14043 apm_irq_restore(flags);
14044 +
14045 + pax_open_kernel();
14046 gdt[0x40 / 8] = save_desc_40;
14047 + pax_close_kernel();
14048 +
14049 put_cpu();
14050 return error;
14051 }
14052 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14053 * code to that CPU.
14054 */
14055 gdt = get_cpu_gdt_table(0);
14056 +
14057 + pax_open_kernel();
14058 set_desc_base(&gdt[APM_CS >> 3],
14059 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14060 set_desc_base(&gdt[APM_CS_16 >> 3],
14061 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14062 set_desc_base(&gdt[APM_DS >> 3],
14063 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14064 + pax_close_kernel();
14065
14066 proc_create("apm", 0, NULL, &apm_file_ops);
14067
14068 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14069 index 68de2dc..1f3c720 100644
14070 --- a/arch/x86/kernel/asm-offsets.c
14071 +++ b/arch/x86/kernel/asm-offsets.c
14072 @@ -33,6 +33,8 @@ void common(void) {
14073 OFFSET(TI_status, thread_info, status);
14074 OFFSET(TI_addr_limit, thread_info, addr_limit);
14075 OFFSET(TI_preempt_count, thread_info, preempt_count);
14076 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14077 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14078
14079 BLANK();
14080 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14081 @@ -53,8 +55,26 @@ void common(void) {
14082 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14083 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14084 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14085 +
14086 +#ifdef CONFIG_PAX_KERNEXEC
14087 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14088 #endif
14089
14090 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14091 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14092 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14093 +#ifdef CONFIG_X86_64
14094 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14095 +#endif
14096 +#endif
14097 +
14098 +#endif
14099 +
14100 + BLANK();
14101 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14102 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14103 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14104 +
14105 #ifdef CONFIG_XEN
14106 BLANK();
14107 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14108 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14109 index 1b4754f..fbb4227 100644
14110 --- a/arch/x86/kernel/asm-offsets_64.c
14111 +++ b/arch/x86/kernel/asm-offsets_64.c
14112 @@ -76,6 +76,7 @@ int main(void)
14113 BLANK();
14114 #undef ENTRY
14115
14116 + DEFINE(TSS_size, sizeof(struct tss_struct));
14117 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14118 BLANK();
14119
14120 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14121 index d30a6a9..79becab 100644
14122 --- a/arch/x86/kernel/cpu/Makefile
14123 +++ b/arch/x86/kernel/cpu/Makefile
14124 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14125 CFLAGS_REMOVE_perf_event.o = -pg
14126 endif
14127
14128 -# Make sure load_percpu_segment has no stackprotector
14129 -nostackp := $(call cc-option, -fno-stack-protector)
14130 -CFLAGS_common.o := $(nostackp)
14131 -
14132 obj-y := intel_cacheinfo.o scattered.o topology.o
14133 obj-y += proc.o capflags.o powerflags.o common.o
14134 obj-y += vmware.o hypervisor.o mshyperv.o
14135 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14136 index 9d92e19..49d7d79 100644
14137 --- a/arch/x86/kernel/cpu/amd.c
14138 +++ b/arch/x86/kernel/cpu/amd.c
14139 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14140 unsigned int size)
14141 {
14142 /* AMD errata T13 (order #21922) */
14143 - if ((c->x86 == 6)) {
14144 + if (c->x86 == 6) {
14145 /* Duron Rev A0 */
14146 if (c->x86_model == 3 && c->x86_mask == 0)
14147 size = 64;
14148 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14149 index a5fbc3c..2254849 100644
14150 --- a/arch/x86/kernel/cpu/common.c
14151 +++ b/arch/x86/kernel/cpu/common.c
14152 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14153
14154 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14155
14156 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14157 -#ifdef CONFIG_X86_64
14158 - /*
14159 - * We need valid kernel segments for data and code in long mode too
14160 - * IRET will check the segment types kkeil 2000/10/28
14161 - * Also sysret mandates a special GDT layout
14162 - *
14163 - * TLS descriptors are currently at a different place compared to i386.
14164 - * Hopefully nobody expects them at a fixed place (Wine?)
14165 - */
14166 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14167 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14168 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14169 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14170 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14171 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14172 -#else
14173 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14174 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14175 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14176 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14177 - /*
14178 - * Segments used for calling PnP BIOS have byte granularity.
14179 - * They code segments and data segments have fixed 64k limits,
14180 - * the transfer segment sizes are set at run time.
14181 - */
14182 - /* 32-bit code */
14183 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14184 - /* 16-bit code */
14185 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14186 - /* 16-bit data */
14187 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14188 - /* 16-bit data */
14189 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14190 - /* 16-bit data */
14191 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14192 - /*
14193 - * The APM segments have byte granularity and their bases
14194 - * are set at run time. All have 64k limits.
14195 - */
14196 - /* 32-bit code */
14197 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14198 - /* 16-bit code */
14199 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14200 - /* data */
14201 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14202 -
14203 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14204 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14205 - GDT_STACK_CANARY_INIT
14206 -#endif
14207 -} };
14208 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14209 -
14210 static int __init x86_xsave_setup(char *s)
14211 {
14212 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14213 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14214 {
14215 struct desc_ptr gdt_descr;
14216
14217 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14218 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14219 gdt_descr.size = GDT_SIZE - 1;
14220 load_gdt(&gdt_descr);
14221 /* Reload the per-cpu base */
14222 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14223 /* Filter out anything that depends on CPUID levels we don't have */
14224 filter_cpuid_features(c, true);
14225
14226 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14227 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14228 +#endif
14229 +
14230 /* If the model name is still unset, do table lookup. */
14231 if (!c->x86_model_id[0]) {
14232 const char *p;
14233 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14234 }
14235 __setup("clearcpuid=", setup_disablecpuid);
14236
14237 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14238 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14239 +
14240 #ifdef CONFIG_X86_64
14241 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14242 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14243 - (unsigned long) nmi_idt_table };
14244 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14245
14246 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14247 irq_stack_union) __aligned(PAGE_SIZE);
14248 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14249 EXPORT_PER_CPU_SYMBOL(current_task);
14250
14251 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14252 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14253 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14254 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14255
14256 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14257 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14258 {
14259 memset(regs, 0, sizeof(struct pt_regs));
14260 regs->fs = __KERNEL_PERCPU;
14261 - regs->gs = __KERNEL_STACK_CANARY;
14262 + savesegment(gs, regs->gs);
14263
14264 return regs;
14265 }
14266 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14267 int i;
14268
14269 cpu = stack_smp_processor_id();
14270 - t = &per_cpu(init_tss, cpu);
14271 + t = init_tss + cpu;
14272 oist = &per_cpu(orig_ist, cpu);
14273
14274 #ifdef CONFIG_NUMA
14275 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14276 switch_to_new_gdt(cpu);
14277 loadsegment(fs, 0);
14278
14279 - load_idt((const struct desc_ptr *)&idt_descr);
14280 + load_idt(&idt_descr);
14281
14282 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14283 syscall_init();
14284 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14285 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14286 barrier();
14287
14288 - x86_configure_nx();
14289 if (cpu != 0)
14290 enable_x2apic();
14291
14292 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14293 {
14294 int cpu = smp_processor_id();
14295 struct task_struct *curr = current;
14296 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14297 + struct tss_struct *t = init_tss + cpu;
14298 struct thread_struct *thread = &curr->thread;
14299
14300 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14301 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14302 index 0a4ce29..f211176 100644
14303 --- a/arch/x86/kernel/cpu/intel.c
14304 +++ b/arch/x86/kernel/cpu/intel.c
14305 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14306 * Update the IDT descriptor and reload the IDT so that
14307 * it uses the read-only mapped virtual address.
14308 */
14309 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14310 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14311 load_idt(&idt_descr);
14312 }
14313 #endif
14314 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14315 index 292d025..b520c94 100644
14316 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14317 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14318 @@ -45,6 +45,7 @@
14319 #include <asm/processor.h>
14320 #include <asm/mce.h>
14321 #include <asm/msr.h>
14322 +#include <asm/local.h>
14323
14324 #include "mce-internal.h"
14325
14326 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14327 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14328 m->cs, m->ip);
14329
14330 - if (m->cs == __KERNEL_CS)
14331 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14332 print_symbol("{%s}", m->ip);
14333 pr_cont("\n");
14334 }
14335 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14336
14337 #define PANIC_TIMEOUT 5 /* 5 seconds */
14338
14339 -static atomic_t mce_paniced;
14340 +static atomic_unchecked_t mce_paniced;
14341
14342 static int fake_panic;
14343 -static atomic_t mce_fake_paniced;
14344 +static atomic_unchecked_t mce_fake_paniced;
14345
14346 /* Panic in progress. Enable interrupts and wait for final IPI */
14347 static void wait_for_panic(void)
14348 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 /*
14350 * Make sure only one CPU runs in machine check panic
14351 */
14352 - if (atomic_inc_return(&mce_paniced) > 1)
14353 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14354 wait_for_panic();
14355 barrier();
14356
14357 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14358 console_verbose();
14359 } else {
14360 /* Don't log too much for fake panic */
14361 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14362 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14363 return;
14364 }
14365 /* First print corrected ones that are still unlogged */
14366 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14367 * might have been modified by someone else.
14368 */
14369 rmb();
14370 - if (atomic_read(&mce_paniced))
14371 + if (atomic_read_unchecked(&mce_paniced))
14372 wait_for_panic();
14373 if (!monarch_timeout)
14374 goto out;
14375 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14376 }
14377
14378 /* Call the installed machine check handler for this CPU setup. */
14379 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14380 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14381 unexpected_machine_check;
14382
14383 /*
14384 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14385 return;
14386 }
14387
14388 + pax_open_kernel();
14389 machine_check_vector = do_machine_check;
14390 + pax_close_kernel();
14391
14392 __mcheck_cpu_init_generic();
14393 __mcheck_cpu_init_vendor(c);
14394 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14395 */
14396
14397 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14398 -static int mce_chrdev_open_count; /* #times opened */
14399 +static local_t mce_chrdev_open_count; /* #times opened */
14400 static int mce_chrdev_open_exclu; /* already open exclusive? */
14401
14402 static int mce_chrdev_open(struct inode *inode, struct file *file)
14403 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404 spin_lock(&mce_chrdev_state_lock);
14405
14406 if (mce_chrdev_open_exclu ||
14407 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14408 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14409 spin_unlock(&mce_chrdev_state_lock);
14410
14411 return -EBUSY;
14412 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14413
14414 if (file->f_flags & O_EXCL)
14415 mce_chrdev_open_exclu = 1;
14416 - mce_chrdev_open_count++;
14417 + local_inc(&mce_chrdev_open_count);
14418
14419 spin_unlock(&mce_chrdev_state_lock);
14420
14421 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14422 {
14423 spin_lock(&mce_chrdev_state_lock);
14424
14425 - mce_chrdev_open_count--;
14426 + local_dec(&mce_chrdev_open_count);
14427 mce_chrdev_open_exclu = 0;
14428
14429 spin_unlock(&mce_chrdev_state_lock);
14430 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14431 static void mce_reset(void)
14432 {
14433 cpu_missing = 0;
14434 - atomic_set(&mce_fake_paniced, 0);
14435 + atomic_set_unchecked(&mce_fake_paniced, 0);
14436 atomic_set(&mce_executing, 0);
14437 atomic_set(&mce_callin, 0);
14438 atomic_set(&global_nwo, 0);
14439 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14440 index 2d5454c..51987eb 100644
14441 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14442 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14443 @@ -11,6 +11,7 @@
14444 #include <asm/processor.h>
14445 #include <asm/mce.h>
14446 #include <asm/msr.h>
14447 +#include <asm/pgtable.h>
14448
14449 /* By default disabled */
14450 int mce_p5_enabled __read_mostly;
14451 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14452 if (!cpu_has(c, X86_FEATURE_MCE))
14453 return;
14454
14455 + pax_open_kernel();
14456 machine_check_vector = pentium_machine_check;
14457 + pax_close_kernel();
14458 /* Make sure the vector pointer is visible before we enable MCEs: */
14459 wmb();
14460
14461 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14462 index 2d7998f..17c9de1 100644
14463 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14464 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14465 @@ -10,6 +10,7 @@
14466 #include <asm/processor.h>
14467 #include <asm/mce.h>
14468 #include <asm/msr.h>
14469 +#include <asm/pgtable.h>
14470
14471 /* Machine check handler for WinChip C6: */
14472 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14473 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14474 {
14475 u32 lo, hi;
14476
14477 + pax_open_kernel();
14478 machine_check_vector = winchip_machine_check;
14479 + pax_close_kernel();
14480 /* Make sure the vector pointer is visible before we enable MCEs: */
14481 wmb();
14482
14483 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14484 index 6b96110..0da73eb 100644
14485 --- a/arch/x86/kernel/cpu/mtrr/main.c
14486 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14487 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14488 u64 size_or_mask, size_and_mask;
14489 static bool mtrr_aps_delayed_init;
14490
14491 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14492 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14493
14494 const struct mtrr_ops *mtrr_if;
14495
14496 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14497 index df5e41f..816c719 100644
14498 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14499 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14500 @@ -25,7 +25,7 @@ struct mtrr_ops {
14501 int (*validate_add_page)(unsigned long base, unsigned long size,
14502 unsigned int type);
14503 int (*have_wrcomb)(void);
14504 -};
14505 +} __do_const;
14506
14507 extern int generic_get_free_region(unsigned long base, unsigned long size,
14508 int replace_reg);
14509 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14510 index 915b876..171f845 100644
14511 --- a/arch/x86/kernel/cpu/perf_event.c
14512 +++ b/arch/x86/kernel/cpu/perf_event.c
14513 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14514 if (idx > GDT_ENTRIES)
14515 return 0;
14516
14517 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14518 + desc = get_cpu_gdt_table(smp_processor_id());
14519 }
14520
14521 return get_desc_base(desc + idx);
14522 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14523 break;
14524
14525 perf_callchain_store(entry, frame.return_address);
14526 - fp = frame.next_frame;
14527 + fp = (const void __force_user *)frame.next_frame;
14528 }
14529 }
14530
14531 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14532 index 6bca492..36e4496 100644
14533 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14534 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14535 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14536 * v2 and above have a perf capabilities MSR
14537 */
14538 if (version > 1) {
14539 - u64 capabilities;
14540 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14541
14542 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14543 - x86_pmu.intel_cap.capabilities = capabilities;
14544 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14545 + x86_pmu.intel_cap.capabilities = capabilities;
14546 }
14547
14548 intel_ds_init();
14549 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14550 index 13ad899..f642b9a 100644
14551 --- a/arch/x86/kernel/crash.c
14552 +++ b/arch/x86/kernel/crash.c
14553 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14554 {
14555 #ifdef CONFIG_X86_32
14556 struct pt_regs fixed_regs;
14557 -#endif
14558
14559 -#ifdef CONFIG_X86_32
14560 - if (!user_mode_vm(regs)) {
14561 + if (!user_mode(regs)) {
14562 crash_fixup_ss_esp(&fixed_regs, regs);
14563 regs = &fixed_regs;
14564 }
14565 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14566 index 37250fe..bf2ec74 100644
14567 --- a/arch/x86/kernel/doublefault_32.c
14568 +++ b/arch/x86/kernel/doublefault_32.c
14569 @@ -11,7 +11,7 @@
14570
14571 #define DOUBLEFAULT_STACKSIZE (1024)
14572 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14573 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14574 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14575
14576 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14577
14578 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14579 unsigned long gdt, tss;
14580
14581 store_gdt(&gdt_desc);
14582 - gdt = gdt_desc.address;
14583 + gdt = (unsigned long)gdt_desc.address;
14584
14585 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14586
14587 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14588 /* 0x2 bit is always set */
14589 .flags = X86_EFLAGS_SF | 0x2,
14590 .sp = STACK_START,
14591 - .es = __USER_DS,
14592 + .es = __KERNEL_DS,
14593 .cs = __KERNEL_CS,
14594 .ss = __KERNEL_DS,
14595 - .ds = __USER_DS,
14596 + .ds = __KERNEL_DS,
14597 .fs = __KERNEL_PERCPU,
14598
14599 .__cr3 = __pa_nodebug(swapper_pg_dir),
14600 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14601 index ae42418b..787c16b 100644
14602 --- a/arch/x86/kernel/dumpstack.c
14603 +++ b/arch/x86/kernel/dumpstack.c
14604 @@ -2,6 +2,9 @@
14605 * Copyright (C) 1991, 1992 Linus Torvalds
14606 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14607 */
14608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14609 +#define __INCLUDED_BY_HIDESYM 1
14610 +#endif
14611 #include <linux/kallsyms.h>
14612 #include <linux/kprobes.h>
14613 #include <linux/uaccess.h>
14614 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14615 static void
14616 print_ftrace_graph_addr(unsigned long addr, void *data,
14617 const struct stacktrace_ops *ops,
14618 - struct thread_info *tinfo, int *graph)
14619 + struct task_struct *task, int *graph)
14620 {
14621 - struct task_struct *task;
14622 unsigned long ret_addr;
14623 int index;
14624
14625 if (addr != (unsigned long)return_to_handler)
14626 return;
14627
14628 - task = tinfo->task;
14629 index = task->curr_ret_stack;
14630
14631 if (!task->ret_stack || index < *graph)
14632 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 static inline void
14634 print_ftrace_graph_addr(unsigned long addr, void *data,
14635 const struct stacktrace_ops *ops,
14636 - struct thread_info *tinfo, int *graph)
14637 + struct task_struct *task, int *graph)
14638 { }
14639 #endif
14640
14641 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14642 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14643 */
14644
14645 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14646 - void *p, unsigned int size, void *end)
14647 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14648 {
14649 - void *t = tinfo;
14650 if (end) {
14651 if (p < end && p >= (end-THREAD_SIZE))
14652 return 1;
14653 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 }
14655
14656 unsigned long
14657 -print_context_stack(struct thread_info *tinfo,
14658 +print_context_stack(struct task_struct *task, void *stack_start,
14659 unsigned long *stack, unsigned long bp,
14660 const struct stacktrace_ops *ops, void *data,
14661 unsigned long *end, int *graph)
14662 {
14663 struct stack_frame *frame = (struct stack_frame *)bp;
14664
14665 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14666 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14667 unsigned long addr;
14668
14669 addr = *stack;
14670 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14671 } else {
14672 ops->address(data, addr, 0);
14673 }
14674 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677 stack++;
14678 }
14679 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14680 EXPORT_SYMBOL_GPL(print_context_stack);
14681
14682 unsigned long
14683 -print_context_stack_bp(struct thread_info *tinfo,
14684 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14685 unsigned long *stack, unsigned long bp,
14686 const struct stacktrace_ops *ops, void *data,
14687 unsigned long *end, int *graph)
14688 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 struct stack_frame *frame = (struct stack_frame *)bp;
14690 unsigned long *ret_addr = &frame->return_address;
14691
14692 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14693 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14694 unsigned long addr = *ret_addr;
14695
14696 if (!__kernel_text_address(addr))
14697 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14698 ops->address(data, addr, 1);
14699 frame = frame->next_frame;
14700 ret_addr = &frame->return_address;
14701 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14702 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14703 }
14704
14705 return (unsigned long)frame;
14706 @@ -189,7 +188,7 @@ void dump_stack(void)
14707
14708 bp = stack_frame(current, NULL);
14709 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14710 - current->pid, current->comm, print_tainted(),
14711 + task_pid_nr(current), current->comm, print_tainted(),
14712 init_utsname()->release,
14713 (int)strcspn(init_utsname()->version, " "),
14714 init_utsname()->version);
14715 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14716 }
14717 EXPORT_SYMBOL_GPL(oops_begin);
14718
14719 +extern void gr_handle_kernel_exploit(void);
14720 +
14721 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14722 {
14723 if (regs && kexec_should_crash(current))
14724 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14725 panic("Fatal exception in interrupt");
14726 if (panic_on_oops)
14727 panic("Fatal exception");
14728 - do_exit(signr);
14729 +
14730 + gr_handle_kernel_exploit();
14731 +
14732 + do_group_exit(signr);
14733 }
14734
14735 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14736 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14737 print_modules();
14738 show_regs(regs);
14739 #ifdef CONFIG_X86_32
14740 - if (user_mode_vm(regs)) {
14741 + if (user_mode(regs)) {
14742 sp = regs->sp;
14743 ss = regs->ss & 0xffff;
14744 } else {
14745 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14746 unsigned long flags = oops_begin();
14747 int sig = SIGSEGV;
14748
14749 - if (!user_mode_vm(regs))
14750 + if (!user_mode(regs))
14751 report_bug(regs->ip, regs);
14752
14753 if (__die(str, regs, err))
14754 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14755 index 1038a41..ac7e5f6 100644
14756 --- a/arch/x86/kernel/dumpstack_32.c
14757 +++ b/arch/x86/kernel/dumpstack_32.c
14758 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14759 bp = stack_frame(task, regs);
14760
14761 for (;;) {
14762 - struct thread_info *context;
14763 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14764
14765 - context = (struct thread_info *)
14766 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14767 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14768 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14769
14770 - stack = (unsigned long *)context->previous_esp;
14771 - if (!stack)
14772 + if (stack_start == task_stack_page(task))
14773 break;
14774 + stack = *(unsigned long **)stack_start;
14775 if (ops->stack(data, "IRQ") < 0)
14776 break;
14777 touch_nmi_watchdog();
14778 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14779 {
14780 int i;
14781
14782 - __show_regs(regs, !user_mode_vm(regs));
14783 + __show_regs(regs, !user_mode(regs));
14784
14785 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14786 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14787 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14788 * When in-kernel, we also print out the stack and code at the
14789 * time of the fault..
14790 */
14791 - if (!user_mode_vm(regs)) {
14792 + if (!user_mode(regs)) {
14793 unsigned int code_prologue = code_bytes * 43 / 64;
14794 unsigned int code_len = code_bytes;
14795 unsigned char c;
14796 u8 *ip;
14797 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14798
14799 pr_emerg("Stack:\n");
14800 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14801
14802 pr_emerg("Code:");
14803
14804 - ip = (u8 *)regs->ip - code_prologue;
14805 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14806 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14807 /* try starting at IP */
14808 - ip = (u8 *)regs->ip;
14809 + ip = (u8 *)regs->ip + cs_base;
14810 code_len = code_len - code_prologue + 1;
14811 }
14812 for (i = 0; i < code_len; i++, ip++) {
14813 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14814 pr_cont(" Bad EIP value.");
14815 break;
14816 }
14817 - if (ip == (u8 *)regs->ip)
14818 + if (ip == (u8 *)regs->ip + cs_base)
14819 pr_cont(" <%02x>", c);
14820 else
14821 pr_cont(" %02x", c);
14822 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14823 {
14824 unsigned short ud2;
14825
14826 + ip = ktla_ktva(ip);
14827 if (ip < PAGE_OFFSET)
14828 return 0;
14829 if (probe_kernel_address((unsigned short *)ip, ud2))
14830 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14831
14832 return ud2 == 0x0b0f;
14833 }
14834 +
14835 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14836 +void pax_check_alloca(unsigned long size)
14837 +{
14838 + unsigned long sp = (unsigned long)&sp, stack_left;
14839 +
14840 + /* all kernel stacks are of the same size */
14841 + stack_left = sp & (THREAD_SIZE - 1);
14842 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14843 +}
14844 +EXPORT_SYMBOL(pax_check_alloca);
14845 +#endif
14846 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14847 index b653675..33190c0 100644
14848 --- a/arch/x86/kernel/dumpstack_64.c
14849 +++ b/arch/x86/kernel/dumpstack_64.c
14850 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14851 unsigned long *irq_stack_end =
14852 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14853 unsigned used = 0;
14854 - struct thread_info *tinfo;
14855 int graph = 0;
14856 unsigned long dummy;
14857 + void *stack_start;
14858
14859 if (!task)
14860 task = current;
14861 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 * current stack address. If the stacks consist of nested
14863 * exceptions
14864 */
14865 - tinfo = task_thread_info(task);
14866 for (;;) {
14867 char *id;
14868 unsigned long *estack_end;
14869 +
14870 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14871 &used, &id);
14872
14873 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 if (ops->stack(data, id) < 0)
14875 break;
14876
14877 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14878 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14879 data, estack_end, &graph);
14880 ops->stack(data, "<EOE>");
14881 /*
14882 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 * second-to-last pointer (index -2 to end) in the
14884 * exception stack:
14885 */
14886 + if ((u16)estack_end[-1] != __KERNEL_DS)
14887 + goto out;
14888 stack = (unsigned long *) estack_end[-2];
14889 continue;
14890 }
14891 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14893 if (ops->stack(data, "IRQ") < 0)
14894 break;
14895 - bp = ops->walk_stack(tinfo, stack, bp,
14896 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14897 ops, data, irq_stack_end, &graph);
14898 /*
14899 * We link to the next stack (which would be
14900 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14901 /*
14902 * This handles the process stack:
14903 */
14904 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14905 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14906 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14907 +out:
14908 put_cpu();
14909 }
14910 EXPORT_SYMBOL(dump_trace);
14911 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14912
14913 return ud2 == 0x0b0f;
14914 }
14915 +
14916 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14917 +void pax_check_alloca(unsigned long size)
14918 +{
14919 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14920 + unsigned cpu, used;
14921 + char *id;
14922 +
14923 + /* check the process stack first */
14924 + stack_start = (unsigned long)task_stack_page(current);
14925 + stack_end = stack_start + THREAD_SIZE;
14926 + if (likely(stack_start <= sp && sp < stack_end)) {
14927 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14928 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14929 + return;
14930 + }
14931 +
14932 + cpu = get_cpu();
14933 +
14934 + /* check the irq stacks */
14935 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14936 + stack_start = stack_end - IRQ_STACK_SIZE;
14937 + if (stack_start <= sp && sp < stack_end) {
14938 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14939 + put_cpu();
14940 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14941 + return;
14942 + }
14943 +
14944 + /* check the exception stacks */
14945 + used = 0;
14946 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14947 + stack_start = stack_end - EXCEPTION_STKSZ;
14948 + if (stack_end && stack_start <= sp && sp < stack_end) {
14949 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14950 + put_cpu();
14951 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14952 + return;
14953 + }
14954 +
14955 + put_cpu();
14956 +
14957 + /* unknown stack */
14958 + BUG();
14959 +}
14960 +EXPORT_SYMBOL(pax_check_alloca);
14961 +#endif
14962 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14963 index 9b9f18b..9fcaa04 100644
14964 --- a/arch/x86/kernel/early_printk.c
14965 +++ b/arch/x86/kernel/early_printk.c
14966 @@ -7,6 +7,7 @@
14967 #include <linux/pci_regs.h>
14968 #include <linux/pci_ids.h>
14969 #include <linux/errno.h>
14970 +#include <linux/sched.h>
14971 #include <asm/io.h>
14972 #include <asm/processor.h>
14973 #include <asm/fcntl.h>
14974 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14975 index 623f288..8bdd78a 100644
14976 --- a/arch/x86/kernel/entry_32.S
14977 +++ b/arch/x86/kernel/entry_32.S
14978 @@ -176,13 +176,153 @@
14979 /*CFI_REL_OFFSET gs, PT_GS*/
14980 .endm
14981 .macro SET_KERNEL_GS reg
14982 +
14983 +#ifdef CONFIG_CC_STACKPROTECTOR
14984 movl $(__KERNEL_STACK_CANARY), \reg
14985 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14986 + movl $(__USER_DS), \reg
14987 +#else
14988 + xorl \reg, \reg
14989 +#endif
14990 +
14991 movl \reg, %gs
14992 .endm
14993
14994 #endif /* CONFIG_X86_32_LAZY_GS */
14995
14996 -.macro SAVE_ALL
14997 +.macro pax_enter_kernel
14998 +#ifdef CONFIG_PAX_KERNEXEC
14999 + call pax_enter_kernel
15000 +#endif
15001 +.endm
15002 +
15003 +.macro pax_exit_kernel
15004 +#ifdef CONFIG_PAX_KERNEXEC
15005 + call pax_exit_kernel
15006 +#endif
15007 +.endm
15008 +
15009 +#ifdef CONFIG_PAX_KERNEXEC
15010 +ENTRY(pax_enter_kernel)
15011 +#ifdef CONFIG_PARAVIRT
15012 + pushl %eax
15013 + pushl %ecx
15014 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15015 + mov %eax, %esi
15016 +#else
15017 + mov %cr0, %esi
15018 +#endif
15019 + bts $16, %esi
15020 + jnc 1f
15021 + mov %cs, %esi
15022 + cmp $__KERNEL_CS, %esi
15023 + jz 3f
15024 + ljmp $__KERNEL_CS, $3f
15025 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15026 +2:
15027 +#ifdef CONFIG_PARAVIRT
15028 + mov %esi, %eax
15029 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15030 +#else
15031 + mov %esi, %cr0
15032 +#endif
15033 +3:
15034 +#ifdef CONFIG_PARAVIRT
15035 + popl %ecx
15036 + popl %eax
15037 +#endif
15038 + ret
15039 +ENDPROC(pax_enter_kernel)
15040 +
15041 +ENTRY(pax_exit_kernel)
15042 +#ifdef CONFIG_PARAVIRT
15043 + pushl %eax
15044 + pushl %ecx
15045 +#endif
15046 + mov %cs, %esi
15047 + cmp $__KERNEXEC_KERNEL_CS, %esi
15048 + jnz 2f
15049 +#ifdef CONFIG_PARAVIRT
15050 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15051 + mov %eax, %esi
15052 +#else
15053 + mov %cr0, %esi
15054 +#endif
15055 + btr $16, %esi
15056 + ljmp $__KERNEL_CS, $1f
15057 +1:
15058 +#ifdef CONFIG_PARAVIRT
15059 + mov %esi, %eax
15060 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15061 +#else
15062 + mov %esi, %cr0
15063 +#endif
15064 +2:
15065 +#ifdef CONFIG_PARAVIRT
15066 + popl %ecx
15067 + popl %eax
15068 +#endif
15069 + ret
15070 +ENDPROC(pax_exit_kernel)
15071 +#endif
15072 +
15073 +.macro pax_erase_kstack
15074 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15075 + call pax_erase_kstack
15076 +#endif
15077 +.endm
15078 +
15079 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15080 +/*
15081 + * ebp: thread_info
15082 + */
15083 +ENTRY(pax_erase_kstack)
15084 + pushl %edi
15085 + pushl %ecx
15086 + pushl %eax
15087 +
15088 + mov TI_lowest_stack(%ebp), %edi
15089 + mov $-0xBEEF, %eax
15090 + std
15091 +
15092 +1: mov %edi, %ecx
15093 + and $THREAD_SIZE_asm - 1, %ecx
15094 + shr $2, %ecx
15095 + repne scasl
15096 + jecxz 2f
15097 +
15098 + cmp $2*16, %ecx
15099 + jc 2f
15100 +
15101 + mov $2*16, %ecx
15102 + repe scasl
15103 + jecxz 2f
15104 + jne 1b
15105 +
15106 +2: cld
15107 + mov %esp, %ecx
15108 + sub %edi, %ecx
15109 +
15110 + cmp $THREAD_SIZE_asm, %ecx
15111 + jb 3f
15112 + ud2
15113 +3:
15114 +
15115 + shr $2, %ecx
15116 + rep stosl
15117 +
15118 + mov TI_task_thread_sp0(%ebp), %edi
15119 + sub $128, %edi
15120 + mov %edi, TI_lowest_stack(%ebp)
15121 +
15122 + popl %eax
15123 + popl %ecx
15124 + popl %edi
15125 + ret
15126 +ENDPROC(pax_erase_kstack)
15127 +#endif
15128 +
15129 +.macro __SAVE_ALL _DS
15130 cld
15131 PUSH_GS
15132 pushl_cfi %fs
15133 @@ -205,7 +345,7 @@
15134 CFI_REL_OFFSET ecx, 0
15135 pushl_cfi %ebx
15136 CFI_REL_OFFSET ebx, 0
15137 - movl $(__USER_DS), %edx
15138 + movl $\_DS, %edx
15139 movl %edx, %ds
15140 movl %edx, %es
15141 movl $(__KERNEL_PERCPU), %edx
15142 @@ -213,6 +353,15 @@
15143 SET_KERNEL_GS %edx
15144 .endm
15145
15146 +.macro SAVE_ALL
15147 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15148 + __SAVE_ALL __KERNEL_DS
15149 + pax_enter_kernel
15150 +#else
15151 + __SAVE_ALL __USER_DS
15152 +#endif
15153 +.endm
15154 +
15155 .macro RESTORE_INT_REGS
15156 popl_cfi %ebx
15157 CFI_RESTORE ebx
15158 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15159 popfl_cfi
15160 jmp syscall_exit
15161 CFI_ENDPROC
15162 -END(ret_from_fork)
15163 +ENDPROC(ret_from_fork)
15164
15165 /*
15166 * Interrupt exit functions should be protected against kprobes
15167 @@ -329,7 +478,15 @@ ret_from_intr:
15168 andl $SEGMENT_RPL_MASK, %eax
15169 #endif
15170 cmpl $USER_RPL, %eax
15171 +
15172 +#ifdef CONFIG_PAX_KERNEXEC
15173 + jae resume_userspace
15174 +
15175 + pax_exit_kernel
15176 + jmp resume_kernel
15177 +#else
15178 jb resume_kernel # not returning to v8086 or userspace
15179 +#endif
15180
15181 ENTRY(resume_userspace)
15182 LOCKDEP_SYS_EXIT
15183 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15184 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15185 # int/exception return?
15186 jne work_pending
15187 - jmp restore_all
15188 -END(ret_from_exception)
15189 + jmp restore_all_pax
15190 +ENDPROC(ret_from_exception)
15191
15192 #ifdef CONFIG_PREEMPT
15193 ENTRY(resume_kernel)
15194 @@ -357,7 +514,7 @@ need_resched:
15195 jz restore_all
15196 call preempt_schedule_irq
15197 jmp need_resched
15198 -END(resume_kernel)
15199 +ENDPROC(resume_kernel)
15200 #endif
15201 CFI_ENDPROC
15202 /*
15203 @@ -391,28 +548,43 @@ sysenter_past_esp:
15204 /*CFI_REL_OFFSET cs, 0*/
15205 /*
15206 * Push current_thread_info()->sysenter_return to the stack.
15207 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15208 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15209 */
15210 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15211 + pushl_cfi $0
15212 CFI_REL_OFFSET eip, 0
15213
15214 pushl_cfi %eax
15215 SAVE_ALL
15216 + GET_THREAD_INFO(%ebp)
15217 + movl TI_sysenter_return(%ebp),%ebp
15218 + movl %ebp,PT_EIP(%esp)
15219 ENABLE_INTERRUPTS(CLBR_NONE)
15220
15221 /*
15222 * Load the potential sixth argument from user stack.
15223 * Careful about security.
15224 */
15225 + movl PT_OLDESP(%esp),%ebp
15226 +
15227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15228 + mov PT_OLDSS(%esp),%ds
15229 +1: movl %ds:(%ebp),%ebp
15230 + push %ss
15231 + pop %ds
15232 +#else
15233 cmpl $__PAGE_OFFSET-3,%ebp
15234 jae syscall_fault
15235 1: movl (%ebp),%ebp
15236 +#endif
15237 +
15238 movl %ebp,PT_EBP(%esp)
15239 _ASM_EXTABLE(1b,syscall_fault)
15240
15241 GET_THREAD_INFO(%ebp)
15242
15243 +#ifdef CONFIG_PAX_RANDKSTACK
15244 + pax_erase_kstack
15245 +#endif
15246 +
15247 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15248 jnz sysenter_audit
15249 sysenter_do_call:
15250 @@ -427,12 +599,24 @@ sysenter_do_call:
15251 testl $_TIF_ALLWORK_MASK, %ecx
15252 jne sysexit_audit
15253 sysenter_exit:
15254 +
15255 +#ifdef CONFIG_PAX_RANDKSTACK
15256 + pushl_cfi %eax
15257 + movl %esp, %eax
15258 + call pax_randomize_kstack
15259 + popl_cfi %eax
15260 +#endif
15261 +
15262 + pax_erase_kstack
15263 +
15264 /* if something modifies registers it must also disable sysexit */
15265 movl PT_EIP(%esp), %edx
15266 movl PT_OLDESP(%esp), %ecx
15267 xorl %ebp,%ebp
15268 TRACE_IRQS_ON
15269 1: mov PT_FS(%esp), %fs
15270 +2: mov PT_DS(%esp), %ds
15271 +3: mov PT_ES(%esp), %es
15272 PTGS_TO_GS
15273 ENABLE_INTERRUPTS_SYSEXIT
15274
15275 @@ -449,6 +633,9 @@ sysenter_audit:
15276 movl %eax,%edx /* 2nd arg: syscall number */
15277 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15278 call __audit_syscall_entry
15279 +
15280 + pax_erase_kstack
15281 +
15282 pushl_cfi %ebx
15283 movl PT_EAX(%esp),%eax /* reload syscall number */
15284 jmp sysenter_do_call
15285 @@ -474,10 +661,16 @@ sysexit_audit:
15286
15287 CFI_ENDPROC
15288 .pushsection .fixup,"ax"
15289 -2: movl $0,PT_FS(%esp)
15290 +4: movl $0,PT_FS(%esp)
15291 + jmp 1b
15292 +5: movl $0,PT_DS(%esp)
15293 + jmp 1b
15294 +6: movl $0,PT_ES(%esp)
15295 jmp 1b
15296 .popsection
15297 - _ASM_EXTABLE(1b,2b)
15298 + _ASM_EXTABLE(1b,4b)
15299 + _ASM_EXTABLE(2b,5b)
15300 + _ASM_EXTABLE(3b,6b)
15301 PTGS_TO_GS_EX
15302 ENDPROC(ia32_sysenter_target)
15303
15304 @@ -491,6 +684,11 @@ ENTRY(system_call)
15305 pushl_cfi %eax # save orig_eax
15306 SAVE_ALL
15307 GET_THREAD_INFO(%ebp)
15308 +
15309 +#ifdef CONFIG_PAX_RANDKSTACK
15310 + pax_erase_kstack
15311 +#endif
15312 +
15313 # system call tracing in operation / emulation
15314 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15315 jnz syscall_trace_entry
15316 @@ -509,6 +707,15 @@ syscall_exit:
15317 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15318 jne syscall_exit_work
15319
15320 +restore_all_pax:
15321 +
15322 +#ifdef CONFIG_PAX_RANDKSTACK
15323 + movl %esp, %eax
15324 + call pax_randomize_kstack
15325 +#endif
15326 +
15327 + pax_erase_kstack
15328 +
15329 restore_all:
15330 TRACE_IRQS_IRET
15331 restore_all_notrace:
15332 @@ -565,14 +772,34 @@ ldt_ss:
15333 * compensating for the offset by changing to the ESPFIX segment with
15334 * a base address that matches for the difference.
15335 */
15336 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15337 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15338 mov %esp, %edx /* load kernel esp */
15339 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15340 mov %dx, %ax /* eax: new kernel esp */
15341 sub %eax, %edx /* offset (low word is 0) */
15342 +#ifdef CONFIG_SMP
15343 + movl PER_CPU_VAR(cpu_number), %ebx
15344 + shll $PAGE_SHIFT_asm, %ebx
15345 + addl $cpu_gdt_table, %ebx
15346 +#else
15347 + movl $cpu_gdt_table, %ebx
15348 +#endif
15349 shr $16, %edx
15350 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15351 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15352 +
15353 +#ifdef CONFIG_PAX_KERNEXEC
15354 + mov %cr0, %esi
15355 + btr $16, %esi
15356 + mov %esi, %cr0
15357 +#endif
15358 +
15359 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15360 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15361 +
15362 +#ifdef CONFIG_PAX_KERNEXEC
15363 + bts $16, %esi
15364 + mov %esi, %cr0
15365 +#endif
15366 +
15367 pushl_cfi $__ESPFIX_SS
15368 pushl_cfi %eax /* new kernel esp */
15369 /* Disable interrupts, but do not irqtrace this section: we
15370 @@ -601,35 +828,23 @@ work_resched:
15371 movl TI_flags(%ebp), %ecx
15372 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15373 # than syscall tracing?
15374 - jz restore_all
15375 + jz restore_all_pax
15376 testb $_TIF_NEED_RESCHED, %cl
15377 jnz work_resched
15378
15379 work_notifysig: # deal with pending signals and
15380 # notify-resume requests
15381 + movl %esp, %eax
15382 #ifdef CONFIG_VM86
15383 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15384 - movl %esp, %eax
15385 - jne work_notifysig_v86 # returning to kernel-space or
15386 + jz 1f # returning to kernel-space or
15387 # vm86-space
15388 - TRACE_IRQS_ON
15389 - ENABLE_INTERRUPTS(CLBR_NONE)
15390 - movb PT_CS(%esp), %bl
15391 - andb $SEGMENT_RPL_MASK, %bl
15392 - cmpb $USER_RPL, %bl
15393 - jb resume_kernel
15394 - xorl %edx, %edx
15395 - call do_notify_resume
15396 - jmp resume_userspace
15397
15398 - ALIGN
15399 -work_notifysig_v86:
15400 pushl_cfi %ecx # save ti_flags for do_notify_resume
15401 call save_v86_state # %eax contains pt_regs pointer
15402 popl_cfi %ecx
15403 movl %eax, %esp
15404 -#else
15405 - movl %esp, %eax
15406 +1:
15407 #endif
15408 TRACE_IRQS_ON
15409 ENABLE_INTERRUPTS(CLBR_NONE)
15410 @@ -640,7 +855,7 @@ work_notifysig_v86:
15411 xorl %edx, %edx
15412 call do_notify_resume
15413 jmp resume_userspace
15414 -END(work_pending)
15415 +ENDPROC(work_pending)
15416
15417 # perform syscall exit tracing
15418 ALIGN
15419 @@ -648,11 +863,14 @@ syscall_trace_entry:
15420 movl $-ENOSYS,PT_EAX(%esp)
15421 movl %esp, %eax
15422 call syscall_trace_enter
15423 +
15424 + pax_erase_kstack
15425 +
15426 /* What it returned is what we'll actually use. */
15427 cmpl $(NR_syscalls), %eax
15428 jnae syscall_call
15429 jmp syscall_exit
15430 -END(syscall_trace_entry)
15431 +ENDPROC(syscall_trace_entry)
15432
15433 # perform syscall exit tracing
15434 ALIGN
15435 @@ -665,20 +883,24 @@ syscall_exit_work:
15436 movl %esp, %eax
15437 call syscall_trace_leave
15438 jmp resume_userspace
15439 -END(syscall_exit_work)
15440 +ENDPROC(syscall_exit_work)
15441 CFI_ENDPROC
15442
15443 RING0_INT_FRAME # can't unwind into user space anyway
15444 syscall_fault:
15445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15446 + push %ss
15447 + pop %ds
15448 +#endif
15449 GET_THREAD_INFO(%ebp)
15450 movl $-EFAULT,PT_EAX(%esp)
15451 jmp resume_userspace
15452 -END(syscall_fault)
15453 +ENDPROC(syscall_fault)
15454
15455 syscall_badsys:
15456 movl $-ENOSYS,PT_EAX(%esp)
15457 jmp resume_userspace
15458 -END(syscall_badsys)
15459 +ENDPROC(syscall_badsys)
15460 CFI_ENDPROC
15461 /*
15462 * End of kprobes section
15463 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15464 CFI_ENDPROC
15465 ENDPROC(ptregs_clone)
15466
15467 + ALIGN;
15468 +ENTRY(kernel_execve)
15469 + CFI_STARTPROC
15470 + pushl_cfi %ebp
15471 + sub $PT_OLDSS+4,%esp
15472 + pushl_cfi %edi
15473 + pushl_cfi %ecx
15474 + pushl_cfi %eax
15475 + lea 3*4(%esp),%edi
15476 + mov $PT_OLDSS/4+1,%ecx
15477 + xorl %eax,%eax
15478 + rep stosl
15479 + popl_cfi %eax
15480 + popl_cfi %ecx
15481 + popl_cfi %edi
15482 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15483 + pushl_cfi %esp
15484 + call sys_execve
15485 + add $4,%esp
15486 + CFI_ADJUST_CFA_OFFSET -4
15487 + GET_THREAD_INFO(%ebp)
15488 + test %eax,%eax
15489 + jz syscall_exit
15490 + add $PT_OLDSS+4,%esp
15491 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15492 + popl_cfi %ebp
15493 + ret
15494 + CFI_ENDPROC
15495 +ENDPROC(kernel_execve)
15496 +
15497 .macro FIXUP_ESPFIX_STACK
15498 /*
15499 * Switch back for ESPFIX stack to the normal zerobased stack
15500 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15501 * normal stack and adjusts ESP with the matching offset.
15502 */
15503 /* fixup the stack */
15504 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15505 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15506 +#ifdef CONFIG_SMP
15507 + movl PER_CPU_VAR(cpu_number), %ebx
15508 + shll $PAGE_SHIFT_asm, %ebx
15509 + addl $cpu_gdt_table, %ebx
15510 +#else
15511 + movl $cpu_gdt_table, %ebx
15512 +#endif
15513 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15514 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15515 shl $16, %eax
15516 addl %esp, %eax /* the adjusted stack pointer */
15517 pushl_cfi $__KERNEL_DS
15518 @@ -813,7 +1072,7 @@ vector=vector+1
15519 .endr
15520 2: jmp common_interrupt
15521 .endr
15522 -END(irq_entries_start)
15523 +ENDPROC(irq_entries_start)
15524
15525 .previous
15526 END(interrupt)
15527 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15528 pushl_cfi $do_coprocessor_error
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(coprocessor_error)
15532 +ENDPROC(coprocessor_error)
15533
15534 ENTRY(simd_coprocessor_error)
15535 RING0_INT_FRAME
15536 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15537 #endif
15538 jmp error_code
15539 CFI_ENDPROC
15540 -END(simd_coprocessor_error)
15541 +ENDPROC(simd_coprocessor_error)
15542
15543 ENTRY(device_not_available)
15544 RING0_INT_FRAME
15545 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15546 pushl_cfi $do_device_not_available
15547 jmp error_code
15548 CFI_ENDPROC
15549 -END(device_not_available)
15550 +ENDPROC(device_not_available)
15551
15552 #ifdef CONFIG_PARAVIRT
15553 ENTRY(native_iret)
15554 iret
15555 _ASM_EXTABLE(native_iret, iret_exc)
15556 -END(native_iret)
15557 +ENDPROC(native_iret)
15558
15559 ENTRY(native_irq_enable_sysexit)
15560 sti
15561 sysexit
15562 -END(native_irq_enable_sysexit)
15563 +ENDPROC(native_irq_enable_sysexit)
15564 #endif
15565
15566 ENTRY(overflow)
15567 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15568 pushl_cfi $do_overflow
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(overflow)
15572 +ENDPROC(overflow)
15573
15574 ENTRY(bounds)
15575 RING0_INT_FRAME
15576 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15577 pushl_cfi $do_bounds
15578 jmp error_code
15579 CFI_ENDPROC
15580 -END(bounds)
15581 +ENDPROC(bounds)
15582
15583 ENTRY(invalid_op)
15584 RING0_INT_FRAME
15585 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15586 pushl_cfi $do_invalid_op
15587 jmp error_code
15588 CFI_ENDPROC
15589 -END(invalid_op)
15590 +ENDPROC(invalid_op)
15591
15592 ENTRY(coprocessor_segment_overrun)
15593 RING0_INT_FRAME
15594 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15595 pushl_cfi $do_coprocessor_segment_overrun
15596 jmp error_code
15597 CFI_ENDPROC
15598 -END(coprocessor_segment_overrun)
15599 +ENDPROC(coprocessor_segment_overrun)
15600
15601 ENTRY(invalid_TSS)
15602 RING0_EC_FRAME
15603 pushl_cfi $do_invalid_TSS
15604 jmp error_code
15605 CFI_ENDPROC
15606 -END(invalid_TSS)
15607 +ENDPROC(invalid_TSS)
15608
15609 ENTRY(segment_not_present)
15610 RING0_EC_FRAME
15611 pushl_cfi $do_segment_not_present
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(segment_not_present)
15615 +ENDPROC(segment_not_present)
15616
15617 ENTRY(stack_segment)
15618 RING0_EC_FRAME
15619 pushl_cfi $do_stack_segment
15620 jmp error_code
15621 CFI_ENDPROC
15622 -END(stack_segment)
15623 +ENDPROC(stack_segment)
15624
15625 ENTRY(alignment_check)
15626 RING0_EC_FRAME
15627 pushl_cfi $do_alignment_check
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(alignment_check)
15631 +ENDPROC(alignment_check)
15632
15633 ENTRY(divide_error)
15634 RING0_INT_FRAME
15635 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15636 pushl_cfi $do_divide_error
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(divide_error)
15640 +ENDPROC(divide_error)
15641
15642 #ifdef CONFIG_X86_MCE
15643 ENTRY(machine_check)
15644 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15645 pushl_cfi machine_check_vector
15646 jmp error_code
15647 CFI_ENDPROC
15648 -END(machine_check)
15649 +ENDPROC(machine_check)
15650 #endif
15651
15652 ENTRY(spurious_interrupt_bug)
15653 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15654 pushl_cfi $do_spurious_interrupt_bug
15655 jmp error_code
15656 CFI_ENDPROC
15657 -END(spurious_interrupt_bug)
15658 +ENDPROC(spurious_interrupt_bug)
15659 /*
15660 * End of kprobes section
15661 */
15662 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15663
15664 ENTRY(mcount)
15665 ret
15666 -END(mcount)
15667 +ENDPROC(mcount)
15668
15669 ENTRY(ftrace_caller)
15670 cmpl $0, function_trace_stop
15671 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15672 .globl ftrace_stub
15673 ftrace_stub:
15674 ret
15675 -END(ftrace_caller)
15676 +ENDPROC(ftrace_caller)
15677
15678 #else /* ! CONFIG_DYNAMIC_FTRACE */
15679
15680 @@ -1165,7 +1424,7 @@ trace:
15681 popl %ecx
15682 popl %eax
15683 jmp ftrace_stub
15684 -END(mcount)
15685 +ENDPROC(mcount)
15686 #endif /* CONFIG_DYNAMIC_FTRACE */
15687 #endif /* CONFIG_FUNCTION_TRACER */
15688
15689 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15690 popl %ecx
15691 popl %eax
15692 ret
15693 -END(ftrace_graph_caller)
15694 +ENDPROC(ftrace_graph_caller)
15695
15696 .globl return_to_handler
15697 return_to_handler:
15698 @@ -1241,15 +1500,18 @@ error_code:
15699 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15700 REG_TO_PTGS %ecx
15701 SET_KERNEL_GS %ecx
15702 - movl $(__USER_DS), %ecx
15703 + movl $(__KERNEL_DS), %ecx
15704 movl %ecx, %ds
15705 movl %ecx, %es
15706 +
15707 + pax_enter_kernel
15708 +
15709 TRACE_IRQS_OFF
15710 movl %esp,%eax # pt_regs pointer
15711 call *%edi
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714 -END(page_fault)
15715 +ENDPROC(page_fault)
15716
15717 /*
15718 * Debug traps and NMI can happen at the one SYSENTER instruction
15719 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15720 call do_debug
15721 jmp ret_from_exception
15722 CFI_ENDPROC
15723 -END(debug)
15724 +ENDPROC(debug)
15725
15726 /*
15727 * NMI is doubly nasty. It can happen _while_ we're handling
15728 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15729 xorl %edx,%edx # zero error code
15730 movl %esp,%eax # pt_regs pointer
15731 call do_nmi
15732 +
15733 + pax_exit_kernel
15734 +
15735 jmp restore_all_notrace
15736 CFI_ENDPROC
15737
15738 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15739 FIXUP_ESPFIX_STACK # %eax == %esp
15740 xorl %edx,%edx # zero error code
15741 call do_nmi
15742 +
15743 + pax_exit_kernel
15744 +
15745 RESTORE_REGS
15746 lss 12+4(%esp), %esp # back to espfix stack
15747 CFI_ADJUST_CFA_OFFSET -24
15748 jmp irq_return
15749 CFI_ENDPROC
15750 -END(nmi)
15751 +ENDPROC(nmi)
15752
15753 ENTRY(int3)
15754 RING0_INT_FRAME
15755 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15756 call do_int3
15757 jmp ret_from_exception
15758 CFI_ENDPROC
15759 -END(int3)
15760 +ENDPROC(int3)
15761
15762 ENTRY(general_protection)
15763 RING0_EC_FRAME
15764 pushl_cfi $do_general_protection
15765 jmp error_code
15766 CFI_ENDPROC
15767 -END(general_protection)
15768 +ENDPROC(general_protection)
15769
15770 #ifdef CONFIG_KVM_GUEST
15771 ENTRY(async_page_fault)
15772 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15773 pushl_cfi $do_async_page_fault
15774 jmp error_code
15775 CFI_ENDPROC
15776 -END(async_page_fault)
15777 +ENDPROC(async_page_fault)
15778 #endif
15779
15780 /*
15781 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15782 index 69babd8..4270a51 100644
15783 --- a/arch/x86/kernel/entry_64.S
15784 +++ b/arch/x86/kernel/entry_64.S
15785 @@ -57,6 +57,8 @@
15786 #include <asm/percpu.h>
15787 #include <asm/asm.h>
15788 #include <linux/err.h>
15789 +#include <asm/pgtable.h>
15790 +#include <asm/alternative-asm.h>
15791
15792 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15793 #include <linux/elf-em.h>
15794 @@ -70,8 +72,9 @@
15795 #ifdef CONFIG_FUNCTION_TRACER
15796 #ifdef CONFIG_DYNAMIC_FTRACE
15797 ENTRY(mcount)
15798 + pax_force_retaddr
15799 retq
15800 -END(mcount)
15801 +ENDPROC(mcount)
15802
15803 ENTRY(ftrace_caller)
15804 cmpl $0, function_trace_stop
15805 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15806 #endif
15807
15808 GLOBAL(ftrace_stub)
15809 + pax_force_retaddr
15810 retq
15811 -END(ftrace_caller)
15812 +ENDPROC(ftrace_caller)
15813
15814 #else /* ! CONFIG_DYNAMIC_FTRACE */
15815 ENTRY(mcount)
15816 @@ -114,6 +118,7 @@ ENTRY(mcount)
15817 #endif
15818
15819 GLOBAL(ftrace_stub)
15820 + pax_force_retaddr
15821 retq
15822
15823 trace:
15824 @@ -123,12 +128,13 @@ trace:
15825 movq 8(%rbp), %rsi
15826 subq $MCOUNT_INSN_SIZE, %rdi
15827
15828 + pax_force_fptr ftrace_trace_function
15829 call *ftrace_trace_function
15830
15831 MCOUNT_RESTORE_FRAME
15832
15833 jmp ftrace_stub
15834 -END(mcount)
15835 +ENDPROC(mcount)
15836 #endif /* CONFIG_DYNAMIC_FTRACE */
15837 #endif /* CONFIG_FUNCTION_TRACER */
15838
15839 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15840
15841 MCOUNT_RESTORE_FRAME
15842
15843 + pax_force_retaddr
15844 retq
15845 -END(ftrace_graph_caller)
15846 +ENDPROC(ftrace_graph_caller)
15847
15848 GLOBAL(return_to_handler)
15849 subq $24, %rsp
15850 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15851 movq 8(%rsp), %rdx
15852 movq (%rsp), %rax
15853 addq $24, %rsp
15854 + pax_force_fptr %rdi
15855 jmp *%rdi
15856 #endif
15857
15858 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15859 ENDPROC(native_usergs_sysret64)
15860 #endif /* CONFIG_PARAVIRT */
15861
15862 + .macro ljmpq sel, off
15863 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15864 + .byte 0x48; ljmp *1234f(%rip)
15865 + .pushsection .rodata
15866 + .align 16
15867 + 1234: .quad \off; .word \sel
15868 + .popsection
15869 +#else
15870 + pushq $\sel
15871 + pushq $\off
15872 + lretq
15873 +#endif
15874 + .endm
15875 +
15876 + .macro pax_enter_kernel
15877 + pax_set_fptr_mask
15878 +#ifdef CONFIG_PAX_KERNEXEC
15879 + call pax_enter_kernel
15880 +#endif
15881 + .endm
15882 +
15883 + .macro pax_exit_kernel
15884 +#ifdef CONFIG_PAX_KERNEXEC
15885 + call pax_exit_kernel
15886 +#endif
15887 + .endm
15888 +
15889 +#ifdef CONFIG_PAX_KERNEXEC
15890 +ENTRY(pax_enter_kernel)
15891 + pushq %rdi
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 + PV_SAVE_REGS(CLBR_RDI)
15895 +#endif
15896 +
15897 + GET_CR0_INTO_RDI
15898 + bts $16,%rdi
15899 + jnc 3f
15900 + mov %cs,%edi
15901 + cmp $__KERNEL_CS,%edi
15902 + jnz 2f
15903 +1:
15904 +
15905 +#ifdef CONFIG_PARAVIRT
15906 + PV_RESTORE_REGS(CLBR_RDI)
15907 +#endif
15908 +
15909 + popq %rdi
15910 + pax_force_retaddr
15911 + retq
15912 +
15913 +2: ljmpq __KERNEL_CS,1f
15914 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15915 +4: SET_RDI_INTO_CR0
15916 + jmp 1b
15917 +ENDPROC(pax_enter_kernel)
15918 +
15919 +ENTRY(pax_exit_kernel)
15920 + pushq %rdi
15921 +
15922 +#ifdef CONFIG_PARAVIRT
15923 + PV_SAVE_REGS(CLBR_RDI)
15924 +#endif
15925 +
15926 + mov %cs,%rdi
15927 + cmp $__KERNEXEC_KERNEL_CS,%edi
15928 + jz 2f
15929 +1:
15930 +
15931 +#ifdef CONFIG_PARAVIRT
15932 + PV_RESTORE_REGS(CLBR_RDI);
15933 +#endif
15934 +
15935 + popq %rdi
15936 + pax_force_retaddr
15937 + retq
15938 +
15939 +2: GET_CR0_INTO_RDI
15940 + btr $16,%rdi
15941 + ljmpq __KERNEL_CS,3f
15942 +3: SET_RDI_INTO_CR0
15943 + jmp 1b
15944 +#ifdef CONFIG_PARAVIRT
15945 + PV_RESTORE_REGS(CLBR_RDI);
15946 +#endif
15947 +
15948 + popq %rdi
15949 + pax_force_retaddr
15950 + retq
15951 +ENDPROC(pax_exit_kernel)
15952 +#endif
15953 +
15954 + .macro pax_enter_kernel_user
15955 + pax_set_fptr_mask
15956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15957 + call pax_enter_kernel_user
15958 +#endif
15959 + .endm
15960 +
15961 + .macro pax_exit_kernel_user
15962 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15963 + call pax_exit_kernel_user
15964 +#endif
15965 +#ifdef CONFIG_PAX_RANDKSTACK
15966 + pushq %rax
15967 + call pax_randomize_kstack
15968 + popq %rax
15969 +#endif
15970 + .endm
15971 +
15972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15973 +ENTRY(pax_enter_kernel_user)
15974 + pushq %rdi
15975 + pushq %rbx
15976 +
15977 +#ifdef CONFIG_PARAVIRT
15978 + PV_SAVE_REGS(CLBR_RDI)
15979 +#endif
15980 +
15981 + GET_CR3_INTO_RDI
15982 + mov %rdi,%rbx
15983 + add $__START_KERNEL_map,%rbx
15984 + sub phys_base(%rip),%rbx
15985 +
15986 +#ifdef CONFIG_PARAVIRT
15987 + pushq %rdi
15988 + cmpl $0, pv_info+PARAVIRT_enabled
15989 + jz 1f
15990 + i = 0
15991 + .rept USER_PGD_PTRS
15992 + mov i*8(%rbx),%rsi
15993 + mov $0,%sil
15994 + lea i*8(%rbx),%rdi
15995 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15996 + i = i + 1
15997 + .endr
15998 + jmp 2f
15999 +1:
16000 +#endif
16001 +
16002 + i = 0
16003 + .rept USER_PGD_PTRS
16004 + movb $0,i*8(%rbx)
16005 + i = i + 1
16006 + .endr
16007 +
16008 +#ifdef CONFIG_PARAVIRT
16009 +2: popq %rdi
16010 +#endif
16011 + SET_RDI_INTO_CR3
16012 +
16013 +#ifdef CONFIG_PAX_KERNEXEC
16014 + GET_CR0_INTO_RDI
16015 + bts $16,%rdi
16016 + SET_RDI_INTO_CR0
16017 +#endif
16018 +
16019 +#ifdef CONFIG_PARAVIRT
16020 + PV_RESTORE_REGS(CLBR_RDI)
16021 +#endif
16022 +
16023 + popq %rbx
16024 + popq %rdi
16025 + pax_force_retaddr
16026 + retq
16027 +ENDPROC(pax_enter_kernel_user)
16028 +
16029 +ENTRY(pax_exit_kernel_user)
16030 + push %rdi
16031 +
16032 +#ifdef CONFIG_PARAVIRT
16033 + pushq %rbx
16034 + PV_SAVE_REGS(CLBR_RDI)
16035 +#endif
16036 +
16037 +#ifdef CONFIG_PAX_KERNEXEC
16038 + GET_CR0_INTO_RDI
16039 + btr $16,%rdi
16040 + SET_RDI_INTO_CR0
16041 +#endif
16042 +
16043 + GET_CR3_INTO_RDI
16044 + add $__START_KERNEL_map,%rdi
16045 + sub phys_base(%rip),%rdi
16046 +
16047 +#ifdef CONFIG_PARAVIRT
16048 + cmpl $0, pv_info+PARAVIRT_enabled
16049 + jz 1f
16050 + mov %rdi,%rbx
16051 + i = 0
16052 + .rept USER_PGD_PTRS
16053 + mov i*8(%rbx),%rsi
16054 + mov $0x67,%sil
16055 + lea i*8(%rbx),%rdi
16056 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16057 + i = i + 1
16058 + .endr
16059 + jmp 2f
16060 +1:
16061 +#endif
16062 +
16063 + i = 0
16064 + .rept USER_PGD_PTRS
16065 + movb $0x67,i*8(%rdi)
16066 + i = i + 1
16067 + .endr
16068 +
16069 +#ifdef CONFIG_PARAVIRT
16070 +2: PV_RESTORE_REGS(CLBR_RDI)
16071 + popq %rbx
16072 +#endif
16073 +
16074 + popq %rdi
16075 + pax_force_retaddr
16076 + retq
16077 +ENDPROC(pax_exit_kernel_user)
16078 +#endif
16079 +
16080 +.macro pax_erase_kstack
16081 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16082 + call pax_erase_kstack
16083 +#endif
16084 +.endm
16085 +
16086 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16087 +ENTRY(pax_erase_kstack)
16088 + pushq %rdi
16089 + pushq %rcx
16090 + pushq %rax
16091 + pushq %r11
16092 +
16093 + GET_THREAD_INFO(%r11)
16094 + mov TI_lowest_stack(%r11), %rdi
16095 + mov $-0xBEEF, %rax
16096 + std
16097 +
16098 +1: mov %edi, %ecx
16099 + and $THREAD_SIZE_asm - 1, %ecx
16100 + shr $3, %ecx
16101 + repne scasq
16102 + jecxz 2f
16103 +
16104 + cmp $2*8, %ecx
16105 + jc 2f
16106 +
16107 + mov $2*8, %ecx
16108 + repe scasq
16109 + jecxz 2f
16110 + jne 1b
16111 +
16112 +2: cld
16113 + mov %esp, %ecx
16114 + sub %edi, %ecx
16115 +
16116 + cmp $THREAD_SIZE_asm, %rcx
16117 + jb 3f
16118 + ud2
16119 +3:
16120 +
16121 + shr $3, %ecx
16122 + rep stosq
16123 +
16124 + mov TI_task_thread_sp0(%r11), %rdi
16125 + sub $256, %rdi
16126 + mov %rdi, TI_lowest_stack(%r11)
16127 +
16128 + popq %r11
16129 + popq %rax
16130 + popq %rcx
16131 + popq %rdi
16132 + pax_force_retaddr
16133 + ret
16134 +ENDPROC(pax_erase_kstack)
16135 +#endif
16136
16137 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16138 #ifdef CONFIG_TRACE_IRQFLAGS
16139 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16140 .endm
16141
16142 .macro UNFAKE_STACK_FRAME
16143 - addq $8*6, %rsp
16144 - CFI_ADJUST_CFA_OFFSET -(6*8)
16145 + addq $8*6 + ARG_SKIP, %rsp
16146 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16147 .endm
16148
16149 /*
16150 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16151 movq %rsp, %rsi
16152
16153 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16154 - testl $3, CS-RBP(%rsi)
16155 + testb $3, CS-RBP(%rsi)
16156 je 1f
16157 SWAPGS
16158 /*
16159 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16160 movq_cfi r15, R15+16
16161 movq %r11, 8(%rsp) /* return address */
16162 FIXUP_TOP_OF_STACK %r11, 16
16163 + pax_force_retaddr
16164 ret
16165 CFI_ENDPROC
16166 -END(save_rest)
16167 +ENDPROC(save_rest)
16168
16169 /* save complete stack frame */
16170 .pushsection .kprobes.text, "ax"
16171 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16172 js 1f /* negative -> in kernel */
16173 SWAPGS
16174 xorl %ebx,%ebx
16175 -1: ret
16176 +1: pax_force_retaddr_bts
16177 + ret
16178 CFI_ENDPROC
16179 -END(save_paranoid)
16180 +ENDPROC(save_paranoid)
16181 .popsection
16182
16183 /*
16184 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16185
16186 RESTORE_REST
16187
16188 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16189 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16190 jz retint_restore_args
16191
16192 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16193 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16194 jmp ret_from_sys_call # go to the SYSRET fastpath
16195
16196 CFI_ENDPROC
16197 -END(ret_from_fork)
16198 +ENDPROC(ret_from_fork)
16199
16200 /*
16201 * System call entry. Up to 6 arguments in registers are supported.
16202 @@ -495,7 +779,7 @@ END(ret_from_fork)
16203 ENTRY(system_call)
16204 CFI_STARTPROC simple
16205 CFI_SIGNAL_FRAME
16206 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16207 + CFI_DEF_CFA rsp,0
16208 CFI_REGISTER rip,rcx
16209 /*CFI_REGISTER rflags,r11*/
16210 SWAPGS_UNSAFE_STACK
16211 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16212
16213 movq %rsp,PER_CPU_VAR(old_rsp)
16214 movq PER_CPU_VAR(kernel_stack),%rsp
16215 + SAVE_ARGS 8*6,0
16216 + pax_enter_kernel_user
16217 +
16218 +#ifdef CONFIG_PAX_RANDKSTACK
16219 + pax_erase_kstack
16220 +#endif
16221 +
16222 /*
16223 * No need to follow this irqs off/on section - it's straight
16224 * and short:
16225 */
16226 ENABLE_INTERRUPTS(CLBR_NONE)
16227 - SAVE_ARGS 8,0
16228 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16229 movq %rcx,RIP-ARGOFFSET(%rsp)
16230 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16231 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16232 + GET_THREAD_INFO(%rcx)
16233 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16234 jnz tracesys
16235 system_call_fastpath:
16236 #if __SYSCALL_MASK == ~0
16237 @@ -527,7 +818,7 @@ system_call_fastpath:
16238 cmpl $__NR_syscall_max,%eax
16239 #endif
16240 ja badsys
16241 - movq %r10,%rcx
16242 + movq R10-ARGOFFSET(%rsp),%rcx
16243 call *sys_call_table(,%rax,8) # XXX: rip relative
16244 movq %rax,RAX-ARGOFFSET(%rsp)
16245 /*
16246 @@ -541,10 +832,13 @@ sysret_check:
16247 LOCKDEP_SYS_EXIT
16248 DISABLE_INTERRUPTS(CLBR_NONE)
16249 TRACE_IRQS_OFF
16250 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16251 + GET_THREAD_INFO(%rcx)
16252 + movl TI_flags(%rcx),%edx
16253 andl %edi,%edx
16254 jnz sysret_careful
16255 CFI_REMEMBER_STATE
16256 + pax_exit_kernel_user
16257 + pax_erase_kstack
16258 /*
16259 * sysretq will re-enable interrupts:
16260 */
16261 @@ -596,14 +890,18 @@ badsys:
16262 * jump back to the normal fast path.
16263 */
16264 auditsys:
16265 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16266 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16267 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16268 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16269 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16270 movq %rax,%rsi /* 2nd arg: syscall number */
16271 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16272 call __audit_syscall_entry
16273 +
16274 + pax_erase_kstack
16275 +
16276 LOAD_ARGS 0 /* reload call-clobbered registers */
16277 + pax_set_fptr_mask
16278 jmp system_call_fastpath
16279
16280 /*
16281 @@ -624,7 +922,7 @@ sysret_audit:
16282 /* Do syscall tracing */
16283 tracesys:
16284 #ifdef CONFIG_AUDITSYSCALL
16285 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16286 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16287 jz auditsys
16288 #endif
16289 SAVE_REST
16290 @@ -632,12 +930,16 @@ tracesys:
16291 FIXUP_TOP_OF_STACK %rdi
16292 movq %rsp,%rdi
16293 call syscall_trace_enter
16294 +
16295 + pax_erase_kstack
16296 +
16297 /*
16298 * Reload arg registers from stack in case ptrace changed them.
16299 * We don't reload %rax because syscall_trace_enter() returned
16300 * the value it wants us to use in the table lookup.
16301 */
16302 LOAD_ARGS ARGOFFSET, 1
16303 + pax_set_fptr_mask
16304 RESTORE_REST
16305 #if __SYSCALL_MASK == ~0
16306 cmpq $__NR_syscall_max,%rax
16307 @@ -646,7 +948,7 @@ tracesys:
16308 cmpl $__NR_syscall_max,%eax
16309 #endif
16310 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16311 - movq %r10,%rcx /* fixup for C */
16312 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16313 call *sys_call_table(,%rax,8)
16314 movq %rax,RAX-ARGOFFSET(%rsp)
16315 /* Use IRET because user could have changed frame */
16316 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16317 andl %edi,%edx
16318 jnz int_careful
16319 andl $~TS_COMPAT,TI_status(%rcx)
16320 - jmp retint_swapgs
16321 + pax_exit_kernel_user
16322 + pax_erase_kstack
16323 + jmp retint_swapgs_pax
16324
16325 /* Either reschedule or signal or syscall exit tracking needed. */
16326 /* First do a reschedule test. */
16327 @@ -713,7 +1017,7 @@ int_restore_rest:
16328 TRACE_IRQS_OFF
16329 jmp int_with_check
16330 CFI_ENDPROC
16331 -END(system_call)
16332 +ENDPROC(system_call)
16333
16334 /*
16335 * Certain special system calls that need to save a complete full stack frame.
16336 @@ -729,7 +1033,7 @@ ENTRY(\label)
16337 call \func
16338 jmp ptregscall_common
16339 CFI_ENDPROC
16340 -END(\label)
16341 +ENDPROC(\label)
16342 .endm
16343
16344 PTREGSCALL stub_clone, sys_clone, %r8
16345 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16346 movq_cfi_restore R12+8, r12
16347 movq_cfi_restore RBP+8, rbp
16348 movq_cfi_restore RBX+8, rbx
16349 + pax_force_retaddr
16350 ret $REST_SKIP /* pop extended registers */
16351 CFI_ENDPROC
16352 -END(ptregscall_common)
16353 +ENDPROC(ptregscall_common)
16354
16355 ENTRY(stub_execve)
16356 CFI_STARTPROC
16357 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361 -END(stub_execve)
16362 +ENDPROC(stub_execve)
16363
16364 /*
16365 * sigreturn is special because it needs to restore all registers on return.
16366 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16367 RESTORE_REST
16368 jmp int_ret_from_sys_call
16369 CFI_ENDPROC
16370 -END(stub_rt_sigreturn)
16371 +ENDPROC(stub_rt_sigreturn)
16372
16373 #ifdef CONFIG_X86_X32_ABI
16374 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16375 @@ -851,7 +1156,7 @@ vector=vector+1
16376 2: jmp common_interrupt
16377 .endr
16378 CFI_ENDPROC
16379 -END(irq_entries_start)
16380 +ENDPROC(irq_entries_start)
16381
16382 .previous
16383 END(interrupt)
16384 @@ -871,6 +1176,16 @@ END(interrupt)
16385 subq $ORIG_RAX-RBP, %rsp
16386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16387 SAVE_ARGS_IRQ
16388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16389 + testb $3, CS(%rdi)
16390 + jnz 1f
16391 + pax_enter_kernel
16392 + jmp 2f
16393 +1: pax_enter_kernel_user
16394 +2:
16395 +#else
16396 + pax_enter_kernel
16397 +#endif
16398 call \func
16399 .endm
16400
16401 @@ -902,7 +1217,7 @@ ret_from_intr:
16402
16403 exit_intr:
16404 GET_THREAD_INFO(%rcx)
16405 - testl $3,CS-ARGOFFSET(%rsp)
16406 + testb $3,CS-ARGOFFSET(%rsp)
16407 je retint_kernel
16408
16409 /* Interrupt came from user space */
16410 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16411 * The iretq could re-enable interrupts:
16412 */
16413 DISABLE_INTERRUPTS(CLBR_ANY)
16414 + pax_exit_kernel_user
16415 +retint_swapgs_pax:
16416 TRACE_IRQS_IRETQ
16417 SWAPGS
16418 jmp restore_args
16419
16420 retint_restore_args: /* return to kernel space */
16421 DISABLE_INTERRUPTS(CLBR_ANY)
16422 + pax_exit_kernel
16423 + pax_force_retaddr RIP-ARGOFFSET
16424 /*
16425 * The iretq could re-enable interrupts:
16426 */
16427 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16428 #endif
16429
16430 CFI_ENDPROC
16431 -END(common_interrupt)
16432 +ENDPROC(common_interrupt)
16433 /*
16434 * End of kprobes section
16435 */
16436 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16437 interrupt \do_sym
16438 jmp ret_from_intr
16439 CFI_ENDPROC
16440 -END(\sym)
16441 +ENDPROC(\sym)
16442 .endm
16443
16444 #ifdef CONFIG_SMP
16445 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16446 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16447 call error_entry
16448 DEFAULT_FRAME 0
16449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16450 + testb $3, CS(%rsp)
16451 + jnz 1f
16452 + pax_enter_kernel
16453 + jmp 2f
16454 +1: pax_enter_kernel_user
16455 +2:
16456 +#else
16457 + pax_enter_kernel
16458 +#endif
16459 movq %rsp,%rdi /* pt_regs pointer */
16460 xorl %esi,%esi /* no error code */
16461 call \do_sym
16462 jmp error_exit /* %ebx: no swapgs flag */
16463 CFI_ENDPROC
16464 -END(\sym)
16465 +ENDPROC(\sym)
16466 .endm
16467
16468 .macro paranoidzeroentry sym do_sym
16469 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16470 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16471 call save_paranoid
16472 TRACE_IRQS_OFF
16473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16474 + testb $3, CS(%rsp)
16475 + jnz 1f
16476 + pax_enter_kernel
16477 + jmp 2f
16478 +1: pax_enter_kernel_user
16479 +2:
16480 +#else
16481 + pax_enter_kernel
16482 +#endif
16483 movq %rsp,%rdi /* pt_regs pointer */
16484 xorl %esi,%esi /* no error code */
16485 call \do_sym
16486 jmp paranoid_exit /* %ebx: no swapgs flag */
16487 CFI_ENDPROC
16488 -END(\sym)
16489 +ENDPROC(\sym)
16490 .endm
16491
16492 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16493 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16494 .macro paranoidzeroentry_ist sym do_sym ist
16495 ENTRY(\sym)
16496 INTR_FRAME
16497 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16498 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16499 call save_paranoid
16500 TRACE_IRQS_OFF_DEBUG
16501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16502 + testb $3, CS(%rsp)
16503 + jnz 1f
16504 + pax_enter_kernel
16505 + jmp 2f
16506 +1: pax_enter_kernel_user
16507 +2:
16508 +#else
16509 + pax_enter_kernel
16510 +#endif
16511 movq %rsp,%rdi /* pt_regs pointer */
16512 xorl %esi,%esi /* no error code */
16513 +#ifdef CONFIG_SMP
16514 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16515 + lea init_tss(%r12), %r12
16516 +#else
16517 + lea init_tss(%rip), %r12
16518 +#endif
16519 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16520 call \do_sym
16521 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16522 jmp paranoid_exit /* %ebx: no swapgs flag */
16523 CFI_ENDPROC
16524 -END(\sym)
16525 +ENDPROC(\sym)
16526 .endm
16527
16528 .macro errorentry sym do_sym
16529 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16530 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16531 call error_entry
16532 DEFAULT_FRAME 0
16533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16534 + testb $3, CS(%rsp)
16535 + jnz 1f
16536 + pax_enter_kernel
16537 + jmp 2f
16538 +1: pax_enter_kernel_user
16539 +2:
16540 +#else
16541 + pax_enter_kernel
16542 +#endif
16543 movq %rsp,%rdi /* pt_regs pointer */
16544 movq ORIG_RAX(%rsp),%rsi /* get error code */
16545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16546 call \do_sym
16547 jmp error_exit /* %ebx: no swapgs flag */
16548 CFI_ENDPROC
16549 -END(\sym)
16550 +ENDPROC(\sym)
16551 .endm
16552
16553 /* error code is on the stack already */
16554 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16555 call save_paranoid
16556 DEFAULT_FRAME 0
16557 TRACE_IRQS_OFF
16558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16559 + testb $3, CS(%rsp)
16560 + jnz 1f
16561 + pax_enter_kernel
16562 + jmp 2f
16563 +1: pax_enter_kernel_user
16564 +2:
16565 +#else
16566 + pax_enter_kernel
16567 +#endif
16568 movq %rsp,%rdi /* pt_regs pointer */
16569 movq ORIG_RAX(%rsp),%rsi /* get error code */
16570 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16571 call \do_sym
16572 jmp paranoid_exit /* %ebx: no swapgs flag */
16573 CFI_ENDPROC
16574 -END(\sym)
16575 +ENDPROC(\sym)
16576 .endm
16577
16578 zeroentry divide_error do_divide_error
16579 @@ -1192,9 +1567,10 @@ gs_change:
16580 2: mfence /* workaround */
16581 SWAPGS
16582 popfq_cfi
16583 + pax_force_retaddr
16584 ret
16585 CFI_ENDPROC
16586 -END(native_load_gs_index)
16587 +ENDPROC(native_load_gs_index)
16588
16589 _ASM_EXTABLE(gs_change,bad_gs)
16590 .section .fixup,"ax"
16591 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16592 * Here we are in the child and the registers are set as they were
16593 * at kernel_thread() invocation in the parent.
16594 */
16595 + pax_force_fptr %rsi
16596 call *%rsi
16597 # exit
16598 mov %eax, %edi
16599 call do_exit
16600 ud2 # padding for call trace
16601 CFI_ENDPROC
16602 -END(kernel_thread_helper)
16603 +ENDPROC(kernel_thread_helper)
16604
16605 /*
16606 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16607 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16608 RESTORE_REST
16609 testq %rax,%rax
16610 je int_ret_from_sys_call
16611 - RESTORE_ARGS
16612 UNFAKE_STACK_FRAME
16613 + pax_force_retaddr
16614 ret
16615 CFI_ENDPROC
16616 -END(kernel_execve)
16617 +ENDPROC(kernel_execve)
16618
16619 /* Call softirq on interrupt stack. Interrupts are off. */
16620 ENTRY(call_softirq)
16621 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16622 CFI_DEF_CFA_REGISTER rsp
16623 CFI_ADJUST_CFA_OFFSET -8
16624 decl PER_CPU_VAR(irq_count)
16625 + pax_force_retaddr
16626 ret
16627 CFI_ENDPROC
16628 -END(call_softirq)
16629 +ENDPROC(call_softirq)
16630
16631 #ifdef CONFIG_XEN
16632 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16633 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16634 decl PER_CPU_VAR(irq_count)
16635 jmp error_exit
16636 CFI_ENDPROC
16637 -END(xen_do_hypervisor_callback)
16638 +ENDPROC(xen_do_hypervisor_callback)
16639
16640 /*
16641 * Hypervisor uses this for application faults while it executes.
16642 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16643 SAVE_ALL
16644 jmp error_exit
16645 CFI_ENDPROC
16646 -END(xen_failsafe_callback)
16647 +ENDPROC(xen_failsafe_callback)
16648
16649 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16650 xen_hvm_callback_vector xen_evtchn_do_upcall
16651 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16652 TRACE_IRQS_OFF_DEBUG
16653 testl %ebx,%ebx /* swapgs needed? */
16654 jnz paranoid_restore
16655 - testl $3,CS(%rsp)
16656 + testb $3,CS(%rsp)
16657 jnz paranoid_userspace
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel
16660 + TRACE_IRQS_IRETQ 0
16661 + SWAPGS_UNSAFE_STACK
16662 + RESTORE_ALL 8
16663 + pax_force_retaddr_bts
16664 + jmp irq_return
16665 +#endif
16666 paranoid_swapgs:
16667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16668 + pax_exit_kernel_user
16669 +#else
16670 + pax_exit_kernel
16671 +#endif
16672 TRACE_IRQS_IRETQ 0
16673 SWAPGS_UNSAFE_STACK
16674 RESTORE_ALL 8
16675 jmp irq_return
16676 paranoid_restore:
16677 + pax_exit_kernel
16678 TRACE_IRQS_IRETQ_DEBUG 0
16679 RESTORE_ALL 8
16680 + pax_force_retaddr_bts
16681 jmp irq_return
16682 paranoid_userspace:
16683 GET_THREAD_INFO(%rcx)
16684 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16685 TRACE_IRQS_OFF
16686 jmp paranoid_userspace
16687 CFI_ENDPROC
16688 -END(paranoid_exit)
16689 +ENDPROC(paranoid_exit)
16690
16691 /*
16692 * Exception entry point. This expects an error code/orig_rax on the stack.
16693 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16694 movq_cfi r14, R14+8
16695 movq_cfi r15, R15+8
16696 xorl %ebx,%ebx
16697 - testl $3,CS+8(%rsp)
16698 + testb $3,CS+8(%rsp)
16699 je error_kernelspace
16700 error_swapgs:
16701 SWAPGS
16702 error_sti:
16703 TRACE_IRQS_OFF
16704 + pax_force_retaddr_bts
16705 ret
16706
16707 /*
16708 @@ -1513,7 +1907,7 @@ bstep_iret:
16709 movq %rcx,RIP+8(%rsp)
16710 jmp error_swapgs
16711 CFI_ENDPROC
16712 -END(error_entry)
16713 +ENDPROC(error_entry)
16714
16715
16716 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16717 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16718 jnz retint_careful
16719 jmp retint_swapgs
16720 CFI_ENDPROC
16721 -END(error_exit)
16722 +ENDPROC(error_exit)
16723
16724 /*
16725 * Test if a given stack is an NMI stack or not.
16726 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16727 * If %cs was not the kernel segment, then the NMI triggered in user
16728 * space, which means it is definitely not nested.
16729 */
16730 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16731 + je 1f
16732 cmpl $__KERNEL_CS, 16(%rsp)
16733 jne first_nmi
16734 -
16735 +1:
16736 /*
16737 * Check the special variable on the stack to see if NMIs are
16738 * executing.
16739 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16740 */
16741 movq %cr2, %r12
16742
16743 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16744 + testb $3, CS(%rsp)
16745 + jnz 1f
16746 + pax_enter_kernel
16747 + jmp 2f
16748 +1: pax_enter_kernel_user
16749 +2:
16750 +#else
16751 + pax_enter_kernel
16752 +#endif
16753 +
16754 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16755 movq %rsp,%rdi
16756 movq $-1,%rsi
16757 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16758 testl %ebx,%ebx /* swapgs needed? */
16759 jnz nmi_restore
16760 nmi_swapgs:
16761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16762 + pax_exit_kernel_user
16763 +#else
16764 + pax_exit_kernel
16765 +#endif
16766 SWAPGS_UNSAFE_STACK
16767 + RESTORE_ALL 8
16768 + /* Clear the NMI executing stack variable */
16769 + movq $0, 10*8(%rsp)
16770 + jmp irq_return
16771 nmi_restore:
16772 + pax_exit_kernel
16773 RESTORE_ALL 8
16774 + pax_force_retaddr_bts
16775 /* Clear the NMI executing stack variable */
16776 movq $0, 10*8(%rsp)
16777 jmp irq_return
16778 CFI_ENDPROC
16779 -END(nmi)
16780 +ENDPROC(nmi)
16781
16782 ENTRY(ignore_sysret)
16783 CFI_STARTPROC
16784 mov $-ENOSYS,%eax
16785 sysret
16786 CFI_ENDPROC
16787 -END(ignore_sysret)
16788 +ENDPROC(ignore_sysret)
16789
16790 /*
16791 * End of kprobes section
16792 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16793 index c3a7cb4..3ad00dc 100644
16794 --- a/arch/x86/kernel/ftrace.c
16795 +++ b/arch/x86/kernel/ftrace.c
16796 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16797 {
16798 unsigned char replaced[MCOUNT_INSN_SIZE];
16799
16800 + ip = ktla_ktva(ip);
16801 +
16802 /*
16803 * Note: Due to modules and __init, code can
16804 * disappear and change, we need to protect against faulting
16805 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16806 unsigned char old[MCOUNT_INSN_SIZE], *new;
16807 int ret;
16808
16809 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16810 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16811 new = ftrace_call_replace(ip, (unsigned long)func);
16812
16813 /* See comment above by declaration of modifying_ftrace_code */
16814 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16815 {
16816 unsigned char code[MCOUNT_INSN_SIZE];
16817
16818 + ip = ktla_ktva(ip);
16819 +
16820 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16821 return -EFAULT;
16822
16823 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16824 index c18f59d..9c0c9f6 100644
16825 --- a/arch/x86/kernel/head32.c
16826 +++ b/arch/x86/kernel/head32.c
16827 @@ -18,6 +18,7 @@
16828 #include <asm/io_apic.h>
16829 #include <asm/bios_ebda.h>
16830 #include <asm/tlbflush.h>
16831 +#include <asm/boot.h>
16832
16833 static void __init i386_default_early_setup(void)
16834 {
16835 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16836
16837 void __init i386_start_kernel(void)
16838 {
16839 - memblock_reserve(__pa_symbol(&_text),
16840 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16841 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16842
16843 #ifdef CONFIG_BLK_DEV_INITRD
16844 /* Reserve INITRD */
16845 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16846 index d42ab17..cb1b997 100644
16847 --- a/arch/x86/kernel/head_32.S
16848 +++ b/arch/x86/kernel/head_32.S
16849 @@ -26,6 +26,12 @@
16850 /* Physical address */
16851 #define pa(X) ((X) - __PAGE_OFFSET)
16852
16853 +#ifdef CONFIG_PAX_KERNEXEC
16854 +#define ta(X) (X)
16855 +#else
16856 +#define ta(X) ((X) - __PAGE_OFFSET)
16857 +#endif
16858 +
16859 /*
16860 * References to members of the new_cpu_data structure.
16861 */
16862 @@ -55,11 +61,7 @@
16863 * and small than max_low_pfn, otherwise will waste some page table entries
16864 */
16865
16866 -#if PTRS_PER_PMD > 1
16867 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16868 -#else
16869 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16870 -#endif
16871 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16872
16873 /* Number of possible pages in the lowmem region */
16874 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16875 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16876 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16877
16878 /*
16879 + * Real beginning of normal "text" segment
16880 + */
16881 +ENTRY(stext)
16882 +ENTRY(_stext)
16883 +
16884 +/*
16885 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16886 * %esi points to the real-mode code as a 32-bit pointer.
16887 * CS and DS must be 4 GB flat segments, but we don't depend on
16888 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16889 * can.
16890 */
16891 __HEAD
16892 +
16893 +#ifdef CONFIG_PAX_KERNEXEC
16894 + jmp startup_32
16895 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16896 +.fill PAGE_SIZE-5,1,0xcc
16897 +#endif
16898 +
16899 ENTRY(startup_32)
16900 movl pa(stack_start),%ecx
16901
16902 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16903 2:
16904 leal -__PAGE_OFFSET(%ecx),%esp
16905
16906 +#ifdef CONFIG_SMP
16907 + movl $pa(cpu_gdt_table),%edi
16908 + movl $__per_cpu_load,%eax
16909 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16910 + rorl $16,%eax
16911 + movb %al,__KERNEL_PERCPU + 4(%edi)
16912 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16913 + movl $__per_cpu_end - 1,%eax
16914 + subl $__per_cpu_start,%eax
16915 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16916 +#endif
16917 +
16918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16919 + movl $NR_CPUS,%ecx
16920 + movl $pa(cpu_gdt_table),%edi
16921 +1:
16922 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16923 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16924 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16925 + addl $PAGE_SIZE_asm,%edi
16926 + loop 1b
16927 +#endif
16928 +
16929 +#ifdef CONFIG_PAX_KERNEXEC
16930 + movl $pa(boot_gdt),%edi
16931 + movl $__LOAD_PHYSICAL_ADDR,%eax
16932 + movw %ax,__BOOT_CS + 2(%edi)
16933 + rorl $16,%eax
16934 + movb %al,__BOOT_CS + 4(%edi)
16935 + movb %ah,__BOOT_CS + 7(%edi)
16936 + rorl $16,%eax
16937 +
16938 + ljmp $(__BOOT_CS),$1f
16939 +1:
16940 +
16941 + movl $NR_CPUS,%ecx
16942 + movl $pa(cpu_gdt_table),%edi
16943 + addl $__PAGE_OFFSET,%eax
16944 +1:
16945 + movw %ax,__KERNEL_CS + 2(%edi)
16946 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16947 + rorl $16,%eax
16948 + movb %al,__KERNEL_CS + 4(%edi)
16949 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16950 + movb %ah,__KERNEL_CS + 7(%edi)
16951 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16952 + rorl $16,%eax
16953 + addl $PAGE_SIZE_asm,%edi
16954 + loop 1b
16955 +#endif
16956 +
16957 /*
16958 * Clear BSS first so that there are no surprises...
16959 */
16960 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16961 movl %eax, pa(max_pfn_mapped)
16962
16963 /* Do early initialization of the fixmap area */
16964 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16965 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16966 +#ifdef CONFIG_COMPAT_VDSO
16967 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16968 +#else
16969 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16970 +#endif
16971 #else /* Not PAE */
16972
16973 page_pde_offset = (__PAGE_OFFSET >> 20);
16974 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16975 movl %eax, pa(max_pfn_mapped)
16976
16977 /* Do early initialization of the fixmap area */
16978 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16979 - movl %eax,pa(initial_page_table+0xffc)
16980 +#ifdef CONFIG_COMPAT_VDSO
16981 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16982 +#else
16983 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16984 +#endif
16985 #endif
16986
16987 #ifdef CONFIG_PARAVIRT
16988 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16989 cmpl $num_subarch_entries, %eax
16990 jae bad_subarch
16991
16992 - movl pa(subarch_entries)(,%eax,4), %eax
16993 - subl $__PAGE_OFFSET, %eax
16994 - jmp *%eax
16995 + jmp *pa(subarch_entries)(,%eax,4)
16996
16997 bad_subarch:
16998 WEAK(lguest_entry)
16999 @@ -256,10 +326,10 @@ WEAK(xen_entry)
17000 __INITDATA
17001
17002 subarch_entries:
17003 - .long default_entry /* normal x86/PC */
17004 - .long lguest_entry /* lguest hypervisor */
17005 - .long xen_entry /* Xen hypervisor */
17006 - .long default_entry /* Moorestown MID */
17007 + .long ta(default_entry) /* normal x86/PC */
17008 + .long ta(lguest_entry) /* lguest hypervisor */
17009 + .long ta(xen_entry) /* Xen hypervisor */
17010 + .long ta(default_entry) /* Moorestown MID */
17011 num_subarch_entries = (. - subarch_entries) / 4
17012 .previous
17013 #else
17014 @@ -310,6 +380,7 @@ default_entry:
17015 orl %edx,%eax
17016 movl %eax,%cr4
17017
17018 +#ifdef CONFIG_X86_PAE
17019 testb $X86_CR4_PAE, %al # check if PAE is enabled
17020 jz 6f
17021
17022 @@ -338,6 +409,9 @@ default_entry:
17023 /* Make changes effective */
17024 wrmsr
17025
17026 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17027 +#endif
17028 +
17029 6:
17030
17031 /*
17032 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17033 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17034 movl %eax,%ss # after changing gdt.
17035
17036 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17037 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17038 movl %eax,%ds
17039 movl %eax,%es
17040
17041 movl $(__KERNEL_PERCPU), %eax
17042 movl %eax,%fs # set this cpu's percpu
17043
17044 +#ifdef CONFIG_CC_STACKPROTECTOR
17045 movl $(__KERNEL_STACK_CANARY),%eax
17046 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17047 + movl $(__USER_DS),%eax
17048 +#else
17049 + xorl %eax,%eax
17050 +#endif
17051 movl %eax,%gs
17052
17053 xorl %eax,%eax # Clear LDT
17054 @@ -520,8 +600,11 @@ setup_once:
17055 * relocation. Manually set base address in stack canary
17056 * segment descriptor.
17057 */
17058 - movl $gdt_page,%eax
17059 + movl $cpu_gdt_table,%eax
17060 movl $stack_canary,%ecx
17061 +#ifdef CONFIG_SMP
17062 + addl $__per_cpu_load,%ecx
17063 +#endif
17064 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17065 shrl $16, %ecx
17066 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17067 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17068 /* This is global to keep gas from relaxing the jumps */
17069 ENTRY(early_idt_handler)
17070 cld
17071 - cmpl $2,%ss:early_recursion_flag
17072 + cmpl $1,%ss:early_recursion_flag
17073 je hlt_loop
17074 incl %ss:early_recursion_flag
17075
17076 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17077 pushl (20+6*4)(%esp) /* trapno */
17078 pushl $fault_msg
17079 call printk
17080 -#endif
17081 call dump_stack
17082 +#endif
17083 hlt_loop:
17084 hlt
17085 jmp hlt_loop
17086 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17087 /* This is the default interrupt "handler" :-) */
17088 ALIGN
17089 ignore_int:
17090 - cld
17091 #ifdef CONFIG_PRINTK
17092 + cmpl $2,%ss:early_recursion_flag
17093 + je hlt_loop
17094 + incl %ss:early_recursion_flag
17095 + cld
17096 pushl %eax
17097 pushl %ecx
17098 pushl %edx
17099 @@ -620,9 +706,6 @@ ignore_int:
17100 movl $(__KERNEL_DS),%eax
17101 movl %eax,%ds
17102 movl %eax,%es
17103 - cmpl $2,early_recursion_flag
17104 - je hlt_loop
17105 - incl early_recursion_flag
17106 pushl 16(%esp)
17107 pushl 24(%esp)
17108 pushl 32(%esp)
17109 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17110 /*
17111 * BSS section
17112 */
17113 -__PAGE_ALIGNED_BSS
17114 - .align PAGE_SIZE
17115 #ifdef CONFIG_X86_PAE
17116 +.section .initial_pg_pmd,"a",@progbits
17117 initial_pg_pmd:
17118 .fill 1024*KPMDS,4,0
17119 #else
17120 +.section .initial_page_table,"a",@progbits
17121 ENTRY(initial_page_table)
17122 .fill 1024,4,0
17123 #endif
17124 +.section .initial_pg_fixmap,"a",@progbits
17125 initial_pg_fixmap:
17126 .fill 1024,4,0
17127 +.section .empty_zero_page,"a",@progbits
17128 ENTRY(empty_zero_page)
17129 .fill 4096,1,0
17130 +.section .swapper_pg_dir,"a",@progbits
17131 ENTRY(swapper_pg_dir)
17132 +#ifdef CONFIG_X86_PAE
17133 + .fill 4,8,0
17134 +#else
17135 .fill 1024,4,0
17136 +#endif
17137 +
17138 +/*
17139 + * The IDT has to be page-aligned to simplify the Pentium
17140 + * F0 0F bug workaround.. We have a special link segment
17141 + * for this.
17142 + */
17143 +.section .idt,"a",@progbits
17144 +ENTRY(idt_table)
17145 + .fill 256,8,0
17146
17147 /*
17148 * This starts the data section.
17149 */
17150 #ifdef CONFIG_X86_PAE
17151 -__PAGE_ALIGNED_DATA
17152 - /* Page-aligned for the benefit of paravirt? */
17153 - .align PAGE_SIZE
17154 +.section .initial_page_table,"a",@progbits
17155 ENTRY(initial_page_table)
17156 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17157 # if KPMDS == 3
17158 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17159 # error "Kernel PMDs should be 1, 2 or 3"
17160 # endif
17161 .align PAGE_SIZE /* needs to be page-sized too */
17162 +
17163 +#ifdef CONFIG_PAX_PER_CPU_PGD
17164 +ENTRY(cpu_pgd)
17165 + .rept NR_CPUS
17166 + .fill 4,8,0
17167 + .endr
17168 +#endif
17169 +
17170 #endif
17171
17172 .data
17173 .balign 4
17174 ENTRY(stack_start)
17175 - .long init_thread_union+THREAD_SIZE
17176 + .long init_thread_union+THREAD_SIZE-8
17177
17178 __INITRODATA
17179 int_msg:
17180 @@ -730,7 +835,7 @@ fault_msg:
17181 * segment size, and 32-bit linear address value:
17182 */
17183
17184 - .data
17185 +.section .rodata,"a",@progbits
17186 .globl boot_gdt_descr
17187 .globl idt_descr
17188
17189 @@ -739,7 +844,7 @@ fault_msg:
17190 .word 0 # 32 bit align gdt_desc.address
17191 boot_gdt_descr:
17192 .word __BOOT_DS+7
17193 - .long boot_gdt - __PAGE_OFFSET
17194 + .long pa(boot_gdt)
17195
17196 .word 0 # 32-bit align idt_desc.address
17197 idt_descr:
17198 @@ -750,7 +855,7 @@ idt_descr:
17199 .word 0 # 32 bit align gdt_desc.address
17200 ENTRY(early_gdt_descr)
17201 .word GDT_ENTRIES*8-1
17202 - .long gdt_page /* Overwritten for secondary CPUs */
17203 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17204
17205 /*
17206 * The boot_gdt must mirror the equivalent in setup.S and is
17207 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17208 .align L1_CACHE_BYTES
17209 ENTRY(boot_gdt)
17210 .fill GDT_ENTRY_BOOT_CS,8,0
17211 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17212 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17213 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17214 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17215 +
17216 + .align PAGE_SIZE_asm
17217 +ENTRY(cpu_gdt_table)
17218 + .rept NR_CPUS
17219 + .quad 0x0000000000000000 /* NULL descriptor */
17220 + .quad 0x0000000000000000 /* 0x0b reserved */
17221 + .quad 0x0000000000000000 /* 0x13 reserved */
17222 + .quad 0x0000000000000000 /* 0x1b reserved */
17223 +
17224 +#ifdef CONFIG_PAX_KERNEXEC
17225 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17226 +#else
17227 + .quad 0x0000000000000000 /* 0x20 unused */
17228 +#endif
17229 +
17230 + .quad 0x0000000000000000 /* 0x28 unused */
17231 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17232 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17233 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17234 + .quad 0x0000000000000000 /* 0x4b reserved */
17235 + .quad 0x0000000000000000 /* 0x53 reserved */
17236 + .quad 0x0000000000000000 /* 0x5b reserved */
17237 +
17238 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17239 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17240 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17241 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17242 +
17243 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17244 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17245 +
17246 + /*
17247 + * Segments used for calling PnP BIOS have byte granularity.
17248 + * The code segments and data segments have fixed 64k limits,
17249 + * the transfer segment sizes are set at run time.
17250 + */
17251 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17252 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17253 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17254 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17255 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17256 +
17257 + /*
17258 + * The APM segments have byte granularity and their bases
17259 + * are set at run time. All have 64k limits.
17260 + */
17261 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17262 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17263 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17264 +
17265 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17266 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17267 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17268 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17269 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17270 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17271 +
17272 + /* Be sure this is zeroed to avoid false validations in Xen */
17273 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17274 + .endr
17275 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17276 index 94bf9cc..400455a 100644
17277 --- a/arch/x86/kernel/head_64.S
17278 +++ b/arch/x86/kernel/head_64.S
17279 @@ -20,6 +20,8 @@
17280 #include <asm/processor-flags.h>
17281 #include <asm/percpu.h>
17282 #include <asm/nops.h>
17283 +#include <asm/cpufeature.h>
17284 +#include <asm/alternative-asm.h>
17285
17286 #ifdef CONFIG_PARAVIRT
17287 #include <asm/asm-offsets.h>
17288 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17289 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17290 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17291 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17292 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17293 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17294 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17295 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17296 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17297 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17298
17299 .text
17300 __HEAD
17301 @@ -88,35 +96,23 @@ startup_64:
17302 */
17303 addq %rbp, init_level4_pgt + 0(%rip)
17304 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17305 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17306 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17307 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17308 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17309
17310 addq %rbp, level3_ident_pgt + 0(%rip)
17311 +#ifndef CONFIG_XEN
17312 + addq %rbp, level3_ident_pgt + 8(%rip)
17313 +#endif
17314
17315 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17316 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17317 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17318 +
17319 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17320 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17321
17322 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17323 -
17324 - /* Add an Identity mapping if I am above 1G */
17325 - leaq _text(%rip), %rdi
17326 - andq $PMD_PAGE_MASK, %rdi
17327 -
17328 - movq %rdi, %rax
17329 - shrq $PUD_SHIFT, %rax
17330 - andq $(PTRS_PER_PUD - 1), %rax
17331 - jz ident_complete
17332 -
17333 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17334 - leaq level3_ident_pgt(%rip), %rbx
17335 - movq %rdx, 0(%rbx, %rax, 8)
17336 -
17337 - movq %rdi, %rax
17338 - shrq $PMD_SHIFT, %rax
17339 - andq $(PTRS_PER_PMD - 1), %rax
17340 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17341 - leaq level2_spare_pgt(%rip), %rbx
17342 - movq %rdx, 0(%rbx, %rax, 8)
17343 -ident_complete:
17344 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17345
17346 /*
17347 * Fixup the kernel text+data virtual addresses. Note that
17348 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17349 * after the boot processor executes this code.
17350 */
17351
17352 - /* Enable PAE mode and PGE */
17353 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17354 + /* Enable PAE mode and PSE/PGE */
17355 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17356 movq %rax, %cr4
17357
17358 /* Setup early boot stage 4 level pagetables. */
17359 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17360 movl $MSR_EFER, %ecx
17361 rdmsr
17362 btsl $_EFER_SCE, %eax /* Enable System Call */
17363 - btl $20,%edi /* No Execute supported? */
17364 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17365 jnc 1f
17366 btsl $_EFER_NX, %eax
17367 + leaq init_level4_pgt(%rip), %rdi
17368 +#ifndef CONFIG_EFI
17369 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17370 +#endif
17371 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17372 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17373 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17374 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17375 1: wrmsr /* Make changes effective */
17376
17377 /* Setup cr0 */
17378 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17379 * jump. In addition we need to ensure %cs is set so we make this
17380 * a far return.
17381 */
17382 + pax_set_fptr_mask
17383 movq initial_code(%rip),%rax
17384 pushq $0 # fake return address to stop unwinder
17385 pushq $__KERNEL_CS # set correct cs
17386 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17387 bad_address:
17388 jmp bad_address
17389
17390 - .section ".init.text","ax"
17391 + __INIT
17392 .globl early_idt_handlers
17393 early_idt_handlers:
17394 # 104(%rsp) %rflags
17395 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17396 addq $16,%rsp # drop vector number and error code
17397 decl early_recursion_flag(%rip)
17398 INTERRUPT_RETURN
17399 + .previous
17400
17401 + __INITDATA
17402 .balign 4
17403 early_recursion_flag:
17404 .long 0
17405 + .previous
17406
17407 + .section .rodata,"a",@progbits
17408 #ifdef CONFIG_EARLY_PRINTK
17409 early_idt_msg:
17410 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17411 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17412 #endif /* CONFIG_EARLY_PRINTK */
17413 .previous
17414
17415 + .section .rodata,"a",@progbits
17416 #define NEXT_PAGE(name) \
17417 .balign PAGE_SIZE; \
17418 ENTRY(name)
17419 @@ -372,7 +382,6 @@ ENTRY(name)
17420 i = i + 1 ; \
17421 .endr
17422
17423 - .data
17424 /*
17425 * This default setting generates an ident mapping at address 0x100000
17426 * and a mapping for the kernel that precisely maps virtual address
17427 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17428 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17429 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17430 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17431 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17432 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17433 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17434 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17435 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17436 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17437 .org init_level4_pgt + L4_START_KERNEL*8, 0
17438 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17439 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17440
17441 +#ifdef CONFIG_PAX_PER_CPU_PGD
17442 +NEXT_PAGE(cpu_pgd)
17443 + .rept NR_CPUS
17444 + .fill 512,8,0
17445 + .endr
17446 +#endif
17447 +
17448 NEXT_PAGE(level3_ident_pgt)
17449 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17450 +#ifdef CONFIG_XEN
17451 .fill 511,8,0
17452 +#else
17453 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17454 + .fill 510,8,0
17455 +#endif
17456 +
17457 +NEXT_PAGE(level3_vmalloc_start_pgt)
17458 + .fill 512,8,0
17459 +
17460 +NEXT_PAGE(level3_vmalloc_end_pgt)
17461 + .fill 512,8,0
17462 +
17463 +NEXT_PAGE(level3_vmemmap_pgt)
17464 + .fill L3_VMEMMAP_START,8,0
17465 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17466
17467 NEXT_PAGE(level3_kernel_pgt)
17468 .fill L3_START_KERNEL,8,0
17469 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17470 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17471 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472
17473 +NEXT_PAGE(level2_vmemmap_pgt)
17474 + .fill 512,8,0
17475 +
17476 NEXT_PAGE(level2_fixmap_pgt)
17477 - .fill 506,8,0
17478 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17479 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17480 - .fill 5,8,0
17481 + .fill 507,8,0
17482 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17483 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17484 + .fill 4,8,0
17485
17486 -NEXT_PAGE(level1_fixmap_pgt)
17487 +NEXT_PAGE(level1_vsyscall_pgt)
17488 .fill 512,8,0
17489
17490 -NEXT_PAGE(level2_ident_pgt)
17491 - /* Since I easily can, map the first 1G.
17492 + /* Since I easily can, map the first 2G.
17493 * Don't set NX because code runs from these pages.
17494 */
17495 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17496 +NEXT_PAGE(level2_ident_pgt)
17497 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17498
17499 NEXT_PAGE(level2_kernel_pgt)
17500 /*
17501 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17502 * If you want to increase this then increase MODULES_VADDR
17503 * too.)
17504 */
17505 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17506 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17507 -
17508 -NEXT_PAGE(level2_spare_pgt)
17509 - .fill 512, 8, 0
17510 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17511
17512 #undef PMDS
17513 #undef NEXT_PAGE
17514
17515 - .data
17516 + .align PAGE_SIZE
17517 +ENTRY(cpu_gdt_table)
17518 + .rept NR_CPUS
17519 + .quad 0x0000000000000000 /* NULL descriptor */
17520 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17521 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17522 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17523 + .quad 0x00cffb000000ffff /* __USER32_CS */
17524 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17525 + .quad 0x00affb000000ffff /* __USER_CS */
17526 +
17527 +#ifdef CONFIG_PAX_KERNEXEC
17528 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17529 +#else
17530 + .quad 0x0 /* unused */
17531 +#endif
17532 +
17533 + .quad 0,0 /* TSS */
17534 + .quad 0,0 /* LDT */
17535 + .quad 0,0,0 /* three TLS descriptors */
17536 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17537 + /* asm/segment.h:GDT_ENTRIES must match this */
17538 +
17539 + /* zero the remaining page */
17540 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17541 + .endr
17542 +
17543 .align 16
17544 .globl early_gdt_descr
17545 early_gdt_descr:
17546 .word GDT_ENTRIES*8-1
17547 early_gdt_descr_base:
17548 - .quad INIT_PER_CPU_VAR(gdt_page)
17549 + .quad cpu_gdt_table
17550
17551 ENTRY(phys_base)
17552 /* This must match the first entry in level2_kernel_pgt */
17553 .quad 0x0000000000000000
17554
17555 #include "../../x86/xen/xen-head.S"
17556 -
17557 - .section .bss, "aw", @nobits
17558 +
17559 + .section .rodata,"a",@progbits
17560 .align L1_CACHE_BYTES
17561 ENTRY(idt_table)
17562 - .skip IDT_ENTRIES * 16
17563 + .fill 512,8,0
17564
17565 .align L1_CACHE_BYTES
17566 ENTRY(nmi_idt_table)
17567 - .skip IDT_ENTRIES * 16
17568 + .fill 512,8,0
17569
17570 __PAGE_ALIGNED_BSS
17571 .align PAGE_SIZE
17572 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17573 index 9c3bd4a..e1d9b35 100644
17574 --- a/arch/x86/kernel/i386_ksyms_32.c
17575 +++ b/arch/x86/kernel/i386_ksyms_32.c
17576 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17577 EXPORT_SYMBOL(cmpxchg8b_emu);
17578 #endif
17579
17580 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17581 +
17582 /* Networking helper routines. */
17583 EXPORT_SYMBOL(csum_partial_copy_generic);
17584 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17585 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17586
17587 EXPORT_SYMBOL(__get_user_1);
17588 EXPORT_SYMBOL(__get_user_2);
17589 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17590
17591 EXPORT_SYMBOL(csum_partial);
17592 EXPORT_SYMBOL(empty_zero_page);
17593 +
17594 +#ifdef CONFIG_PAX_KERNEXEC
17595 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17596 +#endif
17597 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17598 index f250431..54097e7 100644
17599 --- a/arch/x86/kernel/i387.c
17600 +++ b/arch/x86/kernel/i387.c
17601 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17602 static inline bool interrupted_user_mode(void)
17603 {
17604 struct pt_regs *regs = get_irq_regs();
17605 - return regs && user_mode_vm(regs);
17606 + return regs && user_mode(regs);
17607 }
17608
17609 /*
17610 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17611 index 36d1853..bf25736 100644
17612 --- a/arch/x86/kernel/i8259.c
17613 +++ b/arch/x86/kernel/i8259.c
17614 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17615 "spurious 8259A interrupt: IRQ%d.\n", irq);
17616 spurious_irq_mask |= irqmask;
17617 }
17618 - atomic_inc(&irq_err_count);
17619 + atomic_inc_unchecked(&irq_err_count);
17620 /*
17621 * Theoretically we do not have to handle this IRQ,
17622 * but in Linux this does not cause problems and is
17623 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17624 index 8c96897..be66bfa 100644
17625 --- a/arch/x86/kernel/ioport.c
17626 +++ b/arch/x86/kernel/ioport.c
17627 @@ -6,6 +6,7 @@
17628 #include <linux/sched.h>
17629 #include <linux/kernel.h>
17630 #include <linux/capability.h>
17631 +#include <linux/security.h>
17632 #include <linux/errno.h>
17633 #include <linux/types.h>
17634 #include <linux/ioport.h>
17635 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17636
17637 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17638 return -EINVAL;
17639 +#ifdef CONFIG_GRKERNSEC_IO
17640 + if (turn_on && grsec_disable_privio) {
17641 + gr_handle_ioperm();
17642 + return -EPERM;
17643 + }
17644 +#endif
17645 if (turn_on && !capable(CAP_SYS_RAWIO))
17646 return -EPERM;
17647
17648 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17649 * because the ->io_bitmap_max value must match the bitmap
17650 * contents:
17651 */
17652 - tss = &per_cpu(init_tss, get_cpu());
17653 + tss = init_tss + get_cpu();
17654
17655 if (turn_on)
17656 bitmap_clear(t->io_bitmap_ptr, from, num);
17657 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17658 return -EINVAL;
17659 /* Trying to gain more privileges? */
17660 if (level > old) {
17661 +#ifdef CONFIG_GRKERNSEC_IO
17662 + if (grsec_disable_privio) {
17663 + gr_handle_iopl();
17664 + return -EPERM;
17665 + }
17666 +#endif
17667 if (!capable(CAP_SYS_RAWIO))
17668 return -EPERM;
17669 }
17670 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17671 index d44f782..31ab01e 100644
17672 --- a/arch/x86/kernel/irq.c
17673 +++ b/arch/x86/kernel/irq.c
17674 @@ -18,7 +18,7 @@
17675 #include <asm/mce.h>
17676 #include <asm/hw_irq.h>
17677
17678 -atomic_t irq_err_count;
17679 +atomic_unchecked_t irq_err_count;
17680
17681 /* Function pointer for generic interrupt vector handling */
17682 void (*x86_platform_ipi_callback)(void) = NULL;
17683 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17684 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17685 seq_printf(p, " Machine check polls\n");
17686 #endif
17687 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17688 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17689 #if defined(CONFIG_X86_IO_APIC)
17690 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17691 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17692 #endif
17693 return 0;
17694 }
17695 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17696
17697 u64 arch_irq_stat(void)
17698 {
17699 - u64 sum = atomic_read(&irq_err_count);
17700 + u64 sum = atomic_read_unchecked(&irq_err_count);
17701
17702 #ifdef CONFIG_X86_IO_APIC
17703 - sum += atomic_read(&irq_mis_count);
17704 + sum += atomic_read_unchecked(&irq_mis_count);
17705 #endif
17706 return sum;
17707 }
17708 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17709 index 344faf8..355f60d 100644
17710 --- a/arch/x86/kernel/irq_32.c
17711 +++ b/arch/x86/kernel/irq_32.c
17712 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17713 __asm__ __volatile__("andl %%esp,%0" :
17714 "=r" (sp) : "0" (THREAD_SIZE - 1));
17715
17716 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17717 + return sp < STACK_WARN;
17718 }
17719
17720 static void print_stack_overflow(void)
17721 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17722 * per-CPU IRQ handling contexts (thread information and stack)
17723 */
17724 union irq_ctx {
17725 - struct thread_info tinfo;
17726 - u32 stack[THREAD_SIZE/sizeof(u32)];
17727 + unsigned long previous_esp;
17728 + u32 stack[THREAD_SIZE/sizeof(u32)];
17729 } __attribute__((aligned(THREAD_SIZE)));
17730
17731 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17732 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17733 static inline int
17734 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17735 {
17736 - union irq_ctx *curctx, *irqctx;
17737 + union irq_ctx *irqctx;
17738 u32 *isp, arg1, arg2;
17739
17740 - curctx = (union irq_ctx *) current_thread_info();
17741 irqctx = __this_cpu_read(hardirq_ctx);
17742
17743 /*
17744 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17745 * handler) we can't do that and just have to keep using the
17746 * current stack (which is the irq stack already after all)
17747 */
17748 - if (unlikely(curctx == irqctx))
17749 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17750 return 0;
17751
17752 /* build the stack frame on the IRQ stack */
17753 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17754 - irqctx->tinfo.task = curctx->tinfo.task;
17755 - irqctx->tinfo.previous_esp = current_stack_pointer;
17756 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17757 + irqctx->previous_esp = current_stack_pointer;
17758
17759 - /* Copy the preempt_count so that the [soft]irq checks work. */
17760 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17762 + __set_fs(MAKE_MM_SEG(0));
17763 +#endif
17764
17765 if (unlikely(overflow))
17766 call_on_stack(print_stack_overflow, isp);
17767 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 : "0" (irq), "1" (desc), "2" (isp),
17769 "D" (desc->handle_irq)
17770 : "memory", "cc", "ecx");
17771 +
17772 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17773 + __set_fs(current_thread_info()->addr_limit);
17774 +#endif
17775 +
17776 return 1;
17777 }
17778
17779 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17780 */
17781 void __cpuinit irq_ctx_init(int cpu)
17782 {
17783 - union irq_ctx *irqctx;
17784 -
17785 if (per_cpu(hardirq_ctx, cpu))
17786 return;
17787
17788 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17789 - THREADINFO_GFP,
17790 - THREAD_SIZE_ORDER));
17791 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17792 - irqctx->tinfo.cpu = cpu;
17793 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17794 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795 -
17796 - per_cpu(hardirq_ctx, cpu) = irqctx;
17797 -
17798 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799 - THREADINFO_GFP,
17800 - THREAD_SIZE_ORDER));
17801 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802 - irqctx->tinfo.cpu = cpu;
17803 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17804 -
17805 - per_cpu(softirq_ctx, cpu) = irqctx;
17806 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17807 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17808 +
17809 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17810 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17811
17812 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17813 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17814 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17815 asmlinkage void do_softirq(void)
17816 {
17817 unsigned long flags;
17818 - struct thread_info *curctx;
17819 union irq_ctx *irqctx;
17820 u32 *isp;
17821
17822 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17823 local_irq_save(flags);
17824
17825 if (local_softirq_pending()) {
17826 - curctx = current_thread_info();
17827 irqctx = __this_cpu_read(softirq_ctx);
17828 - irqctx->tinfo.task = curctx->task;
17829 - irqctx->tinfo.previous_esp = current_stack_pointer;
17830 + irqctx->previous_esp = current_stack_pointer;
17831
17832 /* build the stack frame on the softirq stack */
17833 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17834 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17835 +
17836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17837 + __set_fs(MAKE_MM_SEG(0));
17838 +#endif
17839
17840 call_on_stack(__do_softirq, isp);
17841 +
17842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17843 + __set_fs(current_thread_info()->addr_limit);
17844 +#endif
17845 +
17846 /*
17847 * Shouldn't happen, we returned above if in_interrupt():
17848 */
17849 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17850 if (unlikely(!desc))
17851 return false;
17852
17853 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17854 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17855 if (unlikely(overflow))
17856 print_stack_overflow();
17857 desc->handle_irq(irq, desc);
17858 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17859 index d04d3ec..ea4b374 100644
17860 --- a/arch/x86/kernel/irq_64.c
17861 +++ b/arch/x86/kernel/irq_64.c
17862 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17863 u64 estack_top, estack_bottom;
17864 u64 curbase = (u64)task_stack_page(current);
17865
17866 - if (user_mode_vm(regs))
17867 + if (user_mode(regs))
17868 return;
17869
17870 if (regs->sp >= curbase + sizeof(struct thread_info) +
17871 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17872 index dc1404b..bbc43e7 100644
17873 --- a/arch/x86/kernel/kdebugfs.c
17874 +++ b/arch/x86/kernel/kdebugfs.c
17875 @@ -27,7 +27,7 @@ struct setup_data_node {
17876 u32 len;
17877 };
17878
17879 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17880 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17881 size_t count, loff_t *ppos)
17882 {
17883 struct setup_data_node *node = file->private_data;
17884 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17885 index 3f61904..873cea9 100644
17886 --- a/arch/x86/kernel/kgdb.c
17887 +++ b/arch/x86/kernel/kgdb.c
17888 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17889 #ifdef CONFIG_X86_32
17890 switch (regno) {
17891 case GDB_SS:
17892 - if (!user_mode_vm(regs))
17893 + if (!user_mode(regs))
17894 *(unsigned long *)mem = __KERNEL_DS;
17895 break;
17896 case GDB_SP:
17897 - if (!user_mode_vm(regs))
17898 + if (!user_mode(regs))
17899 *(unsigned long *)mem = kernel_stack_pointer(regs);
17900 break;
17901 case GDB_GS:
17902 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17903 case 'k':
17904 /* clear the trace bit */
17905 linux_regs->flags &= ~X86_EFLAGS_TF;
17906 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17907 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17908
17909 /* set the trace bit if we're stepping */
17910 if (remcomInBuffer[0] == 's') {
17911 linux_regs->flags |= X86_EFLAGS_TF;
17912 - atomic_set(&kgdb_cpu_doing_single_step,
17913 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17914 raw_smp_processor_id());
17915 }
17916
17917 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17918
17919 switch (cmd) {
17920 case DIE_DEBUG:
17921 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17922 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17923 if (user_mode(regs))
17924 return single_step_cont(regs, args);
17925 break;
17926 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17927 index c5e410e..da6aaf9 100644
17928 --- a/arch/x86/kernel/kprobes-opt.c
17929 +++ b/arch/x86/kernel/kprobes-opt.c
17930 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17931 * Verify if the address gap is in 2GB range, because this uses
17932 * a relative jump.
17933 */
17934 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17935 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17936 if (abs(rel) > 0x7fffffff)
17937 return -ERANGE;
17938
17939 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17940 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17941
17942 /* Set probe function call */
17943 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17944 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17945
17946 /* Set returning jmp instruction at the tail of out-of-line buffer */
17947 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17948 - (u8 *)op->kp.addr + op->optinsn.size);
17949 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17950
17951 flush_icache_range((unsigned long) buf,
17952 (unsigned long) buf + TMPL_END_IDX +
17953 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17954 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17955
17956 /* Backup instructions which will be replaced by jump address */
17957 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17958 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17959 RELATIVE_ADDR_SIZE);
17960
17961 insn_buf[0] = RELATIVEJUMP_OPCODE;
17962 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17963 index e2f751e..dffa2a0 100644
17964 --- a/arch/x86/kernel/kprobes.c
17965 +++ b/arch/x86/kernel/kprobes.c
17966 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17967 } __attribute__((packed)) *insn;
17968
17969 insn = (struct __arch_relative_insn *)from;
17970 +
17971 + pax_open_kernel();
17972 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17973 insn->op = op;
17974 + pax_close_kernel();
17975 }
17976
17977 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17978 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17979 kprobe_opcode_t opcode;
17980 kprobe_opcode_t *orig_opcodes = opcodes;
17981
17982 - if (search_exception_tables((unsigned long)opcodes))
17983 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17984 return 0; /* Page fault may occur on this address. */
17985
17986 retry:
17987 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17988 /* Another subsystem puts a breakpoint, failed to recover */
17989 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17990 return 0;
17991 + pax_open_kernel();
17992 memcpy(dest, insn.kaddr, insn.length);
17993 + pax_close_kernel();
17994
17995 #ifdef CONFIG_X86_64
17996 if (insn_rip_relative(&insn)) {
17997 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17998 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17999 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18000 disp = (u8 *) dest + insn_offset_displacement(&insn);
18001 + pax_open_kernel();
18002 *(s32 *) disp = (s32) newdisp;
18003 + pax_close_kernel();
18004 }
18005 #endif
18006 return insn.length;
18007 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18008 * nor set current_kprobe, because it doesn't use single
18009 * stepping.
18010 */
18011 - regs->ip = (unsigned long)p->ainsn.insn;
18012 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 preempt_enable_no_resched();
18014 return;
18015 }
18016 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18017 if (p->opcode == BREAKPOINT_INSTRUCTION)
18018 regs->ip = (unsigned long)p->addr;
18019 else
18020 - regs->ip = (unsigned long)p->ainsn.insn;
18021 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 }
18023
18024 /*
18025 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18026 setup_singlestep(p, regs, kcb, 0);
18027 return 1;
18028 }
18029 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18030 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18031 /*
18032 * The breakpoint instruction was removed right
18033 * after we hit it. Another cpu has removed
18034 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18035 " movq %rax, 152(%rsp)\n"
18036 RESTORE_REGS_STRING
18037 " popfq\n"
18038 +#ifdef KERNEXEC_PLUGIN
18039 + " btsq $63,(%rsp)\n"
18040 +#endif
18041 #else
18042 " pushf\n"
18043 SAVE_REGS_STRING
18044 @@ -765,7 +775,7 @@ static void __kprobes
18045 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18046 {
18047 unsigned long *tos = stack_addr(regs);
18048 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18049 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 unsigned long orig_ip = (unsigned long)p->addr;
18051 kprobe_opcode_t *insn = p->ainsn.insn;
18052
18053 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18054 struct die_args *args = data;
18055 int ret = NOTIFY_DONE;
18056
18057 - if (args->regs && user_mode_vm(args->regs))
18058 + if (args->regs && user_mode(args->regs))
18059 return ret;
18060
18061 switch (val) {
18062 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18063 index ebc9873..1b9724b 100644
18064 --- a/arch/x86/kernel/ldt.c
18065 +++ b/arch/x86/kernel/ldt.c
18066 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18067 if (reload) {
18068 #ifdef CONFIG_SMP
18069 preempt_disable();
18070 - load_LDT(pc);
18071 + load_LDT_nolock(pc);
18072 if (!cpumask_equal(mm_cpumask(current->mm),
18073 cpumask_of(smp_processor_id())))
18074 smp_call_function(flush_ldt, current->mm, 1);
18075 preempt_enable();
18076 #else
18077 - load_LDT(pc);
18078 + load_LDT_nolock(pc);
18079 #endif
18080 }
18081 if (oldsize) {
18082 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18083 return err;
18084
18085 for (i = 0; i < old->size; i++)
18086 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18087 + write_ldt_entry(new->ldt, i, old->ldt + i);
18088 return 0;
18089 }
18090
18091 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18092 retval = copy_ldt(&mm->context, &old_mm->context);
18093 mutex_unlock(&old_mm->context.lock);
18094 }
18095 +
18096 + if (tsk == current) {
18097 + mm->context.vdso = 0;
18098 +
18099 +#ifdef CONFIG_X86_32
18100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18101 + mm->context.user_cs_base = 0UL;
18102 + mm->context.user_cs_limit = ~0UL;
18103 +
18104 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18105 + cpus_clear(mm->context.cpu_user_cs_mask);
18106 +#endif
18107 +
18108 +#endif
18109 +#endif
18110 +
18111 + }
18112 +
18113 return retval;
18114 }
18115
18116 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18117 }
18118 }
18119
18120 +#ifdef CONFIG_PAX_SEGMEXEC
18121 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18122 + error = -EINVAL;
18123 + goto out_unlock;
18124 + }
18125 +#endif
18126 +
18127 fill_ldt(&ldt, &ldt_info);
18128 if (oldmode)
18129 ldt.avl = 0;
18130 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18131 index 5b19e4d..6476a76 100644
18132 --- a/arch/x86/kernel/machine_kexec_32.c
18133 +++ b/arch/x86/kernel/machine_kexec_32.c
18134 @@ -26,7 +26,7 @@
18135 #include <asm/cacheflush.h>
18136 #include <asm/debugreg.h>
18137
18138 -static void set_idt(void *newidt, __u16 limit)
18139 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18140 {
18141 struct desc_ptr curidt;
18142
18143 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18144 }
18145
18146
18147 -static void set_gdt(void *newgdt, __u16 limit)
18148 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18149 {
18150 struct desc_ptr curgdt;
18151
18152 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18153 }
18154
18155 control_page = page_address(image->control_code_page);
18156 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18157 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18158
18159 relocate_kernel_ptr = control_page;
18160 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18161 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18162 index 0327e2b..e43737b 100644
18163 --- a/arch/x86/kernel/microcode_intel.c
18164 +++ b/arch/x86/kernel/microcode_intel.c
18165 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18166
18167 static int get_ucode_user(void *to, const void *from, size_t n)
18168 {
18169 - return copy_from_user(to, from, n);
18170 + return copy_from_user(to, (const void __force_user *)from, n);
18171 }
18172
18173 static enum ucode_state
18174 request_microcode_user(int cpu, const void __user *buf, size_t size)
18175 {
18176 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18177 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18178 }
18179
18180 static void microcode_fini_cpu(int cpu)
18181 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18182 index 216a4d7..b328f09 100644
18183 --- a/arch/x86/kernel/module.c
18184 +++ b/arch/x86/kernel/module.c
18185 @@ -43,15 +43,60 @@ do { \
18186 } while (0)
18187 #endif
18188
18189 -void *module_alloc(unsigned long size)
18190 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18191 {
18192 - if (PAGE_ALIGN(size) > MODULES_LEN)
18193 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18194 return NULL;
18195 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18196 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18197 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18198 -1, __builtin_return_address(0));
18199 }
18200
18201 +void *module_alloc(unsigned long size)
18202 +{
18203 +
18204 +#ifdef CONFIG_PAX_KERNEXEC
18205 + return __module_alloc(size, PAGE_KERNEL);
18206 +#else
18207 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18208 +#endif
18209 +
18210 +}
18211 +
18212 +#ifdef CONFIG_PAX_KERNEXEC
18213 +#ifdef CONFIG_X86_32
18214 +void *module_alloc_exec(unsigned long size)
18215 +{
18216 + struct vm_struct *area;
18217 +
18218 + if (size == 0)
18219 + return NULL;
18220 +
18221 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18222 + return area ? area->addr : NULL;
18223 +}
18224 +EXPORT_SYMBOL(module_alloc_exec);
18225 +
18226 +void module_free_exec(struct module *mod, void *module_region)
18227 +{
18228 + vunmap(module_region);
18229 +}
18230 +EXPORT_SYMBOL(module_free_exec);
18231 +#else
18232 +void module_free_exec(struct module *mod, void *module_region)
18233 +{
18234 + module_free(mod, module_region);
18235 +}
18236 +EXPORT_SYMBOL(module_free_exec);
18237 +
18238 +void *module_alloc_exec(unsigned long size)
18239 +{
18240 + return __module_alloc(size, PAGE_KERNEL_RX);
18241 +}
18242 +EXPORT_SYMBOL(module_alloc_exec);
18243 +#endif
18244 +#endif
18245 +
18246 #ifdef CONFIG_X86_32
18247 int apply_relocate(Elf32_Shdr *sechdrs,
18248 const char *strtab,
18249 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18250 unsigned int i;
18251 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18252 Elf32_Sym *sym;
18253 - uint32_t *location;
18254 + uint32_t *plocation, location;
18255
18256 DEBUGP("Applying relocate section %u to %u\n",
18257 relsec, sechdrs[relsec].sh_info);
18258 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18259 /* This is where to make the change */
18260 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18261 - + rel[i].r_offset;
18262 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18263 + location = (uint32_t)plocation;
18264 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18265 + plocation = ktla_ktva((void *)plocation);
18266 /* This is the symbol it is referring to. Note that all
18267 undefined symbols have been resolved. */
18268 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18269 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18270 switch (ELF32_R_TYPE(rel[i].r_info)) {
18271 case R_386_32:
18272 /* We add the value into the location given */
18273 - *location += sym->st_value;
18274 + pax_open_kernel();
18275 + *plocation += sym->st_value;
18276 + pax_close_kernel();
18277 break;
18278 case R_386_PC32:
18279 /* Add the value, subtract its position */
18280 - *location += sym->st_value - (uint32_t)location;
18281 + pax_open_kernel();
18282 + *plocation += sym->st_value - location;
18283 + pax_close_kernel();
18284 break;
18285 default:
18286 pr_err("%s: Unknown relocation: %u\n",
18287 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18288 case R_X86_64_NONE:
18289 break;
18290 case R_X86_64_64:
18291 + pax_open_kernel();
18292 *(u64 *)loc = val;
18293 + pax_close_kernel();
18294 break;
18295 case R_X86_64_32:
18296 + pax_open_kernel();
18297 *(u32 *)loc = val;
18298 + pax_close_kernel();
18299 if (val != *(u32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_32S:
18303 + pax_open_kernel();
18304 *(s32 *)loc = val;
18305 + pax_close_kernel();
18306 if ((s64)val != *(s32 *)loc)
18307 goto overflow;
18308 break;
18309 case R_X86_64_PC32:
18310 val -= (u64)loc;
18311 + pax_open_kernel();
18312 *(u32 *)loc = val;
18313 + pax_close_kernel();
18314 +
18315 #if 0
18316 if ((s64)val != *(s32 *)loc)
18317 goto overflow;
18318 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18319 index f84f5c5..e27e54b 100644
18320 --- a/arch/x86/kernel/nmi.c
18321 +++ b/arch/x86/kernel/nmi.c
18322 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18323 dotraplinkage notrace __kprobes void
18324 do_nmi(struct pt_regs *regs, long error_code)
18325 {
18326 +
18327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18328 + if (!user_mode(regs)) {
18329 + unsigned long cs = regs->cs & 0xFFFF;
18330 + unsigned long ip = ktva_ktla(regs->ip);
18331 +
18332 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18333 + regs->ip = ip;
18334 + }
18335 +#endif
18336 +
18337 nmi_nesting_preprocess(regs);
18338
18339 nmi_enter();
18340 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18341 index 676b8c7..870ba04 100644
18342 --- a/arch/x86/kernel/paravirt-spinlocks.c
18343 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18344 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18345 arch_spin_lock(lock);
18346 }
18347
18348 -struct pv_lock_ops pv_lock_ops = {
18349 +struct pv_lock_ops pv_lock_ops __read_only = {
18350 #ifdef CONFIG_SMP
18351 .spin_is_locked = __ticket_spin_is_locked,
18352 .spin_is_contended = __ticket_spin_is_contended,
18353 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18354 index 17fff18..7bb2088 100644
18355 --- a/arch/x86/kernel/paravirt.c
18356 +++ b/arch/x86/kernel/paravirt.c
18357 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18358 {
18359 return x;
18360 }
18361 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18362 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18363 +#endif
18364
18365 void __init default_banner(void)
18366 {
18367 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18368 if (opfunc == NULL)
18369 /* If there's no function, patch it with a ud2a (BUG) */
18370 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18371 - else if (opfunc == _paravirt_nop)
18372 + else if (opfunc == (void *)_paravirt_nop)
18373 /* If the operation is a nop, then nop the callsite */
18374 ret = paravirt_patch_nop();
18375
18376 /* identity functions just return their single argument */
18377 - else if (opfunc == _paravirt_ident_32)
18378 + else if (opfunc == (void *)_paravirt_ident_32)
18379 ret = paravirt_patch_ident_32(insnbuf, len);
18380 - else if (opfunc == _paravirt_ident_64)
18381 + else if (opfunc == (void *)_paravirt_ident_64)
18382 ret = paravirt_patch_ident_64(insnbuf, len);
18383 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18384 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18385 + ret = paravirt_patch_ident_64(insnbuf, len);
18386 +#endif
18387
18388 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18389 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18390 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18391 if (insn_len > len || start == NULL)
18392 insn_len = len;
18393 else
18394 - memcpy(insnbuf, start, insn_len);
18395 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18396
18397 return insn_len;
18398 }
18399 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18400 preempt_enable();
18401 }
18402
18403 -struct pv_info pv_info = {
18404 +struct pv_info pv_info __read_only = {
18405 .name = "bare hardware",
18406 .paravirt_enabled = 0,
18407 .kernel_rpl = 0,
18408 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18409 #endif
18410 };
18411
18412 -struct pv_init_ops pv_init_ops = {
18413 +struct pv_init_ops pv_init_ops __read_only = {
18414 .patch = native_patch,
18415 };
18416
18417 -struct pv_time_ops pv_time_ops = {
18418 +struct pv_time_ops pv_time_ops __read_only = {
18419 .sched_clock = native_sched_clock,
18420 .steal_clock = native_steal_clock,
18421 };
18422
18423 -struct pv_irq_ops pv_irq_ops = {
18424 +struct pv_irq_ops pv_irq_ops __read_only = {
18425 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18426 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18427 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18428 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18429 #endif
18430 };
18431
18432 -struct pv_cpu_ops pv_cpu_ops = {
18433 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18434 .cpuid = native_cpuid,
18435 .get_debugreg = native_get_debugreg,
18436 .set_debugreg = native_set_debugreg,
18437 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18438 .end_context_switch = paravirt_nop,
18439 };
18440
18441 -struct pv_apic_ops pv_apic_ops = {
18442 +struct pv_apic_ops pv_apic_ops __read_only = {
18443 #ifdef CONFIG_X86_LOCAL_APIC
18444 .startup_ipi_hook = paravirt_nop,
18445 #endif
18446 };
18447
18448 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18449 +#ifdef CONFIG_X86_32
18450 +#ifdef CONFIG_X86_PAE
18451 +/* 64-bit pagetable entries */
18452 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18453 +#else
18454 /* 32-bit pagetable entries */
18455 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18456 +#endif
18457 #else
18458 /* 64-bit pagetable entries */
18459 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18460 #endif
18461
18462 -struct pv_mmu_ops pv_mmu_ops = {
18463 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18464
18465 .read_cr2 = native_read_cr2,
18466 .write_cr2 = native_write_cr2,
18467 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18468 .make_pud = PTE_IDENT,
18469
18470 .set_pgd = native_set_pgd,
18471 + .set_pgd_batched = native_set_pgd_batched,
18472 #endif
18473 #endif /* PAGETABLE_LEVELS >= 3 */
18474
18475 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18476 },
18477
18478 .set_fixmap = native_set_fixmap,
18479 +
18480 +#ifdef CONFIG_PAX_KERNEXEC
18481 + .pax_open_kernel = native_pax_open_kernel,
18482 + .pax_close_kernel = native_pax_close_kernel,
18483 +#endif
18484 +
18485 };
18486
18487 EXPORT_SYMBOL_GPL(pv_time_ops);
18488 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18489 index 35ccf75..7a15747 100644
18490 --- a/arch/x86/kernel/pci-iommu_table.c
18491 +++ b/arch/x86/kernel/pci-iommu_table.c
18492 @@ -2,7 +2,7 @@
18493 #include <asm/iommu_table.h>
18494 #include <linux/string.h>
18495 #include <linux/kallsyms.h>
18496 -
18497 +#include <linux/sched.h>
18498
18499 #define DEBUG 1
18500
18501 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18502 index ef6a845..8028ed3 100644
18503 --- a/arch/x86/kernel/process.c
18504 +++ b/arch/x86/kernel/process.c
18505 @@ -36,7 +36,8 @@
18506 * section. Since TSS's are completely CPU-local, we want them
18507 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18508 */
18509 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18510 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18511 +EXPORT_SYMBOL(init_tss);
18512
18513 #ifdef CONFIG_X86_64
18514 static DEFINE_PER_CPU(unsigned char, is_idle);
18515 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18516 task_xstate_cachep =
18517 kmem_cache_create("task_xstate", xstate_size,
18518 __alignof__(union thread_xstate),
18519 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18520 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18521 }
18522
18523 static inline void drop_fpu(struct task_struct *tsk)
18524 @@ -117,7 +118,7 @@ void exit_thread(void)
18525 unsigned long *bp = t->io_bitmap_ptr;
18526
18527 if (bp) {
18528 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18529 + struct tss_struct *tss = init_tss + get_cpu();
18530
18531 t->io_bitmap_ptr = NULL;
18532 clear_thread_flag(TIF_IO_BITMAP);
18533 @@ -148,7 +149,7 @@ void show_regs_common(void)
18534 board = dmi_get_system_info(DMI_BOARD_NAME);
18535
18536 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18537 - current->pid, current->comm, print_tainted(),
18538 + task_pid_nr(current), current->comm, print_tainted(),
18539 init_utsname()->release,
18540 (int)strcspn(init_utsname()->version, " "),
18541 init_utsname()->version,
18542 @@ -161,6 +162,9 @@ void flush_thread(void)
18543 {
18544 struct task_struct *tsk = current;
18545
18546 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18547 + loadsegment(gs, 0);
18548 +#endif
18549 flush_ptrace_hw_breakpoint(tsk);
18550 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18551 drop_fpu(tsk);
18552 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18553 regs.di = (unsigned long) arg;
18554
18555 #ifdef CONFIG_X86_32
18556 - regs.ds = __USER_DS;
18557 - regs.es = __USER_DS;
18558 + regs.ds = __KERNEL_DS;
18559 + regs.es = __KERNEL_DS;
18560 regs.fs = __KERNEL_PERCPU;
18561 - regs.gs = __KERNEL_STACK_CANARY;
18562 + savesegment(gs, regs.gs);
18563 #else
18564 regs.ss = __KERNEL_DS;
18565 #endif
18566 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18567 void exit_idle(void)
18568 {
18569 /* idle loop has pid 0 */
18570 - if (current->pid)
18571 + if (task_pid_nr(current))
18572 return;
18573 __exit_idle();
18574 }
18575 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18576
18577 return ret;
18578 }
18579 -void stop_this_cpu(void *dummy)
18580 +__noreturn void stop_this_cpu(void *dummy)
18581 {
18582 local_irq_disable();
18583 /*
18584 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18585 }
18586 early_param("idle", idle_setup);
18587
18588 -unsigned long arch_align_stack(unsigned long sp)
18589 +#ifdef CONFIG_PAX_RANDKSTACK
18590 +void pax_randomize_kstack(struct pt_regs *regs)
18591 {
18592 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18593 - sp -= get_random_int() % 8192;
18594 - return sp & ~0xf;
18595 -}
18596 + struct thread_struct *thread = &current->thread;
18597 + unsigned long time;
18598
18599 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18600 -{
18601 - unsigned long range_end = mm->brk + 0x02000000;
18602 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18603 -}
18604 + if (!randomize_va_space)
18605 + return;
18606 +
18607 + if (v8086_mode(regs))
18608 + return;
18609
18610 + rdtscl(time);
18611 +
18612 + /* P4 seems to return a 0 LSB, ignore it */
18613 +#ifdef CONFIG_MPENTIUM4
18614 + time &= 0x3EUL;
18615 + time <<= 2;
18616 +#elif defined(CONFIG_X86_64)
18617 + time &= 0xFUL;
18618 + time <<= 4;
18619 +#else
18620 + time &= 0x1FUL;
18621 + time <<= 3;
18622 +#endif
18623 +
18624 + thread->sp0 ^= time;
18625 + load_sp0(init_tss + smp_processor_id(), thread);
18626 +
18627 +#ifdef CONFIG_X86_64
18628 + this_cpu_write(kernel_stack, thread->sp0);
18629 +#endif
18630 +}
18631 +#endif
18632 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18633 index 516fa18..80bd9e6 100644
18634 --- a/arch/x86/kernel/process_32.c
18635 +++ b/arch/x86/kernel/process_32.c
18636 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18637 unsigned long thread_saved_pc(struct task_struct *tsk)
18638 {
18639 return ((unsigned long *)tsk->thread.sp)[3];
18640 +//XXX return tsk->thread.eip;
18641 }
18642
18643 void __show_regs(struct pt_regs *regs, int all)
18644 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18645 unsigned long sp;
18646 unsigned short ss, gs;
18647
18648 - if (user_mode_vm(regs)) {
18649 + if (user_mode(regs)) {
18650 sp = regs->sp;
18651 ss = regs->ss & 0xffff;
18652 - gs = get_user_gs(regs);
18653 } else {
18654 sp = kernel_stack_pointer(regs);
18655 savesegment(ss, ss);
18656 - savesegment(gs, gs);
18657 }
18658 + gs = get_user_gs(regs);
18659
18660 show_regs_common();
18661
18662 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18663 struct task_struct *tsk;
18664 int err;
18665
18666 - childregs = task_pt_regs(p);
18667 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18668 *childregs = *regs;
18669 childregs->ax = 0;
18670 childregs->sp = sp;
18671
18672 p->thread.sp = (unsigned long) childregs;
18673 p->thread.sp0 = (unsigned long) (childregs+1);
18674 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18675
18676 p->thread.ip = (unsigned long) ret_from_fork;
18677
18678 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 struct thread_struct *prev = &prev_p->thread,
18680 *next = &next_p->thread;
18681 int cpu = smp_processor_id();
18682 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18683 + struct tss_struct *tss = init_tss + cpu;
18684 fpu_switch_t fpu;
18685
18686 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18687 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 */
18689 lazy_save_gs(prev->gs);
18690
18691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18692 + __set_fs(task_thread_info(next_p)->addr_limit);
18693 +#endif
18694 +
18695 /*
18696 * Load the per-thread Thread-Local Storage descriptor.
18697 */
18698 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18699 */
18700 arch_end_context_switch(next_p);
18701
18702 + this_cpu_write(current_task, next_p);
18703 + this_cpu_write(current_tinfo, &next_p->tinfo);
18704 +
18705 /*
18706 * Restore %gs if needed (which is common)
18707 */
18708 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709
18710 switch_fpu_finish(next_p, fpu);
18711
18712 - this_cpu_write(current_task, next_p);
18713 -
18714 return prev_p;
18715 }
18716
18717 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18718 } while (count++ < 16);
18719 return 0;
18720 }
18721 -
18722 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18723 index 0a980c9..1d0e689 100644
18724 --- a/arch/x86/kernel/process_64.c
18725 +++ b/arch/x86/kernel/process_64.c
18726 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18727 struct pt_regs *childregs;
18728 struct task_struct *me = current;
18729
18730 - childregs = ((struct pt_regs *)
18731 - (THREAD_SIZE + task_stack_page(p))) - 1;
18732 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18733 *childregs = *regs;
18734
18735 childregs->ax = 0;
18736 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 p->thread.sp = (unsigned long) childregs;
18738 p->thread.sp0 = (unsigned long) (childregs+1);
18739 p->thread.usersp = me->thread.usersp;
18740 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18741
18742 set_tsk_thread_flag(p, TIF_FORK);
18743
18744 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 struct thread_struct *prev = &prev_p->thread;
18746 struct thread_struct *next = &next_p->thread;
18747 int cpu = smp_processor_id();
18748 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18749 + struct tss_struct *tss = init_tss + cpu;
18750 unsigned fsindex, gsindex;
18751 fpu_switch_t fpu;
18752
18753 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18754 prev->usersp = this_cpu_read(old_rsp);
18755 this_cpu_write(old_rsp, next->usersp);
18756 this_cpu_write(current_task, next_p);
18757 + this_cpu_write(current_tinfo, &next_p->tinfo);
18758
18759 - this_cpu_write(kernel_stack,
18760 - (unsigned long)task_stack_page(next_p) +
18761 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18762 + this_cpu_write(kernel_stack, next->sp0);
18763
18764 /*
18765 * Now maybe reload the debug registers and handle I/O bitmaps
18766 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18767 if (!p || p == current || p->state == TASK_RUNNING)
18768 return 0;
18769 stack = (unsigned long)task_stack_page(p);
18770 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18771 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18772 return 0;
18773 fp = *(u64 *)(p->thread.sp);
18774 do {
18775 - if (fp < (unsigned long)stack ||
18776 - fp >= (unsigned long)stack+THREAD_SIZE)
18777 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18778 return 0;
18779 ip = *(u64 *)(fp+8);
18780 if (!in_sched_functions(ip))
18781 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18782 index c4c6a5c..905f440 100644
18783 --- a/arch/x86/kernel/ptrace.c
18784 +++ b/arch/x86/kernel/ptrace.c
18785 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18786 unsigned long addr, unsigned long data)
18787 {
18788 int ret;
18789 - unsigned long __user *datap = (unsigned long __user *)data;
18790 + unsigned long __user *datap = (__force unsigned long __user *)data;
18791
18792 switch (request) {
18793 /* read the word at location addr in the USER area. */
18794 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18795 if ((int) addr < 0)
18796 return -EIO;
18797 ret = do_get_thread_area(child, addr,
18798 - (struct user_desc __user *)data);
18799 + (__force struct user_desc __user *) data);
18800 break;
18801
18802 case PTRACE_SET_THREAD_AREA:
18803 if ((int) addr < 0)
18804 return -EIO;
18805 ret = do_set_thread_area(child, addr,
18806 - (struct user_desc __user *)data, 0);
18807 + (__force struct user_desc __user *) data, 0);
18808 break;
18809 #endif
18810
18811 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18812 memset(info, 0, sizeof(*info));
18813 info->si_signo = SIGTRAP;
18814 info->si_code = si_code;
18815 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18816 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18817 }
18818
18819 void user_single_step_siginfo(struct task_struct *tsk,
18820 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18821 # define IS_IA32 0
18822 #endif
18823
18824 +#ifdef CONFIG_GRKERNSEC_SETXID
18825 +extern void gr_delayed_cred_worker(void);
18826 +#endif
18827 +
18828 /*
18829 * We must return the syscall number to actually look up in the table.
18830 * This can be -1L to skip running any syscall at all.
18831 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18832 {
18833 long ret = 0;
18834
18835 +#ifdef CONFIG_GRKERNSEC_SETXID
18836 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18837 + gr_delayed_cred_worker();
18838 +#endif
18839 +
18840 /*
18841 * If we stepped into a sysenter/syscall insn, it trapped in
18842 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18843 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18844 {
18845 bool step;
18846
18847 +#ifdef CONFIG_GRKERNSEC_SETXID
18848 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18849 + gr_delayed_cred_worker();
18850 +#endif
18851 +
18852 audit_syscall_exit(regs);
18853
18854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18855 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18856 index 42eb330..139955c 100644
18857 --- a/arch/x86/kernel/pvclock.c
18858 +++ b/arch/x86/kernel/pvclock.c
18859 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18860 return pv_tsc_khz;
18861 }
18862
18863 -static atomic64_t last_value = ATOMIC64_INIT(0);
18864 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18865
18866 void pvclock_resume(void)
18867 {
18868 - atomic64_set(&last_value, 0);
18869 + atomic64_set_unchecked(&last_value, 0);
18870 }
18871
18872 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18873 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18874 * updating at the same time, and one of them could be slightly behind,
18875 * making the assumption that last_value always go forward fail to hold.
18876 */
18877 - last = atomic64_read(&last_value);
18878 + last = atomic64_read_unchecked(&last_value);
18879 do {
18880 if (ret < last)
18881 return last;
18882 - last = atomic64_cmpxchg(&last_value, last, ret);
18883 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18884 } while (unlikely(last != ret));
18885
18886 return ret;
18887 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18888 index 52190a9..8074389 100644
18889 --- a/arch/x86/kernel/reboot.c
18890 +++ b/arch/x86/kernel/reboot.c
18891 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18892 EXPORT_SYMBOL(pm_power_off);
18893
18894 static const struct desc_ptr no_idt = {};
18895 -static int reboot_mode;
18896 +static unsigned short reboot_mode;
18897 enum reboot_type reboot_type = BOOT_ACPI;
18898 int reboot_force;
18899
18900 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18901
18902 void __noreturn machine_real_restart(unsigned int type)
18903 {
18904 +
18905 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18906 + struct desc_struct *gdt;
18907 +#endif
18908 +
18909 local_irq_disable();
18910
18911 /*
18912 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18913
18914 /* Jump to the identity-mapped low memory code */
18915 #ifdef CONFIG_X86_32
18916 - asm volatile("jmpl *%0" : :
18917 +
18918 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18919 + gdt = get_cpu_gdt_table(smp_processor_id());
18920 + pax_open_kernel();
18921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18922 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18923 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18924 + loadsegment(ds, __KERNEL_DS);
18925 + loadsegment(es, __KERNEL_DS);
18926 + loadsegment(ss, __KERNEL_DS);
18927 +#endif
18928 +#ifdef CONFIG_PAX_KERNEXEC
18929 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18930 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18931 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18932 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18933 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18934 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18935 +#endif
18936 + pax_close_kernel();
18937 +#endif
18938 +
18939 + asm volatile("ljmpl *%0" : :
18940 "rm" (real_mode_header->machine_real_restart_asm),
18941 "a" (type));
18942 #else
18943 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18944 * try to force a triple fault and then cycle between hitting the keyboard
18945 * controller and doing that
18946 */
18947 -static void native_machine_emergency_restart(void)
18948 +static void __noreturn native_machine_emergency_restart(void)
18949 {
18950 int i;
18951 int attempt = 0;
18952 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18953 #endif
18954 }
18955
18956 -static void __machine_emergency_restart(int emergency)
18957 +static void __noreturn __machine_emergency_restart(int emergency)
18958 {
18959 reboot_emergency = emergency;
18960 machine_ops.emergency_restart();
18961 }
18962
18963 -static void native_machine_restart(char *__unused)
18964 +static void __noreturn native_machine_restart(char *__unused)
18965 {
18966 pr_notice("machine restart\n");
18967
18968 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18969 __machine_emergency_restart(0);
18970 }
18971
18972 -static void native_machine_halt(void)
18973 +static void __noreturn native_machine_halt(void)
18974 {
18975 /* Stop other cpus and apics */
18976 machine_shutdown();
18977 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18978 stop_this_cpu(NULL);
18979 }
18980
18981 -static void native_machine_power_off(void)
18982 +static void __noreturn native_machine_power_off(void)
18983 {
18984 if (pm_power_off) {
18985 if (!reboot_force)
18986 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18987 }
18988 /* A fallback in case there is no PM info available */
18989 tboot_shutdown(TB_SHUTDOWN_HALT);
18990 + unreachable();
18991 }
18992
18993 struct machine_ops machine_ops = {
18994 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18995 index 7a6f3b3..bed145d7 100644
18996 --- a/arch/x86/kernel/relocate_kernel_64.S
18997 +++ b/arch/x86/kernel/relocate_kernel_64.S
18998 @@ -11,6 +11,7 @@
18999 #include <asm/kexec.h>
19000 #include <asm/processor-flags.h>
19001 #include <asm/pgtable_types.h>
19002 +#include <asm/alternative-asm.h>
19003
19004 /*
19005 * Must be relocatable PIC code callable as a C function
19006 @@ -160,13 +161,14 @@ identity_mapped:
19007 xorq %rbp, %rbp
19008 xorq %r8, %r8
19009 xorq %r9, %r9
19010 - xorq %r10, %r9
19011 + xorq %r10, %r10
19012 xorq %r11, %r11
19013 xorq %r12, %r12
19014 xorq %r13, %r13
19015 xorq %r14, %r14
19016 xorq %r15, %r15
19017
19018 + pax_force_retaddr 0, 1
19019 ret
19020
19021 1:
19022 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19023 index f4b9b80..0d05de1 100644
19024 --- a/arch/x86/kernel/setup.c
19025 +++ b/arch/x86/kernel/setup.c
19026 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19027
19028 switch (data->type) {
19029 case SETUP_E820_EXT:
19030 - parse_e820_ext(data);
19031 + parse_e820_ext((struct setup_data __force_kernel *)data);
19032 break;
19033 case SETUP_DTB:
19034 add_dtb(pa_data);
19035 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19036 * area (640->1Mb) as ram even though it is not.
19037 * take them out.
19038 */
19039 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19040 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19041 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19042 }
19043
19044 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19045
19046 if (!boot_params.hdr.root_flags)
19047 root_mountflags &= ~MS_RDONLY;
19048 - init_mm.start_code = (unsigned long) _text;
19049 - init_mm.end_code = (unsigned long) _etext;
19050 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19051 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19052 init_mm.end_data = (unsigned long) _edata;
19053 init_mm.brk = _brk_end;
19054
19055 - code_resource.start = virt_to_phys(_text);
19056 - code_resource.end = virt_to_phys(_etext)-1;
19057 - data_resource.start = virt_to_phys(_etext);
19058 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19059 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19060 + data_resource.start = virt_to_phys(_sdata);
19061 data_resource.end = virt_to_phys(_edata)-1;
19062 bss_resource.start = virt_to_phys(&__bss_start);
19063 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19064 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19065 index 5cdff03..5810740 100644
19066 --- a/arch/x86/kernel/setup_percpu.c
19067 +++ b/arch/x86/kernel/setup_percpu.c
19068 @@ -21,19 +21,17 @@
19069 #include <asm/cpu.h>
19070 #include <asm/stackprotector.h>
19071
19072 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19073 +#ifdef CONFIG_SMP
19074 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19075 EXPORT_PER_CPU_SYMBOL(cpu_number);
19076 +#endif
19077
19078 -#ifdef CONFIG_X86_64
19079 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19080 -#else
19081 -#define BOOT_PERCPU_OFFSET 0
19082 -#endif
19083
19084 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19085 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19086
19087 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19088 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19089 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19090 };
19091 EXPORT_SYMBOL(__per_cpu_offset);
19092 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19093 {
19094 #ifdef CONFIG_X86_32
19095 struct desc_struct gdt;
19096 + unsigned long base = per_cpu_offset(cpu);
19097
19098 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19099 - 0x2 | DESCTYPE_S, 0x8);
19100 - gdt.s = 1;
19101 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19102 + 0x83 | DESCTYPE_S, 0xC);
19103 write_gdt_entry(get_cpu_gdt_table(cpu),
19104 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19105 #endif
19106 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19107 /* alrighty, percpu areas up and running */
19108 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19109 for_each_possible_cpu(cpu) {
19110 +#ifdef CONFIG_CC_STACKPROTECTOR
19111 +#ifdef CONFIG_X86_32
19112 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19113 +#endif
19114 +#endif
19115 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19116 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19117 per_cpu(cpu_number, cpu) = cpu;
19118 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19119 */
19120 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19121 #endif
19122 +#ifdef CONFIG_CC_STACKPROTECTOR
19123 +#ifdef CONFIG_X86_32
19124 + if (!cpu)
19125 + per_cpu(stack_canary.canary, cpu) = canary;
19126 +#endif
19127 +#endif
19128 /*
19129 * Up to this point, the boot CPU has been using .init.data
19130 * area. Reload any changed state for the boot CPU.
19131 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19132 index b280908..6de349e 100644
19133 --- a/arch/x86/kernel/signal.c
19134 +++ b/arch/x86/kernel/signal.c
19135 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19136 * Align the stack pointer according to the i386 ABI,
19137 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19138 */
19139 - sp = ((sp + 4) & -16ul) - 4;
19140 + sp = ((sp - 12) & -16ul) - 4;
19141 #else /* !CONFIG_X86_32 */
19142 sp = round_down(sp, 16) - 8;
19143 #endif
19144 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19145 * Return an always-bogus address instead so we will die with SIGSEGV.
19146 */
19147 if (onsigstack && !likely(on_sig_stack(sp)))
19148 - return (void __user *)-1L;
19149 + return (__force void __user *)-1L;
19150
19151 /* save i387 state */
19152 if (used_math() && save_i387_xstate(*fpstate) < 0)
19153 - return (void __user *)-1L;
19154 + return (__force void __user *)-1L;
19155
19156 return (void __user *)sp;
19157 }
19158 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19159 }
19160
19161 if (current->mm->context.vdso)
19162 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19163 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19164 else
19165 - restorer = &frame->retcode;
19166 + restorer = (void __user *)&frame->retcode;
19167 if (ka->sa.sa_flags & SA_RESTORER)
19168 restorer = ka->sa.sa_restorer;
19169
19170 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19171 * reasons and because gdb uses it as a signature to notice
19172 * signal handler stack frames.
19173 */
19174 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19175 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19176
19177 if (err)
19178 return -EFAULT;
19179 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19180 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19181
19182 /* Set up to return from userspace. */
19183 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19184 + if (current->mm->context.vdso)
19185 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19186 + else
19187 + restorer = (void __user *)&frame->retcode;
19188 if (ka->sa.sa_flags & SA_RESTORER)
19189 restorer = ka->sa.sa_restorer;
19190 put_user_ex(restorer, &frame->pretcode);
19191 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19192 * reasons and because gdb uses it as a signature to notice
19193 * signal handler stack frames.
19194 */
19195 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19196 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19197 } put_user_catch(err);
19198
19199 if (err)
19200 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19201 index 7c5a8c3..88d422f 100644
19202 --- a/arch/x86/kernel/smpboot.c
19203 +++ b/arch/x86/kernel/smpboot.c
19204 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19205 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19206 (THREAD_SIZE + task_stack_page(idle))) - 1);
19207 per_cpu(current_task, cpu) = idle;
19208 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19209
19210 #ifdef CONFIG_X86_32
19211 /* Stack for startup_32 can be just as for start_secondary onwards */
19212 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19213 #else
19214 clear_tsk_thread_flag(idle, TIF_FORK);
19215 initial_gs = per_cpu_offset(cpu);
19216 - per_cpu(kernel_stack, cpu) =
19217 - (unsigned long)task_stack_page(idle) -
19218 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19219 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19220 #endif
19221 +
19222 + pax_open_kernel();
19223 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19224 + pax_close_kernel();
19225 +
19226 initial_code = (unsigned long)start_secondary;
19227 stack_start = idle->thread.sp;
19228
19229 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19230
19231 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19232
19233 +#ifdef CONFIG_PAX_PER_CPU_PGD
19234 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19235 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19236 + KERNEL_PGD_PTRS);
19237 +#endif
19238 +
19239 err = do_boot_cpu(apicid, cpu, tidle);
19240 if (err) {
19241 pr_debug("do_boot_cpu failed %d\n", err);
19242 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19243 index c346d11..d43b163 100644
19244 --- a/arch/x86/kernel/step.c
19245 +++ b/arch/x86/kernel/step.c
19246 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19247 struct desc_struct *desc;
19248 unsigned long base;
19249
19250 - seg &= ~7UL;
19251 + seg >>= 3;
19252
19253 mutex_lock(&child->mm->context.lock);
19254 - if (unlikely((seg >> 3) >= child->mm->context.size))
19255 + if (unlikely(seg >= child->mm->context.size))
19256 addr = -1L; /* bogus selector, access would fault */
19257 else {
19258 desc = child->mm->context.ldt + seg;
19259 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19260 addr += base;
19261 }
19262 mutex_unlock(&child->mm->context.lock);
19263 - }
19264 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19265 + addr = ktla_ktva(addr);
19266
19267 return addr;
19268 }
19269 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19270 unsigned char opcode[15];
19271 unsigned long addr = convert_ip_to_linear(child, regs);
19272
19273 + if (addr == -EINVAL)
19274 + return 0;
19275 +
19276 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19277 for (i = 0; i < copied; i++) {
19278 switch (opcode[i]) {
19279 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19280 index 0b0cb5f..db6b9ed 100644
19281 --- a/arch/x86/kernel/sys_i386_32.c
19282 +++ b/arch/x86/kernel/sys_i386_32.c
19283 @@ -24,17 +24,224 @@
19284
19285 #include <asm/syscalls.h>
19286
19287 -/*
19288 - * Do a system call from kernel instead of calling sys_execve so we
19289 - * end up with proper pt_regs.
19290 - */
19291 -int kernel_execve(const char *filename,
19292 - const char *const argv[],
19293 - const char *const envp[])
19294 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19295 {
19296 - long __res;
19297 - asm volatile ("int $0x80"
19298 - : "=a" (__res)
19299 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19300 - return __res;
19301 + unsigned long pax_task_size = TASK_SIZE;
19302 +
19303 +#ifdef CONFIG_PAX_SEGMEXEC
19304 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19305 + pax_task_size = SEGMEXEC_TASK_SIZE;
19306 +#endif
19307 +
19308 + if (len > pax_task_size || addr > pax_task_size - len)
19309 + return -EINVAL;
19310 +
19311 + return 0;
19312 +}
19313 +
19314 +unsigned long
19315 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19316 + unsigned long len, unsigned long pgoff, unsigned long flags)
19317 +{
19318 + struct mm_struct *mm = current->mm;
19319 + struct vm_area_struct *vma;
19320 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19321 +
19322 +#ifdef CONFIG_PAX_SEGMEXEC
19323 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19324 + pax_task_size = SEGMEXEC_TASK_SIZE;
19325 +#endif
19326 +
19327 + pax_task_size -= PAGE_SIZE;
19328 +
19329 + if (len > pax_task_size)
19330 + return -ENOMEM;
19331 +
19332 + if (flags & MAP_FIXED)
19333 + return addr;
19334 +
19335 +#ifdef CONFIG_PAX_RANDMMAP
19336 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19337 +#endif
19338 +
19339 + if (addr) {
19340 + addr = PAGE_ALIGN(addr);
19341 + if (pax_task_size - len >= addr) {
19342 + vma = find_vma(mm, addr);
19343 + if (check_heap_stack_gap(vma, addr, len))
19344 + return addr;
19345 + }
19346 + }
19347 + if (len > mm->cached_hole_size) {
19348 + start_addr = addr = mm->free_area_cache;
19349 + } else {
19350 + start_addr = addr = mm->mmap_base;
19351 + mm->cached_hole_size = 0;
19352 + }
19353 +
19354 +#ifdef CONFIG_PAX_PAGEEXEC
19355 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19356 + start_addr = 0x00110000UL;
19357 +
19358 +#ifdef CONFIG_PAX_RANDMMAP
19359 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19360 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19361 +#endif
19362 +
19363 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19364 + start_addr = addr = mm->mmap_base;
19365 + else
19366 + addr = start_addr;
19367 + }
19368 +#endif
19369 +
19370 +full_search:
19371 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19372 + /* At this point: (!vma || addr < vma->vm_end). */
19373 + if (pax_task_size - len < addr) {
19374 + /*
19375 + * Start a new search - just in case we missed
19376 + * some holes.
19377 + */
19378 + if (start_addr != mm->mmap_base) {
19379 + start_addr = addr = mm->mmap_base;
19380 + mm->cached_hole_size = 0;
19381 + goto full_search;
19382 + }
19383 + return -ENOMEM;
19384 + }
19385 + if (check_heap_stack_gap(vma, addr, len))
19386 + break;
19387 + if (addr + mm->cached_hole_size < vma->vm_start)
19388 + mm->cached_hole_size = vma->vm_start - addr;
19389 + addr = vma->vm_end;
19390 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19391 + start_addr = addr = mm->mmap_base;
19392 + mm->cached_hole_size = 0;
19393 + goto full_search;
19394 + }
19395 + }
19396 +
19397 + /*
19398 + * Remember the place where we stopped the search:
19399 + */
19400 + mm->free_area_cache = addr + len;
19401 + return addr;
19402 +}
19403 +
19404 +unsigned long
19405 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19406 + const unsigned long len, const unsigned long pgoff,
19407 + const unsigned long flags)
19408 +{
19409 + struct vm_area_struct *vma;
19410 + struct mm_struct *mm = current->mm;
19411 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19412 +
19413 +#ifdef CONFIG_PAX_SEGMEXEC
19414 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19415 + pax_task_size = SEGMEXEC_TASK_SIZE;
19416 +#endif
19417 +
19418 + pax_task_size -= PAGE_SIZE;
19419 +
19420 + /* requested length too big for entire address space */
19421 + if (len > pax_task_size)
19422 + return -ENOMEM;
19423 +
19424 + if (flags & MAP_FIXED)
19425 + return addr;
19426 +
19427 +#ifdef CONFIG_PAX_PAGEEXEC
19428 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19429 + goto bottomup;
19430 +#endif
19431 +
19432 +#ifdef CONFIG_PAX_RANDMMAP
19433 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19434 +#endif
19435 +
19436 + /* requesting a specific address */
19437 + if (addr) {
19438 + addr = PAGE_ALIGN(addr);
19439 + if (pax_task_size - len >= addr) {
19440 + vma = find_vma(mm, addr);
19441 + if (check_heap_stack_gap(vma, addr, len))
19442 + return addr;
19443 + }
19444 + }
19445 +
19446 + /* check if free_area_cache is useful for us */
19447 + if (len <= mm->cached_hole_size) {
19448 + mm->cached_hole_size = 0;
19449 + mm->free_area_cache = mm->mmap_base;
19450 + }
19451 +
19452 + /* either no address requested or can't fit in requested address hole */
19453 + addr = mm->free_area_cache;
19454 +
19455 + /* make sure it can fit in the remaining address space */
19456 + if (addr > len) {
19457 + vma = find_vma(mm, addr-len);
19458 + if (check_heap_stack_gap(vma, addr - len, len))
19459 + /* remember the address as a hint for next time */
19460 + return (mm->free_area_cache = addr-len);
19461 + }
19462 +
19463 + if (mm->mmap_base < len)
19464 + goto bottomup;
19465 +
19466 + addr = mm->mmap_base-len;
19467 +
19468 + do {
19469 + /*
19470 + * Lookup failure means no vma is above this address,
19471 + * else if new region fits below vma->vm_start,
19472 + * return with success:
19473 + */
19474 + vma = find_vma(mm, addr);
19475 + if (check_heap_stack_gap(vma, addr, len))
19476 + /* remember the address as a hint for next time */
19477 + return (mm->free_area_cache = addr);
19478 +
19479 + /* remember the largest hole we saw so far */
19480 + if (addr + mm->cached_hole_size < vma->vm_start)
19481 + mm->cached_hole_size = vma->vm_start - addr;
19482 +
19483 + /* try just below the current vma->vm_start */
19484 + addr = skip_heap_stack_gap(vma, len);
19485 + } while (!IS_ERR_VALUE(addr));
19486 +
19487 +bottomup:
19488 + /*
19489 + * A failed mmap() very likely causes application failure,
19490 + * so fall back to the bottom-up function here. This scenario
19491 + * can happen with large stack limits and large mmap()
19492 + * allocations.
19493 + */
19494 +
19495 +#ifdef CONFIG_PAX_SEGMEXEC
19496 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19497 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19498 + else
19499 +#endif
19500 +
19501 + mm->mmap_base = TASK_UNMAPPED_BASE;
19502 +
19503 +#ifdef CONFIG_PAX_RANDMMAP
19504 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19505 + mm->mmap_base += mm->delta_mmap;
19506 +#endif
19507 +
19508 + mm->free_area_cache = mm->mmap_base;
19509 + mm->cached_hole_size = ~0UL;
19510 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19511 + /*
19512 + * Restore the topdown base:
19513 + */
19514 + mm->mmap_base = base;
19515 + mm->free_area_cache = base;
19516 + mm->cached_hole_size = ~0UL;
19517 +
19518 + return addr;
19519 }
19520 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19521 index b4d3c39..82bb73b 100644
19522 --- a/arch/x86/kernel/sys_x86_64.c
19523 +++ b/arch/x86/kernel/sys_x86_64.c
19524 @@ -95,8 +95,8 @@ out:
19525 return error;
19526 }
19527
19528 -static void find_start_end(unsigned long flags, unsigned long *begin,
19529 - unsigned long *end)
19530 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19531 + unsigned long *begin, unsigned long *end)
19532 {
19533 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19534 unsigned long new_begin;
19535 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19536 *begin = new_begin;
19537 }
19538 } else {
19539 - *begin = TASK_UNMAPPED_BASE;
19540 + *begin = mm->mmap_base;
19541 *end = TASK_SIZE;
19542 }
19543 }
19544 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19545 if (flags & MAP_FIXED)
19546 return addr;
19547
19548 - find_start_end(flags, &begin, &end);
19549 + find_start_end(mm, flags, &begin, &end);
19550
19551 if (len > end)
19552 return -ENOMEM;
19553
19554 +#ifdef CONFIG_PAX_RANDMMAP
19555 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19556 +#endif
19557 +
19558 if (addr) {
19559 addr = PAGE_ALIGN(addr);
19560 vma = find_vma(mm, addr);
19561 - if (end - len >= addr &&
19562 - (!vma || addr + len <= vma->vm_start))
19563 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19564 return addr;
19565 }
19566 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19567 @@ -172,7 +175,7 @@ full_search:
19568 }
19569 return -ENOMEM;
19570 }
19571 - if (!vma || addr + len <= vma->vm_start) {
19572 + if (check_heap_stack_gap(vma, addr, len)) {
19573 /*
19574 * Remember the place where we stopped the search:
19575 */
19576 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19577 {
19578 struct vm_area_struct *vma;
19579 struct mm_struct *mm = current->mm;
19580 - unsigned long addr = addr0, start_addr;
19581 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19582
19583 /* requested length too big for entire address space */
19584 if (len > TASK_SIZE)
19585 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19586 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19587 goto bottomup;
19588
19589 +#ifdef CONFIG_PAX_RANDMMAP
19590 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19591 +#endif
19592 +
19593 /* requesting a specific address */
19594 if (addr) {
19595 addr = PAGE_ALIGN(addr);
19596 - vma = find_vma(mm, addr);
19597 - if (TASK_SIZE - len >= addr &&
19598 - (!vma || addr + len <= vma->vm_start))
19599 - return addr;
19600 + if (TASK_SIZE - len >= addr) {
19601 + vma = find_vma(mm, addr);
19602 + if (check_heap_stack_gap(vma, addr, len))
19603 + return addr;
19604 + }
19605 }
19606
19607 /* check if free_area_cache is useful for us */
19608 @@ -240,7 +248,7 @@ try_again:
19609 * return with success:
19610 */
19611 vma = find_vma(mm, addr);
19612 - if (!vma || addr+len <= vma->vm_start)
19613 + if (check_heap_stack_gap(vma, addr, len))
19614 /* remember the address as a hint for next time */
19615 return mm->free_area_cache = addr;
19616
19617 @@ -249,8 +257,8 @@ try_again:
19618 mm->cached_hole_size = vma->vm_start - addr;
19619
19620 /* try just below the current vma->vm_start */
19621 - addr = vma->vm_start-len;
19622 - } while (len < vma->vm_start);
19623 + addr = skip_heap_stack_gap(vma, len);
19624 + } while (!IS_ERR_VALUE(addr));
19625
19626 fail:
19627 /*
19628 @@ -270,13 +278,21 @@ bottomup:
19629 * can happen with large stack limits and large mmap()
19630 * allocations.
19631 */
19632 + mm->mmap_base = TASK_UNMAPPED_BASE;
19633 +
19634 +#ifdef CONFIG_PAX_RANDMMAP
19635 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19636 + mm->mmap_base += mm->delta_mmap;
19637 +#endif
19638 +
19639 + mm->free_area_cache = mm->mmap_base;
19640 mm->cached_hole_size = ~0UL;
19641 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19642 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19643 /*
19644 * Restore the topdown base:
19645 */
19646 - mm->free_area_cache = mm->mmap_base;
19647 + mm->mmap_base = base;
19648 + mm->free_area_cache = base;
19649 mm->cached_hole_size = ~0UL;
19650
19651 return addr;
19652 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19653 index f84fe00..93fe08f 100644
19654 --- a/arch/x86/kernel/tboot.c
19655 +++ b/arch/x86/kernel/tboot.c
19656 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19657
19658 void tboot_shutdown(u32 shutdown_type)
19659 {
19660 - void (*shutdown)(void);
19661 + void (* __noreturn shutdown)(void);
19662
19663 if (!tboot_enabled())
19664 return;
19665 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19666
19667 switch_to_tboot_pt();
19668
19669 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19670 + shutdown = (void *)tboot->shutdown_entry;
19671 shutdown();
19672
19673 /* should not reach here */
19674 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19675 return 0;
19676 }
19677
19678 -static atomic_t ap_wfs_count;
19679 +static atomic_unchecked_t ap_wfs_count;
19680
19681 static int tboot_wait_for_aps(int num_aps)
19682 {
19683 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19684 {
19685 switch (action) {
19686 case CPU_DYING:
19687 - atomic_inc(&ap_wfs_count);
19688 + atomic_inc_unchecked(&ap_wfs_count);
19689 if (num_online_cpus() == 1)
19690 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19691 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19692 return NOTIFY_BAD;
19693 break;
19694 }
19695 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19696
19697 tboot_create_trampoline();
19698
19699 - atomic_set(&ap_wfs_count, 0);
19700 + atomic_set_unchecked(&ap_wfs_count, 0);
19701 register_hotcpu_notifier(&tboot_cpu_notifier);
19702
19703 acpi_os_set_prepare_sleep(&tboot_sleep);
19704 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19705 index 24d3c91..d06b473 100644
19706 --- a/arch/x86/kernel/time.c
19707 +++ b/arch/x86/kernel/time.c
19708 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19709 {
19710 unsigned long pc = instruction_pointer(regs);
19711
19712 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19713 + if (!user_mode(regs) && in_lock_functions(pc)) {
19714 #ifdef CONFIG_FRAME_POINTER
19715 - return *(unsigned long *)(regs->bp + sizeof(long));
19716 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19717 #else
19718 unsigned long *sp =
19719 (unsigned long *)kernel_stack_pointer(regs);
19720 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19721 * or above a saved flags. Eflags has bits 22-31 zero,
19722 * kernel addresses don't.
19723 */
19724 +
19725 +#ifdef CONFIG_PAX_KERNEXEC
19726 + return ktla_ktva(sp[0]);
19727 +#else
19728 if (sp[0] >> 22)
19729 return sp[0];
19730 if (sp[1] >> 22)
19731 return sp[1];
19732 #endif
19733 +
19734 +#endif
19735 }
19736 return pc;
19737 }
19738 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19739 index 9d9d2f9..cad418a 100644
19740 --- a/arch/x86/kernel/tls.c
19741 +++ b/arch/x86/kernel/tls.c
19742 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19743 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19744 return -EINVAL;
19745
19746 +#ifdef CONFIG_PAX_SEGMEXEC
19747 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19748 + return -EINVAL;
19749 +#endif
19750 +
19751 set_tls_desc(p, idx, &info, 1);
19752
19753 return 0;
19754 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19755
19756 if (kbuf)
19757 info = kbuf;
19758 - else if (__copy_from_user(infobuf, ubuf, count))
19759 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19760 return -EFAULT;
19761 else
19762 info = infobuf;
19763 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19764 index b481341..5918bbe 100644
19765 --- a/arch/x86/kernel/traps.c
19766 +++ b/arch/x86/kernel/traps.c
19767 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19768
19769 /* Do we ignore FPU interrupts ? */
19770 char ignore_fpu_irq;
19771 -
19772 -/*
19773 - * The IDT has to be page-aligned to simplify the Pentium
19774 - * F0 0F bug workaround.
19775 - */
19776 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19777 #endif
19778
19779 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19780 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19781 }
19782
19783 static void __kprobes
19784 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19785 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19786 long error_code, siginfo_t *info)
19787 {
19788 struct task_struct *tsk = current;
19789
19790 #ifdef CONFIG_X86_32
19791 - if (regs->flags & X86_VM_MASK) {
19792 + if (v8086_mode(regs)) {
19793 /*
19794 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19795 * On nmi (interrupt 2), do_trap should not be called.
19796 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19797 }
19798 #endif
19799
19800 - if (!user_mode(regs))
19801 + if (!user_mode_novm(regs))
19802 goto kernel_trap;
19803
19804 #ifdef CONFIG_X86_32
19805 @@ -147,7 +141,7 @@ trap_signal:
19806 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19807 printk_ratelimit()) {
19808 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19809 - tsk->comm, tsk->pid, str,
19810 + tsk->comm, task_pid_nr(tsk), str,
19811 regs->ip, regs->sp, error_code);
19812 print_vma_addr(" in ", regs->ip);
19813 pr_cont("\n");
19814 @@ -164,8 +158,20 @@ kernel_trap:
19815 if (!fixup_exception(regs)) {
19816 tsk->thread.error_code = error_code;
19817 tsk->thread.trap_nr = trapnr;
19818 +
19819 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19820 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19821 + str = "PAX: suspicious stack segment fault";
19822 +#endif
19823 +
19824 die(str, regs, error_code);
19825 }
19826 +
19827 +#ifdef CONFIG_PAX_REFCOUNT
19828 + if (trapnr == 4)
19829 + pax_report_refcount_overflow(regs);
19830 +#endif
19831 +
19832 return;
19833
19834 #ifdef CONFIG_X86_32
19835 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19836 conditional_sti(regs);
19837
19838 #ifdef CONFIG_X86_32
19839 - if (regs->flags & X86_VM_MASK)
19840 + if (v8086_mode(regs))
19841 goto gp_in_vm86;
19842 #endif
19843
19844 tsk = current;
19845 - if (!user_mode(regs))
19846 + if (!user_mode_novm(regs))
19847 goto gp_in_kernel;
19848
19849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19850 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19851 + struct mm_struct *mm = tsk->mm;
19852 + unsigned long limit;
19853 +
19854 + down_write(&mm->mmap_sem);
19855 + limit = mm->context.user_cs_limit;
19856 + if (limit < TASK_SIZE) {
19857 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19858 + up_write(&mm->mmap_sem);
19859 + return;
19860 + }
19861 + up_write(&mm->mmap_sem);
19862 + }
19863 +#endif
19864 +
19865 tsk->thread.error_code = error_code;
19866 tsk->thread.trap_nr = X86_TRAP_GP;
19867
19868 @@ -297,6 +319,13 @@ gp_in_kernel:
19869 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19870 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19871 return;
19872 +
19873 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19874 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19875 + die("PAX: suspicious general protection fault", regs, error_code);
19876 + else
19877 +#endif
19878 +
19879 die("general protection fault", regs, error_code);
19880 }
19881
19882 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19883 /* It's safe to allow irq's after DR6 has been saved */
19884 preempt_conditional_sti(regs);
19885
19886 - if (regs->flags & X86_VM_MASK) {
19887 + if (v8086_mode(regs)) {
19888 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19889 X86_TRAP_DB);
19890 preempt_conditional_cli(regs);
19891 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19892 * We already checked v86 mode above, so we can check for kernel mode
19893 * by just checking the CPL of CS.
19894 */
19895 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19896 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19897 tsk->thread.debugreg6 &= ~DR_STEP;
19898 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19899 regs->flags &= ~X86_EFLAGS_TF;
19900 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19901 return;
19902 conditional_sti(regs);
19903
19904 - if (!user_mode_vm(regs))
19905 + if (!user_mode(regs))
19906 {
19907 if (!fixup_exception(regs)) {
19908 task->thread.error_code = error_code;
19909 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19910 index 36fd420..7e5892d 100644
19911 --- a/arch/x86/kernel/uprobes.c
19912 +++ b/arch/x86/kernel/uprobes.c
19913 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19914 int ret = NOTIFY_DONE;
19915
19916 /* We are only interested in userspace traps */
19917 - if (regs && !user_mode_vm(regs))
19918 + if (regs && !user_mode(regs))
19919 return NOTIFY_DONE;
19920
19921 switch (val) {
19922 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19923 index b9242ba..50c5edd 100644
19924 --- a/arch/x86/kernel/verify_cpu.S
19925 +++ b/arch/x86/kernel/verify_cpu.S
19926 @@ -20,6 +20,7 @@
19927 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19928 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19929 * arch/x86/kernel/head_32.S: processor startup
19930 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19931 *
19932 * verify_cpu, returns the status of longmode and SSE in register %eax.
19933 * 0: Success 1: Failure
19934 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19935 index 54abcc0..eb6c848 100644
19936 --- a/arch/x86/kernel/vm86_32.c
19937 +++ b/arch/x86/kernel/vm86_32.c
19938 @@ -43,6 +43,7 @@
19939 #include <linux/ptrace.h>
19940 #include <linux/audit.h>
19941 #include <linux/stddef.h>
19942 +#include <linux/grsecurity.h>
19943
19944 #include <asm/uaccess.h>
19945 #include <asm/io.h>
19946 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19947 do_exit(SIGSEGV);
19948 }
19949
19950 - tss = &per_cpu(init_tss, get_cpu());
19951 + tss = init_tss + get_cpu();
19952 current->thread.sp0 = current->thread.saved_sp0;
19953 current->thread.sysenter_cs = __KERNEL_CS;
19954 load_sp0(tss, &current->thread);
19955 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19956 struct task_struct *tsk;
19957 int tmp, ret = -EPERM;
19958
19959 +#ifdef CONFIG_GRKERNSEC_VM86
19960 + if (!capable(CAP_SYS_RAWIO)) {
19961 + gr_handle_vm86();
19962 + goto out;
19963 + }
19964 +#endif
19965 +
19966 tsk = current;
19967 if (tsk->thread.saved_sp0)
19968 goto out;
19969 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19970 int tmp, ret;
19971 struct vm86plus_struct __user *v86;
19972
19973 +#ifdef CONFIG_GRKERNSEC_VM86
19974 + if (!capable(CAP_SYS_RAWIO)) {
19975 + gr_handle_vm86();
19976 + ret = -EPERM;
19977 + goto out;
19978 + }
19979 +#endif
19980 +
19981 tsk = current;
19982 switch (cmd) {
19983 case VM86_REQUEST_IRQ:
19984 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19985 tsk->thread.saved_fs = info->regs32->fs;
19986 tsk->thread.saved_gs = get_user_gs(info->regs32);
19987
19988 - tss = &per_cpu(init_tss, get_cpu());
19989 + tss = init_tss + get_cpu();
19990 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19991 if (cpu_has_sep)
19992 tsk->thread.sysenter_cs = 0;
19993 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19994 goto cannot_handle;
19995 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19996 goto cannot_handle;
19997 - intr_ptr = (unsigned long __user *) (i << 2);
19998 + intr_ptr = (__force unsigned long __user *) (i << 2);
19999 if (get_user(segoffs, intr_ptr))
20000 goto cannot_handle;
20001 if ((segoffs >> 16) == BIOSSEG)
20002 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20003 index 22a1530..8fbaaad 100644
20004 --- a/arch/x86/kernel/vmlinux.lds.S
20005 +++ b/arch/x86/kernel/vmlinux.lds.S
20006 @@ -26,6 +26,13 @@
20007 #include <asm/page_types.h>
20008 #include <asm/cache.h>
20009 #include <asm/boot.h>
20010 +#include <asm/segment.h>
20011 +
20012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20013 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20014 +#else
20015 +#define __KERNEL_TEXT_OFFSET 0
20016 +#endif
20017
20018 #undef i386 /* in case the preprocessor is a 32bit one */
20019
20020 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20021
20022 PHDRS {
20023 text PT_LOAD FLAGS(5); /* R_E */
20024 +#ifdef CONFIG_X86_32
20025 + module PT_LOAD FLAGS(5); /* R_E */
20026 +#endif
20027 +#ifdef CONFIG_XEN
20028 + rodata PT_LOAD FLAGS(5); /* R_E */
20029 +#else
20030 + rodata PT_LOAD FLAGS(4); /* R__ */
20031 +#endif
20032 data PT_LOAD FLAGS(6); /* RW_ */
20033 -#ifdef CONFIG_X86_64
20034 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20035 #ifdef CONFIG_SMP
20036 percpu PT_LOAD FLAGS(6); /* RW_ */
20037 #endif
20038 + text.init PT_LOAD FLAGS(5); /* R_E */
20039 + text.exit PT_LOAD FLAGS(5); /* R_E */
20040 init PT_LOAD FLAGS(7); /* RWE */
20041 -#endif
20042 note PT_NOTE FLAGS(0); /* ___ */
20043 }
20044
20045 SECTIONS
20046 {
20047 #ifdef CONFIG_X86_32
20048 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20049 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20050 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20051 #else
20052 - . = __START_KERNEL;
20053 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20054 + . = __START_KERNEL;
20055 #endif
20056
20057 /* Text and read-only data */
20058 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20059 - _text = .;
20060 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20061 /* bootstrapping code */
20062 +#ifdef CONFIG_X86_32
20063 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20064 +#else
20065 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20066 +#endif
20067 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20068 + _text = .;
20069 HEAD_TEXT
20070 #ifdef CONFIG_X86_32
20071 . = ALIGN(PAGE_SIZE);
20072 @@ -108,13 +128,48 @@ SECTIONS
20073 IRQENTRY_TEXT
20074 *(.fixup)
20075 *(.gnu.warning)
20076 - /* End of text section */
20077 - _etext = .;
20078 } :text = 0x9090
20079
20080 - NOTES :text :note
20081 + . += __KERNEL_TEXT_OFFSET;
20082
20083 - EXCEPTION_TABLE(16) :text = 0x9090
20084 +#ifdef CONFIG_X86_32
20085 + . = ALIGN(PAGE_SIZE);
20086 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20087 +
20088 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20089 + MODULES_EXEC_VADDR = .;
20090 + BYTE(0)
20091 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20092 + . = ALIGN(HPAGE_SIZE) - 1;
20093 + MODULES_EXEC_END = .;
20094 +#endif
20095 +
20096 + } :module
20097 +#endif
20098 +
20099 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20100 + /* End of text section */
20101 + BYTE(0)
20102 + _etext = . - __KERNEL_TEXT_OFFSET;
20103 + }
20104 +
20105 +#ifdef CONFIG_X86_32
20106 + . = ALIGN(PAGE_SIZE);
20107 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20108 + *(.idt)
20109 + . = ALIGN(PAGE_SIZE);
20110 + *(.empty_zero_page)
20111 + *(.initial_pg_fixmap)
20112 + *(.initial_pg_pmd)
20113 + *(.initial_page_table)
20114 + *(.swapper_pg_dir)
20115 + } :rodata
20116 +#endif
20117 +
20118 + . = ALIGN(PAGE_SIZE);
20119 + NOTES :rodata :note
20120 +
20121 + EXCEPTION_TABLE(16) :rodata
20122
20123 #if defined(CONFIG_DEBUG_RODATA)
20124 /* .text should occupy whole number of pages */
20125 @@ -126,16 +181,20 @@ SECTIONS
20126
20127 /* Data */
20128 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20129 +
20130 +#ifdef CONFIG_PAX_KERNEXEC
20131 + . = ALIGN(HPAGE_SIZE);
20132 +#else
20133 + . = ALIGN(PAGE_SIZE);
20134 +#endif
20135 +
20136 /* Start of data section */
20137 _sdata = .;
20138
20139 /* init_task */
20140 INIT_TASK_DATA(THREAD_SIZE)
20141
20142 -#ifdef CONFIG_X86_32
20143 - /* 32 bit has nosave before _edata */
20144 NOSAVE_DATA
20145 -#endif
20146
20147 PAGE_ALIGNED_DATA(PAGE_SIZE)
20148
20149 @@ -176,12 +235,19 @@ SECTIONS
20150 #endif /* CONFIG_X86_64 */
20151
20152 /* Init code and data - will be freed after init */
20153 - . = ALIGN(PAGE_SIZE);
20154 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20155 + BYTE(0)
20156 +
20157 +#ifdef CONFIG_PAX_KERNEXEC
20158 + . = ALIGN(HPAGE_SIZE);
20159 +#else
20160 + . = ALIGN(PAGE_SIZE);
20161 +#endif
20162 +
20163 __init_begin = .; /* paired with __init_end */
20164 - }
20165 + } :init.begin
20166
20167 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20168 +#ifdef CONFIG_SMP
20169 /*
20170 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20171 * output PHDR, so the next output section - .init.text - should
20172 @@ -190,12 +256,27 @@ SECTIONS
20173 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20174 #endif
20175
20176 - INIT_TEXT_SECTION(PAGE_SIZE)
20177 -#ifdef CONFIG_X86_64
20178 - :init
20179 -#endif
20180 + . = ALIGN(PAGE_SIZE);
20181 + init_begin = .;
20182 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20183 + VMLINUX_SYMBOL(_sinittext) = .;
20184 + INIT_TEXT
20185 + VMLINUX_SYMBOL(_einittext) = .;
20186 + . = ALIGN(PAGE_SIZE);
20187 + } :text.init
20188
20189 - INIT_DATA_SECTION(16)
20190 + /*
20191 + * .exit.text is discard at runtime, not link time, to deal with
20192 + * references from .altinstructions and .eh_frame
20193 + */
20194 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20195 + EXIT_TEXT
20196 + . = ALIGN(16);
20197 + } :text.exit
20198 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20199 +
20200 + . = ALIGN(PAGE_SIZE);
20201 + INIT_DATA_SECTION(16) :init
20202
20203 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20204 __x86_cpu_dev_start = .;
20205 @@ -257,19 +338,12 @@ SECTIONS
20206 }
20207
20208 . = ALIGN(8);
20209 - /*
20210 - * .exit.text is discard at runtime, not link time, to deal with
20211 - * references from .altinstructions and .eh_frame
20212 - */
20213 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20214 - EXIT_TEXT
20215 - }
20216
20217 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20218 EXIT_DATA
20219 }
20220
20221 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20222 +#ifndef CONFIG_SMP
20223 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20224 #endif
20225
20226 @@ -288,16 +362,10 @@ SECTIONS
20227 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20228 __smp_locks = .;
20229 *(.smp_locks)
20230 - . = ALIGN(PAGE_SIZE);
20231 __smp_locks_end = .;
20232 + . = ALIGN(PAGE_SIZE);
20233 }
20234
20235 -#ifdef CONFIG_X86_64
20236 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20237 - NOSAVE_DATA
20238 - }
20239 -#endif
20240 -
20241 /* BSS */
20242 . = ALIGN(PAGE_SIZE);
20243 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20244 @@ -313,6 +381,7 @@ SECTIONS
20245 __brk_base = .;
20246 . += 64 * 1024; /* 64k alignment slop space */
20247 *(.brk_reservation) /* areas brk users have reserved */
20248 + . = ALIGN(HPAGE_SIZE);
20249 __brk_limit = .;
20250 }
20251
20252 @@ -339,13 +408,12 @@ SECTIONS
20253 * for the boot processor.
20254 */
20255 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20256 -INIT_PER_CPU(gdt_page);
20257 INIT_PER_CPU(irq_stack_union);
20258
20259 /*
20260 * Build-time check on the image size:
20261 */
20262 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20263 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20264 "kernel image bigger than KERNEL_IMAGE_SIZE");
20265
20266 #ifdef CONFIG_SMP
20267 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20268 index 992f890..fc38904 100644
20269 --- a/arch/x86/kernel/vsmp_64.c
20270 +++ b/arch/x86/kernel/vsmp_64.c
20271 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20272 static void vsmp_apic_post_init(void)
20273 {
20274 /* need to update phys_pkg_id */
20275 - apic->phys_pkg_id = apicid_phys_pkg_id;
20276 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20277 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20278 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20279 }
20280
20281 void __init vsmp_init(void)
20282 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20283 index 8d141b3..40a0fe4 100644
20284 --- a/arch/x86/kernel/vsyscall_64.c
20285 +++ b/arch/x86/kernel/vsyscall_64.c
20286 @@ -56,15 +56,13 @@
20287 DEFINE_VVAR(int, vgetcpu_mode);
20288 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20289
20290 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20291 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20292
20293 static int __init vsyscall_setup(char *str)
20294 {
20295 if (str) {
20296 if (!strcmp("emulate", str))
20297 vsyscall_mode = EMULATE;
20298 - else if (!strcmp("native", str))
20299 - vsyscall_mode = NATIVE;
20300 else if (!strcmp("none", str))
20301 vsyscall_mode = NONE;
20302 else
20303 @@ -306,8 +304,7 @@ done:
20304 return true;
20305
20306 sigsegv:
20307 - force_sig(SIGSEGV, current);
20308 - return true;
20309 + do_group_exit(SIGKILL);
20310 }
20311
20312 /*
20313 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20314 extern char __vvar_page;
20315 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20316
20317 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20318 - vsyscall_mode == NATIVE
20319 - ? PAGE_KERNEL_VSYSCALL
20320 - : PAGE_KERNEL_VVAR);
20321 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20322 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20323 (unsigned long)VSYSCALL_START);
20324
20325 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20326 index 6020f6f..bedd6e3 100644
20327 --- a/arch/x86/kernel/x8664_ksyms_64.c
20328 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20329 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20330 EXPORT_SYMBOL(copy_user_generic_unrolled);
20331 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20332 EXPORT_SYMBOL(__copy_user_nocache);
20333 -EXPORT_SYMBOL(_copy_from_user);
20334 -EXPORT_SYMBOL(_copy_to_user);
20335
20336 EXPORT_SYMBOL(copy_page);
20337 EXPORT_SYMBOL(clear_page);
20338 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20339 index 3d3e207..1a73ab2 100644
20340 --- a/arch/x86/kernel/xsave.c
20341 +++ b/arch/x86/kernel/xsave.c
20342 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20343 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20344 return -EINVAL;
20345
20346 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20347 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20348 fx_sw_user->extended_size -
20349 FP_XSTATE_MAGIC2_SIZE));
20350 if (err)
20351 @@ -268,7 +268,7 @@ fx_only:
20352 * the other extended state.
20353 */
20354 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20355 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20356 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20357 }
20358
20359 /*
20360 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20361 if (use_xsave())
20362 err = restore_user_xstate(buf);
20363 else
20364 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20365 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20366 buf);
20367 if (unlikely(err)) {
20368 /*
20369 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20370 index 0595f13..b544fa3 100644
20371 --- a/arch/x86/kvm/cpuid.c
20372 +++ b/arch/x86/kvm/cpuid.c
20373 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20374 struct kvm_cpuid2 *cpuid,
20375 struct kvm_cpuid_entry2 __user *entries)
20376 {
20377 - int r;
20378 + int r, i;
20379
20380 r = -E2BIG;
20381 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20382 goto out;
20383 r = -EFAULT;
20384 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20385 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20386 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20387 goto out;
20388 + for (i = 0; i < cpuid->nent; ++i) {
20389 + struct kvm_cpuid_entry2 cpuid_entry;
20390 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20391 + goto out;
20392 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20393 + }
20394 vcpu->arch.cpuid_nent = cpuid->nent;
20395 kvm_apic_set_version(vcpu);
20396 kvm_x86_ops->cpuid_update(vcpu);
20397 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20398 struct kvm_cpuid2 *cpuid,
20399 struct kvm_cpuid_entry2 __user *entries)
20400 {
20401 - int r;
20402 + int r, i;
20403
20404 r = -E2BIG;
20405 if (cpuid->nent < vcpu->arch.cpuid_nent)
20406 goto out;
20407 r = -EFAULT;
20408 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20409 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20410 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20411 goto out;
20412 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20413 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20414 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20415 + goto out;
20416 + }
20417 return 0;
20418
20419 out:
20420 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20421 index a3b57a2..ebbe732 100644
20422 --- a/arch/x86/kvm/emulate.c
20423 +++ b/arch/x86/kvm/emulate.c
20424 @@ -256,6 +256,7 @@ struct gprefix {
20425
20426 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20427 do { \
20428 + unsigned long _tmp; \
20429 __asm__ __volatile__ ( \
20430 _PRE_EFLAGS("0", "4", "2") \
20431 _op _suffix " %"_x"3,%1; " \
20432 @@ -270,8 +271,6 @@ struct gprefix {
20433 /* Raw emulation: instruction has two explicit operands. */
20434 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20435 do { \
20436 - unsigned long _tmp; \
20437 - \
20438 switch ((ctxt)->dst.bytes) { \
20439 case 2: \
20440 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20441 @@ -287,7 +286,6 @@ struct gprefix {
20442
20443 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20444 do { \
20445 - unsigned long _tmp; \
20446 switch ((ctxt)->dst.bytes) { \
20447 case 1: \
20448 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20449 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20450 index ce87878..ab48aa3 100644
20451 --- a/arch/x86/kvm/lapic.c
20452 +++ b/arch/x86/kvm/lapic.c
20453 @@ -54,7 +54,7 @@
20454 #define APIC_BUS_CYCLE_NS 1
20455
20456 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20457 -#define apic_debug(fmt, arg...)
20458 +#define apic_debug(fmt, arg...) do {} while (0)
20459
20460 #define APIC_LVT_NUM 6
20461 /* 14 is the version for Xeon and Pentium 8.4.8*/
20462 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20463 index bb7cf01..0348a05 100644
20464 --- a/arch/x86/kvm/paging_tmpl.h
20465 +++ b/arch/x86/kvm/paging_tmpl.h
20466 @@ -196,7 +196,7 @@ retry_walk:
20467 if (unlikely(kvm_is_error_hva(host_addr)))
20468 goto error;
20469
20470 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20471 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20472 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20473 goto error;
20474
20475 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20476 index baead95..90feeb4 100644
20477 --- a/arch/x86/kvm/svm.c
20478 +++ b/arch/x86/kvm/svm.c
20479 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20480 int cpu = raw_smp_processor_id();
20481
20482 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20483 +
20484 + pax_open_kernel();
20485 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20486 + pax_close_kernel();
20487 +
20488 load_TR_desc();
20489 }
20490
20491 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20492 #endif
20493 #endif
20494
20495 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20496 + __set_fs(current_thread_info()->addr_limit);
20497 +#endif
20498 +
20499 reload_tss(vcpu);
20500
20501 local_irq_disable();
20502 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20503 index b1eb202..254e292 100644
20504 --- a/arch/x86/kvm/vmx.c
20505 +++ b/arch/x86/kvm/vmx.c
20506 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20507 struct desc_struct *descs;
20508
20509 descs = (void *)gdt->address;
20510 +
20511 + pax_open_kernel();
20512 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20513 + pax_close_kernel();
20514 +
20515 load_TR_desc();
20516 }
20517
20518 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20519 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20520 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20521
20522 +#ifdef CONFIG_PAX_PER_CPU_PGD
20523 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20524 +#endif
20525 +
20526 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20527 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20528 vmx->loaded_vmcs->cpu = cpu;
20529 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20530 if (!cpu_has_vmx_flexpriority())
20531 flexpriority_enabled = 0;
20532
20533 - if (!cpu_has_vmx_tpr_shadow())
20534 - kvm_x86_ops->update_cr8_intercept = NULL;
20535 + if (!cpu_has_vmx_tpr_shadow()) {
20536 + pax_open_kernel();
20537 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20538 + pax_close_kernel();
20539 + }
20540
20541 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20542 kvm_disable_largepages();
20543 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20544
20545 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20546 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20547 +
20548 +#ifndef CONFIG_PAX_PER_CPU_PGD
20549 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20550 +#endif
20551
20552 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20553 #ifdef CONFIG_X86_64
20554 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20555 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20556
20557 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20558 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20559 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20560
20561 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20562 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20563 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20564 "jmp .Lkvm_vmx_return \n\t"
20565 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20566 ".Lkvm_vmx_return: "
20567 +
20568 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20569 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20570 + ".Lkvm_vmx_return2: "
20571 +#endif
20572 +
20573 /* Save guest registers, load host registers, keep flags */
20574 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20575 "pop %0 \n\t"
20576 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20577 #endif
20578 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20579 [wordsize]"i"(sizeof(ulong))
20580 +
20581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20582 + ,[cs]"i"(__KERNEL_CS)
20583 +#endif
20584 +
20585 : "cc", "memory"
20586 , R"ax", R"bx", R"di", R"si"
20587 #ifdef CONFIG_X86_64
20588 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20589 #endif
20590 );
20591
20592 -#ifndef CONFIG_X86_64
20593 +#ifdef CONFIG_X86_32
20594 /*
20595 * The sysexit path does not restore ds/es, so we must set them to
20596 * a reasonable value ourselves.
20597 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20598 * may be executed in interrupt context, which saves and restore segments
20599 * around it, nullifying its effect.
20600 */
20601 - loadsegment(ds, __USER_DS);
20602 - loadsegment(es, __USER_DS);
20603 + loadsegment(ds, __KERNEL_DS);
20604 + loadsegment(es, __KERNEL_DS);
20605 + loadsegment(ss, __KERNEL_DS);
20606 +
20607 +#ifdef CONFIG_PAX_KERNEXEC
20608 + loadsegment(fs, __KERNEL_PERCPU);
20609 +#endif
20610 +
20611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20612 + __set_fs(current_thread_info()->addr_limit);
20613 +#endif
20614 +
20615 #endif
20616
20617 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20618 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20619 index 2966c84..207d0cb 100644
20620 --- a/arch/x86/kvm/x86.c
20621 +++ b/arch/x86/kvm/x86.c
20622 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20623 {
20624 struct kvm *kvm = vcpu->kvm;
20625 int lm = is_long_mode(vcpu);
20626 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20627 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20628 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20629 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20630 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20631 : kvm->arch.xen_hvm_config.blob_size_32;
20632 u32 page_num = data & ~PAGE_MASK;
20633 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20634 if (n < msr_list.nmsrs)
20635 goto out;
20636 r = -EFAULT;
20637 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20638 + goto out;
20639 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20640 num_msrs_to_save * sizeof(u32)))
20641 goto out;
20642 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20643 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20644 struct kvm_interrupt *irq)
20645 {
20646 - if (irq->irq < 0 || irq->irq >= 256)
20647 + if (irq->irq >= 256)
20648 return -EINVAL;
20649 if (irqchip_in_kernel(vcpu->kvm))
20650 return -ENXIO;
20651 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20652 kvm_mmu_set_mmio_spte_mask(mask);
20653 }
20654
20655 -int kvm_arch_init(void *opaque)
20656 +int kvm_arch_init(const void *opaque)
20657 {
20658 int r;
20659 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20660 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20661 index 642d880..cc9ebac 100644
20662 --- a/arch/x86/lguest/boot.c
20663 +++ b/arch/x86/lguest/boot.c
20664 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20665
20666 static void set_lguest_basic_apic_ops(void)
20667 {
20668 - apic->read = lguest_apic_read;
20669 - apic->write = lguest_apic_write;
20670 - apic->icr_read = lguest_apic_icr_read;
20671 - apic->icr_write = lguest_apic_icr_write;
20672 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20673 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20674 + *(void **)&apic->read = lguest_apic_read;
20675 + *(void **)&apic->write = lguest_apic_write;
20676 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20677 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20678 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20679 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20680 };
20681 #endif
20682
20683 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20684 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20685 * Launcher to reboot us.
20686 */
20687 -static void lguest_restart(char *reason)
20688 +static __noreturn void lguest_restart(char *reason)
20689 {
20690 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20691 + BUG();
20692 }
20693
20694 /*G:050
20695 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20696 index 00933d5..3a64af9 100644
20697 --- a/arch/x86/lib/atomic64_386_32.S
20698 +++ b/arch/x86/lib/atomic64_386_32.S
20699 @@ -48,6 +48,10 @@ BEGIN(read)
20700 movl (v), %eax
20701 movl 4(v), %edx
20702 RET_ENDP
20703 +BEGIN(read_unchecked)
20704 + movl (v), %eax
20705 + movl 4(v), %edx
20706 +RET_ENDP
20707 #undef v
20708
20709 #define v %esi
20710 @@ -55,6 +59,10 @@ BEGIN(set)
20711 movl %ebx, (v)
20712 movl %ecx, 4(v)
20713 RET_ENDP
20714 +BEGIN(set_unchecked)
20715 + movl %ebx, (v)
20716 + movl %ecx, 4(v)
20717 +RET_ENDP
20718 #undef v
20719
20720 #define v %esi
20721 @@ -70,6 +78,20 @@ RET_ENDP
20722 BEGIN(add)
20723 addl %eax, (v)
20724 adcl %edx, 4(v)
20725 +
20726 +#ifdef CONFIG_PAX_REFCOUNT
20727 + jno 0f
20728 + subl %eax, (v)
20729 + sbbl %edx, 4(v)
20730 + int $4
20731 +0:
20732 + _ASM_EXTABLE(0b, 0b)
20733 +#endif
20734 +
20735 +RET_ENDP
20736 +BEGIN(add_unchecked)
20737 + addl %eax, (v)
20738 + adcl %edx, 4(v)
20739 RET_ENDP
20740 #undef v
20741
20742 @@ -77,6 +99,24 @@ RET_ENDP
20743 BEGIN(add_return)
20744 addl (v), %eax
20745 adcl 4(v), %edx
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 + into
20749 +1234:
20750 + _ASM_EXTABLE(1234b, 2f)
20751 +#endif
20752 +
20753 + movl %eax, (v)
20754 + movl %edx, 4(v)
20755 +
20756 +#ifdef CONFIG_PAX_REFCOUNT
20757 +2:
20758 +#endif
20759 +
20760 +RET_ENDP
20761 +BEGIN(add_return_unchecked)
20762 + addl (v), %eax
20763 + adcl 4(v), %edx
20764 movl %eax, (v)
20765 movl %edx, 4(v)
20766 RET_ENDP
20767 @@ -86,6 +126,20 @@ RET_ENDP
20768 BEGIN(sub)
20769 subl %eax, (v)
20770 sbbl %edx, 4(v)
20771 +
20772 +#ifdef CONFIG_PAX_REFCOUNT
20773 + jno 0f
20774 + addl %eax, (v)
20775 + adcl %edx, 4(v)
20776 + int $4
20777 +0:
20778 + _ASM_EXTABLE(0b, 0b)
20779 +#endif
20780 +
20781 +RET_ENDP
20782 +BEGIN(sub_unchecked)
20783 + subl %eax, (v)
20784 + sbbl %edx, 4(v)
20785 RET_ENDP
20786 #undef v
20787
20788 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20789 sbbl $0, %edx
20790 addl (v), %eax
20791 adcl 4(v), %edx
20792 +
20793 +#ifdef CONFIG_PAX_REFCOUNT
20794 + into
20795 +1234:
20796 + _ASM_EXTABLE(1234b, 2f)
20797 +#endif
20798 +
20799 + movl %eax, (v)
20800 + movl %edx, 4(v)
20801 +
20802 +#ifdef CONFIG_PAX_REFCOUNT
20803 +2:
20804 +#endif
20805 +
20806 +RET_ENDP
20807 +BEGIN(sub_return_unchecked)
20808 + negl %edx
20809 + negl %eax
20810 + sbbl $0, %edx
20811 + addl (v), %eax
20812 + adcl 4(v), %edx
20813 movl %eax, (v)
20814 movl %edx, 4(v)
20815 RET_ENDP
20816 @@ -105,6 +180,20 @@ RET_ENDP
20817 BEGIN(inc)
20818 addl $1, (v)
20819 adcl $0, 4(v)
20820 +
20821 +#ifdef CONFIG_PAX_REFCOUNT
20822 + jno 0f
20823 + subl $1, (v)
20824 + sbbl $0, 4(v)
20825 + int $4
20826 +0:
20827 + _ASM_EXTABLE(0b, 0b)
20828 +#endif
20829 +
20830 +RET_ENDP
20831 +BEGIN(inc_unchecked)
20832 + addl $1, (v)
20833 + adcl $0, 4(v)
20834 RET_ENDP
20835 #undef v
20836
20837 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20838 movl 4(v), %edx
20839 addl $1, %eax
20840 adcl $0, %edx
20841 +
20842 +#ifdef CONFIG_PAX_REFCOUNT
20843 + into
20844 +1234:
20845 + _ASM_EXTABLE(1234b, 2f)
20846 +#endif
20847 +
20848 + movl %eax, (v)
20849 + movl %edx, 4(v)
20850 +
20851 +#ifdef CONFIG_PAX_REFCOUNT
20852 +2:
20853 +#endif
20854 +
20855 +RET_ENDP
20856 +BEGIN(inc_return_unchecked)
20857 + movl (v), %eax
20858 + movl 4(v), %edx
20859 + addl $1, %eax
20860 + adcl $0, %edx
20861 movl %eax, (v)
20862 movl %edx, 4(v)
20863 RET_ENDP
20864 @@ -123,6 +232,20 @@ RET_ENDP
20865 BEGIN(dec)
20866 subl $1, (v)
20867 sbbl $0, 4(v)
20868 +
20869 +#ifdef CONFIG_PAX_REFCOUNT
20870 + jno 0f
20871 + addl $1, (v)
20872 + adcl $0, 4(v)
20873 + int $4
20874 +0:
20875 + _ASM_EXTABLE(0b, 0b)
20876 +#endif
20877 +
20878 +RET_ENDP
20879 +BEGIN(dec_unchecked)
20880 + subl $1, (v)
20881 + sbbl $0, 4(v)
20882 RET_ENDP
20883 #undef v
20884
20885 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889 +
20890 +#ifdef CONFIG_PAX_REFCOUNT
20891 + into
20892 +1234:
20893 + _ASM_EXTABLE(1234b, 2f)
20894 +#endif
20895 +
20896 + movl %eax, (v)
20897 + movl %edx, 4(v)
20898 +
20899 +#ifdef CONFIG_PAX_REFCOUNT
20900 +2:
20901 +#endif
20902 +
20903 +RET_ENDP
20904 +BEGIN(dec_return_unchecked)
20905 + movl (v), %eax
20906 + movl 4(v), %edx
20907 + subl $1, %eax
20908 + sbbl $0, %edx
20909 movl %eax, (v)
20910 movl %edx, 4(v)
20911 RET_ENDP
20912 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20913 adcl %edx, %edi
20914 addl (v), %eax
20915 adcl 4(v), %edx
20916 +
20917 +#ifdef CONFIG_PAX_REFCOUNT
20918 + into
20919 +1234:
20920 + _ASM_EXTABLE(1234b, 2f)
20921 +#endif
20922 +
20923 cmpl %eax, %ecx
20924 je 3f
20925 1:
20926 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20927 1:
20928 addl $1, %eax
20929 adcl $0, %edx
20930 +
20931 +#ifdef CONFIG_PAX_REFCOUNT
20932 + into
20933 +1234:
20934 + _ASM_EXTABLE(1234b, 2f)
20935 +#endif
20936 +
20937 movl %eax, (v)
20938 movl %edx, 4(v)
20939 movl $1, %eax
20940 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20941 movl 4(v), %edx
20942 subl $1, %eax
20943 sbbl $0, %edx
20944 +
20945 +#ifdef CONFIG_PAX_REFCOUNT
20946 + into
20947 +1234:
20948 + _ASM_EXTABLE(1234b, 1f)
20949 +#endif
20950 +
20951 js 1f
20952 movl %eax, (v)
20953 movl %edx, 4(v)
20954 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20955 index f5cc9eb..51fa319 100644
20956 --- a/arch/x86/lib/atomic64_cx8_32.S
20957 +++ b/arch/x86/lib/atomic64_cx8_32.S
20958 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20959 CFI_STARTPROC
20960
20961 read64 %ecx
20962 + pax_force_retaddr
20963 ret
20964 CFI_ENDPROC
20965 ENDPROC(atomic64_read_cx8)
20966
20967 +ENTRY(atomic64_read_unchecked_cx8)
20968 + CFI_STARTPROC
20969 +
20970 + read64 %ecx
20971 + pax_force_retaddr
20972 + ret
20973 + CFI_ENDPROC
20974 +ENDPROC(atomic64_read_unchecked_cx8)
20975 +
20976 ENTRY(atomic64_set_cx8)
20977 CFI_STARTPROC
20978
20979 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20980 cmpxchg8b (%esi)
20981 jne 1b
20982
20983 + pax_force_retaddr
20984 ret
20985 CFI_ENDPROC
20986 ENDPROC(atomic64_set_cx8)
20987
20988 +ENTRY(atomic64_set_unchecked_cx8)
20989 + CFI_STARTPROC
20990 +
20991 +1:
20992 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20993 + * are atomic on 586 and newer */
20994 + cmpxchg8b (%esi)
20995 + jne 1b
20996 +
20997 + pax_force_retaddr
20998 + ret
20999 + CFI_ENDPROC
21000 +ENDPROC(atomic64_set_unchecked_cx8)
21001 +
21002 ENTRY(atomic64_xchg_cx8)
21003 CFI_STARTPROC
21004
21005 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21006 cmpxchg8b (%esi)
21007 jne 1b
21008
21009 + pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_xchg_cx8)
21013
21014 -.macro addsub_return func ins insc
21015 -ENTRY(atomic64_\func\()_return_cx8)
21016 +.macro addsub_return func ins insc unchecked=""
21017 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21018 CFI_STARTPROC
21019 SAVE ebp
21020 SAVE ebx
21021 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21022 movl %edx, %ecx
21023 \ins\()l %esi, %ebx
21024 \insc\()l %edi, %ecx
21025 +
21026 +.ifb \unchecked
21027 +#ifdef CONFIG_PAX_REFCOUNT
21028 + into
21029 +2:
21030 + _ASM_EXTABLE(2b, 3f)
21031 +#endif
21032 +.endif
21033 +
21034 LOCK_PREFIX
21035 cmpxchg8b (%ebp)
21036 jne 1b
21037 -
21038 -10:
21039 movl %ebx, %eax
21040 movl %ecx, %edx
21041 +
21042 +.ifb \unchecked
21043 +#ifdef CONFIG_PAX_REFCOUNT
21044 +3:
21045 +#endif
21046 +.endif
21047 +
21048 RESTORE edi
21049 RESTORE esi
21050 RESTORE ebx
21051 RESTORE ebp
21052 + pax_force_retaddr
21053 ret
21054 CFI_ENDPROC
21055 -ENDPROC(atomic64_\func\()_return_cx8)
21056 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21057 .endm
21058
21059 addsub_return add add adc
21060 addsub_return sub sub sbb
21061 +addsub_return add add adc _unchecked
21062 +addsub_return sub sub sbb _unchecked
21063
21064 -.macro incdec_return func ins insc
21065 -ENTRY(atomic64_\func\()_return_cx8)
21066 +.macro incdec_return func ins insc unchecked=""
21067 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21068 CFI_STARTPROC
21069 SAVE ebx
21070
21071 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21072 movl %edx, %ecx
21073 \ins\()l $1, %ebx
21074 \insc\()l $0, %ecx
21075 +
21076 +.ifb \unchecked
21077 +#ifdef CONFIG_PAX_REFCOUNT
21078 + into
21079 +2:
21080 + _ASM_EXTABLE(2b, 3f)
21081 +#endif
21082 +.endif
21083 +
21084 LOCK_PREFIX
21085 cmpxchg8b (%esi)
21086 jne 1b
21087
21088 -10:
21089 movl %ebx, %eax
21090 movl %ecx, %edx
21091 +
21092 +.ifb \unchecked
21093 +#ifdef CONFIG_PAX_REFCOUNT
21094 +3:
21095 +#endif
21096 +.endif
21097 +
21098 RESTORE ebx
21099 + pax_force_retaddr
21100 ret
21101 CFI_ENDPROC
21102 -ENDPROC(atomic64_\func\()_return_cx8)
21103 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21104 .endm
21105
21106 incdec_return inc add adc
21107 incdec_return dec sub sbb
21108 +incdec_return inc add adc _unchecked
21109 +incdec_return dec sub sbb _unchecked
21110
21111 ENTRY(atomic64_dec_if_positive_cx8)
21112 CFI_STARTPROC
21113 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21114 movl %edx, %ecx
21115 subl $1, %ebx
21116 sbb $0, %ecx
21117 +
21118 +#ifdef CONFIG_PAX_REFCOUNT
21119 + into
21120 +1234:
21121 + _ASM_EXTABLE(1234b, 2f)
21122 +#endif
21123 +
21124 js 2f
21125 LOCK_PREFIX
21126 cmpxchg8b (%esi)
21127 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21128 movl %ebx, %eax
21129 movl %ecx, %edx
21130 RESTORE ebx
21131 + pax_force_retaddr
21132 ret
21133 CFI_ENDPROC
21134 ENDPROC(atomic64_dec_if_positive_cx8)
21135 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21136 movl %edx, %ecx
21137 addl %ebp, %ebx
21138 adcl %edi, %ecx
21139 +
21140 +#ifdef CONFIG_PAX_REFCOUNT
21141 + into
21142 +1234:
21143 + _ASM_EXTABLE(1234b, 3f)
21144 +#endif
21145 +
21146 LOCK_PREFIX
21147 cmpxchg8b (%esi)
21148 jne 1b
21149 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21150 CFI_ADJUST_CFA_OFFSET -8
21151 RESTORE ebx
21152 RESTORE ebp
21153 + pax_force_retaddr
21154 ret
21155 4:
21156 cmpl %edx, 4(%esp)
21157 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21158 xorl %ecx, %ecx
21159 addl $1, %ebx
21160 adcl %edx, %ecx
21161 +
21162 +#ifdef CONFIG_PAX_REFCOUNT
21163 + into
21164 +1234:
21165 + _ASM_EXTABLE(1234b, 3f)
21166 +#endif
21167 +
21168 LOCK_PREFIX
21169 cmpxchg8b (%esi)
21170 jne 1b
21171 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21172 movl $1, %eax
21173 3:
21174 RESTORE ebx
21175 + pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(atomic64_inc_not_zero_cx8)
21179 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21180 index 2af5df3..62b1a5a 100644
21181 --- a/arch/x86/lib/checksum_32.S
21182 +++ b/arch/x86/lib/checksum_32.S
21183 @@ -29,7 +29,8 @@
21184 #include <asm/dwarf2.h>
21185 #include <asm/errno.h>
21186 #include <asm/asm.h>
21187 -
21188 +#include <asm/segment.h>
21189 +
21190 /*
21191 * computes a partial checksum, e.g. for TCP/UDP fragments
21192 */
21193 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21194
21195 #define ARGBASE 16
21196 #define FP 12
21197 -
21198 -ENTRY(csum_partial_copy_generic)
21199 +
21200 +ENTRY(csum_partial_copy_generic_to_user)
21201 CFI_STARTPROC
21202 +
21203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21204 + pushl_cfi %gs
21205 + popl_cfi %es
21206 + jmp csum_partial_copy_generic
21207 +#endif
21208 +
21209 +ENTRY(csum_partial_copy_generic_from_user)
21210 +
21211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21212 + pushl_cfi %gs
21213 + popl_cfi %ds
21214 +#endif
21215 +
21216 +ENTRY(csum_partial_copy_generic)
21217 subl $4,%esp
21218 CFI_ADJUST_CFA_OFFSET 4
21219 pushl_cfi %edi
21220 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21221 jmp 4f
21222 SRC(1: movw (%esi), %bx )
21223 addl $2, %esi
21224 -DST( movw %bx, (%edi) )
21225 +DST( movw %bx, %es:(%edi) )
21226 addl $2, %edi
21227 addw %bx, %ax
21228 adcl $0, %eax
21229 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21230 SRC(1: movl (%esi), %ebx )
21231 SRC( movl 4(%esi), %edx )
21232 adcl %ebx, %eax
21233 -DST( movl %ebx, (%edi) )
21234 +DST( movl %ebx, %es:(%edi) )
21235 adcl %edx, %eax
21236 -DST( movl %edx, 4(%edi) )
21237 +DST( movl %edx, %es:4(%edi) )
21238
21239 SRC( movl 8(%esi), %ebx )
21240 SRC( movl 12(%esi), %edx )
21241 adcl %ebx, %eax
21242 -DST( movl %ebx, 8(%edi) )
21243 +DST( movl %ebx, %es:8(%edi) )
21244 adcl %edx, %eax
21245 -DST( movl %edx, 12(%edi) )
21246 +DST( movl %edx, %es:12(%edi) )
21247
21248 SRC( movl 16(%esi), %ebx )
21249 SRC( movl 20(%esi), %edx )
21250 adcl %ebx, %eax
21251 -DST( movl %ebx, 16(%edi) )
21252 +DST( movl %ebx, %es:16(%edi) )
21253 adcl %edx, %eax
21254 -DST( movl %edx, 20(%edi) )
21255 +DST( movl %edx, %es:20(%edi) )
21256
21257 SRC( movl 24(%esi), %ebx )
21258 SRC( movl 28(%esi), %edx )
21259 adcl %ebx, %eax
21260 -DST( movl %ebx, 24(%edi) )
21261 +DST( movl %ebx, %es:24(%edi) )
21262 adcl %edx, %eax
21263 -DST( movl %edx, 28(%edi) )
21264 +DST( movl %edx, %es:28(%edi) )
21265
21266 lea 32(%esi), %esi
21267 lea 32(%edi), %edi
21268 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21269 shrl $2, %edx # This clears CF
21270 SRC(3: movl (%esi), %ebx )
21271 adcl %ebx, %eax
21272 -DST( movl %ebx, (%edi) )
21273 +DST( movl %ebx, %es:(%edi) )
21274 lea 4(%esi), %esi
21275 lea 4(%edi), %edi
21276 dec %edx
21277 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21278 jb 5f
21279 SRC( movw (%esi), %cx )
21280 leal 2(%esi), %esi
21281 -DST( movw %cx, (%edi) )
21282 +DST( movw %cx, %es:(%edi) )
21283 leal 2(%edi), %edi
21284 je 6f
21285 shll $16,%ecx
21286 SRC(5: movb (%esi), %cl )
21287 -DST( movb %cl, (%edi) )
21288 +DST( movb %cl, %es:(%edi) )
21289 6: addl %ecx, %eax
21290 adcl $0, %eax
21291 7:
21292 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21293
21294 6001:
21295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21296 - movl $-EFAULT, (%ebx)
21297 + movl $-EFAULT, %ss:(%ebx)
21298
21299 # zero the complete destination - computing the rest
21300 # is too much work
21301 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21302
21303 6002:
21304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21305 - movl $-EFAULT,(%ebx)
21306 + movl $-EFAULT,%ss:(%ebx)
21307 jmp 5000b
21308
21309 .previous
21310
21311 + pushl_cfi %ss
21312 + popl_cfi %ds
21313 + pushl_cfi %ss
21314 + popl_cfi %es
21315 popl_cfi %ebx
21316 CFI_RESTORE ebx
21317 popl_cfi %esi
21318 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21319 popl_cfi %ecx # equivalent to addl $4,%esp
21320 ret
21321 CFI_ENDPROC
21322 -ENDPROC(csum_partial_copy_generic)
21323 +ENDPROC(csum_partial_copy_generic_to_user)
21324
21325 #else
21326
21327 /* Version for PentiumII/PPro */
21328
21329 #define ROUND1(x) \
21330 + nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 addl %ebx, %eax ; \
21333 - DST(movl %ebx, x(%edi) ) ;
21334 + DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ROUND(x) \
21337 + nop; nop; nop; \
21338 SRC(movl x(%esi), %ebx ) ; \
21339 adcl %ebx, %eax ; \
21340 - DST(movl %ebx, x(%edi) ) ;
21341 + DST(movl %ebx, %es:x(%edi)) ;
21342
21343 #define ARGBASE 12
21344 -
21345 -ENTRY(csum_partial_copy_generic)
21346 +
21347 +ENTRY(csum_partial_copy_generic_to_user)
21348 CFI_STARTPROC
21349 +
21350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21351 + pushl_cfi %gs
21352 + popl_cfi %es
21353 + jmp csum_partial_copy_generic
21354 +#endif
21355 +
21356 +ENTRY(csum_partial_copy_generic_from_user)
21357 +
21358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21359 + pushl_cfi %gs
21360 + popl_cfi %ds
21361 +#endif
21362 +
21363 +ENTRY(csum_partial_copy_generic)
21364 pushl_cfi %ebx
21365 CFI_REL_OFFSET ebx, 0
21366 pushl_cfi %edi
21367 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21368 subl %ebx, %edi
21369 lea -1(%esi),%edx
21370 andl $-32,%edx
21371 - lea 3f(%ebx,%ebx), %ebx
21372 + lea 3f(%ebx,%ebx,2), %ebx
21373 testl %esi, %esi
21374 jmp *%ebx
21375 1: addl $64,%esi
21376 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21377 jb 5f
21378 SRC( movw (%esi), %dx )
21379 leal 2(%esi), %esi
21380 -DST( movw %dx, (%edi) )
21381 +DST( movw %dx, %es:(%edi) )
21382 leal 2(%edi), %edi
21383 je 6f
21384 shll $16,%edx
21385 5:
21386 SRC( movb (%esi), %dl )
21387 -DST( movb %dl, (%edi) )
21388 +DST( movb %dl, %es:(%edi) )
21389 6: addl %edx, %eax
21390 adcl $0, %eax
21391 7:
21392 .section .fixup, "ax"
21393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21394 - movl $-EFAULT, (%ebx)
21395 + movl $-EFAULT, %ss:(%ebx)
21396 # zero the complete destination (computing the rest is too much work)
21397 movl ARGBASE+8(%esp),%edi # dst
21398 movl ARGBASE+12(%esp),%ecx # len
21399 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21400 rep; stosb
21401 jmp 7b
21402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21403 - movl $-EFAULT, (%ebx)
21404 + movl $-EFAULT, %ss:(%ebx)
21405 jmp 7b
21406 .previous
21407
21408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21409 + pushl_cfi %ss
21410 + popl_cfi %ds
21411 + pushl_cfi %ss
21412 + popl_cfi %es
21413 +#endif
21414 +
21415 popl_cfi %esi
21416 CFI_RESTORE esi
21417 popl_cfi %edi
21418 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21419 CFI_RESTORE ebx
21420 ret
21421 CFI_ENDPROC
21422 -ENDPROC(csum_partial_copy_generic)
21423 +ENDPROC(csum_partial_copy_generic_to_user)
21424
21425 #undef ROUND
21426 #undef ROUND1
21427 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21428 index f2145cf..cea889d 100644
21429 --- a/arch/x86/lib/clear_page_64.S
21430 +++ b/arch/x86/lib/clear_page_64.S
21431 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21432 movl $4096/8,%ecx
21433 xorl %eax,%eax
21434 rep stosq
21435 + pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(clear_page_c)
21439 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21440 movl $4096,%ecx
21441 xorl %eax,%eax
21442 rep stosb
21443 + pax_force_retaddr
21444 ret
21445 CFI_ENDPROC
21446 ENDPROC(clear_page_c_e)
21447 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21448 leaq 64(%rdi),%rdi
21449 jnz .Lloop
21450 nop
21451 + pax_force_retaddr
21452 ret
21453 CFI_ENDPROC
21454 .Lclear_page_end:
21455 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21456
21457 #include <asm/cpufeature.h>
21458
21459 - .section .altinstr_replacement,"ax"
21460 + .section .altinstr_replacement,"a"
21461 1: .byte 0xeb /* jmp <disp8> */
21462 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21463 2: .byte 0xeb /* jmp <disp8> */
21464 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21465 index 1e572c5..2a162cd 100644
21466 --- a/arch/x86/lib/cmpxchg16b_emu.S
21467 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21468 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21469
21470 popf
21471 mov $1, %al
21472 + pax_force_retaddr
21473 ret
21474
21475 not_same:
21476 popf
21477 xor %al,%al
21478 + pax_force_retaddr
21479 ret
21480
21481 CFI_ENDPROC
21482 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21483 index 6b34d04..dccb07f 100644
21484 --- a/arch/x86/lib/copy_page_64.S
21485 +++ b/arch/x86/lib/copy_page_64.S
21486 @@ -9,6 +9,7 @@ copy_page_c:
21487 CFI_STARTPROC
21488 movl $4096/8,%ecx
21489 rep movsq
21490 + pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(copy_page_c)
21494 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21495
21496 ENTRY(copy_page)
21497 CFI_STARTPROC
21498 - subq $2*8,%rsp
21499 - CFI_ADJUST_CFA_OFFSET 2*8
21500 + subq $3*8,%rsp
21501 + CFI_ADJUST_CFA_OFFSET 3*8
21502 movq %rbx,(%rsp)
21503 CFI_REL_OFFSET rbx, 0
21504 movq %r12,1*8(%rsp)
21505 CFI_REL_OFFSET r12, 1*8
21506 + movq %r13,2*8(%rsp)
21507 + CFI_REL_OFFSET r13, 2*8
21508
21509 movl $(4096/64)-5,%ecx
21510 .p2align 4
21511 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21512 movq 16 (%rsi), %rdx
21513 movq 24 (%rsi), %r8
21514 movq 32 (%rsi), %r9
21515 - movq 40 (%rsi), %r10
21516 + movq 40 (%rsi), %r13
21517 movq 48 (%rsi), %r11
21518 movq 56 (%rsi), %r12
21519
21520 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21521 movq %rdx, 16 (%rdi)
21522 movq %r8, 24 (%rdi)
21523 movq %r9, 32 (%rdi)
21524 - movq %r10, 40 (%rdi)
21525 + movq %r13, 40 (%rdi)
21526 movq %r11, 48 (%rdi)
21527 movq %r12, 56 (%rdi)
21528
21529 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21530 movq 16 (%rsi), %rdx
21531 movq 24 (%rsi), %r8
21532 movq 32 (%rsi), %r9
21533 - movq 40 (%rsi), %r10
21534 + movq 40 (%rsi), %r13
21535 movq 48 (%rsi), %r11
21536 movq 56 (%rsi), %r12
21537
21538 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21539 movq %rdx, 16 (%rdi)
21540 movq %r8, 24 (%rdi)
21541 movq %r9, 32 (%rdi)
21542 - movq %r10, 40 (%rdi)
21543 + movq %r13, 40 (%rdi)
21544 movq %r11, 48 (%rdi)
21545 movq %r12, 56 (%rdi)
21546
21547 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21548 CFI_RESTORE rbx
21549 movq 1*8(%rsp),%r12
21550 CFI_RESTORE r12
21551 - addq $2*8,%rsp
21552 - CFI_ADJUST_CFA_OFFSET -2*8
21553 + movq 2*8(%rsp),%r13
21554 + CFI_RESTORE r13
21555 + addq $3*8,%rsp
21556 + CFI_ADJUST_CFA_OFFSET -3*8
21557 + pax_force_retaddr
21558 ret
21559 .Lcopy_page_end:
21560 CFI_ENDPROC
21561 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21562
21563 #include <asm/cpufeature.h>
21564
21565 - .section .altinstr_replacement,"ax"
21566 + .section .altinstr_replacement,"a"
21567 1: .byte 0xeb /* jmp <disp8> */
21568 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21569 2:
21570 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21571 index 5b2995f..78e7644 100644
21572 --- a/arch/x86/lib/copy_user_64.S
21573 +++ b/arch/x86/lib/copy_user_64.S
21574 @@ -17,6 +17,7 @@
21575 #include <asm/cpufeature.h>
21576 #include <asm/alternative-asm.h>
21577 #include <asm/asm.h>
21578 +#include <asm/pgtable.h>
21579
21580 /*
21581 * By placing feature2 after feature1 in altinstructions section, we logically
21582 @@ -30,7 +31,7 @@
21583 .byte 0xe9 /* 32bit jump */
21584 .long \orig-1f /* by default jump to orig */
21585 1:
21586 - .section .altinstr_replacement,"ax"
21587 + .section .altinstr_replacement,"a"
21588 2: .byte 0xe9 /* near jump with 32bit immediate */
21589 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21590 3: .byte 0xe9 /* near jump with 32bit immediate */
21591 @@ -69,47 +70,20 @@
21592 #endif
21593 .endm
21594
21595 -/* Standard copy_to_user with segment limit checking */
21596 -ENTRY(_copy_to_user)
21597 - CFI_STARTPROC
21598 - GET_THREAD_INFO(%rax)
21599 - movq %rdi,%rcx
21600 - addq %rdx,%rcx
21601 - jc bad_to_user
21602 - cmpq TI_addr_limit(%rax),%rcx
21603 - ja bad_to_user
21604 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21605 - copy_user_generic_unrolled,copy_user_generic_string, \
21606 - copy_user_enhanced_fast_string
21607 - CFI_ENDPROC
21608 -ENDPROC(_copy_to_user)
21609 -
21610 -/* Standard copy_from_user with segment limit checking */
21611 -ENTRY(_copy_from_user)
21612 - CFI_STARTPROC
21613 - GET_THREAD_INFO(%rax)
21614 - movq %rsi,%rcx
21615 - addq %rdx,%rcx
21616 - jc bad_from_user
21617 - cmpq TI_addr_limit(%rax),%rcx
21618 - ja bad_from_user
21619 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21620 - copy_user_generic_unrolled,copy_user_generic_string, \
21621 - copy_user_enhanced_fast_string
21622 - CFI_ENDPROC
21623 -ENDPROC(_copy_from_user)
21624 -
21625 .section .fixup,"ax"
21626 /* must zero dest */
21627 ENTRY(bad_from_user)
21628 bad_from_user:
21629 CFI_STARTPROC
21630 + testl %edx,%edx
21631 + js bad_to_user
21632 movl %edx,%ecx
21633 xorl %eax,%eax
21634 rep
21635 stosb
21636 bad_to_user:
21637 movl %edx,%eax
21638 + pax_force_retaddr
21639 ret
21640 CFI_ENDPROC
21641 ENDPROC(bad_from_user)
21642 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21643 jz 17f
21644 1: movq (%rsi),%r8
21645 2: movq 1*8(%rsi),%r9
21646 -3: movq 2*8(%rsi),%r10
21647 +3: movq 2*8(%rsi),%rax
21648 4: movq 3*8(%rsi),%r11
21649 5: movq %r8,(%rdi)
21650 6: movq %r9,1*8(%rdi)
21651 -7: movq %r10,2*8(%rdi)
21652 +7: movq %rax,2*8(%rdi)
21653 8: movq %r11,3*8(%rdi)
21654 9: movq 4*8(%rsi),%r8
21655 10: movq 5*8(%rsi),%r9
21656 -11: movq 6*8(%rsi),%r10
21657 +11: movq 6*8(%rsi),%rax
21658 12: movq 7*8(%rsi),%r11
21659 13: movq %r8,4*8(%rdi)
21660 14: movq %r9,5*8(%rdi)
21661 -15: movq %r10,6*8(%rdi)
21662 +15: movq %rax,6*8(%rdi)
21663 16: movq %r11,7*8(%rdi)
21664 leaq 64(%rsi),%rsi
21665 leaq 64(%rdi),%rdi
21666 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21667 decl %ecx
21668 jnz 21b
21669 23: xor %eax,%eax
21670 + pax_force_retaddr
21671 ret
21672
21673 .section .fixup,"ax"
21674 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21675 3: rep
21676 movsb
21677 4: xorl %eax,%eax
21678 + pax_force_retaddr
21679 ret
21680
21681 .section .fixup,"ax"
21682 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21683 1: rep
21684 movsb
21685 2: xorl %eax,%eax
21686 + pax_force_retaddr
21687 ret
21688
21689 .section .fixup,"ax"
21690 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21691 index cacddc7..09d49e4 100644
21692 --- a/arch/x86/lib/copy_user_nocache_64.S
21693 +++ b/arch/x86/lib/copy_user_nocache_64.S
21694 @@ -8,6 +8,7 @@
21695
21696 #include <linux/linkage.h>
21697 #include <asm/dwarf2.h>
21698 +#include <asm/alternative-asm.h>
21699
21700 #define FIX_ALIGNMENT 1
21701
21702 @@ -15,6 +16,7 @@
21703 #include <asm/asm-offsets.h>
21704 #include <asm/thread_info.h>
21705 #include <asm/asm.h>
21706 +#include <asm/pgtable.h>
21707
21708 .macro ALIGN_DESTINATION
21709 #ifdef FIX_ALIGNMENT
21710 @@ -48,6 +50,15 @@
21711 */
21712 ENTRY(__copy_user_nocache)
21713 CFI_STARTPROC
21714 +
21715 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21716 + mov $PAX_USER_SHADOW_BASE,%rcx
21717 + cmp %rcx,%rsi
21718 + jae 1f
21719 + add %rcx,%rsi
21720 +1:
21721 +#endif
21722 +
21723 cmpl $8,%edx
21724 jb 20f /* less then 8 bytes, go to byte copy loop */
21725 ALIGN_DESTINATION
21726 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21727 jz 17f
21728 1: movq (%rsi),%r8
21729 2: movq 1*8(%rsi),%r9
21730 -3: movq 2*8(%rsi),%r10
21731 +3: movq 2*8(%rsi),%rax
21732 4: movq 3*8(%rsi),%r11
21733 5: movnti %r8,(%rdi)
21734 6: movnti %r9,1*8(%rdi)
21735 -7: movnti %r10,2*8(%rdi)
21736 +7: movnti %rax,2*8(%rdi)
21737 8: movnti %r11,3*8(%rdi)
21738 9: movq 4*8(%rsi),%r8
21739 10: movq 5*8(%rsi),%r9
21740 -11: movq 6*8(%rsi),%r10
21741 +11: movq 6*8(%rsi),%rax
21742 12: movq 7*8(%rsi),%r11
21743 13: movnti %r8,4*8(%rdi)
21744 14: movnti %r9,5*8(%rdi)
21745 -15: movnti %r10,6*8(%rdi)
21746 +15: movnti %rax,6*8(%rdi)
21747 16: movnti %r11,7*8(%rdi)
21748 leaq 64(%rsi),%rsi
21749 leaq 64(%rdi),%rdi
21750 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21751 jnz 21b
21752 23: xorl %eax,%eax
21753 sfence
21754 + pax_force_retaddr
21755 ret
21756
21757 .section .fixup,"ax"
21758 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21759 index 2419d5f..953ee51 100644
21760 --- a/arch/x86/lib/csum-copy_64.S
21761 +++ b/arch/x86/lib/csum-copy_64.S
21762 @@ -9,6 +9,7 @@
21763 #include <asm/dwarf2.h>
21764 #include <asm/errno.h>
21765 #include <asm/asm.h>
21766 +#include <asm/alternative-asm.h>
21767
21768 /*
21769 * Checksum copy with exception handling.
21770 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21771 CFI_RESTORE rbp
21772 addq $7*8, %rsp
21773 CFI_ADJUST_CFA_OFFSET -7*8
21774 + pax_force_retaddr 0, 1
21775 ret
21776 CFI_RESTORE_STATE
21777
21778 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21779 index 25b7ae8..3b52ccd 100644
21780 --- a/arch/x86/lib/csum-wrappers_64.c
21781 +++ b/arch/x86/lib/csum-wrappers_64.c
21782 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21783 len -= 2;
21784 }
21785 }
21786 - isum = csum_partial_copy_generic((__force const void *)src,
21787 +
21788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21789 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21790 + src += PAX_USER_SHADOW_BASE;
21791 +#endif
21792 +
21793 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21794 dst, len, isum, errp, NULL);
21795 if (unlikely(*errp))
21796 goto out_err;
21797 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21798 }
21799
21800 *errp = 0;
21801 - return csum_partial_copy_generic(src, (void __force *)dst,
21802 +
21803 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21804 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21805 + dst += PAX_USER_SHADOW_BASE;
21806 +#endif
21807 +
21808 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21809 len, isum, NULL, errp);
21810 }
21811 EXPORT_SYMBOL(csum_partial_copy_to_user);
21812 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21813 index b33b1fb..219f389 100644
21814 --- a/arch/x86/lib/getuser.S
21815 +++ b/arch/x86/lib/getuser.S
21816 @@ -33,15 +33,38 @@
21817 #include <asm/asm-offsets.h>
21818 #include <asm/thread_info.h>
21819 #include <asm/asm.h>
21820 +#include <asm/segment.h>
21821 +#include <asm/pgtable.h>
21822 +#include <asm/alternative-asm.h>
21823 +
21824 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21825 +#define __copyuser_seg gs;
21826 +#else
21827 +#define __copyuser_seg
21828 +#endif
21829
21830 .text
21831 ENTRY(__get_user_1)
21832 CFI_STARTPROC
21833 +
21834 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838 -1: movzb (%_ASM_AX),%edx
21839 +
21840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842 + cmp %_ASM_DX,%_ASM_AX
21843 + jae 1234f
21844 + add %_ASM_DX,%_ASM_AX
21845 +1234:
21846 +#endif
21847 +
21848 +#endif
21849 +
21850 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21851 xor %eax,%eax
21852 + pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_1)
21856 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21857 ENTRY(__get_user_2)
21858 CFI_STARTPROC
21859 add $1,%_ASM_AX
21860 +
21861 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21862 jc bad_get_user
21863 GET_THREAD_INFO(%_ASM_DX)
21864 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21865 jae bad_get_user
21866 -2: movzwl -1(%_ASM_AX),%edx
21867 +
21868 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21869 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21870 + cmp %_ASM_DX,%_ASM_AX
21871 + jae 1234f
21872 + add %_ASM_DX,%_ASM_AX
21873 +1234:
21874 +#endif
21875 +
21876 +#endif
21877 +
21878 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21879 xor %eax,%eax
21880 + pax_force_retaddr
21881 ret
21882 CFI_ENDPROC
21883 ENDPROC(__get_user_2)
21884 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21885 ENTRY(__get_user_4)
21886 CFI_STARTPROC
21887 add $3,%_ASM_AX
21888 +
21889 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21890 jc bad_get_user
21891 GET_THREAD_INFO(%_ASM_DX)
21892 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21893 jae bad_get_user
21894 -3: mov -3(%_ASM_AX),%edx
21895 +
21896 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21897 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21898 + cmp %_ASM_DX,%_ASM_AX
21899 + jae 1234f
21900 + add %_ASM_DX,%_ASM_AX
21901 +1234:
21902 +#endif
21903 +
21904 +#endif
21905 +
21906 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21907 xor %eax,%eax
21908 + pax_force_retaddr
21909 ret
21910 CFI_ENDPROC
21911 ENDPROC(__get_user_4)
21912 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21913 GET_THREAD_INFO(%_ASM_DX)
21914 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21915 jae bad_get_user
21916 +
21917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21918 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21919 + cmp %_ASM_DX,%_ASM_AX
21920 + jae 1234f
21921 + add %_ASM_DX,%_ASM_AX
21922 +1234:
21923 +#endif
21924 +
21925 4: movq -7(%_ASM_AX),%_ASM_DX
21926 xor %eax,%eax
21927 + pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_8)
21931 @@ -91,6 +152,7 @@ bad_get_user:
21932 CFI_STARTPROC
21933 xor %edx,%edx
21934 mov $(-EFAULT),%_ASM_AX
21935 + pax_force_retaddr
21936 ret
21937 CFI_ENDPROC
21938 END(bad_get_user)
21939 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21940 index b1e6c4b..21ae8fc 100644
21941 --- a/arch/x86/lib/insn.c
21942 +++ b/arch/x86/lib/insn.c
21943 @@ -21,6 +21,11 @@
21944 #include <linux/string.h>
21945 #include <asm/inat.h>
21946 #include <asm/insn.h>
21947 +#ifdef __KERNEL__
21948 +#include <asm/pgtable_types.h>
21949 +#else
21950 +#define ktla_ktva(addr) addr
21951 +#endif
21952
21953 /* Verify next sizeof(t) bytes can be on the same instruction */
21954 #define validate_next(t, insn, n) \
21955 @@ -49,8 +54,8 @@
21956 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21957 {
21958 memset(insn, 0, sizeof(*insn));
21959 - insn->kaddr = kaddr;
21960 - insn->next_byte = kaddr;
21961 + insn->kaddr = ktla_ktva(kaddr);
21962 + insn->next_byte = ktla_ktva(kaddr);
21963 insn->x86_64 = x86_64 ? 1 : 0;
21964 insn->opnd_bytes = 4;
21965 if (x86_64)
21966 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21967 index 05a95e7..326f2fa 100644
21968 --- a/arch/x86/lib/iomap_copy_64.S
21969 +++ b/arch/x86/lib/iomap_copy_64.S
21970 @@ -17,6 +17,7 @@
21971
21972 #include <linux/linkage.h>
21973 #include <asm/dwarf2.h>
21974 +#include <asm/alternative-asm.h>
21975
21976 /*
21977 * override generic version in lib/iomap_copy.c
21978 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21979 CFI_STARTPROC
21980 movl %edx,%ecx
21981 rep movsd
21982 + pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 ENDPROC(__iowrite32_copy)
21986 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21987 index 1c273be..da9cc0e 100644
21988 --- a/arch/x86/lib/memcpy_64.S
21989 +++ b/arch/x86/lib/memcpy_64.S
21990 @@ -33,6 +33,7 @@
21991 rep movsq
21992 movl %edx, %ecx
21993 rep movsb
21994 + pax_force_retaddr
21995 ret
21996 .Lmemcpy_e:
21997 .previous
21998 @@ -49,6 +50,7 @@
21999 movq %rdi, %rax
22000 movq %rdx, %rcx
22001 rep movsb
22002 + pax_force_retaddr
22003 ret
22004 .Lmemcpy_e_e:
22005 .previous
22006 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22007 */
22008 movq 0*8(%rsi), %r8
22009 movq 1*8(%rsi), %r9
22010 - movq 2*8(%rsi), %r10
22011 + movq 2*8(%rsi), %rcx
22012 movq 3*8(%rsi), %r11
22013 leaq 4*8(%rsi), %rsi
22014
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017 - movq %r10, 2*8(%rdi)
22018 + movq %rcx, 2*8(%rdi)
22019 movq %r11, 3*8(%rdi)
22020 leaq 4*8(%rdi), %rdi
22021 jae .Lcopy_forward_loop
22022 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22023 subq $0x20, %rdx
22024 movq -1*8(%rsi), %r8
22025 movq -2*8(%rsi), %r9
22026 - movq -3*8(%rsi), %r10
22027 + movq -3*8(%rsi), %rcx
22028 movq -4*8(%rsi), %r11
22029 leaq -4*8(%rsi), %rsi
22030 movq %r8, -1*8(%rdi)
22031 movq %r9, -2*8(%rdi)
22032 - movq %r10, -3*8(%rdi)
22033 + movq %rcx, -3*8(%rdi)
22034 movq %r11, -4*8(%rdi)
22035 leaq -4*8(%rdi), %rdi
22036 jae .Lcopy_backward_loop
22037 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22038 */
22039 movq 0*8(%rsi), %r8
22040 movq 1*8(%rsi), %r9
22041 - movq -2*8(%rsi, %rdx), %r10
22042 + movq -2*8(%rsi, %rdx), %rcx
22043 movq -1*8(%rsi, %rdx), %r11
22044 movq %r8, 0*8(%rdi)
22045 movq %r9, 1*8(%rdi)
22046 - movq %r10, -2*8(%rdi, %rdx)
22047 + movq %rcx, -2*8(%rdi, %rdx)
22048 movq %r11, -1*8(%rdi, %rdx)
22049 + pax_force_retaddr
22050 retq
22051 .p2align 4
22052 .Lless_16bytes:
22053 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22054 movq -1*8(%rsi, %rdx), %r9
22055 movq %r8, 0*8(%rdi)
22056 movq %r9, -1*8(%rdi, %rdx)
22057 + pax_force_retaddr
22058 retq
22059 .p2align 4
22060 .Lless_8bytes:
22061 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22062 movl -4(%rsi, %rdx), %r8d
22063 movl %ecx, (%rdi)
22064 movl %r8d, -4(%rdi, %rdx)
22065 + pax_force_retaddr
22066 retq
22067 .p2align 4
22068 .Lless_3bytes:
22069 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22070 movb %cl, (%rdi)
22071
22072 .Lend:
22073 + pax_force_retaddr
22074 retq
22075 CFI_ENDPROC
22076 ENDPROC(memcpy)
22077 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22078 index ee16461..c39c199 100644
22079 --- a/arch/x86/lib/memmove_64.S
22080 +++ b/arch/x86/lib/memmove_64.S
22081 @@ -61,13 +61,13 @@ ENTRY(memmove)
22082 5:
22083 sub $0x20, %rdx
22084 movq 0*8(%rsi), %r11
22085 - movq 1*8(%rsi), %r10
22086 + movq 1*8(%rsi), %rcx
22087 movq 2*8(%rsi), %r9
22088 movq 3*8(%rsi), %r8
22089 leaq 4*8(%rsi), %rsi
22090
22091 movq %r11, 0*8(%rdi)
22092 - movq %r10, 1*8(%rdi)
22093 + movq %rcx, 1*8(%rdi)
22094 movq %r9, 2*8(%rdi)
22095 movq %r8, 3*8(%rdi)
22096 leaq 4*8(%rdi), %rdi
22097 @@ -81,10 +81,10 @@ ENTRY(memmove)
22098 4:
22099 movq %rdx, %rcx
22100 movq -8(%rsi, %rdx), %r11
22101 - lea -8(%rdi, %rdx), %r10
22102 + lea -8(%rdi, %rdx), %r9
22103 shrq $3, %rcx
22104 rep movsq
22105 - movq %r11, (%r10)
22106 + movq %r11, (%r9)
22107 jmp 13f
22108 .Lmemmove_end_forward:
22109
22110 @@ -95,14 +95,14 @@ ENTRY(memmove)
22111 7:
22112 movq %rdx, %rcx
22113 movq (%rsi), %r11
22114 - movq %rdi, %r10
22115 + movq %rdi, %r9
22116 leaq -8(%rsi, %rdx), %rsi
22117 leaq -8(%rdi, %rdx), %rdi
22118 shrq $3, %rcx
22119 std
22120 rep movsq
22121 cld
22122 - movq %r11, (%r10)
22123 + movq %r11, (%r9)
22124 jmp 13f
22125
22126 /*
22127 @@ -127,13 +127,13 @@ ENTRY(memmove)
22128 8:
22129 subq $0x20, %rdx
22130 movq -1*8(%rsi), %r11
22131 - movq -2*8(%rsi), %r10
22132 + movq -2*8(%rsi), %rcx
22133 movq -3*8(%rsi), %r9
22134 movq -4*8(%rsi), %r8
22135 leaq -4*8(%rsi), %rsi
22136
22137 movq %r11, -1*8(%rdi)
22138 - movq %r10, -2*8(%rdi)
22139 + movq %rcx, -2*8(%rdi)
22140 movq %r9, -3*8(%rdi)
22141 movq %r8, -4*8(%rdi)
22142 leaq -4*8(%rdi), %rdi
22143 @@ -151,11 +151,11 @@ ENTRY(memmove)
22144 * Move data from 16 bytes to 31 bytes.
22145 */
22146 movq 0*8(%rsi), %r11
22147 - movq 1*8(%rsi), %r10
22148 + movq 1*8(%rsi), %rcx
22149 movq -2*8(%rsi, %rdx), %r9
22150 movq -1*8(%rsi, %rdx), %r8
22151 movq %r11, 0*8(%rdi)
22152 - movq %r10, 1*8(%rdi)
22153 + movq %rcx, 1*8(%rdi)
22154 movq %r9, -2*8(%rdi, %rdx)
22155 movq %r8, -1*8(%rdi, %rdx)
22156 jmp 13f
22157 @@ -167,9 +167,9 @@ ENTRY(memmove)
22158 * Move data from 8 bytes to 15 bytes.
22159 */
22160 movq 0*8(%rsi), %r11
22161 - movq -1*8(%rsi, %rdx), %r10
22162 + movq -1*8(%rsi, %rdx), %r9
22163 movq %r11, 0*8(%rdi)
22164 - movq %r10, -1*8(%rdi, %rdx)
22165 + movq %r9, -1*8(%rdi, %rdx)
22166 jmp 13f
22167 10:
22168 cmpq $4, %rdx
22169 @@ -178,9 +178,9 @@ ENTRY(memmove)
22170 * Move data from 4 bytes to 7 bytes.
22171 */
22172 movl (%rsi), %r11d
22173 - movl -4(%rsi, %rdx), %r10d
22174 + movl -4(%rsi, %rdx), %r9d
22175 movl %r11d, (%rdi)
22176 - movl %r10d, -4(%rdi, %rdx)
22177 + movl %r9d, -4(%rdi, %rdx)
22178 jmp 13f
22179 11:
22180 cmp $2, %rdx
22181 @@ -189,9 +189,9 @@ ENTRY(memmove)
22182 * Move data from 2 bytes to 3 bytes.
22183 */
22184 movw (%rsi), %r11w
22185 - movw -2(%rsi, %rdx), %r10w
22186 + movw -2(%rsi, %rdx), %r9w
22187 movw %r11w, (%rdi)
22188 - movw %r10w, -2(%rdi, %rdx)
22189 + movw %r9w, -2(%rdi, %rdx)
22190 jmp 13f
22191 12:
22192 cmp $1, %rdx
22193 @@ -202,6 +202,7 @@ ENTRY(memmove)
22194 movb (%rsi), %r11b
22195 movb %r11b, (%rdi)
22196 13:
22197 + pax_force_retaddr
22198 retq
22199 CFI_ENDPROC
22200
22201 @@ -210,6 +211,7 @@ ENTRY(memmove)
22202 /* Forward moving data. */
22203 movq %rdx, %rcx
22204 rep movsb
22205 + pax_force_retaddr
22206 retq
22207 .Lmemmove_end_forward_efs:
22208 .previous
22209 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22210 index 2dcb380..963660a 100644
22211 --- a/arch/x86/lib/memset_64.S
22212 +++ b/arch/x86/lib/memset_64.S
22213 @@ -30,6 +30,7 @@
22214 movl %edx,%ecx
22215 rep stosb
22216 movq %r9,%rax
22217 + pax_force_retaddr
22218 ret
22219 .Lmemset_e:
22220 .previous
22221 @@ -52,6 +53,7 @@
22222 movq %rdx,%rcx
22223 rep stosb
22224 movq %r9,%rax
22225 + pax_force_retaddr
22226 ret
22227 .Lmemset_e_e:
22228 .previous
22229 @@ -59,7 +61,7 @@
22230 ENTRY(memset)
22231 ENTRY(__memset)
22232 CFI_STARTPROC
22233 - movq %rdi,%r10
22234 + movq %rdi,%r11
22235
22236 /* expand byte value */
22237 movzbl %sil,%ecx
22238 @@ -117,7 +119,8 @@ ENTRY(__memset)
22239 jnz .Lloop_1
22240
22241 .Lende:
22242 - movq %r10,%rax
22243 + movq %r11,%rax
22244 + pax_force_retaddr
22245 ret
22246
22247 CFI_RESTORE_STATE
22248 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22249 index c9f2d9b..e7fd2c0 100644
22250 --- a/arch/x86/lib/mmx_32.c
22251 +++ b/arch/x86/lib/mmx_32.c
22252 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22253 {
22254 void *p;
22255 int i;
22256 + unsigned long cr0;
22257
22258 if (unlikely(in_interrupt()))
22259 return __memcpy(to, from, len);
22260 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22261 kernel_fpu_begin();
22262
22263 __asm__ __volatile__ (
22264 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22265 - " prefetch 64(%0)\n"
22266 - " prefetch 128(%0)\n"
22267 - " prefetch 192(%0)\n"
22268 - " prefetch 256(%0)\n"
22269 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22270 + " prefetch 64(%1)\n"
22271 + " prefetch 128(%1)\n"
22272 + " prefetch 192(%1)\n"
22273 + " prefetch 256(%1)\n"
22274 "2: \n"
22275 ".section .fixup, \"ax\"\n"
22276 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22277 + "3: \n"
22278 +
22279 +#ifdef CONFIG_PAX_KERNEXEC
22280 + " movl %%cr0, %0\n"
22281 + " movl %0, %%eax\n"
22282 + " andl $0xFFFEFFFF, %%eax\n"
22283 + " movl %%eax, %%cr0\n"
22284 +#endif
22285 +
22286 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22287 +
22288 +#ifdef CONFIG_PAX_KERNEXEC
22289 + " movl %0, %%cr0\n"
22290 +#endif
22291 +
22292 " jmp 2b\n"
22293 ".previous\n"
22294 _ASM_EXTABLE(1b, 3b)
22295 - : : "r" (from));
22296 + : "=&r" (cr0) : "r" (from) : "ax");
22297
22298 for ( ; i > 5; i--) {
22299 __asm__ __volatile__ (
22300 - "1: prefetch 320(%0)\n"
22301 - "2: movq (%0), %%mm0\n"
22302 - " movq 8(%0), %%mm1\n"
22303 - " movq 16(%0), %%mm2\n"
22304 - " movq 24(%0), %%mm3\n"
22305 - " movq %%mm0, (%1)\n"
22306 - " movq %%mm1, 8(%1)\n"
22307 - " movq %%mm2, 16(%1)\n"
22308 - " movq %%mm3, 24(%1)\n"
22309 - " movq 32(%0), %%mm0\n"
22310 - " movq 40(%0), %%mm1\n"
22311 - " movq 48(%0), %%mm2\n"
22312 - " movq 56(%0), %%mm3\n"
22313 - " movq %%mm0, 32(%1)\n"
22314 - " movq %%mm1, 40(%1)\n"
22315 - " movq %%mm2, 48(%1)\n"
22316 - " movq %%mm3, 56(%1)\n"
22317 + "1: prefetch 320(%1)\n"
22318 + "2: movq (%1), %%mm0\n"
22319 + " movq 8(%1), %%mm1\n"
22320 + " movq 16(%1), %%mm2\n"
22321 + " movq 24(%1), %%mm3\n"
22322 + " movq %%mm0, (%2)\n"
22323 + " movq %%mm1, 8(%2)\n"
22324 + " movq %%mm2, 16(%2)\n"
22325 + " movq %%mm3, 24(%2)\n"
22326 + " movq 32(%1), %%mm0\n"
22327 + " movq 40(%1), %%mm1\n"
22328 + " movq 48(%1), %%mm2\n"
22329 + " movq 56(%1), %%mm3\n"
22330 + " movq %%mm0, 32(%2)\n"
22331 + " movq %%mm1, 40(%2)\n"
22332 + " movq %%mm2, 48(%2)\n"
22333 + " movq %%mm3, 56(%2)\n"
22334 ".section .fixup, \"ax\"\n"
22335 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22336 + "3:\n"
22337 +
22338 +#ifdef CONFIG_PAX_KERNEXEC
22339 + " movl %%cr0, %0\n"
22340 + " movl %0, %%eax\n"
22341 + " andl $0xFFFEFFFF, %%eax\n"
22342 + " movl %%eax, %%cr0\n"
22343 +#endif
22344 +
22345 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22346 +
22347 +#ifdef CONFIG_PAX_KERNEXEC
22348 + " movl %0, %%cr0\n"
22349 +#endif
22350 +
22351 " jmp 2b\n"
22352 ".previous\n"
22353 _ASM_EXTABLE(1b, 3b)
22354 - : : "r" (from), "r" (to) : "memory");
22355 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22356
22357 from += 64;
22358 to += 64;
22359 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22360 static void fast_copy_page(void *to, void *from)
22361 {
22362 int i;
22363 + unsigned long cr0;
22364
22365 kernel_fpu_begin();
22366
22367 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22368 * but that is for later. -AV
22369 */
22370 __asm__ __volatile__(
22371 - "1: prefetch (%0)\n"
22372 - " prefetch 64(%0)\n"
22373 - " prefetch 128(%0)\n"
22374 - " prefetch 192(%0)\n"
22375 - " prefetch 256(%0)\n"
22376 + "1: prefetch (%1)\n"
22377 + " prefetch 64(%1)\n"
22378 + " prefetch 128(%1)\n"
22379 + " prefetch 192(%1)\n"
22380 + " prefetch 256(%1)\n"
22381 "2: \n"
22382 ".section .fixup, \"ax\"\n"
22383 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22384 + "3: \n"
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %%cr0, %0\n"
22388 + " movl %0, %%eax\n"
22389 + " andl $0xFFFEFFFF, %%eax\n"
22390 + " movl %%eax, %%cr0\n"
22391 +#endif
22392 +
22393 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + " movl %0, %%cr0\n"
22397 +#endif
22398 +
22399 " jmp 2b\n"
22400 ".previous\n"
22401 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22402 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22403
22404 for (i = 0; i < (4096-320)/64; i++) {
22405 __asm__ __volatile__ (
22406 - "1: prefetch 320(%0)\n"
22407 - "2: movq (%0), %%mm0\n"
22408 - " movntq %%mm0, (%1)\n"
22409 - " movq 8(%0), %%mm1\n"
22410 - " movntq %%mm1, 8(%1)\n"
22411 - " movq 16(%0), %%mm2\n"
22412 - " movntq %%mm2, 16(%1)\n"
22413 - " movq 24(%0), %%mm3\n"
22414 - " movntq %%mm3, 24(%1)\n"
22415 - " movq 32(%0), %%mm4\n"
22416 - " movntq %%mm4, 32(%1)\n"
22417 - " movq 40(%0), %%mm5\n"
22418 - " movntq %%mm5, 40(%1)\n"
22419 - " movq 48(%0), %%mm6\n"
22420 - " movntq %%mm6, 48(%1)\n"
22421 - " movq 56(%0), %%mm7\n"
22422 - " movntq %%mm7, 56(%1)\n"
22423 + "1: prefetch 320(%1)\n"
22424 + "2: movq (%1), %%mm0\n"
22425 + " movntq %%mm0, (%2)\n"
22426 + " movq 8(%1), %%mm1\n"
22427 + " movntq %%mm1, 8(%2)\n"
22428 + " movq 16(%1), %%mm2\n"
22429 + " movntq %%mm2, 16(%2)\n"
22430 + " movq 24(%1), %%mm3\n"
22431 + " movntq %%mm3, 24(%2)\n"
22432 + " movq 32(%1), %%mm4\n"
22433 + " movntq %%mm4, 32(%2)\n"
22434 + " movq 40(%1), %%mm5\n"
22435 + " movntq %%mm5, 40(%2)\n"
22436 + " movq 48(%1), %%mm6\n"
22437 + " movntq %%mm6, 48(%2)\n"
22438 + " movq 56(%1), %%mm7\n"
22439 + " movntq %%mm7, 56(%2)\n"
22440 ".section .fixup, \"ax\"\n"
22441 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22442 + "3:\n"
22443 +
22444 +#ifdef CONFIG_PAX_KERNEXEC
22445 + " movl %%cr0, %0\n"
22446 + " movl %0, %%eax\n"
22447 + " andl $0xFFFEFFFF, %%eax\n"
22448 + " movl %%eax, %%cr0\n"
22449 +#endif
22450 +
22451 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452 +
22453 +#ifdef CONFIG_PAX_KERNEXEC
22454 + " movl %0, %%cr0\n"
22455 +#endif
22456 +
22457 " jmp 2b\n"
22458 ".previous\n"
22459 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22460 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22461
22462 from += 64;
22463 to += 64;
22464 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22465 static void fast_copy_page(void *to, void *from)
22466 {
22467 int i;
22468 + unsigned long cr0;
22469
22470 kernel_fpu_begin();
22471
22472 __asm__ __volatile__ (
22473 - "1: prefetch (%0)\n"
22474 - " prefetch 64(%0)\n"
22475 - " prefetch 128(%0)\n"
22476 - " prefetch 192(%0)\n"
22477 - " prefetch 256(%0)\n"
22478 + "1: prefetch (%1)\n"
22479 + " prefetch 64(%1)\n"
22480 + " prefetch 128(%1)\n"
22481 + " prefetch 192(%1)\n"
22482 + " prefetch 256(%1)\n"
22483 "2: \n"
22484 ".section .fixup, \"ax\"\n"
22485 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22486 + "3: \n"
22487 +
22488 +#ifdef CONFIG_PAX_KERNEXEC
22489 + " movl %%cr0, %0\n"
22490 + " movl %0, %%eax\n"
22491 + " andl $0xFFFEFFFF, %%eax\n"
22492 + " movl %%eax, %%cr0\n"
22493 +#endif
22494 +
22495 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22496 +
22497 +#ifdef CONFIG_PAX_KERNEXEC
22498 + " movl %0, %%cr0\n"
22499 +#endif
22500 +
22501 " jmp 2b\n"
22502 ".previous\n"
22503 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22504 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22505
22506 for (i = 0; i < 4096/64; i++) {
22507 __asm__ __volatile__ (
22508 - "1: prefetch 320(%0)\n"
22509 - "2: movq (%0), %%mm0\n"
22510 - " movq 8(%0), %%mm1\n"
22511 - " movq 16(%0), %%mm2\n"
22512 - " movq 24(%0), %%mm3\n"
22513 - " movq %%mm0, (%1)\n"
22514 - " movq %%mm1, 8(%1)\n"
22515 - " movq %%mm2, 16(%1)\n"
22516 - " movq %%mm3, 24(%1)\n"
22517 - " movq 32(%0), %%mm0\n"
22518 - " movq 40(%0), %%mm1\n"
22519 - " movq 48(%0), %%mm2\n"
22520 - " movq 56(%0), %%mm3\n"
22521 - " movq %%mm0, 32(%1)\n"
22522 - " movq %%mm1, 40(%1)\n"
22523 - " movq %%mm2, 48(%1)\n"
22524 - " movq %%mm3, 56(%1)\n"
22525 + "1: prefetch 320(%1)\n"
22526 + "2: movq (%1), %%mm0\n"
22527 + " movq 8(%1), %%mm1\n"
22528 + " movq 16(%1), %%mm2\n"
22529 + " movq 24(%1), %%mm3\n"
22530 + " movq %%mm0, (%2)\n"
22531 + " movq %%mm1, 8(%2)\n"
22532 + " movq %%mm2, 16(%2)\n"
22533 + " movq %%mm3, 24(%2)\n"
22534 + " movq 32(%1), %%mm0\n"
22535 + " movq 40(%1), %%mm1\n"
22536 + " movq 48(%1), %%mm2\n"
22537 + " movq 56(%1), %%mm3\n"
22538 + " movq %%mm0, 32(%2)\n"
22539 + " movq %%mm1, 40(%2)\n"
22540 + " movq %%mm2, 48(%2)\n"
22541 + " movq %%mm3, 56(%2)\n"
22542 ".section .fixup, \"ax\"\n"
22543 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22544 + "3:\n"
22545 +
22546 +#ifdef CONFIG_PAX_KERNEXEC
22547 + " movl %%cr0, %0\n"
22548 + " movl %0, %%eax\n"
22549 + " andl $0xFFFEFFFF, %%eax\n"
22550 + " movl %%eax, %%cr0\n"
22551 +#endif
22552 +
22553 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22554 +
22555 +#ifdef CONFIG_PAX_KERNEXEC
22556 + " movl %0, %%cr0\n"
22557 +#endif
22558 +
22559 " jmp 2b\n"
22560 ".previous\n"
22561 _ASM_EXTABLE(1b, 3b)
22562 - : : "r" (from), "r" (to) : "memory");
22563 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22564
22565 from += 64;
22566 to += 64;
22567 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22568 index f6d13ee..aca5f0b 100644
22569 --- a/arch/x86/lib/msr-reg.S
22570 +++ b/arch/x86/lib/msr-reg.S
22571 @@ -3,6 +3,7 @@
22572 #include <asm/dwarf2.h>
22573 #include <asm/asm.h>
22574 #include <asm/msr.h>
22575 +#include <asm/alternative-asm.h>
22576
22577 #ifdef CONFIG_X86_64
22578 /*
22579 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22580 CFI_STARTPROC
22581 pushq_cfi %rbx
22582 pushq_cfi %rbp
22583 - movq %rdi, %r10 /* Save pointer */
22584 + movq %rdi, %r9 /* Save pointer */
22585 xorl %r11d, %r11d /* Return value */
22586 movl (%rdi), %eax
22587 movl 4(%rdi), %ecx
22588 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22589 movl 28(%rdi), %edi
22590 CFI_REMEMBER_STATE
22591 1: \op
22592 -2: movl %eax, (%r10)
22593 +2: movl %eax, (%r9)
22594 movl %r11d, %eax /* Return value */
22595 - movl %ecx, 4(%r10)
22596 - movl %edx, 8(%r10)
22597 - movl %ebx, 12(%r10)
22598 - movl %ebp, 20(%r10)
22599 - movl %esi, 24(%r10)
22600 - movl %edi, 28(%r10)
22601 + movl %ecx, 4(%r9)
22602 + movl %edx, 8(%r9)
22603 + movl %ebx, 12(%r9)
22604 + movl %ebp, 20(%r9)
22605 + movl %esi, 24(%r9)
22606 + movl %edi, 28(%r9)
22607 popq_cfi %rbp
22608 popq_cfi %rbx
22609 + pax_force_retaddr
22610 ret
22611 3:
22612 CFI_RESTORE_STATE
22613 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22614 index 7f951c8..ebd573a 100644
22615 --- a/arch/x86/lib/putuser.S
22616 +++ b/arch/x86/lib/putuser.S
22617 @@ -15,7 +15,9 @@
22618 #include <asm/thread_info.h>
22619 #include <asm/errno.h>
22620 #include <asm/asm.h>
22621 -
22622 +#include <asm/segment.h>
22623 +#include <asm/pgtable.h>
22624 +#include <asm/alternative-asm.h>
22625
22626 /*
22627 * __put_user_X
22628 @@ -29,52 +31,119 @@
22629 * as they get called from within inline assembly.
22630 */
22631
22632 -#define ENTER CFI_STARTPROC ; \
22633 - GET_THREAD_INFO(%_ASM_BX)
22634 -#define EXIT ret ; \
22635 +#define ENTER CFI_STARTPROC
22636 +#define EXIT pax_force_retaddr; ret ; \
22637 CFI_ENDPROC
22638
22639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22640 +#define _DEST %_ASM_CX,%_ASM_BX
22641 +#else
22642 +#define _DEST %_ASM_CX
22643 +#endif
22644 +
22645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22646 +#define __copyuser_seg gs;
22647 +#else
22648 +#define __copyuser_seg
22649 +#endif
22650 +
22651 .text
22652 ENTRY(__put_user_1)
22653 ENTER
22654 +
22655 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22656 + GET_THREAD_INFO(%_ASM_BX)
22657 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22658 jae bad_put_user
22659 -1: movb %al,(%_ASM_CX)
22660 +
22661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22662 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22663 + cmp %_ASM_BX,%_ASM_CX
22664 + jb 1234f
22665 + xor %ebx,%ebx
22666 +1234:
22667 +#endif
22668 +
22669 +#endif
22670 +
22671 +1: __copyuser_seg movb %al,(_DEST)
22672 xor %eax,%eax
22673 EXIT
22674 ENDPROC(__put_user_1)
22675
22676 ENTRY(__put_user_2)
22677 ENTER
22678 +
22679 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22680 + GET_THREAD_INFO(%_ASM_BX)
22681 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22682 sub $1,%_ASM_BX
22683 cmp %_ASM_BX,%_ASM_CX
22684 jae bad_put_user
22685 -2: movw %ax,(%_ASM_CX)
22686 +
22687 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22689 + cmp %_ASM_BX,%_ASM_CX
22690 + jb 1234f
22691 + xor %ebx,%ebx
22692 +1234:
22693 +#endif
22694 +
22695 +#endif
22696 +
22697 +2: __copyuser_seg movw %ax,(_DEST)
22698 xor %eax,%eax
22699 EXIT
22700 ENDPROC(__put_user_2)
22701
22702 ENTRY(__put_user_4)
22703 ENTER
22704 +
22705 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22706 + GET_THREAD_INFO(%_ASM_BX)
22707 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22708 sub $3,%_ASM_BX
22709 cmp %_ASM_BX,%_ASM_CX
22710 jae bad_put_user
22711 -3: movl %eax,(%_ASM_CX)
22712 +
22713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22714 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22715 + cmp %_ASM_BX,%_ASM_CX
22716 + jb 1234f
22717 + xor %ebx,%ebx
22718 +1234:
22719 +#endif
22720 +
22721 +#endif
22722 +
22723 +3: __copyuser_seg movl %eax,(_DEST)
22724 xor %eax,%eax
22725 EXIT
22726 ENDPROC(__put_user_4)
22727
22728 ENTRY(__put_user_8)
22729 ENTER
22730 +
22731 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22732 + GET_THREAD_INFO(%_ASM_BX)
22733 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22734 sub $7,%_ASM_BX
22735 cmp %_ASM_BX,%_ASM_CX
22736 jae bad_put_user
22737 -4: mov %_ASM_AX,(%_ASM_CX)
22738 +
22739 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22740 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22741 + cmp %_ASM_BX,%_ASM_CX
22742 + jb 1234f
22743 + xor %ebx,%ebx
22744 +1234:
22745 +#endif
22746 +
22747 +#endif
22748 +
22749 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22750 #ifdef CONFIG_X86_32
22751 -5: movl %edx,4(%_ASM_CX)
22752 +5: __copyuser_seg movl %edx,4(_DEST)
22753 #endif
22754 xor %eax,%eax
22755 EXIT
22756 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22757 index 1cad221..de671ee 100644
22758 --- a/arch/x86/lib/rwlock.S
22759 +++ b/arch/x86/lib/rwlock.S
22760 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22761 FRAME
22762 0: LOCK_PREFIX
22763 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22764 +
22765 +#ifdef CONFIG_PAX_REFCOUNT
22766 + jno 1234f
22767 + LOCK_PREFIX
22768 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22769 + int $4
22770 +1234:
22771 + _ASM_EXTABLE(1234b, 1234b)
22772 +#endif
22773 +
22774 1: rep; nop
22775 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22776 jne 1b
22777 LOCK_PREFIX
22778 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22779 +
22780 +#ifdef CONFIG_PAX_REFCOUNT
22781 + jno 1234f
22782 + LOCK_PREFIX
22783 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22784 + int $4
22785 +1234:
22786 + _ASM_EXTABLE(1234b, 1234b)
22787 +#endif
22788 +
22789 jnz 0b
22790 ENDFRAME
22791 + pax_force_retaddr
22792 ret
22793 CFI_ENDPROC
22794 END(__write_lock_failed)
22795 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22796 FRAME
22797 0: LOCK_PREFIX
22798 READ_LOCK_SIZE(inc) (%__lock_ptr)
22799 +
22800 +#ifdef CONFIG_PAX_REFCOUNT
22801 + jno 1234f
22802 + LOCK_PREFIX
22803 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22804 + int $4
22805 +1234:
22806 + _ASM_EXTABLE(1234b, 1234b)
22807 +#endif
22808 +
22809 1: rep; nop
22810 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22811 js 1b
22812 LOCK_PREFIX
22813 READ_LOCK_SIZE(dec) (%__lock_ptr)
22814 +
22815 +#ifdef CONFIG_PAX_REFCOUNT
22816 + jno 1234f
22817 + LOCK_PREFIX
22818 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22819 + int $4
22820 +1234:
22821 + _ASM_EXTABLE(1234b, 1234b)
22822 +#endif
22823 +
22824 js 0b
22825 ENDFRAME
22826 + pax_force_retaddr
22827 ret
22828 CFI_ENDPROC
22829 END(__read_lock_failed)
22830 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22831 index 5dff5f0..cadebf4 100644
22832 --- a/arch/x86/lib/rwsem.S
22833 +++ b/arch/x86/lib/rwsem.S
22834 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22835 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22836 CFI_RESTORE __ASM_REG(dx)
22837 restore_common_regs
22838 + pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_down_read_failed)
22842 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22843 movq %rax,%rdi
22844 call rwsem_down_write_failed
22845 restore_common_regs
22846 + pax_force_retaddr
22847 ret
22848 CFI_ENDPROC
22849 ENDPROC(call_rwsem_down_write_failed)
22850 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22851 movq %rax,%rdi
22852 call rwsem_wake
22853 restore_common_regs
22854 -1: ret
22855 +1: pax_force_retaddr
22856 + ret
22857 CFI_ENDPROC
22858 ENDPROC(call_rwsem_wake)
22859
22860 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22861 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22862 CFI_RESTORE __ASM_REG(dx)
22863 restore_common_regs
22864 + pax_force_retaddr
22865 ret
22866 CFI_ENDPROC
22867 ENDPROC(call_rwsem_downgrade_wake)
22868 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22869 index a63efd6..ccecad8 100644
22870 --- a/arch/x86/lib/thunk_64.S
22871 +++ b/arch/x86/lib/thunk_64.S
22872 @@ -8,6 +8,7 @@
22873 #include <linux/linkage.h>
22874 #include <asm/dwarf2.h>
22875 #include <asm/calling.h>
22876 +#include <asm/alternative-asm.h>
22877
22878 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22879 .macro THUNK name, func, put_ret_addr_in_rdi=0
22880 @@ -41,5 +42,6 @@
22881 SAVE_ARGS
22882 restore:
22883 RESTORE_ARGS
22884 + pax_force_retaddr
22885 ret
22886 CFI_ENDPROC
22887 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22888 index 1781b2f..90368dd 100644
22889 --- a/arch/x86/lib/usercopy_32.c
22890 +++ b/arch/x86/lib/usercopy_32.c
22891 @@ -42,10 +42,12 @@ do { \
22892 int __d0; \
22893 might_fault(); \
22894 __asm__ __volatile__( \
22895 + __COPYUSER_SET_ES \
22896 "0: rep; stosl\n" \
22897 " movl %2,%0\n" \
22898 "1: rep; stosb\n" \
22899 "2:\n" \
22900 + __COPYUSER_RESTORE_ES \
22901 ".section .fixup,\"ax\"\n" \
22902 "3: lea 0(%2,%0,4),%0\n" \
22903 " jmp 2b\n" \
22904 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22905
22906 #ifdef CONFIG_X86_INTEL_USERCOPY
22907 static unsigned long
22908 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22909 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22910 {
22911 int d0, d1;
22912 __asm__ __volatile__(
22913 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22914 " .align 2,0x90\n"
22915 "3: movl 0(%4), %%eax\n"
22916 "4: movl 4(%4), %%edx\n"
22917 - "5: movl %%eax, 0(%3)\n"
22918 - "6: movl %%edx, 4(%3)\n"
22919 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22920 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22921 "7: movl 8(%4), %%eax\n"
22922 "8: movl 12(%4),%%edx\n"
22923 - "9: movl %%eax, 8(%3)\n"
22924 - "10: movl %%edx, 12(%3)\n"
22925 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22926 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22927 "11: movl 16(%4), %%eax\n"
22928 "12: movl 20(%4), %%edx\n"
22929 - "13: movl %%eax, 16(%3)\n"
22930 - "14: movl %%edx, 20(%3)\n"
22931 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22932 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22933 "15: movl 24(%4), %%eax\n"
22934 "16: movl 28(%4), %%edx\n"
22935 - "17: movl %%eax, 24(%3)\n"
22936 - "18: movl %%edx, 28(%3)\n"
22937 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22938 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22939 "19: movl 32(%4), %%eax\n"
22940 "20: movl 36(%4), %%edx\n"
22941 - "21: movl %%eax, 32(%3)\n"
22942 - "22: movl %%edx, 36(%3)\n"
22943 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22944 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22945 "23: movl 40(%4), %%eax\n"
22946 "24: movl 44(%4), %%edx\n"
22947 - "25: movl %%eax, 40(%3)\n"
22948 - "26: movl %%edx, 44(%3)\n"
22949 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22950 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22951 "27: movl 48(%4), %%eax\n"
22952 "28: movl 52(%4), %%edx\n"
22953 - "29: movl %%eax, 48(%3)\n"
22954 - "30: movl %%edx, 52(%3)\n"
22955 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22956 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22957 "31: movl 56(%4), %%eax\n"
22958 "32: movl 60(%4), %%edx\n"
22959 - "33: movl %%eax, 56(%3)\n"
22960 - "34: movl %%edx, 60(%3)\n"
22961 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22962 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22963 " addl $-64, %0\n"
22964 " addl $64, %4\n"
22965 " addl $64, %3\n"
22966 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22967 " shrl $2, %0\n"
22968 " andl $3, %%eax\n"
22969 " cld\n"
22970 + __COPYUSER_SET_ES
22971 "99: rep; movsl\n"
22972 "36: movl %%eax, %0\n"
22973 "37: rep; movsb\n"
22974 "100:\n"
22975 + __COPYUSER_RESTORE_ES
22976 ".section .fixup,\"ax\"\n"
22977 "101: lea 0(%%eax,%0,4),%0\n"
22978 " jmp 100b\n"
22979 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22980 }
22981
22982 static unsigned long
22983 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22984 +{
22985 + int d0, d1;
22986 + __asm__ __volatile__(
22987 + " .align 2,0x90\n"
22988 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22989 + " cmpl $67, %0\n"
22990 + " jbe 3f\n"
22991 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22992 + " .align 2,0x90\n"
22993 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22994 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22995 + "5: movl %%eax, 0(%3)\n"
22996 + "6: movl %%edx, 4(%3)\n"
22997 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22998 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22999 + "9: movl %%eax, 8(%3)\n"
23000 + "10: movl %%edx, 12(%3)\n"
23001 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23002 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23003 + "13: movl %%eax, 16(%3)\n"
23004 + "14: movl %%edx, 20(%3)\n"
23005 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23006 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23007 + "17: movl %%eax, 24(%3)\n"
23008 + "18: movl %%edx, 28(%3)\n"
23009 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23010 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23011 + "21: movl %%eax, 32(%3)\n"
23012 + "22: movl %%edx, 36(%3)\n"
23013 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23014 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23015 + "25: movl %%eax, 40(%3)\n"
23016 + "26: movl %%edx, 44(%3)\n"
23017 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23018 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23019 + "29: movl %%eax, 48(%3)\n"
23020 + "30: movl %%edx, 52(%3)\n"
23021 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23022 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23023 + "33: movl %%eax, 56(%3)\n"
23024 + "34: movl %%edx, 60(%3)\n"
23025 + " addl $-64, %0\n"
23026 + " addl $64, %4\n"
23027 + " addl $64, %3\n"
23028 + " cmpl $63, %0\n"
23029 + " ja 1b\n"
23030 + "35: movl %0, %%eax\n"
23031 + " shrl $2, %0\n"
23032 + " andl $3, %%eax\n"
23033 + " cld\n"
23034 + "99: rep; "__copyuser_seg" movsl\n"
23035 + "36: movl %%eax, %0\n"
23036 + "37: rep; "__copyuser_seg" movsb\n"
23037 + "100:\n"
23038 + ".section .fixup,\"ax\"\n"
23039 + "101: lea 0(%%eax,%0,4),%0\n"
23040 + " jmp 100b\n"
23041 + ".previous\n"
23042 + _ASM_EXTABLE(1b,100b)
23043 + _ASM_EXTABLE(2b,100b)
23044 + _ASM_EXTABLE(3b,100b)
23045 + _ASM_EXTABLE(4b,100b)
23046 + _ASM_EXTABLE(5b,100b)
23047 + _ASM_EXTABLE(6b,100b)
23048 + _ASM_EXTABLE(7b,100b)
23049 + _ASM_EXTABLE(8b,100b)
23050 + _ASM_EXTABLE(9b,100b)
23051 + _ASM_EXTABLE(10b,100b)
23052 + _ASM_EXTABLE(11b,100b)
23053 + _ASM_EXTABLE(12b,100b)
23054 + _ASM_EXTABLE(13b,100b)
23055 + _ASM_EXTABLE(14b,100b)
23056 + _ASM_EXTABLE(15b,100b)
23057 + _ASM_EXTABLE(16b,100b)
23058 + _ASM_EXTABLE(17b,100b)
23059 + _ASM_EXTABLE(18b,100b)
23060 + _ASM_EXTABLE(19b,100b)
23061 + _ASM_EXTABLE(20b,100b)
23062 + _ASM_EXTABLE(21b,100b)
23063 + _ASM_EXTABLE(22b,100b)
23064 + _ASM_EXTABLE(23b,100b)
23065 + _ASM_EXTABLE(24b,100b)
23066 + _ASM_EXTABLE(25b,100b)
23067 + _ASM_EXTABLE(26b,100b)
23068 + _ASM_EXTABLE(27b,100b)
23069 + _ASM_EXTABLE(28b,100b)
23070 + _ASM_EXTABLE(29b,100b)
23071 + _ASM_EXTABLE(30b,100b)
23072 + _ASM_EXTABLE(31b,100b)
23073 + _ASM_EXTABLE(32b,100b)
23074 + _ASM_EXTABLE(33b,100b)
23075 + _ASM_EXTABLE(34b,100b)
23076 + _ASM_EXTABLE(35b,100b)
23077 + _ASM_EXTABLE(36b,100b)
23078 + _ASM_EXTABLE(37b,100b)
23079 + _ASM_EXTABLE(99b,101b)
23080 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23081 + : "1"(to), "2"(from), "0"(size)
23082 + : "eax", "edx", "memory");
23083 + return size;
23084 +}
23085 +
23086 +static unsigned long __size_overflow(3)
23087 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23088 {
23089 int d0, d1;
23090 __asm__ __volatile__(
23091 " .align 2,0x90\n"
23092 - "0: movl 32(%4), %%eax\n"
23093 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23094 " cmpl $67, %0\n"
23095 " jbe 2f\n"
23096 - "1: movl 64(%4), %%eax\n"
23097 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23098 " .align 2,0x90\n"
23099 - "2: movl 0(%4), %%eax\n"
23100 - "21: movl 4(%4), %%edx\n"
23101 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23102 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23103 " movl %%eax, 0(%3)\n"
23104 " movl %%edx, 4(%3)\n"
23105 - "3: movl 8(%4), %%eax\n"
23106 - "31: movl 12(%4),%%edx\n"
23107 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23108 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23109 " movl %%eax, 8(%3)\n"
23110 " movl %%edx, 12(%3)\n"
23111 - "4: movl 16(%4), %%eax\n"
23112 - "41: movl 20(%4), %%edx\n"
23113 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23114 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23115 " movl %%eax, 16(%3)\n"
23116 " movl %%edx, 20(%3)\n"
23117 - "10: movl 24(%4), %%eax\n"
23118 - "51: movl 28(%4), %%edx\n"
23119 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23120 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23121 " movl %%eax, 24(%3)\n"
23122 " movl %%edx, 28(%3)\n"
23123 - "11: movl 32(%4), %%eax\n"
23124 - "61: movl 36(%4), %%edx\n"
23125 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23126 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23127 " movl %%eax, 32(%3)\n"
23128 " movl %%edx, 36(%3)\n"
23129 - "12: movl 40(%4), %%eax\n"
23130 - "71: movl 44(%4), %%edx\n"
23131 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23132 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23133 " movl %%eax, 40(%3)\n"
23134 " movl %%edx, 44(%3)\n"
23135 - "13: movl 48(%4), %%eax\n"
23136 - "81: movl 52(%4), %%edx\n"
23137 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23138 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23139 " movl %%eax, 48(%3)\n"
23140 " movl %%edx, 52(%3)\n"
23141 - "14: movl 56(%4), %%eax\n"
23142 - "91: movl 60(%4), %%edx\n"
23143 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23144 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23145 " movl %%eax, 56(%3)\n"
23146 " movl %%edx, 60(%3)\n"
23147 " addl $-64, %0\n"
23148 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23149 " shrl $2, %0\n"
23150 " andl $3, %%eax\n"
23151 " cld\n"
23152 - "6: rep; movsl\n"
23153 + "6: rep; "__copyuser_seg" movsl\n"
23154 " movl %%eax,%0\n"
23155 - "7: rep; movsb\n"
23156 + "7: rep; "__copyuser_seg" movsb\n"
23157 "8:\n"
23158 ".section .fixup,\"ax\"\n"
23159 "9: lea 0(%%eax,%0,4),%0\n"
23160 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23161 * hyoshiok@miraclelinux.com
23162 */
23163
23164 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23165 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23166 const void __user *from, unsigned long size)
23167 {
23168 int d0, d1;
23169
23170 __asm__ __volatile__(
23171 " .align 2,0x90\n"
23172 - "0: movl 32(%4), %%eax\n"
23173 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23174 " cmpl $67, %0\n"
23175 " jbe 2f\n"
23176 - "1: movl 64(%4), %%eax\n"
23177 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23178 " .align 2,0x90\n"
23179 - "2: movl 0(%4), %%eax\n"
23180 - "21: movl 4(%4), %%edx\n"
23181 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23182 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23183 " movnti %%eax, 0(%3)\n"
23184 " movnti %%edx, 4(%3)\n"
23185 - "3: movl 8(%4), %%eax\n"
23186 - "31: movl 12(%4),%%edx\n"
23187 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23188 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23189 " movnti %%eax, 8(%3)\n"
23190 " movnti %%edx, 12(%3)\n"
23191 - "4: movl 16(%4), %%eax\n"
23192 - "41: movl 20(%4), %%edx\n"
23193 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23194 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23195 " movnti %%eax, 16(%3)\n"
23196 " movnti %%edx, 20(%3)\n"
23197 - "10: movl 24(%4), %%eax\n"
23198 - "51: movl 28(%4), %%edx\n"
23199 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23200 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23201 " movnti %%eax, 24(%3)\n"
23202 " movnti %%edx, 28(%3)\n"
23203 - "11: movl 32(%4), %%eax\n"
23204 - "61: movl 36(%4), %%edx\n"
23205 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23206 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23207 " movnti %%eax, 32(%3)\n"
23208 " movnti %%edx, 36(%3)\n"
23209 - "12: movl 40(%4), %%eax\n"
23210 - "71: movl 44(%4), %%edx\n"
23211 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23212 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23213 " movnti %%eax, 40(%3)\n"
23214 " movnti %%edx, 44(%3)\n"
23215 - "13: movl 48(%4), %%eax\n"
23216 - "81: movl 52(%4), %%edx\n"
23217 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23218 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23219 " movnti %%eax, 48(%3)\n"
23220 " movnti %%edx, 52(%3)\n"
23221 - "14: movl 56(%4), %%eax\n"
23222 - "91: movl 60(%4), %%edx\n"
23223 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23224 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23225 " movnti %%eax, 56(%3)\n"
23226 " movnti %%edx, 60(%3)\n"
23227 " addl $-64, %0\n"
23228 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23229 " shrl $2, %0\n"
23230 " andl $3, %%eax\n"
23231 " cld\n"
23232 - "6: rep; movsl\n"
23233 + "6: rep; "__copyuser_seg" movsl\n"
23234 " movl %%eax,%0\n"
23235 - "7: rep; movsb\n"
23236 + "7: rep; "__copyuser_seg" movsb\n"
23237 "8:\n"
23238 ".section .fixup,\"ax\"\n"
23239 "9: lea 0(%%eax,%0,4),%0\n"
23240 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23241 return size;
23242 }
23243
23244 -static unsigned long __copy_user_intel_nocache(void *to,
23245 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23246 const void __user *from, unsigned long size)
23247 {
23248 int d0, d1;
23249
23250 __asm__ __volatile__(
23251 " .align 2,0x90\n"
23252 - "0: movl 32(%4), %%eax\n"
23253 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23254 " cmpl $67, %0\n"
23255 " jbe 2f\n"
23256 - "1: movl 64(%4), %%eax\n"
23257 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23258 " .align 2,0x90\n"
23259 - "2: movl 0(%4), %%eax\n"
23260 - "21: movl 4(%4), %%edx\n"
23261 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23262 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23263 " movnti %%eax, 0(%3)\n"
23264 " movnti %%edx, 4(%3)\n"
23265 - "3: movl 8(%4), %%eax\n"
23266 - "31: movl 12(%4),%%edx\n"
23267 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23268 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23269 " movnti %%eax, 8(%3)\n"
23270 " movnti %%edx, 12(%3)\n"
23271 - "4: movl 16(%4), %%eax\n"
23272 - "41: movl 20(%4), %%edx\n"
23273 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23274 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23275 " movnti %%eax, 16(%3)\n"
23276 " movnti %%edx, 20(%3)\n"
23277 - "10: movl 24(%4), %%eax\n"
23278 - "51: movl 28(%4), %%edx\n"
23279 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23280 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23281 " movnti %%eax, 24(%3)\n"
23282 " movnti %%edx, 28(%3)\n"
23283 - "11: movl 32(%4), %%eax\n"
23284 - "61: movl 36(%4), %%edx\n"
23285 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23286 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23287 " movnti %%eax, 32(%3)\n"
23288 " movnti %%edx, 36(%3)\n"
23289 - "12: movl 40(%4), %%eax\n"
23290 - "71: movl 44(%4), %%edx\n"
23291 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23292 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23293 " movnti %%eax, 40(%3)\n"
23294 " movnti %%edx, 44(%3)\n"
23295 - "13: movl 48(%4), %%eax\n"
23296 - "81: movl 52(%4), %%edx\n"
23297 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23298 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23299 " movnti %%eax, 48(%3)\n"
23300 " movnti %%edx, 52(%3)\n"
23301 - "14: movl 56(%4), %%eax\n"
23302 - "91: movl 60(%4), %%edx\n"
23303 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23304 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23305 " movnti %%eax, 56(%3)\n"
23306 " movnti %%edx, 60(%3)\n"
23307 " addl $-64, %0\n"
23308 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23309 " shrl $2, %0\n"
23310 " andl $3, %%eax\n"
23311 " cld\n"
23312 - "6: rep; movsl\n"
23313 + "6: rep; "__copyuser_seg" movsl\n"
23314 " movl %%eax,%0\n"
23315 - "7: rep; movsb\n"
23316 + "7: rep; "__copyuser_seg" movsb\n"
23317 "8:\n"
23318 ".section .fixup,\"ax\"\n"
23319 "9: lea 0(%%eax,%0,4),%0\n"
23320 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23321 */
23322 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23323 unsigned long size);
23324 -unsigned long __copy_user_intel(void __user *to, const void *from,
23325 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23326 + unsigned long size);
23327 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23328 unsigned long size);
23329 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23330 const void __user *from, unsigned long size);
23331 #endif /* CONFIG_X86_INTEL_USERCOPY */
23332
23333 /* Generic arbitrary sized copy. */
23334 -#define __copy_user(to, from, size) \
23335 +#define __copy_user(to, from, size, prefix, set, restore) \
23336 do { \
23337 int __d0, __d1, __d2; \
23338 __asm__ __volatile__( \
23339 + set \
23340 " cmp $7,%0\n" \
23341 " jbe 1f\n" \
23342 " movl %1,%0\n" \
23343 " negl %0\n" \
23344 " andl $7,%0\n" \
23345 " subl %0,%3\n" \
23346 - "4: rep; movsb\n" \
23347 + "4: rep; "prefix"movsb\n" \
23348 " movl %3,%0\n" \
23349 " shrl $2,%0\n" \
23350 " andl $3,%3\n" \
23351 " .align 2,0x90\n" \
23352 - "0: rep; movsl\n" \
23353 + "0: rep; "prefix"movsl\n" \
23354 " movl %3,%0\n" \
23355 - "1: rep; movsb\n" \
23356 + "1: rep; "prefix"movsb\n" \
23357 "2:\n" \
23358 + restore \
23359 ".section .fixup,\"ax\"\n" \
23360 "5: addl %3,%0\n" \
23361 " jmp 2b\n" \
23362 @@ -537,14 +649,14 @@ do { \
23363 " negl %0\n" \
23364 " andl $7,%0\n" \
23365 " subl %0,%3\n" \
23366 - "4: rep; movsb\n" \
23367 + "4: rep; "__copyuser_seg"movsb\n" \
23368 " movl %3,%0\n" \
23369 " shrl $2,%0\n" \
23370 " andl $3,%3\n" \
23371 " .align 2,0x90\n" \
23372 - "0: rep; movsl\n" \
23373 + "0: rep; "__copyuser_seg"movsl\n" \
23374 " movl %3,%0\n" \
23375 - "1: rep; movsb\n" \
23376 + "1: rep; "__copyuser_seg"movsb\n" \
23377 "2:\n" \
23378 ".section .fixup,\"ax\"\n" \
23379 "5: addl %3,%0\n" \
23380 @@ -627,9 +739,9 @@ survive:
23381 }
23382 #endif
23383 if (movsl_is_ok(to, from, n))
23384 - __copy_user(to, from, n);
23385 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23386 else
23387 - n = __copy_user_intel(to, from, n);
23388 + n = __generic_copy_to_user_intel(to, from, n);
23389 return n;
23390 }
23391 EXPORT_SYMBOL(__copy_to_user_ll);
23392 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23393 unsigned long n)
23394 {
23395 if (movsl_is_ok(to, from, n))
23396 - __copy_user(to, from, n);
23397 + __copy_user(to, from, n, __copyuser_seg, "", "");
23398 else
23399 - n = __copy_user_intel((void __user *)to,
23400 - (const void *)from, n);
23401 + n = __generic_copy_from_user_intel(to, from, n);
23402 return n;
23403 }
23404 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23405 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23406 if (n > 64 && cpu_has_xmm2)
23407 n = __copy_user_intel_nocache(to, from, n);
23408 else
23409 - __copy_user(to, from, n);
23410 + __copy_user(to, from, n, __copyuser_seg, "", "");
23411 #else
23412 - __copy_user(to, from, n);
23413 + __copy_user(to, from, n, __copyuser_seg, "", "");
23414 #endif
23415 return n;
23416 }
23417 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23418
23419 -/**
23420 - * copy_to_user: - Copy a block of data into user space.
23421 - * @to: Destination address, in user space.
23422 - * @from: Source address, in kernel space.
23423 - * @n: Number of bytes to copy.
23424 - *
23425 - * Context: User context only. This function may sleep.
23426 - *
23427 - * Copy data from kernel space to user space.
23428 - *
23429 - * Returns number of bytes that could not be copied.
23430 - * On success, this will be zero.
23431 - */
23432 -unsigned long
23433 -copy_to_user(void __user *to, const void *from, unsigned long n)
23434 -{
23435 - if (access_ok(VERIFY_WRITE, to, n))
23436 - n = __copy_to_user(to, from, n);
23437 - return n;
23438 -}
23439 -EXPORT_SYMBOL(copy_to_user);
23440 -
23441 -/**
23442 - * copy_from_user: - Copy a block of data from user space.
23443 - * @to: Destination address, in kernel space.
23444 - * @from: Source address, in user space.
23445 - * @n: Number of bytes to copy.
23446 - *
23447 - * Context: User context only. This function may sleep.
23448 - *
23449 - * Copy data from user space to kernel space.
23450 - *
23451 - * Returns number of bytes that could not be copied.
23452 - * On success, this will be zero.
23453 - *
23454 - * If some data could not be copied, this function will pad the copied
23455 - * data to the requested size using zero bytes.
23456 - */
23457 -unsigned long
23458 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23459 -{
23460 - if (access_ok(VERIFY_READ, from, n))
23461 - n = __copy_from_user(to, from, n);
23462 - else
23463 - memset(to, 0, n);
23464 - return n;
23465 -}
23466 -EXPORT_SYMBOL(_copy_from_user);
23467 -
23468 void copy_from_user_overflow(void)
23469 {
23470 WARN(1, "Buffer overflow detected!\n");
23471 }
23472 EXPORT_SYMBOL(copy_from_user_overflow);
23473 +
23474 +void copy_to_user_overflow(void)
23475 +{
23476 + WARN(1, "Buffer overflow detected!\n");
23477 +}
23478 +EXPORT_SYMBOL(copy_to_user_overflow);
23479 +
23480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23481 +void __set_fs(mm_segment_t x)
23482 +{
23483 + switch (x.seg) {
23484 + case 0:
23485 + loadsegment(gs, 0);
23486 + break;
23487 + case TASK_SIZE_MAX:
23488 + loadsegment(gs, __USER_DS);
23489 + break;
23490 + case -1UL:
23491 + loadsegment(gs, __KERNEL_DS);
23492 + break;
23493 + default:
23494 + BUG();
23495 + }
23496 + return;
23497 +}
23498 +EXPORT_SYMBOL(__set_fs);
23499 +
23500 +void set_fs(mm_segment_t x)
23501 +{
23502 + current_thread_info()->addr_limit = x;
23503 + __set_fs(x);
23504 +}
23505 +EXPORT_SYMBOL(set_fs);
23506 +#endif
23507 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23508 index e5b130b..6690d31 100644
23509 --- a/arch/x86/lib/usercopy_64.c
23510 +++ b/arch/x86/lib/usercopy_64.c
23511 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23512 {
23513 long __d0;
23514 might_fault();
23515 +
23516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23517 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23518 + addr += PAX_USER_SHADOW_BASE;
23519 +#endif
23520 +
23521 /* no memory constraint because it doesn't change any memory gcc knows
23522 about */
23523 asm volatile(
23524 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23525 }
23526 EXPORT_SYMBOL(clear_user);
23527
23528 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23529 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23530 {
23531 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23532 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23533 - }
23534 - return len;
23535 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23536 +
23537 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23538 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23539 + to += PAX_USER_SHADOW_BASE;
23540 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23541 + from += PAX_USER_SHADOW_BASE;
23542 +#endif
23543 +
23544 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23545 + }
23546 + return len;
23547 }
23548 EXPORT_SYMBOL(copy_in_user);
23549
23550 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23551 * it is not necessary to optimize tail handling.
23552 */
23553 unsigned long
23554 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23556 {
23557 char c;
23558 unsigned zero_len;
23559 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23560 break;
23561 return len;
23562 }
23563 +
23564 +void copy_from_user_overflow(void)
23565 +{
23566 + WARN(1, "Buffer overflow detected!\n");
23567 +}
23568 +EXPORT_SYMBOL(copy_from_user_overflow);
23569 +
23570 +void copy_to_user_overflow(void)
23571 +{
23572 + WARN(1, "Buffer overflow detected!\n");
23573 +}
23574 +EXPORT_SYMBOL(copy_to_user_overflow);
23575 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23576 index 903ec1e..c4166b2 100644
23577 --- a/arch/x86/mm/extable.c
23578 +++ b/arch/x86/mm/extable.c
23579 @@ -6,12 +6,24 @@
23580 static inline unsigned long
23581 ex_insn_addr(const struct exception_table_entry *x)
23582 {
23583 - return (unsigned long)&x->insn + x->insn;
23584 + unsigned long reloc = 0;
23585 +
23586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23587 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23588 +#endif
23589 +
23590 + return (unsigned long)&x->insn + x->insn + reloc;
23591 }
23592 static inline unsigned long
23593 ex_fixup_addr(const struct exception_table_entry *x)
23594 {
23595 - return (unsigned long)&x->fixup + x->fixup;
23596 + unsigned long reloc = 0;
23597 +
23598 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23599 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23600 +#endif
23601 +
23602 + return (unsigned long)&x->fixup + x->fixup + reloc;
23603 }
23604
23605 int fixup_exception(struct pt_regs *regs)
23606 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23607 unsigned long new_ip;
23608
23609 #ifdef CONFIG_PNPBIOS
23610 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23611 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23612 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23613 extern u32 pnp_bios_is_utter_crap;
23614 pnp_bios_is_utter_crap = 1;
23615 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23616 i += 4;
23617 p->fixup -= i;
23618 i += 4;
23619 +
23620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23622 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23624 +#endif
23625 +
23626 }
23627 }
23628
23629 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23630 index 76dcd9d..e9dffde 100644
23631 --- a/arch/x86/mm/fault.c
23632 +++ b/arch/x86/mm/fault.c
23633 @@ -13,11 +13,18 @@
23634 #include <linux/perf_event.h> /* perf_sw_event */
23635 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23636 #include <linux/prefetch.h> /* prefetchw */
23637 +#include <linux/unistd.h>
23638 +#include <linux/compiler.h>
23639
23640 #include <asm/traps.h> /* dotraplinkage, ... */
23641 #include <asm/pgalloc.h> /* pgd_*(), ... */
23642 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23643 #include <asm/fixmap.h> /* VSYSCALL_START */
23644 +#include <asm/tlbflush.h>
23645 +
23646 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23647 +#include <asm/stacktrace.h>
23648 +#endif
23649
23650 /*
23651 * Page fault error code bits:
23652 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23653 int ret = 0;
23654
23655 /* kprobe_running() needs smp_processor_id() */
23656 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23657 + if (kprobes_built_in() && !user_mode(regs)) {
23658 preempt_disable();
23659 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23660 ret = 1;
23661 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23662 return !instr_lo || (instr_lo>>1) == 1;
23663 case 0x00:
23664 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23665 - if (probe_kernel_address(instr, opcode))
23666 + if (user_mode(regs)) {
23667 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23668 + return 0;
23669 + } else if (probe_kernel_address(instr, opcode))
23670 return 0;
23671
23672 *prefetch = (instr_lo == 0xF) &&
23673 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23674 while (instr < max_instr) {
23675 unsigned char opcode;
23676
23677 - if (probe_kernel_address(instr, opcode))
23678 + if (user_mode(regs)) {
23679 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23680 + break;
23681 + } else if (probe_kernel_address(instr, opcode))
23682 break;
23683
23684 instr++;
23685 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23686 force_sig_info(si_signo, &info, tsk);
23687 }
23688
23689 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23690 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23691 +#endif
23692 +
23693 +#ifdef CONFIG_PAX_EMUTRAMP
23694 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23695 +#endif
23696 +
23697 +#ifdef CONFIG_PAX_PAGEEXEC
23698 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23699 +{
23700 + pgd_t *pgd;
23701 + pud_t *pud;
23702 + pmd_t *pmd;
23703 +
23704 + pgd = pgd_offset(mm, address);
23705 + if (!pgd_present(*pgd))
23706 + return NULL;
23707 + pud = pud_offset(pgd, address);
23708 + if (!pud_present(*pud))
23709 + return NULL;
23710 + pmd = pmd_offset(pud, address);
23711 + if (!pmd_present(*pmd))
23712 + return NULL;
23713 + return pmd;
23714 +}
23715 +#endif
23716 +
23717 DEFINE_SPINLOCK(pgd_lock);
23718 LIST_HEAD(pgd_list);
23719
23720 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23721 for (address = VMALLOC_START & PMD_MASK;
23722 address >= TASK_SIZE && address < FIXADDR_TOP;
23723 address += PMD_SIZE) {
23724 +
23725 +#ifdef CONFIG_PAX_PER_CPU_PGD
23726 + unsigned long cpu;
23727 +#else
23728 struct page *page;
23729 +#endif
23730
23731 spin_lock(&pgd_lock);
23732 +
23733 +#ifdef CONFIG_PAX_PER_CPU_PGD
23734 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23735 + pgd_t *pgd = get_cpu_pgd(cpu);
23736 + pmd_t *ret;
23737 +#else
23738 list_for_each_entry(page, &pgd_list, lru) {
23739 + pgd_t *pgd = page_address(page);
23740 spinlock_t *pgt_lock;
23741 pmd_t *ret;
23742
23743 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23744 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23745
23746 spin_lock(pgt_lock);
23747 - ret = vmalloc_sync_one(page_address(page), address);
23748 +#endif
23749 +
23750 + ret = vmalloc_sync_one(pgd, address);
23751 +
23752 +#ifndef CONFIG_PAX_PER_CPU_PGD
23753 spin_unlock(pgt_lock);
23754 +#endif
23755
23756 if (!ret)
23757 break;
23758 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23759 * an interrupt in the middle of a task switch..
23760 */
23761 pgd_paddr = read_cr3();
23762 +
23763 +#ifdef CONFIG_PAX_PER_CPU_PGD
23764 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23765 +#endif
23766 +
23767 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23768 if (!pmd_k)
23769 return -1;
23770 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23771 * happen within a race in page table update. In the later
23772 * case just flush:
23773 */
23774 +
23775 +#ifdef CONFIG_PAX_PER_CPU_PGD
23776 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23777 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23778 +#else
23779 pgd = pgd_offset(current->active_mm, address);
23780 +#endif
23781 +
23782 pgd_ref = pgd_offset_k(address);
23783 if (pgd_none(*pgd_ref))
23784 return -1;
23785 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23786 static int is_errata100(struct pt_regs *regs, unsigned long address)
23787 {
23788 #ifdef CONFIG_X86_64
23789 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23790 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23791 return 1;
23792 #endif
23793 return 0;
23794 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23795 }
23796
23797 static const char nx_warning[] = KERN_CRIT
23798 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23799 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23800
23801 static void
23802 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23803 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23804 if (!oops_may_print())
23805 return;
23806
23807 - if (error_code & PF_INSTR) {
23808 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23809 unsigned int level;
23810
23811 pte_t *pte = lookup_address(address, &level);
23812
23813 if (pte && pte_present(*pte) && !pte_exec(*pte))
23814 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23815 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23816 }
23817
23818 +#ifdef CONFIG_PAX_KERNEXEC
23819 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23820 + if (current->signal->curr_ip)
23821 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23822 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23823 + else
23824 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23825 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23826 + }
23827 +#endif
23828 +
23829 printk(KERN_ALERT "BUG: unable to handle kernel ");
23830 if (address < PAGE_SIZE)
23831 printk(KERN_CONT "NULL pointer dereference");
23832 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23833 }
23834 #endif
23835
23836 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23837 + if (pax_is_fetch_fault(regs, error_code, address)) {
23838 +
23839 +#ifdef CONFIG_PAX_EMUTRAMP
23840 + switch (pax_handle_fetch_fault(regs)) {
23841 + case 2:
23842 + return;
23843 + }
23844 +#endif
23845 +
23846 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23847 + do_group_exit(SIGKILL);
23848 + }
23849 +#endif
23850 +
23851 if (unlikely(show_unhandled_signals))
23852 show_signal_msg(regs, error_code, address, tsk);
23853
23854 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23855 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23856 printk(KERN_ERR
23857 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23858 - tsk->comm, tsk->pid, address);
23859 + tsk->comm, task_pid_nr(tsk), address);
23860 code = BUS_MCEERR_AR;
23861 }
23862 #endif
23863 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23864 return 1;
23865 }
23866
23867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23868 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23869 +{
23870 + pte_t *pte;
23871 + pmd_t *pmd;
23872 + spinlock_t *ptl;
23873 + unsigned char pte_mask;
23874 +
23875 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23876 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23877 + return 0;
23878 +
23879 + /* PaX: it's our fault, let's handle it if we can */
23880 +
23881 + /* PaX: take a look at read faults before acquiring any locks */
23882 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23883 + /* instruction fetch attempt from a protected page in user mode */
23884 + up_read(&mm->mmap_sem);
23885 +
23886 +#ifdef CONFIG_PAX_EMUTRAMP
23887 + switch (pax_handle_fetch_fault(regs)) {
23888 + case 2:
23889 + return 1;
23890 + }
23891 +#endif
23892 +
23893 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894 + do_group_exit(SIGKILL);
23895 + }
23896 +
23897 + pmd = pax_get_pmd(mm, address);
23898 + if (unlikely(!pmd))
23899 + return 0;
23900 +
23901 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23902 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23903 + pte_unmap_unlock(pte, ptl);
23904 + return 0;
23905 + }
23906 +
23907 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23908 + /* write attempt to a protected page in user mode */
23909 + pte_unmap_unlock(pte, ptl);
23910 + return 0;
23911 + }
23912 +
23913 +#ifdef CONFIG_SMP
23914 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23915 +#else
23916 + if (likely(address > get_limit(regs->cs)))
23917 +#endif
23918 + {
23919 + set_pte(pte, pte_mkread(*pte));
23920 + __flush_tlb_one(address);
23921 + pte_unmap_unlock(pte, ptl);
23922 + up_read(&mm->mmap_sem);
23923 + return 1;
23924 + }
23925 +
23926 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23927 +
23928 + /*
23929 + * PaX: fill DTLB with user rights and retry
23930 + */
23931 + __asm__ __volatile__ (
23932 + "orb %2,(%1)\n"
23933 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23934 +/*
23935 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23936 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23937 + * page fault when examined during a TLB load attempt. this is true not only
23938 + * for PTEs holding a non-present entry but also present entries that will
23939 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23940 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23941 + * for our target pages since their PTEs are simply not in the TLBs at all.
23942 +
23943 + * the best thing in omitting it is that we gain around 15-20% speed in the
23944 + * fast path of the page fault handler and can get rid of tracing since we
23945 + * can no longer flush unintended entries.
23946 + */
23947 + "invlpg (%0)\n"
23948 +#endif
23949 + __copyuser_seg"testb $0,(%0)\n"
23950 + "xorb %3,(%1)\n"
23951 + :
23952 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23953 + : "memory", "cc");
23954 + pte_unmap_unlock(pte, ptl);
23955 + up_read(&mm->mmap_sem);
23956 + return 1;
23957 +}
23958 +#endif
23959 +
23960 /*
23961 * Handle a spurious fault caused by a stale TLB entry.
23962 *
23963 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23964 static inline int
23965 access_error(unsigned long error_code, struct vm_area_struct *vma)
23966 {
23967 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23968 + return 1;
23969 +
23970 if (error_code & PF_WRITE) {
23971 /* write, present and write, not present: */
23972 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23973 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23974 {
23975 struct vm_area_struct *vma;
23976 struct task_struct *tsk;
23977 - unsigned long address;
23978 struct mm_struct *mm;
23979 int fault;
23980 int write = error_code & PF_WRITE;
23981 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23982 (write ? FAULT_FLAG_WRITE : 0);
23983
23984 - tsk = current;
23985 - mm = tsk->mm;
23986 -
23987 /* Get the faulting address: */
23988 - address = read_cr2();
23989 + unsigned long address = read_cr2();
23990 +
23991 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23992 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23993 + if (!search_exception_tables(regs->ip)) {
23994 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23995 + bad_area_nosemaphore(regs, error_code, address);
23996 + return;
23997 + }
23998 + if (address < PAX_USER_SHADOW_BASE) {
23999 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24000 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24001 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24002 + } else
24003 + address -= PAX_USER_SHADOW_BASE;
24004 + }
24005 +#endif
24006 +
24007 + tsk = current;
24008 + mm = tsk->mm;
24009
24010 /*
24011 * Detect and handle instructions that would cause a page fault for
24012 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24013 * User-mode registers count as a user access even for any
24014 * potential system fault or CPU buglet:
24015 */
24016 - if (user_mode_vm(regs)) {
24017 + if (user_mode(regs)) {
24018 local_irq_enable();
24019 error_code |= PF_USER;
24020 } else {
24021 @@ -1132,6 +1339,11 @@ retry:
24022 might_sleep();
24023 }
24024
24025 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24026 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24027 + return;
24028 +#endif
24029 +
24030 vma = find_vma(mm, address);
24031 if (unlikely(!vma)) {
24032 bad_area(regs, error_code, address);
24033 @@ -1143,18 +1355,24 @@ retry:
24034 bad_area(regs, error_code, address);
24035 return;
24036 }
24037 - if (error_code & PF_USER) {
24038 - /*
24039 - * Accessing the stack below %sp is always a bug.
24040 - * The large cushion allows instructions like enter
24041 - * and pusha to work. ("enter $65535, $31" pushes
24042 - * 32 pointers and then decrements %sp by 65535.)
24043 - */
24044 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24045 - bad_area(regs, error_code, address);
24046 - return;
24047 - }
24048 + /*
24049 + * Accessing the stack below %sp is always a bug.
24050 + * The large cushion allows instructions like enter
24051 + * and pusha to work. ("enter $65535, $31" pushes
24052 + * 32 pointers and then decrements %sp by 65535.)
24053 + */
24054 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24055 + bad_area(regs, error_code, address);
24056 + return;
24057 }
24058 +
24059 +#ifdef CONFIG_PAX_SEGMEXEC
24060 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24061 + bad_area(regs, error_code, address);
24062 + return;
24063 + }
24064 +#endif
24065 +
24066 if (unlikely(expand_stack(vma, address))) {
24067 bad_area(regs, error_code, address);
24068 return;
24069 @@ -1209,3 +1427,292 @@ good_area:
24070
24071 up_read(&mm->mmap_sem);
24072 }
24073 +
24074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24075 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24076 +{
24077 + struct mm_struct *mm = current->mm;
24078 + unsigned long ip = regs->ip;
24079 +
24080 + if (v8086_mode(regs))
24081 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24082 +
24083 +#ifdef CONFIG_PAX_PAGEEXEC
24084 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24085 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24086 + return true;
24087 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24088 + return true;
24089 + return false;
24090 + }
24091 +#endif
24092 +
24093 +#ifdef CONFIG_PAX_SEGMEXEC
24094 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24095 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24096 + return true;
24097 + return false;
24098 + }
24099 +#endif
24100 +
24101 + return false;
24102 +}
24103 +#endif
24104 +
24105 +#ifdef CONFIG_PAX_EMUTRAMP
24106 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24107 +{
24108 + int err;
24109 +
24110 + do { /* PaX: libffi trampoline emulation */
24111 + unsigned char mov, jmp;
24112 + unsigned int addr1, addr2;
24113 +
24114 +#ifdef CONFIG_X86_64
24115 + if ((regs->ip + 9) >> 32)
24116 + break;
24117 +#endif
24118 +
24119 + err = get_user(mov, (unsigned char __user *)regs->ip);
24120 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24121 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24122 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24123 +
24124 + if (err)
24125 + break;
24126 +
24127 + if (mov == 0xB8 && jmp == 0xE9) {
24128 + regs->ax = addr1;
24129 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24130 + return 2;
24131 + }
24132 + } while (0);
24133 +
24134 + do { /* PaX: gcc trampoline emulation #1 */
24135 + unsigned char mov1, mov2;
24136 + unsigned short jmp;
24137 + unsigned int addr1, addr2;
24138 +
24139 +#ifdef CONFIG_X86_64
24140 + if ((regs->ip + 11) >> 32)
24141 + break;
24142 +#endif
24143 +
24144 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24145 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24146 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24147 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24148 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24149 +
24150 + if (err)
24151 + break;
24152 +
24153 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24154 + regs->cx = addr1;
24155 + regs->ax = addr2;
24156 + regs->ip = addr2;
24157 + return 2;
24158 + }
24159 + } while (0);
24160 +
24161 + do { /* PaX: gcc trampoline emulation #2 */
24162 + unsigned char mov, jmp;
24163 + unsigned int addr1, addr2;
24164 +
24165 +#ifdef CONFIG_X86_64
24166 + if ((regs->ip + 9) >> 32)
24167 + break;
24168 +#endif
24169 +
24170 + err = get_user(mov, (unsigned char __user *)regs->ip);
24171 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24172 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24173 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24174 +
24175 + if (err)
24176 + break;
24177 +
24178 + if (mov == 0xB9 && jmp == 0xE9) {
24179 + regs->cx = addr1;
24180 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24181 + return 2;
24182 + }
24183 + } while (0);
24184 +
24185 + return 1; /* PaX in action */
24186 +}
24187 +
24188 +#ifdef CONFIG_X86_64
24189 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24190 +{
24191 + int err;
24192 +
24193 + do { /* PaX: libffi trampoline emulation */
24194 + unsigned short mov1, mov2, jmp1;
24195 + unsigned char stcclc, jmp2;
24196 + unsigned long addr1, addr2;
24197 +
24198 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24199 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24200 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24201 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24202 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24203 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24204 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24205 +
24206 + if (err)
24207 + break;
24208 +
24209 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24210 + regs->r11 = addr1;
24211 + regs->r10 = addr2;
24212 + if (stcclc == 0xF8)
24213 + regs->flags &= ~X86_EFLAGS_CF;
24214 + else
24215 + regs->flags |= X86_EFLAGS_CF;
24216 + regs->ip = addr1;
24217 + return 2;
24218 + }
24219 + } while (0);
24220 +
24221 + do { /* PaX: gcc trampoline emulation #1 */
24222 + unsigned short mov1, mov2, jmp1;
24223 + unsigned char jmp2;
24224 + unsigned int addr1;
24225 + unsigned long addr2;
24226 +
24227 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24228 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24229 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24230 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24231 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24232 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24233 +
24234 + if (err)
24235 + break;
24236 +
24237 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24238 + regs->r11 = addr1;
24239 + regs->r10 = addr2;
24240 + regs->ip = addr1;
24241 + return 2;
24242 + }
24243 + } while (0);
24244 +
24245 + do { /* PaX: gcc trampoline emulation #2 */
24246 + unsigned short mov1, mov2, jmp1;
24247 + unsigned char jmp2;
24248 + unsigned long addr1, addr2;
24249 +
24250 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24251 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24252 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24253 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24254 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24255 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24256 +
24257 + if (err)
24258 + break;
24259 +
24260 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24261 + regs->r11 = addr1;
24262 + regs->r10 = addr2;
24263 + regs->ip = addr1;
24264 + return 2;
24265 + }
24266 + } while (0);
24267 +
24268 + return 1; /* PaX in action */
24269 +}
24270 +#endif
24271 +
24272 +/*
24273 + * PaX: decide what to do with offenders (regs->ip = fault address)
24274 + *
24275 + * returns 1 when task should be killed
24276 + * 2 when gcc trampoline was detected
24277 + */
24278 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24279 +{
24280 + if (v8086_mode(regs))
24281 + return 1;
24282 +
24283 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24284 + return 1;
24285 +
24286 +#ifdef CONFIG_X86_32
24287 + return pax_handle_fetch_fault_32(regs);
24288 +#else
24289 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24290 + return pax_handle_fetch_fault_32(regs);
24291 + else
24292 + return pax_handle_fetch_fault_64(regs);
24293 +#endif
24294 +}
24295 +#endif
24296 +
24297 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24299 +{
24300 + long i;
24301 +
24302 + printk(KERN_ERR "PAX: bytes at PC: ");
24303 + for (i = 0; i < 20; i++) {
24304 + unsigned char c;
24305 + if (get_user(c, (unsigned char __force_user *)pc+i))
24306 + printk(KERN_CONT "?? ");
24307 + else
24308 + printk(KERN_CONT "%02x ", c);
24309 + }
24310 + printk("\n");
24311 +
24312 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24313 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24314 + unsigned long c;
24315 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24316 +#ifdef CONFIG_X86_32
24317 + printk(KERN_CONT "???????? ");
24318 +#else
24319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24320 + printk(KERN_CONT "???????? ???????? ");
24321 + else
24322 + printk(KERN_CONT "???????????????? ");
24323 +#endif
24324 + } else {
24325 +#ifdef CONFIG_X86_64
24326 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24327 + printk(KERN_CONT "%08x ", (unsigned int)c);
24328 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24329 + } else
24330 +#endif
24331 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24332 + }
24333 + }
24334 + printk("\n");
24335 +}
24336 +#endif
24337 +
24338 +/**
24339 + * probe_kernel_write(): safely attempt to write to a location
24340 + * @dst: address to write to
24341 + * @src: pointer to the data that shall be written
24342 + * @size: size of the data chunk
24343 + *
24344 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24345 + * happens, handle that and return -EFAULT.
24346 + */
24347 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24348 +{
24349 + long ret;
24350 + mm_segment_t old_fs = get_fs();
24351 +
24352 + set_fs(KERNEL_DS);
24353 + pagefault_disable();
24354 + pax_open_kernel();
24355 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24356 + pax_close_kernel();
24357 + pagefault_enable();
24358 + set_fs(old_fs);
24359 +
24360 + return ret ? -EFAULT : 0;
24361 +}
24362 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24363 index dd74e46..7d26398 100644
24364 --- a/arch/x86/mm/gup.c
24365 +++ b/arch/x86/mm/gup.c
24366 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24367 addr = start;
24368 len = (unsigned long) nr_pages << PAGE_SHIFT;
24369 end = start + len;
24370 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24371 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24372 (void __user *)start, len)))
24373 return 0;
24374
24375 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24376 index 6f31ee5..8ee4164 100644
24377 --- a/arch/x86/mm/highmem_32.c
24378 +++ b/arch/x86/mm/highmem_32.c
24379 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24380 idx = type + KM_TYPE_NR*smp_processor_id();
24381 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24382 BUG_ON(!pte_none(*(kmap_pte-idx)));
24383 +
24384 + pax_open_kernel();
24385 set_pte(kmap_pte-idx, mk_pte(page, prot));
24386 + pax_close_kernel();
24387 +
24388 arch_flush_lazy_mmu_mode();
24389
24390 return (void *)vaddr;
24391 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24392 index b91e485..d00e7c9 100644
24393 --- a/arch/x86/mm/hugetlbpage.c
24394 +++ b/arch/x86/mm/hugetlbpage.c
24395 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24396 struct hstate *h = hstate_file(file);
24397 struct mm_struct *mm = current->mm;
24398 struct vm_area_struct *vma;
24399 - unsigned long start_addr;
24400 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24401 +
24402 +#ifdef CONFIG_PAX_SEGMEXEC
24403 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24404 + pax_task_size = SEGMEXEC_TASK_SIZE;
24405 +#endif
24406 +
24407 + pax_task_size -= PAGE_SIZE;
24408
24409 if (len > mm->cached_hole_size) {
24410 - start_addr = mm->free_area_cache;
24411 + start_addr = mm->free_area_cache;
24412 } else {
24413 - start_addr = TASK_UNMAPPED_BASE;
24414 - mm->cached_hole_size = 0;
24415 + start_addr = mm->mmap_base;
24416 + mm->cached_hole_size = 0;
24417 }
24418
24419 full_search:
24420 @@ -291,26 +298,27 @@ full_search:
24421
24422 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24423 /* At this point: (!vma || addr < vma->vm_end). */
24424 - if (TASK_SIZE - len < addr) {
24425 + if (pax_task_size - len < addr) {
24426 /*
24427 * Start a new search - just in case we missed
24428 * some holes.
24429 */
24430 - if (start_addr != TASK_UNMAPPED_BASE) {
24431 - start_addr = TASK_UNMAPPED_BASE;
24432 + if (start_addr != mm->mmap_base) {
24433 + start_addr = mm->mmap_base;
24434 mm->cached_hole_size = 0;
24435 goto full_search;
24436 }
24437 return -ENOMEM;
24438 }
24439 - if (!vma || addr + len <= vma->vm_start) {
24440 - mm->free_area_cache = addr + len;
24441 - return addr;
24442 - }
24443 + if (check_heap_stack_gap(vma, addr, len))
24444 + break;
24445 if (addr + mm->cached_hole_size < vma->vm_start)
24446 mm->cached_hole_size = vma->vm_start - addr;
24447 addr = ALIGN(vma->vm_end, huge_page_size(h));
24448 }
24449 +
24450 + mm->free_area_cache = addr + len;
24451 + return addr;
24452 }
24453
24454 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24455 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24456 struct mm_struct *mm = current->mm;
24457 struct vm_area_struct *vma;
24458 unsigned long base = mm->mmap_base;
24459 - unsigned long addr = addr0;
24460 + unsigned long addr;
24461 unsigned long largest_hole = mm->cached_hole_size;
24462 - unsigned long start_addr;
24463
24464 /* don't allow allocations above current base */
24465 if (mm->free_area_cache > base)
24466 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24467 largest_hole = 0;
24468 mm->free_area_cache = base;
24469 }
24470 -try_again:
24471 - start_addr = mm->free_area_cache;
24472
24473 /* make sure it can fit in the remaining address space */
24474 if (mm->free_area_cache < len)
24475 goto fail;
24476
24477 /* either no address requested or can't fit in requested address hole */
24478 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24479 + addr = mm->free_area_cache - len;
24480 do {
24481 + addr &= huge_page_mask(h);
24482 /*
24483 * Lookup failure means no vma is above this address,
24484 * i.e. return with success:
24485 @@ -351,10 +357,10 @@ try_again:
24486 if (!vma)
24487 return addr;
24488
24489 - if (addr + len <= vma->vm_start) {
24490 + if (check_heap_stack_gap(vma, addr, len)) {
24491 /* remember the address as a hint for next time */
24492 - mm->cached_hole_size = largest_hole;
24493 - return (mm->free_area_cache = addr);
24494 + mm->cached_hole_size = largest_hole;
24495 + return (mm->free_area_cache = addr);
24496 } else if (mm->free_area_cache == vma->vm_end) {
24497 /* pull free_area_cache down to the first hole */
24498 mm->free_area_cache = vma->vm_start;
24499 @@ -363,29 +369,34 @@ try_again:
24500
24501 /* remember the largest hole we saw so far */
24502 if (addr + largest_hole < vma->vm_start)
24503 - largest_hole = vma->vm_start - addr;
24504 + largest_hole = vma->vm_start - addr;
24505
24506 /* try just below the current vma->vm_start */
24507 - addr = (vma->vm_start - len) & huge_page_mask(h);
24508 - } while (len <= vma->vm_start);
24509 + addr = skip_heap_stack_gap(vma, len);
24510 + } while (!IS_ERR_VALUE(addr));
24511
24512 fail:
24513 /*
24514 - * if hint left us with no space for the requested
24515 - * mapping then try again:
24516 - */
24517 - if (start_addr != base) {
24518 - mm->free_area_cache = base;
24519 - largest_hole = 0;
24520 - goto try_again;
24521 - }
24522 - /*
24523 * A failed mmap() very likely causes application failure,
24524 * so fall back to the bottom-up function here. This scenario
24525 * can happen with large stack limits and large mmap()
24526 * allocations.
24527 */
24528 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24529 +
24530 +#ifdef CONFIG_PAX_SEGMEXEC
24531 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24532 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24533 + else
24534 +#endif
24535 +
24536 + mm->mmap_base = TASK_UNMAPPED_BASE;
24537 +
24538 +#ifdef CONFIG_PAX_RANDMMAP
24539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24540 + mm->mmap_base += mm->delta_mmap;
24541 +#endif
24542 +
24543 + mm->free_area_cache = mm->mmap_base;
24544 mm->cached_hole_size = ~0UL;
24545 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24546 len, pgoff, flags);
24547 @@ -393,6 +404,7 @@ fail:
24548 /*
24549 * Restore the topdown base:
24550 */
24551 + mm->mmap_base = base;
24552 mm->free_area_cache = base;
24553 mm->cached_hole_size = ~0UL;
24554
24555 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24556 struct hstate *h = hstate_file(file);
24557 struct mm_struct *mm = current->mm;
24558 struct vm_area_struct *vma;
24559 + unsigned long pax_task_size = TASK_SIZE;
24560
24561 if (len & ~huge_page_mask(h))
24562 return -EINVAL;
24563 - if (len > TASK_SIZE)
24564 +
24565 +#ifdef CONFIG_PAX_SEGMEXEC
24566 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567 + pax_task_size = SEGMEXEC_TASK_SIZE;
24568 +#endif
24569 +
24570 + pax_task_size -= PAGE_SIZE;
24571 +
24572 + if (len > pax_task_size)
24573 return -ENOMEM;
24574
24575 if (flags & MAP_FIXED) {
24576 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24577 if (addr) {
24578 addr = ALIGN(addr, huge_page_size(h));
24579 vma = find_vma(mm, addr);
24580 - if (TASK_SIZE - len >= addr &&
24581 - (!vma || addr + len <= vma->vm_start))
24582 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24583 return addr;
24584 }
24585 if (mm->get_unmapped_area == arch_get_unmapped_area)
24586 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24587 index ab1f6a9..e16d764 100644
24588 --- a/arch/x86/mm/init.c
24589 +++ b/arch/x86/mm/init.c
24590 @@ -16,6 +16,8 @@
24591 #include <asm/tlb.h>
24592 #include <asm/proto.h>
24593 #include <asm/dma.h> /* for MAX_DMA_PFN */
24594 +#include <asm/desc.h>
24595 +#include <asm/bios_ebda.h>
24596
24597 unsigned long __initdata pgt_buf_start;
24598 unsigned long __meminitdata pgt_buf_end;
24599 @@ -38,7 +40,7 @@ struct map_range {
24600 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24601 int use_pse, int use_gbpages)
24602 {
24603 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24604 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24605 phys_addr_t base;
24606
24607 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24608 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24609 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24610 * mmio resources as well as potential bios/acpi data regions.
24611 */
24612 +
24613 +#ifdef CONFIG_GRKERNSEC_KMEM
24614 +static unsigned int ebda_start __read_only;
24615 +static unsigned int ebda_end __read_only;
24616 +#endif
24617 +
24618 int devmem_is_allowed(unsigned long pagenr)
24619 {
24620 - if (pagenr < 256)
24621 +#ifdef CONFIG_GRKERNSEC_KMEM
24622 + /* allow BDA */
24623 + if (!pagenr)
24624 return 1;
24625 + /* allow EBDA */
24626 + if (pagenr >= ebda_start && pagenr < ebda_end)
24627 + return 1;
24628 +#else
24629 + if (!pagenr)
24630 + return 1;
24631 +#ifdef CONFIG_VM86
24632 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24633 + return 1;
24634 +#endif
24635 +#endif
24636 +
24637 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24638 + return 1;
24639 +#ifdef CONFIG_GRKERNSEC_KMEM
24640 + /* throw out everything else below 1MB */
24641 + if (pagenr <= 256)
24642 + return 0;
24643 +#endif
24644 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24645 return 0;
24646 if (!page_is_ram(pagenr))
24647 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24648 #endif
24649 }
24650
24651 +#ifdef CONFIG_GRKERNSEC_KMEM
24652 +static inline void gr_init_ebda(void)
24653 +{
24654 + unsigned int ebda_addr;
24655 + unsigned int ebda_size = 0;
24656 +
24657 + ebda_addr = get_bios_ebda();
24658 + if (ebda_addr) {
24659 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24660 + ebda_size <<= 10;
24661 + }
24662 + if (ebda_addr && ebda_size) {
24663 + ebda_start = ebda_addr >> PAGE_SHIFT;
24664 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24665 + } else {
24666 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24667 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24668 + }
24669 +}
24670 +#else
24671 +static inline void gr_init_ebda(void) { }
24672 +#endif
24673 +
24674 void free_initmem(void)
24675 {
24676 +#ifdef CONFIG_PAX_KERNEXEC
24677 +#ifdef CONFIG_X86_32
24678 + /* PaX: limit KERNEL_CS to actual size */
24679 + unsigned long addr, limit;
24680 + struct desc_struct d;
24681 + int cpu;
24682 +#else
24683 + pgd_t *pgd;
24684 + pud_t *pud;
24685 + pmd_t *pmd;
24686 + unsigned long addr, end;
24687 +#endif
24688 +#endif
24689 +
24690 + gr_init_ebda();
24691 +
24692 +#ifdef CONFIG_PAX_KERNEXEC
24693 +#ifdef CONFIG_X86_32
24694 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24695 + limit = (limit - 1UL) >> PAGE_SHIFT;
24696 +
24697 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24698 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24699 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24700 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24701 + }
24702 +
24703 + /* PaX: make KERNEL_CS read-only */
24704 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24705 + if (!paravirt_enabled())
24706 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24707 +/*
24708 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24709 + pgd = pgd_offset_k(addr);
24710 + pud = pud_offset(pgd, addr);
24711 + pmd = pmd_offset(pud, addr);
24712 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24713 + }
24714 +*/
24715 +#ifdef CONFIG_X86_PAE
24716 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24717 +/*
24718 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24719 + pgd = pgd_offset_k(addr);
24720 + pud = pud_offset(pgd, addr);
24721 + pmd = pmd_offset(pud, addr);
24722 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24723 + }
24724 +*/
24725 +#endif
24726 +
24727 +#ifdef CONFIG_MODULES
24728 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24729 +#endif
24730 +
24731 +#else
24732 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24733 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24734 + pgd = pgd_offset_k(addr);
24735 + pud = pud_offset(pgd, addr);
24736 + pmd = pmd_offset(pud, addr);
24737 + if (!pmd_present(*pmd))
24738 + continue;
24739 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24740 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24741 + else
24742 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24743 + }
24744 +
24745 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24746 + end = addr + KERNEL_IMAGE_SIZE;
24747 + for (; addr < end; addr += PMD_SIZE) {
24748 + pgd = pgd_offset_k(addr);
24749 + pud = pud_offset(pgd, addr);
24750 + pmd = pmd_offset(pud, addr);
24751 + if (!pmd_present(*pmd))
24752 + continue;
24753 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24754 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24755 + }
24756 +#endif
24757 +
24758 + flush_tlb_all();
24759 +#endif
24760 +
24761 free_init_pages("unused kernel memory",
24762 (unsigned long)(&__init_begin),
24763 (unsigned long)(&__init_end));
24764 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24765 index 575d86f..4987469 100644
24766 --- a/arch/x86/mm/init_32.c
24767 +++ b/arch/x86/mm/init_32.c
24768 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24769 }
24770
24771 /*
24772 - * Creates a middle page table and puts a pointer to it in the
24773 - * given global directory entry. This only returns the gd entry
24774 - * in non-PAE compilation mode, since the middle layer is folded.
24775 - */
24776 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24777 -{
24778 - pud_t *pud;
24779 - pmd_t *pmd_table;
24780 -
24781 -#ifdef CONFIG_X86_PAE
24782 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24783 - if (after_bootmem)
24784 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24785 - else
24786 - pmd_table = (pmd_t *)alloc_low_page();
24787 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24788 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24789 - pud = pud_offset(pgd, 0);
24790 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24791 -
24792 - return pmd_table;
24793 - }
24794 -#endif
24795 - pud = pud_offset(pgd, 0);
24796 - pmd_table = pmd_offset(pud, 0);
24797 -
24798 - return pmd_table;
24799 -}
24800 -
24801 -/*
24802 * Create a page table and place a pointer to it in a middle page
24803 * directory entry:
24804 */
24805 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24806 page_table = (pte_t *)alloc_low_page();
24807
24808 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24809 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24810 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24811 +#else
24812 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24813 +#endif
24814 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24815 }
24816
24817 return pte_offset_kernel(pmd, 0);
24818 }
24819
24820 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24821 +{
24822 + pud_t *pud;
24823 + pmd_t *pmd_table;
24824 +
24825 + pud = pud_offset(pgd, 0);
24826 + pmd_table = pmd_offset(pud, 0);
24827 +
24828 + return pmd_table;
24829 +}
24830 +
24831 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24832 {
24833 int pgd_idx = pgd_index(vaddr);
24834 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24835 int pgd_idx, pmd_idx;
24836 unsigned long vaddr;
24837 pgd_t *pgd;
24838 + pud_t *pud;
24839 pmd_t *pmd;
24840 pte_t *pte = NULL;
24841
24842 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24843 pgd = pgd_base + pgd_idx;
24844
24845 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24846 - pmd = one_md_table_init(pgd);
24847 - pmd = pmd + pmd_index(vaddr);
24848 + pud = pud_offset(pgd, vaddr);
24849 + pmd = pmd_offset(pud, vaddr);
24850 +
24851 +#ifdef CONFIG_X86_PAE
24852 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24853 +#endif
24854 +
24855 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24856 pmd++, pmd_idx++) {
24857 pte = page_table_kmap_check(one_page_table_init(pmd),
24858 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24859 }
24860 }
24861
24862 -static inline int is_kernel_text(unsigned long addr)
24863 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24864 {
24865 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24866 - return 1;
24867 - return 0;
24868 + if ((start > ktla_ktva((unsigned long)_etext) ||
24869 + end <= ktla_ktva((unsigned long)_stext)) &&
24870 + (start > ktla_ktva((unsigned long)_einittext) ||
24871 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24872 +
24873 +#ifdef CONFIG_ACPI_SLEEP
24874 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24875 +#endif
24876 +
24877 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24878 + return 0;
24879 + return 1;
24880 }
24881
24882 /*
24883 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24884 unsigned long last_map_addr = end;
24885 unsigned long start_pfn, end_pfn;
24886 pgd_t *pgd_base = swapper_pg_dir;
24887 - int pgd_idx, pmd_idx, pte_ofs;
24888 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24889 unsigned long pfn;
24890 pgd_t *pgd;
24891 + pud_t *pud;
24892 pmd_t *pmd;
24893 pte_t *pte;
24894 unsigned pages_2m, pages_4k;
24895 @@ -280,8 +281,13 @@ repeat:
24896 pfn = start_pfn;
24897 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24898 pgd = pgd_base + pgd_idx;
24899 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24900 - pmd = one_md_table_init(pgd);
24901 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24902 + pud = pud_offset(pgd, 0);
24903 + pmd = pmd_offset(pud, 0);
24904 +
24905 +#ifdef CONFIG_X86_PAE
24906 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24907 +#endif
24908
24909 if (pfn >= end_pfn)
24910 continue;
24911 @@ -293,14 +299,13 @@ repeat:
24912 #endif
24913 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24914 pmd++, pmd_idx++) {
24915 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24916 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24917
24918 /*
24919 * Map with big pages if possible, otherwise
24920 * create normal page tables:
24921 */
24922 if (use_pse) {
24923 - unsigned int addr2;
24924 pgprot_t prot = PAGE_KERNEL_LARGE;
24925 /*
24926 * first pass will use the same initial
24927 @@ -310,11 +315,7 @@ repeat:
24928 __pgprot(PTE_IDENT_ATTR |
24929 _PAGE_PSE);
24930
24931 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24932 - PAGE_OFFSET + PAGE_SIZE-1;
24933 -
24934 - if (is_kernel_text(addr) ||
24935 - is_kernel_text(addr2))
24936 + if (is_kernel_text(address, address + PMD_SIZE))
24937 prot = PAGE_KERNEL_LARGE_EXEC;
24938
24939 pages_2m++;
24940 @@ -331,7 +332,7 @@ repeat:
24941 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24942 pte += pte_ofs;
24943 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24944 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24945 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24946 pgprot_t prot = PAGE_KERNEL;
24947 /*
24948 * first pass will use the same initial
24949 @@ -339,7 +340,7 @@ repeat:
24950 */
24951 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24952
24953 - if (is_kernel_text(addr))
24954 + if (is_kernel_text(address, address + PAGE_SIZE))
24955 prot = PAGE_KERNEL_EXEC;
24956
24957 pages_4k++;
24958 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24959
24960 pud = pud_offset(pgd, va);
24961 pmd = pmd_offset(pud, va);
24962 - if (!pmd_present(*pmd))
24963 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24964 break;
24965
24966 pte = pte_offset_kernel(pmd, va);
24967 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24968
24969 static void __init pagetable_init(void)
24970 {
24971 - pgd_t *pgd_base = swapper_pg_dir;
24972 -
24973 - permanent_kmaps_init(pgd_base);
24974 + permanent_kmaps_init(swapper_pg_dir);
24975 }
24976
24977 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24978 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24979 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24980
24981 /* user-defined highmem size */
24982 @@ -734,6 +733,12 @@ void __init mem_init(void)
24983
24984 pci_iommu_alloc();
24985
24986 +#ifdef CONFIG_PAX_PER_CPU_PGD
24987 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24988 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24989 + KERNEL_PGD_PTRS);
24990 +#endif
24991 +
24992 #ifdef CONFIG_FLATMEM
24993 BUG_ON(!mem_map);
24994 #endif
24995 @@ -760,7 +765,7 @@ void __init mem_init(void)
24996 reservedpages++;
24997
24998 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24999 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25000 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25001 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25002
25003 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25004 @@ -801,10 +806,10 @@ void __init mem_init(void)
25005 ((unsigned long)&__init_end -
25006 (unsigned long)&__init_begin) >> 10,
25007
25008 - (unsigned long)&_etext, (unsigned long)&_edata,
25009 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25010 + (unsigned long)&_sdata, (unsigned long)&_edata,
25011 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25012
25013 - (unsigned long)&_text, (unsigned long)&_etext,
25014 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25015 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25016
25017 /*
25018 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25019 if (!kernel_set_to_readonly)
25020 return;
25021
25022 + start = ktla_ktva(start);
25023 pr_debug("Set kernel text: %lx - %lx for read write\n",
25024 start, start+size);
25025
25026 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25027 if (!kernel_set_to_readonly)
25028 return;
25029
25030 + start = ktla_ktva(start);
25031 pr_debug("Set kernel text: %lx - %lx for read only\n",
25032 start, start+size);
25033
25034 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25035 unsigned long start = PFN_ALIGN(_text);
25036 unsigned long size = PFN_ALIGN(_etext) - start;
25037
25038 + start = ktla_ktva(start);
25039 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25040 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25041 size >> 10);
25042 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25043 index 2b6b4a3..c17210d 100644
25044 --- a/arch/x86/mm/init_64.c
25045 +++ b/arch/x86/mm/init_64.c
25046 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25047 * around without checking the pgd every time.
25048 */
25049
25050 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25051 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25052 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25053
25054 int force_personality32;
25055 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25056
25057 for (address = start; address <= end; address += PGDIR_SIZE) {
25058 const pgd_t *pgd_ref = pgd_offset_k(address);
25059 +
25060 +#ifdef CONFIG_PAX_PER_CPU_PGD
25061 + unsigned long cpu;
25062 +#else
25063 struct page *page;
25064 +#endif
25065
25066 if (pgd_none(*pgd_ref))
25067 continue;
25068
25069 spin_lock(&pgd_lock);
25070 +
25071 +#ifdef CONFIG_PAX_PER_CPU_PGD
25072 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25073 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25074 +#else
25075 list_for_each_entry(page, &pgd_list, lru) {
25076 pgd_t *pgd;
25077 spinlock_t *pgt_lock;
25078 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25079 /* the pgt_lock only for Xen */
25080 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25081 spin_lock(pgt_lock);
25082 +#endif
25083
25084 if (pgd_none(*pgd))
25085 set_pgd(pgd, *pgd_ref);
25086 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25087 BUG_ON(pgd_page_vaddr(*pgd)
25088 != pgd_page_vaddr(*pgd_ref));
25089
25090 +#ifndef CONFIG_PAX_PER_CPU_PGD
25091 spin_unlock(pgt_lock);
25092 +#endif
25093 +
25094 }
25095 spin_unlock(&pgd_lock);
25096 }
25097 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25098 {
25099 if (pgd_none(*pgd)) {
25100 pud_t *pud = (pud_t *)spp_getpage();
25101 - pgd_populate(&init_mm, pgd, pud);
25102 + pgd_populate_kernel(&init_mm, pgd, pud);
25103 if (pud != pud_offset(pgd, 0))
25104 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25105 pud, pud_offset(pgd, 0));
25106 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25107 {
25108 if (pud_none(*pud)) {
25109 pmd_t *pmd = (pmd_t *) spp_getpage();
25110 - pud_populate(&init_mm, pud, pmd);
25111 + pud_populate_kernel(&init_mm, pud, pmd);
25112 if (pmd != pmd_offset(pud, 0))
25113 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25114 pmd, pmd_offset(pud, 0));
25115 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25116 pmd = fill_pmd(pud, vaddr);
25117 pte = fill_pte(pmd, vaddr);
25118
25119 + pax_open_kernel();
25120 set_pte(pte, new_pte);
25121 + pax_close_kernel();
25122
25123 /*
25124 * It's enough to flush this one mapping.
25125 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25126 pgd = pgd_offset_k((unsigned long)__va(phys));
25127 if (pgd_none(*pgd)) {
25128 pud = (pud_t *) spp_getpage();
25129 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25130 - _PAGE_USER));
25131 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25132 }
25133 pud = pud_offset(pgd, (unsigned long)__va(phys));
25134 if (pud_none(*pud)) {
25135 pmd = (pmd_t *) spp_getpage();
25136 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25137 - _PAGE_USER));
25138 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25139 }
25140 pmd = pmd_offset(pud, phys);
25141 BUG_ON(!pmd_none(*pmd));
25142 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25143 if (pfn >= pgt_buf_top)
25144 panic("alloc_low_page: ran out of memory");
25145
25146 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25147 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25148 clear_page(adr);
25149 *phys = pfn * PAGE_SIZE;
25150 return adr;
25151 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25152
25153 phys = __pa(virt);
25154 left = phys & (PAGE_SIZE - 1);
25155 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25156 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25157 adr = (void *)(((unsigned long)adr) | left);
25158
25159 return adr;
25160 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25161 unmap_low_page(pmd);
25162
25163 spin_lock(&init_mm.page_table_lock);
25164 - pud_populate(&init_mm, pud, __va(pmd_phys));
25165 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25166 spin_unlock(&init_mm.page_table_lock);
25167 }
25168 __flush_tlb_all();
25169 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25170 unmap_low_page(pud);
25171
25172 spin_lock(&init_mm.page_table_lock);
25173 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25174 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25175 spin_unlock(&init_mm.page_table_lock);
25176 pgd_changed = true;
25177 }
25178 @@ -686,6 +700,12 @@ void __init mem_init(void)
25179
25180 pci_iommu_alloc();
25181
25182 +#ifdef CONFIG_PAX_PER_CPU_PGD
25183 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25184 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25185 + KERNEL_PGD_PTRS);
25186 +#endif
25187 +
25188 /* clear_bss() already clear the empty_zero_page */
25189
25190 reservedpages = 0;
25191 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25192 static struct vm_area_struct gate_vma = {
25193 .vm_start = VSYSCALL_START,
25194 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25195 - .vm_page_prot = PAGE_READONLY_EXEC,
25196 - .vm_flags = VM_READ | VM_EXEC
25197 + .vm_page_prot = PAGE_READONLY,
25198 + .vm_flags = VM_READ
25199 };
25200
25201 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25202 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25203
25204 const char *arch_vma_name(struct vm_area_struct *vma)
25205 {
25206 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25207 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25208 return "[vdso]";
25209 if (vma == &gate_vma)
25210 return "[vsyscall]";
25211 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25212 index 7b179b4..6bd1777 100644
25213 --- a/arch/x86/mm/iomap_32.c
25214 +++ b/arch/x86/mm/iomap_32.c
25215 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25216 type = kmap_atomic_idx_push();
25217 idx = type + KM_TYPE_NR * smp_processor_id();
25218 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25219 +
25220 + pax_open_kernel();
25221 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25222 + pax_close_kernel();
25223 +
25224 arch_flush_lazy_mmu_mode();
25225
25226 return (void *)vaddr;
25227 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25228 index 78fe3f1..8293b6f 100644
25229 --- a/arch/x86/mm/ioremap.c
25230 +++ b/arch/x86/mm/ioremap.c
25231 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25232 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25233 int is_ram = page_is_ram(pfn);
25234
25235 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25236 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25237 return NULL;
25238 WARN_ON_ONCE(is_ram);
25239 }
25240 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25241
25242 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25243 if (page_is_ram(start >> PAGE_SHIFT))
25244 +#ifdef CONFIG_HIGHMEM
25245 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25246 +#endif
25247 return __va(phys);
25248
25249 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25250 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25251 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25252
25253 static __initdata int after_paging_init;
25254 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25255 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25256
25257 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25258 {
25259 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25260 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25261
25262 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25263 - memset(bm_pte, 0, sizeof(bm_pte));
25264 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25265 + pmd_populate_user(&init_mm, pmd, bm_pte);
25266
25267 /*
25268 * The boot-ioremap range spans multiple pmds, for which
25269 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25270 index d87dd6d..bf3fa66 100644
25271 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25272 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25273 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25274 * memory (e.g. tracked pages)? For now, we need this to avoid
25275 * invoking kmemcheck for PnP BIOS calls.
25276 */
25277 - if (regs->flags & X86_VM_MASK)
25278 + if (v8086_mode(regs))
25279 return false;
25280 - if (regs->cs != __KERNEL_CS)
25281 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25282 return false;
25283
25284 pte = kmemcheck_pte_lookup(address);
25285 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25286 index 845df68..1d8d29f 100644
25287 --- a/arch/x86/mm/mmap.c
25288 +++ b/arch/x86/mm/mmap.c
25289 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25290 * Leave an at least ~128 MB hole with possible stack randomization.
25291 */
25292 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25293 -#define MAX_GAP (TASK_SIZE/6*5)
25294 +#define MAX_GAP (pax_task_size/6*5)
25295
25296 static int mmap_is_legacy(void)
25297 {
25298 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25299 return rnd << PAGE_SHIFT;
25300 }
25301
25302 -static unsigned long mmap_base(void)
25303 +static unsigned long mmap_base(struct mm_struct *mm)
25304 {
25305 unsigned long gap = rlimit(RLIMIT_STACK);
25306 + unsigned long pax_task_size = TASK_SIZE;
25307 +
25308 +#ifdef CONFIG_PAX_SEGMEXEC
25309 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25310 + pax_task_size = SEGMEXEC_TASK_SIZE;
25311 +#endif
25312
25313 if (gap < MIN_GAP)
25314 gap = MIN_GAP;
25315 else if (gap > MAX_GAP)
25316 gap = MAX_GAP;
25317
25318 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25319 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25320 }
25321
25322 /*
25323 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25324 * does, but not when emulating X86_32
25325 */
25326 -static unsigned long mmap_legacy_base(void)
25327 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25328 {
25329 - if (mmap_is_ia32())
25330 + if (mmap_is_ia32()) {
25331 +
25332 +#ifdef CONFIG_PAX_SEGMEXEC
25333 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25334 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25335 + else
25336 +#endif
25337 +
25338 return TASK_UNMAPPED_BASE;
25339 - else
25340 + } else
25341 return TASK_UNMAPPED_BASE + mmap_rnd();
25342 }
25343
25344 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25345 void arch_pick_mmap_layout(struct mm_struct *mm)
25346 {
25347 if (mmap_is_legacy()) {
25348 - mm->mmap_base = mmap_legacy_base();
25349 + mm->mmap_base = mmap_legacy_base(mm);
25350 +
25351 +#ifdef CONFIG_PAX_RANDMMAP
25352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25353 + mm->mmap_base += mm->delta_mmap;
25354 +#endif
25355 +
25356 mm->get_unmapped_area = arch_get_unmapped_area;
25357 mm->unmap_area = arch_unmap_area;
25358 } else {
25359 - mm->mmap_base = mmap_base();
25360 + mm->mmap_base = mmap_base(mm);
25361 +
25362 +#ifdef CONFIG_PAX_RANDMMAP
25363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25364 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25365 +#endif
25366 +
25367 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25368 mm->unmap_area = arch_unmap_area_topdown;
25369 }
25370 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25371 index dc0b727..dc9d71a 100644
25372 --- a/arch/x86/mm/mmio-mod.c
25373 +++ b/arch/x86/mm/mmio-mod.c
25374 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25375 break;
25376 default:
25377 {
25378 - unsigned char *ip = (unsigned char *)instptr;
25379 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25380 my_trace->opcode = MMIO_UNKNOWN_OP;
25381 my_trace->width = 0;
25382 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25383 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25384 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25385 void __iomem *addr)
25386 {
25387 - static atomic_t next_id;
25388 + static atomic_unchecked_t next_id;
25389 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25390 /* These are page-unaligned. */
25391 struct mmiotrace_map map = {
25392 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25393 .private = trace
25394 },
25395 .phys = offset,
25396 - .id = atomic_inc_return(&next_id)
25397 + .id = atomic_inc_return_unchecked(&next_id)
25398 };
25399 map.map_id = trace->id;
25400
25401 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25402 index b008656..773eac2 100644
25403 --- a/arch/x86/mm/pageattr-test.c
25404 +++ b/arch/x86/mm/pageattr-test.c
25405 @@ -36,7 +36,7 @@ enum {
25406
25407 static int pte_testbit(pte_t pte)
25408 {
25409 - return pte_flags(pte) & _PAGE_UNUSED1;
25410 + return pte_flags(pte) & _PAGE_CPA_TEST;
25411 }
25412
25413 struct split_state {
25414 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25415 index a718e0d..45efc32 100644
25416 --- a/arch/x86/mm/pageattr.c
25417 +++ b/arch/x86/mm/pageattr.c
25418 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25419 */
25420 #ifdef CONFIG_PCI_BIOS
25421 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25422 - pgprot_val(forbidden) |= _PAGE_NX;
25423 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25424 #endif
25425
25426 /*
25427 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25428 * Does not cover __inittext since that is gone later on. On
25429 * 64bit we do not enforce !NX on the low mapping
25430 */
25431 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25432 - pgprot_val(forbidden) |= _PAGE_NX;
25433 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25434 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25435
25436 +#ifdef CONFIG_DEBUG_RODATA
25437 /*
25438 * The .rodata section needs to be read-only. Using the pfn
25439 * catches all aliases.
25440 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25441 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25442 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25443 pgprot_val(forbidden) |= _PAGE_RW;
25444 +#endif
25445
25446 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25447 /*
25448 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25449 }
25450 #endif
25451
25452 +#ifdef CONFIG_PAX_KERNEXEC
25453 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25454 + pgprot_val(forbidden) |= _PAGE_RW;
25455 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25456 + }
25457 +#endif
25458 +
25459 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25460
25461 return prot;
25462 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25463 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25464 {
25465 /* change init_mm */
25466 + pax_open_kernel();
25467 set_pte_atomic(kpte, pte);
25468 +
25469 #ifdef CONFIG_X86_32
25470 if (!SHARED_KERNEL_PMD) {
25471 +
25472 +#ifdef CONFIG_PAX_PER_CPU_PGD
25473 + unsigned long cpu;
25474 +#else
25475 struct page *page;
25476 +#endif
25477
25478 +#ifdef CONFIG_PAX_PER_CPU_PGD
25479 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25480 + pgd_t *pgd = get_cpu_pgd(cpu);
25481 +#else
25482 list_for_each_entry(page, &pgd_list, lru) {
25483 - pgd_t *pgd;
25484 + pgd_t *pgd = (pgd_t *)page_address(page);
25485 +#endif
25486 +
25487 pud_t *pud;
25488 pmd_t *pmd;
25489
25490 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25491 + pgd += pgd_index(address);
25492 pud = pud_offset(pgd, address);
25493 pmd = pmd_offset(pud, address);
25494 set_pte_atomic((pte_t *)pmd, pte);
25495 }
25496 }
25497 #endif
25498 + pax_close_kernel();
25499 }
25500
25501 static int
25502 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25503 index 3d68ef6..7f69136 100644
25504 --- a/arch/x86/mm/pat.c
25505 +++ b/arch/x86/mm/pat.c
25506 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25507
25508 if (!entry) {
25509 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25510 - current->comm, current->pid, start, end - 1);
25511 + current->comm, task_pid_nr(current), start, end - 1);
25512 return -EINVAL;
25513 }
25514
25515 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25516
25517 while (cursor < to) {
25518 if (!devmem_is_allowed(pfn)) {
25519 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25520 - current->comm, from, to - 1);
25521 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25522 + current->comm, from, to - 1, cursor);
25523 return 0;
25524 }
25525 cursor += PAGE_SIZE;
25526 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25527 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25528 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25529 "for [mem %#010Lx-%#010Lx]\n",
25530 - current->comm, current->pid,
25531 + current->comm, task_pid_nr(current),
25532 cattr_name(flags),
25533 base, (unsigned long long)(base + size-1));
25534 return -EINVAL;
25535 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25536 flags = lookup_memtype(paddr);
25537 if (want_flags != flags) {
25538 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25539 - current->comm, current->pid,
25540 + current->comm, task_pid_nr(current),
25541 cattr_name(want_flags),
25542 (unsigned long long)paddr,
25543 (unsigned long long)(paddr + size - 1),
25544 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25545 free_memtype(paddr, paddr + size);
25546 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25547 " for [mem %#010Lx-%#010Lx], got %s\n",
25548 - current->comm, current->pid,
25549 + current->comm, task_pid_nr(current),
25550 cattr_name(want_flags),
25551 (unsigned long long)paddr,
25552 (unsigned long long)(paddr + size - 1),
25553 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25554 index 9f0614d..92ae64a 100644
25555 --- a/arch/x86/mm/pf_in.c
25556 +++ b/arch/x86/mm/pf_in.c
25557 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25558 int i;
25559 enum reason_type rv = OTHERS;
25560
25561 - p = (unsigned char *)ins_addr;
25562 + p = (unsigned char *)ktla_ktva(ins_addr);
25563 p += skip_prefix(p, &prf);
25564 p += get_opcode(p, &opcode);
25565
25566 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25567 struct prefix_bits prf;
25568 int i;
25569
25570 - p = (unsigned char *)ins_addr;
25571 + p = (unsigned char *)ktla_ktva(ins_addr);
25572 p += skip_prefix(p, &prf);
25573 p += get_opcode(p, &opcode);
25574
25575 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25576 struct prefix_bits prf;
25577 int i;
25578
25579 - p = (unsigned char *)ins_addr;
25580 + p = (unsigned char *)ktla_ktva(ins_addr);
25581 p += skip_prefix(p, &prf);
25582 p += get_opcode(p, &opcode);
25583
25584 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25585 struct prefix_bits prf;
25586 int i;
25587
25588 - p = (unsigned char *)ins_addr;
25589 + p = (unsigned char *)ktla_ktva(ins_addr);
25590 p += skip_prefix(p, &prf);
25591 p += get_opcode(p, &opcode);
25592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25593 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25594 struct prefix_bits prf;
25595 int i;
25596
25597 - p = (unsigned char *)ins_addr;
25598 + p = (unsigned char *)ktla_ktva(ins_addr);
25599 p += skip_prefix(p, &prf);
25600 p += get_opcode(p, &opcode);
25601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25602 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25603 index 8573b83..4f3ed7e 100644
25604 --- a/arch/x86/mm/pgtable.c
25605 +++ b/arch/x86/mm/pgtable.c
25606 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25607 list_del(&page->lru);
25608 }
25609
25610 -#define UNSHARED_PTRS_PER_PGD \
25611 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25613 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25614
25615 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25616 +{
25617 + unsigned int count = USER_PGD_PTRS;
25618
25619 + while (count--)
25620 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25621 +}
25622 +#endif
25623 +
25624 +#ifdef CONFIG_PAX_PER_CPU_PGD
25625 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25626 +{
25627 + unsigned int count = USER_PGD_PTRS;
25628 +
25629 + while (count--) {
25630 + pgd_t pgd;
25631 +
25632 +#ifdef CONFIG_X86_64
25633 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25634 +#else
25635 + pgd = *src++;
25636 +#endif
25637 +
25638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25639 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25640 +#endif
25641 +
25642 + *dst++ = pgd;
25643 + }
25644 +
25645 +}
25646 +#endif
25647 +
25648 +#ifdef CONFIG_X86_64
25649 +#define pxd_t pud_t
25650 +#define pyd_t pgd_t
25651 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25652 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25653 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25654 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25655 +#define PYD_SIZE PGDIR_SIZE
25656 +#else
25657 +#define pxd_t pmd_t
25658 +#define pyd_t pud_t
25659 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25660 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25661 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25662 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25663 +#define PYD_SIZE PUD_SIZE
25664 +#endif
25665 +
25666 +#ifdef CONFIG_PAX_PER_CPU_PGD
25667 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25668 +static inline void pgd_dtor(pgd_t *pgd) {}
25669 +#else
25670 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25671 {
25672 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25673 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25674 pgd_list_del(pgd);
25675 spin_unlock(&pgd_lock);
25676 }
25677 +#endif
25678
25679 /*
25680 * List of all pgd's needed for non-PAE so it can invalidate entries
25681 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25682 * -- wli
25683 */
25684
25685 -#ifdef CONFIG_X86_PAE
25686 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25687 /*
25688 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25689 * updating the top-level pagetable entries to guarantee the
25690 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25691 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25692 * and initialize the kernel pmds here.
25693 */
25694 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25695 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25696
25697 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25698 {
25699 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25700 */
25701 flush_tlb_mm(mm);
25702 }
25703 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25704 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25705 #else /* !CONFIG_X86_PAE */
25706
25707 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25708 -#define PREALLOCATED_PMDS 0
25709 +#define PREALLOCATED_PXDS 0
25710
25711 #endif /* CONFIG_X86_PAE */
25712
25713 -static void free_pmds(pmd_t *pmds[])
25714 +static void free_pxds(pxd_t *pxds[])
25715 {
25716 int i;
25717
25718 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25719 - if (pmds[i])
25720 - free_page((unsigned long)pmds[i]);
25721 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25722 + if (pxds[i])
25723 + free_page((unsigned long)pxds[i]);
25724 }
25725
25726 -static int preallocate_pmds(pmd_t *pmds[])
25727 +static int preallocate_pxds(pxd_t *pxds[])
25728 {
25729 int i;
25730 bool failed = false;
25731
25732 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25733 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25734 - if (pmd == NULL)
25735 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25736 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25737 + if (pxd == NULL)
25738 failed = true;
25739 - pmds[i] = pmd;
25740 + pxds[i] = pxd;
25741 }
25742
25743 if (failed) {
25744 - free_pmds(pmds);
25745 + free_pxds(pxds);
25746 return -ENOMEM;
25747 }
25748
25749 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25750 * preallocate which never got a corresponding vma will need to be
25751 * freed manually.
25752 */
25753 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25754 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25755 {
25756 int i;
25757
25758 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25759 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25760 pgd_t pgd = pgdp[i];
25761
25762 if (pgd_val(pgd) != 0) {
25763 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25764 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25765
25766 - pgdp[i] = native_make_pgd(0);
25767 + set_pgd(pgdp + i, native_make_pgd(0));
25768
25769 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25770 - pmd_free(mm, pmd);
25771 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25772 + pxd_free(mm, pxd);
25773 }
25774 }
25775 }
25776
25777 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25778 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25779 {
25780 - pud_t *pud;
25781 + pyd_t *pyd;
25782 unsigned long addr;
25783 int i;
25784
25785 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25786 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25787 return;
25788
25789 - pud = pud_offset(pgd, 0);
25790 +#ifdef CONFIG_X86_64
25791 + pyd = pyd_offset(mm, 0L);
25792 +#else
25793 + pyd = pyd_offset(pgd, 0L);
25794 +#endif
25795
25796 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25797 - i++, pud++, addr += PUD_SIZE) {
25798 - pmd_t *pmd = pmds[i];
25799 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25800 + i++, pyd++, addr += PYD_SIZE) {
25801 + pxd_t *pxd = pxds[i];
25802
25803 if (i >= KERNEL_PGD_BOUNDARY)
25804 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25805 - sizeof(pmd_t) * PTRS_PER_PMD);
25806 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25807 + sizeof(pxd_t) * PTRS_PER_PMD);
25808
25809 - pud_populate(mm, pud, pmd);
25810 + pyd_populate(mm, pyd, pxd);
25811 }
25812 }
25813
25814 pgd_t *pgd_alloc(struct mm_struct *mm)
25815 {
25816 pgd_t *pgd;
25817 - pmd_t *pmds[PREALLOCATED_PMDS];
25818 + pxd_t *pxds[PREALLOCATED_PXDS];
25819
25820 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25821
25822 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25823
25824 mm->pgd = pgd;
25825
25826 - if (preallocate_pmds(pmds) != 0)
25827 + if (preallocate_pxds(pxds) != 0)
25828 goto out_free_pgd;
25829
25830 if (paravirt_pgd_alloc(mm) != 0)
25831 - goto out_free_pmds;
25832 + goto out_free_pxds;
25833
25834 /*
25835 * Make sure that pre-populating the pmds is atomic with
25836 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25837 spin_lock(&pgd_lock);
25838
25839 pgd_ctor(mm, pgd);
25840 - pgd_prepopulate_pmd(mm, pgd, pmds);
25841 + pgd_prepopulate_pxd(mm, pgd, pxds);
25842
25843 spin_unlock(&pgd_lock);
25844
25845 return pgd;
25846
25847 -out_free_pmds:
25848 - free_pmds(pmds);
25849 +out_free_pxds:
25850 + free_pxds(pxds);
25851 out_free_pgd:
25852 free_page((unsigned long)pgd);
25853 out:
25854 @@ -295,7 +356,7 @@ out:
25855
25856 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25857 {
25858 - pgd_mop_up_pmds(mm, pgd);
25859 + pgd_mop_up_pxds(mm, pgd);
25860 pgd_dtor(pgd);
25861 paravirt_pgd_free(mm, pgd);
25862 free_page((unsigned long)pgd);
25863 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25864 index a69bcb8..19068ab 100644
25865 --- a/arch/x86/mm/pgtable_32.c
25866 +++ b/arch/x86/mm/pgtable_32.c
25867 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25868 return;
25869 }
25870 pte = pte_offset_kernel(pmd, vaddr);
25871 +
25872 + pax_open_kernel();
25873 if (pte_val(pteval))
25874 set_pte_at(&init_mm, vaddr, pte, pteval);
25875 else
25876 pte_clear(&init_mm, vaddr, pte);
25877 + pax_close_kernel();
25878
25879 /*
25880 * It's enough to flush this one mapping.
25881 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25882 index 410531d..0f16030 100644
25883 --- a/arch/x86/mm/setup_nx.c
25884 +++ b/arch/x86/mm/setup_nx.c
25885 @@ -5,8 +5,10 @@
25886 #include <asm/pgtable.h>
25887 #include <asm/proto.h>
25888
25889 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25890 static int disable_nx __cpuinitdata;
25891
25892 +#ifndef CONFIG_PAX_PAGEEXEC
25893 /*
25894 * noexec = on|off
25895 *
25896 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25897 return 0;
25898 }
25899 early_param("noexec", noexec_setup);
25900 +#endif
25901 +
25902 +#endif
25903
25904 void __cpuinit x86_configure_nx(void)
25905 {
25906 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25907 if (cpu_has_nx && !disable_nx)
25908 __supported_pte_mask |= _PAGE_NX;
25909 else
25910 +#endif
25911 __supported_pte_mask &= ~_PAGE_NX;
25912 }
25913
25914 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25915 index 613cd83..3a21f1c 100644
25916 --- a/arch/x86/mm/tlb.c
25917 +++ b/arch/x86/mm/tlb.c
25918 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25919 BUG();
25920 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25921 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25922 +
25923 +#ifndef CONFIG_PAX_PER_CPU_PGD
25924 load_cr3(swapper_pg_dir);
25925 +#endif
25926 +
25927 }
25928 }
25929 EXPORT_SYMBOL_GPL(leave_mm);
25930 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25931 index 877b9a1..a8ecf42 100644
25932 --- a/arch/x86/net/bpf_jit.S
25933 +++ b/arch/x86/net/bpf_jit.S
25934 @@ -9,6 +9,7 @@
25935 */
25936 #include <linux/linkage.h>
25937 #include <asm/dwarf2.h>
25938 +#include <asm/alternative-asm.h>
25939
25940 /*
25941 * Calling convention :
25942 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25943 jle bpf_slow_path_word
25944 mov (SKBDATA,%rsi),%eax
25945 bswap %eax /* ntohl() */
25946 + pax_force_retaddr
25947 ret
25948
25949 sk_load_half:
25950 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25951 jle bpf_slow_path_half
25952 movzwl (SKBDATA,%rsi),%eax
25953 rol $8,%ax # ntohs()
25954 + pax_force_retaddr
25955 ret
25956
25957 sk_load_byte:
25958 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25959 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25960 jle bpf_slow_path_byte
25961 movzbl (SKBDATA,%rsi),%eax
25962 + pax_force_retaddr
25963 ret
25964
25965 /**
25966 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25967 movzbl (SKBDATA,%rsi),%ebx
25968 and $15,%bl
25969 shl $2,%bl
25970 + pax_force_retaddr
25971 ret
25972
25973 /* rsi contains offset and can be scratched */
25974 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25975 js bpf_error
25976 mov -12(%rbp),%eax
25977 bswap %eax
25978 + pax_force_retaddr
25979 ret
25980
25981 bpf_slow_path_half:
25982 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25983 mov -12(%rbp),%ax
25984 rol $8,%ax
25985 movzwl %ax,%eax
25986 + pax_force_retaddr
25987 ret
25988
25989 bpf_slow_path_byte:
25990 bpf_slow_path_common(1)
25991 js bpf_error
25992 movzbl -12(%rbp),%eax
25993 + pax_force_retaddr
25994 ret
25995
25996 bpf_slow_path_byte_msh:
25997 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25998 and $15,%al
25999 shl $2,%al
26000 xchg %eax,%ebx
26001 + pax_force_retaddr
26002 ret
26003
26004 #define sk_negative_common(SIZE) \
26005 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26006 sk_negative_common(4)
26007 mov (%rax), %eax
26008 bswap %eax
26009 + pax_force_retaddr
26010 ret
26011
26012 bpf_slow_path_half_neg:
26013 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26014 mov (%rax),%ax
26015 rol $8,%ax
26016 movzwl %ax,%eax
26017 + pax_force_retaddr
26018 ret
26019
26020 bpf_slow_path_byte_neg:
26021 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26022 .globl sk_load_byte_negative_offset
26023 sk_negative_common(1)
26024 movzbl (%rax), %eax
26025 + pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_byte_msh_neg:
26029 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26030 and $15,%al
26031 shl $2,%al
26032 xchg %eax,%ebx
26033 + pax_force_retaddr
26034 ret
26035
26036 bpf_error:
26037 @@ -197,4 +210,5 @@ bpf_error:
26038 xor %eax,%eax
26039 mov -8(%rbp),%rbx
26040 leaveq
26041 + pax_force_retaddr
26042 ret
26043 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26044 index 33643a8..8e44870 100644
26045 --- a/arch/x86/net/bpf_jit_comp.c
26046 +++ b/arch/x86/net/bpf_jit_comp.c
26047 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26048 set_fs(old_fs);
26049 }
26050
26051 +struct bpf_jit_work {
26052 + struct work_struct work;
26053 + void *image;
26054 +};
26055 +
26056 #define CHOOSE_LOAD_FUNC(K, func) \
26057 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26058
26059 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26060 if (addrs == NULL)
26061 return;
26062
26063 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26064 + if (!fp->work)
26065 + goto out;
26066 +
26067 /* Before first pass, make a rough estimation of addrs[]
26068 * each bpf instruction is translated to less than 64 bytes
26069 */
26070 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26071 break;
26072 default:
26073 /* hmm, too complex filter, give up with jit compiler */
26074 - goto out;
26075 + goto error;
26076 }
26077 ilen = prog - temp;
26078 if (image) {
26079 if (unlikely(proglen + ilen > oldproglen)) {
26080 pr_err("bpb_jit_compile fatal error\n");
26081 - kfree(addrs);
26082 - module_free(NULL, image);
26083 - return;
26084 + module_free_exec(NULL, image);
26085 + goto error;
26086 }
26087 + pax_open_kernel();
26088 memcpy(image + proglen, temp, ilen);
26089 + pax_close_kernel();
26090 }
26091 proglen += ilen;
26092 addrs[i] = proglen;
26093 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26094 break;
26095 }
26096 if (proglen == oldproglen) {
26097 - image = module_alloc(max_t(unsigned int,
26098 - proglen,
26099 - sizeof(struct work_struct)));
26100 + image = module_alloc_exec(proglen);
26101 if (!image)
26102 - goto out;
26103 + goto error;
26104 }
26105 oldproglen = proglen;
26106 }
26107 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26108 bpf_flush_icache(image, image + proglen);
26109
26110 fp->bpf_func = (void *)image;
26111 - }
26112 + } else
26113 +error:
26114 + kfree(fp->work);
26115 +
26116 out:
26117 kfree(addrs);
26118 return;
26119 @@ -652,18 +663,20 @@ out:
26120
26121 static void jit_free_defer(struct work_struct *arg)
26122 {
26123 - module_free(NULL, arg);
26124 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26125 + kfree(arg);
26126 }
26127
26128 /* run from softirq, we must use a work_struct to call
26129 - * module_free() from process context
26130 + * module_free_exec() from process context
26131 */
26132 void bpf_jit_free(struct sk_filter *fp)
26133 {
26134 if (fp->bpf_func != sk_run_filter) {
26135 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26136 + struct work_struct *work = &fp->work->work;
26137
26138 INIT_WORK(work, jit_free_defer);
26139 + fp->work->image = fp->bpf_func;
26140 schedule_work(work);
26141 }
26142 }
26143 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26144 index d6aa6e8..266395a 100644
26145 --- a/arch/x86/oprofile/backtrace.c
26146 +++ b/arch/x86/oprofile/backtrace.c
26147 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26148 struct stack_frame_ia32 *fp;
26149 unsigned long bytes;
26150
26151 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26152 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26153 if (bytes != sizeof(bufhead))
26154 return NULL;
26155
26156 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26157 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26158
26159 oprofile_add_trace(bufhead[0].return_address);
26160
26161 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26162 struct stack_frame bufhead[2];
26163 unsigned long bytes;
26164
26165 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26166 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26167 if (bytes != sizeof(bufhead))
26168 return NULL;
26169
26170 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26171 {
26172 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26173
26174 - if (!user_mode_vm(regs)) {
26175 + if (!user_mode(regs)) {
26176 unsigned long stack = kernel_stack_pointer(regs);
26177 if (depth)
26178 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26179 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26180 index e14a2ff..3fd6b58 100644
26181 --- a/arch/x86/pci/mrst.c
26182 +++ b/arch/x86/pci/mrst.c
26183 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26184 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26185 pci_mmcfg_late_init();
26186 pcibios_enable_irq = mrst_pci_irq_enable;
26187 - pci_root_ops = pci_mrst_ops;
26188 + pax_open_kernel();
26189 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26190 + pax_close_kernel();
26191 pci_soc_mode = 1;
26192 /* Continue with standard init */
26193 return 1;
26194 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26195 index da8fe05..7ee6704 100644
26196 --- a/arch/x86/pci/pcbios.c
26197 +++ b/arch/x86/pci/pcbios.c
26198 @@ -79,50 +79,93 @@ union bios32 {
26199 static struct {
26200 unsigned long address;
26201 unsigned short segment;
26202 -} bios32_indirect = { 0, __KERNEL_CS };
26203 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26204
26205 /*
26206 * Returns the entry point for the given service, NULL on error
26207 */
26208
26209 -static unsigned long bios32_service(unsigned long service)
26210 +static unsigned long __devinit bios32_service(unsigned long service)
26211 {
26212 unsigned char return_code; /* %al */
26213 unsigned long address; /* %ebx */
26214 unsigned long length; /* %ecx */
26215 unsigned long entry; /* %edx */
26216 unsigned long flags;
26217 + struct desc_struct d, *gdt;
26218
26219 local_irq_save(flags);
26220 - __asm__("lcall *(%%edi); cld"
26221 +
26222 + gdt = get_cpu_gdt_table(smp_processor_id());
26223 +
26224 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26225 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26226 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26227 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26228 +
26229 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26230 : "=a" (return_code),
26231 "=b" (address),
26232 "=c" (length),
26233 "=d" (entry)
26234 : "0" (service),
26235 "1" (0),
26236 - "D" (&bios32_indirect));
26237 + "D" (&bios32_indirect),
26238 + "r"(__PCIBIOS_DS)
26239 + : "memory");
26240 +
26241 + pax_open_kernel();
26242 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26243 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26244 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26245 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26246 + pax_close_kernel();
26247 +
26248 local_irq_restore(flags);
26249
26250 switch (return_code) {
26251 - case 0:
26252 - return address + entry;
26253 - case 0x80: /* Not present */
26254 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26255 - return 0;
26256 - default: /* Shouldn't happen */
26257 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26258 - service, return_code);
26259 + case 0: {
26260 + int cpu;
26261 + unsigned char flags;
26262 +
26263 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26264 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26265 + printk(KERN_WARNING "bios32_service: not valid\n");
26266 return 0;
26267 + }
26268 + address = address + PAGE_OFFSET;
26269 + length += 16UL; /* some BIOSs underreport this... */
26270 + flags = 4;
26271 + if (length >= 64*1024*1024) {
26272 + length >>= PAGE_SHIFT;
26273 + flags |= 8;
26274 + }
26275 +
26276 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26277 + gdt = get_cpu_gdt_table(cpu);
26278 + pack_descriptor(&d, address, length, 0x9b, flags);
26279 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26280 + pack_descriptor(&d, address, length, 0x93, flags);
26281 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26282 + }
26283 + return entry;
26284 + }
26285 + case 0x80: /* Not present */
26286 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26287 + return 0;
26288 + default: /* Shouldn't happen */
26289 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26290 + service, return_code);
26291 + return 0;
26292 }
26293 }
26294
26295 static struct {
26296 unsigned long address;
26297 unsigned short segment;
26298 -} pci_indirect = { 0, __KERNEL_CS };
26299 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26300
26301 -static int pci_bios_present;
26302 +static int pci_bios_present __read_only;
26303
26304 static int __devinit check_pcibios(void)
26305 {
26306 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26307 unsigned long flags, pcibios_entry;
26308
26309 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26310 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26311 + pci_indirect.address = pcibios_entry;
26312
26313 local_irq_save(flags);
26314 - __asm__(
26315 - "lcall *(%%edi); cld\n\t"
26316 + __asm__("movw %w6, %%ds\n\t"
26317 + "lcall *%%ss:(%%edi); cld\n\t"
26318 + "push %%ss\n\t"
26319 + "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26324 "=b" (ebx),
26325 "=c" (ecx)
26326 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26327 - "D" (&pci_indirect)
26328 + "D" (&pci_indirect),
26329 + "r" (__PCIBIOS_DS)
26330 : "memory");
26331 local_irq_restore(flags);
26332
26333 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337 - __asm__("lcall *(%%esi); cld\n\t"
26338 + __asm__("movw %w6, %%ds\n\t"
26339 + "lcall *%%ss:(%%esi); cld\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26346 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26347 "b" (bx),
26348 "D" ((long)reg),
26349 - "S" (&pci_indirect));
26350 + "S" (&pci_indirect),
26351 + "r" (__PCIBIOS_DS));
26352 /*
26353 * Zero-extend the result beyond 8 bits, do not trust the
26354 * BIOS having done it:
26355 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26356 *value &= 0xff;
26357 break;
26358 case 2:
26359 - __asm__("lcall *(%%esi); cld\n\t"
26360 + __asm__("movw %w6, %%ds\n\t"
26361 + "lcall *%%ss:(%%esi); cld\n\t"
26362 + "push %%ss\n\t"
26363 + "pop %%ds\n\t"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26368 : "1" (PCIBIOS_READ_CONFIG_WORD),
26369 "b" (bx),
26370 "D" ((long)reg),
26371 - "S" (&pci_indirect));
26372 + "S" (&pci_indirect),
26373 + "r" (__PCIBIOS_DS));
26374 /*
26375 * Zero-extend the result beyond 16 bits, do not trust the
26376 * BIOS having done it:
26377 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 *value &= 0xffff;
26379 break;
26380 case 4:
26381 - __asm__("lcall *(%%esi); cld\n\t"
26382 + __asm__("movw %w6, %%ds\n\t"
26383 + "lcall *%%ss:(%%esi); cld\n\t"
26384 + "push %%ss\n\t"
26385 + "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26390 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26391 "b" (bx),
26392 "D" ((long)reg),
26393 - "S" (&pci_indirect));
26394 + "S" (&pci_indirect),
26395 + "r" (__PCIBIOS_DS));
26396 break;
26397 }
26398
26399 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400
26401 switch (len) {
26402 case 1:
26403 - __asm__("lcall *(%%esi); cld\n\t"
26404 + __asm__("movw %w6, %%ds\n\t"
26405 + "lcall *%%ss:(%%esi); cld\n\t"
26406 + "push %%ss\n\t"
26407 + "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26412 "c" (value),
26413 "b" (bx),
26414 "D" ((long)reg),
26415 - "S" (&pci_indirect));
26416 + "S" (&pci_indirect),
26417 + "r" (__PCIBIOS_DS));
26418 break;
26419 case 2:
26420 - __asm__("lcall *(%%esi); cld\n\t"
26421 + __asm__("movw %w6, %%ds\n\t"
26422 + "lcall *%%ss:(%%esi); cld\n\t"
26423 + "push %%ss\n\t"
26424 + "pop %%ds\n\t"
26425 "jc 1f\n\t"
26426 "xor %%ah, %%ah\n"
26427 "1:"
26428 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26429 "c" (value),
26430 "b" (bx),
26431 "D" ((long)reg),
26432 - "S" (&pci_indirect));
26433 + "S" (&pci_indirect),
26434 + "r" (__PCIBIOS_DS));
26435 break;
26436 case 4:
26437 - __asm__("lcall *(%%esi); cld\n\t"
26438 + __asm__("movw %w6, %%ds\n\t"
26439 + "lcall *%%ss:(%%esi); cld\n\t"
26440 + "push %%ss\n\t"
26441 + "pop %%ds\n\t"
26442 "jc 1f\n\t"
26443 "xor %%ah, %%ah\n"
26444 "1:"
26445 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26446 "c" (value),
26447 "b" (bx),
26448 "D" ((long)reg),
26449 - "S" (&pci_indirect));
26450 + "S" (&pci_indirect),
26451 + "r" (__PCIBIOS_DS));
26452 break;
26453 }
26454
26455 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26456
26457 DBG("PCI: Fetching IRQ routing table... ");
26458 __asm__("push %%es\n\t"
26459 + "movw %w8, %%ds\n\t"
26460 "push %%ds\n\t"
26461 "pop %%es\n\t"
26462 - "lcall *(%%esi); cld\n\t"
26463 + "lcall *%%ss:(%%esi); cld\n\t"
26464 "pop %%es\n\t"
26465 + "push %%ss\n\t"
26466 + "pop %%ds\n"
26467 "jc 1f\n\t"
26468 "xor %%ah, %%ah\n"
26469 "1:"
26470 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26471 "1" (0),
26472 "D" ((long) &opt),
26473 "S" (&pci_indirect),
26474 - "m" (opt)
26475 + "m" (opt),
26476 + "r" (__PCIBIOS_DS)
26477 : "memory");
26478 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26479 if (ret & 0xff00)
26480 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26481 {
26482 int ret;
26483
26484 - __asm__("lcall *(%%esi); cld\n\t"
26485 + __asm__("movw %w5, %%ds\n\t"
26486 + "lcall *%%ss:(%%esi); cld\n\t"
26487 + "push %%ss\n\t"
26488 + "pop %%ds\n"
26489 "jc 1f\n\t"
26490 "xor %%ah, %%ah\n"
26491 "1:"
26492 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26493 : "0" (PCIBIOS_SET_PCI_HW_INT),
26494 "b" ((dev->bus->number << 8) | dev->devfn),
26495 "c" ((irq << 8) | (pin + 10)),
26496 - "S" (&pci_indirect));
26497 + "S" (&pci_indirect),
26498 + "r" (__PCIBIOS_DS));
26499 return !(ret & 0xff00);
26500 }
26501 EXPORT_SYMBOL(pcibios_set_irq_routing);
26502 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26503 index 40e4469..1ab536e 100644
26504 --- a/arch/x86/platform/efi/efi_32.c
26505 +++ b/arch/x86/platform/efi/efi_32.c
26506 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26507 {
26508 struct desc_ptr gdt_descr;
26509
26510 +#ifdef CONFIG_PAX_KERNEXEC
26511 + struct desc_struct d;
26512 +#endif
26513 +
26514 local_irq_save(efi_rt_eflags);
26515
26516 load_cr3(initial_page_table);
26517 __flush_tlb_all();
26518
26519 +#ifdef CONFIG_PAX_KERNEXEC
26520 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26521 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26522 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26523 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26524 +#endif
26525 +
26526 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26527 gdt_descr.size = GDT_SIZE - 1;
26528 load_gdt(&gdt_descr);
26529 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26530 {
26531 struct desc_ptr gdt_descr;
26532
26533 +#ifdef CONFIG_PAX_KERNEXEC
26534 + struct desc_struct d;
26535 +
26536 + memset(&d, 0, sizeof d);
26537 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26538 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26539 +#endif
26540 +
26541 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26542 gdt_descr.size = GDT_SIZE - 1;
26543 load_gdt(&gdt_descr);
26544 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26545 index fbe66e6..eae5e38 100644
26546 --- a/arch/x86/platform/efi/efi_stub_32.S
26547 +++ b/arch/x86/platform/efi/efi_stub_32.S
26548 @@ -6,7 +6,9 @@
26549 */
26550
26551 #include <linux/linkage.h>
26552 +#include <linux/init.h>
26553 #include <asm/page_types.h>
26554 +#include <asm/segment.h>
26555
26556 /*
26557 * efi_call_phys(void *, ...) is a function with variable parameters.
26558 @@ -20,7 +22,7 @@
26559 * service functions will comply with gcc calling convention, too.
26560 */
26561
26562 -.text
26563 +__INIT
26564 ENTRY(efi_call_phys)
26565 /*
26566 * 0. The function can only be called in Linux kernel. So CS has been
26567 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26568 * The mapping of lower virtual memory has been created in prelog and
26569 * epilog.
26570 */
26571 - movl $1f, %edx
26572 - subl $__PAGE_OFFSET, %edx
26573 - jmp *%edx
26574 +#ifdef CONFIG_PAX_KERNEXEC
26575 + movl $(__KERNEXEC_EFI_DS), %edx
26576 + mov %edx, %ds
26577 + mov %edx, %es
26578 + mov %edx, %ss
26579 + addl $2f,(1f)
26580 + ljmp *(1f)
26581 +
26582 +__INITDATA
26583 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26584 +.previous
26585 +
26586 +2:
26587 + subl $2b,(1b)
26588 +#else
26589 + jmp 1f-__PAGE_OFFSET
26590 1:
26591 +#endif
26592
26593 /*
26594 * 2. Now on the top of stack is the return
26595 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26596 * parameter 2, ..., param n. To make things easy, we save the return
26597 * address of efi_call_phys in a global variable.
26598 */
26599 - popl %edx
26600 - movl %edx, saved_return_addr
26601 - /* get the function pointer into ECX*/
26602 - popl %ecx
26603 - movl %ecx, efi_rt_function_ptr
26604 - movl $2f, %edx
26605 - subl $__PAGE_OFFSET, %edx
26606 - pushl %edx
26607 + popl (saved_return_addr)
26608 + popl (efi_rt_function_ptr)
26609
26610 /*
26611 * 3. Clear PG bit in %CR0.
26612 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26613 /*
26614 * 5. Call the physical function.
26615 */
26616 - jmp *%ecx
26617 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26618
26619 -2:
26620 /*
26621 * 6. After EFI runtime service returns, control will return to
26622 * following instruction. We'd better readjust stack pointer first.
26623 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26624 movl %cr0, %edx
26625 orl $0x80000000, %edx
26626 movl %edx, %cr0
26627 - jmp 1f
26628 -1:
26629 +
26630 /*
26631 * 8. Now restore the virtual mode from flat mode by
26632 * adding EIP with PAGE_OFFSET.
26633 */
26634 - movl $1f, %edx
26635 - jmp *%edx
26636 +#ifdef CONFIG_PAX_KERNEXEC
26637 + movl $(__KERNEL_DS), %edx
26638 + mov %edx, %ds
26639 + mov %edx, %es
26640 + mov %edx, %ss
26641 + ljmp $(__KERNEL_CS),$1f
26642 +#else
26643 + jmp 1f+__PAGE_OFFSET
26644 +#endif
26645 1:
26646
26647 /*
26648 * 9. Balance the stack. And because EAX contain the return value,
26649 * we'd better not clobber it.
26650 */
26651 - leal efi_rt_function_ptr, %edx
26652 - movl (%edx), %ecx
26653 - pushl %ecx
26654 + pushl (efi_rt_function_ptr)
26655
26656 /*
26657 - * 10. Push the saved return address onto the stack and return.
26658 + * 10. Return to the saved return address.
26659 */
26660 - leal saved_return_addr, %edx
26661 - movl (%edx), %ecx
26662 - pushl %ecx
26663 - ret
26664 + jmpl *(saved_return_addr)
26665 ENDPROC(efi_call_phys)
26666 .previous
26667
26668 -.data
26669 +__INITDATA
26670 saved_return_addr:
26671 .long 0
26672 efi_rt_function_ptr:
26673 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26674 index 4c07cca..2c8427d 100644
26675 --- a/arch/x86/platform/efi/efi_stub_64.S
26676 +++ b/arch/x86/platform/efi/efi_stub_64.S
26677 @@ -7,6 +7,7 @@
26678 */
26679
26680 #include <linux/linkage.h>
26681 +#include <asm/alternative-asm.h>
26682
26683 #define SAVE_XMM \
26684 mov %rsp, %rax; \
26685 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26686 call *%rdi
26687 addq $32, %rsp
26688 RESTORE_XMM
26689 + pax_force_retaddr 0, 1
26690 ret
26691 ENDPROC(efi_call0)
26692
26693 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26694 call *%rdi
26695 addq $32, %rsp
26696 RESTORE_XMM
26697 + pax_force_retaddr 0, 1
26698 ret
26699 ENDPROC(efi_call1)
26700
26701 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26702 call *%rdi
26703 addq $32, %rsp
26704 RESTORE_XMM
26705 + pax_force_retaddr 0, 1
26706 ret
26707 ENDPROC(efi_call2)
26708
26709 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26710 call *%rdi
26711 addq $32, %rsp
26712 RESTORE_XMM
26713 + pax_force_retaddr 0, 1
26714 ret
26715 ENDPROC(efi_call3)
26716
26717 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26718 call *%rdi
26719 addq $32, %rsp
26720 RESTORE_XMM
26721 + pax_force_retaddr 0, 1
26722 ret
26723 ENDPROC(efi_call4)
26724
26725 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26726 call *%rdi
26727 addq $48, %rsp
26728 RESTORE_XMM
26729 + pax_force_retaddr 0, 1
26730 ret
26731 ENDPROC(efi_call5)
26732
26733 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26734 call *%rdi
26735 addq $48, %rsp
26736 RESTORE_XMM
26737 + pax_force_retaddr 0, 1
26738 ret
26739 ENDPROC(efi_call6)
26740 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26741 index fd41a92..9c33628 100644
26742 --- a/arch/x86/platform/mrst/mrst.c
26743 +++ b/arch/x86/platform/mrst/mrst.c
26744 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26745 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26746 int sfi_mrtc_num;
26747
26748 -static void mrst_power_off(void)
26749 +static __noreturn void mrst_power_off(void)
26750 {
26751 + BUG();
26752 }
26753
26754 -static void mrst_reboot(void)
26755 +static __noreturn void mrst_reboot(void)
26756 {
26757 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26758 + BUG();
26759 }
26760
26761 /* parse all the mtimer info to a static mtimer array */
26762 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26763 index 218cdb1..fd55c08 100644
26764 --- a/arch/x86/power/cpu.c
26765 +++ b/arch/x86/power/cpu.c
26766 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26767 static void fix_processor_context(void)
26768 {
26769 int cpu = smp_processor_id();
26770 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26771 + struct tss_struct *t = init_tss + cpu;
26772
26773 set_tss_desc(cpu, t); /*
26774 * This just modifies memory; should not be
26775 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26776 */
26777
26778 #ifdef CONFIG_X86_64
26779 + pax_open_kernel();
26780 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26781 + pax_close_kernel();
26782
26783 syscall_init(); /* This sets MSR_*STAR and related */
26784 #endif
26785 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26786 index cbca565..bae7133 100644
26787 --- a/arch/x86/realmode/init.c
26788 +++ b/arch/x86/realmode/init.c
26789 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26790 __va(real_mode_header->trampoline_header);
26791
26792 #ifdef CONFIG_X86_32
26793 - trampoline_header->start = __pa(startup_32_smp);
26794 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26795 +
26796 +#ifdef CONFIG_PAX_KERNEXEC
26797 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26798 +#endif
26799 +
26800 + trampoline_header->boot_cs = __BOOT_CS;
26801 trampoline_header->gdt_limit = __BOOT_DS + 7;
26802 trampoline_header->gdt_base = __pa(boot_gdt);
26803 #else
26804 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26805 index 8869287..d577672 100644
26806 --- a/arch/x86/realmode/rm/Makefile
26807 +++ b/arch/x86/realmode/rm/Makefile
26808 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26809 $(call cc-option, -fno-unit-at-a-time)) \
26810 $(call cc-option, -fno-stack-protector) \
26811 $(call cc-option, -mpreferred-stack-boundary=2)
26812 +ifdef CONSTIFY_PLUGIN
26813 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26814 +endif
26815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26816 GCOV_PROFILE := n
26817 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26818 index a28221d..93c40f1 100644
26819 --- a/arch/x86/realmode/rm/header.S
26820 +++ b/arch/x86/realmode/rm/header.S
26821 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26822 #endif
26823 /* APM/BIOS reboot */
26824 .long pa_machine_real_restart_asm
26825 -#ifdef CONFIG_X86_64
26826 +#ifdef CONFIG_X86_32
26827 + .long __KERNEL_CS
26828 +#else
26829 .long __KERNEL32_CS
26830 #endif
26831 END(real_mode_header)
26832 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26833 index c1b2791..f9e31c7 100644
26834 --- a/arch/x86/realmode/rm/trampoline_32.S
26835 +++ b/arch/x86/realmode/rm/trampoline_32.S
26836 @@ -25,6 +25,12 @@
26837 #include <asm/page_types.h>
26838 #include "realmode.h"
26839
26840 +#ifdef CONFIG_PAX_KERNEXEC
26841 +#define ta(X) (X)
26842 +#else
26843 +#define ta(X) (pa_ ## X)
26844 +#endif
26845 +
26846 .text
26847 .code16
26848
26849 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26850
26851 cli # We should be safe anyway
26852
26853 - movl tr_start, %eax # where we need to go
26854 -
26855 movl $0xA5A5A5A5, trampoline_status
26856 # write marker for master knows we're running
26857
26858 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26859 movw $1, %dx # protected mode (PE) bit
26860 lmsw %dx # into protected mode
26861
26862 - ljmpl $__BOOT_CS, $pa_startup_32
26863 + ljmpl *(trampoline_header)
26864
26865 .section ".text32","ax"
26866 .code32
26867 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26868 .balign 8
26869 GLOBAL(trampoline_header)
26870 tr_start: .space 4
26871 - tr_gdt_pad: .space 2
26872 + tr_boot_cs: .space 2
26873 tr_gdt: .space 6
26874 END(trampoline_header)
26875
26876 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26877 index bb360dc..3e5945f 100644
26878 --- a/arch/x86/realmode/rm/trampoline_64.S
26879 +++ b/arch/x86/realmode/rm/trampoline_64.S
26880 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26881 wrmsr
26882
26883 # Enable paging and in turn activate Long Mode
26884 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26885 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26886 movl %eax, %cr0
26887
26888 /*
26889 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26890 index 5a1847d..deccb30 100644
26891 --- a/arch/x86/tools/relocs.c
26892 +++ b/arch/x86/tools/relocs.c
26893 @@ -12,10 +12,13 @@
26894 #include <regex.h>
26895 #include <tools/le_byteshift.h>
26896
26897 +#include "../../../include/generated/autoconf.h"
26898 +
26899 static void die(char *fmt, ...);
26900
26901 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26902 static Elf32_Ehdr ehdr;
26903 +static Elf32_Phdr *phdr;
26904 static unsigned long reloc_count, reloc_idx;
26905 static unsigned long *relocs;
26906 static unsigned long reloc16_count, reloc16_idx;
26907 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26908 }
26909 }
26910
26911 +static void read_phdrs(FILE *fp)
26912 +{
26913 + unsigned int i;
26914 +
26915 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26916 + if (!phdr) {
26917 + die("Unable to allocate %d program headers\n",
26918 + ehdr.e_phnum);
26919 + }
26920 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26921 + die("Seek to %d failed: %s\n",
26922 + ehdr.e_phoff, strerror(errno));
26923 + }
26924 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26925 + die("Cannot read ELF program headers: %s\n",
26926 + strerror(errno));
26927 + }
26928 + for(i = 0; i < ehdr.e_phnum; i++) {
26929 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26930 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26931 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26932 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26933 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26934 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26935 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26936 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26937 + }
26938 +
26939 +}
26940 +
26941 static void read_shdrs(FILE *fp)
26942 {
26943 - int i;
26944 + unsigned int i;
26945 Elf32_Shdr shdr;
26946
26947 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26948 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26949
26950 static void read_strtabs(FILE *fp)
26951 {
26952 - int i;
26953 + unsigned int i;
26954 for (i = 0; i < ehdr.e_shnum; i++) {
26955 struct section *sec = &secs[i];
26956 if (sec->shdr.sh_type != SHT_STRTAB) {
26957 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26958
26959 static void read_symtabs(FILE *fp)
26960 {
26961 - int i,j;
26962 + unsigned int i,j;
26963 for (i = 0; i < ehdr.e_shnum; i++) {
26964 struct section *sec = &secs[i];
26965 if (sec->shdr.sh_type != SHT_SYMTAB) {
26966 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26967 }
26968
26969
26970 -static void read_relocs(FILE *fp)
26971 +static void read_relocs(FILE *fp, int use_real_mode)
26972 {
26973 - int i,j;
26974 + unsigned int i,j;
26975 + uint32_t base;
26976 +
26977 for (i = 0; i < ehdr.e_shnum; i++) {
26978 struct section *sec = &secs[i];
26979 if (sec->shdr.sh_type != SHT_REL) {
26980 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26981 die("Cannot read symbol table: %s\n",
26982 strerror(errno));
26983 }
26984 + base = 0;
26985 +
26986 +#ifdef CONFIG_X86_32
26987 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26988 + if (phdr[j].p_type != PT_LOAD )
26989 + continue;
26990 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
26991 + continue;
26992 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26993 + break;
26994 + }
26995 +#endif
26996 +
26997 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26998 Elf32_Rel *rel = &sec->reltab[j];
26999 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27000 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27001 rel->r_info = elf32_to_cpu(rel->r_info);
27002 }
27003 }
27004 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27005
27006 static void print_absolute_symbols(void)
27007 {
27008 - int i;
27009 + unsigned int i;
27010 printf("Absolute symbols\n");
27011 printf(" Num: Value Size Type Bind Visibility Name\n");
27012 for (i = 0; i < ehdr.e_shnum; i++) {
27013 struct section *sec = &secs[i];
27014 char *sym_strtab;
27015 - int j;
27016 + unsigned int j;
27017
27018 if (sec->shdr.sh_type != SHT_SYMTAB) {
27019 continue;
27020 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27021
27022 static void print_absolute_relocs(void)
27023 {
27024 - int i, printed = 0;
27025 + unsigned int i, printed = 0;
27026
27027 for (i = 0; i < ehdr.e_shnum; i++) {
27028 struct section *sec = &secs[i];
27029 struct section *sec_applies, *sec_symtab;
27030 char *sym_strtab;
27031 Elf32_Sym *sh_symtab;
27032 - int j;
27033 + unsigned int j;
27034 if (sec->shdr.sh_type != SHT_REL) {
27035 continue;
27036 }
27037 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27038 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27039 int use_real_mode)
27040 {
27041 - int i;
27042 + unsigned int i;
27043 /* Walk through the relocations */
27044 for (i = 0; i < ehdr.e_shnum; i++) {
27045 char *sym_strtab;
27046 Elf32_Sym *sh_symtab;
27047 struct section *sec_applies, *sec_symtab;
27048 - int j;
27049 + unsigned int j;
27050 struct section *sec = &secs[i];
27051
27052 if (sec->shdr.sh_type != SHT_REL) {
27053 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27054 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27055 r_type = ELF32_R_TYPE(rel->r_info);
27056
27057 + if (!use_real_mode) {
27058 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27059 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27060 + continue;
27061 +
27062 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27063 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27064 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27065 + continue;
27066 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27067 + continue;
27068 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27069 + continue;
27070 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27071 + continue;
27072 +#endif
27073 + }
27074 +
27075 shn_abs = sym->st_shndx == SHN_ABS;
27076
27077 switch (r_type) {
27078 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27079
27080 static void emit_relocs(int as_text, int use_real_mode)
27081 {
27082 - int i;
27083 + unsigned int i;
27084 /* Count how many relocations I have and allocate space for them. */
27085 reloc_count = 0;
27086 walk_relocs(count_reloc, use_real_mode);
27087 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27088 fname, strerror(errno));
27089 }
27090 read_ehdr(fp);
27091 + read_phdrs(fp);
27092 read_shdrs(fp);
27093 read_strtabs(fp);
27094 read_symtabs(fp);
27095 - read_relocs(fp);
27096 + read_relocs(fp, use_real_mode);
27097 if (show_absolute_syms) {
27098 print_absolute_symbols();
27099 return 0;
27100 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27101 index fd14be1..e3c79c0 100644
27102 --- a/arch/x86/vdso/Makefile
27103 +++ b/arch/x86/vdso/Makefile
27104 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27107
27108 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27109 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27110 GCOV_PROFILE := n
27111
27112 #
27113 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27114 index 0faad64..39ef157 100644
27115 --- a/arch/x86/vdso/vdso32-setup.c
27116 +++ b/arch/x86/vdso/vdso32-setup.c
27117 @@ -25,6 +25,7 @@
27118 #include <asm/tlbflush.h>
27119 #include <asm/vdso.h>
27120 #include <asm/proto.h>
27121 +#include <asm/mman.h>
27122
27123 enum {
27124 VDSO_DISABLED = 0,
27125 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27126 void enable_sep_cpu(void)
27127 {
27128 int cpu = get_cpu();
27129 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27130 + struct tss_struct *tss = init_tss + cpu;
27131
27132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27133 put_cpu();
27134 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27135 gate_vma.vm_start = FIXADDR_USER_START;
27136 gate_vma.vm_end = FIXADDR_USER_END;
27137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27138 - gate_vma.vm_page_prot = __P101;
27139 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27140
27141 return 0;
27142 }
27143 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27144 if (compat)
27145 addr = VDSO_HIGH_BASE;
27146 else {
27147 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27148 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27149 if (IS_ERR_VALUE(addr)) {
27150 ret = addr;
27151 goto up_fail;
27152 }
27153 }
27154
27155 - current->mm->context.vdso = (void *)addr;
27156 + current->mm->context.vdso = addr;
27157
27158 if (compat_uses_vma || !compat) {
27159 /*
27160 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27161 }
27162
27163 current_thread_info()->sysenter_return =
27164 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27165 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27166
27167 up_fail:
27168 if (ret)
27169 - current->mm->context.vdso = NULL;
27170 + current->mm->context.vdso = 0;
27171
27172 up_write(&mm->mmap_sem);
27173
27174 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27175
27176 const char *arch_vma_name(struct vm_area_struct *vma)
27177 {
27178 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27179 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27180 return "[vdso]";
27181 +
27182 +#ifdef CONFIG_PAX_SEGMEXEC
27183 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27184 + return "[vdso]";
27185 +#endif
27186 +
27187 return NULL;
27188 }
27189
27190 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27191 * Check to see if the corresponding task was created in compat vdso
27192 * mode.
27193 */
27194 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27195 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27196 return &gate_vma;
27197 return NULL;
27198 }
27199 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27200 index 00aaf04..4a26505 100644
27201 --- a/arch/x86/vdso/vma.c
27202 +++ b/arch/x86/vdso/vma.c
27203 @@ -16,8 +16,6 @@
27204 #include <asm/vdso.h>
27205 #include <asm/page.h>
27206
27207 -unsigned int __read_mostly vdso_enabled = 1;
27208 -
27209 extern char vdso_start[], vdso_end[];
27210 extern unsigned short vdso_sync_cpuid;
27211
27212 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27213 * unaligned here as a result of stack start randomization.
27214 */
27215 addr = PAGE_ALIGN(addr);
27216 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27217
27218 return addr;
27219 }
27220 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27221 unsigned size)
27222 {
27223 struct mm_struct *mm = current->mm;
27224 - unsigned long addr;
27225 + unsigned long addr = 0;
27226 int ret;
27227
27228 - if (!vdso_enabled)
27229 - return 0;
27230 -
27231 down_write(&mm->mmap_sem);
27232 +
27233 +#ifdef CONFIG_PAX_RANDMMAP
27234 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27235 +#endif
27236 +
27237 addr = vdso_addr(mm->start_stack, size);
27238 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27240 if (IS_ERR_VALUE(addr)) {
27241 ret = addr;
27242 goto up_fail;
27243 }
27244
27245 - current->mm->context.vdso = (void *)addr;
27246 + mm->context.vdso = addr;
27247
27248 ret = install_special_mapping(mm, addr, size,
27249 VM_READ|VM_EXEC|
27250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27251 pages);
27252 - if (ret) {
27253 - current->mm->context.vdso = NULL;
27254 - goto up_fail;
27255 - }
27256 + if (ret)
27257 + mm->context.vdso = 0;
27258
27259 up_fail:
27260 up_write(&mm->mmap_sem);
27261 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27262 vdsox32_size);
27263 }
27264 #endif
27265 -
27266 -static __init int vdso_setup(char *s)
27267 -{
27268 - vdso_enabled = simple_strtoul(s, NULL, 0);
27269 - return 0;
27270 -}
27271 -__setup("vdso=", vdso_setup);
27272 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27273 index c1461de..355f120 100644
27274 --- a/arch/x86/xen/enlighten.c
27275 +++ b/arch/x86/xen/enlighten.c
27276 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27277
27278 struct shared_info xen_dummy_shared_info;
27279
27280 -void *xen_initial_gdt;
27281 -
27282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27283 __read_mostly int xen_have_vector_callback;
27284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27285 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27286
27287 static void set_xen_basic_apic_ops(void)
27288 {
27289 - apic->read = xen_apic_read;
27290 - apic->write = xen_apic_write;
27291 - apic->icr_read = xen_apic_icr_read;
27292 - apic->icr_write = xen_apic_icr_write;
27293 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27294 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27295 - apic->set_apic_id = xen_set_apic_id;
27296 - apic->get_apic_id = xen_get_apic_id;
27297 + *(void **)&apic->read = xen_apic_read;
27298 + *(void **)&apic->write = xen_apic_write;
27299 + *(void **)&apic->icr_read = xen_apic_icr_read;
27300 + *(void **)&apic->icr_write = xen_apic_icr_write;
27301 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27302 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27303 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27304 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27305
27306 #ifdef CONFIG_SMP
27307 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27308 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27309 - apic->send_IPI_mask = xen_send_IPI_mask;
27310 - apic->send_IPI_all = xen_send_IPI_all;
27311 - apic->send_IPI_self = xen_send_IPI_self;
27312 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27313 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27314 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27315 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27316 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27317 #endif
27318 }
27319
27320 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27321 #endif
27322 };
27323
27324 -static void xen_reboot(int reason)
27325 +static __noreturn void xen_reboot(int reason)
27326 {
27327 struct sched_shutdown r = { .reason = reason };
27328
27329 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27330 - BUG();
27331 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27332 + BUG();
27333 }
27334
27335 -static void xen_restart(char *msg)
27336 +static __noreturn void xen_restart(char *msg)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341 -static void xen_emergency_restart(void)
27342 +static __noreturn void xen_emergency_restart(void)
27343 {
27344 xen_reboot(SHUTDOWN_reboot);
27345 }
27346
27347 -static void xen_machine_halt(void)
27348 +static __noreturn void xen_machine_halt(void)
27349 {
27350 xen_reboot(SHUTDOWN_poweroff);
27351 }
27352
27353 -static void xen_machine_power_off(void)
27354 +static __noreturn void xen_machine_power_off(void)
27355 {
27356 if (pm_power_off)
27357 pm_power_off();
27358 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27359 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27360
27361 /* Work out if we support NX */
27362 - x86_configure_nx();
27363 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27364 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27365 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27366 + unsigned l, h;
27367 +
27368 + __supported_pte_mask |= _PAGE_NX;
27369 + rdmsr(MSR_EFER, l, h);
27370 + l |= EFER_NX;
27371 + wrmsr(MSR_EFER, l, h);
27372 + }
27373 +#endif
27374
27375 xen_setup_features();
27376
27377 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27378
27379 machine_ops = xen_machine_ops;
27380
27381 - /*
27382 - * The only reliable way to retain the initial address of the
27383 - * percpu gdt_page is to remember it here, so we can go and
27384 - * mark it RW later, when the initial percpu area is freed.
27385 - */
27386 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27387 -
27388 xen_smp_init();
27389
27390 #ifdef CONFIG_ACPI_NUMA
27391 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27392 index 5141d80..6c9fb41 100644
27393 --- a/arch/x86/xen/mmu.c
27394 +++ b/arch/x86/xen/mmu.c
27395 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27396 convert_pfn_mfn(init_level4_pgt);
27397 convert_pfn_mfn(level3_ident_pgt);
27398 convert_pfn_mfn(level3_kernel_pgt);
27399 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27400 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27401 + convert_pfn_mfn(level3_vmemmap_pgt);
27402
27403 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27404 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27405 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27406 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27407 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27409 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27410 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27411 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27412 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27413 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27414 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27415 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27416
27417 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27418 pv_mmu_ops.set_pud = xen_set_pud;
27419 #if PAGETABLE_LEVELS == 4
27420 pv_mmu_ops.set_pgd = xen_set_pgd;
27421 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27422 #endif
27423
27424 /* This will work as long as patching hasn't happened yet
27425 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27426 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27427 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27428 .set_pgd = xen_set_pgd_hyper,
27429 + .set_pgd_batched = xen_set_pgd_hyper,
27430
27431 .alloc_pud = xen_alloc_pmd_init,
27432 .release_pud = xen_release_pmd_init,
27433 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27434 index f58dca7..ad21f52 100644
27435 --- a/arch/x86/xen/smp.c
27436 +++ b/arch/x86/xen/smp.c
27437 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27438 {
27439 BUG_ON(smp_processor_id() != 0);
27440 native_smp_prepare_boot_cpu();
27441 -
27442 - /* We've switched to the "real" per-cpu gdt, so make sure the
27443 - old memory can be recycled */
27444 - make_lowmem_page_readwrite(xen_initial_gdt);
27445 -
27446 xen_filter_cpu_maps();
27447 xen_setup_vcpu_info_placement();
27448 }
27449 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27450 gdt = get_cpu_gdt_table(cpu);
27451
27452 ctxt->flags = VGCF_IN_KERNEL;
27453 - ctxt->user_regs.ds = __USER_DS;
27454 - ctxt->user_regs.es = __USER_DS;
27455 + ctxt->user_regs.ds = __KERNEL_DS;
27456 + ctxt->user_regs.es = __KERNEL_DS;
27457 ctxt->user_regs.ss = __KERNEL_DS;
27458 #ifdef CONFIG_X86_32
27459 ctxt->user_regs.fs = __KERNEL_PERCPU;
27460 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27461 + savesegment(gs, ctxt->user_regs.gs);
27462 #else
27463 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27464 #endif
27465 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27466 int rc;
27467
27468 per_cpu(current_task, cpu) = idle;
27469 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27470 #ifdef CONFIG_X86_32
27471 irq_ctx_init(cpu);
27472 #else
27473 clear_tsk_thread_flag(idle, TIF_FORK);
27474 - per_cpu(kernel_stack, cpu) =
27475 - (unsigned long)task_stack_page(idle) -
27476 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27477 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27478 #endif
27479 xen_setup_runstate_info(cpu);
27480 xen_setup_timer(cpu);
27481 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27482 index f9643fc..602e8af 100644
27483 --- a/arch/x86/xen/xen-asm_32.S
27484 +++ b/arch/x86/xen/xen-asm_32.S
27485 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27486 ESP_OFFSET=4 # bytes pushed onto stack
27487
27488 /*
27489 - * Store vcpu_info pointer for easy access. Do it this way to
27490 - * avoid having to reload %fs
27491 + * Store vcpu_info pointer for easy access.
27492 */
27493 #ifdef CONFIG_SMP
27494 - GET_THREAD_INFO(%eax)
27495 - movl TI_cpu(%eax), %eax
27496 - movl __per_cpu_offset(,%eax,4), %eax
27497 - mov xen_vcpu(%eax), %eax
27498 + push %fs
27499 + mov $(__KERNEL_PERCPU), %eax
27500 + mov %eax, %fs
27501 + mov PER_CPU_VAR(xen_vcpu), %eax
27502 + pop %fs
27503 #else
27504 movl xen_vcpu, %eax
27505 #endif
27506 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27507 index aaa7291..3f77960 100644
27508 --- a/arch/x86/xen/xen-head.S
27509 +++ b/arch/x86/xen/xen-head.S
27510 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27511 #ifdef CONFIG_X86_32
27512 mov %esi,xen_start_info
27513 mov $init_thread_union+THREAD_SIZE,%esp
27514 +#ifdef CONFIG_SMP
27515 + movl $cpu_gdt_table,%edi
27516 + movl $__per_cpu_load,%eax
27517 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27518 + rorl $16,%eax
27519 + movb %al,__KERNEL_PERCPU + 4(%edi)
27520 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27521 + movl $__per_cpu_end - 1,%eax
27522 + subl $__per_cpu_start,%eax
27523 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27524 +#endif
27525 #else
27526 mov %rsi,xen_start_info
27527 mov $init_thread_union+THREAD_SIZE,%rsp
27528 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27529 index 202d4c1..99b072a 100644
27530 --- a/arch/x86/xen/xen-ops.h
27531 +++ b/arch/x86/xen/xen-ops.h
27532 @@ -10,8 +10,6 @@
27533 extern const char xen_hypervisor_callback[];
27534 extern const char xen_failsafe_callback[];
27535
27536 -extern void *xen_initial_gdt;
27537 -
27538 struct trap_info;
27539 void xen_copy_trap_info(struct trap_info *traps);
27540
27541 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27542 index 525bd3d..ef888b1 100644
27543 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27544 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27545 @@ -119,9 +119,9 @@
27546 ----------------------------------------------------------------------*/
27547
27548 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27549 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27550 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27551 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27552 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27553
27554 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27555 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27556 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27557 index 2f33760..835e50a 100644
27558 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27559 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27560 @@ -11,6 +11,7 @@
27561 #ifndef _XTENSA_CORE_H
27562 #define _XTENSA_CORE_H
27563
27564 +#include <linux/const.h>
27565
27566 /****************************************************************************
27567 Parameters Useful for Any Code, USER or PRIVILEGED
27568 @@ -112,9 +113,9 @@
27569 ----------------------------------------------------------------------*/
27570
27571 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27572 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27573 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27574 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27575 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27576
27577 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27578 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27579 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27580 index af00795..2bb8105 100644
27581 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27582 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27583 @@ -11,6 +11,7 @@
27584 #ifndef _XTENSA_CORE_CONFIGURATION_H
27585 #define _XTENSA_CORE_CONFIGURATION_H
27586
27587 +#include <linux/const.h>
27588
27589 /****************************************************************************
27590 Parameters Useful for Any Code, USER or PRIVILEGED
27591 @@ -118,9 +119,9 @@
27592 ----------------------------------------------------------------------*/
27593
27594 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27595 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27596 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27597 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27598 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27599
27600 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27601 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27602 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27603 index 58916af..9cb880b 100644
27604 --- a/block/blk-iopoll.c
27605 +++ b/block/blk-iopoll.c
27606 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27607 }
27608 EXPORT_SYMBOL(blk_iopoll_complete);
27609
27610 -static void blk_iopoll_softirq(struct softirq_action *h)
27611 +static void blk_iopoll_softirq(void)
27612 {
27613 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27614 int rearm = 0, budget = blk_iopoll_budget;
27615 diff --git a/block/blk-map.c b/block/blk-map.c
27616 index 623e1cd..ca1e109 100644
27617 --- a/block/blk-map.c
27618 +++ b/block/blk-map.c
27619 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27620 if (!len || !kbuf)
27621 return -EINVAL;
27622
27623 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27624 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27625 if (do_copy)
27626 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27627 else
27628 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27629 index 467c8de..4bddc6d 100644
27630 --- a/block/blk-softirq.c
27631 +++ b/block/blk-softirq.c
27632 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27633 * Softirq action handler - move entries to local list and loop over them
27634 * while passing them to the queue registered handler.
27635 */
27636 -static void blk_done_softirq(struct softirq_action *h)
27637 +static void blk_done_softirq(void)
27638 {
27639 struct list_head *cpu_list, local_list;
27640
27641 diff --git a/block/bsg.c b/block/bsg.c
27642 index ff64ae3..593560c 100644
27643 --- a/block/bsg.c
27644 +++ b/block/bsg.c
27645 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27646 struct sg_io_v4 *hdr, struct bsg_device *bd,
27647 fmode_t has_write_perm)
27648 {
27649 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27650 + unsigned char *cmdptr;
27651 +
27652 if (hdr->request_len > BLK_MAX_CDB) {
27653 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27654 if (!rq->cmd)
27655 return -ENOMEM;
27656 - }
27657 + cmdptr = rq->cmd;
27658 + } else
27659 + cmdptr = tmpcmd;
27660
27661 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27662 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27663 hdr->request_len))
27664 return -EFAULT;
27665
27666 + if (cmdptr != rq->cmd)
27667 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27668 +
27669 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27670 if (blk_verify_command(rq->cmd, has_write_perm))
27671 return -EPERM;
27672 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27673 index 7c668c8..db3521c 100644
27674 --- a/block/compat_ioctl.c
27675 +++ b/block/compat_ioctl.c
27676 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27677 err |= __get_user(f->spec1, &uf->spec1);
27678 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27679 err |= __get_user(name, &uf->name);
27680 - f->name = compat_ptr(name);
27681 + f->name = (void __force_kernel *)compat_ptr(name);
27682 if (err) {
27683 err = -EFAULT;
27684 goto out;
27685 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27686 index 6296b40..417c00f 100644
27687 --- a/block/partitions/efi.c
27688 +++ b/block/partitions/efi.c
27689 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27690 if (!gpt)
27691 return NULL;
27692
27693 + if (!le32_to_cpu(gpt->num_partition_entries))
27694 + return NULL;
27695 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27696 + if (!pte)
27697 + return NULL;
27698 +
27699 count = le32_to_cpu(gpt->num_partition_entries) *
27700 le32_to_cpu(gpt->sizeof_partition_entry);
27701 - if (!count)
27702 - return NULL;
27703 - pte = kzalloc(count, GFP_KERNEL);
27704 - if (!pte)
27705 - return NULL;
27706 -
27707 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27708 (u8 *) pte,
27709 count) < count) {
27710 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27711 index 9a87daa..fb17486 100644
27712 --- a/block/scsi_ioctl.c
27713 +++ b/block/scsi_ioctl.c
27714 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27715 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27716 struct sg_io_hdr *hdr, fmode_t mode)
27717 {
27718 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27719 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27720 + unsigned char *cmdptr;
27721 +
27722 + if (rq->cmd != rq->__cmd)
27723 + cmdptr = rq->cmd;
27724 + else
27725 + cmdptr = tmpcmd;
27726 +
27727 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27728 return -EFAULT;
27729 +
27730 + if (cmdptr != rq->cmd)
27731 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27732 +
27733 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27734 return -EPERM;
27735
27736 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27737 int err;
27738 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27739 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27740 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27741 + unsigned char *cmdptr;
27742
27743 if (!sic)
27744 return -EINVAL;
27745 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27746 */
27747 err = -EFAULT;
27748 rq->cmd_len = cmdlen;
27749 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27750 +
27751 + if (rq->cmd != rq->__cmd)
27752 + cmdptr = rq->cmd;
27753 + else
27754 + cmdptr = tmpcmd;
27755 +
27756 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27757 goto error;
27758
27759 + if (rq->cmd != cmdptr)
27760 + memcpy(rq->cmd, cmdptr, cmdlen);
27761 +
27762 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27763 goto error;
27764
27765 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27766 index 671d4d6..5f24030 100644
27767 --- a/crypto/cryptd.c
27768 +++ b/crypto/cryptd.c
27769 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27770
27771 struct cryptd_blkcipher_request_ctx {
27772 crypto_completion_t complete;
27773 -};
27774 +} __no_const;
27775
27776 struct cryptd_hash_ctx {
27777 struct crypto_shash *child;
27778 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27779
27780 struct cryptd_aead_request_ctx {
27781 crypto_completion_t complete;
27782 -};
27783 +} __no_const;
27784
27785 static void cryptd_queue_worker(struct work_struct *work);
27786
27787 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27788 index e6defd8..c26a225 100644
27789 --- a/drivers/acpi/apei/cper.c
27790 +++ b/drivers/acpi/apei/cper.c
27791 @@ -38,12 +38,12 @@
27792 */
27793 u64 cper_next_record_id(void)
27794 {
27795 - static atomic64_t seq;
27796 + static atomic64_unchecked_t seq;
27797
27798 - if (!atomic64_read(&seq))
27799 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27800 + if (!atomic64_read_unchecked(&seq))
27801 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27802
27803 - return atomic64_inc_return(&seq);
27804 + return atomic64_inc_return_unchecked(&seq);
27805 }
27806 EXPORT_SYMBOL_GPL(cper_next_record_id);
27807
27808 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27809 index 7586544..636a2f0 100644
27810 --- a/drivers/acpi/ec_sys.c
27811 +++ b/drivers/acpi/ec_sys.c
27812 @@ -12,6 +12,7 @@
27813 #include <linux/acpi.h>
27814 #include <linux/debugfs.h>
27815 #include <linux/module.h>
27816 +#include <linux/uaccess.h>
27817 #include "internal.h"
27818
27819 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27820 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27821 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27822 */
27823 unsigned int size = EC_SPACE_SIZE;
27824 - u8 *data = (u8 *) buf;
27825 + u8 data;
27826 loff_t init_off = *off;
27827 int err = 0;
27828
27829 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27830 size = count;
27831
27832 while (size) {
27833 - err = ec_read(*off, &data[*off - init_off]);
27834 + err = ec_read(*off, &data);
27835 if (err)
27836 return err;
27837 + if (put_user(data, &buf[*off - init_off]))
27838 + return -EFAULT;
27839 *off += 1;
27840 size--;
27841 }
27842 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27843
27844 unsigned int size = count;
27845 loff_t init_off = *off;
27846 - u8 *data = (u8 *) buf;
27847 int err = 0;
27848
27849 if (*off >= EC_SPACE_SIZE)
27850 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27851 }
27852
27853 while (size) {
27854 - u8 byte_write = data[*off - init_off];
27855 + u8 byte_write;
27856 + if (get_user(byte_write, &buf[*off - init_off]))
27857 + return -EFAULT;
27858 err = ec_write(*off, byte_write);
27859 if (err)
27860 return err;
27861 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27862 index 251c7b62..000462d 100644
27863 --- a/drivers/acpi/proc.c
27864 +++ b/drivers/acpi/proc.c
27865 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27866 size_t count, loff_t * ppos)
27867 {
27868 struct list_head *node, *next;
27869 - char strbuf[5];
27870 - char str[5] = "";
27871 - unsigned int len = count;
27872 + char strbuf[5] = {0};
27873
27874 - if (len > 4)
27875 - len = 4;
27876 - if (len < 0)
27877 + if (count > 4)
27878 + count = 4;
27879 + if (copy_from_user(strbuf, buffer, count))
27880 return -EFAULT;
27881 -
27882 - if (copy_from_user(strbuf, buffer, len))
27883 - return -EFAULT;
27884 - strbuf[len] = '\0';
27885 - sscanf(strbuf, "%s", str);
27886 + strbuf[count] = '\0';
27887
27888 mutex_lock(&acpi_device_lock);
27889 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27890 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27891 if (!dev->wakeup.flags.valid)
27892 continue;
27893
27894 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27895 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27896 if (device_can_wakeup(&dev->dev)) {
27897 bool enable = !device_may_wakeup(&dev->dev);
27898 device_set_wakeup_enable(&dev->dev, enable);
27899 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27900 index bfc31cb..8213ce1 100644
27901 --- a/drivers/acpi/processor_driver.c
27902 +++ b/drivers/acpi/processor_driver.c
27903 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27904 return 0;
27905 #endif
27906
27907 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27908 + BUG_ON(pr->id >= nr_cpu_ids);
27909
27910 /*
27911 * Buggy BIOS check
27912 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27913 index 8e1039c..ea9cbd4 100644
27914 --- a/drivers/ata/libata-core.c
27915 +++ b/drivers/ata/libata-core.c
27916 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27917 struct ata_port *ap;
27918 unsigned int tag;
27919
27920 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27921 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27922 ap = qc->ap;
27923
27924 qc->flags = 0;
27925 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27926 struct ata_port *ap;
27927 struct ata_link *link;
27928
27929 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27930 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27931 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27932 ap = qc->ap;
27933 link = qc->dev->link;
27934 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27935 return;
27936
27937 spin_lock(&lock);
27938 + pax_open_kernel();
27939
27940 for (cur = ops->inherits; cur; cur = cur->inherits) {
27941 void **inherit = (void **)cur;
27942 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27943 if (IS_ERR(*pp))
27944 *pp = NULL;
27945
27946 - ops->inherits = NULL;
27947 + *(struct ata_port_operations **)&ops->inherits = NULL;
27948
27949 + pax_close_kernel();
27950 spin_unlock(&lock);
27951 }
27952
27953 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27954 index bfaa5cb..3ba1cc3 100644
27955 --- a/drivers/ata/pata_arasan_cf.c
27956 +++ b/drivers/ata/pata_arasan_cf.c
27957 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27958 /* Handle platform specific quirks */
27959 if (pdata->quirk) {
27960 if (pdata->quirk & CF_BROKEN_PIO) {
27961 - ap->ops->set_piomode = NULL;
27962 + pax_open_kernel();
27963 + *(void **)&ap->ops->set_piomode = NULL;
27964 + pax_close_kernel();
27965 ap->pio_mask = 0;
27966 }
27967 if (pdata->quirk & CF_BROKEN_MWDMA)
27968 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27969 index f9b983a..887b9d8 100644
27970 --- a/drivers/atm/adummy.c
27971 +++ b/drivers/atm/adummy.c
27972 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27973 vcc->pop(vcc, skb);
27974 else
27975 dev_kfree_skb_any(skb);
27976 - atomic_inc(&vcc->stats->tx);
27977 + atomic_inc_unchecked(&vcc->stats->tx);
27978
27979 return 0;
27980 }
27981 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27982 index 89b30f3..7964211 100644
27983 --- a/drivers/atm/ambassador.c
27984 +++ b/drivers/atm/ambassador.c
27985 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27986 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27987
27988 // VC layer stats
27989 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27990 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27991
27992 // free the descriptor
27993 kfree (tx_descr);
27994 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27995 dump_skb ("<<<", vc, skb);
27996
27997 // VC layer stats
27998 - atomic_inc(&atm_vcc->stats->rx);
27999 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28000 __net_timestamp(skb);
28001 // end of our responsibility
28002 atm_vcc->push (atm_vcc, skb);
28003 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28004 } else {
28005 PRINTK (KERN_INFO, "dropped over-size frame");
28006 // should we count this?
28007 - atomic_inc(&atm_vcc->stats->rx_drop);
28008 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28009 }
28010
28011 } else {
28012 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28013 }
28014
28015 if (check_area (skb->data, skb->len)) {
28016 - atomic_inc(&atm_vcc->stats->tx_err);
28017 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28018 return -ENOMEM; // ?
28019 }
28020
28021 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28022 index b22d71c..d6e1049 100644
28023 --- a/drivers/atm/atmtcp.c
28024 +++ b/drivers/atm/atmtcp.c
28025 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28026 if (vcc->pop) vcc->pop(vcc,skb);
28027 else dev_kfree_skb(skb);
28028 if (dev_data) return 0;
28029 - atomic_inc(&vcc->stats->tx_err);
28030 + atomic_inc_unchecked(&vcc->stats->tx_err);
28031 return -ENOLINK;
28032 }
28033 size = skb->len+sizeof(struct atmtcp_hdr);
28034 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28035 if (!new_skb) {
28036 if (vcc->pop) vcc->pop(vcc,skb);
28037 else dev_kfree_skb(skb);
28038 - atomic_inc(&vcc->stats->tx_err);
28039 + atomic_inc_unchecked(&vcc->stats->tx_err);
28040 return -ENOBUFS;
28041 }
28042 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28043 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28044 if (vcc->pop) vcc->pop(vcc,skb);
28045 else dev_kfree_skb(skb);
28046 out_vcc->push(out_vcc,new_skb);
28047 - atomic_inc(&vcc->stats->tx);
28048 - atomic_inc(&out_vcc->stats->rx);
28049 + atomic_inc_unchecked(&vcc->stats->tx);
28050 + atomic_inc_unchecked(&out_vcc->stats->rx);
28051 return 0;
28052 }
28053
28054 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28056 read_unlock(&vcc_sklist_lock);
28057 if (!out_vcc) {
28058 - atomic_inc(&vcc->stats->tx_err);
28059 + atomic_inc_unchecked(&vcc->stats->tx_err);
28060 goto done;
28061 }
28062 skb_pull(skb,sizeof(struct atmtcp_hdr));
28063 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28064 __net_timestamp(new_skb);
28065 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28066 out_vcc->push(out_vcc,new_skb);
28067 - atomic_inc(&vcc->stats->tx);
28068 - atomic_inc(&out_vcc->stats->rx);
28069 + atomic_inc_unchecked(&vcc->stats->tx);
28070 + atomic_inc_unchecked(&out_vcc->stats->rx);
28071 done:
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb(skb);
28074 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28075 index 2059ee4..faf51c7 100644
28076 --- a/drivers/atm/eni.c
28077 +++ b/drivers/atm/eni.c
28078 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28079 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28080 vcc->dev->number);
28081 length = 0;
28082 - atomic_inc(&vcc->stats->rx_err);
28083 + atomic_inc_unchecked(&vcc->stats->rx_err);
28084 }
28085 else {
28086 length = ATM_CELL_SIZE-1; /* no HEC */
28087 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28088 size);
28089 }
28090 eff = length = 0;
28091 - atomic_inc(&vcc->stats->rx_err);
28092 + atomic_inc_unchecked(&vcc->stats->rx_err);
28093 }
28094 else {
28095 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28096 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28097 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28098 vcc->dev->number,vcc->vci,length,size << 2,descr);
28099 length = eff = 0;
28100 - atomic_inc(&vcc->stats->rx_err);
28101 + atomic_inc_unchecked(&vcc->stats->rx_err);
28102 }
28103 }
28104 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28105 @@ -767,7 +767,7 @@ rx_dequeued++;
28106 vcc->push(vcc,skb);
28107 pushed++;
28108 }
28109 - atomic_inc(&vcc->stats->rx);
28110 + atomic_inc_unchecked(&vcc->stats->rx);
28111 }
28112 wake_up(&eni_dev->rx_wait);
28113 }
28114 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28115 PCI_DMA_TODEVICE);
28116 if (vcc->pop) vcc->pop(vcc,skb);
28117 else dev_kfree_skb_irq(skb);
28118 - atomic_inc(&vcc->stats->tx);
28119 + atomic_inc_unchecked(&vcc->stats->tx);
28120 wake_up(&eni_dev->tx_wait);
28121 dma_complete++;
28122 }
28123 @@ -1567,7 +1567,7 @@ tx_complete++;
28124 /*--------------------------------- entries ---------------------------------*/
28125
28126
28127 -static const char *media_name[] __devinitdata = {
28128 +static const char *media_name[] __devinitconst = {
28129 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28130 "UTP", "05?", "06?", "07?", /* 4- 7 */
28131 "TAXI","09?", "10?", "11?", /* 8-11 */
28132 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28133 index 86fed1b..6dc4721 100644
28134 --- a/drivers/atm/firestream.c
28135 +++ b/drivers/atm/firestream.c
28136 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28137 }
28138 }
28139
28140 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28141 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28142
28143 fs_dprintk (FS_DEBUG_TXMEM, "i");
28144 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28145 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28146 #endif
28147 skb_put (skb, qe->p1 & 0xffff);
28148 ATM_SKB(skb)->vcc = atm_vcc;
28149 - atomic_inc(&atm_vcc->stats->rx);
28150 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28151 __net_timestamp(skb);
28152 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28153 atm_vcc->push (atm_vcc, skb);
28154 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28155 kfree (pe);
28156 }
28157 if (atm_vcc)
28158 - atomic_inc(&atm_vcc->stats->rx_drop);
28159 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 case 0x1f: /* Reassembly abort: no buffers. */
28162 /* Silently increment error counter. */
28163 if (atm_vcc)
28164 - atomic_inc(&atm_vcc->stats->rx_drop);
28165 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28166 break;
28167 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28168 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28169 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28170 index 361f5ae..7fc552d 100644
28171 --- a/drivers/atm/fore200e.c
28172 +++ b/drivers/atm/fore200e.c
28173 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28174 #endif
28175 /* check error condition */
28176 if (*entry->status & STATUS_ERROR)
28177 - atomic_inc(&vcc->stats->tx_err);
28178 + atomic_inc_unchecked(&vcc->stats->tx_err);
28179 else
28180 - atomic_inc(&vcc->stats->tx);
28181 + atomic_inc_unchecked(&vcc->stats->tx);
28182 }
28183 }
28184
28185 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28186 if (skb == NULL) {
28187 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28188
28189 - atomic_inc(&vcc->stats->rx_drop);
28190 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28191 return -ENOMEM;
28192 }
28193
28194 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28195
28196 dev_kfree_skb_any(skb);
28197
28198 - atomic_inc(&vcc->stats->rx_drop);
28199 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28200 return -ENOMEM;
28201 }
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 vcc->push(vcc, skb);
28206 - atomic_inc(&vcc->stats->rx);
28207 + atomic_inc_unchecked(&vcc->stats->rx);
28208
28209 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28210
28211 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28212 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28213 fore200e->atm_dev->number,
28214 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28215 - atomic_inc(&vcc->stats->rx_err);
28216 + atomic_inc_unchecked(&vcc->stats->rx_err);
28217 }
28218 }
28219
28220 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28221 goto retry_here;
28222 }
28223
28224 - atomic_inc(&vcc->stats->tx_err);
28225 + atomic_inc_unchecked(&vcc->stats->tx_err);
28226
28227 fore200e->tx_sat++;
28228 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28229 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28230 index b182c2f..1c6fa8a 100644
28231 --- a/drivers/atm/he.c
28232 +++ b/drivers/atm/he.c
28233 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28234
28235 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28236 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28237 - atomic_inc(&vcc->stats->rx_drop);
28238 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28239 goto return_host_buffers;
28240 }
28241
28242 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28243 RBRQ_LEN_ERR(he_dev->rbrq_head)
28244 ? "LEN_ERR" : "",
28245 vcc->vpi, vcc->vci);
28246 - atomic_inc(&vcc->stats->rx_err);
28247 + atomic_inc_unchecked(&vcc->stats->rx_err);
28248 goto return_host_buffers;
28249 }
28250
28251 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28252 vcc->push(vcc, skb);
28253 spin_lock(&he_dev->global_lock);
28254
28255 - atomic_inc(&vcc->stats->rx);
28256 + atomic_inc_unchecked(&vcc->stats->rx);
28257
28258 return_host_buffers:
28259 ++pdus_assembled;
28260 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28261 tpd->vcc->pop(tpd->vcc, tpd->skb);
28262 else
28263 dev_kfree_skb_any(tpd->skb);
28264 - atomic_inc(&tpd->vcc->stats->tx_err);
28265 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28266 }
28267 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28268 return;
28269 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28270 vcc->pop(vcc, skb);
28271 else
28272 dev_kfree_skb_any(skb);
28273 - atomic_inc(&vcc->stats->tx_err);
28274 + atomic_inc_unchecked(&vcc->stats->tx_err);
28275 return -EINVAL;
28276 }
28277
28278 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28279 vcc->pop(vcc, skb);
28280 else
28281 dev_kfree_skb_any(skb);
28282 - atomic_inc(&vcc->stats->tx_err);
28283 + atomic_inc_unchecked(&vcc->stats->tx_err);
28284 return -EINVAL;
28285 }
28286 #endif
28287 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28288 vcc->pop(vcc, skb);
28289 else
28290 dev_kfree_skb_any(skb);
28291 - atomic_inc(&vcc->stats->tx_err);
28292 + atomic_inc_unchecked(&vcc->stats->tx_err);
28293 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28294 return -ENOMEM;
28295 }
28296 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28297 vcc->pop(vcc, skb);
28298 else
28299 dev_kfree_skb_any(skb);
28300 - atomic_inc(&vcc->stats->tx_err);
28301 + atomic_inc_unchecked(&vcc->stats->tx_err);
28302 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28303 return -ENOMEM;
28304 }
28305 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28306 __enqueue_tpd(he_dev, tpd, cid);
28307 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28308
28309 - atomic_inc(&vcc->stats->tx);
28310 + atomic_inc_unchecked(&vcc->stats->tx);
28311
28312 return 0;
28313 }
28314 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28315 index 7d01c2a..4e3ac01 100644
28316 --- a/drivers/atm/horizon.c
28317 +++ b/drivers/atm/horizon.c
28318 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28319 {
28320 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28321 // VC layer stats
28322 - atomic_inc(&vcc->stats->rx);
28323 + atomic_inc_unchecked(&vcc->stats->rx);
28324 __net_timestamp(skb);
28325 // end of our responsibility
28326 vcc->push (vcc, skb);
28327 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28328 dev->tx_iovec = NULL;
28329
28330 // VC layer stats
28331 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28332 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28333
28334 // free the skb
28335 hrz_kfree_skb (skb);
28336 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28337 index 8974bd2..b856f85 100644
28338 --- a/drivers/atm/idt77252.c
28339 +++ b/drivers/atm/idt77252.c
28340 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28341 else
28342 dev_kfree_skb(skb);
28343
28344 - atomic_inc(&vcc->stats->tx);
28345 + atomic_inc_unchecked(&vcc->stats->tx);
28346 }
28347
28348 atomic_dec(&scq->used);
28349 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28350 if ((sb = dev_alloc_skb(64)) == NULL) {
28351 printk("%s: Can't allocate buffers for aal0.\n",
28352 card->name);
28353 - atomic_add(i, &vcc->stats->rx_drop);
28354 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28355 break;
28356 }
28357 if (!atm_charge(vcc, sb->truesize)) {
28358 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28359 card->name);
28360 - atomic_add(i - 1, &vcc->stats->rx_drop);
28361 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28362 dev_kfree_skb(sb);
28363 break;
28364 }
28365 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28366 ATM_SKB(sb)->vcc = vcc;
28367 __net_timestamp(sb);
28368 vcc->push(vcc, sb);
28369 - atomic_inc(&vcc->stats->rx);
28370 + atomic_inc_unchecked(&vcc->stats->rx);
28371
28372 cell += ATM_CELL_PAYLOAD;
28373 }
28374 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28375 "(CDC: %08x)\n",
28376 card->name, len, rpp->len, readl(SAR_REG_CDC));
28377 recycle_rx_pool_skb(card, rpp);
28378 - atomic_inc(&vcc->stats->rx_err);
28379 + atomic_inc_unchecked(&vcc->stats->rx_err);
28380 return;
28381 }
28382 if (stat & SAR_RSQE_CRC) {
28383 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28384 recycle_rx_pool_skb(card, rpp);
28385 - atomic_inc(&vcc->stats->rx_err);
28386 + atomic_inc_unchecked(&vcc->stats->rx_err);
28387 return;
28388 }
28389 if (skb_queue_len(&rpp->queue) > 1) {
28390 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28391 RXPRINTK("%s: Can't alloc RX skb.\n",
28392 card->name);
28393 recycle_rx_pool_skb(card, rpp);
28394 - atomic_inc(&vcc->stats->rx_err);
28395 + atomic_inc_unchecked(&vcc->stats->rx_err);
28396 return;
28397 }
28398 if (!atm_charge(vcc, skb->truesize)) {
28399 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28400 __net_timestamp(skb);
28401
28402 vcc->push(vcc, skb);
28403 - atomic_inc(&vcc->stats->rx);
28404 + atomic_inc_unchecked(&vcc->stats->rx);
28405
28406 return;
28407 }
28408 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28409 __net_timestamp(skb);
28410
28411 vcc->push(vcc, skb);
28412 - atomic_inc(&vcc->stats->rx);
28413 + atomic_inc_unchecked(&vcc->stats->rx);
28414
28415 if (skb->truesize > SAR_FB_SIZE_3)
28416 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28417 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28418 if (vcc->qos.aal != ATM_AAL0) {
28419 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28420 card->name, vpi, vci);
28421 - atomic_inc(&vcc->stats->rx_drop);
28422 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28423 goto drop;
28424 }
28425
28426 if ((sb = dev_alloc_skb(64)) == NULL) {
28427 printk("%s: Can't allocate buffers for AAL0.\n",
28428 card->name);
28429 - atomic_inc(&vcc->stats->rx_err);
28430 + atomic_inc_unchecked(&vcc->stats->rx_err);
28431 goto drop;
28432 }
28433
28434 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28435 ATM_SKB(sb)->vcc = vcc;
28436 __net_timestamp(sb);
28437 vcc->push(vcc, sb);
28438 - atomic_inc(&vcc->stats->rx);
28439 + atomic_inc_unchecked(&vcc->stats->rx);
28440
28441 drop:
28442 skb_pull(queue, 64);
28443 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28444
28445 if (vc == NULL) {
28446 printk("%s: NULL connection in send().\n", card->name);
28447 - atomic_inc(&vcc->stats->tx_err);
28448 + atomic_inc_unchecked(&vcc->stats->tx_err);
28449 dev_kfree_skb(skb);
28450 return -EINVAL;
28451 }
28452 if (!test_bit(VCF_TX, &vc->flags)) {
28453 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28454 - atomic_inc(&vcc->stats->tx_err);
28455 + atomic_inc_unchecked(&vcc->stats->tx_err);
28456 dev_kfree_skb(skb);
28457 return -EINVAL;
28458 }
28459 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28460 break;
28461 default:
28462 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28463 - atomic_inc(&vcc->stats->tx_err);
28464 + atomic_inc_unchecked(&vcc->stats->tx_err);
28465 dev_kfree_skb(skb);
28466 return -EINVAL;
28467 }
28468
28469 if (skb_shinfo(skb)->nr_frags != 0) {
28470 printk("%s: No scatter-gather yet.\n", card->name);
28471 - atomic_inc(&vcc->stats->tx_err);
28472 + atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb(skb);
28474 return -EINVAL;
28475 }
28476 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28477
28478 err = queue_skb(card, vc, skb, oam);
28479 if (err) {
28480 - atomic_inc(&vcc->stats->tx_err);
28481 + atomic_inc_unchecked(&vcc->stats->tx_err);
28482 dev_kfree_skb(skb);
28483 return err;
28484 }
28485 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28486 skb = dev_alloc_skb(64);
28487 if (!skb) {
28488 printk("%s: Out of memory in send_oam().\n", card->name);
28489 - atomic_inc(&vcc->stats->tx_err);
28490 + atomic_inc_unchecked(&vcc->stats->tx_err);
28491 return -ENOMEM;
28492 }
28493 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28494 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28495 index 96cce6d..62c3ec5 100644
28496 --- a/drivers/atm/iphase.c
28497 +++ b/drivers/atm/iphase.c
28498 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28499 status = (u_short) (buf_desc_ptr->desc_mode);
28500 if (status & (RX_CER | RX_PTE | RX_OFL))
28501 {
28502 - atomic_inc(&vcc->stats->rx_err);
28503 + atomic_inc_unchecked(&vcc->stats->rx_err);
28504 IF_ERR(printk("IA: bad packet, dropping it");)
28505 if (status & RX_CER) {
28506 IF_ERR(printk(" cause: packet CRC error\n");)
28507 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28508 len = dma_addr - buf_addr;
28509 if (len > iadev->rx_buf_sz) {
28510 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28511 - atomic_inc(&vcc->stats->rx_err);
28512 + atomic_inc_unchecked(&vcc->stats->rx_err);
28513 goto out_free_desc;
28514 }
28515
28516 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28517 ia_vcc = INPH_IA_VCC(vcc);
28518 if (ia_vcc == NULL)
28519 {
28520 - atomic_inc(&vcc->stats->rx_err);
28521 + atomic_inc_unchecked(&vcc->stats->rx_err);
28522 atm_return(vcc, skb->truesize);
28523 dev_kfree_skb_any(skb);
28524 goto INCR_DLE;
28525 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28526 if ((length > iadev->rx_buf_sz) || (length >
28527 (skb->len - sizeof(struct cpcs_trailer))))
28528 {
28529 - atomic_inc(&vcc->stats->rx_err);
28530 + atomic_inc_unchecked(&vcc->stats->rx_err);
28531 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28532 length, skb->len);)
28533 atm_return(vcc, skb->truesize);
28534 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28535
28536 IF_RX(printk("rx_dle_intr: skb push");)
28537 vcc->push(vcc,skb);
28538 - atomic_inc(&vcc->stats->rx);
28539 + atomic_inc_unchecked(&vcc->stats->rx);
28540 iadev->rx_pkt_cnt++;
28541 }
28542 INCR_DLE:
28543 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28544 {
28545 struct k_sonet_stats *stats;
28546 stats = &PRIV(_ia_dev[board])->sonet_stats;
28547 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28548 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28549 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28550 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28551 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28552 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28553 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28554 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28555 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28556 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28557 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28558 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28559 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28560 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28561 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28562 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28563 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28564 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28565 }
28566 ia_cmds.status = 0;
28567 break;
28568 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28569 if ((desc == 0) || (desc > iadev->num_tx_desc))
28570 {
28571 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28572 - atomic_inc(&vcc->stats->tx);
28573 + atomic_inc_unchecked(&vcc->stats->tx);
28574 if (vcc->pop)
28575 vcc->pop(vcc, skb);
28576 else
28577 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28578 ATM_DESC(skb) = vcc->vci;
28579 skb_queue_tail(&iadev->tx_dma_q, skb);
28580
28581 - atomic_inc(&vcc->stats->tx);
28582 + atomic_inc_unchecked(&vcc->stats->tx);
28583 iadev->tx_pkt_cnt++;
28584 /* Increment transaction counter */
28585 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28586
28587 #if 0
28588 /* add flow control logic */
28589 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28590 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28591 if (iavcc->vc_desc_cnt > 10) {
28592 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28593 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28594 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28595 index 68c7588..7036683 100644
28596 --- a/drivers/atm/lanai.c
28597 +++ b/drivers/atm/lanai.c
28598 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28599 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28600 lanai_endtx(lanai, lvcc);
28601 lanai_free_skb(lvcc->tx.atmvcc, skb);
28602 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28603 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28604 }
28605
28606 /* Try to fill the buffer - don't call unless there is backlog */
28607 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28608 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28609 __net_timestamp(skb);
28610 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28611 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28612 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28613 out:
28614 lvcc->rx.buf.ptr = end;
28615 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28616 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28617 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28618 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28619 lanai->stats.service_rxnotaal5++;
28620 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28621 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28622 return 0;
28623 }
28624 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28625 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28626 int bytes;
28627 read_unlock(&vcc_sklist_lock);
28628 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28629 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28630 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28631 lvcc->stats.x.aal5.service_trash++;
28632 bytes = (SERVICE_GET_END(s) * 16) -
28633 (((unsigned long) lvcc->rx.buf.ptr) -
28634 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28635 }
28636 if (s & SERVICE_STREAM) {
28637 read_unlock(&vcc_sklist_lock);
28638 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28639 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28640 lvcc->stats.x.aal5.service_stream++;
28641 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28642 "PDU on VCI %d!\n", lanai->number, vci);
28643 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28644 return 0;
28645 }
28646 DPRINTK("got rx crc error on vci %d\n", vci);
28647 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28648 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28649 lvcc->stats.x.aal5.service_rxcrc++;
28650 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28651 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28652 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28653 index 1c70c45..300718d 100644
28654 --- a/drivers/atm/nicstar.c
28655 +++ b/drivers/atm/nicstar.c
28656 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28657 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28658 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28659 card->index);
28660 - atomic_inc(&vcc->stats->tx_err);
28661 + atomic_inc_unchecked(&vcc->stats->tx_err);
28662 dev_kfree_skb_any(skb);
28663 return -EINVAL;
28664 }
28665 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28666 if (!vc->tx) {
28667 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28668 card->index);
28669 - atomic_inc(&vcc->stats->tx_err);
28670 + atomic_inc_unchecked(&vcc->stats->tx_err);
28671 dev_kfree_skb_any(skb);
28672 return -EINVAL;
28673 }
28674 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28675 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28676 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28677 card->index);
28678 - atomic_inc(&vcc->stats->tx_err);
28679 + atomic_inc_unchecked(&vcc->stats->tx_err);
28680 dev_kfree_skb_any(skb);
28681 return -EINVAL;
28682 }
28683
28684 if (skb_shinfo(skb)->nr_frags != 0) {
28685 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28686 - atomic_inc(&vcc->stats->tx_err);
28687 + atomic_inc_unchecked(&vcc->stats->tx_err);
28688 dev_kfree_skb_any(skb);
28689 return -EINVAL;
28690 }
28691 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28692 }
28693
28694 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28695 - atomic_inc(&vcc->stats->tx_err);
28696 + atomic_inc_unchecked(&vcc->stats->tx_err);
28697 dev_kfree_skb_any(skb);
28698 return -EIO;
28699 }
28700 - atomic_inc(&vcc->stats->tx);
28701 + atomic_inc_unchecked(&vcc->stats->tx);
28702
28703 return 0;
28704 }
28705 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 printk
28707 ("nicstar%d: Can't allocate buffers for aal0.\n",
28708 card->index);
28709 - atomic_add(i, &vcc->stats->rx_drop);
28710 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28711 break;
28712 }
28713 if (!atm_charge(vcc, sb->truesize)) {
28714 RXPRINTK
28715 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28716 card->index);
28717 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28718 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28719 dev_kfree_skb_any(sb);
28720 break;
28721 }
28722 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28723 ATM_SKB(sb)->vcc = vcc;
28724 __net_timestamp(sb);
28725 vcc->push(vcc, sb);
28726 - atomic_inc(&vcc->stats->rx);
28727 + atomic_inc_unchecked(&vcc->stats->rx);
28728 cell += ATM_CELL_PAYLOAD;
28729 }
28730
28731 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28732 if (iovb == NULL) {
28733 printk("nicstar%d: Out of iovec buffers.\n",
28734 card->index);
28735 - atomic_inc(&vcc->stats->rx_drop);
28736 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28737 recycle_rx_buf(card, skb);
28738 return;
28739 }
28740 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28741 small or large buffer itself. */
28742 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28743 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28744 - atomic_inc(&vcc->stats->rx_err);
28745 + atomic_inc_unchecked(&vcc->stats->rx_err);
28746 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28747 NS_MAX_IOVECS);
28748 NS_PRV_IOVCNT(iovb) = 0;
28749 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28750 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28751 card->index);
28752 which_list(card, skb);
28753 - atomic_inc(&vcc->stats->rx_err);
28754 + atomic_inc_unchecked(&vcc->stats->rx_err);
28755 recycle_rx_buf(card, skb);
28756 vc->rx_iov = NULL;
28757 recycle_iov_buf(card, iovb);
28758 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28759 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28760 card->index);
28761 which_list(card, skb);
28762 - atomic_inc(&vcc->stats->rx_err);
28763 + atomic_inc_unchecked(&vcc->stats->rx_err);
28764 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28765 NS_PRV_IOVCNT(iovb));
28766 vc->rx_iov = NULL;
28767 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28768 printk(" - PDU size mismatch.\n");
28769 else
28770 printk(".\n");
28771 - atomic_inc(&vcc->stats->rx_err);
28772 + atomic_inc_unchecked(&vcc->stats->rx_err);
28773 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28774 NS_PRV_IOVCNT(iovb));
28775 vc->rx_iov = NULL;
28776 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28777 /* skb points to a small buffer */
28778 if (!atm_charge(vcc, skb->truesize)) {
28779 push_rxbufs(card, skb);
28780 - atomic_inc(&vcc->stats->rx_drop);
28781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28782 } else {
28783 skb_put(skb, len);
28784 dequeue_sm_buf(card, skb);
28785 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28786 ATM_SKB(skb)->vcc = vcc;
28787 __net_timestamp(skb);
28788 vcc->push(vcc, skb);
28789 - atomic_inc(&vcc->stats->rx);
28790 + atomic_inc_unchecked(&vcc->stats->rx);
28791 }
28792 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28793 struct sk_buff *sb;
28794 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28795 if (len <= NS_SMBUFSIZE) {
28796 if (!atm_charge(vcc, sb->truesize)) {
28797 push_rxbufs(card, sb);
28798 - atomic_inc(&vcc->stats->rx_drop);
28799 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28800 } else {
28801 skb_put(sb, len);
28802 dequeue_sm_buf(card, sb);
28803 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28804 ATM_SKB(sb)->vcc = vcc;
28805 __net_timestamp(sb);
28806 vcc->push(vcc, sb);
28807 - atomic_inc(&vcc->stats->rx);
28808 + atomic_inc_unchecked(&vcc->stats->rx);
28809 }
28810
28811 push_rxbufs(card, skb);
28812 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813
28814 if (!atm_charge(vcc, skb->truesize)) {
28815 push_rxbufs(card, skb);
28816 - atomic_inc(&vcc->stats->rx_drop);
28817 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28818 } else {
28819 dequeue_lg_buf(card, skb);
28820 #ifdef NS_USE_DESTRUCTORS
28821 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 ATM_SKB(skb)->vcc = vcc;
28823 __net_timestamp(skb);
28824 vcc->push(vcc, skb);
28825 - atomic_inc(&vcc->stats->rx);
28826 + atomic_inc_unchecked(&vcc->stats->rx);
28827 }
28828
28829 push_rxbufs(card, sb);
28830 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 printk
28832 ("nicstar%d: Out of huge buffers.\n",
28833 card->index);
28834 - atomic_inc(&vcc->stats->rx_drop);
28835 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28836 recycle_iovec_rx_bufs(card,
28837 (struct iovec *)
28838 iovb->data,
28839 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 card->hbpool.count++;
28841 } else
28842 dev_kfree_skb_any(hb);
28843 - atomic_inc(&vcc->stats->rx_drop);
28844 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28845 } else {
28846 /* Copy the small buffer to the huge buffer */
28847 sb = (struct sk_buff *)iov->iov_base;
28848 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28849 #endif /* NS_USE_DESTRUCTORS */
28850 __net_timestamp(hb);
28851 vcc->push(vcc, hb);
28852 - atomic_inc(&vcc->stats->rx);
28853 + atomic_inc_unchecked(&vcc->stats->rx);
28854 }
28855 }
28856
28857 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28858 index 9851093..adb2b1e 100644
28859 --- a/drivers/atm/solos-pci.c
28860 +++ b/drivers/atm/solos-pci.c
28861 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28862 }
28863 atm_charge(vcc, skb->truesize);
28864 vcc->push(vcc, skb);
28865 - atomic_inc(&vcc->stats->rx);
28866 + atomic_inc_unchecked(&vcc->stats->rx);
28867 break;
28868
28869 case PKT_STATUS:
28870 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28871 vcc = SKB_CB(oldskb)->vcc;
28872
28873 if (vcc) {
28874 - atomic_inc(&vcc->stats->tx);
28875 + atomic_inc_unchecked(&vcc->stats->tx);
28876 solos_pop(vcc, oldskb);
28877 } else
28878 dev_kfree_skb_irq(oldskb);
28879 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28880 index 0215934..ce9f5b1 100644
28881 --- a/drivers/atm/suni.c
28882 +++ b/drivers/atm/suni.c
28883 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28884
28885
28886 #define ADD_LIMITED(s,v) \
28887 - atomic_add((v),&stats->s); \
28888 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28889 + atomic_add_unchecked((v),&stats->s); \
28890 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28891
28892
28893 static void suni_hz(unsigned long from_timer)
28894 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28895 index 5120a96..e2572bd 100644
28896 --- a/drivers/atm/uPD98402.c
28897 +++ b/drivers/atm/uPD98402.c
28898 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28899 struct sonet_stats tmp;
28900 int error = 0;
28901
28902 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28903 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28904 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28905 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28906 if (zero && !error) {
28907 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28908
28909
28910 #define ADD_LIMITED(s,v) \
28911 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28912 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28913 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28914 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28915 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28916 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28917
28918
28919 static void stat_event(struct atm_dev *dev)
28920 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28921 if (reason & uPD98402_INT_PFM) stat_event(dev);
28922 if (reason & uPD98402_INT_PCO) {
28923 (void) GET(PCOCR); /* clear interrupt cause */
28924 - atomic_add(GET(HECCT),
28925 + atomic_add_unchecked(GET(HECCT),
28926 &PRIV(dev)->sonet_stats.uncorr_hcs);
28927 }
28928 if ((reason & uPD98402_INT_RFO) &&
28929 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28930 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28931 uPD98402_INT_LOS),PIMR); /* enable them */
28932 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28933 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28934 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28935 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28936 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28937 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28938 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28939 return 0;
28940 }
28941
28942 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28943 index abe4e20..83c4727 100644
28944 --- a/drivers/atm/zatm.c
28945 +++ b/drivers/atm/zatm.c
28946 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28947 }
28948 if (!size) {
28949 dev_kfree_skb_irq(skb);
28950 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28951 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28952 continue;
28953 }
28954 if (!atm_charge(vcc,skb->truesize)) {
28955 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28956 skb->len = size;
28957 ATM_SKB(skb)->vcc = vcc;
28958 vcc->push(vcc,skb);
28959 - atomic_inc(&vcc->stats->rx);
28960 + atomic_inc_unchecked(&vcc->stats->rx);
28961 }
28962 zout(pos & 0xffff,MTA(mbx));
28963 #if 0 /* probably a stupid idea */
28964 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28965 skb_queue_head(&zatm_vcc->backlog,skb);
28966 break;
28967 }
28968 - atomic_inc(&vcc->stats->tx);
28969 + atomic_inc_unchecked(&vcc->stats->tx);
28970 wake_up(&zatm_vcc->tx_wait);
28971 }
28972
28973 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28974 index deb4a45..211eff2 100644
28975 --- a/drivers/base/devtmpfs.c
28976 +++ b/drivers/base/devtmpfs.c
28977 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28978 if (!thread)
28979 return 0;
28980
28981 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28982 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28983 if (err)
28984 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28985 else
28986 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28987 index cbb463b..babe2cf 100644
28988 --- a/drivers/base/power/wakeup.c
28989 +++ b/drivers/base/power/wakeup.c
28990 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28991 * They need to be modified together atomically, so it's better to use one
28992 * atomic variable to hold them both.
28993 */
28994 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28995 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28996
28997 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28998 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28999
29000 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29001 {
29002 - unsigned int comb = atomic_read(&combined_event_count);
29003 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29004
29005 *cnt = (comb >> IN_PROGRESS_BITS);
29006 *inpr = comb & MAX_IN_PROGRESS;
29007 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29008 ws->start_prevent_time = ws->last_time;
29009
29010 /* Increment the counter of events in progress. */
29011 - cec = atomic_inc_return(&combined_event_count);
29012 + cec = atomic_inc_return_unchecked(&combined_event_count);
29013
29014 trace_wakeup_source_activate(ws->name, cec);
29015 }
29016 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29017 * Increment the counter of registered wakeup events and decrement the
29018 * couter of wakeup events in progress simultaneously.
29019 */
29020 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29021 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29022 trace_wakeup_source_deactivate(ws->name, cec);
29023
29024 split_counters(&cnt, &inpr);
29025 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29026 index b0f553b..77b928b 100644
29027 --- a/drivers/block/cciss.c
29028 +++ b/drivers/block/cciss.c
29029 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29030 int err;
29031 u32 cp;
29032
29033 + memset(&arg64, 0, sizeof(arg64));
29034 +
29035 err = 0;
29036 err |=
29037 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29038 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29039 while (!list_empty(&h->reqQ)) {
29040 c = list_entry(h->reqQ.next, CommandList_struct, list);
29041 /* can't do anything if fifo is full */
29042 - if ((h->access.fifo_full(h))) {
29043 + if ((h->access->fifo_full(h))) {
29044 dev_warn(&h->pdev->dev, "fifo full\n");
29045 break;
29046 }
29047 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29048 h->Qdepth--;
29049
29050 /* Tell the controller execute command */
29051 - h->access.submit_command(h, c);
29052 + h->access->submit_command(h, c);
29053
29054 /* Put job onto the completed Q */
29055 addQ(&h->cmpQ, c);
29056 @@ -3443,17 +3445,17 @@ startio:
29057
29058 static inline unsigned long get_next_completion(ctlr_info_t *h)
29059 {
29060 - return h->access.command_completed(h);
29061 + return h->access->command_completed(h);
29062 }
29063
29064 static inline int interrupt_pending(ctlr_info_t *h)
29065 {
29066 - return h->access.intr_pending(h);
29067 + return h->access->intr_pending(h);
29068 }
29069
29070 static inline long interrupt_not_for_us(ctlr_info_t *h)
29071 {
29072 - return ((h->access.intr_pending(h) == 0) ||
29073 + return ((h->access->intr_pending(h) == 0) ||
29074 (h->interrupts_enabled == 0));
29075 }
29076
29077 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29078 u32 a;
29079
29080 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29081 - return h->access.command_completed(h);
29082 + return h->access->command_completed(h);
29083
29084 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29085 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29086 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29087 trans_support & CFGTBL_Trans_use_short_tags);
29088
29089 /* Change the access methods to the performant access methods */
29090 - h->access = SA5_performant_access;
29091 + h->access = &SA5_performant_access;
29092 h->transMethod = CFGTBL_Trans_Performant;
29093
29094 return;
29095 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29096 if (prod_index < 0)
29097 return -ENODEV;
29098 h->product_name = products[prod_index].product_name;
29099 - h->access = *(products[prod_index].access);
29100 + h->access = products[prod_index].access;
29101
29102 if (cciss_board_disabled(h)) {
29103 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29104 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29105 }
29106
29107 /* make sure the board interrupts are off */
29108 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29109 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29110 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29111 if (rc)
29112 goto clean2;
29113 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29114 * fake ones to scoop up any residual completions.
29115 */
29116 spin_lock_irqsave(&h->lock, flags);
29117 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29118 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29119 spin_unlock_irqrestore(&h->lock, flags);
29120 free_irq(h->intr[h->intr_mode], h);
29121 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29122 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29123 dev_info(&h->pdev->dev, "Board READY.\n");
29124 dev_info(&h->pdev->dev,
29125 "Waiting for stale completions to drain.\n");
29126 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29127 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29128 msleep(10000);
29129 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29130 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29131
29132 rc = controller_reset_failed(h->cfgtable);
29133 if (rc)
29134 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29135 cciss_scsi_setup(h);
29136
29137 /* Turn the interrupts on so we can service requests */
29138 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29139 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29140
29141 /* Get the firmware version */
29142 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29143 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29144 kfree(flush_buf);
29145 if (return_code != IO_OK)
29146 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29147 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29148 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29149 free_irq(h->intr[h->intr_mode], h);
29150 }
29151
29152 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29153 index 7fda30e..eb5dfe0 100644
29154 --- a/drivers/block/cciss.h
29155 +++ b/drivers/block/cciss.h
29156 @@ -101,7 +101,7 @@ struct ctlr_info
29157 /* information about each logical volume */
29158 drive_info_struct *drv[CISS_MAX_LUN];
29159
29160 - struct access_method access;
29161 + struct access_method *access;
29162
29163 /* queue and queue Info */
29164 struct list_head reqQ;
29165 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29166 index 9125bbe..eede5c8 100644
29167 --- a/drivers/block/cpqarray.c
29168 +++ b/drivers/block/cpqarray.c
29169 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29170 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29171 goto Enomem4;
29172 }
29173 - hba[i]->access.set_intr_mask(hba[i], 0);
29174 + hba[i]->access->set_intr_mask(hba[i], 0);
29175 if (request_irq(hba[i]->intr, do_ida_intr,
29176 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29177 {
29178 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29179 add_timer(&hba[i]->timer);
29180
29181 /* Enable IRQ now that spinlock and rate limit timer are set up */
29182 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29183 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29184
29185 for(j=0; j<NWD; j++) {
29186 struct gendisk *disk = ida_gendisk[i][j];
29187 @@ -694,7 +694,7 @@ DBGINFO(
29188 for(i=0; i<NR_PRODUCTS; i++) {
29189 if (board_id == products[i].board_id) {
29190 c->product_name = products[i].product_name;
29191 - c->access = *(products[i].access);
29192 + c->access = products[i].access;
29193 break;
29194 }
29195 }
29196 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29197 hba[ctlr]->intr = intr;
29198 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29199 hba[ctlr]->product_name = products[j].product_name;
29200 - hba[ctlr]->access = *(products[j].access);
29201 + hba[ctlr]->access = products[j].access;
29202 hba[ctlr]->ctlr = ctlr;
29203 hba[ctlr]->board_id = board_id;
29204 hba[ctlr]->pci_dev = NULL; /* not PCI */
29205 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29206
29207 while((c = h->reqQ) != NULL) {
29208 /* Can't do anything if we're busy */
29209 - if (h->access.fifo_full(h) == 0)
29210 + if (h->access->fifo_full(h) == 0)
29211 return;
29212
29213 /* Get the first entry from the request Q */
29214 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29215 h->Qdepth--;
29216
29217 /* Tell the controller to do our bidding */
29218 - h->access.submit_command(h, c);
29219 + h->access->submit_command(h, c);
29220
29221 /* Get onto the completion Q */
29222 addQ(&h->cmpQ, c);
29223 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29224 unsigned long flags;
29225 __u32 a,a1;
29226
29227 - istat = h->access.intr_pending(h);
29228 + istat = h->access->intr_pending(h);
29229 /* Is this interrupt for us? */
29230 if (istat == 0)
29231 return IRQ_NONE;
29232 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29233 */
29234 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29235 if (istat & FIFO_NOT_EMPTY) {
29236 - while((a = h->access.command_completed(h))) {
29237 + while((a = h->access->command_completed(h))) {
29238 a1 = a; a &= ~3;
29239 if ((c = h->cmpQ) == NULL)
29240 {
29241 @@ -1449,11 +1449,11 @@ static int sendcmd(
29242 /*
29243 * Disable interrupt
29244 */
29245 - info_p->access.set_intr_mask(info_p, 0);
29246 + info_p->access->set_intr_mask(info_p, 0);
29247 /* Make sure there is room in the command FIFO */
29248 /* Actually it should be completely empty at this time. */
29249 for (i = 200000; i > 0; i--) {
29250 - temp = info_p->access.fifo_full(info_p);
29251 + temp = info_p->access->fifo_full(info_p);
29252 if (temp != 0) {
29253 break;
29254 }
29255 @@ -1466,7 +1466,7 @@ DBG(
29256 /*
29257 * Send the cmd
29258 */
29259 - info_p->access.submit_command(info_p, c);
29260 + info_p->access->submit_command(info_p, c);
29261 complete = pollcomplete(ctlr);
29262
29263 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29264 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29265 * we check the new geometry. Then turn interrupts back on when
29266 * we're done.
29267 */
29268 - host->access.set_intr_mask(host, 0);
29269 + host->access->set_intr_mask(host, 0);
29270 getgeometry(ctlr);
29271 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29272 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29273
29274 for(i=0; i<NWD; i++) {
29275 struct gendisk *disk = ida_gendisk[ctlr][i];
29276 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29277 /* Wait (up to 2 seconds) for a command to complete */
29278
29279 for (i = 200000; i > 0; i--) {
29280 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29281 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29282 if (done == 0) {
29283 udelay(10); /* a short fixed delay */
29284 } else
29285 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29286 index be73e9d..7fbf140 100644
29287 --- a/drivers/block/cpqarray.h
29288 +++ b/drivers/block/cpqarray.h
29289 @@ -99,7 +99,7 @@ struct ctlr_info {
29290 drv_info_t drv[NWD];
29291 struct proc_dir_entry *proc;
29292
29293 - struct access_method access;
29294 + struct access_method *access;
29295
29296 cmdlist_t *reqQ;
29297 cmdlist_t *cmpQ;
29298 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29299 index b953cc7..e3dc580 100644
29300 --- a/drivers/block/drbd/drbd_int.h
29301 +++ b/drivers/block/drbd/drbd_int.h
29302 @@ -735,7 +735,7 @@ struct drbd_request;
29303 struct drbd_epoch {
29304 struct list_head list;
29305 unsigned int barrier_nr;
29306 - atomic_t epoch_size; /* increased on every request added. */
29307 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29308 atomic_t active; /* increased on every req. added, and dec on every finished. */
29309 unsigned long flags;
29310 };
29311 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29312 void *int_dig_in;
29313 void *int_dig_vv;
29314 wait_queue_head_t seq_wait;
29315 - atomic_t packet_seq;
29316 + atomic_unchecked_t packet_seq;
29317 unsigned int peer_seq;
29318 spinlock_t peer_seq_lock;
29319 unsigned int minor;
29320 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29321
29322 static inline void drbd_tcp_cork(struct socket *sock)
29323 {
29324 - int __user val = 1;
29325 + int val = 1;
29326 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29327 - (char __user *)&val, sizeof(val));
29328 + (char __force_user *)&val, sizeof(val));
29329 }
29330
29331 static inline void drbd_tcp_uncork(struct socket *sock)
29332 {
29333 - int __user val = 0;
29334 + int val = 0;
29335 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29336 - (char __user *)&val, sizeof(val));
29337 + (char __force_user *)&val, sizeof(val));
29338 }
29339
29340 static inline void drbd_tcp_nodelay(struct socket *sock)
29341 {
29342 - int __user val = 1;
29343 + int val = 1;
29344 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29345 - (char __user *)&val, sizeof(val));
29346 + (char __force_user *)&val, sizeof(val));
29347 }
29348
29349 static inline void drbd_tcp_quickack(struct socket *sock)
29350 {
29351 - int __user val = 2;
29352 + int val = 2;
29353 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29354 - (char __user *)&val, sizeof(val));
29355 + (char __force_user *)&val, sizeof(val));
29356 }
29357
29358 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29359 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29360 index f93a032..71c87bf 100644
29361 --- a/drivers/block/drbd/drbd_main.c
29362 +++ b/drivers/block/drbd/drbd_main.c
29363 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29364 p.sector = sector;
29365 p.block_id = block_id;
29366 p.blksize = blksize;
29367 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29368 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29369
29370 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29371 return false;
29372 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29373
29374 p.sector = cpu_to_be64(req->sector);
29375 p.block_id = (unsigned long)req;
29376 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29377 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29378
29379 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29380
29381 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29382 atomic_set(&mdev->unacked_cnt, 0);
29383 atomic_set(&mdev->local_cnt, 0);
29384 atomic_set(&mdev->net_cnt, 0);
29385 - atomic_set(&mdev->packet_seq, 0);
29386 + atomic_set_unchecked(&mdev->packet_seq, 0);
29387 atomic_set(&mdev->pp_in_use, 0);
29388 atomic_set(&mdev->pp_in_use_by_net, 0);
29389 atomic_set(&mdev->rs_sect_in, 0);
29390 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29391 mdev->receiver.t_state);
29392
29393 /* no need to lock it, I'm the only thread alive */
29394 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29395 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29396 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29397 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29398 mdev->al_writ_cnt =
29399 mdev->bm_writ_cnt =
29400 mdev->read_cnt =
29401 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29402 index edb490a..ecd69da 100644
29403 --- a/drivers/block/drbd/drbd_nl.c
29404 +++ b/drivers/block/drbd/drbd_nl.c
29405 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29406 module_put(THIS_MODULE);
29407 }
29408
29409 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29410 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29411
29412 static unsigned short *
29413 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29414 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29415 cn_reply->id.idx = CN_IDX_DRBD;
29416 cn_reply->id.val = CN_VAL_DRBD;
29417
29418 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29419 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29420 cn_reply->ack = 0; /* not used here. */
29421 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29422 (int)((char *)tl - (char *)reply->tag_list);
29423 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29424 cn_reply->id.idx = CN_IDX_DRBD;
29425 cn_reply->id.val = CN_VAL_DRBD;
29426
29427 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29428 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29429 cn_reply->ack = 0; /* not used here. */
29430 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29431 (int)((char *)tl - (char *)reply->tag_list);
29432 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29433 cn_reply->id.idx = CN_IDX_DRBD;
29434 cn_reply->id.val = CN_VAL_DRBD;
29435
29436 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29437 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29438 cn_reply->ack = 0; // not used here.
29439 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29440 (int)((char*)tl - (char*)reply->tag_list);
29441 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29442 cn_reply->id.idx = CN_IDX_DRBD;
29443 cn_reply->id.val = CN_VAL_DRBD;
29444
29445 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29446 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29447 cn_reply->ack = 0; /* not used here. */
29448 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29449 (int)((char *)tl - (char *)reply->tag_list);
29450 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29451 index c74ca2d..860c819 100644
29452 --- a/drivers/block/drbd/drbd_receiver.c
29453 +++ b/drivers/block/drbd/drbd_receiver.c
29454 @@ -898,7 +898,7 @@ retry:
29455 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29456 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29457
29458 - atomic_set(&mdev->packet_seq, 0);
29459 + atomic_set_unchecked(&mdev->packet_seq, 0);
29460 mdev->peer_seq = 0;
29461
29462 if (drbd_send_protocol(mdev) == -1)
29463 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29464 do {
29465 next_epoch = NULL;
29466
29467 - epoch_size = atomic_read(&epoch->epoch_size);
29468 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29469
29470 switch (ev & ~EV_CLEANUP) {
29471 case EV_PUT:
29472 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29473 rv = FE_DESTROYED;
29474 } else {
29475 epoch->flags = 0;
29476 - atomic_set(&epoch->epoch_size, 0);
29477 + atomic_set_unchecked(&epoch->epoch_size, 0);
29478 /* atomic_set(&epoch->active, 0); is already zero */
29479 if (rv == FE_STILL_LIVE)
29480 rv = FE_RECYCLED;
29481 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29482 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29483 drbd_flush(mdev);
29484
29485 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29486 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29487 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29488 if (epoch)
29489 break;
29490 }
29491
29492 epoch = mdev->current_epoch;
29493 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29494 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29495
29496 D_ASSERT(atomic_read(&epoch->active) == 0);
29497 D_ASSERT(epoch->flags == 0);
29498 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29499 }
29500
29501 epoch->flags = 0;
29502 - atomic_set(&epoch->epoch_size, 0);
29503 + atomic_set_unchecked(&epoch->epoch_size, 0);
29504 atomic_set(&epoch->active, 0);
29505
29506 spin_lock(&mdev->epoch_lock);
29507 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29508 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29509 list_add(&epoch->list, &mdev->current_epoch->list);
29510 mdev->current_epoch = epoch;
29511 mdev->epochs++;
29512 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29513 spin_unlock(&mdev->peer_seq_lock);
29514
29515 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29516 - atomic_inc(&mdev->current_epoch->epoch_size);
29517 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29518 return drbd_drain_block(mdev, data_size);
29519 }
29520
29521 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29522
29523 spin_lock(&mdev->epoch_lock);
29524 e->epoch = mdev->current_epoch;
29525 - atomic_inc(&e->epoch->epoch_size);
29526 + atomic_inc_unchecked(&e->epoch->epoch_size);
29527 atomic_inc(&e->epoch->active);
29528 spin_unlock(&mdev->epoch_lock);
29529
29530 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29531 D_ASSERT(list_empty(&mdev->done_ee));
29532
29533 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29534 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29535 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29536 D_ASSERT(list_empty(&mdev->current_epoch->list));
29537 }
29538
29539 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29540 index 3bba655..6151b66 100644
29541 --- a/drivers/block/loop.c
29542 +++ b/drivers/block/loop.c
29543 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29544 mm_segment_t old_fs = get_fs();
29545
29546 set_fs(get_ds());
29547 - bw = file->f_op->write(file, buf, len, &pos);
29548 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29549 set_fs(old_fs);
29550 if (likely(bw == len))
29551 return 0;
29552 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29553 index ea6f632..eafb192 100644
29554 --- a/drivers/char/Kconfig
29555 +++ b/drivers/char/Kconfig
29556 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29557
29558 config DEVKMEM
29559 bool "/dev/kmem virtual device support"
29560 - default y
29561 + default n
29562 + depends on !GRKERNSEC_KMEM
29563 help
29564 Say Y here if you want to support the /dev/kmem device. The
29565 /dev/kmem device is rarely used, but can be used for certain
29566 @@ -581,6 +582,7 @@ config DEVPORT
29567 bool
29568 depends on !M68K
29569 depends on ISA || PCI
29570 + depends on !GRKERNSEC_KMEM
29571 default y
29572
29573 source "drivers/s390/char/Kconfig"
29574 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29575 index 2e04433..22afc64 100644
29576 --- a/drivers/char/agp/frontend.c
29577 +++ b/drivers/char/agp/frontend.c
29578 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29579 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29580 return -EFAULT;
29581
29582 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29583 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29584 return -EFAULT;
29585
29586 client = agp_find_client_by_pid(reserve.pid);
29587 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29588 index 21cb980..f15107c 100644
29589 --- a/drivers/char/genrtc.c
29590 +++ b/drivers/char/genrtc.c
29591 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29592 switch (cmd) {
29593
29594 case RTC_PLL_GET:
29595 + memset(&pll, 0, sizeof(pll));
29596 if (get_rtc_pll(&pll))
29597 return -EINVAL;
29598 else
29599 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29600 index dfd7876..c0b0885 100644
29601 --- a/drivers/char/hpet.c
29602 +++ b/drivers/char/hpet.c
29603 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29604 }
29605
29606 static int
29607 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29608 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29609 struct hpet_info *info)
29610 {
29611 struct hpet_timer __iomem *timer;
29612 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29613 index 2c29942..604c5ba 100644
29614 --- a/drivers/char/ipmi/ipmi_msghandler.c
29615 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29616 @@ -420,7 +420,7 @@ struct ipmi_smi {
29617 struct proc_dir_entry *proc_dir;
29618 char proc_dir_name[10];
29619
29620 - atomic_t stats[IPMI_NUM_STATS];
29621 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29622
29623 /*
29624 * run_to_completion duplicate of smb_info, smi_info
29625 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29626
29627
29628 #define ipmi_inc_stat(intf, stat) \
29629 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29630 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29631 #define ipmi_get_stat(intf, stat) \
29632 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29633 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29634
29635 static int is_lan_addr(struct ipmi_addr *addr)
29636 {
29637 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29638 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29639 init_waitqueue_head(&intf->waitq);
29640 for (i = 0; i < IPMI_NUM_STATS; i++)
29641 - atomic_set(&intf->stats[i], 0);
29642 + atomic_set_unchecked(&intf->stats[i], 0);
29643
29644 intf->proc_dir = NULL;
29645
29646 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29647 index 83f85cf..279e63f 100644
29648 --- a/drivers/char/ipmi/ipmi_si_intf.c
29649 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29650 @@ -275,7 +275,7 @@ struct smi_info {
29651 unsigned char slave_addr;
29652
29653 /* Counters and things for the proc filesystem. */
29654 - atomic_t stats[SI_NUM_STATS];
29655 + atomic_unchecked_t stats[SI_NUM_STATS];
29656
29657 struct task_struct *thread;
29658
29659 @@ -284,9 +284,9 @@ struct smi_info {
29660 };
29661
29662 #define smi_inc_stat(smi, stat) \
29663 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29664 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29665 #define smi_get_stat(smi, stat) \
29666 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29667 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29668
29669 #define SI_MAX_PARMS 4
29670
29671 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29672 atomic_set(&new_smi->req_events, 0);
29673 new_smi->run_to_completion = 0;
29674 for (i = 0; i < SI_NUM_STATS; i++)
29675 - atomic_set(&new_smi->stats[i], 0);
29676 + atomic_set_unchecked(&new_smi->stats[i], 0);
29677
29678 new_smi->interrupt_disabled = 1;
29679 atomic_set(&new_smi->stop_operation, 0);
29680 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29681 index 47ff7e4..0c7d340 100644
29682 --- a/drivers/char/mbcs.c
29683 +++ b/drivers/char/mbcs.c
29684 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29685 return 0;
29686 }
29687
29688 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29689 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29690 {
29691 .part_num = MBCS_PART_NUM,
29692 .mfg_num = MBCS_MFG_NUM,
29693 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29694 index e5eedfa..fcab50ea 100644
29695 --- a/drivers/char/mem.c
29696 +++ b/drivers/char/mem.c
29697 @@ -18,6 +18,7 @@
29698 #include <linux/raw.h>
29699 #include <linux/tty.h>
29700 #include <linux/capability.h>
29701 +#include <linux/security.h>
29702 #include <linux/ptrace.h>
29703 #include <linux/device.h>
29704 #include <linux/highmem.h>
29705 @@ -37,6 +38,10 @@
29706
29707 #define DEVPORT_MINOR 4
29708
29709 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29710 +extern const struct file_operations grsec_fops;
29711 +#endif
29712 +
29713 static inline unsigned long size_inside_page(unsigned long start,
29714 unsigned long size)
29715 {
29716 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29717
29718 while (cursor < to) {
29719 if (!devmem_is_allowed(pfn)) {
29720 +#ifdef CONFIG_GRKERNSEC_KMEM
29721 + gr_handle_mem_readwrite(from, to);
29722 +#else
29723 printk(KERN_INFO
29724 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29725 current->comm, from, to);
29726 +#endif
29727 return 0;
29728 }
29729 cursor += PAGE_SIZE;
29730 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29731 }
29732 return 1;
29733 }
29734 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29735 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29736 +{
29737 + return 0;
29738 +}
29739 #else
29740 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29741 {
29742 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29743
29744 while (count > 0) {
29745 unsigned long remaining;
29746 + char *temp;
29747
29748 sz = size_inside_page(p, count);
29749
29750 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29751 if (!ptr)
29752 return -EFAULT;
29753
29754 - remaining = copy_to_user(buf, ptr, sz);
29755 +#ifdef CONFIG_PAX_USERCOPY
29756 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29757 + if (!temp) {
29758 + unxlate_dev_mem_ptr(p, ptr);
29759 + return -ENOMEM;
29760 + }
29761 + memcpy(temp, ptr, sz);
29762 +#else
29763 + temp = ptr;
29764 +#endif
29765 +
29766 + remaining = copy_to_user(buf, temp, sz);
29767 +
29768 +#ifdef CONFIG_PAX_USERCOPY
29769 + kfree(temp);
29770 +#endif
29771 +
29772 unxlate_dev_mem_ptr(p, ptr);
29773 if (remaining)
29774 return -EFAULT;
29775 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29776 size_t count, loff_t *ppos)
29777 {
29778 unsigned long p = *ppos;
29779 - ssize_t low_count, read, sz;
29780 + ssize_t low_count, read, sz, err = 0;
29781 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29782 - int err = 0;
29783
29784 read = 0;
29785 if (p < (unsigned long) high_memory) {
29786 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 }
29788 #endif
29789 while (low_count > 0) {
29790 + char *temp;
29791 +
29792 sz = size_inside_page(p, low_count);
29793
29794 /*
29795 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29796 */
29797 kbuf = xlate_dev_kmem_ptr((char *)p);
29798
29799 - if (copy_to_user(buf, kbuf, sz))
29800 +#ifdef CONFIG_PAX_USERCOPY
29801 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29802 + if (!temp)
29803 + return -ENOMEM;
29804 + memcpy(temp, kbuf, sz);
29805 +#else
29806 + temp = kbuf;
29807 +#endif
29808 +
29809 + err = copy_to_user(buf, temp, sz);
29810 +
29811 +#ifdef CONFIG_PAX_USERCOPY
29812 + kfree(temp);
29813 +#endif
29814 +
29815 + if (err)
29816 return -EFAULT;
29817 buf += sz;
29818 p += sz;
29819 @@ -833,6 +880,9 @@ static const struct memdev {
29820 #ifdef CONFIG_CRASH_DUMP
29821 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29822 #endif
29823 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29824 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29825 +#endif
29826 };
29827
29828 static int memory_open(struct inode *inode, struct file *filp)
29829 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29830 index 9df78e2..01ba9ae 100644
29831 --- a/drivers/char/nvram.c
29832 +++ b/drivers/char/nvram.c
29833 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29834
29835 spin_unlock_irq(&rtc_lock);
29836
29837 - if (copy_to_user(buf, contents, tmp - contents))
29838 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29839 return -EFAULT;
29840
29841 *ppos = i;
29842 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29843 index 0a484b4..f48ccd1 100644
29844 --- a/drivers/char/pcmcia/synclink_cs.c
29845 +++ b/drivers/char/pcmcia/synclink_cs.c
29846 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29847
29848 if (debug_level >= DEBUG_LEVEL_INFO)
29849 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29850 - __FILE__,__LINE__, info->device_name, port->count);
29851 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29852
29853 - WARN_ON(!port->count);
29854 + WARN_ON(!atomic_read(&port->count));
29855
29856 if (tty_port_close_start(port, tty, filp) == 0)
29857 goto cleanup;
29858 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29859 cleanup:
29860 if (debug_level >= DEBUG_LEVEL_INFO)
29861 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29862 - tty->driver->name, port->count);
29863 + tty->driver->name, atomic_read(&port->count));
29864 }
29865
29866 /* Wait until the transmitter is empty.
29867 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29868
29869 if (debug_level >= DEBUG_LEVEL_INFO)
29870 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29871 - __FILE__,__LINE__,tty->driver->name, port->count);
29872 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29873
29874 /* If port is closing, signal caller to try again */
29875 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29876 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29877 goto cleanup;
29878 }
29879 spin_lock(&port->lock);
29880 - port->count++;
29881 + atomic_inc(&port->count);
29882 spin_unlock(&port->lock);
29883 spin_unlock_irqrestore(&info->netlock, flags);
29884
29885 - if (port->count == 1) {
29886 + if (atomic_read(&port->count) == 1) {
29887 /* 1st open on this device, init hardware */
29888 retval = startup(info, tty);
29889 if (retval < 0)
29890 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29891 unsigned short new_crctype;
29892
29893 /* return error if TTY interface open */
29894 - if (info->port.count)
29895 + if (atomic_read(&info->port.count))
29896 return -EBUSY;
29897
29898 switch (encoding)
29899 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29900
29901 /* arbitrate between network and tty opens */
29902 spin_lock_irqsave(&info->netlock, flags);
29903 - if (info->port.count != 0 || info->netcount != 0) {
29904 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29905 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29906 spin_unlock_irqrestore(&info->netlock, flags);
29907 return -EBUSY;
29908 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29909 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29910
29911 /* return error if TTY interface open */
29912 - if (info->port.count)
29913 + if (atomic_read(&info->port.count))
29914 return -EBUSY;
29915
29916 if (cmd != SIOCWANDEV)
29917 diff --git a/drivers/char/random.c b/drivers/char/random.c
29918 index b86eae9..4192a7a 100644
29919 --- a/drivers/char/random.c
29920 +++ b/drivers/char/random.c
29921 @@ -272,8 +272,13 @@
29922 /*
29923 * Configuration information
29924 */
29925 +#ifdef CONFIG_GRKERNSEC_RANDNET
29926 +#define INPUT_POOL_WORDS 512
29927 +#define OUTPUT_POOL_WORDS 128
29928 +#else
29929 #define INPUT_POOL_WORDS 128
29930 #define OUTPUT_POOL_WORDS 32
29931 +#endif
29932 #define SEC_XFER_SIZE 512
29933 #define EXTRACT_SIZE 10
29934
29935 @@ -313,10 +318,17 @@ static struct poolinfo {
29936 int poolwords;
29937 int tap1, tap2, tap3, tap4, tap5;
29938 } poolinfo_table[] = {
29939 +#ifdef CONFIG_GRKERNSEC_RANDNET
29940 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29941 + { 512, 411, 308, 208, 104, 1 },
29942 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29943 + { 128, 103, 76, 51, 25, 1 },
29944 +#else
29945 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29946 { 128, 103, 76, 51, 25, 1 },
29947 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29948 { 32, 26, 20, 14, 7, 1 },
29949 +#endif
29950 #if 0
29951 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29952 { 2048, 1638, 1231, 819, 411, 1 },
29953 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29954 input_rotate += i ? 7 : 14;
29955 }
29956
29957 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29958 - ACCESS_ONCE(r->add_ptr) = i;
29959 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29960 + ACCESS_ONCE_RW(r->add_ptr) = i;
29961 smp_wmb();
29962
29963 if (out)
29964 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29965 }
29966 #endif
29967
29968 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29969 +u64 latent_entropy;
29970 +
29971 +__init void transfer_latent_entropy(void)
29972 +{
29973 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29974 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29975 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29976 +}
29977 +#endif
29978 +
29979 /*********************************************************************
29980 *
29981 * Entropy extraction routines
29982 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29983
29984 extract_buf(r, tmp);
29985 i = min_t(int, nbytes, EXTRACT_SIZE);
29986 - if (copy_to_user(buf, tmp, i)) {
29987 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29988 ret = -EFAULT;
29989 break;
29990 }
29991 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29992 #include <linux/sysctl.h>
29993
29994 static int min_read_thresh = 8, min_write_thresh;
29995 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29996 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29997 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29998 static char sysctl_bootid[16];
29999
30000 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30001 index f877805..403375a 100644
30002 --- a/drivers/char/sonypi.c
30003 +++ b/drivers/char/sonypi.c
30004 @@ -54,6 +54,7 @@
30005
30006 #include <asm/uaccess.h>
30007 #include <asm/io.h>
30008 +#include <asm/local.h>
30009
30010 #include <linux/sonypi.h>
30011
30012 @@ -490,7 +491,7 @@ static struct sonypi_device {
30013 spinlock_t fifo_lock;
30014 wait_queue_head_t fifo_proc_list;
30015 struct fasync_struct *fifo_async;
30016 - int open_count;
30017 + local_t open_count;
30018 int model;
30019 struct input_dev *input_jog_dev;
30020 struct input_dev *input_key_dev;
30021 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30022 static int sonypi_misc_release(struct inode *inode, struct file *file)
30023 {
30024 mutex_lock(&sonypi_device.lock);
30025 - sonypi_device.open_count--;
30026 + local_dec(&sonypi_device.open_count);
30027 mutex_unlock(&sonypi_device.lock);
30028 return 0;
30029 }
30030 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30031 {
30032 mutex_lock(&sonypi_device.lock);
30033 /* Flush input queue on first open */
30034 - if (!sonypi_device.open_count)
30035 + if (!local_read(&sonypi_device.open_count))
30036 kfifo_reset(&sonypi_device.fifo);
30037 - sonypi_device.open_count++;
30038 + local_inc(&sonypi_device.open_count);
30039 mutex_unlock(&sonypi_device.lock);
30040
30041 return 0;
30042 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30043 index 4dc8024..90108d1 100644
30044 --- a/drivers/char/tpm/tpm.c
30045 +++ b/drivers/char/tpm/tpm.c
30046 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30047 chip->vendor.req_complete_val)
30048 goto out_recv;
30049
30050 - if ((status == chip->vendor.req_canceled)) {
30051 + if (status == chip->vendor.req_canceled) {
30052 dev_err(chip->dev, "Operation Canceled\n");
30053 rc = -ECANCELED;
30054 goto out;
30055 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30056 index 0636520..169c1d0 100644
30057 --- a/drivers/char/tpm/tpm_bios.c
30058 +++ b/drivers/char/tpm/tpm_bios.c
30059 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30060 event = addr;
30061
30062 if ((event->event_type == 0 && event->event_size == 0) ||
30063 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30064 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30065 return NULL;
30066
30067 return addr;
30068 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30069 return NULL;
30070
30071 if ((event->event_type == 0 && event->event_size == 0) ||
30072 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30073 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30074 return NULL;
30075
30076 (*pos)++;
30077 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30078 int i;
30079
30080 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30081 - seq_putc(m, data[i]);
30082 + if (!seq_putc(m, data[i]))
30083 + return -EFAULT;
30084
30085 return 0;
30086 }
30087 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30088 log->bios_event_log_end = log->bios_event_log + len;
30089
30090 virt = acpi_os_map_memory(start, len);
30091 + if (!virt) {
30092 + kfree(log->bios_event_log);
30093 + log->bios_event_log = NULL;
30094 + return -EFAULT;
30095 + }
30096
30097 - memcpy(log->bios_event_log, virt, len);
30098 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30099
30100 acpi_os_unmap_memory(virt, len);
30101 return 0;
30102 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30103 index cdf2f54..e55c197 100644
30104 --- a/drivers/char/virtio_console.c
30105 +++ b/drivers/char/virtio_console.c
30106 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30107 if (to_user) {
30108 ssize_t ret;
30109
30110 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30111 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30112 if (ret)
30113 return -EFAULT;
30114 } else {
30115 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30116 if (!port_has_data(port) && !port->host_connected)
30117 return 0;
30118
30119 - return fill_readbuf(port, ubuf, count, true);
30120 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30121 }
30122
30123 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30124 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30125 index e164c55..3aabb50 100644
30126 --- a/drivers/edac/edac_pci_sysfs.c
30127 +++ b/drivers/edac/edac_pci_sysfs.c
30128 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30129 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30130 static int edac_pci_poll_msec = 1000; /* one second workq period */
30131
30132 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30133 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30134 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30135 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30136
30137 static struct kobject *edac_pci_top_main_kobj;
30138 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30139 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30140 edac_printk(KERN_CRIT, EDAC_PCI,
30141 "Signaled System Error on %s\n",
30142 pci_name(dev));
30143 - atomic_inc(&pci_nonparity_count);
30144 + atomic_inc_unchecked(&pci_nonparity_count);
30145 }
30146
30147 if (status & (PCI_STATUS_PARITY)) {
30148 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30149 "Master Data Parity Error on %s\n",
30150 pci_name(dev));
30151
30152 - atomic_inc(&pci_parity_count);
30153 + atomic_inc_unchecked(&pci_parity_count);
30154 }
30155
30156 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30157 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30158 "Detected Parity Error on %s\n",
30159 pci_name(dev));
30160
30161 - atomic_inc(&pci_parity_count);
30162 + atomic_inc_unchecked(&pci_parity_count);
30163 }
30164 }
30165
30166 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30167 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30168 "Signaled System Error on %s\n",
30169 pci_name(dev));
30170 - atomic_inc(&pci_nonparity_count);
30171 + atomic_inc_unchecked(&pci_nonparity_count);
30172 }
30173
30174 if (status & (PCI_STATUS_PARITY)) {
30175 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30176 "Master Data Parity Error on "
30177 "%s\n", pci_name(dev));
30178
30179 - atomic_inc(&pci_parity_count);
30180 + atomic_inc_unchecked(&pci_parity_count);
30181 }
30182
30183 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30184 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30185 "Detected Parity Error on %s\n",
30186 pci_name(dev));
30187
30188 - atomic_inc(&pci_parity_count);
30189 + atomic_inc_unchecked(&pci_parity_count);
30190 }
30191 }
30192 }
30193 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30194 if (!check_pci_errors)
30195 return;
30196
30197 - before_count = atomic_read(&pci_parity_count);
30198 + before_count = atomic_read_unchecked(&pci_parity_count);
30199
30200 /* scan all PCI devices looking for a Parity Error on devices and
30201 * bridges.
30202 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30203 /* Only if operator has selected panic on PCI Error */
30204 if (edac_pci_get_panic_on_pe()) {
30205 /* If the count is different 'after' from 'before' */
30206 - if (before_count != atomic_read(&pci_parity_count))
30207 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30208 panic("EDAC: PCI Parity Error");
30209 }
30210 }
30211 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30212 index 8c87a5e..a19cbd7 100644
30213 --- a/drivers/edac/mce_amd.h
30214 +++ b/drivers/edac/mce_amd.h
30215 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30216 struct amd_decoder_ops {
30217 bool (*dc_mce)(u16, u8);
30218 bool (*ic_mce)(u16, u8);
30219 -};
30220 +} __no_const;
30221
30222 void amd_report_gart_errors(bool);
30223 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30224 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30225 index 57ea7f4..789e3c3 100644
30226 --- a/drivers/firewire/core-card.c
30227 +++ b/drivers/firewire/core-card.c
30228 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30229
30230 void fw_core_remove_card(struct fw_card *card)
30231 {
30232 - struct fw_card_driver dummy_driver = dummy_driver_template;
30233 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30234
30235 card->driver->update_phy_reg(card, 4,
30236 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30237 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30238 index f8d2287..5aaf4db 100644
30239 --- a/drivers/firewire/core-cdev.c
30240 +++ b/drivers/firewire/core-cdev.c
30241 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30242 int ret;
30243
30244 if ((request->channels == 0 && request->bandwidth == 0) ||
30245 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30246 - request->bandwidth < 0)
30247 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30248 return -EINVAL;
30249
30250 r = kmalloc(sizeof(*r), GFP_KERNEL);
30251 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30252 index 87d6f2d..5bf9d90 100644
30253 --- a/drivers/firewire/core-transaction.c
30254 +++ b/drivers/firewire/core-transaction.c
30255 @@ -37,6 +37,7 @@
30256 #include <linux/timer.h>
30257 #include <linux/types.h>
30258 #include <linux/workqueue.h>
30259 +#include <linux/sched.h>
30260
30261 #include <asm/byteorder.h>
30262
30263 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30264 index 515a42c..5ecf3ba 100644
30265 --- a/drivers/firewire/core.h
30266 +++ b/drivers/firewire/core.h
30267 @@ -111,6 +111,7 @@ struct fw_card_driver {
30268
30269 int (*stop_iso)(struct fw_iso_context *ctx);
30270 };
30271 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30272
30273 void fw_card_initialize(struct fw_card *card,
30274 const struct fw_card_driver *driver, struct device *device);
30275 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30276 index b298158..7ed8432 100644
30277 --- a/drivers/firmware/dmi_scan.c
30278 +++ b/drivers/firmware/dmi_scan.c
30279 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30280 }
30281 }
30282 else {
30283 - /*
30284 - * no iounmap() for that ioremap(); it would be a no-op, but
30285 - * it's so early in setup that sucker gets confused into doing
30286 - * what it shouldn't if we actually call it.
30287 - */
30288 p = dmi_ioremap(0xF0000, 0x10000);
30289 if (p == NULL)
30290 goto error;
30291 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30292 if (buf == NULL)
30293 return -1;
30294
30295 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30296 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30297
30298 iounmap(buf);
30299 return 0;
30300 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30301 index 82d5c20..44a7177 100644
30302 --- a/drivers/gpio/gpio-vr41xx.c
30303 +++ b/drivers/gpio/gpio-vr41xx.c
30304 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30305 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30306 maskl, pendl, maskh, pendh);
30307
30308 - atomic_inc(&irq_err_count);
30309 + atomic_inc_unchecked(&irq_err_count);
30310
30311 return -EINVAL;
30312 }
30313 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30314 index 3252e70..b5314ace 100644
30315 --- a/drivers/gpu/drm/drm_crtc_helper.c
30316 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30317 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30318 struct drm_crtc *tmp;
30319 int crtc_mask = 1;
30320
30321 - WARN(!crtc, "checking null crtc?\n");
30322 + BUG_ON(!crtc);
30323
30324 dev = crtc->dev;
30325
30326 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30327 index 9238de4..a27c72a 100644
30328 --- a/drivers/gpu/drm/drm_drv.c
30329 +++ b/drivers/gpu/drm/drm_drv.c
30330 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30331 /**
30332 * Copy and IOCTL return string to user space
30333 */
30334 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30335 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30336 {
30337 int len;
30338
30339 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30340 return -ENODEV;
30341
30342 atomic_inc(&dev->ioctl_count);
30343 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30344 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30345 ++file_priv->ioctl_count;
30346
30347 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30348 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30349 index 5062eec..4e3e51f 100644
30350 --- a/drivers/gpu/drm/drm_fops.c
30351 +++ b/drivers/gpu/drm/drm_fops.c
30352 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30353 }
30354
30355 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30356 - atomic_set(&dev->counts[i], 0);
30357 + atomic_set_unchecked(&dev->counts[i], 0);
30358
30359 dev->sigdata.lock = NULL;
30360
30361 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30362
30363 retcode = drm_open_helper(inode, filp, dev);
30364 if (!retcode) {
30365 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30366 - if (!dev->open_count++)
30367 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30368 + if (local_inc_return(&dev->open_count) == 1)
30369 retcode = drm_setup(dev);
30370 }
30371 if (!retcode) {
30372 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30373
30374 mutex_lock(&drm_global_mutex);
30375
30376 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30377 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30378
30379 if (dev->driver->preclose)
30380 dev->driver->preclose(dev, file_priv);
30381 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30382 * Begin inline drm_release
30383 */
30384
30385 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30386 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30387 task_pid_nr(current),
30388 (long)old_encode_dev(file_priv->minor->device),
30389 - dev->open_count);
30390 + local_read(&dev->open_count));
30391
30392 /* Release any auth tokens that might point to this file_priv,
30393 (do that under the drm_global_mutex) */
30394 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30395 * End inline drm_release
30396 */
30397
30398 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30399 - if (!--dev->open_count) {
30400 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30401 + if (local_dec_and_test(&dev->open_count)) {
30402 if (atomic_read(&dev->ioctl_count)) {
30403 DRM_ERROR("Device busy: %d\n",
30404 atomic_read(&dev->ioctl_count));
30405 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30406 index c87dc96..326055d 100644
30407 --- a/drivers/gpu/drm/drm_global.c
30408 +++ b/drivers/gpu/drm/drm_global.c
30409 @@ -36,7 +36,7 @@
30410 struct drm_global_item {
30411 struct mutex mutex;
30412 void *object;
30413 - int refcount;
30414 + atomic_t refcount;
30415 };
30416
30417 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30418 @@ -49,7 +49,7 @@ void drm_global_init(void)
30419 struct drm_global_item *item = &glob[i];
30420 mutex_init(&item->mutex);
30421 item->object = NULL;
30422 - item->refcount = 0;
30423 + atomic_set(&item->refcount, 0);
30424 }
30425 }
30426
30427 @@ -59,7 +59,7 @@ void drm_global_release(void)
30428 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30429 struct drm_global_item *item = &glob[i];
30430 BUG_ON(item->object != NULL);
30431 - BUG_ON(item->refcount != 0);
30432 + BUG_ON(atomic_read(&item->refcount) != 0);
30433 }
30434 }
30435
30436 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30437 void *object;
30438
30439 mutex_lock(&item->mutex);
30440 - if (item->refcount == 0) {
30441 + if (atomic_read(&item->refcount) == 0) {
30442 item->object = kzalloc(ref->size, GFP_KERNEL);
30443 if (unlikely(item->object == NULL)) {
30444 ret = -ENOMEM;
30445 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30446 goto out_err;
30447
30448 }
30449 - ++item->refcount;
30450 + atomic_inc(&item->refcount);
30451 ref->object = item->object;
30452 object = item->object;
30453 mutex_unlock(&item->mutex);
30454 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30455 struct drm_global_item *item = &glob[ref->global_type];
30456
30457 mutex_lock(&item->mutex);
30458 - BUG_ON(item->refcount == 0);
30459 + BUG_ON(atomic_read(&item->refcount) == 0);
30460 BUG_ON(ref->object != item->object);
30461 - if (--item->refcount == 0) {
30462 + if (atomic_dec_and_test(&item->refcount)) {
30463 ref->release(ref);
30464 item->object = NULL;
30465 }
30466 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30467 index 8928edb..0c79258 100644
30468 --- a/drivers/gpu/drm/drm_info.c
30469 +++ b/drivers/gpu/drm/drm_info.c
30470 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30471 struct drm_local_map *map;
30472 struct drm_map_list *r_list;
30473
30474 - /* Hardcoded from _DRM_FRAME_BUFFER,
30475 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30476 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30477 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30478 + static const char * const types[] = {
30479 + [_DRM_FRAME_BUFFER] = "FB",
30480 + [_DRM_REGISTERS] = "REG",
30481 + [_DRM_SHM] = "SHM",
30482 + [_DRM_AGP] = "AGP",
30483 + [_DRM_SCATTER_GATHER] = "SG",
30484 + [_DRM_CONSISTENT] = "PCI",
30485 + [_DRM_GEM] = "GEM" };
30486 const char *type;
30487 int i;
30488
30489 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30490 map = r_list->map;
30491 if (!map)
30492 continue;
30493 - if (map->type < 0 || map->type > 5)
30494 + if (map->type >= ARRAY_SIZE(types))
30495 type = "??";
30496 else
30497 type = types[map->type];
30498 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30499 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30500 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30501 vma->vm_flags & VM_IO ? 'i' : '-',
30502 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30503 + 0);
30504 +#else
30505 vma->vm_pgoff);
30506 +#endif
30507
30508 #if defined(__i386__)
30509 pgprot = pgprot_val(vma->vm_page_prot);
30510 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30511 index 637fcc3..e890b33 100644
30512 --- a/drivers/gpu/drm/drm_ioc32.c
30513 +++ b/drivers/gpu/drm/drm_ioc32.c
30514 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30515 request = compat_alloc_user_space(nbytes);
30516 if (!access_ok(VERIFY_WRITE, request, nbytes))
30517 return -EFAULT;
30518 - list = (struct drm_buf_desc *) (request + 1);
30519 + list = (struct drm_buf_desc __user *) (request + 1);
30520
30521 if (__put_user(count, &request->count)
30522 || __put_user(list, &request->list))
30523 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30524 request = compat_alloc_user_space(nbytes);
30525 if (!access_ok(VERIFY_WRITE, request, nbytes))
30526 return -EFAULT;
30527 - list = (struct drm_buf_pub *) (request + 1);
30528 + list = (struct drm_buf_pub __user *) (request + 1);
30529
30530 if (__put_user(count, &request->count)
30531 || __put_user(list, &request->list))
30532 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30533 index 64a62c6..ceab35e 100644
30534 --- a/drivers/gpu/drm/drm_ioctl.c
30535 +++ b/drivers/gpu/drm/drm_ioctl.c
30536 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30537 stats->data[i].value =
30538 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30539 else
30540 - stats->data[i].value = atomic_read(&dev->counts[i]);
30541 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30542 stats->data[i].type = dev->types[i];
30543 }
30544
30545 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30546 index 3203955..c8090af 100644
30547 --- a/drivers/gpu/drm/drm_lock.c
30548 +++ b/drivers/gpu/drm/drm_lock.c
30549 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30550 if (drm_lock_take(&master->lock, lock->context)) {
30551 master->lock.file_priv = file_priv;
30552 master->lock.lock_time = jiffies;
30553 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30554 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30555 break; /* Got lock */
30556 }
30557
30558 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30559 return -EINVAL;
30560 }
30561
30562 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30563 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30564
30565 if (drm_lock_free(&master->lock, lock->context)) {
30566 /* FIXME: Should really bail out here. */
30567 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30568 index 21bcd4a..8e074e0 100644
30569 --- a/drivers/gpu/drm/drm_stub.c
30570 +++ b/drivers/gpu/drm/drm_stub.c
30571 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30572
30573 drm_device_set_unplugged(dev);
30574
30575 - if (dev->open_count == 0) {
30576 + if (local_read(&dev->open_count) == 0) {
30577 drm_put_dev(dev);
30578 }
30579 mutex_unlock(&drm_global_mutex);
30580 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30581 index 463ec68..f5bd2b5 100644
30582 --- a/drivers/gpu/drm/i810/i810_dma.c
30583 +++ b/drivers/gpu/drm/i810/i810_dma.c
30584 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30585 dma->buflist[vertex->idx],
30586 vertex->discard, vertex->used);
30587
30588 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30589 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30590 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30592 sarea_priv->last_enqueue = dev_priv->counter - 1;
30593 sarea_priv->last_dispatch = (int)hw_status[5];
30594
30595 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30596 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30597 mc->last_render);
30598
30599 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30600 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30601 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30603 sarea_priv->last_enqueue = dev_priv->counter - 1;
30604 sarea_priv->last_dispatch = (int)hw_status[5];
30605
30606 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30607 index 6e0acad..93c8289 100644
30608 --- a/drivers/gpu/drm/i810/i810_drv.h
30609 +++ b/drivers/gpu/drm/i810/i810_drv.h
30610 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30611 int page_flipping;
30612
30613 wait_queue_head_t irq_queue;
30614 - atomic_t irq_received;
30615 - atomic_t irq_emitted;
30616 + atomic_unchecked_t irq_received;
30617 + atomic_unchecked_t irq_emitted;
30618
30619 int front_offset;
30620 } drm_i810_private_t;
30621 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30622 index 359f6e8..ada68fd 100644
30623 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30624 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30625 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30626 I915_READ(GTIMR));
30627 }
30628 seq_printf(m, "Interrupts received: %d\n",
30629 - atomic_read(&dev_priv->irq_received));
30630 + atomic_read_unchecked(&dev_priv->irq_received));
30631 for (i = 0; i < I915_NUM_RINGS; i++) {
30632 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30633 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30634 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30635 index 914c0df..d47d380 100644
30636 --- a/drivers/gpu/drm/i915/i915_dma.c
30637 +++ b/drivers/gpu/drm/i915/i915_dma.c
30638 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30639 bool can_switch;
30640
30641 spin_lock(&dev->count_lock);
30642 - can_switch = (dev->open_count == 0);
30643 + can_switch = (local_read(&dev->open_count) == 0);
30644 spin_unlock(&dev->count_lock);
30645 return can_switch;
30646 }
30647 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30648 index 627fe35..c9a7346 100644
30649 --- a/drivers/gpu/drm/i915/i915_drv.h
30650 +++ b/drivers/gpu/drm/i915/i915_drv.h
30651 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30652 /* render clock increase/decrease */
30653 /* display clock increase/decrease */
30654 /* pll clock increase/decrease */
30655 -};
30656 +} __no_const;
30657
30658 struct drm_i915_gt_funcs {
30659 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30660 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30661 -};
30662 +} __no_const;
30663
30664 struct intel_device_info {
30665 u8 gen;
30666 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30667 int current_page;
30668 int page_flipping;
30669
30670 - atomic_t irq_received;
30671 + atomic_unchecked_t irq_received;
30672
30673 /* protects the irq masks */
30674 spinlock_t irq_lock;
30675 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30676 * will be page flipped away on the next vblank. When it
30677 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30678 */
30679 - atomic_t pending_flip;
30680 + atomic_unchecked_t pending_flip;
30681 };
30682
30683 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30684 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30685 struct drm_i915_private *dev_priv, unsigned port);
30686 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30687 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30688 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30689 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30690 {
30691 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30692 }
30693 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30694 index ff2819e..6b5997b 100644
30695 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30696 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30697 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30698 i915_gem_clflush_object(obj);
30699
30700 if (obj->base.pending_write_domain)
30701 - cd->flips |= atomic_read(&obj->pending_flip);
30702 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30703
30704 /* The actual obj->write_domain will be updated with
30705 * pending_write_domain after we emit the accumulated flush for all
30706 @@ -906,9 +906,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30707
30708 static int
30709 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30710 - int count)
30711 + unsigned int count)
30712 {
30713 - int i;
30714 + unsigned int i;
30715
30716 for (i = 0; i < count; i++) {
30717 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30718 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30719 index 73fa3e1..ab2e9b9 100644
30720 --- a/drivers/gpu/drm/i915/i915_irq.c
30721 +++ b/drivers/gpu/drm/i915/i915_irq.c
30722 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30723 u32 pipe_stats[I915_MAX_PIPES];
30724 bool blc_event;
30725
30726 - atomic_inc(&dev_priv->irq_received);
30727 + atomic_inc_unchecked(&dev_priv->irq_received);
30728
30729 while (true) {
30730 iir = I915_READ(VLV_IIR);
30731 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30732 irqreturn_t ret = IRQ_NONE;
30733 int i;
30734
30735 - atomic_inc(&dev_priv->irq_received);
30736 + atomic_inc_unchecked(&dev_priv->irq_received);
30737
30738 /* disable master interrupt before clearing iir */
30739 de_ier = I915_READ(DEIER);
30740 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30741 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30742 u32 hotplug_mask;
30743
30744 - atomic_inc(&dev_priv->irq_received);
30745 + atomic_inc_unchecked(&dev_priv->irq_received);
30746
30747 /* disable master interrupt before clearing iir */
30748 de_ier = I915_READ(DEIER);
30749 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30750 {
30751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30752
30753 - atomic_set(&dev_priv->irq_received, 0);
30754 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30755
30756 I915_WRITE(HWSTAM, 0xeffe);
30757
30758 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30759 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30760 int pipe;
30761
30762 - atomic_set(&dev_priv->irq_received, 0);
30763 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30764
30765 /* VLV magic */
30766 I915_WRITE(VLV_IMR, 0);
30767 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30769 int pipe;
30770
30771 - atomic_set(&dev_priv->irq_received, 0);
30772 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30773
30774 for_each_pipe(pipe)
30775 I915_WRITE(PIPESTAT(pipe), 0);
30776 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30777 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30778 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30779
30780 - atomic_inc(&dev_priv->irq_received);
30781 + atomic_inc_unchecked(&dev_priv->irq_received);
30782
30783 iir = I915_READ16(IIR);
30784 if (iir == 0)
30785 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30786 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30787 int pipe;
30788
30789 - atomic_set(&dev_priv->irq_received, 0);
30790 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30791
30792 if (I915_HAS_HOTPLUG(dev)) {
30793 I915_WRITE(PORT_HOTPLUG_EN, 0);
30794 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30795 };
30796 int pipe, ret = IRQ_NONE;
30797
30798 - atomic_inc(&dev_priv->irq_received);
30799 + atomic_inc_unchecked(&dev_priv->irq_received);
30800
30801 iir = I915_READ(IIR);
30802 do {
30803 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30804 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30805 int pipe;
30806
30807 - atomic_set(&dev_priv->irq_received, 0);
30808 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30809
30810 I915_WRITE(PORT_HOTPLUG_EN, 0);
30811 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30812 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30813 int irq_received;
30814 int ret = IRQ_NONE, pipe;
30815
30816 - atomic_inc(&dev_priv->irq_received);
30817 + atomic_inc_unchecked(&dev_priv->irq_received);
30818
30819 iir = I915_READ(IIR);
30820
30821 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30822 index b634f6f..84bb8ba 100644
30823 --- a/drivers/gpu/drm/i915/intel_display.c
30824 +++ b/drivers/gpu/drm/i915/intel_display.c
30825 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30826
30827 wait_event(dev_priv->pending_flip_queue,
30828 atomic_read(&dev_priv->mm.wedged) ||
30829 - atomic_read(&obj->pending_flip) == 0);
30830 + atomic_read_unchecked(&obj->pending_flip) == 0);
30831
30832 /* Big Hammer, we also need to ensure that any pending
30833 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30834 @@ -6168,7 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30835
30836 obj = work->old_fb_obj;
30837
30838 - atomic_clear_mask(1 << intel_crtc->plane,
30839 + atomic_clear_mask_unchecked(1 << intel_crtc->plane,
30840 &obj->pending_flip.counter);
30841
30842 wake_up(&dev_priv->pending_flip_queue);
30843 @@ -6515,7 +6515,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30844 /* Block clients from rendering to the new back buffer until
30845 * the flip occurs and the object is no longer visible.
30846 */
30847 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30848 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30849
30850 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30851 if (ret)
30852 @@ -6530,7 +6530,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30853 return 0;
30854
30855 cleanup_pending:
30856 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30857 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30858 drm_gem_object_unreference(&work->old_fb_obj->base);
30859 drm_gem_object_unreference(&obj->base);
30860 mutex_unlock(&dev->struct_mutex);
30861 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30862 index 54558a0..2d97005 100644
30863 --- a/drivers/gpu/drm/mga/mga_drv.h
30864 +++ b/drivers/gpu/drm/mga/mga_drv.h
30865 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30866 u32 clear_cmd;
30867 u32 maccess;
30868
30869 - atomic_t vbl_received; /**< Number of vblanks received. */
30870 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30871 wait_queue_head_t fence_queue;
30872 - atomic_t last_fence_retired;
30873 + atomic_unchecked_t last_fence_retired;
30874 u32 next_fence_to_post;
30875
30876 unsigned int fb_cpp;
30877 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30878 index 2581202..f230a8d9 100644
30879 --- a/drivers/gpu/drm/mga/mga_irq.c
30880 +++ b/drivers/gpu/drm/mga/mga_irq.c
30881 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30882 if (crtc != 0)
30883 return 0;
30884
30885 - return atomic_read(&dev_priv->vbl_received);
30886 + return atomic_read_unchecked(&dev_priv->vbl_received);
30887 }
30888
30889
30890 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30891 /* VBLANK interrupt */
30892 if (status & MGA_VLINEPEN) {
30893 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30894 - atomic_inc(&dev_priv->vbl_received);
30895 + atomic_inc_unchecked(&dev_priv->vbl_received);
30896 drm_handle_vblank(dev, 0);
30897 handled = 1;
30898 }
30899 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30900 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30901 MGA_WRITE(MGA_PRIMEND, prim_end);
30902
30903 - atomic_inc(&dev_priv->last_fence_retired);
30904 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30905 DRM_WAKEUP(&dev_priv->fence_queue);
30906 handled = 1;
30907 }
30908 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30909 * using fences.
30910 */
30911 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30912 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30913 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30914 - *sequence) <= (1 << 23)));
30915
30916 *sequence = cur_fence;
30917 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30918 index a0a3fe3..209bf10 100644
30919 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30920 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30921 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30922 struct bit_table {
30923 const char id;
30924 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30925 -};
30926 +} __no_const;
30927
30928 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30929
30930 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30931 index 4f2cc95..9c6c510 100644
30932 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30933 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30934 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30935 u32 handle, u16 class);
30936 void (*set_tile_region)(struct drm_device *dev, int i);
30937 void (*tlb_flush)(struct drm_device *, int engine);
30938 -};
30939 +} __no_const;
30940
30941 struct nouveau_instmem_engine {
30942 void *priv;
30943 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30944 struct nouveau_mc_engine {
30945 int (*init)(struct drm_device *dev);
30946 void (*takedown)(struct drm_device *dev);
30947 -};
30948 +} __no_const;
30949
30950 struct nouveau_timer_engine {
30951 int (*init)(struct drm_device *dev);
30952 void (*takedown)(struct drm_device *dev);
30953 uint64_t (*read)(struct drm_device *dev);
30954 -};
30955 +} __no_const;
30956
30957 struct nouveau_fb_engine {
30958 int num_tiles;
30959 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30960 void (*put)(struct drm_device *, struct nouveau_mem **);
30961
30962 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30963 -};
30964 +} __no_const;
30965
30966 struct nouveau_engine {
30967 struct nouveau_instmem_engine instmem;
30968 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30969 struct drm_global_reference mem_global_ref;
30970 struct ttm_bo_global_ref bo_global_ref;
30971 struct ttm_bo_device bdev;
30972 - atomic_t validate_sequence;
30973 + atomic_unchecked_t validate_sequence;
30974 int (*move)(struct nouveau_channel *,
30975 struct ttm_buffer_object *,
30976 struct ttm_mem_reg *, struct ttm_mem_reg *);
30977 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30978 index af7cfb8..aadc2a3 100644
30979 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30980 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30981 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30982 int trycnt = 0;
30983 int ret, i;
30984
30985 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30986 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30987 retry:
30988 if (++trycnt > 100000) {
30989 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30990 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30991 index c610144..97440e2 100644
30992 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30993 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30994 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30995 bool can_switch;
30996
30997 spin_lock(&dev->count_lock);
30998 - can_switch = (dev->open_count == 0);
30999 + can_switch = (local_read(&dev->open_count) == 0);
31000 spin_unlock(&dev->count_lock);
31001 return can_switch;
31002 }
31003 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31004 index 93240bd..c490f60 100644
31005 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31006 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31007 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31008 }
31009
31010 if (nv_encoder->dcb->type == OUTPUT_DP) {
31011 - struct dp_train_func func = {
31012 + static struct dp_train_func func = {
31013 .link_set = nv50_sor_dp_link_set,
31014 .train_set = nv50_sor_dp_train_set,
31015 .train_adj = nv50_sor_dp_train_adj
31016 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31017 index 8a2fc89..3a5cf40 100644
31018 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31019 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31020 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31021 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31022
31023 if (nv_encoder->dcb->type == OUTPUT_DP) {
31024 - struct dp_train_func func = {
31025 + static struct dp_train_func func = {
31026 .link_set = nvd0_sor_dp_link_set,
31027 .train_set = nvd0_sor_dp_train_set,
31028 .train_adj = nvd0_sor_dp_train_adj
31029 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31030 index bcac90b..53bfc76 100644
31031 --- a/drivers/gpu/drm/r128/r128_cce.c
31032 +++ b/drivers/gpu/drm/r128/r128_cce.c
31033 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31034
31035 /* GH: Simple idle check.
31036 */
31037 - atomic_set(&dev_priv->idle_count, 0);
31038 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31039
31040 /* We don't support anything other than bus-mastering ring mode,
31041 * but the ring can be in either AGP or PCI space for the ring
31042 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31043 index 930c71b..499aded 100644
31044 --- a/drivers/gpu/drm/r128/r128_drv.h
31045 +++ b/drivers/gpu/drm/r128/r128_drv.h
31046 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31047 int is_pci;
31048 unsigned long cce_buffers_offset;
31049
31050 - atomic_t idle_count;
31051 + atomic_unchecked_t idle_count;
31052
31053 int page_flipping;
31054 int current_page;
31055 u32 crtc_offset;
31056 u32 crtc_offset_cntl;
31057
31058 - atomic_t vbl_received;
31059 + atomic_unchecked_t vbl_received;
31060
31061 u32 color_fmt;
31062 unsigned int front_offset;
31063 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31064 index 429d5a0..7e899ed 100644
31065 --- a/drivers/gpu/drm/r128/r128_irq.c
31066 +++ b/drivers/gpu/drm/r128/r128_irq.c
31067 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31068 if (crtc != 0)
31069 return 0;
31070
31071 - return atomic_read(&dev_priv->vbl_received);
31072 + return atomic_read_unchecked(&dev_priv->vbl_received);
31073 }
31074
31075 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31076 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31077 /* VBLANK interrupt */
31078 if (status & R128_CRTC_VBLANK_INT) {
31079 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31080 - atomic_inc(&dev_priv->vbl_received);
31081 + atomic_inc_unchecked(&dev_priv->vbl_received);
31082 drm_handle_vblank(dev, 0);
31083 return IRQ_HANDLED;
31084 }
31085 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31086 index a9e33ce..09edd4b 100644
31087 --- a/drivers/gpu/drm/r128/r128_state.c
31088 +++ b/drivers/gpu/drm/r128/r128_state.c
31089 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31090
31091 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31092 {
31093 - if (atomic_read(&dev_priv->idle_count) == 0)
31094 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31095 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31096 else
31097 - atomic_set(&dev_priv->idle_count, 0);
31098 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31099 }
31100
31101 #endif
31102 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31103 index 5a82b6b..9e69c73 100644
31104 --- a/drivers/gpu/drm/radeon/mkregtable.c
31105 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31106 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31107 regex_t mask_rex;
31108 regmatch_t match[4];
31109 char buf[1024];
31110 - size_t end;
31111 + long end;
31112 int len;
31113 int done = 0;
31114 int r;
31115 unsigned o;
31116 struct offset *offset;
31117 char last_reg_s[10];
31118 - int last_reg;
31119 + unsigned long last_reg;
31120
31121 if (regcomp
31122 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31123 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31124 index 59a1531..3bab49b 100644
31125 --- a/drivers/gpu/drm/radeon/radeon.h
31126 +++ b/drivers/gpu/drm/radeon/radeon.h
31127 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31128 int x2, int y2);
31129 void (*draw_auto)(struct radeon_device *rdev);
31130 void (*set_default_state)(struct radeon_device *rdev);
31131 -};
31132 +} __no_const;
31133
31134 struct r600_blit {
31135 struct radeon_bo *shader_obj;
31136 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31137 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31138 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31139 } pflip;
31140 -};
31141 +} __no_const;
31142
31143 /*
31144 * Asic structures
31145 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31146 index 7a3daeb..5016171 100644
31147 --- a/drivers/gpu/drm/radeon/radeon_device.c
31148 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31149 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31150 bool can_switch;
31151
31152 spin_lock(&dev->count_lock);
31153 - can_switch = (dev->open_count == 0);
31154 + can_switch = (local_read(&dev->open_count) == 0);
31155 spin_unlock(&dev->count_lock);
31156 return can_switch;
31157 }
31158 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31159 index a1b59ca..86f2d44 100644
31160 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31161 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31162 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31163
31164 /* SW interrupt */
31165 wait_queue_head_t swi_queue;
31166 - atomic_t swi_emitted;
31167 + atomic_unchecked_t swi_emitted;
31168 int vblank_crtc;
31169 uint32_t irq_enable_reg;
31170 uint32_t r500_disp_irq_reg;
31171 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31172 index 48b7cea..342236f 100644
31173 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31174 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31175 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31176 request = compat_alloc_user_space(sizeof(*request));
31177 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31178 || __put_user(req32.param, &request->param)
31179 - || __put_user((void __user *)(unsigned long)req32.value,
31180 + || __put_user((unsigned long)req32.value,
31181 &request->value))
31182 return -EFAULT;
31183
31184 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31185 index 00da384..32f972d 100644
31186 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31187 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31188 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31189 unsigned int ret;
31190 RING_LOCALS;
31191
31192 - atomic_inc(&dev_priv->swi_emitted);
31193 - ret = atomic_read(&dev_priv->swi_emitted);
31194 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31195 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31196
31197 BEGIN_RING(4);
31198 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31199 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31200 drm_radeon_private_t *dev_priv =
31201 (drm_radeon_private_t *) dev->dev_private;
31202
31203 - atomic_set(&dev_priv->swi_emitted, 0);
31204 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31205 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31206
31207 dev->max_vblank_count = 0x001fffff;
31208 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31209 index e8422ae..d22d4a8 100644
31210 --- a/drivers/gpu/drm/radeon/radeon_state.c
31211 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31212 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31213 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31214 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31215
31216 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31217 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31218 sarea_priv->nbox * sizeof(depth_boxes[0])))
31219 return -EFAULT;
31220
31221 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31222 {
31223 drm_radeon_private_t *dev_priv = dev->dev_private;
31224 drm_radeon_getparam_t *param = data;
31225 - int value;
31226 + int value = 0;
31227
31228 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31229
31230 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31231 index 5b71c71..650f9e4 100644
31232 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31233 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31234 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31235 }
31236 if (unlikely(ttm_vm_ops == NULL)) {
31237 ttm_vm_ops = vma->vm_ops;
31238 - radeon_ttm_vm_ops = *ttm_vm_ops;
31239 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31240 + pax_open_kernel();
31241 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31242 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31243 + pax_close_kernel();
31244 }
31245 vma->vm_ops = &radeon_ttm_vm_ops;
31246 return 0;
31247 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31248 index 3b663fc..57850f4 100644
31249 --- a/drivers/gpu/drm/radeon/rs690.c
31250 +++ b/drivers/gpu/drm/radeon/rs690.c
31251 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31252 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31253 rdev->pm.sideport_bandwidth.full)
31254 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31255 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31256 + read_delay_latency.full = dfixed_const(800 * 1000);
31257 read_delay_latency.full = dfixed_div(read_delay_latency,
31258 rdev->pm.igp_sideport_mclk);
31259 + a.full = dfixed_const(370);
31260 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31261 } else {
31262 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31263 rdev->pm.k8_bandwidth.full)
31264 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31265 index ebc6fac..a8313ed 100644
31266 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31267 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31268 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31269 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31270 struct shrink_control *sc)
31271 {
31272 - static atomic_t start_pool = ATOMIC_INIT(0);
31273 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31274 unsigned i;
31275 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31276 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31277 struct ttm_page_pool *pool;
31278 int shrink_pages = sc->nr_to_scan;
31279
31280 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31281 index 88edacc..1e5412b 100644
31282 --- a/drivers/gpu/drm/via/via_drv.h
31283 +++ b/drivers/gpu/drm/via/via_drv.h
31284 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31285 typedef uint32_t maskarray_t[5];
31286
31287 typedef struct drm_via_irq {
31288 - atomic_t irq_received;
31289 + atomic_unchecked_t irq_received;
31290 uint32_t pending_mask;
31291 uint32_t enable_mask;
31292 wait_queue_head_t irq_queue;
31293 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31294 struct timeval last_vblank;
31295 int last_vblank_valid;
31296 unsigned usec_per_vblank;
31297 - atomic_t vbl_received;
31298 + atomic_unchecked_t vbl_received;
31299 drm_via_state_t hc_state;
31300 char pci_buf[VIA_PCI_BUF_SIZE];
31301 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31302 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31303 index d391f48..10c8ca3 100644
31304 --- a/drivers/gpu/drm/via/via_irq.c
31305 +++ b/drivers/gpu/drm/via/via_irq.c
31306 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31307 if (crtc != 0)
31308 return 0;
31309
31310 - return atomic_read(&dev_priv->vbl_received);
31311 + return atomic_read_unchecked(&dev_priv->vbl_received);
31312 }
31313
31314 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31315 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31316
31317 status = VIA_READ(VIA_REG_INTERRUPT);
31318 if (status & VIA_IRQ_VBLANK_PENDING) {
31319 - atomic_inc(&dev_priv->vbl_received);
31320 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31321 + atomic_inc_unchecked(&dev_priv->vbl_received);
31322 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31323 do_gettimeofday(&cur_vblank);
31324 if (dev_priv->last_vblank_valid) {
31325 dev_priv->usec_per_vblank =
31326 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31327 dev_priv->last_vblank = cur_vblank;
31328 dev_priv->last_vblank_valid = 1;
31329 }
31330 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31331 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31332 DRM_DEBUG("US per vblank is: %u\n",
31333 dev_priv->usec_per_vblank);
31334 }
31335 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31336
31337 for (i = 0; i < dev_priv->num_irqs; ++i) {
31338 if (status & cur_irq->pending_mask) {
31339 - atomic_inc(&cur_irq->irq_received);
31340 + atomic_inc_unchecked(&cur_irq->irq_received);
31341 DRM_WAKEUP(&cur_irq->irq_queue);
31342 handled = 1;
31343 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31344 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31345 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31346 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31347 masks[irq][4]));
31348 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31349 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31350 } else {
31351 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31352 (((cur_irq_sequence =
31353 - atomic_read(&cur_irq->irq_received)) -
31354 + atomic_read_unchecked(&cur_irq->irq_received)) -
31355 *sequence) <= (1 << 23)));
31356 }
31357 *sequence = cur_irq_sequence;
31358 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31359 }
31360
31361 for (i = 0; i < dev_priv->num_irqs; ++i) {
31362 - atomic_set(&cur_irq->irq_received, 0);
31363 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31364 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31365 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31366 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31367 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31368 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31369 case VIA_IRQ_RELATIVE:
31370 irqwait->request.sequence +=
31371 - atomic_read(&cur_irq->irq_received);
31372 + atomic_read_unchecked(&cur_irq->irq_received);
31373 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31374 case VIA_IRQ_ABSOLUTE:
31375 break;
31376 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31377 index 29c984f..4084f1a 100644
31378 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31379 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31380 @@ -263,7 +263,7 @@ struct vmw_private {
31381 * Fencing and IRQs.
31382 */
31383
31384 - atomic_t marker_seq;
31385 + atomic_unchecked_t marker_seq;
31386 wait_queue_head_t fence_queue;
31387 wait_queue_head_t fifo_queue;
31388 int fence_queue_waiters; /* Protected by hw_mutex */
31389 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31390 index a0c2f12..68ae6cb 100644
31391 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31392 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31393 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31394 (unsigned int) min,
31395 (unsigned int) fifo->capabilities);
31396
31397 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31398 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31399 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31400 vmw_marker_queue_init(&fifo->marker_queue);
31401 return vmw_fifo_send_fence(dev_priv, &dummy);
31402 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31403 if (reserveable)
31404 iowrite32(bytes, fifo_mem +
31405 SVGA_FIFO_RESERVED);
31406 - return fifo_mem + (next_cmd >> 2);
31407 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31408 } else {
31409 need_bounce = true;
31410 }
31411 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31412
31413 fm = vmw_fifo_reserve(dev_priv, bytes);
31414 if (unlikely(fm == NULL)) {
31415 - *seqno = atomic_read(&dev_priv->marker_seq);
31416 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31417 ret = -ENOMEM;
31418 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31419 false, 3*HZ);
31420 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31421 }
31422
31423 do {
31424 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31425 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31426 } while (*seqno == 0);
31427
31428 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31429 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31430 index cabc95f..14b3d77 100644
31431 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31432 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31433 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31434 * emitted. Then the fence is stale and signaled.
31435 */
31436
31437 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31438 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31439 > VMW_FENCE_WRAP);
31440
31441 return ret;
31442 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31443
31444 if (fifo_idle)
31445 down_read(&fifo_state->rwsem);
31446 - signal_seq = atomic_read(&dev_priv->marker_seq);
31447 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31448 ret = 0;
31449
31450 for (;;) {
31451 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31452 index 8a8725c..afed796 100644
31453 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31454 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31455 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31456 while (!vmw_lag_lt(queue, us)) {
31457 spin_lock(&queue->lock);
31458 if (list_empty(&queue->head))
31459 - seqno = atomic_read(&dev_priv->marker_seq);
31460 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31461 else {
31462 marker = list_first_entry(&queue->head,
31463 struct vmw_marker, head);
31464 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31465 index 5de3bb3..08e5063 100644
31466 --- a/drivers/hid/hid-core.c
31467 +++ b/drivers/hid/hid-core.c
31468 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31469
31470 int hid_add_device(struct hid_device *hdev)
31471 {
31472 - static atomic_t id = ATOMIC_INIT(0);
31473 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31474 int ret;
31475
31476 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31477 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31478 /* XXX hack, any other cleaner solution after the driver core
31479 * is converted to allow more than 20 bytes as the device name? */
31480 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31481 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31482 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31483
31484 hid_debug_register(hdev, dev_name(&hdev->dev));
31485 ret = device_add(&hdev->dev);
31486 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31487 index eec3291..8ed706b 100644
31488 --- a/drivers/hid/hid-wiimote-debug.c
31489 +++ b/drivers/hid/hid-wiimote-debug.c
31490 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31491 else if (size == 0)
31492 return -EIO;
31493
31494 - if (copy_to_user(u, buf, size))
31495 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31496 return -EFAULT;
31497
31498 *off += size;
31499 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31500 index 14599e2..711c965 100644
31501 --- a/drivers/hid/usbhid/hiddev.c
31502 +++ b/drivers/hid/usbhid/hiddev.c
31503 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31504 break;
31505
31506 case HIDIOCAPPLICATION:
31507 - if (arg < 0 || arg >= hid->maxapplication)
31508 + if (arg >= hid->maxapplication)
31509 break;
31510
31511 for (i = 0; i < hid->maxcollection; i++)
31512 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31513 index 4065374..10ed7dc 100644
31514 --- a/drivers/hv/channel.c
31515 +++ b/drivers/hv/channel.c
31516 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31517 int ret = 0;
31518 int t;
31519
31520 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31521 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31522 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31523 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31524
31525 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31526 if (ret)
31527 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31528 index 86f8885..ab9cb2b 100644
31529 --- a/drivers/hv/hv.c
31530 +++ b/drivers/hv/hv.c
31531 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31532 u64 output_address = (output) ? virt_to_phys(output) : 0;
31533 u32 output_address_hi = output_address >> 32;
31534 u32 output_address_lo = output_address & 0xFFFFFFFF;
31535 - void *hypercall_page = hv_context.hypercall_page;
31536 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31537
31538 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31539 "=a"(hv_status_lo) : "d" (control_hi),
31540 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31541 index 0614ff3..f0b2b5c 100644
31542 --- a/drivers/hv/hyperv_vmbus.h
31543 +++ b/drivers/hv/hyperv_vmbus.h
31544 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31545 struct vmbus_connection {
31546 enum vmbus_connect_state conn_state;
31547
31548 - atomic_t next_gpadl_handle;
31549 + atomic_unchecked_t next_gpadl_handle;
31550
31551 /*
31552 * Represents channel interrupts. Each bit position represents a
31553 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31554 index 4748086..3abf845 100644
31555 --- a/drivers/hv/vmbus_drv.c
31556 +++ b/drivers/hv/vmbus_drv.c
31557 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31558 {
31559 int ret = 0;
31560
31561 - static atomic_t device_num = ATOMIC_INIT(0);
31562 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31563
31564 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31565 - atomic_inc_return(&device_num));
31566 + atomic_inc_return_unchecked(&device_num));
31567
31568 child_device_obj->device.bus = &hv_bus;
31569 child_device_obj->device.parent = &hv_acpi_dev->dev;
31570 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31571 index 8b011d0..3de24a1 100644
31572 --- a/drivers/hwmon/sht15.c
31573 +++ b/drivers/hwmon/sht15.c
31574 @@ -166,7 +166,7 @@ struct sht15_data {
31575 int supply_uV;
31576 bool supply_uV_valid;
31577 struct work_struct update_supply_work;
31578 - atomic_t interrupt_handled;
31579 + atomic_unchecked_t interrupt_handled;
31580 };
31581
31582 /**
31583 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31584 return ret;
31585
31586 gpio_direction_input(data->pdata->gpio_data);
31587 - atomic_set(&data->interrupt_handled, 0);
31588 + atomic_set_unchecked(&data->interrupt_handled, 0);
31589
31590 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31591 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31592 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31593 /* Only relevant if the interrupt hasn't occurred. */
31594 - if (!atomic_read(&data->interrupt_handled))
31595 + if (!atomic_read_unchecked(&data->interrupt_handled))
31596 schedule_work(&data->read_work);
31597 }
31598 ret = wait_event_timeout(data->wait_queue,
31599 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31600
31601 /* First disable the interrupt */
31602 disable_irq_nosync(irq);
31603 - atomic_inc(&data->interrupt_handled);
31604 + atomic_inc_unchecked(&data->interrupt_handled);
31605 /* Then schedule a reading work struct */
31606 if (data->state != SHT15_READING_NOTHING)
31607 schedule_work(&data->read_work);
31608 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31609 * If not, then start the interrupt again - care here as could
31610 * have gone low in meantime so verify it hasn't!
31611 */
31612 - atomic_set(&data->interrupt_handled, 0);
31613 + atomic_set_unchecked(&data->interrupt_handled, 0);
31614 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31615 /* If still not occurred or another handler was scheduled */
31616 if (gpio_get_value(data->pdata->gpio_data)
31617 - || atomic_read(&data->interrupt_handled))
31618 + || atomic_read_unchecked(&data->interrupt_handled))
31619 return;
31620 }
31621
31622 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31623 index 378fcb5..5e91fa8 100644
31624 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31625 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31626 @@ -43,7 +43,7 @@
31627 extern struct i2c_adapter amd756_smbus;
31628
31629 static struct i2c_adapter *s4882_adapter;
31630 -static struct i2c_algorithm *s4882_algo;
31631 +static i2c_algorithm_no_const *s4882_algo;
31632
31633 /* Wrapper access functions for multiplexed SMBus */
31634 static DEFINE_MUTEX(amd756_lock);
31635 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31636 index 29015eb..af2d8e9 100644
31637 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31638 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31639 @@ -41,7 +41,7 @@
31640 extern struct i2c_adapter *nforce2_smbus;
31641
31642 static struct i2c_adapter *s4985_adapter;
31643 -static struct i2c_algorithm *s4985_algo;
31644 +static i2c_algorithm_no_const *s4985_algo;
31645
31646 /* Wrapper access functions for multiplexed SMBus */
31647 static DEFINE_MUTEX(nforce2_lock);
31648 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31649 index 1038c38..eb92f51 100644
31650 --- a/drivers/i2c/i2c-mux.c
31651 +++ b/drivers/i2c/i2c-mux.c
31652 @@ -30,7 +30,7 @@
31653 /* multiplexer per channel data */
31654 struct i2c_mux_priv {
31655 struct i2c_adapter adap;
31656 - struct i2c_algorithm algo;
31657 + i2c_algorithm_no_const algo;
31658
31659 struct i2c_adapter *parent;
31660 void *mux_priv; /* the mux chip/device */
31661 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31662 index 57d00ca..0145194 100644
31663 --- a/drivers/ide/aec62xx.c
31664 +++ b/drivers/ide/aec62xx.c
31665 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31666 .cable_detect = atp86x_cable_detect,
31667 };
31668
31669 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31670 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31671 { /* 0: AEC6210 */
31672 .name = DRV_NAME,
31673 .init_chipset = init_chipset_aec62xx,
31674 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31675 index 2c8016a..911a27c 100644
31676 --- a/drivers/ide/alim15x3.c
31677 +++ b/drivers/ide/alim15x3.c
31678 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31679 .dma_sff_read_status = ide_dma_sff_read_status,
31680 };
31681
31682 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31683 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31684 .name = DRV_NAME,
31685 .init_chipset = init_chipset_ali15x3,
31686 .init_hwif = init_hwif_ali15x3,
31687 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31688 index 3747b25..56fc995 100644
31689 --- a/drivers/ide/amd74xx.c
31690 +++ b/drivers/ide/amd74xx.c
31691 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31692 .udma_mask = udma, \
31693 }
31694
31695 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31696 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31697 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31698 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31699 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31700 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31701 index 15f0ead..cb43480 100644
31702 --- a/drivers/ide/atiixp.c
31703 +++ b/drivers/ide/atiixp.c
31704 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31705 .cable_detect = atiixp_cable_detect,
31706 };
31707
31708 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31709 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31710 { /* 0: IXP200/300/400/700 */
31711 .name = DRV_NAME,
31712 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31713 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31714 index 5f80312..d1fc438 100644
31715 --- a/drivers/ide/cmd64x.c
31716 +++ b/drivers/ide/cmd64x.c
31717 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31718 .dma_sff_read_status = ide_dma_sff_read_status,
31719 };
31720
31721 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31722 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31723 { /* 0: CMD643 */
31724 .name = DRV_NAME,
31725 .init_chipset = init_chipset_cmd64x,
31726 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31727 index 2c1e5f7..1444762 100644
31728 --- a/drivers/ide/cs5520.c
31729 +++ b/drivers/ide/cs5520.c
31730 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31731 .set_dma_mode = cs5520_set_dma_mode,
31732 };
31733
31734 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31735 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31736 .name = DRV_NAME,
31737 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31738 .port_ops = &cs5520_port_ops,
31739 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31740 index 4dc4eb9..49b40ad 100644
31741 --- a/drivers/ide/cs5530.c
31742 +++ b/drivers/ide/cs5530.c
31743 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31744 .udma_filter = cs5530_udma_filter,
31745 };
31746
31747 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31748 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31749 .name = DRV_NAME,
31750 .init_chipset = init_chipset_cs5530,
31751 .init_hwif = init_hwif_cs5530,
31752 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31753 index 5059faf..18d4c85 100644
31754 --- a/drivers/ide/cs5535.c
31755 +++ b/drivers/ide/cs5535.c
31756 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31757 .cable_detect = cs5535_cable_detect,
31758 };
31759
31760 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31761 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31762 .name = DRV_NAME,
31763 .port_ops = &cs5535_port_ops,
31764 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31765 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31766 index 847553f..3ffb49d 100644
31767 --- a/drivers/ide/cy82c693.c
31768 +++ b/drivers/ide/cy82c693.c
31769 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31770 .set_dma_mode = cy82c693_set_dma_mode,
31771 };
31772
31773 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31774 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31775 .name = DRV_NAME,
31776 .init_iops = init_iops_cy82c693,
31777 .port_ops = &cy82c693_port_ops,
31778 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31779 index 58c51cd..4aec3b8 100644
31780 --- a/drivers/ide/hpt366.c
31781 +++ b/drivers/ide/hpt366.c
31782 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31783 }
31784 };
31785
31786 -static const struct hpt_info hpt36x __devinitdata = {
31787 +static const struct hpt_info hpt36x __devinitconst = {
31788 .chip_name = "HPT36x",
31789 .chip_type = HPT36x,
31790 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31791 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31792 .timings = &hpt36x_timings
31793 };
31794
31795 -static const struct hpt_info hpt370 __devinitdata = {
31796 +static const struct hpt_info hpt370 __devinitconst = {
31797 .chip_name = "HPT370",
31798 .chip_type = HPT370,
31799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31800 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31801 .timings = &hpt37x_timings
31802 };
31803
31804 -static const struct hpt_info hpt370a __devinitdata = {
31805 +static const struct hpt_info hpt370a __devinitconst = {
31806 .chip_name = "HPT370A",
31807 .chip_type = HPT370A,
31808 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31809 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31810 .timings = &hpt37x_timings
31811 };
31812
31813 -static const struct hpt_info hpt374 __devinitdata = {
31814 +static const struct hpt_info hpt374 __devinitconst = {
31815 .chip_name = "HPT374",
31816 .chip_type = HPT374,
31817 .udma_mask = ATA_UDMA5,
31818 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31819 .timings = &hpt37x_timings
31820 };
31821
31822 -static const struct hpt_info hpt372 __devinitdata = {
31823 +static const struct hpt_info hpt372 __devinitconst = {
31824 .chip_name = "HPT372",
31825 .chip_type = HPT372,
31826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31827 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31828 .timings = &hpt37x_timings
31829 };
31830
31831 -static const struct hpt_info hpt372a __devinitdata = {
31832 +static const struct hpt_info hpt372a __devinitconst = {
31833 .chip_name = "HPT372A",
31834 .chip_type = HPT372A,
31835 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31836 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31837 .timings = &hpt37x_timings
31838 };
31839
31840 -static const struct hpt_info hpt302 __devinitdata = {
31841 +static const struct hpt_info hpt302 __devinitconst = {
31842 .chip_name = "HPT302",
31843 .chip_type = HPT302,
31844 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31845 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31846 .timings = &hpt37x_timings
31847 };
31848
31849 -static const struct hpt_info hpt371 __devinitdata = {
31850 +static const struct hpt_info hpt371 __devinitconst = {
31851 .chip_name = "HPT371",
31852 .chip_type = HPT371,
31853 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31854 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31855 .timings = &hpt37x_timings
31856 };
31857
31858 -static const struct hpt_info hpt372n __devinitdata = {
31859 +static const struct hpt_info hpt372n __devinitconst = {
31860 .chip_name = "HPT372N",
31861 .chip_type = HPT372N,
31862 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31863 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31864 .timings = &hpt37x_timings
31865 };
31866
31867 -static const struct hpt_info hpt302n __devinitdata = {
31868 +static const struct hpt_info hpt302n __devinitconst = {
31869 .chip_name = "HPT302N",
31870 .chip_type = HPT302N,
31871 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31872 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31873 .timings = &hpt37x_timings
31874 };
31875
31876 -static const struct hpt_info hpt371n __devinitdata = {
31877 +static const struct hpt_info hpt371n __devinitconst = {
31878 .chip_name = "HPT371N",
31879 .chip_type = HPT371N,
31880 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31881 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31882 .dma_sff_read_status = ide_dma_sff_read_status,
31883 };
31884
31885 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31886 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31887 { /* 0: HPT36x */
31888 .name = DRV_NAME,
31889 .init_chipset = init_chipset_hpt366,
31890 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31891 index 8126824..55a2798 100644
31892 --- a/drivers/ide/ide-cd.c
31893 +++ b/drivers/ide/ide-cd.c
31894 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31895 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31896 if ((unsigned long)buf & alignment
31897 || blk_rq_bytes(rq) & q->dma_pad_mask
31898 - || object_is_on_stack(buf))
31899 + || object_starts_on_stack(buf))
31900 drive->dma = 0;
31901 }
31902 }
31903 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31904 index 7f56b73..dab5b67 100644
31905 --- a/drivers/ide/ide-pci-generic.c
31906 +++ b/drivers/ide/ide-pci-generic.c
31907 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31908 .udma_mask = ATA_UDMA6, \
31909 }
31910
31911 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31912 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31913 /* 0: Unknown */
31914 DECLARE_GENERIC_PCI_DEV(0),
31915
31916 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31917 index 560e66d..d5dd180 100644
31918 --- a/drivers/ide/it8172.c
31919 +++ b/drivers/ide/it8172.c
31920 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31921 .set_dma_mode = it8172_set_dma_mode,
31922 };
31923
31924 -static const struct ide_port_info it8172_port_info __devinitdata = {
31925 +static const struct ide_port_info it8172_port_info __devinitconst = {
31926 .name = DRV_NAME,
31927 .port_ops = &it8172_port_ops,
31928 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31929 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31930 index 46816ba..1847aeb 100644
31931 --- a/drivers/ide/it8213.c
31932 +++ b/drivers/ide/it8213.c
31933 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31934 .cable_detect = it8213_cable_detect,
31935 };
31936
31937 -static const struct ide_port_info it8213_chipset __devinitdata = {
31938 +static const struct ide_port_info it8213_chipset __devinitconst = {
31939 .name = DRV_NAME,
31940 .enablebits = { {0x41, 0x80, 0x80} },
31941 .port_ops = &it8213_port_ops,
31942 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31943 index 2e3169f..c5611db 100644
31944 --- a/drivers/ide/it821x.c
31945 +++ b/drivers/ide/it821x.c
31946 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31947 .cable_detect = it821x_cable_detect,
31948 };
31949
31950 -static const struct ide_port_info it821x_chipset __devinitdata = {
31951 +static const struct ide_port_info it821x_chipset __devinitconst = {
31952 .name = DRV_NAME,
31953 .init_chipset = init_chipset_it821x,
31954 .init_hwif = init_hwif_it821x,
31955 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31956 index 74c2c4a..efddd7d 100644
31957 --- a/drivers/ide/jmicron.c
31958 +++ b/drivers/ide/jmicron.c
31959 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31960 .cable_detect = jmicron_cable_detect,
31961 };
31962
31963 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31964 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31965 .name = DRV_NAME,
31966 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31967 .port_ops = &jmicron_port_ops,
31968 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31969 index 95327a2..73f78d8 100644
31970 --- a/drivers/ide/ns87415.c
31971 +++ b/drivers/ide/ns87415.c
31972 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31973 .dma_sff_read_status = superio_dma_sff_read_status,
31974 };
31975
31976 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31977 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31978 .name = DRV_NAME,
31979 .init_hwif = init_hwif_ns87415,
31980 .tp_ops = &ns87415_tp_ops,
31981 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31982 index 1a53a4c..39edc66 100644
31983 --- a/drivers/ide/opti621.c
31984 +++ b/drivers/ide/opti621.c
31985 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31986 .set_pio_mode = opti621_set_pio_mode,
31987 };
31988
31989 -static const struct ide_port_info opti621_chipset __devinitdata = {
31990 +static const struct ide_port_info opti621_chipset __devinitconst = {
31991 .name = DRV_NAME,
31992 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31993 .port_ops = &opti621_port_ops,
31994 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31995 index 9546fe2..2e5ceb6 100644
31996 --- a/drivers/ide/pdc202xx_new.c
31997 +++ b/drivers/ide/pdc202xx_new.c
31998 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31999 .udma_mask = udma, \
32000 }
32001
32002 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32003 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32004 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32005 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32006 };
32007 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32008 index 3a35ec6..5634510 100644
32009 --- a/drivers/ide/pdc202xx_old.c
32010 +++ b/drivers/ide/pdc202xx_old.c
32011 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32012 .max_sectors = sectors, \
32013 }
32014
32015 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32016 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32017 { /* 0: PDC20246 */
32018 .name = DRV_NAME,
32019 .init_chipset = init_chipset_pdc202xx,
32020 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32021 index 1892e81..fe0fd60 100644
32022 --- a/drivers/ide/piix.c
32023 +++ b/drivers/ide/piix.c
32024 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32025 .udma_mask = udma, \
32026 }
32027
32028 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32029 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32030 /* 0: MPIIX */
32031 { /*
32032 * MPIIX actually has only a single IDE channel mapped to
32033 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32034 index a6414a8..c04173e 100644
32035 --- a/drivers/ide/rz1000.c
32036 +++ b/drivers/ide/rz1000.c
32037 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32038 }
32039 }
32040
32041 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32042 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32043 .name = DRV_NAME,
32044 .host_flags = IDE_HFLAG_NO_DMA,
32045 };
32046 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32047 index 356b9b5..d4758eb 100644
32048 --- a/drivers/ide/sc1200.c
32049 +++ b/drivers/ide/sc1200.c
32050 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32051 .dma_sff_read_status = ide_dma_sff_read_status,
32052 };
32053
32054 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32055 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32056 .name = DRV_NAME,
32057 .port_ops = &sc1200_port_ops,
32058 .dma_ops = &sc1200_dma_ops,
32059 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32060 index b7f5b0c..9701038 100644
32061 --- a/drivers/ide/scc_pata.c
32062 +++ b/drivers/ide/scc_pata.c
32063 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32064 .dma_sff_read_status = scc_dma_sff_read_status,
32065 };
32066
32067 -static const struct ide_port_info scc_chipset __devinitdata = {
32068 +static const struct ide_port_info scc_chipset __devinitconst = {
32069 .name = "sccIDE",
32070 .init_iops = init_iops_scc,
32071 .init_dma = scc_init_dma,
32072 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32073 index 35fb8da..24d72ef 100644
32074 --- a/drivers/ide/serverworks.c
32075 +++ b/drivers/ide/serverworks.c
32076 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32077 .cable_detect = svwks_cable_detect,
32078 };
32079
32080 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32081 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32082 { /* 0: OSB4 */
32083 .name = DRV_NAME,
32084 .init_chipset = init_chipset_svwks,
32085 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32086 index ddeda44..46f7e30 100644
32087 --- a/drivers/ide/siimage.c
32088 +++ b/drivers/ide/siimage.c
32089 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32090 .udma_mask = ATA_UDMA6, \
32091 }
32092
32093 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32094 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32095 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32096 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32097 };
32098 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32099 index 4a00225..09e61b4 100644
32100 --- a/drivers/ide/sis5513.c
32101 +++ b/drivers/ide/sis5513.c
32102 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32103 .cable_detect = sis_cable_detect,
32104 };
32105
32106 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32107 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32108 .name = DRV_NAME,
32109 .init_chipset = init_chipset_sis5513,
32110 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32111 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32112 index f21dc2a..d051cd2 100644
32113 --- a/drivers/ide/sl82c105.c
32114 +++ b/drivers/ide/sl82c105.c
32115 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32116 .dma_sff_read_status = ide_dma_sff_read_status,
32117 };
32118
32119 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32120 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32121 .name = DRV_NAME,
32122 .init_chipset = init_chipset_sl82c105,
32123 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32124 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32125 index 864ffe0..863a5e9 100644
32126 --- a/drivers/ide/slc90e66.c
32127 +++ b/drivers/ide/slc90e66.c
32128 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32129 .cable_detect = slc90e66_cable_detect,
32130 };
32131
32132 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32133 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32134 .name = DRV_NAME,
32135 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32136 .port_ops = &slc90e66_port_ops,
32137 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32138 index 4799d5c..1794678 100644
32139 --- a/drivers/ide/tc86c001.c
32140 +++ b/drivers/ide/tc86c001.c
32141 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32142 .dma_sff_read_status = ide_dma_sff_read_status,
32143 };
32144
32145 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32146 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32147 .name = DRV_NAME,
32148 .init_hwif = init_hwif_tc86c001,
32149 .port_ops = &tc86c001_port_ops,
32150 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32151 index 281c914..55ce1b8 100644
32152 --- a/drivers/ide/triflex.c
32153 +++ b/drivers/ide/triflex.c
32154 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32155 .set_dma_mode = triflex_set_mode,
32156 };
32157
32158 -static const struct ide_port_info triflex_device __devinitdata = {
32159 +static const struct ide_port_info triflex_device __devinitconst = {
32160 .name = DRV_NAME,
32161 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32162 .port_ops = &triflex_port_ops,
32163 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32164 index 4b42ca0..e494a98 100644
32165 --- a/drivers/ide/trm290.c
32166 +++ b/drivers/ide/trm290.c
32167 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32168 .dma_check = trm290_dma_check,
32169 };
32170
32171 -static const struct ide_port_info trm290_chipset __devinitdata = {
32172 +static const struct ide_port_info trm290_chipset __devinitconst = {
32173 .name = DRV_NAME,
32174 .init_hwif = init_hwif_trm290,
32175 .tp_ops = &trm290_tp_ops,
32176 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32177 index f46f49c..eb77678 100644
32178 --- a/drivers/ide/via82cxxx.c
32179 +++ b/drivers/ide/via82cxxx.c
32180 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32181 .cable_detect = via82cxxx_cable_detect,
32182 };
32183
32184 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32185 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32186 .name = DRV_NAME,
32187 .init_chipset = init_chipset_via82cxxx,
32188 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32189 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32190 index 73d4531..c90cd2d 100644
32191 --- a/drivers/ieee802154/fakehard.c
32192 +++ b/drivers/ieee802154/fakehard.c
32193 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32194 phy->transmit_power = 0xbf;
32195
32196 dev->netdev_ops = &fake_ops;
32197 - dev->ml_priv = &fake_mlme;
32198 + dev->ml_priv = (void *)&fake_mlme;
32199
32200 priv = netdev_priv(dev);
32201 priv->phy = phy;
32202 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32203 index d67999f..4c5d083 100644
32204 --- a/drivers/infiniband/core/cm.c
32205 +++ b/drivers/infiniband/core/cm.c
32206 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32207
32208 struct cm_counter_group {
32209 struct kobject obj;
32210 - atomic_long_t counter[CM_ATTR_COUNT];
32211 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32212 };
32213
32214 struct cm_counter_attribute {
32215 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32216 struct ib_mad_send_buf *msg = NULL;
32217 int ret;
32218
32219 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32220 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32221 counter[CM_REQ_COUNTER]);
32222
32223 /* Quick state check to discard duplicate REQs. */
32224 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32225 if (!cm_id_priv)
32226 return;
32227
32228 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32229 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32230 counter[CM_REP_COUNTER]);
32231 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32232 if (ret)
32233 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32234 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32235 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32236 spin_unlock_irq(&cm_id_priv->lock);
32237 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32238 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32239 counter[CM_RTU_COUNTER]);
32240 goto out;
32241 }
32242 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32243 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32244 dreq_msg->local_comm_id);
32245 if (!cm_id_priv) {
32246 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32247 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32248 counter[CM_DREQ_COUNTER]);
32249 cm_issue_drep(work->port, work->mad_recv_wc);
32250 return -EINVAL;
32251 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32252 case IB_CM_MRA_REP_RCVD:
32253 break;
32254 case IB_CM_TIMEWAIT:
32255 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32256 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32257 counter[CM_DREQ_COUNTER]);
32258 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32259 goto unlock;
32260 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32261 cm_free_msg(msg);
32262 goto deref;
32263 case IB_CM_DREQ_RCVD:
32264 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32265 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32266 counter[CM_DREQ_COUNTER]);
32267 goto unlock;
32268 default:
32269 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32270 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32271 cm_id_priv->msg, timeout)) {
32272 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32273 - atomic_long_inc(&work->port->
32274 + atomic_long_inc_unchecked(&work->port->
32275 counter_group[CM_RECV_DUPLICATES].
32276 counter[CM_MRA_COUNTER]);
32277 goto out;
32278 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32279 break;
32280 case IB_CM_MRA_REQ_RCVD:
32281 case IB_CM_MRA_REP_RCVD:
32282 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32283 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32284 counter[CM_MRA_COUNTER]);
32285 /* fall through */
32286 default:
32287 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32288 case IB_CM_LAP_IDLE:
32289 break;
32290 case IB_CM_MRA_LAP_SENT:
32291 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32292 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32293 counter[CM_LAP_COUNTER]);
32294 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32295 goto unlock;
32296 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32297 cm_free_msg(msg);
32298 goto deref;
32299 case IB_CM_LAP_RCVD:
32300 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32301 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32302 counter[CM_LAP_COUNTER]);
32303 goto unlock;
32304 default:
32305 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32306 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32307 if (cur_cm_id_priv) {
32308 spin_unlock_irq(&cm.lock);
32309 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32310 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32311 counter[CM_SIDR_REQ_COUNTER]);
32312 goto out; /* Duplicate message. */
32313 }
32314 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32315 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32316 msg->retries = 1;
32317
32318 - atomic_long_add(1 + msg->retries,
32319 + atomic_long_add_unchecked(1 + msg->retries,
32320 &port->counter_group[CM_XMIT].counter[attr_index]);
32321 if (msg->retries)
32322 - atomic_long_add(msg->retries,
32323 + atomic_long_add_unchecked(msg->retries,
32324 &port->counter_group[CM_XMIT_RETRIES].
32325 counter[attr_index]);
32326
32327 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32328 }
32329
32330 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32331 - atomic_long_inc(&port->counter_group[CM_RECV].
32332 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32333 counter[attr_id - CM_ATTR_ID_OFFSET]);
32334
32335 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32336 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32337 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32338
32339 return sprintf(buf, "%ld\n",
32340 - atomic_long_read(&group->counter[cm_attr->index]));
32341 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32342 }
32343
32344 static const struct sysfs_ops cm_counter_ops = {
32345 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32346 index 176c8f9..2627b62 100644
32347 --- a/drivers/infiniband/core/fmr_pool.c
32348 +++ b/drivers/infiniband/core/fmr_pool.c
32349 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32350
32351 struct task_struct *thread;
32352
32353 - atomic_t req_ser;
32354 - atomic_t flush_ser;
32355 + atomic_unchecked_t req_ser;
32356 + atomic_unchecked_t flush_ser;
32357
32358 wait_queue_head_t force_wait;
32359 };
32360 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32361 struct ib_fmr_pool *pool = pool_ptr;
32362
32363 do {
32364 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32365 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32366 ib_fmr_batch_release(pool);
32367
32368 - atomic_inc(&pool->flush_ser);
32369 + atomic_inc_unchecked(&pool->flush_ser);
32370 wake_up_interruptible(&pool->force_wait);
32371
32372 if (pool->flush_function)
32373 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32374 }
32375
32376 set_current_state(TASK_INTERRUPTIBLE);
32377 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32378 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32379 !kthread_should_stop())
32380 schedule();
32381 __set_current_state(TASK_RUNNING);
32382 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32383 pool->dirty_watermark = params->dirty_watermark;
32384 pool->dirty_len = 0;
32385 spin_lock_init(&pool->pool_lock);
32386 - atomic_set(&pool->req_ser, 0);
32387 - atomic_set(&pool->flush_ser, 0);
32388 + atomic_set_unchecked(&pool->req_ser, 0);
32389 + atomic_set_unchecked(&pool->flush_ser, 0);
32390 init_waitqueue_head(&pool->force_wait);
32391
32392 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32393 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32394 }
32395 spin_unlock_irq(&pool->pool_lock);
32396
32397 - serial = atomic_inc_return(&pool->req_ser);
32398 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32399 wake_up_process(pool->thread);
32400
32401 if (wait_event_interruptible(pool->force_wait,
32402 - atomic_read(&pool->flush_ser) - serial >= 0))
32403 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32404 return -EINTR;
32405
32406 return 0;
32407 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32408 } else {
32409 list_add_tail(&fmr->list, &pool->dirty_list);
32410 if (++pool->dirty_len >= pool->dirty_watermark) {
32411 - atomic_inc(&pool->req_ser);
32412 + atomic_inc_unchecked(&pool->req_ser);
32413 wake_up_process(pool->thread);
32414 }
32415 }
32416 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32417 index 57e07c6..56d09d4 100644
32418 --- a/drivers/infiniband/hw/cxgb4/mem.c
32419 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32420 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32421 int err;
32422 struct fw_ri_tpte tpt;
32423 u32 stag_idx;
32424 - static atomic_t key;
32425 + static atomic_unchecked_t key;
32426
32427 if (c4iw_fatal_error(rdev))
32428 return -EIO;
32429 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32430 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32431 rdev->stats.stag.max = rdev->stats.stag.cur;
32432 mutex_unlock(&rdev->stats.lock);
32433 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32434 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32435 }
32436 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32437 __func__, stag_state, type, pdid, stag_idx);
32438 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32439 index 79b3dbc..96e5fcc 100644
32440 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32441 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32442 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32443 struct ib_atomic_eth *ateth;
32444 struct ipath_ack_entry *e;
32445 u64 vaddr;
32446 - atomic64_t *maddr;
32447 + atomic64_unchecked_t *maddr;
32448 u64 sdata;
32449 u32 rkey;
32450 u8 next;
32451 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32452 IB_ACCESS_REMOTE_ATOMIC)))
32453 goto nack_acc_unlck;
32454 /* Perform atomic OP and save result. */
32455 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32456 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32457 sdata = be64_to_cpu(ateth->swap_data);
32458 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32459 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32460 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32461 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32462 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32463 be64_to_cpu(ateth->compare_data),
32464 sdata);
32465 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32466 index 1f95bba..9530f87 100644
32467 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32468 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32469 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32470 unsigned long flags;
32471 struct ib_wc wc;
32472 u64 sdata;
32473 - atomic64_t *maddr;
32474 + atomic64_unchecked_t *maddr;
32475 enum ib_wc_status send_status;
32476
32477 /*
32478 @@ -382,11 +382,11 @@ again:
32479 IB_ACCESS_REMOTE_ATOMIC)))
32480 goto acc_err;
32481 /* Perform atomic OP and save result. */
32482 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32483 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32484 sdata = wqe->wr.wr.atomic.compare_add;
32485 *(u64 *) sqp->s_sge.sge.vaddr =
32486 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32487 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32488 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32489 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32490 sdata, wqe->wr.wr.atomic.swap);
32491 goto send_comp;
32492 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32493 index 7140199..da60063 100644
32494 --- a/drivers/infiniband/hw/nes/nes.c
32495 +++ b/drivers/infiniband/hw/nes/nes.c
32496 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32497 LIST_HEAD(nes_adapter_list);
32498 static LIST_HEAD(nes_dev_list);
32499
32500 -atomic_t qps_destroyed;
32501 +atomic_unchecked_t qps_destroyed;
32502
32503 static unsigned int ee_flsh_adapter;
32504 static unsigned int sysfs_nonidx_addr;
32505 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32506 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32507 struct nes_adapter *nesadapter = nesdev->nesadapter;
32508
32509 - atomic_inc(&qps_destroyed);
32510 + atomic_inc_unchecked(&qps_destroyed);
32511
32512 /* Free the control structures */
32513
32514 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32515 index c438e46..ca30356 100644
32516 --- a/drivers/infiniband/hw/nes/nes.h
32517 +++ b/drivers/infiniband/hw/nes/nes.h
32518 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32519 extern unsigned int wqm_quanta;
32520 extern struct list_head nes_adapter_list;
32521
32522 -extern atomic_t cm_connects;
32523 -extern atomic_t cm_accepts;
32524 -extern atomic_t cm_disconnects;
32525 -extern atomic_t cm_closes;
32526 -extern atomic_t cm_connecteds;
32527 -extern atomic_t cm_connect_reqs;
32528 -extern atomic_t cm_rejects;
32529 -extern atomic_t mod_qp_timouts;
32530 -extern atomic_t qps_created;
32531 -extern atomic_t qps_destroyed;
32532 -extern atomic_t sw_qps_destroyed;
32533 +extern atomic_unchecked_t cm_connects;
32534 +extern atomic_unchecked_t cm_accepts;
32535 +extern atomic_unchecked_t cm_disconnects;
32536 +extern atomic_unchecked_t cm_closes;
32537 +extern atomic_unchecked_t cm_connecteds;
32538 +extern atomic_unchecked_t cm_connect_reqs;
32539 +extern atomic_unchecked_t cm_rejects;
32540 +extern atomic_unchecked_t mod_qp_timouts;
32541 +extern atomic_unchecked_t qps_created;
32542 +extern atomic_unchecked_t qps_destroyed;
32543 +extern atomic_unchecked_t sw_qps_destroyed;
32544 extern u32 mh_detected;
32545 extern u32 mh_pauses_sent;
32546 extern u32 cm_packets_sent;
32547 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32548 extern u32 cm_packets_received;
32549 extern u32 cm_packets_dropped;
32550 extern u32 cm_packets_retrans;
32551 -extern atomic_t cm_listens_created;
32552 -extern atomic_t cm_listens_destroyed;
32553 +extern atomic_unchecked_t cm_listens_created;
32554 +extern atomic_unchecked_t cm_listens_destroyed;
32555 extern u32 cm_backlog_drops;
32556 -extern atomic_t cm_loopbacks;
32557 -extern atomic_t cm_nodes_created;
32558 -extern atomic_t cm_nodes_destroyed;
32559 -extern atomic_t cm_accel_dropped_pkts;
32560 -extern atomic_t cm_resets_recvd;
32561 -extern atomic_t pau_qps_created;
32562 -extern atomic_t pau_qps_destroyed;
32563 +extern atomic_unchecked_t cm_loopbacks;
32564 +extern atomic_unchecked_t cm_nodes_created;
32565 +extern atomic_unchecked_t cm_nodes_destroyed;
32566 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32567 +extern atomic_unchecked_t cm_resets_recvd;
32568 +extern atomic_unchecked_t pau_qps_created;
32569 +extern atomic_unchecked_t pau_qps_destroyed;
32570
32571 extern u32 int_mod_timer_init;
32572 extern u32 int_mod_cq_depth_256;
32573 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32574 index 020e95c..fbb3450 100644
32575 --- a/drivers/infiniband/hw/nes/nes_cm.c
32576 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32577 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32578 u32 cm_packets_retrans;
32579 u32 cm_packets_created;
32580 u32 cm_packets_received;
32581 -atomic_t cm_listens_created;
32582 -atomic_t cm_listens_destroyed;
32583 +atomic_unchecked_t cm_listens_created;
32584 +atomic_unchecked_t cm_listens_destroyed;
32585 u32 cm_backlog_drops;
32586 -atomic_t cm_loopbacks;
32587 -atomic_t cm_nodes_created;
32588 -atomic_t cm_nodes_destroyed;
32589 -atomic_t cm_accel_dropped_pkts;
32590 -atomic_t cm_resets_recvd;
32591 +atomic_unchecked_t cm_loopbacks;
32592 +atomic_unchecked_t cm_nodes_created;
32593 +atomic_unchecked_t cm_nodes_destroyed;
32594 +atomic_unchecked_t cm_accel_dropped_pkts;
32595 +atomic_unchecked_t cm_resets_recvd;
32596
32597 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32598 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32599 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32600
32601 static struct nes_cm_core *g_cm_core;
32602
32603 -atomic_t cm_connects;
32604 -atomic_t cm_accepts;
32605 -atomic_t cm_disconnects;
32606 -atomic_t cm_closes;
32607 -atomic_t cm_connecteds;
32608 -atomic_t cm_connect_reqs;
32609 -atomic_t cm_rejects;
32610 +atomic_unchecked_t cm_connects;
32611 +atomic_unchecked_t cm_accepts;
32612 +atomic_unchecked_t cm_disconnects;
32613 +atomic_unchecked_t cm_closes;
32614 +atomic_unchecked_t cm_connecteds;
32615 +atomic_unchecked_t cm_connect_reqs;
32616 +atomic_unchecked_t cm_rejects;
32617
32618 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32619 {
32620 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32621 kfree(listener);
32622 listener = NULL;
32623 ret = 0;
32624 - atomic_inc(&cm_listens_destroyed);
32625 + atomic_inc_unchecked(&cm_listens_destroyed);
32626 } else {
32627 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32628 }
32629 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32630 cm_node->rem_mac);
32631
32632 add_hte_node(cm_core, cm_node);
32633 - atomic_inc(&cm_nodes_created);
32634 + atomic_inc_unchecked(&cm_nodes_created);
32635
32636 return cm_node;
32637 }
32638 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32639 }
32640
32641 atomic_dec(&cm_core->node_cnt);
32642 - atomic_inc(&cm_nodes_destroyed);
32643 + atomic_inc_unchecked(&cm_nodes_destroyed);
32644 nesqp = cm_node->nesqp;
32645 if (nesqp) {
32646 nesqp->cm_node = NULL;
32647 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32648
32649 static void drop_packet(struct sk_buff *skb)
32650 {
32651 - atomic_inc(&cm_accel_dropped_pkts);
32652 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32653 dev_kfree_skb_any(skb);
32654 }
32655
32656 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32657 {
32658
32659 int reset = 0; /* whether to send reset in case of err.. */
32660 - atomic_inc(&cm_resets_recvd);
32661 + atomic_inc_unchecked(&cm_resets_recvd);
32662 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32663 " refcnt=%d\n", cm_node, cm_node->state,
32664 atomic_read(&cm_node->ref_count));
32665 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32666 rem_ref_cm_node(cm_node->cm_core, cm_node);
32667 return NULL;
32668 }
32669 - atomic_inc(&cm_loopbacks);
32670 + atomic_inc_unchecked(&cm_loopbacks);
32671 loopbackremotenode->loopbackpartner = cm_node;
32672 loopbackremotenode->tcp_cntxt.rcv_wscale =
32673 NES_CM_DEFAULT_RCV_WND_SCALE;
32674 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32675 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32676 else {
32677 rem_ref_cm_node(cm_core, cm_node);
32678 - atomic_inc(&cm_accel_dropped_pkts);
32679 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32680 dev_kfree_skb_any(skb);
32681 }
32682 break;
32683 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32684
32685 if ((cm_id) && (cm_id->event_handler)) {
32686 if (issue_disconn) {
32687 - atomic_inc(&cm_disconnects);
32688 + atomic_inc_unchecked(&cm_disconnects);
32689 cm_event.event = IW_CM_EVENT_DISCONNECT;
32690 cm_event.status = disconn_status;
32691 cm_event.local_addr = cm_id->local_addr;
32692 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32693 }
32694
32695 if (issue_close) {
32696 - atomic_inc(&cm_closes);
32697 + atomic_inc_unchecked(&cm_closes);
32698 nes_disconnect(nesqp, 1);
32699
32700 cm_id->provider_data = nesqp;
32701 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32702
32703 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32704 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32705 - atomic_inc(&cm_accepts);
32706 + atomic_inc_unchecked(&cm_accepts);
32707
32708 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32709 netdev_refcnt_read(nesvnic->netdev));
32710 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32711 struct nes_cm_core *cm_core;
32712 u8 *start_buff;
32713
32714 - atomic_inc(&cm_rejects);
32715 + atomic_inc_unchecked(&cm_rejects);
32716 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32717 loopback = cm_node->loopbackpartner;
32718 cm_core = cm_node->cm_core;
32719 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32720 ntohl(cm_id->local_addr.sin_addr.s_addr),
32721 ntohs(cm_id->local_addr.sin_port));
32722
32723 - atomic_inc(&cm_connects);
32724 + atomic_inc_unchecked(&cm_connects);
32725 nesqp->active_conn = 1;
32726
32727 /* cache the cm_id in the qp */
32728 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32729 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32730 return err;
32731 }
32732 - atomic_inc(&cm_listens_created);
32733 + atomic_inc_unchecked(&cm_listens_created);
32734 }
32735
32736 cm_id->add_ref(cm_id);
32737 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32738
32739 if (nesqp->destroyed)
32740 return;
32741 - atomic_inc(&cm_connecteds);
32742 + atomic_inc_unchecked(&cm_connecteds);
32743 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32744 " local port 0x%04X. jiffies = %lu.\n",
32745 nesqp->hwqp.qp_id,
32746 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32747
32748 cm_id->add_ref(cm_id);
32749 ret = cm_id->event_handler(cm_id, &cm_event);
32750 - atomic_inc(&cm_closes);
32751 + atomic_inc_unchecked(&cm_closes);
32752 cm_event.event = IW_CM_EVENT_CLOSE;
32753 cm_event.status = 0;
32754 cm_event.provider_data = cm_id->provider_data;
32755 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32756 return;
32757 cm_id = cm_node->cm_id;
32758
32759 - atomic_inc(&cm_connect_reqs);
32760 + atomic_inc_unchecked(&cm_connect_reqs);
32761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32762 cm_node, cm_id, jiffies);
32763
32764 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32765 return;
32766 cm_id = cm_node->cm_id;
32767
32768 - atomic_inc(&cm_connect_reqs);
32769 + atomic_inc_unchecked(&cm_connect_reqs);
32770 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32771 cm_node, cm_id, jiffies);
32772
32773 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32774 index 3ba7be3..c81f6ff 100644
32775 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32776 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32777 @@ -40,8 +40,8 @@
32778 #include "nes.h"
32779 #include "nes_mgt.h"
32780
32781 -atomic_t pau_qps_created;
32782 -atomic_t pau_qps_destroyed;
32783 +atomic_unchecked_t pau_qps_created;
32784 +atomic_unchecked_t pau_qps_destroyed;
32785
32786 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32787 {
32788 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32789 {
32790 struct sk_buff *skb;
32791 unsigned long flags;
32792 - atomic_inc(&pau_qps_destroyed);
32793 + atomic_inc_unchecked(&pau_qps_destroyed);
32794
32795 /* Free packets that have not yet been forwarded */
32796 /* Lock is acquired by skb_dequeue when removing the skb */
32797 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32798 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32799 skb_queue_head_init(&nesqp->pau_list);
32800 spin_lock_init(&nesqp->pau_lock);
32801 - atomic_inc(&pau_qps_created);
32802 + atomic_inc_unchecked(&pau_qps_created);
32803 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32804 }
32805
32806 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32807 index f3a3ecf..57d311d 100644
32808 --- a/drivers/infiniband/hw/nes/nes_nic.c
32809 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32810 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32811 target_stat_values[++index] = mh_detected;
32812 target_stat_values[++index] = mh_pauses_sent;
32813 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32814 - target_stat_values[++index] = atomic_read(&cm_connects);
32815 - target_stat_values[++index] = atomic_read(&cm_accepts);
32816 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32817 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32818 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32819 - target_stat_values[++index] = atomic_read(&cm_rejects);
32820 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32821 - target_stat_values[++index] = atomic_read(&qps_created);
32822 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32823 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32824 - target_stat_values[++index] = atomic_read(&cm_closes);
32825 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32826 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32827 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32828 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32829 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32830 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32831 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32832 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32833 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32834 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32835 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32836 target_stat_values[++index] = cm_packets_sent;
32837 target_stat_values[++index] = cm_packets_bounced;
32838 target_stat_values[++index] = cm_packets_created;
32839 target_stat_values[++index] = cm_packets_received;
32840 target_stat_values[++index] = cm_packets_dropped;
32841 target_stat_values[++index] = cm_packets_retrans;
32842 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32843 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32844 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32845 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32846 target_stat_values[++index] = cm_backlog_drops;
32847 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32848 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32849 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32850 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32851 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32852 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32853 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32854 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32855 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32856 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32857 target_stat_values[++index] = nesadapter->free_4kpbl;
32858 target_stat_values[++index] = nesadapter->free_256pbl;
32859 target_stat_values[++index] = int_mod_timer_init;
32860 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32861 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32862 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32863 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32864 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32865 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32866 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32867 }
32868
32869 /**
32870 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32871 index 8b8812d..a5e1133 100644
32872 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32873 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32874 @@ -46,9 +46,9 @@
32875
32876 #include <rdma/ib_umem.h>
32877
32878 -atomic_t mod_qp_timouts;
32879 -atomic_t qps_created;
32880 -atomic_t sw_qps_destroyed;
32881 +atomic_unchecked_t mod_qp_timouts;
32882 +atomic_unchecked_t qps_created;
32883 +atomic_unchecked_t sw_qps_destroyed;
32884
32885 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32886
32887 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32888 if (init_attr->create_flags)
32889 return ERR_PTR(-EINVAL);
32890
32891 - atomic_inc(&qps_created);
32892 + atomic_inc_unchecked(&qps_created);
32893 switch (init_attr->qp_type) {
32894 case IB_QPT_RC:
32895 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32896 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32897 struct iw_cm_event cm_event;
32898 int ret = 0;
32899
32900 - atomic_inc(&sw_qps_destroyed);
32901 + atomic_inc_unchecked(&sw_qps_destroyed);
32902 nesqp->destroyed = 1;
32903
32904 /* Blow away the connection if it exists. */
32905 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32906 index 7b1b8669..4b69f85 100644
32907 --- a/drivers/infiniband/hw/qib/qib.h
32908 +++ b/drivers/infiniband/hw/qib/qib.h
32909 @@ -51,6 +51,7 @@
32910 #include <linux/completion.h>
32911 #include <linux/kref.h>
32912 #include <linux/sched.h>
32913 +#include <linux/slab.h>
32914
32915 #include "qib_common.h"
32916 #include "qib_verbs.h"
32917 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32918 index da739d9..da1c7f4 100644
32919 --- a/drivers/input/gameport/gameport.c
32920 +++ b/drivers/input/gameport/gameport.c
32921 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32922 */
32923 static void gameport_init_port(struct gameport *gameport)
32924 {
32925 - static atomic_t gameport_no = ATOMIC_INIT(0);
32926 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32927
32928 __module_get(THIS_MODULE);
32929
32930 mutex_init(&gameport->drv_mutex);
32931 device_initialize(&gameport->dev);
32932 dev_set_name(&gameport->dev, "gameport%lu",
32933 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32934 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32935 gameport->dev.bus = &gameport_bus;
32936 gameport->dev.release = gameport_release_port;
32937 if (gameport->parent)
32938 diff --git a/drivers/input/input.c b/drivers/input/input.c
32939 index 8921c61..f5cd63d 100644
32940 --- a/drivers/input/input.c
32941 +++ b/drivers/input/input.c
32942 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32943 */
32944 int input_register_device(struct input_dev *dev)
32945 {
32946 - static atomic_t input_no = ATOMIC_INIT(0);
32947 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32948 struct input_handler *handler;
32949 const char *path;
32950 int error;
32951 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32952 dev->setkeycode = input_default_setkeycode;
32953
32954 dev_set_name(&dev->dev, "input%ld",
32955 - (unsigned long) atomic_inc_return(&input_no) - 1);
32956 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32957
32958 error = device_add(&dev->dev);
32959 if (error)
32960 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32961 index 04c69af..5f92d00 100644
32962 --- a/drivers/input/joystick/sidewinder.c
32963 +++ b/drivers/input/joystick/sidewinder.c
32964 @@ -30,6 +30,7 @@
32965 #include <linux/kernel.h>
32966 #include <linux/module.h>
32967 #include <linux/slab.h>
32968 +#include <linux/sched.h>
32969 #include <linux/init.h>
32970 #include <linux/input.h>
32971 #include <linux/gameport.h>
32972 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32973 index 83811e4..0822b90 100644
32974 --- a/drivers/input/joystick/xpad.c
32975 +++ b/drivers/input/joystick/xpad.c
32976 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32977
32978 static int xpad_led_probe(struct usb_xpad *xpad)
32979 {
32980 - static atomic_t led_seq = ATOMIC_INIT(0);
32981 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32982 long led_no;
32983 struct xpad_led *led;
32984 struct led_classdev *led_cdev;
32985 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32986 if (!led)
32987 return -ENOMEM;
32988
32989 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32990 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32991
32992 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32993 led->xpad = xpad;
32994 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32995 index 0110b5a..d3ad144 100644
32996 --- a/drivers/input/mousedev.c
32997 +++ b/drivers/input/mousedev.c
32998 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32999
33000 spin_unlock_irq(&client->packet_lock);
33001
33002 - if (copy_to_user(buffer, data, count))
33003 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33004 return -EFAULT;
33005
33006 return count;
33007 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33008 index d0f7533..fb8215b 100644
33009 --- a/drivers/input/serio/serio.c
33010 +++ b/drivers/input/serio/serio.c
33011 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33012 */
33013 static void serio_init_port(struct serio *serio)
33014 {
33015 - static atomic_t serio_no = ATOMIC_INIT(0);
33016 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33017
33018 __module_get(THIS_MODULE);
33019
33020 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33021 mutex_init(&serio->drv_mutex);
33022 device_initialize(&serio->dev);
33023 dev_set_name(&serio->dev, "serio%ld",
33024 - (long)atomic_inc_return(&serio_no) - 1);
33025 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33026 serio->dev.bus = &serio_bus;
33027 serio->dev.release = serio_release_port;
33028 serio->dev.groups = serio_device_attr_groups;
33029 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33030 index 38c4bd8..58965d9 100644
33031 --- a/drivers/isdn/capi/capi.c
33032 +++ b/drivers/isdn/capi/capi.c
33033 @@ -83,8 +83,8 @@ struct capiminor {
33034
33035 struct capi20_appl *ap;
33036 u32 ncci;
33037 - atomic_t datahandle;
33038 - atomic_t msgid;
33039 + atomic_unchecked_t datahandle;
33040 + atomic_unchecked_t msgid;
33041
33042 struct tty_port port;
33043 int ttyinstop;
33044 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33045 capimsg_setu16(s, 2, mp->ap->applid);
33046 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33047 capimsg_setu8 (s, 5, CAPI_RESP);
33048 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33049 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33050 capimsg_setu32(s, 8, mp->ncci);
33051 capimsg_setu16(s, 12, datahandle);
33052 }
33053 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33054 mp->outbytes -= len;
33055 spin_unlock_bh(&mp->outlock);
33056
33057 - datahandle = atomic_inc_return(&mp->datahandle);
33058 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33059 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33060 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33061 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33062 capimsg_setu16(skb->data, 2, mp->ap->applid);
33063 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33064 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33065 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33066 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33067 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33068 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33069 capimsg_setu16(skb->data, 16, len); /* Data length */
33070 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33071 index a6d9fd2..afdb8a3 100644
33072 --- a/drivers/isdn/gigaset/interface.c
33073 +++ b/drivers/isdn/gigaset/interface.c
33074 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33075 }
33076 tty->driver_data = cs;
33077
33078 - ++cs->port.count;
33079 + atomic_inc(&cs->port.count);
33080
33081 - if (cs->port.count == 1) {
33082 + if (atomic_read(&cs->port.count) == 1) {
33083 tty_port_tty_set(&cs->port, tty);
33084 tty->low_latency = 1;
33085 }
33086 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33087
33088 if (!cs->connected)
33089 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33090 - else if (!cs->port.count)
33091 + else if (!atomic_read(&cs->port.count))
33092 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33093 - else if (!--cs->port.count)
33094 + else if (!atomic_dec_return(&cs->port.count))
33095 tty_port_tty_set(&cs->port, NULL);
33096
33097 mutex_unlock(&cs->mutex);
33098 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33099 index 821f7ac..28d4030 100644
33100 --- a/drivers/isdn/hardware/avm/b1.c
33101 +++ b/drivers/isdn/hardware/avm/b1.c
33102 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33103 }
33104 if (left) {
33105 if (t4file->user) {
33106 - if (copy_from_user(buf, dp, left))
33107 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33108 return -EFAULT;
33109 } else {
33110 memcpy(buf, dp, left);
33111 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33112 }
33113 if (left) {
33114 if (config->user) {
33115 - if (copy_from_user(buf, dp, left))
33116 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33117 return -EFAULT;
33118 } else {
33119 memcpy(buf, dp, left);
33120 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33121 index dd6b53a..19d9ee6 100644
33122 --- a/drivers/isdn/hardware/eicon/divasync.h
33123 +++ b/drivers/isdn/hardware/eicon/divasync.h
33124 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33125 } diva_didd_add_adapter_t;
33126 typedef struct _diva_didd_remove_adapter {
33127 IDI_CALL p_request;
33128 -} diva_didd_remove_adapter_t;
33129 +} __no_const diva_didd_remove_adapter_t;
33130 typedef struct _diva_didd_read_adapter_array {
33131 void *buffer;
33132 dword length;
33133 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33134 index d303e65..28bcb7b 100644
33135 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33136 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33137 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33138 typedef struct _diva_os_idi_adapter_interface {
33139 diva_init_card_proc_t cleanup_adapter_proc;
33140 diva_cmd_card_proc_t cmd_proc;
33141 -} diva_os_idi_adapter_interface_t;
33142 +} __no_const diva_os_idi_adapter_interface_t;
33143
33144 typedef struct _diva_os_xdi_adapter {
33145 struct list_head link;
33146 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33147 index 7bc5067..fd36232 100644
33148 --- a/drivers/isdn/i4l/isdn_tty.c
33149 +++ b/drivers/isdn/i4l/isdn_tty.c
33150 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33151 port = &info->port;
33152 #ifdef ISDN_DEBUG_MODEM_OPEN
33153 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33154 - port->count);
33155 + atomic_read(&port->count))
33156 #endif
33157 - port->count++;
33158 + atomic_inc(&port->count);
33159 tty->driver_data = info;
33160 port->tty = tty;
33161 tty->port = port;
33162 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33163 #endif
33164 return;
33165 }
33166 - if ((tty->count == 1) && (port->count != 1)) {
33167 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33168 /*
33169 * Uh, oh. tty->count is 1, which means that the tty
33170 * structure will be freed. Info->count should always
33171 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33172 * serial port won't be shutdown.
33173 */
33174 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33175 - "info->count is %d\n", port->count);
33176 - port->count = 1;
33177 + "info->count is %d\n", atomic_read(&port->count));
33178 + atomic_set(&port->count, 1);
33179 }
33180 - if (--port->count < 0) {
33181 + if (atomic_dec_return(&port->count) < 0) {
33182 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33183 - info->line, port->count);
33184 - port->count = 0;
33185 + info->line, atomic_read(&port->count));
33186 + atomic_set(&port->count, 0);
33187 }
33188 - if (port->count) {
33189 + if (atomic_read(&port->count)) {
33190 #ifdef ISDN_DEBUG_MODEM_OPEN
33191 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33192 #endif
33193 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33194 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33195 return;
33196 isdn_tty_shutdown(info);
33197 - port->count = 0;
33198 + atomic_set(&port->count, 0);
33199 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33200 port->tty = NULL;
33201 wake_up_interruptible(&port->open_wait);
33202 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33203 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33204 modem_info *info = &dev->mdm.info[i];
33205
33206 - if (info->port.count == 0)
33207 + if (atomic_read(&info->port.count) == 0)
33208 continue;
33209 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33210 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33211 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33212 index e74df7c..03a03ba 100644
33213 --- a/drivers/isdn/icn/icn.c
33214 +++ b/drivers/isdn/icn/icn.c
33215 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33216 if (count > len)
33217 count = len;
33218 if (user) {
33219 - if (copy_from_user(msg, buf, count))
33220 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33221 return -EFAULT;
33222 } else
33223 memcpy(msg, buf, count);
33224 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33225 index b5fdcb7..5b6c59f 100644
33226 --- a/drivers/lguest/core.c
33227 +++ b/drivers/lguest/core.c
33228 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33229 * it's worked so far. The end address needs +1 because __get_vm_area
33230 * allocates an extra guard page, so we need space for that.
33231 */
33232 +
33233 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33234 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33235 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33236 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33237 +#else
33238 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33239 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33240 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33241 +#endif
33242 +
33243 if (!switcher_vma) {
33244 err = -ENOMEM;
33245 printk("lguest: could not map switcher pages high\n");
33246 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33247 * Now the Switcher is mapped at the right address, we can't fail!
33248 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33249 */
33250 - memcpy(switcher_vma->addr, start_switcher_text,
33251 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33252 end_switcher_text - start_switcher_text);
33253
33254 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33255 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33256 index 39809035..ce25c5e 100644
33257 --- a/drivers/lguest/x86/core.c
33258 +++ b/drivers/lguest/x86/core.c
33259 @@ -59,7 +59,7 @@ static struct {
33260 /* Offset from where switcher.S was compiled to where we've copied it */
33261 static unsigned long switcher_offset(void)
33262 {
33263 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33264 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33265 }
33266
33267 /* This cpu's struct lguest_pages. */
33268 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33269 * These copies are pretty cheap, so we do them unconditionally: */
33270 /* Save the current Host top-level page directory.
33271 */
33272 +
33273 +#ifdef CONFIG_PAX_PER_CPU_PGD
33274 + pages->state.host_cr3 = read_cr3();
33275 +#else
33276 pages->state.host_cr3 = __pa(current->mm->pgd);
33277 +#endif
33278 +
33279 /*
33280 * Set up the Guest's page tables to see this CPU's pages (and no
33281 * other CPU's pages).
33282 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33283 * compiled-in switcher code and the high-mapped copy we just made.
33284 */
33285 for (i = 0; i < IDT_ENTRIES; i++)
33286 - default_idt_entries[i] += switcher_offset();
33287 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33288
33289 /*
33290 * Set up the Switcher's per-cpu areas.
33291 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33292 * it will be undisturbed when we switch. To change %cs and jump we
33293 * need this structure to feed to Intel's "lcall" instruction.
33294 */
33295 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33296 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33297 lguest_entry.segment = LGUEST_CS;
33298
33299 /*
33300 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33301 index 40634b0..4f5855e 100644
33302 --- a/drivers/lguest/x86/switcher_32.S
33303 +++ b/drivers/lguest/x86/switcher_32.S
33304 @@ -87,6 +87,7 @@
33305 #include <asm/page.h>
33306 #include <asm/segment.h>
33307 #include <asm/lguest.h>
33308 +#include <asm/processor-flags.h>
33309
33310 // We mark the start of the code to copy
33311 // It's placed in .text tho it's never run here
33312 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33313 // Changes type when we load it: damn Intel!
33314 // For after we switch over our page tables
33315 // That entry will be read-only: we'd crash.
33316 +
33317 +#ifdef CONFIG_PAX_KERNEXEC
33318 + mov %cr0, %edx
33319 + xor $X86_CR0_WP, %edx
33320 + mov %edx, %cr0
33321 +#endif
33322 +
33323 movl $(GDT_ENTRY_TSS*8), %edx
33324 ltr %dx
33325
33326 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33327 // Let's clear it again for our return.
33328 // The GDT descriptor of the Host
33329 // Points to the table after two "size" bytes
33330 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33331 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33332 // Clear "used" from type field (byte 5, bit 2)
33333 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33334 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33335 +
33336 +#ifdef CONFIG_PAX_KERNEXEC
33337 + mov %cr0, %eax
33338 + xor $X86_CR0_WP, %eax
33339 + mov %eax, %cr0
33340 +#endif
33341
33342 // Once our page table's switched, the Guest is live!
33343 // The Host fades as we run this final step.
33344 @@ -295,13 +309,12 @@ deliver_to_host:
33345 // I consulted gcc, and it gave
33346 // These instructions, which I gladly credit:
33347 leal (%edx,%ebx,8), %eax
33348 - movzwl (%eax),%edx
33349 - movl 4(%eax), %eax
33350 - xorw %ax, %ax
33351 - orl %eax, %edx
33352 + movl 4(%eax), %edx
33353 + movw (%eax), %dx
33354 // Now the address of the handler's in %edx
33355 // We call it now: its "iret" drops us home.
33356 - jmp *%edx
33357 + ljmp $__KERNEL_CS, $1f
33358 +1: jmp *%edx
33359
33360 // Every interrupt can come to us here
33361 // But we must truly tell each apart.
33362 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33363 index 20e5c2c..9e849a9 100644
33364 --- a/drivers/macintosh/macio_asic.c
33365 +++ b/drivers/macintosh/macio_asic.c
33366 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33367 * MacIO is matched against any Apple ID, it's probe() function
33368 * will then decide wether it applies or not
33369 */
33370 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33371 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33372 .vendor = PCI_VENDOR_ID_APPLE,
33373 .device = PCI_ANY_ID,
33374 .subvendor = PCI_ANY_ID,
33375 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33376 index 94e7f6b..2f4a0d8 100644
33377 --- a/drivers/md/bitmap.c
33378 +++ b/drivers/md/bitmap.c
33379 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33380 chunk_kb ? "KB" : "B");
33381 if (bitmap->storage.file) {
33382 seq_printf(seq, ", file: ");
33383 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33384 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33385 }
33386
33387 seq_printf(seq, "\n");
33388 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33389 index afd9598..528d8f9 100644
33390 --- a/drivers/md/dm-ioctl.c
33391 +++ b/drivers/md/dm-ioctl.c
33392 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33393 cmd == DM_LIST_VERSIONS_CMD)
33394 return 0;
33395
33396 - if ((cmd == DM_DEV_CREATE_CMD)) {
33397 + if (cmd == DM_DEV_CREATE_CMD) {
33398 if (!*param->name) {
33399 DMWARN("name not supplied when creating device");
33400 return -EINVAL;
33401 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33402 index bc5ddba8..b961159 100644
33403 --- a/drivers/md/dm-raid1.c
33404 +++ b/drivers/md/dm-raid1.c
33405 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33406
33407 struct mirror {
33408 struct mirror_set *ms;
33409 - atomic_t error_count;
33410 + atomic_unchecked_t error_count;
33411 unsigned long error_type;
33412 struct dm_dev *dev;
33413 sector_t offset;
33414 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33415 struct mirror *m;
33416
33417 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33418 - if (!atomic_read(&m->error_count))
33419 + if (!atomic_read_unchecked(&m->error_count))
33420 return m;
33421
33422 return NULL;
33423 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33424 * simple way to tell if a device has encountered
33425 * errors.
33426 */
33427 - atomic_inc(&m->error_count);
33428 + atomic_inc_unchecked(&m->error_count);
33429
33430 if (test_and_set_bit(error_type, &m->error_type))
33431 return;
33432 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33433 struct mirror *m = get_default_mirror(ms);
33434
33435 do {
33436 - if (likely(!atomic_read(&m->error_count)))
33437 + if (likely(!atomic_read_unchecked(&m->error_count)))
33438 return m;
33439
33440 if (m-- == ms->mirror)
33441 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33442 {
33443 struct mirror *default_mirror = get_default_mirror(m->ms);
33444
33445 - return !atomic_read(&default_mirror->error_count);
33446 + return !atomic_read_unchecked(&default_mirror->error_count);
33447 }
33448
33449 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33450 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33451 */
33452 if (likely(region_in_sync(ms, region, 1)))
33453 m = choose_mirror(ms, bio->bi_sector);
33454 - else if (m && atomic_read(&m->error_count))
33455 + else if (m && atomic_read_unchecked(&m->error_count))
33456 m = NULL;
33457
33458 if (likely(m))
33459 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33460 }
33461
33462 ms->mirror[mirror].ms = ms;
33463 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33464 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33465 ms->mirror[mirror].error_type = 0;
33466 ms->mirror[mirror].offset = offset;
33467
33468 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33469 */
33470 static char device_status_char(struct mirror *m)
33471 {
33472 - if (!atomic_read(&(m->error_count)))
33473 + if (!atomic_read_unchecked(&(m->error_count)))
33474 return 'A';
33475
33476 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33477 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33478 index a087bf2..4c94786 100644
33479 --- a/drivers/md/dm-stripe.c
33480 +++ b/drivers/md/dm-stripe.c
33481 @@ -20,7 +20,7 @@ struct stripe {
33482 struct dm_dev *dev;
33483 sector_t physical_start;
33484
33485 - atomic_t error_count;
33486 + atomic_unchecked_t error_count;
33487 };
33488
33489 struct stripe_c {
33490 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33491 kfree(sc);
33492 return r;
33493 }
33494 - atomic_set(&(sc->stripe[i].error_count), 0);
33495 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33496 }
33497
33498 ti->private = sc;
33499 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33500 DMEMIT("%d ", sc->stripes);
33501 for (i = 0; i < sc->stripes; i++) {
33502 DMEMIT("%s ", sc->stripe[i].dev->name);
33503 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33504 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33505 'D' : 'A';
33506 }
33507 buffer[i] = '\0';
33508 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33509 */
33510 for (i = 0; i < sc->stripes; i++)
33511 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33512 - atomic_inc(&(sc->stripe[i].error_count));
33513 - if (atomic_read(&(sc->stripe[i].error_count)) <
33514 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33515 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33516 DM_IO_ERROR_THRESHOLD)
33517 schedule_work(&sc->trigger_event);
33518 }
33519 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33520 index 100368e..64262ce 100644
33521 --- a/drivers/md/dm-table.c
33522 +++ b/drivers/md/dm-table.c
33523 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33524 if (!dev_size)
33525 return 0;
33526
33527 - if ((start >= dev_size) || (start + len > dev_size)) {
33528 + if ((start >= dev_size) || (len > dev_size - start)) {
33529 DMWARN("%s: %s too small for target: "
33530 "start=%llu, len=%llu, dev_size=%llu",
33531 dm_device_name(ti->table->md), bdevname(bdev, b),
33532 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33533 index 693e149..b7e0fde 100644
33534 --- a/drivers/md/dm-thin-metadata.c
33535 +++ b/drivers/md/dm-thin-metadata.c
33536 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33537 {
33538 pmd->info.tm = pmd->tm;
33539 pmd->info.levels = 2;
33540 - pmd->info.value_type.context = pmd->data_sm;
33541 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33542 pmd->info.value_type.size = sizeof(__le64);
33543 pmd->info.value_type.inc = data_block_inc;
33544 pmd->info.value_type.dec = data_block_dec;
33545 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33546
33547 pmd->bl_info.tm = pmd->tm;
33548 pmd->bl_info.levels = 1;
33549 - pmd->bl_info.value_type.context = pmd->data_sm;
33550 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33551 pmd->bl_info.value_type.size = sizeof(__le64);
33552 pmd->bl_info.value_type.inc = data_block_inc;
33553 pmd->bl_info.value_type.dec = data_block_dec;
33554 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33555 index 67ffa39..cb3b1dd 100644
33556 --- a/drivers/md/dm.c
33557 +++ b/drivers/md/dm.c
33558 @@ -176,9 +176,9 @@ struct mapped_device {
33559 /*
33560 * Event handling.
33561 */
33562 - atomic_t event_nr;
33563 + atomic_unchecked_t event_nr;
33564 wait_queue_head_t eventq;
33565 - atomic_t uevent_seq;
33566 + atomic_unchecked_t uevent_seq;
33567 struct list_head uevent_list;
33568 spinlock_t uevent_lock; /* Protect access to uevent_list */
33569
33570 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33571 rwlock_init(&md->map_lock);
33572 atomic_set(&md->holders, 1);
33573 atomic_set(&md->open_count, 0);
33574 - atomic_set(&md->event_nr, 0);
33575 - atomic_set(&md->uevent_seq, 0);
33576 + atomic_set_unchecked(&md->event_nr, 0);
33577 + atomic_set_unchecked(&md->uevent_seq, 0);
33578 INIT_LIST_HEAD(&md->uevent_list);
33579 spin_lock_init(&md->uevent_lock);
33580
33581 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33582
33583 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33584
33585 - atomic_inc(&md->event_nr);
33586 + atomic_inc_unchecked(&md->event_nr);
33587 wake_up(&md->eventq);
33588 }
33589
33590 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33591
33592 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33593 {
33594 - return atomic_add_return(1, &md->uevent_seq);
33595 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33596 }
33597
33598 uint32_t dm_get_event_nr(struct mapped_device *md)
33599 {
33600 - return atomic_read(&md->event_nr);
33601 + return atomic_read_unchecked(&md->event_nr);
33602 }
33603
33604 int dm_wait_event(struct mapped_device *md, int event_nr)
33605 {
33606 return wait_event_interruptible(md->eventq,
33607 - (event_nr != atomic_read(&md->event_nr)));
33608 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33609 }
33610
33611 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33612 diff --git a/drivers/md/md.c b/drivers/md/md.c
33613 index 308e87b..7f365d6 100644
33614 --- a/drivers/md/md.c
33615 +++ b/drivers/md/md.c
33616 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33617 * start build, activate spare
33618 */
33619 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33620 -static atomic_t md_event_count;
33621 +static atomic_unchecked_t md_event_count;
33622 void md_new_event(struct mddev *mddev)
33623 {
33624 - atomic_inc(&md_event_count);
33625 + atomic_inc_unchecked(&md_event_count);
33626 wake_up(&md_event_waiters);
33627 }
33628 EXPORT_SYMBOL_GPL(md_new_event);
33629 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33630 */
33631 static void md_new_event_inintr(struct mddev *mddev)
33632 {
33633 - atomic_inc(&md_event_count);
33634 + atomic_inc_unchecked(&md_event_count);
33635 wake_up(&md_event_waiters);
33636 }
33637
33638 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33639 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33640 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33641 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33642 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33643 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33644
33645 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33646 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33647 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33648 else
33649 sb->resync_offset = cpu_to_le64(0);
33650
33651 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33652 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33653
33654 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33655 sb->size = cpu_to_le64(mddev->dev_sectors);
33656 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33657 static ssize_t
33658 errors_show(struct md_rdev *rdev, char *page)
33659 {
33660 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33661 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33662 }
33663
33664 static ssize_t
33665 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33666 char *e;
33667 unsigned long n = simple_strtoul(buf, &e, 10);
33668 if (*buf && (*e == 0 || *e == '\n')) {
33669 - atomic_set(&rdev->corrected_errors, n);
33670 + atomic_set_unchecked(&rdev->corrected_errors, n);
33671 return len;
33672 }
33673 return -EINVAL;
33674 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33675 rdev->sb_loaded = 0;
33676 rdev->bb_page = NULL;
33677 atomic_set(&rdev->nr_pending, 0);
33678 - atomic_set(&rdev->read_errors, 0);
33679 - atomic_set(&rdev->corrected_errors, 0);
33680 + atomic_set_unchecked(&rdev->read_errors, 0);
33681 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33682
33683 INIT_LIST_HEAD(&rdev->same_set);
33684 init_waitqueue_head(&rdev->blocked_wait);
33685 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33686
33687 spin_unlock(&pers_lock);
33688 seq_printf(seq, "\n");
33689 - seq->poll_event = atomic_read(&md_event_count);
33690 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33691 return 0;
33692 }
33693 if (v == (void*)2) {
33694 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33695 return error;
33696
33697 seq = file->private_data;
33698 - seq->poll_event = atomic_read(&md_event_count);
33699 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33700 return error;
33701 }
33702
33703 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33704 /* always allow read */
33705 mask = POLLIN | POLLRDNORM;
33706
33707 - if (seq->poll_event != atomic_read(&md_event_count))
33708 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33709 mask |= POLLERR | POLLPRI;
33710 return mask;
33711 }
33712 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33713 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33714 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33715 (int)part_stat_read(&disk->part0, sectors[1]) -
33716 - atomic_read(&disk->sync_io);
33717 + atomic_read_unchecked(&disk->sync_io);
33718 /* sync IO will cause sync_io to increase before the disk_stats
33719 * as sync_io is counted when a request starts, and
33720 * disk_stats is counted when it completes.
33721 diff --git a/drivers/md/md.h b/drivers/md/md.h
33722 index f385b03..b600be8 100644
33723 --- a/drivers/md/md.h
33724 +++ b/drivers/md/md.h
33725 @@ -94,13 +94,13 @@ struct md_rdev {
33726 * only maintained for arrays that
33727 * support hot removal
33728 */
33729 - atomic_t read_errors; /* number of consecutive read errors that
33730 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33731 * we have tried to ignore.
33732 */
33733 struct timespec last_read_error; /* monotonic time since our
33734 * last read error
33735 */
33736 - atomic_t corrected_errors; /* number of corrected read errors,
33737 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33738 * for reporting to userspace and storing
33739 * in superblock.
33740 */
33741 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33742
33743 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33744 {
33745 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33746 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33747 }
33748
33749 struct md_personality
33750 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33751 index f6d29e6..7917f5e 100644
33752 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33753 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33754 @@ -22,7 +22,7 @@
33755 * Space map interface.
33756 */
33757 struct sm_disk {
33758 - struct dm_space_map sm;
33759 + dm_space_map_no_const sm;
33760
33761 struct ll_disk ll;
33762 struct ll_disk old_ll;
33763 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33764 index e89ae5e..062e4c2 100644
33765 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33766 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33767 @@ -43,7 +43,7 @@ struct block_op {
33768 };
33769
33770 struct sm_metadata {
33771 - struct dm_space_map sm;
33772 + dm_space_map_no_const sm;
33773
33774 struct ll_disk ll;
33775 struct ll_disk old_ll;
33776 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33777 index 1cbfc6b..56e1dbb 100644
33778 --- a/drivers/md/persistent-data/dm-space-map.h
33779 +++ b/drivers/md/persistent-data/dm-space-map.h
33780 @@ -60,6 +60,7 @@ struct dm_space_map {
33781 int (*root_size)(struct dm_space_map *sm, size_t *result);
33782 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33783 };
33784 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33785
33786 /*----------------------------------------------------------------*/
33787
33788 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33789 index 611b5f7..cee0bfb 100644
33790 --- a/drivers/md/raid1.c
33791 +++ b/drivers/md/raid1.c
33792 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33793 if (r1_sync_page_io(rdev, sect, s,
33794 bio->bi_io_vec[idx].bv_page,
33795 READ) != 0)
33796 - atomic_add(s, &rdev->corrected_errors);
33797 + atomic_add_unchecked(s, &rdev->corrected_errors);
33798 }
33799 sectors -= s;
33800 sect += s;
33801 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33802 test_bit(In_sync, &rdev->flags)) {
33803 if (r1_sync_page_io(rdev, sect, s,
33804 conf->tmppage, READ)) {
33805 - atomic_add(s, &rdev->corrected_errors);
33806 + atomic_add_unchecked(s, &rdev->corrected_errors);
33807 printk(KERN_INFO
33808 "md/raid1:%s: read error corrected "
33809 "(%d sectors at %llu on %s)\n",
33810 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33811 index a48c215..6bda6f4 100644
33812 --- a/drivers/md/raid10.c
33813 +++ b/drivers/md/raid10.c
33814 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33815 /* The write handler will notice the lack of
33816 * R10BIO_Uptodate and record any errors etc
33817 */
33818 - atomic_add(r10_bio->sectors,
33819 + atomic_add_unchecked(r10_bio->sectors,
33820 &conf->mirrors[d].rdev->corrected_errors);
33821
33822 /* for reconstruct, we always reschedule after a read.
33823 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33824 {
33825 struct timespec cur_time_mon;
33826 unsigned long hours_since_last;
33827 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33828 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33829
33830 ktime_get_ts(&cur_time_mon);
33831
33832 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33833 * overflowing the shift of read_errors by hours_since_last.
33834 */
33835 if (hours_since_last >= 8 * sizeof(read_errors))
33836 - atomic_set(&rdev->read_errors, 0);
33837 + atomic_set_unchecked(&rdev->read_errors, 0);
33838 else
33839 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33840 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33841 }
33842
33843 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33844 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33845 return;
33846
33847 check_decay_read_errors(mddev, rdev);
33848 - atomic_inc(&rdev->read_errors);
33849 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33850 + atomic_inc_unchecked(&rdev->read_errors);
33851 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33852 char b[BDEVNAME_SIZE];
33853 bdevname(rdev->bdev, b);
33854
33855 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33856 "md/raid10:%s: %s: Raid device exceeded "
33857 "read_error threshold [cur %d:max %d]\n",
33858 mdname(mddev), b,
33859 - atomic_read(&rdev->read_errors), max_read_errors);
33860 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33861 printk(KERN_NOTICE
33862 "md/raid10:%s: %s: Failing raid device\n",
33863 mdname(mddev), b);
33864 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33865 sect +
33866 choose_data_offset(r10_bio, rdev)),
33867 bdevname(rdev->bdev, b));
33868 - atomic_add(s, &rdev->corrected_errors);
33869 + atomic_add_unchecked(s, &rdev->corrected_errors);
33870 }
33871
33872 rdev_dec_pending(rdev, mddev);
33873 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33874 index 0689173..35df76c 100644
33875 --- a/drivers/md/raid5.c
33876 +++ b/drivers/md/raid5.c
33877 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33878 mdname(conf->mddev), STRIPE_SECTORS,
33879 (unsigned long long)s,
33880 bdevname(rdev->bdev, b));
33881 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33882 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33883 clear_bit(R5_ReadError, &sh->dev[i].flags);
33884 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33885 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33886 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33887
33888 - if (atomic_read(&rdev->read_errors))
33889 - atomic_set(&rdev->read_errors, 0);
33890 + if (atomic_read_unchecked(&rdev->read_errors))
33891 + atomic_set_unchecked(&rdev->read_errors, 0);
33892 } else {
33893 const char *bdn = bdevname(rdev->bdev, b);
33894 int retry = 0;
33895 int set_bad = 0;
33896
33897 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33898 - atomic_inc(&rdev->read_errors);
33899 + atomic_inc_unchecked(&rdev->read_errors);
33900 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33901 printk_ratelimited(
33902 KERN_WARNING
33903 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33904 mdname(conf->mddev),
33905 (unsigned long long)s,
33906 bdn);
33907 - } else if (atomic_read(&rdev->read_errors)
33908 + } else if (atomic_read_unchecked(&rdev->read_errors)
33909 > conf->max_nr_stripes)
33910 printk(KERN_WARNING
33911 "md/raid:%s: Too many read errors, failing device %s.\n",
33912 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33913 index ebf3f05..b1f3e77 100644
33914 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33915 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33916 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33917 .subvendor = _subvend, .subdevice = _subdev, \
33918 .driver_data = (unsigned long)&_driverdata }
33919
33920 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33921 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33922 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33923 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33924 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33925 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33926 index fa7188a..04a045e 100644
33927 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33928 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33929 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33930 union {
33931 dmx_ts_cb ts;
33932 dmx_section_cb sec;
33933 - } cb;
33934 + } __no_const cb;
33935
33936 struct dvb_demux *demux;
33937 void *priv;
33938 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33939 index 39eab73..60033e7 100644
33940 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33941 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33942 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33943 const struct dvb_device *template, void *priv, int type)
33944 {
33945 struct dvb_device *dvbdev;
33946 - struct file_operations *dvbdevfops;
33947 + file_operations_no_const *dvbdevfops;
33948 struct device *clsdev;
33949 int minor;
33950 int id;
33951 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33952 index 3940bb0..fb3952a 100644
33953 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33954 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33955 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33956
33957 struct dib0700_adapter_state {
33958 int (*set_param_save) (struct dvb_frontend *);
33959 -};
33960 +} __no_const;
33961
33962 static int dib7070_set_param_override(struct dvb_frontend *fe)
33963 {
33964 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33965 index 9382895..ac8093c 100644
33966 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33967 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33968 @@ -95,7 +95,7 @@ struct su3000_state {
33969
33970 struct s6x0_state {
33971 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33972 -};
33973 +} __no_const;
33974
33975 /* debug */
33976 static int dvb_usb_dw2102_debug;
33977 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33978 index 404f63a..4796533 100644
33979 --- a/drivers/media/dvb/frontends/dib3000.h
33980 +++ b/drivers/media/dvb/frontends/dib3000.h
33981 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33982 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33983 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33984 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33985 -};
33986 +} __no_const;
33987
33988 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33989 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33990 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33991 index 72ee8de..eae0c80 100644
33992 --- a/drivers/media/dvb/ngene/ngene-cards.c
33993 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33994 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33995
33996 /****************************************************************************/
33997
33998 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33999 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34000 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34001 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34002 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34003 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34004 index 697a421..16c5a5f 100644
34005 --- a/drivers/media/radio/radio-cadet.c
34006 +++ b/drivers/media/radio/radio-cadet.c
34007 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34008 unsigned char readbuf[RDS_BUFFER];
34009 int i = 0;
34010
34011 + if (count > RDS_BUFFER)
34012 + return -EFAULT;
34013 mutex_lock(&dev->lock);
34014 if (dev->rdsstat == 0)
34015 cadet_start_rds(dev);
34016 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34017 while (i < count && dev->rdsin != dev->rdsout)
34018 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34019
34020 - if (i && copy_to_user(data, readbuf, i))
34021 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34022 i = -EFAULT;
34023 unlock:
34024 mutex_unlock(&dev->lock);
34025 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34026 index 55cbd78..428b0da 100644
34027 --- a/drivers/media/radio/radio-tea5777.h
34028 +++ b/drivers/media/radio/radio-tea5777.h
34029 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34030
34031 struct radio_tea5777 {
34032 struct v4l2_device *v4l2_dev;
34033 - struct v4l2_file_operations fops;
34034 + v4l2_file_operations_no_const fops;
34035 struct video_device vd; /* video device */
34036 bool has_am; /* Device can tune to AM freqs */
34037 bool write_before_read; /* must write before read quirk */
34038 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34039 index 9cde353..8c6a1c3 100644
34040 --- a/drivers/media/video/au0828/au0828.h
34041 +++ b/drivers/media/video/au0828/au0828.h
34042 @@ -191,7 +191,7 @@ struct au0828_dev {
34043
34044 /* I2C */
34045 struct i2c_adapter i2c_adap;
34046 - struct i2c_algorithm i2c_algo;
34047 + i2c_algorithm_no_const i2c_algo;
34048 struct i2c_client i2c_client;
34049 u32 i2c_rc;
34050
34051 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34052 index dfac6e3..c26de31 100644
34053 --- a/drivers/media/video/cx88/cx88-alsa.c
34054 +++ b/drivers/media/video/cx88/cx88-alsa.c
34055 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34056 * Only boards with eeprom and byte 1 at eeprom=1 have it
34057 */
34058
34059 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34060 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34061 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34062 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34063 {0, }
34064 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34065 index 88cf9d9..bbc4b2c 100644
34066 --- a/drivers/media/video/omap/omap_vout.c
34067 +++ b/drivers/media/video/omap/omap_vout.c
34068 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34069 OMAP_VIDEO2,
34070 };
34071
34072 -static struct videobuf_queue_ops video_vbq_ops;
34073 /* Variables configurable through module params*/
34074 static u32 video1_numbuffers = 3;
34075 static u32 video2_numbuffers = 3;
34076 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34077 {
34078 struct videobuf_queue *q;
34079 struct omap_vout_device *vout = NULL;
34080 + static struct videobuf_queue_ops video_vbq_ops = {
34081 + .buf_setup = omap_vout_buffer_setup,
34082 + .buf_prepare = omap_vout_buffer_prepare,
34083 + .buf_release = omap_vout_buffer_release,
34084 + .buf_queue = omap_vout_buffer_queue,
34085 + };
34086
34087 vout = video_drvdata(file);
34088 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34089 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34090 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34091
34092 q = &vout->vbq;
34093 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34094 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34095 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34096 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34097 spin_lock_init(&vout->vbq_lock);
34098
34099 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34100 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34101 index 036952f..80d356d 100644
34102 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34103 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34104 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34105
34106 /* I2C stuff */
34107 struct i2c_adapter i2c_adap;
34108 - struct i2c_algorithm i2c_algo;
34109 + i2c_algorithm_no_const i2c_algo;
34110 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34111 int i2c_cx25840_hack_state;
34112 int i2c_linked;
34113 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34114 index 02194c0..091733b 100644
34115 --- a/drivers/media/video/timblogiw.c
34116 +++ b/drivers/media/video/timblogiw.c
34117 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34118
34119 /* Platform device functions */
34120
34121 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34122 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34123 .vidioc_querycap = timblogiw_querycap,
34124 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34125 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34126 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34127 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34128 };
34129
34130 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34131 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34132 .owner = THIS_MODULE,
34133 .open = timblogiw_open,
34134 .release = timblogiw_close,
34135 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34136 index d99db56..a16b959 100644
34137 --- a/drivers/message/fusion/mptbase.c
34138 +++ b/drivers/message/fusion/mptbase.c
34139 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34140 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34141 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34142
34143 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34144 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34145 +#else
34146 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34147 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34148 +#endif
34149 +
34150 /*
34151 * Rounding UP to nearest 4-kB boundary here...
34152 */
34153 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34154 index 551262e..7551198 100644
34155 --- a/drivers/message/fusion/mptsas.c
34156 +++ b/drivers/message/fusion/mptsas.c
34157 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34158 return 0;
34159 }
34160
34161 +static inline void
34162 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34163 +{
34164 + if (phy_info->port_details) {
34165 + phy_info->port_details->rphy = rphy;
34166 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34167 + ioc->name, rphy));
34168 + }
34169 +
34170 + if (rphy) {
34171 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34172 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34173 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34174 + ioc->name, rphy, rphy->dev.release));
34175 + }
34176 +}
34177 +
34178 /* no mutex */
34179 static void
34180 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34181 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34182 return NULL;
34183 }
34184
34185 -static inline void
34186 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34187 -{
34188 - if (phy_info->port_details) {
34189 - phy_info->port_details->rphy = rphy;
34190 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34191 - ioc->name, rphy));
34192 - }
34193 -
34194 - if (rphy) {
34195 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34196 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34197 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34198 - ioc->name, rphy, rphy->dev.release));
34199 - }
34200 -}
34201 -
34202 static inline struct sas_port *
34203 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34204 {
34205 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34206 index 0c3ced7..1fe34ec 100644
34207 --- a/drivers/message/fusion/mptscsih.c
34208 +++ b/drivers/message/fusion/mptscsih.c
34209 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34210
34211 h = shost_priv(SChost);
34212
34213 - if (h) {
34214 - if (h->info_kbuf == NULL)
34215 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34216 - return h->info_kbuf;
34217 - h->info_kbuf[0] = '\0';
34218 + if (!h)
34219 + return NULL;
34220
34221 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34222 - h->info_kbuf[size-1] = '\0';
34223 - }
34224 + if (h->info_kbuf == NULL)
34225 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34226 + return h->info_kbuf;
34227 + h->info_kbuf[0] = '\0';
34228 +
34229 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34230 + h->info_kbuf[size-1] = '\0';
34231
34232 return h->info_kbuf;
34233 }
34234 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34235 index 8001aa6..b137580 100644
34236 --- a/drivers/message/i2o/i2o_proc.c
34237 +++ b/drivers/message/i2o/i2o_proc.c
34238 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34239 "Array Controller Device"
34240 };
34241
34242 -static char *chtostr(char *tmp, u8 *chars, int n)
34243 -{
34244 - tmp[0] = 0;
34245 - return strncat(tmp, (char *)chars, n);
34246 -}
34247 -
34248 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34249 char *group)
34250 {
34251 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34252 } *result;
34253
34254 i2o_exec_execute_ddm_table ddm_table;
34255 - char tmp[28 + 1];
34256
34257 result = kmalloc(sizeof(*result), GFP_KERNEL);
34258 if (!result)
34259 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34260
34261 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34262 seq_printf(seq, "%-#8x", ddm_table.module_id);
34263 - seq_printf(seq, "%-29s",
34264 - chtostr(tmp, ddm_table.module_name_version, 28));
34265 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34266 seq_printf(seq, "%9d ", ddm_table.data_size);
34267 seq_printf(seq, "%8d", ddm_table.code_size);
34268
34269 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34270
34271 i2o_driver_result_table *result;
34272 i2o_driver_store_table *dst;
34273 - char tmp[28 + 1];
34274
34275 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34276 if (result == NULL)
34277 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34278
34279 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34280 seq_printf(seq, "%-#8x", dst->module_id);
34281 - seq_printf(seq, "%-29s",
34282 - chtostr(tmp, dst->module_name_version, 28));
34283 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34284 + seq_printf(seq, "%-.28s", dst->module_name_version);
34285 + seq_printf(seq, "%-.8s", dst->date);
34286 seq_printf(seq, "%8d ", dst->module_size);
34287 seq_printf(seq, "%8d ", dst->mpb_size);
34288 seq_printf(seq, "0x%04x", dst->module_flags);
34289 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34290 // == (allow) 512d bytes (max)
34291 static u16 *work16 = (u16 *) work32;
34292 int token;
34293 - char tmp[16 + 1];
34294
34295 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34296
34297 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34298 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34299 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34300 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34301 - seq_printf(seq, "Vendor info : %s\n",
34302 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34303 - seq_printf(seq, "Product info : %s\n",
34304 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34305 - seq_printf(seq, "Description : %s\n",
34306 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34307 - seq_printf(seq, "Product rev. : %s\n",
34308 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34309 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34310 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34311 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34312 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34313
34314 seq_printf(seq, "Serial number : ");
34315 print_serial_number(seq, (u8 *) (work32 + 16),
34316 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34317 u8 pad[256]; // allow up to 256 byte (max) serial number
34318 } result;
34319
34320 - char tmp[24 + 1];
34321 -
34322 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34323
34324 if (token < 0) {
34325 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34326 }
34327
34328 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34329 - seq_printf(seq, "Module name : %s\n",
34330 - chtostr(tmp, result.module_name, 24));
34331 - seq_printf(seq, "Module revision : %s\n",
34332 - chtostr(tmp, result.module_rev, 8));
34333 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34334 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34335
34336 seq_printf(seq, "Serial number : ");
34337 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34338 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34339 u8 instance_number[4];
34340 } result;
34341
34342 - char tmp[64 + 1];
34343 -
34344 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34345
34346 if (token < 0) {
34347 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34348 return 0;
34349 }
34350
34351 - seq_printf(seq, "Device name : %s\n",
34352 - chtostr(tmp, result.device_name, 64));
34353 - seq_printf(seq, "Service name : %s\n",
34354 - chtostr(tmp, result.service_name, 64));
34355 - seq_printf(seq, "Physical name : %s\n",
34356 - chtostr(tmp, result.physical_location, 64));
34357 - seq_printf(seq, "Instance number : %s\n",
34358 - chtostr(tmp, result.instance_number, 4));
34359 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34360 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34361 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34362 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34363
34364 return 0;
34365 }
34366 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34367 index a8c08f3..155fe3d 100644
34368 --- a/drivers/message/i2o/iop.c
34369 +++ b/drivers/message/i2o/iop.c
34370 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34371
34372 spin_lock_irqsave(&c->context_list_lock, flags);
34373
34374 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34375 - atomic_inc(&c->context_list_counter);
34376 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34377 + atomic_inc_unchecked(&c->context_list_counter);
34378
34379 - entry->context = atomic_read(&c->context_list_counter);
34380 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34381
34382 list_add(&entry->list, &c->context_list);
34383
34384 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34385
34386 #if BITS_PER_LONG == 64
34387 spin_lock_init(&c->context_list_lock);
34388 - atomic_set(&c->context_list_counter, 0);
34389 + atomic_set_unchecked(&c->context_list_counter, 0);
34390 INIT_LIST_HEAD(&c->context_list);
34391 #endif
34392
34393 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34394 index 7ce65f4..e66e9bc 100644
34395 --- a/drivers/mfd/abx500-core.c
34396 +++ b/drivers/mfd/abx500-core.c
34397 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34398
34399 struct abx500_device_entry {
34400 struct list_head list;
34401 - struct abx500_ops ops;
34402 + abx500_ops_no_const ops;
34403 struct device *dev;
34404 };
34405
34406 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34407 index 965c480..71f2db9 100644
34408 --- a/drivers/mfd/janz-cmodio.c
34409 +++ b/drivers/mfd/janz-cmodio.c
34410 @@ -13,6 +13,7 @@
34411
34412 #include <linux/kernel.h>
34413 #include <linux/module.h>
34414 +#include <linux/slab.h>
34415 #include <linux/init.h>
34416 #include <linux/pci.h>
34417 #include <linux/interrupt.h>
34418 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34419 index a981e2a..5ca0c8b 100644
34420 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34421 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34422 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34423 * the lid is closed. This leads to interrupts as soon as a little move
34424 * is done.
34425 */
34426 - atomic_inc(&lis3->count);
34427 + atomic_inc_unchecked(&lis3->count);
34428
34429 wake_up_interruptible(&lis3->misc_wait);
34430 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34431 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34432 if (lis3->pm_dev)
34433 pm_runtime_get_sync(lis3->pm_dev);
34434
34435 - atomic_set(&lis3->count, 0);
34436 + atomic_set_unchecked(&lis3->count, 0);
34437 return 0;
34438 }
34439
34440 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34441 add_wait_queue(&lis3->misc_wait, &wait);
34442 while (true) {
34443 set_current_state(TASK_INTERRUPTIBLE);
34444 - data = atomic_xchg(&lis3->count, 0);
34445 + data = atomic_xchg_unchecked(&lis3->count, 0);
34446 if (data)
34447 break;
34448
34449 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34450 struct lis3lv02d, miscdev);
34451
34452 poll_wait(file, &lis3->misc_wait, wait);
34453 - if (atomic_read(&lis3->count))
34454 + if (atomic_read_unchecked(&lis3->count))
34455 return POLLIN | POLLRDNORM;
34456 return 0;
34457 }
34458 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34459 index 2b1482a..5d33616 100644
34460 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34461 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34462 @@ -266,7 +266,7 @@ struct lis3lv02d {
34463 struct input_polled_dev *idev; /* input device */
34464 struct platform_device *pdev; /* platform device */
34465 struct regulator_bulk_data regulators[2];
34466 - atomic_t count; /* interrupt count after last read */
34467 + atomic_unchecked_t count; /* interrupt count after last read */
34468 union axis_conversion ac; /* hw -> logical axis */
34469 int mapped_btns[3];
34470
34471 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34472 index 2f30bad..c4c13d0 100644
34473 --- a/drivers/misc/sgi-gru/gruhandles.c
34474 +++ b/drivers/misc/sgi-gru/gruhandles.c
34475 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34476 unsigned long nsec;
34477
34478 nsec = CLKS2NSEC(clks);
34479 - atomic_long_inc(&mcs_op_statistics[op].count);
34480 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34481 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34482 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34483 if (mcs_op_statistics[op].max < nsec)
34484 mcs_op_statistics[op].max = nsec;
34485 }
34486 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34487 index 950dbe9..eeef0f8 100644
34488 --- a/drivers/misc/sgi-gru/gruprocfs.c
34489 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34490 @@ -32,9 +32,9 @@
34491
34492 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34493
34494 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34495 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34496 {
34497 - unsigned long val = atomic_long_read(v);
34498 + unsigned long val = atomic_long_read_unchecked(v);
34499
34500 seq_printf(s, "%16lu %s\n", val, id);
34501 }
34502 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34503
34504 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34505 for (op = 0; op < mcsop_last; op++) {
34506 - count = atomic_long_read(&mcs_op_statistics[op].count);
34507 - total = atomic_long_read(&mcs_op_statistics[op].total);
34508 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34509 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34510 max = mcs_op_statistics[op].max;
34511 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34512 count ? total / count : 0, max);
34513 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34514 index 5c3ce24..4915ccb 100644
34515 --- a/drivers/misc/sgi-gru/grutables.h
34516 +++ b/drivers/misc/sgi-gru/grutables.h
34517 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34518 * GRU statistics.
34519 */
34520 struct gru_stats_s {
34521 - atomic_long_t vdata_alloc;
34522 - atomic_long_t vdata_free;
34523 - atomic_long_t gts_alloc;
34524 - atomic_long_t gts_free;
34525 - atomic_long_t gms_alloc;
34526 - atomic_long_t gms_free;
34527 - atomic_long_t gts_double_allocate;
34528 - atomic_long_t assign_context;
34529 - atomic_long_t assign_context_failed;
34530 - atomic_long_t free_context;
34531 - atomic_long_t load_user_context;
34532 - atomic_long_t load_kernel_context;
34533 - atomic_long_t lock_kernel_context;
34534 - atomic_long_t unlock_kernel_context;
34535 - atomic_long_t steal_user_context;
34536 - atomic_long_t steal_kernel_context;
34537 - atomic_long_t steal_context_failed;
34538 - atomic_long_t nopfn;
34539 - atomic_long_t asid_new;
34540 - atomic_long_t asid_next;
34541 - atomic_long_t asid_wrap;
34542 - atomic_long_t asid_reuse;
34543 - atomic_long_t intr;
34544 - atomic_long_t intr_cbr;
34545 - atomic_long_t intr_tfh;
34546 - atomic_long_t intr_spurious;
34547 - atomic_long_t intr_mm_lock_failed;
34548 - atomic_long_t call_os;
34549 - atomic_long_t call_os_wait_queue;
34550 - atomic_long_t user_flush_tlb;
34551 - atomic_long_t user_unload_context;
34552 - atomic_long_t user_exception;
34553 - atomic_long_t set_context_option;
34554 - atomic_long_t check_context_retarget_intr;
34555 - atomic_long_t check_context_unload;
34556 - atomic_long_t tlb_dropin;
34557 - atomic_long_t tlb_preload_page;
34558 - atomic_long_t tlb_dropin_fail_no_asid;
34559 - atomic_long_t tlb_dropin_fail_upm;
34560 - atomic_long_t tlb_dropin_fail_invalid;
34561 - atomic_long_t tlb_dropin_fail_range_active;
34562 - atomic_long_t tlb_dropin_fail_idle;
34563 - atomic_long_t tlb_dropin_fail_fmm;
34564 - atomic_long_t tlb_dropin_fail_no_exception;
34565 - atomic_long_t tfh_stale_on_fault;
34566 - atomic_long_t mmu_invalidate_range;
34567 - atomic_long_t mmu_invalidate_page;
34568 - atomic_long_t flush_tlb;
34569 - atomic_long_t flush_tlb_gru;
34570 - atomic_long_t flush_tlb_gru_tgh;
34571 - atomic_long_t flush_tlb_gru_zero_asid;
34572 + atomic_long_unchecked_t vdata_alloc;
34573 + atomic_long_unchecked_t vdata_free;
34574 + atomic_long_unchecked_t gts_alloc;
34575 + atomic_long_unchecked_t gts_free;
34576 + atomic_long_unchecked_t gms_alloc;
34577 + atomic_long_unchecked_t gms_free;
34578 + atomic_long_unchecked_t gts_double_allocate;
34579 + atomic_long_unchecked_t assign_context;
34580 + atomic_long_unchecked_t assign_context_failed;
34581 + atomic_long_unchecked_t free_context;
34582 + atomic_long_unchecked_t load_user_context;
34583 + atomic_long_unchecked_t load_kernel_context;
34584 + atomic_long_unchecked_t lock_kernel_context;
34585 + atomic_long_unchecked_t unlock_kernel_context;
34586 + atomic_long_unchecked_t steal_user_context;
34587 + atomic_long_unchecked_t steal_kernel_context;
34588 + atomic_long_unchecked_t steal_context_failed;
34589 + atomic_long_unchecked_t nopfn;
34590 + atomic_long_unchecked_t asid_new;
34591 + atomic_long_unchecked_t asid_next;
34592 + atomic_long_unchecked_t asid_wrap;
34593 + atomic_long_unchecked_t asid_reuse;
34594 + atomic_long_unchecked_t intr;
34595 + atomic_long_unchecked_t intr_cbr;
34596 + atomic_long_unchecked_t intr_tfh;
34597 + atomic_long_unchecked_t intr_spurious;
34598 + atomic_long_unchecked_t intr_mm_lock_failed;
34599 + atomic_long_unchecked_t call_os;
34600 + atomic_long_unchecked_t call_os_wait_queue;
34601 + atomic_long_unchecked_t user_flush_tlb;
34602 + atomic_long_unchecked_t user_unload_context;
34603 + atomic_long_unchecked_t user_exception;
34604 + atomic_long_unchecked_t set_context_option;
34605 + atomic_long_unchecked_t check_context_retarget_intr;
34606 + atomic_long_unchecked_t check_context_unload;
34607 + atomic_long_unchecked_t tlb_dropin;
34608 + atomic_long_unchecked_t tlb_preload_page;
34609 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34610 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34611 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34612 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34613 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34614 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34615 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34616 + atomic_long_unchecked_t tfh_stale_on_fault;
34617 + atomic_long_unchecked_t mmu_invalidate_range;
34618 + atomic_long_unchecked_t mmu_invalidate_page;
34619 + atomic_long_unchecked_t flush_tlb;
34620 + atomic_long_unchecked_t flush_tlb_gru;
34621 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34622 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34623
34624 - atomic_long_t copy_gpa;
34625 - atomic_long_t read_gpa;
34626 + atomic_long_unchecked_t copy_gpa;
34627 + atomic_long_unchecked_t read_gpa;
34628
34629 - atomic_long_t mesq_receive;
34630 - atomic_long_t mesq_receive_none;
34631 - atomic_long_t mesq_send;
34632 - atomic_long_t mesq_send_failed;
34633 - atomic_long_t mesq_noop;
34634 - atomic_long_t mesq_send_unexpected_error;
34635 - atomic_long_t mesq_send_lb_overflow;
34636 - atomic_long_t mesq_send_qlimit_reached;
34637 - atomic_long_t mesq_send_amo_nacked;
34638 - atomic_long_t mesq_send_put_nacked;
34639 - atomic_long_t mesq_page_overflow;
34640 - atomic_long_t mesq_qf_locked;
34641 - atomic_long_t mesq_qf_noop_not_full;
34642 - atomic_long_t mesq_qf_switch_head_failed;
34643 - atomic_long_t mesq_qf_unexpected_error;
34644 - atomic_long_t mesq_noop_unexpected_error;
34645 - atomic_long_t mesq_noop_lb_overflow;
34646 - atomic_long_t mesq_noop_qlimit_reached;
34647 - atomic_long_t mesq_noop_amo_nacked;
34648 - atomic_long_t mesq_noop_put_nacked;
34649 - atomic_long_t mesq_noop_page_overflow;
34650 + atomic_long_unchecked_t mesq_receive;
34651 + atomic_long_unchecked_t mesq_receive_none;
34652 + atomic_long_unchecked_t mesq_send;
34653 + atomic_long_unchecked_t mesq_send_failed;
34654 + atomic_long_unchecked_t mesq_noop;
34655 + atomic_long_unchecked_t mesq_send_unexpected_error;
34656 + atomic_long_unchecked_t mesq_send_lb_overflow;
34657 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34658 + atomic_long_unchecked_t mesq_send_amo_nacked;
34659 + atomic_long_unchecked_t mesq_send_put_nacked;
34660 + atomic_long_unchecked_t mesq_page_overflow;
34661 + atomic_long_unchecked_t mesq_qf_locked;
34662 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34663 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34664 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34665 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34666 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34667 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34668 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34669 + atomic_long_unchecked_t mesq_noop_put_nacked;
34670 + atomic_long_unchecked_t mesq_noop_page_overflow;
34671
34672 };
34673
34674 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34675 tghop_invalidate, mcsop_last};
34676
34677 struct mcs_op_statistic {
34678 - atomic_long_t count;
34679 - atomic_long_t total;
34680 + atomic_long_unchecked_t count;
34681 + atomic_long_unchecked_t total;
34682 unsigned long max;
34683 };
34684
34685 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34686
34687 #define STAT(id) do { \
34688 if (gru_options & OPT_STATS) \
34689 - atomic_long_inc(&gru_stats.id); \
34690 + atomic_long_inc_unchecked(&gru_stats.id); \
34691 } while (0)
34692
34693 #ifdef CONFIG_SGI_GRU_DEBUG
34694 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34695 index c862cd4..0d176fe 100644
34696 --- a/drivers/misc/sgi-xp/xp.h
34697 +++ b/drivers/misc/sgi-xp/xp.h
34698 @@ -288,7 +288,7 @@ struct xpc_interface {
34699 xpc_notify_func, void *);
34700 void (*received) (short, int, void *);
34701 enum xp_retval (*partid_to_nasids) (short, void *);
34702 -};
34703 +} __no_const;
34704
34705 extern struct xpc_interface xpc_interface;
34706
34707 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34708 index b94d5f7..7f494c5 100644
34709 --- a/drivers/misc/sgi-xp/xpc.h
34710 +++ b/drivers/misc/sgi-xp/xpc.h
34711 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34712 void (*received_payload) (struct xpc_channel *, void *);
34713 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34714 };
34715 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34716
34717 /* struct xpc_partition act_state values (for XPC HB) */
34718
34719 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34720 /* found in xpc_main.c */
34721 extern struct device *xpc_part;
34722 extern struct device *xpc_chan;
34723 -extern struct xpc_arch_operations xpc_arch_ops;
34724 +extern xpc_arch_operations_no_const xpc_arch_ops;
34725 extern int xpc_disengage_timelimit;
34726 extern int xpc_disengage_timedout;
34727 extern int xpc_activate_IRQ_rcvd;
34728 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34729 index 8d082b4..aa749ae 100644
34730 --- a/drivers/misc/sgi-xp/xpc_main.c
34731 +++ b/drivers/misc/sgi-xp/xpc_main.c
34732 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34733 .notifier_call = xpc_system_die,
34734 };
34735
34736 -struct xpc_arch_operations xpc_arch_ops;
34737 +xpc_arch_operations_no_const xpc_arch_ops;
34738
34739 /*
34740 * Timer function to enforce the timelimit on the partition disengage.
34741 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34742 index 504da71..9722d43 100644
34743 --- a/drivers/mmc/host/sdhci-pci.c
34744 +++ b/drivers/mmc/host/sdhci-pci.c
34745 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34746 .probe = via_probe,
34747 };
34748
34749 -static const struct pci_device_id pci_ids[] __devinitdata = {
34750 +static const struct pci_device_id pci_ids[] __devinitconst = {
34751 {
34752 .vendor = PCI_VENDOR_ID_RICOH,
34753 .device = PCI_DEVICE_ID_RICOH_R5C822,
34754 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34755 index a4eb8b5..8c0628f 100644
34756 --- a/drivers/mtd/devices/doc2000.c
34757 +++ b/drivers/mtd/devices/doc2000.c
34758 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34759
34760 /* The ECC will not be calculated correctly if less than 512 is written */
34761 /* DBB-
34762 - if (len != 0x200 && eccbuf)
34763 + if (len != 0x200)
34764 printk(KERN_WARNING
34765 "ECC needs a full sector write (adr: %lx size %lx)\n",
34766 (long) to, (long) len);
34767 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34768 index 0650aaf..7718762 100644
34769 --- a/drivers/mtd/nand/denali.c
34770 +++ b/drivers/mtd/nand/denali.c
34771 @@ -26,6 +26,7 @@
34772 #include <linux/pci.h>
34773 #include <linux/mtd/mtd.h>
34774 #include <linux/module.h>
34775 +#include <linux/slab.h>
34776
34777 #include "denali.h"
34778
34779 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34780 index 51b9d6a..52af9a7 100644
34781 --- a/drivers/mtd/nftlmount.c
34782 +++ b/drivers/mtd/nftlmount.c
34783 @@ -24,6 +24,7 @@
34784 #include <asm/errno.h>
34785 #include <linux/delay.h>
34786 #include <linux/slab.h>
34787 +#include <linux/sched.h>
34788 #include <linux/mtd/mtd.h>
34789 #include <linux/mtd/nand.h>
34790 #include <linux/mtd/nftl.h>
34791 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34792 index 57d64b8..623dd86 100644
34793 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34794 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34795 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34796 */
34797
34798 #define ATL2_PARAM(X, desc) \
34799 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34800 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34801 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34802 MODULE_PARM_DESC(X, desc);
34803 #else
34804 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34805 index f83e033..8b4f43a 100644
34806 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34807 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34808 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34809
34810 int (*wait_comp)(struct bnx2x *bp,
34811 struct bnx2x_rx_mode_ramrod_params *p);
34812 -};
34813 +} __no_const;
34814
34815 /********************** Set multicast group ***********************************/
34816
34817 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34818 index 6d52cb2..bc95640 100644
34819 --- a/drivers/net/ethernet/broadcom/tg3.h
34820 +++ b/drivers/net/ethernet/broadcom/tg3.h
34821 @@ -140,6 +140,7 @@
34822 #define CHIPREV_ID_5750_A0 0x4000
34823 #define CHIPREV_ID_5750_A1 0x4001
34824 #define CHIPREV_ID_5750_A3 0x4003
34825 +#define CHIPREV_ID_5750_C1 0x4201
34826 #define CHIPREV_ID_5750_C2 0x4202
34827 #define CHIPREV_ID_5752_A0_HW 0x5000
34828 #define CHIPREV_ID_5752_A0 0x6000
34829 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34830 index 8cffcdf..aadf043 100644
34831 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34832 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34833 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34834 */
34835 struct l2t_skb_cb {
34836 arp_failure_handler_func arp_failure_handler;
34837 -};
34838 +} __no_const;
34839
34840 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34841
34842 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34843 index f879e92..726f20f 100644
34844 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34845 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34846 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34847 for (i=0; i<ETH_ALEN; i++) {
34848 tmp.addr[i] = dev->dev_addr[i];
34849 }
34850 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34851 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34852 break;
34853
34854 case DE4X5_SET_HWADDR: /* Set the hardware address */
34855 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34856 spin_lock_irqsave(&lp->lock, flags);
34857 memcpy(&statbuf, &lp->pktStats, ioc->len);
34858 spin_unlock_irqrestore(&lp->lock, flags);
34859 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34860 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34861 return -EFAULT;
34862 break;
34863 }
34864 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34865 index ed7d1dc..d426748 100644
34866 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34867 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34868 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34869 {NULL}};
34870
34871
34872 -static const char *block_name[] __devinitdata = {
34873 +static const char *block_name[] __devinitconst = {
34874 "21140 non-MII",
34875 "21140 MII PHY",
34876 "21142 Serial PHY",
34877 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34878 index 75d45f8..3d9c55b 100644
34879 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34880 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34881 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34882 struct uli_phy_ops {
34883 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34884 u16 (*read)(struct uli526x_board_info *, u8, u8);
34885 - } phy;
34886 + } __no_const phy;
34887 struct net_device *next_dev; /* next device */
34888 struct pci_dev *pdev; /* PCI device */
34889 spinlock_t lock;
34890 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34891 index 4d1ffca..7c1ec4d 100644
34892 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34893 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34894 @@ -236,7 +236,7 @@ struct pci_id_info {
34895 int drv_flags; /* Driver use, intended as capability flags. */
34896 };
34897
34898 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34899 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34900 { /* Sometime a Level-One switch card. */
34901 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34902 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34903 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34904 index d7bb52a..3b83588 100644
34905 --- a/drivers/net/ethernet/dlink/sundance.c
34906 +++ b/drivers/net/ethernet/dlink/sundance.c
34907 @@ -218,7 +218,7 @@ enum {
34908 struct pci_id_info {
34909 const char *name;
34910 };
34911 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34912 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34913 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34914 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34915 {"D-Link DFE-580TX 4 port Server Adapter"},
34916 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34917 index 78b8aa8..dd6323a 100644
34918 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34919 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34920 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34921
34922 if (wrapped)
34923 newacc += 65536;
34924 - ACCESS_ONCE(*acc) = newacc;
34925 + ACCESS_ONCE_RW(*acc) = newacc;
34926 }
34927
34928 void be_parse_stats(struct be_adapter *adapter)
34929 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34930 index 74d749e..eefb1bd 100644
34931 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34932 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34933 @@ -31,6 +31,8 @@
34934 #include <linux/netdevice.h>
34935 #include <linux/phy.h>
34936 #include <linux/platform_device.h>
34937 +#include <linux/interrupt.h>
34938 +#include <linux/irqreturn.h>
34939 #include <net/ip.h>
34940
34941 #include "ftgmac100.h"
34942 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34943 index b901a01..1ff32ee 100644
34944 --- a/drivers/net/ethernet/faraday/ftmac100.c
34945 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34946 @@ -31,6 +31,8 @@
34947 #include <linux/module.h>
34948 #include <linux/netdevice.h>
34949 #include <linux/platform_device.h>
34950 +#include <linux/interrupt.h>
34951 +#include <linux/irqreturn.h>
34952
34953 #include "ftmac100.h"
34954
34955 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34956 index 9d71c9c..0e4a0ac 100644
34957 --- a/drivers/net/ethernet/fealnx.c
34958 +++ b/drivers/net/ethernet/fealnx.c
34959 @@ -150,7 +150,7 @@ struct chip_info {
34960 int flags;
34961 };
34962
34963 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34964 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34965 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34966 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34967 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34968 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34969 index ed5b409..ec37828 100644
34970 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34971 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34972 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34973 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34974 s32 (*read_mac_addr)(struct e1000_hw *);
34975 };
34976 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34977
34978 /*
34979 * When to use various PHY register access functions:
34980 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34981 void (*power_up)(struct e1000_hw *);
34982 void (*power_down)(struct e1000_hw *);
34983 };
34984 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34985
34986 /* Function pointers for the NVM. */
34987 struct e1000_nvm_operations {
34988 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34989 s32 (*validate)(struct e1000_hw *);
34990 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34991 };
34992 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34993
34994 struct e1000_mac_info {
34995 - struct e1000_mac_operations ops;
34996 + e1000_mac_operations_no_const ops;
34997 u8 addr[ETH_ALEN];
34998 u8 perm_addr[ETH_ALEN];
34999
35000 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35001 };
35002
35003 struct e1000_phy_info {
35004 - struct e1000_phy_operations ops;
35005 + e1000_phy_operations_no_const ops;
35006
35007 enum e1000_phy_type type;
35008
35009 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35010 };
35011
35012 struct e1000_nvm_info {
35013 - struct e1000_nvm_operations ops;
35014 + e1000_nvm_operations_no_const ops;
35015
35016 enum e1000_nvm_type type;
35017 enum e1000_nvm_override override;
35018 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35019 index c2a51dc..c2bd262 100644
35020 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35021 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35022 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35023 void (*release_swfw_sync)(struct e1000_hw *, u16);
35024
35025 };
35026 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35027
35028 struct e1000_phy_operations {
35029 s32 (*acquire)(struct e1000_hw *);
35030 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35031 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35032 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35033 };
35034 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35035
35036 struct e1000_nvm_operations {
35037 s32 (*acquire)(struct e1000_hw *);
35038 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35039 s32 (*validate)(struct e1000_hw *);
35040 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35041 };
35042 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35043
35044 struct e1000_info {
35045 s32 (*get_invariants)(struct e1000_hw *);
35046 @@ -364,7 +367,7 @@ struct e1000_info {
35047 extern const struct e1000_info e1000_82575_info;
35048
35049 struct e1000_mac_info {
35050 - struct e1000_mac_operations ops;
35051 + e1000_mac_operations_no_const ops;
35052
35053 u8 addr[6];
35054 u8 perm_addr[6];
35055 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35056 };
35057
35058 struct e1000_phy_info {
35059 - struct e1000_phy_operations ops;
35060 + e1000_phy_operations_no_const ops;
35061
35062 enum e1000_phy_type type;
35063
35064 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35065 };
35066
35067 struct e1000_nvm_info {
35068 - struct e1000_nvm_operations ops;
35069 + e1000_nvm_operations_no_const ops;
35070 enum e1000_nvm_type type;
35071 enum e1000_nvm_override override;
35072
35073 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35074 s32 (*check_for_ack)(struct e1000_hw *, u16);
35075 s32 (*check_for_rst)(struct e1000_hw *, u16);
35076 };
35077 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35078
35079 struct e1000_mbx_stats {
35080 u32 msgs_tx;
35081 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35082 };
35083
35084 struct e1000_mbx_info {
35085 - struct e1000_mbx_operations ops;
35086 + e1000_mbx_operations_no_const ops;
35087 struct e1000_mbx_stats stats;
35088 u32 timeout;
35089 u32 usec_delay;
35090 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35091 index 57db3c6..aa825fc 100644
35092 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35093 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35094 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35095 s32 (*read_mac_addr)(struct e1000_hw *);
35096 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35097 };
35098 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35099
35100 struct e1000_mac_info {
35101 - struct e1000_mac_operations ops;
35102 + e1000_mac_operations_no_const ops;
35103 u8 addr[6];
35104 u8 perm_addr[6];
35105
35106 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35107 s32 (*check_for_ack)(struct e1000_hw *);
35108 s32 (*check_for_rst)(struct e1000_hw *);
35109 };
35110 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35111
35112 struct e1000_mbx_stats {
35113 u32 msgs_tx;
35114 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35115 };
35116
35117 struct e1000_mbx_info {
35118 - struct e1000_mbx_operations ops;
35119 + e1000_mbx_operations_no_const ops;
35120 struct e1000_mbx_stats stats;
35121 u32 timeout;
35122 u32 usec_delay;
35123 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35124 index 3456d56..b688d81 100644
35125 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35126 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35127 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35128 /* store the new cycle speed */
35129 adapter->cycle_speed = cycle_speed;
35130
35131 - ACCESS_ONCE(adapter->base_incval) = incval;
35132 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35133 smp_mb();
35134
35135 /* grab the ptp lock */
35136 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35137 index 400f86a..7f2e062 100644
35138 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35139 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35140 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35141 s32 (*update_checksum)(struct ixgbe_hw *);
35142 u16 (*calc_checksum)(struct ixgbe_hw *);
35143 };
35144 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35145
35146 struct ixgbe_mac_operations {
35147 s32 (*init_hw)(struct ixgbe_hw *);
35148 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35149 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35150 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35151 };
35152 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35153
35154 struct ixgbe_phy_operations {
35155 s32 (*identify)(struct ixgbe_hw *);
35156 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35157 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35158 s32 (*check_overtemp)(struct ixgbe_hw *);
35159 };
35160 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35161
35162 struct ixgbe_eeprom_info {
35163 - struct ixgbe_eeprom_operations ops;
35164 + ixgbe_eeprom_operations_no_const ops;
35165 enum ixgbe_eeprom_type type;
35166 u32 semaphore_delay;
35167 u16 word_size;
35168 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35169
35170 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35171 struct ixgbe_mac_info {
35172 - struct ixgbe_mac_operations ops;
35173 + ixgbe_mac_operations_no_const ops;
35174 enum ixgbe_mac_type type;
35175 u8 addr[ETH_ALEN];
35176 u8 perm_addr[ETH_ALEN];
35177 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35178 };
35179
35180 struct ixgbe_phy_info {
35181 - struct ixgbe_phy_operations ops;
35182 + ixgbe_phy_operations_no_const ops;
35183 struct mdio_if_info mdio;
35184 enum ixgbe_phy_type type;
35185 u32 id;
35186 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35187 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35188 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35189 };
35190 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35191
35192 struct ixgbe_mbx_stats {
35193 u32 msgs_tx;
35194 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35195 };
35196
35197 struct ixgbe_mbx_info {
35198 - struct ixgbe_mbx_operations ops;
35199 + ixgbe_mbx_operations_no_const ops;
35200 struct ixgbe_mbx_stats stats;
35201 u32 timeout;
35202 u32 usec_delay;
35203 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35204 index 25c951d..cc7cf33 100644
35205 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35206 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35207 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35208 s32 (*clear_vfta)(struct ixgbe_hw *);
35209 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35210 };
35211 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35212
35213 enum ixgbe_mac_type {
35214 ixgbe_mac_unknown = 0,
35215 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35216 };
35217
35218 struct ixgbe_mac_info {
35219 - struct ixgbe_mac_operations ops;
35220 + ixgbe_mac_operations_no_const ops;
35221 u8 addr[6];
35222 u8 perm_addr[6];
35223
35224 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35225 s32 (*check_for_ack)(struct ixgbe_hw *);
35226 s32 (*check_for_rst)(struct ixgbe_hw *);
35227 };
35228 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35229
35230 struct ixgbe_mbx_stats {
35231 u32 msgs_tx;
35232 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35233 };
35234
35235 struct ixgbe_mbx_info {
35236 - struct ixgbe_mbx_operations ops;
35237 + ixgbe_mbx_operations_no_const ops;
35238 struct ixgbe_mbx_stats stats;
35239 u32 timeout;
35240 u32 udelay;
35241 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35242 index 9e0c1ee..8471f77 100644
35243 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35244 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35245 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35246 void (*link_down)(struct __vxge_hw_device *devh);
35247 void (*crit_err)(struct __vxge_hw_device *devh,
35248 enum vxge_hw_event type, u64 ext_data);
35249 -};
35250 +} __no_const;
35251
35252 /*
35253 * struct __vxge_hw_blockpool_entry - Block private data structure
35254 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35255 index 4a518a3..936b334 100644
35256 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35257 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35258 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35259 struct vxge_hw_mempool_dma *dma_object,
35260 u32 index,
35261 u32 is_last);
35262 -};
35263 +} __no_const;
35264
35265 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35266 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35267 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35268 index b47d5b3..273a516 100644
35269 --- a/drivers/net/ethernet/realtek/r8169.c
35270 +++ b/drivers/net/ethernet/realtek/r8169.c
35271 @@ -745,22 +745,22 @@ struct rtl8169_private {
35272 struct mdio_ops {
35273 void (*write)(struct rtl8169_private *, int, int);
35274 int (*read)(struct rtl8169_private *, int);
35275 - } mdio_ops;
35276 + } __no_const mdio_ops;
35277
35278 struct pll_power_ops {
35279 void (*down)(struct rtl8169_private *);
35280 void (*up)(struct rtl8169_private *);
35281 - } pll_power_ops;
35282 + } __no_const pll_power_ops;
35283
35284 struct jumbo_ops {
35285 void (*enable)(struct rtl8169_private *);
35286 void (*disable)(struct rtl8169_private *);
35287 - } jumbo_ops;
35288 + } __no_const jumbo_ops;
35289
35290 struct csi_ops {
35291 void (*write)(struct rtl8169_private *, int, int);
35292 u32 (*read)(struct rtl8169_private *, int);
35293 - } csi_ops;
35294 + } __no_const csi_ops;
35295
35296 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35297 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35298 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35299 index 4613591..d816601 100644
35300 --- a/drivers/net/ethernet/sis/sis190.c
35301 +++ b/drivers/net/ethernet/sis/sis190.c
35302 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35303 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35304 struct net_device *dev)
35305 {
35306 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35307 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35308 struct sis190_private *tp = netdev_priv(dev);
35309 struct pci_dev *isa_bridge;
35310 u8 reg, tmp8;
35311 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35312 index 0c74a70..3bc6f68 100644
35313 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35314 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35315 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35316
35317 writel(value, ioaddr + MMC_CNTRL);
35318
35319 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35320 - MMC_CNTRL, value);
35321 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35322 +// MMC_CNTRL, value);
35323 }
35324
35325 /* To mask all all interrupts.*/
35326 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35327 index 95ceb35..318fc12 100644
35328 --- a/drivers/net/hyperv/hyperv_net.h
35329 +++ b/drivers/net/hyperv/hyperv_net.h
35330 @@ -99,7 +99,7 @@ struct rndis_device {
35331
35332 enum rndis_device_state state;
35333 bool link_state;
35334 - atomic_t new_req_id;
35335 + atomic_unchecked_t new_req_id;
35336
35337 spinlock_t request_lock;
35338 struct list_head req_list;
35339 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35340 index 1e88a10..1b01736 100644
35341 --- a/drivers/net/hyperv/rndis_filter.c
35342 +++ b/drivers/net/hyperv/rndis_filter.c
35343 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35344 * template
35345 */
35346 set = &rndis_msg->msg.set_req;
35347 - set->req_id = atomic_inc_return(&dev->new_req_id);
35348 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35349
35350 /* Add to the request list */
35351 spin_lock_irqsave(&dev->request_lock, flags);
35352 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35353
35354 /* Setup the rndis set */
35355 halt = &request->request_msg.msg.halt_req;
35356 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35357 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35358
35359 /* Ignore return since this msg is optional. */
35360 rndis_filter_send_request(dev, request);
35361 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35362 index 5c05572..389610b 100644
35363 --- a/drivers/net/ppp/ppp_generic.c
35364 +++ b/drivers/net/ppp/ppp_generic.c
35365 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35366 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35367 struct ppp_stats stats;
35368 struct ppp_comp_stats cstats;
35369 - char *vers;
35370
35371 switch (cmd) {
35372 case SIOCGPPPSTATS:
35373 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35374 break;
35375
35376 case SIOCGPPPVER:
35377 - vers = PPP_VERSION;
35378 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35379 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35380 break;
35381 err = 0;
35382 break;
35383 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35384 index 3a16d4f..a311cec 100644
35385 --- a/drivers/net/tun.c
35386 +++ b/drivers/net/tun.c
35387 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35388 }
35389
35390 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35391 - unsigned long arg, int ifreq_len)
35392 + unsigned long arg, size_t ifreq_len)
35393 {
35394 struct tun_file *tfile = file->private_data;
35395 struct tun_struct *tun;
35396 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35397 int vnet_hdr_sz;
35398 int ret;
35399
35400 + if (ifreq_len > sizeof ifr)
35401 + return -EFAULT;
35402 +
35403 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35404 if (copy_from_user(&ifr, argp, ifreq_len))
35405 return -EFAULT;
35406 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35407 index 62f30b4..ff99dfd 100644
35408 --- a/drivers/net/usb/hso.c
35409 +++ b/drivers/net/usb/hso.c
35410 @@ -71,7 +71,7 @@
35411 #include <asm/byteorder.h>
35412 #include <linux/serial_core.h>
35413 #include <linux/serial.h>
35414 -
35415 +#include <asm/local.h>
35416
35417 #define MOD_AUTHOR "Option Wireless"
35418 #define MOD_DESCRIPTION "USB High Speed Option driver"
35419 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35420 struct urb *urb;
35421
35422 urb = serial->rx_urb[0];
35423 - if (serial->port.count > 0) {
35424 + if (atomic_read(&serial->port.count) > 0) {
35425 count = put_rxbuf_data(urb, serial);
35426 if (count == -1)
35427 return;
35428 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35429 DUMP1(urb->transfer_buffer, urb->actual_length);
35430
35431 /* Anyone listening? */
35432 - if (serial->port.count == 0)
35433 + if (atomic_read(&serial->port.count) == 0)
35434 return;
35435
35436 if (status == 0) {
35437 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35438 tty_port_tty_set(&serial->port, tty);
35439
35440 /* check for port already opened, if not set the termios */
35441 - serial->port.count++;
35442 - if (serial->port.count == 1) {
35443 + if (atomic_inc_return(&serial->port.count) == 1) {
35444 serial->rx_state = RX_IDLE;
35445 /* Force default termio settings */
35446 _hso_serial_set_termios(tty, NULL);
35447 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35448 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35449 if (result) {
35450 hso_stop_serial_device(serial->parent);
35451 - serial->port.count--;
35452 + atomic_dec(&serial->port.count);
35453 kref_put(&serial->parent->ref, hso_serial_ref_free);
35454 }
35455 } else {
35456 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35457
35458 /* reset the rts and dtr */
35459 /* do the actual close */
35460 - serial->port.count--;
35461 + atomic_dec(&serial->port.count);
35462
35463 - if (serial->port.count <= 0) {
35464 - serial->port.count = 0;
35465 + if (atomic_read(&serial->port.count) <= 0) {
35466 + atomic_set(&serial->port.count, 0);
35467 tty_port_tty_set(&serial->port, NULL);
35468 if (!usb_gone)
35469 hso_stop_serial_device(serial->parent);
35470 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35471
35472 /* the actual setup */
35473 spin_lock_irqsave(&serial->serial_lock, flags);
35474 - if (serial->port.count)
35475 + if (atomic_read(&serial->port.count))
35476 _hso_serial_set_termios(tty, old);
35477 else
35478 tty->termios = old;
35479 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35480 D1("Pending read interrupt on port %d\n", i);
35481 spin_lock(&serial->serial_lock);
35482 if (serial->rx_state == RX_IDLE &&
35483 - serial->port.count > 0) {
35484 + atomic_read(&serial->port.count) > 0) {
35485 /* Setup and send a ctrl req read on
35486 * port i */
35487 if (!serial->rx_urb_filled[0]) {
35488 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35489 /* Start all serial ports */
35490 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35491 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35492 - if (dev2ser(serial_table[i])->port.count) {
35493 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35494 result =
35495 hso_start_serial_device(serial_table[i], GFP_NOIO);
35496 hso_kick_transmit(dev2ser(serial_table[i]));
35497 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35498 index 6169fbd..40e8422 100644
35499 --- a/drivers/net/wireless/ath/ath.h
35500 +++ b/drivers/net/wireless/ath/ath.h
35501 @@ -119,6 +119,7 @@ struct ath_ops {
35502 void (*write_flush) (void *);
35503 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35504 };
35505 +typedef struct ath_ops __no_const ath_ops_no_const;
35506
35507 struct ath_common;
35508 struct ath_bus_ops;
35509 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35510 index 8d78253..bebbb68 100644
35511 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35512 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35513 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35514 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35515 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35516
35517 - ACCESS_ONCE(ads->ds_link) = i->link;
35518 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35519 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35520 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35521
35522 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35523 ctl6 = SM(i->keytype, AR_EncrType);
35524 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35525
35526 if ((i->is_first || i->is_last) &&
35527 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35528 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35529 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35530 | set11nTries(i->rates, 1)
35531 | set11nTries(i->rates, 2)
35532 | set11nTries(i->rates, 3)
35533 | (i->dur_update ? AR_DurUpdateEna : 0)
35534 | SM(0, AR_BurstDur);
35535
35536 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35537 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35538 | set11nRate(i->rates, 1)
35539 | set11nRate(i->rates, 2)
35540 | set11nRate(i->rates, 3);
35541 } else {
35542 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35543 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35544 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35545 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35546 }
35547
35548 if (!i->is_first) {
35549 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35550 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35551 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35552 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35553 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35554 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35555 return;
35556 }
35557
35558 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35559 break;
35560 }
35561
35562 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35563 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35564 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35565 | SM(i->txpower, AR_XmitPower)
35566 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35567 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35568 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35569 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35570
35571 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35572 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35573 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35574 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35575
35576 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35577 return;
35578
35579 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35580 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35581 | set11nPktDurRTSCTS(i->rates, 1);
35582
35583 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35584 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35585 | set11nPktDurRTSCTS(i->rates, 3);
35586
35587 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35588 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35589 | set11nRateFlags(i->rates, 1)
35590 | set11nRateFlags(i->rates, 2)
35591 | set11nRateFlags(i->rates, 3)
35592 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35593 index 78816b8..1fcdfae 100644
35594 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35595 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35596 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35597 (i->qcu << AR_TxQcuNum_S) | desc_len;
35598
35599 checksum += val;
35600 - ACCESS_ONCE(ads->info) = val;
35601 + ACCESS_ONCE_RW(ads->info) = val;
35602
35603 checksum += i->link;
35604 - ACCESS_ONCE(ads->link) = i->link;
35605 + ACCESS_ONCE_RW(ads->link) = i->link;
35606
35607 checksum += i->buf_addr[0];
35608 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35609 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35610 checksum += i->buf_addr[1];
35611 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35612 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35613 checksum += i->buf_addr[2];
35614 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35615 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35616 checksum += i->buf_addr[3];
35617 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35618 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35619
35620 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35621 - ACCESS_ONCE(ads->ctl3) = val;
35622 + ACCESS_ONCE_RW(ads->ctl3) = val;
35623 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35624 - ACCESS_ONCE(ads->ctl5) = val;
35625 + ACCESS_ONCE_RW(ads->ctl5) = val;
35626 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35627 - ACCESS_ONCE(ads->ctl7) = val;
35628 + ACCESS_ONCE_RW(ads->ctl7) = val;
35629 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35630 - ACCESS_ONCE(ads->ctl9) = val;
35631 + ACCESS_ONCE_RW(ads->ctl9) = val;
35632
35633 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35634 - ACCESS_ONCE(ads->ctl10) = checksum;
35635 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35636
35637 if (i->is_first || i->is_last) {
35638 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35639 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35640 | set11nTries(i->rates, 1)
35641 | set11nTries(i->rates, 2)
35642 | set11nTries(i->rates, 3)
35643 | (i->dur_update ? AR_DurUpdateEna : 0)
35644 | SM(0, AR_BurstDur);
35645
35646 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35647 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35648 | set11nRate(i->rates, 1)
35649 | set11nRate(i->rates, 2)
35650 | set11nRate(i->rates, 3);
35651 } else {
35652 - ACCESS_ONCE(ads->ctl13) = 0;
35653 - ACCESS_ONCE(ads->ctl14) = 0;
35654 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35655 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35656 }
35657
35658 ads->ctl20 = 0;
35659 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35660
35661 ctl17 = SM(i->keytype, AR_EncrType);
35662 if (!i->is_first) {
35663 - ACCESS_ONCE(ads->ctl11) = 0;
35664 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35665 - ACCESS_ONCE(ads->ctl15) = 0;
35666 - ACCESS_ONCE(ads->ctl16) = 0;
35667 - ACCESS_ONCE(ads->ctl17) = ctl17;
35668 - ACCESS_ONCE(ads->ctl18) = 0;
35669 - ACCESS_ONCE(ads->ctl19) = 0;
35670 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35671 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35672 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35673 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35674 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35675 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35676 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35677 return;
35678 }
35679
35680 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35681 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35682 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35683 | SM(i->txpower, AR_XmitPower)
35684 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35685 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35686 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35687 ctl12 |= SM(val, AR_PAPRDChainMask);
35688
35689 - ACCESS_ONCE(ads->ctl12) = ctl12;
35690 - ACCESS_ONCE(ads->ctl17) = ctl17;
35691 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35692 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35693
35694 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35695 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35696 | set11nPktDurRTSCTS(i->rates, 1);
35697
35698 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35699 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35700 | set11nPktDurRTSCTS(i->rates, 3);
35701
35702 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35703 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35704 | set11nRateFlags(i->rates, 1)
35705 | set11nRateFlags(i->rates, 2)
35706 | set11nRateFlags(i->rates, 3)
35707 | SM(i->rtscts_rate, AR_RTSCTSRate);
35708
35709 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35710 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35711 }
35712
35713 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35714 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35715 index de6968f..29ac4c1 100644
35716 --- a/drivers/net/wireless/ath/ath9k/hw.h
35717 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35718 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35719
35720 /* ANI */
35721 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35722 -};
35723 +} __no_const;
35724
35725 /**
35726 * struct ath_hw_ops - callbacks used by hardware code and driver code
35727 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35728 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35729 struct ath_hw_antcomb_conf *antconf);
35730
35731 -};
35732 +} __no_const;
35733
35734 struct ath_nf_limits {
35735 s16 max;
35736 @@ -706,7 +706,7 @@ enum ath_cal_list {
35737 #define AH_FASTCC 0x4
35738
35739 struct ath_hw {
35740 - struct ath_ops reg_ops;
35741 + ath_ops_no_const reg_ops;
35742
35743 struct ieee80211_hw *hw;
35744 struct ath_common common;
35745 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35746 index af00e2c..ab04d34 100644
35747 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35748 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35749 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35750 void (*carrsuppr)(struct brcms_phy *);
35751 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35752 void (*detach)(struct brcms_phy *);
35753 -};
35754 +} __no_const;
35755
35756 struct brcms_phy {
35757 struct brcms_phy_pub pubpi_ro;
35758 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35759 index faec404..a5277f1 100644
35760 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35761 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35762 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35763 */
35764 if (il3945_mod_params.disable_hw_scan) {
35765 D_INFO("Disabling hw_scan\n");
35766 - il3945_mac_ops.hw_scan = NULL;
35767 + pax_open_kernel();
35768 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35769 + pax_close_kernel();
35770 }
35771
35772 D_INFO("*** LOAD DRIVER ***\n");
35773 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35774 index a47b306..297daf2 100644
35775 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35776 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35777 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35778 {
35779 struct iwl_priv *priv = file->private_data;
35780 char buf[64];
35781 - int buf_size;
35782 + size_t buf_size;
35783 u32 offset, len;
35784
35785 memset(buf, 0, sizeof(buf));
35786 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35787 struct iwl_priv *priv = file->private_data;
35788
35789 char buf[8];
35790 - int buf_size;
35791 + size_t buf_size;
35792 u32 reset_flag;
35793
35794 memset(buf, 0, sizeof(buf));
35795 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35796 {
35797 struct iwl_priv *priv = file->private_data;
35798 char buf[8];
35799 - int buf_size;
35800 + size_t buf_size;
35801 int ht40;
35802
35803 memset(buf, 0, sizeof(buf));
35804 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35805 {
35806 struct iwl_priv *priv = file->private_data;
35807 char buf[8];
35808 - int buf_size;
35809 + size_t buf_size;
35810 int value;
35811
35812 memset(buf, 0, sizeof(buf));
35813 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35814 {
35815 struct iwl_priv *priv = file->private_data;
35816 char buf[8];
35817 - int buf_size;
35818 + size_t buf_size;
35819 int clear;
35820
35821 memset(buf, 0, sizeof(buf));
35822 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35823 {
35824 struct iwl_priv *priv = file->private_data;
35825 char buf[8];
35826 - int buf_size;
35827 + size_t buf_size;
35828 int trace;
35829
35830 memset(buf, 0, sizeof(buf));
35831 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35832 {
35833 struct iwl_priv *priv = file->private_data;
35834 char buf[8];
35835 - int buf_size;
35836 + size_t buf_size;
35837 int missed;
35838
35839 memset(buf, 0, sizeof(buf));
35840 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35841
35842 struct iwl_priv *priv = file->private_data;
35843 char buf[8];
35844 - int buf_size;
35845 + size_t buf_size;
35846 int plcp;
35847
35848 memset(buf, 0, sizeof(buf));
35849 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35850
35851 struct iwl_priv *priv = file->private_data;
35852 char buf[8];
35853 - int buf_size;
35854 + size_t buf_size;
35855 int flush;
35856
35857 memset(buf, 0, sizeof(buf));
35858 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35859
35860 struct iwl_priv *priv = file->private_data;
35861 char buf[8];
35862 - int buf_size;
35863 + size_t buf_size;
35864 int rts;
35865
35866 if (!priv->cfg->ht_params)
35867 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35868 {
35869 struct iwl_priv *priv = file->private_data;
35870 char buf[8];
35871 - int buf_size;
35872 + size_t buf_size;
35873
35874 memset(buf, 0, sizeof(buf));
35875 buf_size = min(count, sizeof(buf) - 1);
35876 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35877 struct iwl_priv *priv = file->private_data;
35878 u32 event_log_flag;
35879 char buf[8];
35880 - int buf_size;
35881 + size_t buf_size;
35882
35883 /* check that the interface is up */
35884 if (!iwl_is_ready(priv))
35885 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35886 struct iwl_priv *priv = file->private_data;
35887 char buf[8];
35888 u32 calib_disabled;
35889 - int buf_size;
35890 + size_t buf_size;
35891
35892 memset(buf, 0, sizeof(buf));
35893 buf_size = min(count, sizeof(buf) - 1);
35894 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35895 index dbeebef..b45a152 100644
35896 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35897 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35898 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35899 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35900
35901 char buf[8];
35902 - int buf_size;
35903 + size_t buf_size;
35904 u32 reset_flag;
35905
35906 memset(buf, 0, sizeof(buf));
35907 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35908 {
35909 struct iwl_trans *trans = file->private_data;
35910 char buf[8];
35911 - int buf_size;
35912 + size_t buf_size;
35913 int csr;
35914
35915 memset(buf, 0, sizeof(buf));
35916 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35917 index 0083839..fcb7225 100644
35918 --- a/drivers/net/wireless/mac80211_hwsim.c
35919 +++ b/drivers/net/wireless/mac80211_hwsim.c
35920 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35921 return -EINVAL;
35922
35923 if (fake_hw_scan) {
35924 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35925 - mac80211_hwsim_ops.sw_scan_start = NULL;
35926 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35927 + pax_open_kernel();
35928 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35929 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35930 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35931 + pax_close_kernel();
35932 }
35933
35934 spin_lock_init(&hwsim_radio_lock);
35935 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35936 index e7c2a82..582e228 100644
35937 --- a/drivers/net/wireless/mwifiex/main.h
35938 +++ b/drivers/net/wireless/mwifiex/main.h
35939 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35940 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35941 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35942 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35943 -};
35944 +} __no_const;
35945
35946 struct mwifiex_adapter {
35947 u8 iface_type;
35948 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35949 index 7a4ae9e..56e00bd 100644
35950 --- a/drivers/net/wireless/rndis_wlan.c
35951 +++ b/drivers/net/wireless/rndis_wlan.c
35952 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35953
35954 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35955
35956 - if (rts_threshold < 0 || rts_threshold > 2347)
35957 + if (rts_threshold > 2347)
35958 rts_threshold = 2347;
35959
35960 tmp = cpu_to_le32(rts_threshold);
35961 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35962 index 8afb546..0c0dc5c 100644
35963 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35964 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35965 @@ -397,7 +397,7 @@ struct rt2x00_intf {
35966 * for hardware which doesn't support hardware
35967 * sequence counting.
35968 */
35969 - atomic_t seqno;
35970 + atomic_unchecked_t seqno;
35971 };
35972
35973 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35974 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35975 index f7e74a0..da71431 100644
35976 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35977 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35978 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35979 * sequence counter given by mac80211.
35980 */
35981 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35982 - seqno = atomic_add_return(0x10, &intf->seqno);
35983 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35984 else
35985 - seqno = atomic_read(&intf->seqno);
35986 + seqno = atomic_read_unchecked(&intf->seqno);
35987
35988 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35989 hdr->seq_ctrl |= cpu_to_le16(seqno);
35990 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35991 index fd02060..74ee481 100644
35992 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35993 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35994 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35995 void (*reset)(struct wl1251 *wl);
35996 void (*enable_irq)(struct wl1251 *wl);
35997 void (*disable_irq)(struct wl1251 *wl);
35998 -};
35999 +} __no_const;
36000
36001 struct wl1251 {
36002 struct ieee80211_hw *hw;
36003 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36004 index 0ce7a8e..56a0ccf 100644
36005 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36006 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36007 @@ -81,7 +81,7 @@ struct wlcore_ops {
36008 struct ieee80211_sta *sta,
36009 struct ieee80211_key_conf *key_conf);
36010 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36011 -};
36012 +} __no_const;
36013
36014 enum wlcore_partitions {
36015 PART_DOWN,
36016 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36017 index f34b5b2..b5abb9f 100644
36018 --- a/drivers/oprofile/buffer_sync.c
36019 +++ b/drivers/oprofile/buffer_sync.c
36020 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36021 if (cookie == NO_COOKIE)
36022 offset = pc;
36023 if (cookie == INVALID_COOKIE) {
36024 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36025 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36026 offset = pc;
36027 }
36028 if (cookie != last_cookie) {
36029 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36030 /* add userspace sample */
36031
36032 if (!mm) {
36033 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36034 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36035 return 0;
36036 }
36037
36038 cookie = lookup_dcookie(mm, s->eip, &offset);
36039
36040 if (cookie == INVALID_COOKIE) {
36041 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36042 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36043 return 0;
36044 }
36045
36046 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36047 /* ignore backtraces if failed to add a sample */
36048 if (state == sb_bt_start) {
36049 state = sb_bt_ignore;
36050 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36051 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36052 }
36053 }
36054 release_mm(mm);
36055 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36056 index c0cc4e7..44d4e54 100644
36057 --- a/drivers/oprofile/event_buffer.c
36058 +++ b/drivers/oprofile/event_buffer.c
36059 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36060 }
36061
36062 if (buffer_pos == buffer_size) {
36063 - atomic_inc(&oprofile_stats.event_lost_overflow);
36064 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36065 return;
36066 }
36067
36068 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36069 index ed2c3ec..deda85a 100644
36070 --- a/drivers/oprofile/oprof.c
36071 +++ b/drivers/oprofile/oprof.c
36072 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36073 if (oprofile_ops.switch_events())
36074 return;
36075
36076 - atomic_inc(&oprofile_stats.multiplex_counter);
36077 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36078 start_switch_worker();
36079 }
36080
36081 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36082 index 917d28e..d62d981 100644
36083 --- a/drivers/oprofile/oprofile_stats.c
36084 +++ b/drivers/oprofile/oprofile_stats.c
36085 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36086 cpu_buf->sample_invalid_eip = 0;
36087 }
36088
36089 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36090 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36091 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36092 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36093 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36094 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36095 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36096 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36097 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36098 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36099 }
36100
36101
36102 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36103 index 38b6fc0..b5cbfce 100644
36104 --- a/drivers/oprofile/oprofile_stats.h
36105 +++ b/drivers/oprofile/oprofile_stats.h
36106 @@ -13,11 +13,11 @@
36107 #include <linux/atomic.h>
36108
36109 struct oprofile_stat_struct {
36110 - atomic_t sample_lost_no_mm;
36111 - atomic_t sample_lost_no_mapping;
36112 - atomic_t bt_lost_no_mapping;
36113 - atomic_t event_lost_overflow;
36114 - atomic_t multiplex_counter;
36115 + atomic_unchecked_t sample_lost_no_mm;
36116 + atomic_unchecked_t sample_lost_no_mapping;
36117 + atomic_unchecked_t bt_lost_no_mapping;
36118 + atomic_unchecked_t event_lost_overflow;
36119 + atomic_unchecked_t multiplex_counter;
36120 };
36121
36122 extern struct oprofile_stat_struct oprofile_stats;
36123 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36124 index 849357c..b83c1e0 100644
36125 --- a/drivers/oprofile/oprofilefs.c
36126 +++ b/drivers/oprofile/oprofilefs.c
36127 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36128
36129
36130 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36131 - char const *name, atomic_t *val)
36132 + char const *name, atomic_unchecked_t *val)
36133 {
36134 return __oprofilefs_create_file(sb, root, name,
36135 &atomic_ro_fops, 0444, val);
36136 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36137 index 3f56bc0..707d642 100644
36138 --- a/drivers/parport/procfs.c
36139 +++ b/drivers/parport/procfs.c
36140 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36141
36142 *ppos += len;
36143
36144 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36145 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36146 }
36147
36148 #ifdef CONFIG_PARPORT_1284
36149 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36150
36151 *ppos += len;
36152
36153 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36154 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36155 }
36156 #endif /* IEEE1284.3 support. */
36157
36158 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36159 index 9fff878..ad0ad53 100644
36160 --- a/drivers/pci/hotplug/cpci_hotplug.h
36161 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36162 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36163 int (*hardware_test) (struct slot* slot, u32 value);
36164 u8 (*get_power) (struct slot* slot);
36165 int (*set_power) (struct slot* slot, int value);
36166 -};
36167 +} __no_const;
36168
36169 struct cpci_hp_controller {
36170 unsigned int irq;
36171 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36172 index 76ba8a1..20ca857 100644
36173 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36174 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36175 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36176
36177 void compaq_nvram_init (void __iomem *rom_start)
36178 {
36179 +
36180 +#ifndef CONFIG_PAX_KERNEXEC
36181 if (rom_start) {
36182 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36183 }
36184 +#endif
36185 +
36186 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36187
36188 /* initialize our int15 lock */
36189 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36190 index b500840..d7159d3 100644
36191 --- a/drivers/pci/pcie/aspm.c
36192 +++ b/drivers/pci/pcie/aspm.c
36193 @@ -27,9 +27,9 @@
36194 #define MODULE_PARAM_PREFIX "pcie_aspm."
36195
36196 /* Note: those are not register definitions */
36197 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36198 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36199 -#define ASPM_STATE_L1 (4) /* L1 state */
36200 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36201 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36202 +#define ASPM_STATE_L1 (4U) /* L1 state */
36203 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36204 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36205
36206 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36207 index 61859d0..124539e 100644
36208 --- a/drivers/pci/probe.c
36209 +++ b/drivers/pci/probe.c
36210 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36211 struct pci_bus_region region;
36212 bool bar_too_big = false, bar_disabled = false;
36213
36214 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36215 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36216
36217 /* No printks while decoding is disabled! */
36218 if (!dev->mmio_always_on) {
36219 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36220 index 27911b5..5b6db88 100644
36221 --- a/drivers/pci/proc.c
36222 +++ b/drivers/pci/proc.c
36223 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36224 static int __init pci_proc_init(void)
36225 {
36226 struct pci_dev *dev = NULL;
36227 +
36228 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36229 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36230 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36231 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36232 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36233 +#endif
36234 +#else
36235 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36236 +#endif
36237 proc_create("devices", 0, proc_bus_pci_dir,
36238 &proc_bus_pci_dev_operations);
36239 proc_initialized = 1;
36240 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36241 index 52daaa8..d6b81eb 100644
36242 --- a/drivers/platform/x86/thinkpad_acpi.c
36243 +++ b/drivers/platform/x86/thinkpad_acpi.c
36244 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36245 return 0;
36246 }
36247
36248 -void static hotkey_mask_warn_incomplete_mask(void)
36249 +static void hotkey_mask_warn_incomplete_mask(void)
36250 {
36251 /* log only what the user can fix... */
36252 const u32 wantedmask = hotkey_driver_mask &
36253 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36254 }
36255 }
36256
36257 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36258 - struct tp_nvram_state *newn,
36259 - const u32 event_mask)
36260 -{
36261 -
36262 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36263 do { \
36264 if ((event_mask & (1 << __scancode)) && \
36265 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36266 tpacpi_hotkey_send_key(__scancode); \
36267 } while (0)
36268
36269 - void issue_volchange(const unsigned int oldvol,
36270 - const unsigned int newvol)
36271 - {
36272 - unsigned int i = oldvol;
36273 +static void issue_volchange(const unsigned int oldvol,
36274 + const unsigned int newvol,
36275 + const u32 event_mask)
36276 +{
36277 + unsigned int i = oldvol;
36278
36279 - while (i > newvol) {
36280 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36281 - i--;
36282 - }
36283 - while (i < newvol) {
36284 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36285 - i++;
36286 - }
36287 + while (i > newvol) {
36288 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36289 + i--;
36290 }
36291 + while (i < newvol) {
36292 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36293 + i++;
36294 + }
36295 +}
36296
36297 - void issue_brightnesschange(const unsigned int oldbrt,
36298 - const unsigned int newbrt)
36299 - {
36300 - unsigned int i = oldbrt;
36301 +static void issue_brightnesschange(const unsigned int oldbrt,
36302 + const unsigned int newbrt,
36303 + const u32 event_mask)
36304 +{
36305 + unsigned int i = oldbrt;
36306
36307 - while (i > newbrt) {
36308 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36309 - i--;
36310 - }
36311 - while (i < newbrt) {
36312 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36313 - i++;
36314 - }
36315 + while (i > newbrt) {
36316 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36317 + i--;
36318 + }
36319 + while (i < newbrt) {
36320 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36321 + i++;
36322 }
36323 +}
36324
36325 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36326 + struct tp_nvram_state *newn,
36327 + const u32 event_mask)
36328 +{
36329 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36330 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36331 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36332 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36333 oldn->volume_level != newn->volume_level) {
36334 /* recently muted, or repeated mute keypress, or
36335 * multiple presses ending in mute */
36336 - issue_volchange(oldn->volume_level, newn->volume_level);
36337 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36338 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36339 }
36340 } else {
36341 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36342 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36343 }
36344 if (oldn->volume_level != newn->volume_level) {
36345 - issue_volchange(oldn->volume_level, newn->volume_level);
36346 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36347 } else if (oldn->volume_toggle != newn->volume_toggle) {
36348 /* repeated vol up/down keypress at end of scale ? */
36349 if (newn->volume_level == 0)
36350 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36351 /* handle brightness */
36352 if (oldn->brightness_level != newn->brightness_level) {
36353 issue_brightnesschange(oldn->brightness_level,
36354 - newn->brightness_level);
36355 + newn->brightness_level,
36356 + event_mask);
36357 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36358 /* repeated key presses that didn't change state */
36359 if (newn->brightness_level == 0)
36360 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36361 && !tp_features.bright_unkfw)
36362 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36363 }
36364 +}
36365
36366 #undef TPACPI_COMPARE_KEY
36367 #undef TPACPI_MAY_SEND_KEY
36368 -}
36369
36370 /*
36371 * Polling driver
36372 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36373 index 769d265..a3a05ca 100644
36374 --- a/drivers/pnp/pnpbios/bioscalls.c
36375 +++ b/drivers/pnp/pnpbios/bioscalls.c
36376 @@ -58,7 +58,7 @@ do { \
36377 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36378 } while(0)
36379
36380 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36381 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36382 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36383
36384 /*
36385 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36386
36387 cpu = get_cpu();
36388 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36389 +
36390 + pax_open_kernel();
36391 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36392 + pax_close_kernel();
36393
36394 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36395 spin_lock_irqsave(&pnp_bios_lock, flags);
36396 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36397 :"memory");
36398 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36399
36400 + pax_open_kernel();
36401 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36402 + pax_close_kernel();
36403 +
36404 put_cpu();
36405
36406 /* If we get here and this is set then the PnP BIOS faulted on us. */
36407 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36408 return status;
36409 }
36410
36411 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36412 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36413 {
36414 int i;
36415
36416 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36417 pnp_bios_callpoint.offset = header->fields.pm16offset;
36418 pnp_bios_callpoint.segment = PNP_CS16;
36419
36420 + pax_open_kernel();
36421 +
36422 for_each_possible_cpu(i) {
36423 struct desc_struct *gdt = get_cpu_gdt_table(i);
36424 if (!gdt)
36425 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36426 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36427 (unsigned long)__va(header->fields.pm16dseg));
36428 }
36429 +
36430 + pax_close_kernel();
36431 }
36432 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36433 index b0ecacb..7c9da2e 100644
36434 --- a/drivers/pnp/resource.c
36435 +++ b/drivers/pnp/resource.c
36436 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36437 return 1;
36438
36439 /* check if the resource is valid */
36440 - if (*irq < 0 || *irq > 15)
36441 + if (*irq > 15)
36442 return 0;
36443
36444 /* check if the resource is reserved */
36445 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36446 return 1;
36447
36448 /* check if the resource is valid */
36449 - if (*dma < 0 || *dma == 4 || *dma > 7)
36450 + if (*dma == 4 || *dma > 7)
36451 return 0;
36452
36453 /* check if the resource is reserved */
36454 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36455 index 181ddec..774b6da 100644
36456 --- a/drivers/power/bq27x00_battery.c
36457 +++ b/drivers/power/bq27x00_battery.c
36458 @@ -80,7 +80,7 @@
36459 struct bq27x00_device_info;
36460 struct bq27x00_access_methods {
36461 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36462 -};
36463 +} __no_const;
36464
36465 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36466
36467 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36468 index 8d53174..04c65de 100644
36469 --- a/drivers/regulator/max8660.c
36470 +++ b/drivers/regulator/max8660.c
36471 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36472 max8660->shadow_regs[MAX8660_OVER1] = 5;
36473 } else {
36474 /* Otherwise devices can be toggled via software */
36475 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36476 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36477 + pax_open_kernel();
36478 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36479 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36480 + pax_close_kernel();
36481 }
36482
36483 /*
36484 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36485 index b388b74..ed82573 100644
36486 --- a/drivers/regulator/mc13892-regulator.c
36487 +++ b/drivers/regulator/mc13892-regulator.c
36488 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36489 }
36490 mc13xxx_unlock(mc13892);
36491
36492 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36493 + pax_open_kernel();
36494 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36495 = mc13892_vcam_set_mode;
36496 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36497 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36498 = mc13892_vcam_get_mode;
36499 + pax_close_kernel();
36500
36501 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36502 ARRAY_SIZE(mc13892_regulators));
36503 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36504 index cace6d3..f623fda 100644
36505 --- a/drivers/rtc/rtc-dev.c
36506 +++ b/drivers/rtc/rtc-dev.c
36507 @@ -14,6 +14,7 @@
36508 #include <linux/module.h>
36509 #include <linux/rtc.h>
36510 #include <linux/sched.h>
36511 +#include <linux/grsecurity.h>
36512 #include "rtc-core.h"
36513
36514 static dev_t rtc_devt;
36515 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36516 if (copy_from_user(&tm, uarg, sizeof(tm)))
36517 return -EFAULT;
36518
36519 + gr_log_timechange();
36520 +
36521 return rtc_set_time(rtc, &tm);
36522
36523 case RTC_PIE_ON:
36524 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36525 index 9e933a8..4f969f7 100644
36526 --- a/drivers/scsi/aacraid/aacraid.h
36527 +++ b/drivers/scsi/aacraid/aacraid.h
36528 @@ -503,7 +503,7 @@ struct adapter_ops
36529 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36530 /* Administrative operations */
36531 int (*adapter_comm)(struct aac_dev * dev, int comm);
36532 -};
36533 +} __no_const;
36534
36535 /*
36536 * Define which interrupt handler needs to be installed
36537 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36538 index 7199534..cb7f158 100644
36539 --- a/drivers/scsi/aacraid/linit.c
36540 +++ b/drivers/scsi/aacraid/linit.c
36541 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36542 #elif defined(__devinitconst)
36543 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36544 #else
36545 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36546 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36547 #endif
36548 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36549 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36550 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36551 index ff80552..1c4120c 100644
36552 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36553 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36554 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36555 .lldd_ata_set_dmamode = asd_set_dmamode,
36556 };
36557
36558 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36559 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36560 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36561 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36562 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36563 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36564 index 4ad7e36..d004679 100644
36565 --- a/drivers/scsi/bfa/bfa.h
36566 +++ b/drivers/scsi/bfa/bfa.h
36567 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36568 u32 *end);
36569 int cpe_vec_q0;
36570 int rme_vec_q0;
36571 -};
36572 +} __no_const;
36573 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36574
36575 struct bfa_faa_cbfn_s {
36576 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36577 index f0f80e2..8ec946b 100644
36578 --- a/drivers/scsi/bfa/bfa_fcpim.c
36579 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36580 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36581
36582 bfa_iotag_attach(fcp);
36583
36584 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36585 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36586 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36587 (fcp->num_itns * sizeof(struct bfa_itn_s));
36588 memset(fcp->itn_arr, 0,
36589 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36590 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36591 {
36592 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36593 - struct bfa_itn_s *itn;
36594 + bfa_itn_s_no_const *itn;
36595
36596 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36597 itn->isr = isr;
36598 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36599 index 36f26da..38a34a8 100644
36600 --- a/drivers/scsi/bfa/bfa_fcpim.h
36601 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36602 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36603 struct bfa_itn_s {
36604 bfa_isr_func_t isr;
36605 };
36606 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36607
36608 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36609 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36610 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36611 struct list_head iotag_tio_free_q; /* free IO resources */
36612 struct list_head iotag_unused_q; /* unused IO resources*/
36613 struct bfa_iotag_s *iotag_arr;
36614 - struct bfa_itn_s *itn_arr;
36615 + bfa_itn_s_no_const *itn_arr;
36616 int num_ioim_reqs;
36617 int num_fwtio_reqs;
36618 int num_itns;
36619 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36620 index 1a99d4b..e85d64b 100644
36621 --- a/drivers/scsi/bfa/bfa_ioc.h
36622 +++ b/drivers/scsi/bfa/bfa_ioc.h
36623 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36624 bfa_ioc_disable_cbfn_t disable_cbfn;
36625 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36626 bfa_ioc_reset_cbfn_t reset_cbfn;
36627 -};
36628 +} __no_const;
36629
36630 /*
36631 * IOC event notification mechanism.
36632 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36633 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36634 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36635 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36636 -};
36637 +} __no_const;
36638
36639 /*
36640 * Queue element to wait for room in request queue. FIFO order is
36641 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36642 index 593085a..47aa999 100644
36643 --- a/drivers/scsi/hosts.c
36644 +++ b/drivers/scsi/hosts.c
36645 @@ -42,7 +42,7 @@
36646 #include "scsi_logging.h"
36647
36648
36649 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36650 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36651
36652
36653 static void scsi_host_cls_release(struct device *dev)
36654 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36655 * subtract one because we increment first then return, but we need to
36656 * know what the next host number was before increment
36657 */
36658 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36659 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36660 shost->dma_channel = 0xff;
36661
36662 /* These three are default values which can be overridden */
36663 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36664 index f9823f2..7bc3e81 100644
36665 --- a/drivers/scsi/hpsa.c
36666 +++ b/drivers/scsi/hpsa.c
36667 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36668 unsigned long flags;
36669
36670 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36671 - return h->access.command_completed(h, q);
36672 + return h->access->command_completed(h, q);
36673
36674 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36675 a = rq->head[rq->current_entry];
36676 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36677 while (!list_empty(&h->reqQ)) {
36678 c = list_entry(h->reqQ.next, struct CommandList, list);
36679 /* can't do anything if fifo is full */
36680 - if ((h->access.fifo_full(h))) {
36681 + if ((h->access->fifo_full(h))) {
36682 dev_warn(&h->pdev->dev, "fifo full\n");
36683 break;
36684 }
36685 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36686
36687 /* Tell the controller execute command */
36688 spin_unlock_irqrestore(&h->lock, flags);
36689 - h->access.submit_command(h, c);
36690 + h->access->submit_command(h, c);
36691 spin_lock_irqsave(&h->lock, flags);
36692 }
36693 spin_unlock_irqrestore(&h->lock, flags);
36694 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36695
36696 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36697 {
36698 - return h->access.command_completed(h, q);
36699 + return h->access->command_completed(h, q);
36700 }
36701
36702 static inline bool interrupt_pending(struct ctlr_info *h)
36703 {
36704 - return h->access.intr_pending(h);
36705 + return h->access->intr_pending(h);
36706 }
36707
36708 static inline long interrupt_not_for_us(struct ctlr_info *h)
36709 {
36710 - return (h->access.intr_pending(h) == 0) ||
36711 + return (h->access->intr_pending(h) == 0) ||
36712 (h->interrupts_enabled == 0);
36713 }
36714
36715 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36716 if (prod_index < 0)
36717 return -ENODEV;
36718 h->product_name = products[prod_index].product_name;
36719 - h->access = *(products[prod_index].access);
36720 + h->access = products[prod_index].access;
36721
36722 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36723 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36724 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36725
36726 assert_spin_locked(&lockup_detector_lock);
36727 remove_ctlr_from_lockup_detector_list(h);
36728 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36729 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36730 spin_lock_irqsave(&h->lock, flags);
36731 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36732 spin_unlock_irqrestore(&h->lock, flags);
36733 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36734 }
36735
36736 /* make sure the board interrupts are off */
36737 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36738 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36739
36740 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36741 goto clean2;
36742 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36743 * fake ones to scoop up any residual completions.
36744 */
36745 spin_lock_irqsave(&h->lock, flags);
36746 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36747 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36748 spin_unlock_irqrestore(&h->lock, flags);
36749 free_irqs(h);
36750 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36751 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36752 dev_info(&h->pdev->dev, "Board READY.\n");
36753 dev_info(&h->pdev->dev,
36754 "Waiting for stale completions to drain.\n");
36755 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36756 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36757 msleep(10000);
36758 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36759 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36760
36761 rc = controller_reset_failed(h->cfgtable);
36762 if (rc)
36763 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36764 }
36765
36766 /* Turn the interrupts on so we can service requests */
36767 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36768 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36769
36770 hpsa_hba_inquiry(h);
36771 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36772 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36773 * To write all data in the battery backed cache to disks
36774 */
36775 hpsa_flush_cache(h);
36776 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36777 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36778 hpsa_free_irqs_and_disable_msix(h);
36779 }
36780
36781 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36782 return;
36783 }
36784 /* Change the access methods to the performant access methods */
36785 - h->access = SA5_performant_access;
36786 + h->access = &SA5_performant_access;
36787 h->transMethod = CFGTBL_Trans_Performant;
36788 }
36789
36790 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36791 index 9816479..c5d4e97 100644
36792 --- a/drivers/scsi/hpsa.h
36793 +++ b/drivers/scsi/hpsa.h
36794 @@ -79,7 +79,7 @@ struct ctlr_info {
36795 unsigned int msix_vector;
36796 unsigned int msi_vector;
36797 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36798 - struct access_method access;
36799 + struct access_method *access;
36800
36801 /* queue and queue Info */
36802 struct list_head reqQ;
36803 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36804 index f2df059..a3a9930 100644
36805 --- a/drivers/scsi/ips.h
36806 +++ b/drivers/scsi/ips.h
36807 @@ -1027,7 +1027,7 @@ typedef struct {
36808 int (*intr)(struct ips_ha *);
36809 void (*enableint)(struct ips_ha *);
36810 uint32_t (*statupd)(struct ips_ha *);
36811 -} ips_hw_func_t;
36812 +} __no_const ips_hw_func_t;
36813
36814 typedef struct ips_ha {
36815 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36816 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36817 index c772d8d..35c362c 100644
36818 --- a/drivers/scsi/libfc/fc_exch.c
36819 +++ b/drivers/scsi/libfc/fc_exch.c
36820 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36821 u16 pool_max_index;
36822
36823 struct {
36824 - atomic_t no_free_exch;
36825 - atomic_t no_free_exch_xid;
36826 - atomic_t xid_not_found;
36827 - atomic_t xid_busy;
36828 - atomic_t seq_not_found;
36829 - atomic_t non_bls_resp;
36830 + atomic_unchecked_t no_free_exch;
36831 + atomic_unchecked_t no_free_exch_xid;
36832 + atomic_unchecked_t xid_not_found;
36833 + atomic_unchecked_t xid_busy;
36834 + atomic_unchecked_t seq_not_found;
36835 + atomic_unchecked_t non_bls_resp;
36836 } stats;
36837 };
36838
36839 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36840 /* allocate memory for exchange */
36841 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36842 if (!ep) {
36843 - atomic_inc(&mp->stats.no_free_exch);
36844 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36845 goto out;
36846 }
36847 memset(ep, 0, sizeof(*ep));
36848 @@ -786,7 +786,7 @@ out:
36849 return ep;
36850 err:
36851 spin_unlock_bh(&pool->lock);
36852 - atomic_inc(&mp->stats.no_free_exch_xid);
36853 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36854 mempool_free(ep, mp->ep_pool);
36855 return NULL;
36856 }
36857 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36858 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36859 ep = fc_exch_find(mp, xid);
36860 if (!ep) {
36861 - atomic_inc(&mp->stats.xid_not_found);
36862 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36863 reject = FC_RJT_OX_ID;
36864 goto out;
36865 }
36866 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36867 ep = fc_exch_find(mp, xid);
36868 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36869 if (ep) {
36870 - atomic_inc(&mp->stats.xid_busy);
36871 + atomic_inc_unchecked(&mp->stats.xid_busy);
36872 reject = FC_RJT_RX_ID;
36873 goto rel;
36874 }
36875 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36876 }
36877 xid = ep->xid; /* get our XID */
36878 } else if (!ep) {
36879 - atomic_inc(&mp->stats.xid_not_found);
36880 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36881 reject = FC_RJT_RX_ID; /* XID not found */
36882 goto out;
36883 }
36884 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36885 } else {
36886 sp = &ep->seq;
36887 if (sp->id != fh->fh_seq_id) {
36888 - atomic_inc(&mp->stats.seq_not_found);
36889 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36890 if (f_ctl & FC_FC_END_SEQ) {
36891 /*
36892 * Update sequence_id based on incoming last
36893 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36894
36895 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36896 if (!ep) {
36897 - atomic_inc(&mp->stats.xid_not_found);
36898 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36899 goto out;
36900 }
36901 if (ep->esb_stat & ESB_ST_COMPLETE) {
36902 - atomic_inc(&mp->stats.xid_not_found);
36903 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36904 goto rel;
36905 }
36906 if (ep->rxid == FC_XID_UNKNOWN)
36907 ep->rxid = ntohs(fh->fh_rx_id);
36908 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36909 - atomic_inc(&mp->stats.xid_not_found);
36910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36911 goto rel;
36912 }
36913 if (ep->did != ntoh24(fh->fh_s_id) &&
36914 ep->did != FC_FID_FLOGI) {
36915 - atomic_inc(&mp->stats.xid_not_found);
36916 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36917 goto rel;
36918 }
36919 sof = fr_sof(fp);
36920 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36921 sp->ssb_stat |= SSB_ST_RESP;
36922 sp->id = fh->fh_seq_id;
36923 } else if (sp->id != fh->fh_seq_id) {
36924 - atomic_inc(&mp->stats.seq_not_found);
36925 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36926 goto rel;
36927 }
36928
36929 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36930 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36931
36932 if (!sp)
36933 - atomic_inc(&mp->stats.xid_not_found);
36934 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36935 else
36936 - atomic_inc(&mp->stats.non_bls_resp);
36937 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36938
36939 fc_frame_free(fp);
36940 }
36941 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36942
36943 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36944 mp = ema->mp;
36945 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36946 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36947 st->fc_no_free_exch_xid +=
36948 - atomic_read(&mp->stats.no_free_exch_xid);
36949 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36950 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36951 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36952 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36953 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36954 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36955 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36956 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36957 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36958 }
36959 }
36960 EXPORT_SYMBOL(fc_exch_update_stats);
36961 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36962 index a59fcdc..abe55f3 100644
36963 --- a/drivers/scsi/libsas/sas_ata.c
36964 +++ b/drivers/scsi/libsas/sas_ata.c
36965 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36966 .postreset = ata_std_postreset,
36967 .error_handler = ata_std_error_handler,
36968 .post_internal_cmd = sas_ata_post_internal,
36969 - .qc_defer = ata_std_qc_defer,
36970 + .qc_defer = ata_std_qc_defer,
36971 .qc_prep = ata_noop_qc_prep,
36972 .qc_issue = sas_ata_qc_issue,
36973 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36974 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36975 index a65c05a..a39e402 100644
36976 --- a/drivers/scsi/lpfc/lpfc.h
36977 +++ b/drivers/scsi/lpfc/lpfc.h
36978 @@ -420,7 +420,7 @@ struct lpfc_vport {
36979 struct dentry *debug_nodelist;
36980 struct dentry *vport_debugfs_root;
36981 struct lpfc_debugfs_trc *disc_trc;
36982 - atomic_t disc_trc_cnt;
36983 + atomic_unchecked_t disc_trc_cnt;
36984 #endif
36985 uint8_t stat_data_enabled;
36986 uint8_t stat_data_blocked;
36987 @@ -834,8 +834,8 @@ struct lpfc_hba {
36988 struct timer_list fabric_block_timer;
36989 unsigned long bit_flags;
36990 #define FABRIC_COMANDS_BLOCKED 0
36991 - atomic_t num_rsrc_err;
36992 - atomic_t num_cmd_success;
36993 + atomic_unchecked_t num_rsrc_err;
36994 + atomic_unchecked_t num_cmd_success;
36995 unsigned long last_rsrc_error_time;
36996 unsigned long last_ramp_down_time;
36997 unsigned long last_ramp_up_time;
36998 @@ -871,7 +871,7 @@ struct lpfc_hba {
36999
37000 struct dentry *debug_slow_ring_trc;
37001 struct lpfc_debugfs_trc *slow_ring_trc;
37002 - atomic_t slow_ring_trc_cnt;
37003 + atomic_unchecked_t slow_ring_trc_cnt;
37004 /* iDiag debugfs sub-directory */
37005 struct dentry *idiag_root;
37006 struct dentry *idiag_pci_cfg;
37007 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37008 index 3217d63..c417981 100644
37009 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37010 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37011 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37012
37013 #include <linux/debugfs.h>
37014
37015 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37016 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37017 static unsigned long lpfc_debugfs_start_time = 0L;
37018
37019 /* iDiag */
37020 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37021 lpfc_debugfs_enable = 0;
37022
37023 len = 0;
37024 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37025 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37026 (lpfc_debugfs_max_disc_trc - 1);
37027 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37028 dtp = vport->disc_trc + i;
37029 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37030 lpfc_debugfs_enable = 0;
37031
37032 len = 0;
37033 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37034 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37035 (lpfc_debugfs_max_slow_ring_trc - 1);
37036 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37037 dtp = phba->slow_ring_trc + i;
37038 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37039 !vport || !vport->disc_trc)
37040 return;
37041
37042 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37043 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37044 (lpfc_debugfs_max_disc_trc - 1);
37045 dtp = vport->disc_trc + index;
37046 dtp->fmt = fmt;
37047 dtp->data1 = data1;
37048 dtp->data2 = data2;
37049 dtp->data3 = data3;
37050 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37051 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37052 dtp->jif = jiffies;
37053 #endif
37054 return;
37055 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37056 !phba || !phba->slow_ring_trc)
37057 return;
37058
37059 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37060 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37061 (lpfc_debugfs_max_slow_ring_trc - 1);
37062 dtp = phba->slow_ring_trc + index;
37063 dtp->fmt = fmt;
37064 dtp->data1 = data1;
37065 dtp->data2 = data2;
37066 dtp->data3 = data3;
37067 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37068 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37069 dtp->jif = jiffies;
37070 #endif
37071 return;
37072 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37073 "slow_ring buffer\n");
37074 goto debug_failed;
37075 }
37076 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37077 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37078 memset(phba->slow_ring_trc, 0,
37079 (sizeof(struct lpfc_debugfs_trc) *
37080 lpfc_debugfs_max_slow_ring_trc));
37081 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37082 "buffer\n");
37083 goto debug_failed;
37084 }
37085 - atomic_set(&vport->disc_trc_cnt, 0);
37086 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37087
37088 snprintf(name, sizeof(name), "discovery_trace");
37089 vport->debug_disc_trc =
37090 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37091 index 45c1520..35ba744 100644
37092 --- a/drivers/scsi/lpfc/lpfc_init.c
37093 +++ b/drivers/scsi/lpfc/lpfc_init.c
37094 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37095 "misc_register returned with status %d", error);
37096
37097 if (lpfc_enable_npiv) {
37098 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37099 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37100 + pax_open_kernel();
37101 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37102 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37103 + pax_close_kernel();
37104 }
37105 lpfc_transport_template =
37106 fc_attach_transport(&lpfc_transport_functions);
37107 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37108 index 925975d..0f1fc07 100644
37109 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37110 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37111 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37112 uint32_t evt_posted;
37113
37114 spin_lock_irqsave(&phba->hbalock, flags);
37115 - atomic_inc(&phba->num_rsrc_err);
37116 + atomic_inc_unchecked(&phba->num_rsrc_err);
37117 phba->last_rsrc_error_time = jiffies;
37118
37119 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37120 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37121 unsigned long flags;
37122 struct lpfc_hba *phba = vport->phba;
37123 uint32_t evt_posted;
37124 - atomic_inc(&phba->num_cmd_success);
37125 + atomic_inc_unchecked(&phba->num_cmd_success);
37126
37127 if (vport->cfg_lun_queue_depth <= queue_depth)
37128 return;
37129 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37130 unsigned long num_rsrc_err, num_cmd_success;
37131 int i;
37132
37133 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37134 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37135 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37136 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37137
37138 /*
37139 * The error and success command counters are global per
37140 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37141 }
37142 }
37143 lpfc_destroy_vport_work_array(phba, vports);
37144 - atomic_set(&phba->num_rsrc_err, 0);
37145 - atomic_set(&phba->num_cmd_success, 0);
37146 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37147 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37148 }
37149
37150 /**
37151 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37152 }
37153 }
37154 lpfc_destroy_vport_work_array(phba, vports);
37155 - atomic_set(&phba->num_rsrc_err, 0);
37156 - atomic_set(&phba->num_cmd_success, 0);
37157 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37158 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37159 }
37160
37161 /**
37162 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37163 index ea8a0b4..812a124 100644
37164 --- a/drivers/scsi/pmcraid.c
37165 +++ b/drivers/scsi/pmcraid.c
37166 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37167 res->scsi_dev = scsi_dev;
37168 scsi_dev->hostdata = res;
37169 res->change_detected = 0;
37170 - atomic_set(&res->read_failures, 0);
37171 - atomic_set(&res->write_failures, 0);
37172 + atomic_set_unchecked(&res->read_failures, 0);
37173 + atomic_set_unchecked(&res->write_failures, 0);
37174 rc = 0;
37175 }
37176 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37177 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37178
37179 /* If this was a SCSI read/write command keep count of errors */
37180 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37181 - atomic_inc(&res->read_failures);
37182 + atomic_inc_unchecked(&res->read_failures);
37183 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37184 - atomic_inc(&res->write_failures);
37185 + atomic_inc_unchecked(&res->write_failures);
37186
37187 if (!RES_IS_GSCSI(res->cfg_entry) &&
37188 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37189 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37190 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37191 * hrrq_id assigned here in queuecommand
37192 */
37193 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37194 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37195 pinstance->num_hrrq;
37196 cmd->cmd_done = pmcraid_io_done;
37197
37198 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37199 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37200 * hrrq_id assigned here in queuecommand
37201 */
37202 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37203 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37204 pinstance->num_hrrq;
37205
37206 if (request_size) {
37207 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37208
37209 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37210 /* add resources only after host is added into system */
37211 - if (!atomic_read(&pinstance->expose_resources))
37212 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37213 return;
37214
37215 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37216 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37217 init_waitqueue_head(&pinstance->reset_wait_q);
37218
37219 atomic_set(&pinstance->outstanding_cmds, 0);
37220 - atomic_set(&pinstance->last_message_id, 0);
37221 - atomic_set(&pinstance->expose_resources, 0);
37222 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37223 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37224
37225 INIT_LIST_HEAD(&pinstance->free_res_q);
37226 INIT_LIST_HEAD(&pinstance->used_res_q);
37227 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37228 /* Schedule worker thread to handle CCN and take care of adding and
37229 * removing devices to OS
37230 */
37231 - atomic_set(&pinstance->expose_resources, 1);
37232 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37233 schedule_work(&pinstance->worker_q);
37234 return rc;
37235
37236 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37237 index e1d150f..6c6df44 100644
37238 --- a/drivers/scsi/pmcraid.h
37239 +++ b/drivers/scsi/pmcraid.h
37240 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37241 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37242
37243 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37244 - atomic_t last_message_id;
37245 + atomic_unchecked_t last_message_id;
37246
37247 /* configuration table */
37248 struct pmcraid_config_table *cfg_table;
37249 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37250 atomic_t outstanding_cmds;
37251
37252 /* should add/delete resources to mid-layer now ?*/
37253 - atomic_t expose_resources;
37254 + atomic_unchecked_t expose_resources;
37255
37256
37257
37258 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37259 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37260 };
37261 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37262 - atomic_t read_failures; /* count of failed READ commands */
37263 - atomic_t write_failures; /* count of failed WRITE commands */
37264 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37265 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37266
37267 /* To indicate add/delete/modify during CCN */
37268 u8 change_detected;
37269 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37270 index 5ab9530..2dd80f7 100644
37271 --- a/drivers/scsi/qla2xxx/qla_attr.c
37272 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37273 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37274 return 0;
37275 }
37276
37277 -struct fc_function_template qla2xxx_transport_functions = {
37278 +fc_function_template_no_const qla2xxx_transport_functions = {
37279
37280 .show_host_node_name = 1,
37281 .show_host_port_name = 1,
37282 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37283 .bsg_timeout = qla24xx_bsg_timeout,
37284 };
37285
37286 -struct fc_function_template qla2xxx_transport_vport_functions = {
37287 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37288
37289 .show_host_node_name = 1,
37290 .show_host_port_name = 1,
37291 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37292 index 39007f5..7fafc64 100644
37293 --- a/drivers/scsi/qla2xxx/qla_def.h
37294 +++ b/drivers/scsi/qla2xxx/qla_def.h
37295 @@ -2284,7 +2284,7 @@ struct isp_operations {
37296 int (*start_scsi) (srb_t *);
37297 int (*abort_isp) (struct scsi_qla_host *);
37298 int (*iospace_config)(struct qla_hw_data*);
37299 -};
37300 +} __no_const;
37301
37302 /* MSI-X Support *************************************************************/
37303
37304 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37305 index 9eacd2d..d79629c 100644
37306 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37307 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37308 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37309 struct device_attribute;
37310 extern struct device_attribute *qla2x00_host_attrs[];
37311 struct fc_function_template;
37312 -extern struct fc_function_template qla2xxx_transport_functions;
37313 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37314 +extern fc_function_template_no_const qla2xxx_transport_functions;
37315 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37316 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37317 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37318 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37319 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37320 index 7fdba7f..1b4b2c2 100644
37321 --- a/drivers/scsi/qla4xxx/ql4_def.h
37322 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37323 @@ -268,7 +268,7 @@ struct ddb_entry {
37324 * (4000 only) */
37325 atomic_t relogin_timer; /* Max Time to wait for
37326 * relogin to complete */
37327 - atomic_t relogin_retry_count; /* Num of times relogin has been
37328 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37329 * retried */
37330 uint32_t default_time2wait; /* Default Min time between
37331 * relogins (+aens) */
37332 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37333 index 9da4266..377b3b6 100644
37334 --- a/drivers/scsi/qla4xxx/ql4_os.c
37335 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37336 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37337 */
37338 if (!iscsi_is_session_online(cls_sess)) {
37339 /* Reset retry relogin timer */
37340 - atomic_inc(&ddb_entry->relogin_retry_count);
37341 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37342 DEBUG2(ql4_printk(KERN_INFO, ha,
37343 "%s: index[%d] relogin timed out-retrying"
37344 " relogin (%d), retry (%d)\n", __func__,
37345 ddb_entry->fw_ddb_index,
37346 - atomic_read(&ddb_entry->relogin_retry_count),
37347 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37348 ddb_entry->default_time2wait + 4));
37349 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37350 atomic_set(&ddb_entry->retry_relogin_timer,
37351 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37352
37353 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37354 atomic_set(&ddb_entry->relogin_timer, 0);
37355 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37356 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37357 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37358 ddb_entry->default_relogin_timeout =
37359 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37360 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37361 index 2936b44..546ecdb 100644
37362 --- a/drivers/scsi/scsi.c
37363 +++ b/drivers/scsi/scsi.c
37364 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37365 unsigned long timeout;
37366 int rtn = 0;
37367
37368 - atomic_inc(&cmd->device->iorequest_cnt);
37369 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37370
37371 /* check if the device is still usable */
37372 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37373 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37374 index faa790f..7e351ddd 100644
37375 --- a/drivers/scsi/scsi_lib.c
37376 +++ b/drivers/scsi/scsi_lib.c
37377 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37378 shost = sdev->host;
37379 scsi_init_cmd_errh(cmd);
37380 cmd->result = DID_NO_CONNECT << 16;
37381 - atomic_inc(&cmd->device->iorequest_cnt);
37382 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37383
37384 /*
37385 * SCSI request completion path will do scsi_device_unbusy(),
37386 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37387
37388 INIT_LIST_HEAD(&cmd->eh_entry);
37389
37390 - atomic_inc(&cmd->device->iodone_cnt);
37391 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37392 if (cmd->result)
37393 - atomic_inc(&cmd->device->ioerr_cnt);
37394 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37395
37396 disposition = scsi_decide_disposition(cmd);
37397 if (disposition != SUCCESS &&
37398 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37399 index ce5224c..8c6d071 100644
37400 --- a/drivers/scsi/scsi_sysfs.c
37401 +++ b/drivers/scsi/scsi_sysfs.c
37402 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37403 char *buf) \
37404 { \
37405 struct scsi_device *sdev = to_scsi_device(dev); \
37406 - unsigned long long count = atomic_read(&sdev->field); \
37407 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37408 return snprintf(buf, 20, "0x%llx\n", count); \
37409 } \
37410 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37411 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37412 index 84a1fdf..693b0d6 100644
37413 --- a/drivers/scsi/scsi_tgt_lib.c
37414 +++ b/drivers/scsi/scsi_tgt_lib.c
37415 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37416 int err;
37417
37418 dprintk("%lx %u\n", uaddr, len);
37419 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37420 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37421 if (err) {
37422 /*
37423 * TODO: need to fixup sg_tablesize, max_segment_size,
37424 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37425 index e894ca7..de9d7660 100644
37426 --- a/drivers/scsi/scsi_transport_fc.c
37427 +++ b/drivers/scsi/scsi_transport_fc.c
37428 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37429 * Netlink Infrastructure
37430 */
37431
37432 -static atomic_t fc_event_seq;
37433 +static atomic_unchecked_t fc_event_seq;
37434
37435 /**
37436 * fc_get_event_number - Obtain the next sequential FC event number
37437 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37438 u32
37439 fc_get_event_number(void)
37440 {
37441 - return atomic_add_return(1, &fc_event_seq);
37442 + return atomic_add_return_unchecked(1, &fc_event_seq);
37443 }
37444 EXPORT_SYMBOL(fc_get_event_number);
37445
37446 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37447 {
37448 int error;
37449
37450 - atomic_set(&fc_event_seq, 0);
37451 + atomic_set_unchecked(&fc_event_seq, 0);
37452
37453 error = transport_class_register(&fc_host_class);
37454 if (error)
37455 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37456 char *cp;
37457
37458 *val = simple_strtoul(buf, &cp, 0);
37459 - if ((*cp && (*cp != '\n')) || (*val < 0))
37460 + if (*cp && (*cp != '\n'))
37461 return -EINVAL;
37462 /*
37463 * Check for overflow; dev_loss_tmo is u32
37464 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37465 index fa1dfaa..4bb620c 100644
37466 --- a/drivers/scsi/scsi_transport_iscsi.c
37467 +++ b/drivers/scsi/scsi_transport_iscsi.c
37468 @@ -79,7 +79,7 @@ struct iscsi_internal {
37469 struct transport_container session_cont;
37470 };
37471
37472 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37473 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37474 static struct workqueue_struct *iscsi_eh_timer_workq;
37475
37476 static DEFINE_IDA(iscsi_sess_ida);
37477 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37478 int err;
37479
37480 ihost = shost->shost_data;
37481 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37482 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37483
37484 if (target_id == ISCSI_MAX_TARGET) {
37485 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37486 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37487 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37488 ISCSI_TRANSPORT_VERSION);
37489
37490 - atomic_set(&iscsi_session_nr, 0);
37491 + atomic_set_unchecked(&iscsi_session_nr, 0);
37492
37493 err = class_register(&iscsi_transport_class);
37494 if (err)
37495 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37496 index 21a045e..ec89e03 100644
37497 --- a/drivers/scsi/scsi_transport_srp.c
37498 +++ b/drivers/scsi/scsi_transport_srp.c
37499 @@ -33,7 +33,7 @@
37500 #include "scsi_transport_srp_internal.h"
37501
37502 struct srp_host_attrs {
37503 - atomic_t next_port_id;
37504 + atomic_unchecked_t next_port_id;
37505 };
37506 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37507
37508 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37509 struct Scsi_Host *shost = dev_to_shost(dev);
37510 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37511
37512 - atomic_set(&srp_host->next_port_id, 0);
37513 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37514 return 0;
37515 }
37516
37517 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37518 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37519 rport->roles = ids->roles;
37520
37521 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37522 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37523 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37524
37525 transport_setup_device(&rport->dev);
37526 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37527 index 4df73e5..b691c58 100644
37528 --- a/drivers/scsi/sd.c
37529 +++ b/drivers/scsi/sd.c
37530 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37531 sdkp->disk = gd;
37532 sdkp->index = index;
37533 atomic_set(&sdkp->openers, 0);
37534 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37535 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37536
37537 if (!sdp->request_queue->rq_timeout) {
37538 if (sdp->type != TYPE_MOD)
37539 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37540 index 9c5c5f2..8414557 100644
37541 --- a/drivers/scsi/sg.c
37542 +++ b/drivers/scsi/sg.c
37543 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37544 sdp->disk->disk_name,
37545 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37546 NULL,
37547 - (char *)arg);
37548 + (char __user *)arg);
37549 case BLKTRACESTART:
37550 return blk_trace_startstop(sdp->device->request_queue, 1);
37551 case BLKTRACESTOP:
37552 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37553 index 84c2861..ece0a31 100644
37554 --- a/drivers/spi/spi.c
37555 +++ b/drivers/spi/spi.c
37556 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37557 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37558
37559 /* portable code must never pass more than 32 bytes */
37560 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37561 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37562
37563 static u8 *buf;
37564
37565 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37566 index 34afc16..ffe44dd 100644
37567 --- a/drivers/staging/octeon/ethernet-rx.c
37568 +++ b/drivers/staging/octeon/ethernet-rx.c
37569 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37570 /* Increment RX stats for virtual ports */
37571 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37572 #ifdef CONFIG_64BIT
37573 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37574 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37575 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37576 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37577 #else
37578 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37579 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37580 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37581 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37582 #endif
37583 }
37584 netif_receive_skb(skb);
37585 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37586 dev->name);
37587 */
37588 #ifdef CONFIG_64BIT
37589 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37590 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37591 #else
37592 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37593 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37594 #endif
37595 dev_kfree_skb_irq(skb);
37596 }
37597 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37598 index 683bedc..86dba9a 100644
37599 --- a/drivers/staging/octeon/ethernet.c
37600 +++ b/drivers/staging/octeon/ethernet.c
37601 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37602 * since the RX tasklet also increments it.
37603 */
37604 #ifdef CONFIG_64BIT
37605 - atomic64_add(rx_status.dropped_packets,
37606 - (atomic64_t *)&priv->stats.rx_dropped);
37607 + atomic64_add_unchecked(rx_status.dropped_packets,
37608 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37609 #else
37610 - atomic_add(rx_status.dropped_packets,
37611 - (atomic_t *)&priv->stats.rx_dropped);
37612 + atomic_add_unchecked(rx_status.dropped_packets,
37613 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37614 #endif
37615 }
37616
37617 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37618 index dc23395..cf7e9b1 100644
37619 --- a/drivers/staging/rtl8712/rtl871x_io.h
37620 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37621 @@ -108,7 +108,7 @@ struct _io_ops {
37622 u8 *pmem);
37623 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37624 u8 *pmem);
37625 -};
37626 +} __no_const;
37627
37628 struct io_req {
37629 struct list_head list;
37630 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37631 index c7b5e8b..783d6cb 100644
37632 --- a/drivers/staging/sbe-2t3e3/netdev.c
37633 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37634 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37635 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37636
37637 if (rlen)
37638 - if (copy_to_user(data, &resp, rlen))
37639 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37640 return -EFAULT;
37641
37642 return 0;
37643 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37644 index 5d89c0f..9261317 100644
37645 --- a/drivers/staging/usbip/usbip_common.h
37646 +++ b/drivers/staging/usbip/usbip_common.h
37647 @@ -289,7 +289,7 @@ struct usbip_device {
37648 void (*shutdown)(struct usbip_device *);
37649 void (*reset)(struct usbip_device *);
37650 void (*unusable)(struct usbip_device *);
37651 - } eh_ops;
37652 + } __no_const eh_ops;
37653 };
37654
37655 #define kthread_get_run(threadfn, data, namefmt, ...) \
37656 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37657 index c66b8b3..a4a035b 100644
37658 --- a/drivers/staging/usbip/vhci.h
37659 +++ b/drivers/staging/usbip/vhci.h
37660 @@ -83,7 +83,7 @@ struct vhci_hcd {
37661 unsigned resuming:1;
37662 unsigned long re_timeout;
37663
37664 - atomic_t seqnum;
37665 + atomic_unchecked_t seqnum;
37666
37667 /*
37668 * NOTE:
37669 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37670 index 12a9a5f..afd8295 100644
37671 --- a/drivers/staging/usbip/vhci_hcd.c
37672 +++ b/drivers/staging/usbip/vhci_hcd.c
37673 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37674 return;
37675 }
37676
37677 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37678 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37679 if (priv->seqnum == 0xffff)
37680 dev_info(&urb->dev->dev, "seqnum max\n");
37681
37682 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37683 return -ENOMEM;
37684 }
37685
37686 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37687 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37688 if (unlink->seqnum == 0xffff)
37689 pr_info("seqnum max\n");
37690
37691 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37692 vdev->rhport = rhport;
37693 }
37694
37695 - atomic_set(&vhci->seqnum, 0);
37696 + atomic_set_unchecked(&vhci->seqnum, 0);
37697 spin_lock_init(&vhci->lock);
37698
37699 hcd->power_budget = 0; /* no limit */
37700 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37701 index f0eaf04..5a82e06 100644
37702 --- a/drivers/staging/usbip/vhci_rx.c
37703 +++ b/drivers/staging/usbip/vhci_rx.c
37704 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37705 if (!urb) {
37706 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37707 pr_info("max seqnum %d\n",
37708 - atomic_read(&the_controller->seqnum));
37709 + atomic_read_unchecked(&the_controller->seqnum));
37710 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37711 return;
37712 }
37713 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37714 index 6ac6f45..1b208ba 100644
37715 --- a/drivers/staging/vt6655/hostap.c
37716 +++ b/drivers/staging/vt6655/hostap.c
37717 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37718 *
37719 */
37720
37721 +static net_device_ops_no_const apdev_netdev_ops;
37722 +
37723 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37724 {
37725 PSDevice apdev_priv;
37726 struct net_device *dev = pDevice->dev;
37727 int ret;
37728 - const struct net_device_ops apdev_netdev_ops = {
37729 - .ndo_start_xmit = pDevice->tx_80211,
37730 - };
37731
37732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37733
37734 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37735 *apdev_priv = *pDevice;
37736 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37737
37738 + /* only half broken now */
37739 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37740 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37741
37742 pDevice->apdev->type = ARPHRD_IEEE80211;
37743 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37744 index 682002a..35ed5cf 100644
37745 --- a/drivers/staging/vt6656/hostap.c
37746 +++ b/drivers/staging/vt6656/hostap.c
37747 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37748 *
37749 */
37750
37751 +static net_device_ops_no_const apdev_netdev_ops;
37752 +
37753 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37754 {
37755 PSDevice apdev_priv;
37756 struct net_device *dev = pDevice->dev;
37757 int ret;
37758 - const struct net_device_ops apdev_netdev_ops = {
37759 - .ndo_start_xmit = pDevice->tx_80211,
37760 - };
37761
37762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37763
37764 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37765 *apdev_priv = *pDevice;
37766 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37767
37768 + /* only half broken now */
37769 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37770 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37771
37772 pDevice->apdev->type = ARPHRD_IEEE80211;
37773 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37774 index 7843dfd..3db105f 100644
37775 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37776 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37777 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37778
37779 struct usbctlx_completor {
37780 int (*complete) (struct usbctlx_completor *);
37781 -};
37782 +} __no_const;
37783
37784 static int
37785 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37786 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37787 index eaa9021..43f023b 100644
37788 --- a/drivers/staging/zcache/tmem.c
37789 +++ b/drivers/staging/zcache/tmem.c
37790 @@ -39,7 +39,7 @@
37791 * A tmem host implementation must use this function to register callbacks
37792 * for memory allocation.
37793 */
37794 -static struct tmem_hostops tmem_hostops;
37795 +static tmem_hostops_no_const tmem_hostops;
37796
37797 static void tmem_objnode_tree_init(void);
37798
37799 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37800 * A tmem host implementation must use this function to register
37801 * callbacks for a page-accessible memory (PAM) implementation
37802 */
37803 -static struct tmem_pamops tmem_pamops;
37804 +static tmem_pamops_no_const tmem_pamops;
37805
37806 void tmem_register_pamops(struct tmem_pamops *m)
37807 {
37808 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37809 index 0d4aa82..f7832d4 100644
37810 --- a/drivers/staging/zcache/tmem.h
37811 +++ b/drivers/staging/zcache/tmem.h
37812 @@ -180,6 +180,7 @@ struct tmem_pamops {
37813 void (*new_obj)(struct tmem_obj *);
37814 int (*replace_in_obj)(void *, struct tmem_obj *);
37815 };
37816 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37817 extern void tmem_register_pamops(struct tmem_pamops *m);
37818
37819 /* memory allocation methods provided by the host implementation */
37820 @@ -189,6 +190,7 @@ struct tmem_hostops {
37821 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37822 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37823 };
37824 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37825 extern void tmem_register_hostops(struct tmem_hostops *m);
37826
37827 /* core tmem accessor functions */
37828 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37829 index 269f544..32def0d 100644
37830 --- a/drivers/target/target_core_transport.c
37831 +++ b/drivers/target/target_core_transport.c
37832 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37833 spin_lock_init(&dev->se_port_lock);
37834 spin_lock_init(&dev->se_tmr_lock);
37835 spin_lock_init(&dev->qf_cmd_lock);
37836 - atomic_set(&dev->dev_ordered_id, 0);
37837 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37838
37839 se_dev_set_default_attribs(dev, dev_limits);
37840
37841 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37842 * Used to determine when ORDERED commands should go from
37843 * Dormant to Active status.
37844 */
37845 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37846 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37847 smp_mb__after_atomic_inc();
37848 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37849 cmd->se_ordered_id, cmd->sam_task_attr,
37850 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37851 index e61cabd..7617d26 100644
37852 --- a/drivers/tty/cyclades.c
37853 +++ b/drivers/tty/cyclades.c
37854 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37855 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37856 info->port.count);
37857 #endif
37858 - info->port.count++;
37859 + atomic_inc(&info->port.count);
37860 #ifdef CY_DEBUG_COUNT
37861 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37862 - current->pid, info->port.count);
37863 + current->pid, atomic_read(&info->port.count));
37864 #endif
37865
37866 /*
37867 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37868 for (j = 0; j < cy_card[i].nports; j++) {
37869 info = &cy_card[i].ports[j];
37870
37871 - if (info->port.count) {
37872 + if (atomic_read(&info->port.count)) {
37873 /* XXX is the ldisc num worth this? */
37874 struct tty_struct *tty;
37875 struct tty_ldisc *ld;
37876 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37877 index 2d691eb..be02ebd 100644
37878 --- a/drivers/tty/hvc/hvc_console.c
37879 +++ b/drivers/tty/hvc/hvc_console.c
37880 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37881
37882 spin_lock_irqsave(&hp->port.lock, flags);
37883 /* Check and then increment for fast path open. */
37884 - if (hp->port.count++ > 0) {
37885 + if (atomic_inc_return(&hp->port.count) > 1) {
37886 spin_unlock_irqrestore(&hp->port.lock, flags);
37887 hvc_kick();
37888 return 0;
37889 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37890
37891 spin_lock_irqsave(&hp->port.lock, flags);
37892
37893 - if (--hp->port.count == 0) {
37894 + if (atomic_dec_return(&hp->port.count) == 0) {
37895 spin_unlock_irqrestore(&hp->port.lock, flags);
37896 /* We are done with the tty pointer now. */
37897 tty_port_tty_set(&hp->port, NULL);
37898 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37899 */
37900 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37901 } else {
37902 - if (hp->port.count < 0)
37903 + if (atomic_read(&hp->port.count) < 0)
37904 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37905 - hp->vtermno, hp->port.count);
37906 + hp->vtermno, atomic_read(&hp->port.count));
37907 spin_unlock_irqrestore(&hp->port.lock, flags);
37908 }
37909
37910 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37911 * open->hangup case this can be called after the final close so prevent
37912 * that from happening for now.
37913 */
37914 - if (hp->port.count <= 0) {
37915 + if (atomic_read(&hp->port.count) <= 0) {
37916 spin_unlock_irqrestore(&hp->port.lock, flags);
37917 return;
37918 }
37919
37920 - temp_open_count = hp->port.count;
37921 - hp->port.count = 0;
37922 + temp_open_count = atomic_read(&hp->port.count);
37923 + atomic_set(&hp->port.count, 0);
37924 spin_unlock_irqrestore(&hp->port.lock, flags);
37925 tty_port_tty_set(&hp->port, NULL);
37926
37927 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37928 return -EPIPE;
37929
37930 /* FIXME what's this (unprotected) check for? */
37931 - if (hp->port.count <= 0)
37932 + if (atomic_read(&hp->port.count) <= 0)
37933 return -EIO;
37934
37935 spin_lock_irqsave(&hp->lock, flags);
37936 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37937 index d56788c..12d8f85 100644
37938 --- a/drivers/tty/hvc/hvcs.c
37939 +++ b/drivers/tty/hvc/hvcs.c
37940 @@ -83,6 +83,7 @@
37941 #include <asm/hvcserver.h>
37942 #include <asm/uaccess.h>
37943 #include <asm/vio.h>
37944 +#include <asm/local.h>
37945
37946 /*
37947 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37948 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37949
37950 spin_lock_irqsave(&hvcsd->lock, flags);
37951
37952 - if (hvcsd->port.count > 0) {
37953 + if (atomic_read(&hvcsd->port.count) > 0) {
37954 spin_unlock_irqrestore(&hvcsd->lock, flags);
37955 printk(KERN_INFO "HVCS: vterm state unchanged. "
37956 "The hvcs device node is still in use.\n");
37957 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37958 if ((retval = hvcs_partner_connect(hvcsd)))
37959 goto error_release;
37960
37961 - hvcsd->port.count = 1;
37962 + atomic_set(&hvcsd->port.count, 1);
37963 hvcsd->port.tty = tty;
37964 tty->driver_data = hvcsd;
37965
37966 @@ -1168,7 +1169,7 @@ fast_open:
37967
37968 spin_lock_irqsave(&hvcsd->lock, flags);
37969 tty_port_get(&hvcsd->port);
37970 - hvcsd->port.count++;
37971 + atomic_inc(&hvcsd->port.count);
37972 hvcsd->todo_mask |= HVCS_SCHED_READ;
37973 spin_unlock_irqrestore(&hvcsd->lock, flags);
37974
37975 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37976 hvcsd = tty->driver_data;
37977
37978 spin_lock_irqsave(&hvcsd->lock, flags);
37979 - if (--hvcsd->port.count == 0) {
37980 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37981
37982 vio_disable_interrupts(hvcsd->vdev);
37983
37984 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37985 free_irq(irq, hvcsd);
37986 tty_port_put(&hvcsd->port);
37987 return;
37988 - } else if (hvcsd->port.count < 0) {
37989 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37990 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37991 " is missmanaged.\n",
37992 - hvcsd->vdev->unit_address, hvcsd->port.count);
37993 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37994 }
37995
37996 spin_unlock_irqrestore(&hvcsd->lock, flags);
37997 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37998
37999 spin_lock_irqsave(&hvcsd->lock, flags);
38000 /* Preserve this so that we know how many kref refs to put */
38001 - temp_open_count = hvcsd->port.count;
38002 + temp_open_count = atomic_read(&hvcsd->port.count);
38003
38004 /*
38005 * Don't kref put inside the spinlock because the destruction
38006 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38007 tty->driver_data = NULL;
38008 hvcsd->port.tty = NULL;
38009
38010 - hvcsd->port.count = 0;
38011 + atomic_set(&hvcsd->port.count, 0);
38012
38013 /* This will drop any buffered data on the floor which is OK in a hangup
38014 * scenario. */
38015 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38016 * the middle of a write operation? This is a crummy place to do this
38017 * but we want to keep it all in the spinlock.
38018 */
38019 - if (hvcsd->port.count <= 0) {
38020 + if (atomic_read(&hvcsd->port.count) <= 0) {
38021 spin_unlock_irqrestore(&hvcsd->lock, flags);
38022 return -ENODEV;
38023 }
38024 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38025 {
38026 struct hvcs_struct *hvcsd = tty->driver_data;
38027
38028 - if (!hvcsd || hvcsd->port.count <= 0)
38029 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38030 return 0;
38031
38032 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38033 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38034 index f8b5fa0..4ba9f89 100644
38035 --- a/drivers/tty/ipwireless/tty.c
38036 +++ b/drivers/tty/ipwireless/tty.c
38037 @@ -29,6 +29,7 @@
38038 #include <linux/tty_driver.h>
38039 #include <linux/tty_flip.h>
38040 #include <linux/uaccess.h>
38041 +#include <asm/local.h>
38042
38043 #include "tty.h"
38044 #include "network.h"
38045 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38046 mutex_unlock(&tty->ipw_tty_mutex);
38047 return -ENODEV;
38048 }
38049 - if (tty->port.count == 0)
38050 + if (atomic_read(&tty->port.count) == 0)
38051 tty->tx_bytes_queued = 0;
38052
38053 - tty->port.count++;
38054 + atomic_inc(&tty->port.count);
38055
38056 tty->port.tty = linux_tty;
38057 linux_tty->driver_data = tty;
38058 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38059
38060 static void do_ipw_close(struct ipw_tty *tty)
38061 {
38062 - tty->port.count--;
38063 -
38064 - if (tty->port.count == 0) {
38065 + if (atomic_dec_return(&tty->port.count) == 0) {
38066 struct tty_struct *linux_tty = tty->port.tty;
38067
38068 if (linux_tty != NULL) {
38069 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38070 return;
38071
38072 mutex_lock(&tty->ipw_tty_mutex);
38073 - if (tty->port.count == 0) {
38074 + if (atomic_read(&tty->port.count) == 0) {
38075 mutex_unlock(&tty->ipw_tty_mutex);
38076 return;
38077 }
38078 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38079 return;
38080 }
38081
38082 - if (!tty->port.count) {
38083 + if (!atomic_read(&tty->port.count)) {
38084 mutex_unlock(&tty->ipw_tty_mutex);
38085 return;
38086 }
38087 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38088 return -ENODEV;
38089
38090 mutex_lock(&tty->ipw_tty_mutex);
38091 - if (!tty->port.count) {
38092 + if (!atomic_read(&tty->port.count)) {
38093 mutex_unlock(&tty->ipw_tty_mutex);
38094 return -EINVAL;
38095 }
38096 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38097 if (!tty)
38098 return -ENODEV;
38099
38100 - if (!tty->port.count)
38101 + if (!atomic_read(&tty->port.count))
38102 return -EINVAL;
38103
38104 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38105 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38106 if (!tty)
38107 return 0;
38108
38109 - if (!tty->port.count)
38110 + if (!atomic_read(&tty->port.count))
38111 return 0;
38112
38113 return tty->tx_bytes_queued;
38114 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38115 if (!tty)
38116 return -ENODEV;
38117
38118 - if (!tty->port.count)
38119 + if (!atomic_read(&tty->port.count))
38120 return -EINVAL;
38121
38122 return get_control_lines(tty);
38123 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38124 if (!tty)
38125 return -ENODEV;
38126
38127 - if (!tty->port.count)
38128 + if (!atomic_read(&tty->port.count))
38129 return -EINVAL;
38130
38131 return set_control_lines(tty, set, clear);
38132 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38133 if (!tty)
38134 return -ENODEV;
38135
38136 - if (!tty->port.count)
38137 + if (!atomic_read(&tty->port.count))
38138 return -EINVAL;
38139
38140 /* FIXME: Exactly how is the tty object locked here .. */
38141 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38142 * are gone */
38143 mutex_lock(&ttyj->ipw_tty_mutex);
38144 }
38145 - while (ttyj->port.count)
38146 + while (atomic_read(&ttyj->port.count))
38147 do_ipw_close(ttyj);
38148 ipwireless_disassociate_network_ttys(network,
38149 ttyj->channel_idx);
38150 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38151 index 324467d..504cc25 100644
38152 --- a/drivers/tty/moxa.c
38153 +++ b/drivers/tty/moxa.c
38154 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38155 }
38156
38157 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38158 - ch->port.count++;
38159 + atomic_inc(&ch->port.count);
38160 tty->driver_data = ch;
38161 tty_port_tty_set(&ch->port, tty);
38162 mutex_lock(&ch->port.mutex);
38163 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38164 index 90dff82..08119c3 100644
38165 --- a/drivers/tty/n_gsm.c
38166 +++ b/drivers/tty/n_gsm.c
38167 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38168 kref_init(&dlci->ref);
38169 mutex_init(&dlci->mutex);
38170 dlci->fifo = &dlci->_fifo;
38171 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38172 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38173 kfree(dlci);
38174 return NULL;
38175 }
38176 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38177 if (dlci == NULL)
38178 return -ENOMEM;
38179 port = &dlci->port;
38180 - port->count++;
38181 + atomic_inc(&port->count);
38182 tty->driver_data = dlci;
38183 dlci_get(dlci);
38184 dlci_get(dlci->gsm->dlci[0]);
38185 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38186 index 26f0d0e..b7c4273 100644
38187 --- a/drivers/tty/n_tty.c
38188 +++ b/drivers/tty/n_tty.c
38189 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38190 {
38191 *ops = tty_ldisc_N_TTY;
38192 ops->owner = NULL;
38193 - ops->refcount = ops->flags = 0;
38194 + atomic_set(&ops->refcount, 0);
38195 + ops->flags = 0;
38196 }
38197 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38198 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38199 index 5505ffc..7affff9 100644
38200 --- a/drivers/tty/pty.c
38201 +++ b/drivers/tty/pty.c
38202 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38203 panic("Couldn't register Unix98 pts driver");
38204
38205 /* Now create the /dev/ptmx special device */
38206 + pax_open_kernel();
38207 tty_default_fops(&ptmx_fops);
38208 - ptmx_fops.open = ptmx_open;
38209 + *(void **)&ptmx_fops.open = ptmx_open;
38210 + pax_close_kernel();
38211
38212 cdev_init(&ptmx_cdev, &ptmx_fops);
38213 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38214 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38215 index 777d5f9..56d67ca 100644
38216 --- a/drivers/tty/rocket.c
38217 +++ b/drivers/tty/rocket.c
38218 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38219 tty->driver_data = info;
38220 tty_port_tty_set(port, tty);
38221
38222 - if (port->count++ == 0) {
38223 + if (atomic_inc_return(&port->count) == 1) {
38224 atomic_inc(&rp_num_ports_open);
38225
38226 #ifdef ROCKET_DEBUG_OPEN
38227 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38228 #endif
38229 }
38230 #ifdef ROCKET_DEBUG_OPEN
38231 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38232 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38233 #endif
38234
38235 /*
38236 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38237 spin_unlock_irqrestore(&info->port.lock, flags);
38238 return;
38239 }
38240 - if (info->port.count)
38241 + if (atomic_read(&info->port.count))
38242 atomic_dec(&rp_num_ports_open);
38243 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38244 spin_unlock_irqrestore(&info->port.lock, flags);
38245 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38246 index 2b42a01..32a2ed3 100644
38247 --- a/drivers/tty/serial/kgdboc.c
38248 +++ b/drivers/tty/serial/kgdboc.c
38249 @@ -24,8 +24,9 @@
38250 #define MAX_CONFIG_LEN 40
38251
38252 static struct kgdb_io kgdboc_io_ops;
38253 +static struct kgdb_io kgdboc_io_ops_console;
38254
38255 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38256 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38257 static int configured = -1;
38258
38259 static char config[MAX_CONFIG_LEN];
38260 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38261 kgdboc_unregister_kbd();
38262 if (configured == 1)
38263 kgdb_unregister_io_module(&kgdboc_io_ops);
38264 + else if (configured == 2)
38265 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38266 }
38267
38268 static int configure_kgdboc(void)
38269 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38270 int err;
38271 char *cptr = config;
38272 struct console *cons;
38273 + int is_console = 0;
38274
38275 err = kgdboc_option_setup(config);
38276 if (err || !strlen(config) || isspace(config[0]))
38277 goto noconfig;
38278
38279 err = -ENODEV;
38280 - kgdboc_io_ops.is_console = 0;
38281 kgdb_tty_driver = NULL;
38282
38283 kgdboc_use_kms = 0;
38284 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38285 int idx;
38286 if (cons->device && cons->device(cons, &idx) == p &&
38287 idx == tty_line) {
38288 - kgdboc_io_ops.is_console = 1;
38289 + is_console = 1;
38290 break;
38291 }
38292 cons = cons->next;
38293 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38294 kgdb_tty_line = tty_line;
38295
38296 do_register:
38297 - err = kgdb_register_io_module(&kgdboc_io_ops);
38298 + if (is_console) {
38299 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38300 + configured = 2;
38301 + } else {
38302 + err = kgdb_register_io_module(&kgdboc_io_ops);
38303 + configured = 1;
38304 + }
38305 if (err)
38306 goto noconfig;
38307
38308 - configured = 1;
38309 -
38310 return 0;
38311
38312 noconfig:
38313 @@ -213,7 +220,7 @@ noconfig:
38314 static int __init init_kgdboc(void)
38315 {
38316 /* Already configured? */
38317 - if (configured == 1)
38318 + if (configured >= 1)
38319 return 0;
38320
38321 return configure_kgdboc();
38322 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38323 if (config[len - 1] == '\n')
38324 config[len - 1] = '\0';
38325
38326 - if (configured == 1)
38327 + if (configured >= 1)
38328 cleanup_kgdboc();
38329
38330 /* Go and configure with the new params. */
38331 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38332 .post_exception = kgdboc_post_exp_handler,
38333 };
38334
38335 +static struct kgdb_io kgdboc_io_ops_console = {
38336 + .name = "kgdboc",
38337 + .read_char = kgdboc_get_char,
38338 + .write_char = kgdboc_put_char,
38339 + .pre_exception = kgdboc_pre_exp_handler,
38340 + .post_exception = kgdboc_post_exp_handler,
38341 + .is_console = 1
38342 +};
38343 +
38344 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38345 /* This is only available if kgdboc is a built in for early debugging */
38346 static int __init kgdboc_early_init(char *opt)
38347 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38348 index a21dc8e..fe43e9e 100644
38349 --- a/drivers/tty/serial/serial_core.c
38350 +++ b/drivers/tty/serial/serial_core.c
38351 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38352 uart_flush_buffer(tty);
38353 uart_shutdown(tty, state);
38354 spin_lock_irqsave(&port->lock, flags);
38355 - port->count = 0;
38356 + atomic_set(&port->count, 0);
38357 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38358 spin_unlock_irqrestore(&port->lock, flags);
38359 tty_port_tty_set(port, NULL);
38360 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38361 goto end;
38362 }
38363
38364 - port->count++;
38365 + atomic_inc(&port->count);
38366 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38367 retval = -ENXIO;
38368 goto err_dec_count;
38369 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38370 /*
38371 * Make sure the device is in D0 state.
38372 */
38373 - if (port->count == 1)
38374 + if (atomic_read(&port->count) == 1)
38375 uart_change_pm(state, 0);
38376
38377 /*
38378 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38379 end:
38380 return retval;
38381 err_dec_count:
38382 - port->count--;
38383 + atomic_inc(&port->count);
38384 mutex_unlock(&port->mutex);
38385 goto end;
38386 }
38387 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38388 index 593d40a..bdc61f3 100644
38389 --- a/drivers/tty/synclink.c
38390 +++ b/drivers/tty/synclink.c
38391 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38392
38393 if (debug_level >= DEBUG_LEVEL_INFO)
38394 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38395 - __FILE__,__LINE__, info->device_name, info->port.count);
38396 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38397
38398 if (tty_port_close_start(&info->port, tty, filp) == 0)
38399 goto cleanup;
38400 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38401 cleanup:
38402 if (debug_level >= DEBUG_LEVEL_INFO)
38403 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38404 - tty->driver->name, info->port.count);
38405 + tty->driver->name, atomic_read(&info->port.count));
38406
38407 } /* end of mgsl_close() */
38408
38409 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38410
38411 mgsl_flush_buffer(tty);
38412 shutdown(info);
38413 -
38414 - info->port.count = 0;
38415 +
38416 + atomic_set(&info->port.count, 0);
38417 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38418 info->port.tty = NULL;
38419
38420 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38421
38422 if (debug_level >= DEBUG_LEVEL_INFO)
38423 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38424 - __FILE__,__LINE__, tty->driver->name, port->count );
38425 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38426
38427 spin_lock_irqsave(&info->irq_spinlock, flags);
38428 if (!tty_hung_up_p(filp)) {
38429 extra_count = true;
38430 - port->count--;
38431 + atomic_dec(&port->count);
38432 }
38433 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38434 port->blocked_open++;
38435 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38436
38437 if (debug_level >= DEBUG_LEVEL_INFO)
38438 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38439 - __FILE__,__LINE__, tty->driver->name, port->count );
38440 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38441
38442 tty_unlock();
38443 schedule();
38444 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38445
38446 /* FIXME: Racy on hangup during close wait */
38447 if (extra_count)
38448 - port->count++;
38449 + atomic_inc(&port->count);
38450 port->blocked_open--;
38451
38452 if (debug_level >= DEBUG_LEVEL_INFO)
38453 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38454 - __FILE__,__LINE__, tty->driver->name, port->count );
38455 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38456
38457 if (!retval)
38458 port->flags |= ASYNC_NORMAL_ACTIVE;
38459 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38460
38461 if (debug_level >= DEBUG_LEVEL_INFO)
38462 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38463 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38464 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38465
38466 /* If port is closing, signal caller to try again */
38467 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38468 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38469 spin_unlock_irqrestore(&info->netlock, flags);
38470 goto cleanup;
38471 }
38472 - info->port.count++;
38473 + atomic_inc(&info->port.count);
38474 spin_unlock_irqrestore(&info->netlock, flags);
38475
38476 - if (info->port.count == 1) {
38477 + if (atomic_read(&info->port.count) == 1) {
38478 /* 1st open on this device, init hardware */
38479 retval = startup(info);
38480 if (retval < 0)
38481 @@ -3444,8 +3444,8 @@ cleanup:
38482 if (retval) {
38483 if (tty->count == 1)
38484 info->port.tty = NULL; /* tty layer will release tty struct */
38485 - if(info->port.count)
38486 - info->port.count--;
38487 + if (atomic_read(&info->port.count))
38488 + atomic_dec(&info->port.count);
38489 }
38490
38491 return retval;
38492 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38493 unsigned short new_crctype;
38494
38495 /* return error if TTY interface open */
38496 - if (info->port.count)
38497 + if (atomic_read(&info->port.count))
38498 return -EBUSY;
38499
38500 switch (encoding)
38501 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38502
38503 /* arbitrate between network and tty opens */
38504 spin_lock_irqsave(&info->netlock, flags);
38505 - if (info->port.count != 0 || info->netcount != 0) {
38506 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38507 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38508 spin_unlock_irqrestore(&info->netlock, flags);
38509 return -EBUSY;
38510 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38511 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38512
38513 /* return error if TTY interface open */
38514 - if (info->port.count)
38515 + if (atomic_read(&info->port.count))
38516 return -EBUSY;
38517
38518 if (cmd != SIOCWANDEV)
38519 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38520 index aa1debf..9297a16 100644
38521 --- a/drivers/tty/synclink_gt.c
38522 +++ b/drivers/tty/synclink_gt.c
38523 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38524 tty->driver_data = info;
38525 info->port.tty = tty;
38526
38527 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38528 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38529
38530 /* If port is closing, signal caller to try again */
38531 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38532 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38533 mutex_unlock(&info->port.mutex);
38534 goto cleanup;
38535 }
38536 - info->port.count++;
38537 + atomic_inc(&info->port.count);
38538 spin_unlock_irqrestore(&info->netlock, flags);
38539
38540 - if (info->port.count == 1) {
38541 + if (atomic_read(&info->port.count) == 1) {
38542 /* 1st open on this device, init hardware */
38543 retval = startup(info);
38544 if (retval < 0) {
38545 @@ -716,8 +716,8 @@ cleanup:
38546 if (retval) {
38547 if (tty->count == 1)
38548 info->port.tty = NULL; /* tty layer will release tty struct */
38549 - if(info->port.count)
38550 - info->port.count--;
38551 + if(atomic_read(&info->port.count))
38552 + atomic_dec(&info->port.count);
38553 }
38554
38555 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38556 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38557
38558 if (sanity_check(info, tty->name, "close"))
38559 return;
38560 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38561 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38562
38563 if (tty_port_close_start(&info->port, tty, filp) == 0)
38564 goto cleanup;
38565 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38566 tty_port_close_end(&info->port, tty);
38567 info->port.tty = NULL;
38568 cleanup:
38569 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38570 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38571 }
38572
38573 static void hangup(struct tty_struct *tty)
38574 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38575 shutdown(info);
38576
38577 spin_lock_irqsave(&info->port.lock, flags);
38578 - info->port.count = 0;
38579 + atomic_set(&info->port.count, 0);
38580 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38581 info->port.tty = NULL;
38582 spin_unlock_irqrestore(&info->port.lock, flags);
38583 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38584 unsigned short new_crctype;
38585
38586 /* return error if TTY interface open */
38587 - if (info->port.count)
38588 + if (atomic_read(&info->port.count))
38589 return -EBUSY;
38590
38591 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38592 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38593
38594 /* arbitrate between network and tty opens */
38595 spin_lock_irqsave(&info->netlock, flags);
38596 - if (info->port.count != 0 || info->netcount != 0) {
38597 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38598 DBGINFO(("%s hdlc_open busy\n", dev->name));
38599 spin_unlock_irqrestore(&info->netlock, flags);
38600 return -EBUSY;
38601 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38602 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38603
38604 /* return error if TTY interface open */
38605 - if (info->port.count)
38606 + if (atomic_read(&info->port.count))
38607 return -EBUSY;
38608
38609 if (cmd != SIOCWANDEV)
38610 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38611 if (port == NULL)
38612 continue;
38613 spin_lock(&port->lock);
38614 - if ((port->port.count || port->netcount) &&
38615 + if ((atomic_read(&port->port.count) || port->netcount) &&
38616 port->pending_bh && !port->bh_running &&
38617 !port->bh_requested) {
38618 DBGISR(("%s bh queued\n", port->device_name));
38619 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38620 spin_lock_irqsave(&info->lock, flags);
38621 if (!tty_hung_up_p(filp)) {
38622 extra_count = true;
38623 - port->count--;
38624 + atomic_dec(&port->count);
38625 }
38626 spin_unlock_irqrestore(&info->lock, flags);
38627 port->blocked_open++;
38628 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38629 remove_wait_queue(&port->open_wait, &wait);
38630
38631 if (extra_count)
38632 - port->count++;
38633 + atomic_inc(&port->count);
38634 port->blocked_open--;
38635
38636 if (!retval)
38637 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38638 index a3dddc1..8905ab2 100644
38639 --- a/drivers/tty/synclinkmp.c
38640 +++ b/drivers/tty/synclinkmp.c
38641 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38642
38643 if (debug_level >= DEBUG_LEVEL_INFO)
38644 printk("%s(%d):%s open(), old ref count = %d\n",
38645 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38646 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38647
38648 /* If port is closing, signal caller to try again */
38649 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38650 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38651 spin_unlock_irqrestore(&info->netlock, flags);
38652 goto cleanup;
38653 }
38654 - info->port.count++;
38655 + atomic_inc(&info->port.count);
38656 spin_unlock_irqrestore(&info->netlock, flags);
38657
38658 - if (info->port.count == 1) {
38659 + if (atomic_read(&info->port.count) == 1) {
38660 /* 1st open on this device, init hardware */
38661 retval = startup(info);
38662 if (retval < 0)
38663 @@ -788,8 +788,8 @@ cleanup:
38664 if (retval) {
38665 if (tty->count == 1)
38666 info->port.tty = NULL; /* tty layer will release tty struct */
38667 - if(info->port.count)
38668 - info->port.count--;
38669 + if(atomic_read(&info->port.count))
38670 + atomic_dec(&info->port.count);
38671 }
38672
38673 return retval;
38674 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38675
38676 if (debug_level >= DEBUG_LEVEL_INFO)
38677 printk("%s(%d):%s close() entry, count=%d\n",
38678 - __FILE__,__LINE__, info->device_name, info->port.count);
38679 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38680
38681 if (tty_port_close_start(&info->port, tty, filp) == 0)
38682 goto cleanup;
38683 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38684 cleanup:
38685 if (debug_level >= DEBUG_LEVEL_INFO)
38686 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38687 - tty->driver->name, info->port.count);
38688 + tty->driver->name, atomic_read(&info->port.count));
38689 }
38690
38691 /* Called by tty_hangup() when a hangup is signaled.
38692 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38693 shutdown(info);
38694
38695 spin_lock_irqsave(&info->port.lock, flags);
38696 - info->port.count = 0;
38697 + atomic_set(&info->port.count, 0);
38698 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38699 info->port.tty = NULL;
38700 spin_unlock_irqrestore(&info->port.lock, flags);
38701 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38702 unsigned short new_crctype;
38703
38704 /* return error if TTY interface open */
38705 - if (info->port.count)
38706 + if (atomic_read(&info->port.count))
38707 return -EBUSY;
38708
38709 switch (encoding)
38710 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38711
38712 /* arbitrate between network and tty opens */
38713 spin_lock_irqsave(&info->netlock, flags);
38714 - if (info->port.count != 0 || info->netcount != 0) {
38715 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38716 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38717 spin_unlock_irqrestore(&info->netlock, flags);
38718 return -EBUSY;
38719 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38720 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38721
38722 /* return error if TTY interface open */
38723 - if (info->port.count)
38724 + if (atomic_read(&info->port.count))
38725 return -EBUSY;
38726
38727 if (cmd != SIOCWANDEV)
38728 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38729 * do not request bottom half processing if the
38730 * device is not open in a normal mode.
38731 */
38732 - if ( port && (port->port.count || port->netcount) &&
38733 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38734 port->pending_bh && !port->bh_running &&
38735 !port->bh_requested ) {
38736 if ( debug_level >= DEBUG_LEVEL_ISR )
38737 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38738
38739 if (debug_level >= DEBUG_LEVEL_INFO)
38740 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38741 - __FILE__,__LINE__, tty->driver->name, port->count );
38742 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38743
38744 spin_lock_irqsave(&info->lock, flags);
38745 if (!tty_hung_up_p(filp)) {
38746 extra_count = true;
38747 - port->count--;
38748 + atomic_dec(&port->count);
38749 }
38750 spin_unlock_irqrestore(&info->lock, flags);
38751 port->blocked_open++;
38752 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38753
38754 if (debug_level >= DEBUG_LEVEL_INFO)
38755 printk("%s(%d):%s block_til_ready() count=%d\n",
38756 - __FILE__,__LINE__, tty->driver->name, port->count );
38757 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38758
38759 tty_unlock();
38760 schedule();
38761 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38762 remove_wait_queue(&port->open_wait, &wait);
38763
38764 if (extra_count)
38765 - port->count++;
38766 + atomic_inc(&port->count);
38767 port->blocked_open--;
38768
38769 if (debug_level >= DEBUG_LEVEL_INFO)
38770 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38771 - __FILE__,__LINE__, tty->driver->name, port->count );
38772 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38773
38774 if (!retval)
38775 port->flags |= ASYNC_NORMAL_ACTIVE;
38776 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38777 index 05728894..b9d44c6 100644
38778 --- a/drivers/tty/sysrq.c
38779 +++ b/drivers/tty/sysrq.c
38780 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38781 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38782 size_t count, loff_t *ppos)
38783 {
38784 - if (count) {
38785 + if (count && capable(CAP_SYS_ADMIN)) {
38786 char c;
38787
38788 if (get_user(c, buf))
38789 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38790 index b425c79..08a3f06 100644
38791 --- a/drivers/tty/tty_io.c
38792 +++ b/drivers/tty/tty_io.c
38793 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38794
38795 void tty_default_fops(struct file_operations *fops)
38796 {
38797 - *fops = tty_fops;
38798 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38799 }
38800
38801 /*
38802 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38803 index 6f99c99..8947bc4 100644
38804 --- a/drivers/tty/tty_ldisc.c
38805 +++ b/drivers/tty/tty_ldisc.c
38806 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38807 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38808 struct tty_ldisc_ops *ldo = ld->ops;
38809
38810 - ldo->refcount--;
38811 + atomic_dec(&ldo->refcount);
38812 module_put(ldo->owner);
38813 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38814
38815 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38816 spin_lock_irqsave(&tty_ldisc_lock, flags);
38817 tty_ldiscs[disc] = new_ldisc;
38818 new_ldisc->num = disc;
38819 - new_ldisc->refcount = 0;
38820 + atomic_set(&new_ldisc->refcount, 0);
38821 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38822
38823 return ret;
38824 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38825 return -EINVAL;
38826
38827 spin_lock_irqsave(&tty_ldisc_lock, flags);
38828 - if (tty_ldiscs[disc]->refcount)
38829 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38830 ret = -EBUSY;
38831 else
38832 tty_ldiscs[disc] = NULL;
38833 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38834 if (ldops) {
38835 ret = ERR_PTR(-EAGAIN);
38836 if (try_module_get(ldops->owner)) {
38837 - ldops->refcount++;
38838 + atomic_inc(&ldops->refcount);
38839 ret = ldops;
38840 }
38841 }
38842 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38843 unsigned long flags;
38844
38845 spin_lock_irqsave(&tty_ldisc_lock, flags);
38846 - ldops->refcount--;
38847 + atomic_dec(&ldops->refcount);
38848 module_put(ldops->owner);
38849 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38850 }
38851 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38852 index bf6e238..d401c04 100644
38853 --- a/drivers/tty/tty_port.c
38854 +++ b/drivers/tty/tty_port.c
38855 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38856 unsigned long flags;
38857
38858 spin_lock_irqsave(&port->lock, flags);
38859 - port->count = 0;
38860 + atomic_set(&port->count, 0);
38861 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38862 if (port->tty) {
38863 set_bit(TTY_IO_ERROR, &port->tty->flags);
38864 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38865 /* The port lock protects the port counts */
38866 spin_lock_irqsave(&port->lock, flags);
38867 if (!tty_hung_up_p(filp))
38868 - port->count--;
38869 + atomic_dec(&port->count);
38870 port->blocked_open++;
38871 spin_unlock_irqrestore(&port->lock, flags);
38872
38873 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38874 we must not mess that up further */
38875 spin_lock_irqsave(&port->lock, flags);
38876 if (!tty_hung_up_p(filp))
38877 - port->count++;
38878 + atomic_inc(&port->count);
38879 port->blocked_open--;
38880 if (retval == 0)
38881 port->flags |= ASYNC_NORMAL_ACTIVE;
38882 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38883 return 0;
38884 }
38885
38886 - if (tty->count == 1 && port->count != 1) {
38887 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38888 printk(KERN_WARNING
38889 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38890 - port->count);
38891 - port->count = 1;
38892 + atomic_read(&port->count));
38893 + atomic_set(&port->count, 1);
38894 }
38895 - if (--port->count < 0) {
38896 + if (atomic_dec_return(&port->count) < 0) {
38897 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38898 - port->count);
38899 - port->count = 0;
38900 + atomic_read(&port->count));
38901 + atomic_set(&port->count, 0);
38902 }
38903
38904 - if (port->count) {
38905 + if (atomic_read(&port->count)) {
38906 spin_unlock_irqrestore(&port->lock, flags);
38907 if (port->ops->drop)
38908 port->ops->drop(port);
38909 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38910 {
38911 spin_lock_irq(&port->lock);
38912 if (!tty_hung_up_p(filp))
38913 - ++port->count;
38914 + atomic_inc(&port->count);
38915 spin_unlock_irq(&port->lock);
38916 tty_port_tty_set(port, tty);
38917
38918 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38919 index 770a854..e5d3db3 100644
38920 --- a/drivers/tty/vt/keyboard.c
38921 +++ b/drivers/tty/vt/keyboard.c
38922 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38923 kbd->kbdmode == VC_OFF) &&
38924 value != KVAL(K_SAK))
38925 return; /* SAK is allowed even in raw mode */
38926 +
38927 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38928 + {
38929 + void *func = fn_handler[value];
38930 + if (func == fn_show_state || func == fn_show_ptregs ||
38931 + func == fn_show_mem)
38932 + return;
38933 + }
38934 +#endif
38935 +
38936 fn_handler[value](vc);
38937 }
38938
38939 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38940 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38941 return -EFAULT;
38942
38943 - if (!capable(CAP_SYS_TTY_CONFIG))
38944 - perm = 0;
38945 -
38946 switch (cmd) {
38947 case KDGKBENT:
38948 /* Ensure another thread doesn't free it under us */
38949 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38950 spin_unlock_irqrestore(&kbd_event_lock, flags);
38951 return put_user(val, &user_kbe->kb_value);
38952 case KDSKBENT:
38953 + if (!capable(CAP_SYS_TTY_CONFIG))
38954 + perm = 0;
38955 +
38956 if (!perm)
38957 return -EPERM;
38958 if (!i && v == K_NOSUCHMAP) {
38959 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38960 int i, j, k;
38961 int ret;
38962
38963 - if (!capable(CAP_SYS_TTY_CONFIG))
38964 - perm = 0;
38965 -
38966 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38967 if (!kbs) {
38968 ret = -ENOMEM;
38969 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38970 kfree(kbs);
38971 return ((p && *p) ? -EOVERFLOW : 0);
38972 case KDSKBSENT:
38973 + if (!capable(CAP_SYS_TTY_CONFIG))
38974 + perm = 0;
38975 +
38976 if (!perm) {
38977 ret = -EPERM;
38978 goto reterr;
38979 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38980 index a783d53..cb30d94 100644
38981 --- a/drivers/uio/uio.c
38982 +++ b/drivers/uio/uio.c
38983 @@ -25,6 +25,7 @@
38984 #include <linux/kobject.h>
38985 #include <linux/cdev.h>
38986 #include <linux/uio_driver.h>
38987 +#include <asm/local.h>
38988
38989 #define UIO_MAX_DEVICES (1U << MINORBITS)
38990
38991 @@ -32,10 +33,10 @@ struct uio_device {
38992 struct module *owner;
38993 struct device *dev;
38994 int minor;
38995 - atomic_t event;
38996 + atomic_unchecked_t event;
38997 struct fasync_struct *async_queue;
38998 wait_queue_head_t wait;
38999 - int vma_count;
39000 + local_t vma_count;
39001 struct uio_info *info;
39002 struct kobject *map_dir;
39003 struct kobject *portio_dir;
39004 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39005 struct device_attribute *attr, char *buf)
39006 {
39007 struct uio_device *idev = dev_get_drvdata(dev);
39008 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39009 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39010 }
39011
39012 static struct device_attribute uio_class_attributes[] = {
39013 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39014 {
39015 struct uio_device *idev = info->uio_dev;
39016
39017 - atomic_inc(&idev->event);
39018 + atomic_inc_unchecked(&idev->event);
39019 wake_up_interruptible(&idev->wait);
39020 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39021 }
39022 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39023 }
39024
39025 listener->dev = idev;
39026 - listener->event_count = atomic_read(&idev->event);
39027 + listener->event_count = atomic_read_unchecked(&idev->event);
39028 filep->private_data = listener;
39029
39030 if (idev->info->open) {
39031 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39032 return -EIO;
39033
39034 poll_wait(filep, &idev->wait, wait);
39035 - if (listener->event_count != atomic_read(&idev->event))
39036 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39037 return POLLIN | POLLRDNORM;
39038 return 0;
39039 }
39040 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39041 do {
39042 set_current_state(TASK_INTERRUPTIBLE);
39043
39044 - event_count = atomic_read(&idev->event);
39045 + event_count = atomic_read_unchecked(&idev->event);
39046 if (event_count != listener->event_count) {
39047 if (copy_to_user(buf, &event_count, count))
39048 retval = -EFAULT;
39049 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39050 static void uio_vma_open(struct vm_area_struct *vma)
39051 {
39052 struct uio_device *idev = vma->vm_private_data;
39053 - idev->vma_count++;
39054 + local_inc(&idev->vma_count);
39055 }
39056
39057 static void uio_vma_close(struct vm_area_struct *vma)
39058 {
39059 struct uio_device *idev = vma->vm_private_data;
39060 - idev->vma_count--;
39061 + local_dec(&idev->vma_count);
39062 }
39063
39064 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39065 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39066 idev->owner = owner;
39067 idev->info = info;
39068 init_waitqueue_head(&idev->wait);
39069 - atomic_set(&idev->event, 0);
39070 + atomic_set_unchecked(&idev->event, 0);
39071
39072 ret = uio_get_minor(idev);
39073 if (ret)
39074 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39075 index b7eb86a..36d28af 100644
39076 --- a/drivers/usb/atm/cxacru.c
39077 +++ b/drivers/usb/atm/cxacru.c
39078 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39079 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39080 if (ret < 2)
39081 return -EINVAL;
39082 - if (index < 0 || index > 0x7f)
39083 + if (index > 0x7f)
39084 return -EINVAL;
39085 pos += tmp;
39086
39087 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39088 index ee62b35..b663594 100644
39089 --- a/drivers/usb/atm/usbatm.c
39090 +++ b/drivers/usb/atm/usbatm.c
39091 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39092 if (printk_ratelimit())
39093 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39094 __func__, vpi, vci);
39095 - atomic_inc(&vcc->stats->rx_err);
39096 + atomic_inc_unchecked(&vcc->stats->rx_err);
39097 return;
39098 }
39099
39100 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39101 if (length > ATM_MAX_AAL5_PDU) {
39102 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39103 __func__, length, vcc);
39104 - atomic_inc(&vcc->stats->rx_err);
39105 + atomic_inc_unchecked(&vcc->stats->rx_err);
39106 goto out;
39107 }
39108
39109 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39110 if (sarb->len < pdu_length) {
39111 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39112 __func__, pdu_length, sarb->len, vcc);
39113 - atomic_inc(&vcc->stats->rx_err);
39114 + atomic_inc_unchecked(&vcc->stats->rx_err);
39115 goto out;
39116 }
39117
39118 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39119 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39120 __func__, vcc);
39121 - atomic_inc(&vcc->stats->rx_err);
39122 + atomic_inc_unchecked(&vcc->stats->rx_err);
39123 goto out;
39124 }
39125
39126 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39127 if (printk_ratelimit())
39128 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39129 __func__, length);
39130 - atomic_inc(&vcc->stats->rx_drop);
39131 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39132 goto out;
39133 }
39134
39135 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39136
39137 vcc->push(vcc, skb);
39138
39139 - atomic_inc(&vcc->stats->rx);
39140 + atomic_inc_unchecked(&vcc->stats->rx);
39141 out:
39142 skb_trim(sarb, 0);
39143 }
39144 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39145 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39146
39147 usbatm_pop(vcc, skb);
39148 - atomic_inc(&vcc->stats->tx);
39149 + atomic_inc_unchecked(&vcc->stats->tx);
39150
39151 skb = skb_dequeue(&instance->sndqueue);
39152 }
39153 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39154 if (!left--)
39155 return sprintf(page,
39156 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39157 - atomic_read(&atm_dev->stats.aal5.tx),
39158 - atomic_read(&atm_dev->stats.aal5.tx_err),
39159 - atomic_read(&atm_dev->stats.aal5.rx),
39160 - atomic_read(&atm_dev->stats.aal5.rx_err),
39161 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39162 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39163 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39164 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39165 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39166 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39167
39168 if (!left--) {
39169 if (instance->disconnected)
39170 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39171 index 3440812..2a4ef1f 100644
39172 --- a/drivers/usb/core/devices.c
39173 +++ b/drivers/usb/core/devices.c
39174 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39175 * time it gets called.
39176 */
39177 static struct device_connect_event {
39178 - atomic_t count;
39179 + atomic_unchecked_t count;
39180 wait_queue_head_t wait;
39181 } device_event = {
39182 .count = ATOMIC_INIT(1),
39183 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39184
39185 void usbfs_conn_disc_event(void)
39186 {
39187 - atomic_add(2, &device_event.count);
39188 + atomic_add_unchecked(2, &device_event.count);
39189 wake_up(&device_event.wait);
39190 }
39191
39192 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39193
39194 poll_wait(file, &device_event.wait, wait);
39195
39196 - event_count = atomic_read(&device_event.count);
39197 + event_count = atomic_read_unchecked(&device_event.count);
39198 if (file->f_version != event_count) {
39199 file->f_version = event_count;
39200 return POLLIN | POLLRDNORM;
39201 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39202 index 89dcf15..481800b 100644
39203 --- a/drivers/usb/early/ehci-dbgp.c
39204 +++ b/drivers/usb/early/ehci-dbgp.c
39205 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39206
39207 #ifdef CONFIG_KGDB
39208 static struct kgdb_io kgdbdbgp_io_ops;
39209 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39210 +static struct kgdb_io kgdbdbgp_io_ops_console;
39211 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39212 #else
39213 #define dbgp_kgdb_mode (0)
39214 #endif
39215 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39216 .write_char = kgdbdbgp_write_char,
39217 };
39218
39219 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39220 + .name = "kgdbdbgp",
39221 + .read_char = kgdbdbgp_read_char,
39222 + .write_char = kgdbdbgp_write_char,
39223 + .is_console = 1
39224 +};
39225 +
39226 static int kgdbdbgp_wait_time;
39227
39228 static int __init kgdbdbgp_parse_config(char *str)
39229 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39230 ptr++;
39231 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39232 }
39233 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39234 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39235 + if (early_dbgp_console.index != -1)
39236 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39237 + else
39238 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39239
39240 return 0;
39241 }
39242 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39243 index da6d479..80ed10b 100644
39244 --- a/drivers/usb/gadget/u_serial.c
39245 +++ b/drivers/usb/gadget/u_serial.c
39246 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39247 spin_lock_irq(&port->port_lock);
39248
39249 /* already open? Great. */
39250 - if (port->port.count) {
39251 + if (atomic_read(&port->port.count)) {
39252 status = 0;
39253 - port->port.count++;
39254 + atomic_inc(&port->port.count);
39255
39256 /* currently opening/closing? wait ... */
39257 } else if (port->openclose) {
39258 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39259 tty->driver_data = port;
39260 port->port.tty = tty;
39261
39262 - port->port.count = 1;
39263 + atomic_set(&port->port.count, 1);
39264 port->openclose = false;
39265
39266 /* if connected, start the I/O stream */
39267 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39268
39269 spin_lock_irq(&port->port_lock);
39270
39271 - if (port->port.count != 1) {
39272 - if (port->port.count == 0)
39273 + if (atomic_read(&port->port.count) != 1) {
39274 + if (atomic_read(&port->port.count) == 0)
39275 WARN_ON(1);
39276 else
39277 - --port->port.count;
39278 + atomic_dec(&port->port.count);
39279 goto exit;
39280 }
39281
39282 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39283 * and sleep if necessary
39284 */
39285 port->openclose = true;
39286 - port->port.count = 0;
39287 + atomic_set(&port->port.count, 0);
39288
39289 gser = port->port_usb;
39290 if (gser && gser->disconnect)
39291 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39292 int cond;
39293
39294 spin_lock_irq(&port->port_lock);
39295 - cond = (port->port.count == 0) && !port->openclose;
39296 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39297 spin_unlock_irq(&port->port_lock);
39298 return cond;
39299 }
39300 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39301 /* if it's already open, start I/O ... and notify the serial
39302 * protocol about open/close status (connect/disconnect).
39303 */
39304 - if (port->port.count) {
39305 + if (atomic_read(&port->port.count)) {
39306 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39307 gs_start_io(port);
39308 if (gser->connect)
39309 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39310
39311 port->port_usb = NULL;
39312 gser->ioport = NULL;
39313 - if (port->port.count > 0 || port->openclose) {
39314 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39315 wake_up_interruptible(&port->drain_wait);
39316 if (port->port.tty)
39317 tty_hangup(port->port.tty);
39318 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39319
39320 /* finally, free any unused/unusable I/O buffers */
39321 spin_lock_irqsave(&port->port_lock, flags);
39322 - if (port->port.count == 0 && !port->openclose)
39323 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39324 gs_buf_free(&port->port_write_buf);
39325 gs_free_requests(gser->out, &port->read_pool, NULL);
39326 gs_free_requests(gser->out, &port->read_queue, NULL);
39327 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39328 index b9cca6d..75c75df 100644
39329 --- a/drivers/usb/serial/console.c
39330 +++ b/drivers/usb/serial/console.c
39331 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39332
39333 info->port = port;
39334
39335 - ++port->port.count;
39336 + atomic_inc(&port->port.count);
39337 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39338 if (serial->type->set_termios) {
39339 /*
39340 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39341 }
39342 /* Now that any required fake tty operations are completed restore
39343 * the tty port count */
39344 - --port->port.count;
39345 + atomic_dec(&port->port.count);
39346 /* The console is special in terms of closing the device so
39347 * indicate this port is now acting as a system console. */
39348 port->port.console = 1;
39349 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39350 free_tty:
39351 kfree(tty);
39352 reset_open_count:
39353 - port->port.count = 0;
39354 + atomic_set(&port->port.count, 0);
39355 usb_autopm_put_interface(serial->interface);
39356 error_get_interface:
39357 usb_serial_put(serial);
39358 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39359 index d6bea3e..60b250e 100644
39360 --- a/drivers/usb/wusbcore/wa-hc.h
39361 +++ b/drivers/usb/wusbcore/wa-hc.h
39362 @@ -192,7 +192,7 @@ struct wahc {
39363 struct list_head xfer_delayed_list;
39364 spinlock_t xfer_list_lock;
39365 struct work_struct xfer_work;
39366 - atomic_t xfer_id_count;
39367 + atomic_unchecked_t xfer_id_count;
39368 };
39369
39370
39371 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39372 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39373 spin_lock_init(&wa->xfer_list_lock);
39374 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39375 - atomic_set(&wa->xfer_id_count, 1);
39376 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39377 }
39378
39379 /**
39380 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39381 index 57c01ab..8a05959 100644
39382 --- a/drivers/usb/wusbcore/wa-xfer.c
39383 +++ b/drivers/usb/wusbcore/wa-xfer.c
39384 @@ -296,7 +296,7 @@ out:
39385 */
39386 static void wa_xfer_id_init(struct wa_xfer *xfer)
39387 {
39388 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39389 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39390 }
39391
39392 /*
39393 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39394 index ef82a0d..da8a0b3 100644
39395 --- a/drivers/vhost/vhost.c
39396 +++ b/drivers/vhost/vhost.c
39397 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39398 return 0;
39399 }
39400
39401 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39402 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39403 {
39404 struct file *eventfp, *filep = NULL,
39405 *pollstart = NULL, *pollstop = NULL;
39406 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39407 index 747442d..7c0c434 100644
39408 --- a/drivers/video/aty/aty128fb.c
39409 +++ b/drivers/video/aty/aty128fb.c
39410 @@ -149,7 +149,7 @@ enum {
39411 };
39412
39413 /* Must match above enum */
39414 -static const char *r128_family[] __devinitdata = {
39415 +static const char *r128_family[] __devinitconst = {
39416 "AGP",
39417 "PCI",
39418 "PRO AGP",
39419 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39420 index 5c3960d..15cf8fc 100644
39421 --- a/drivers/video/fbcmap.c
39422 +++ b/drivers/video/fbcmap.c
39423 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39424 rc = -ENODEV;
39425 goto out;
39426 }
39427 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39428 - !info->fbops->fb_setcmap)) {
39429 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39430 rc = -EINVAL;
39431 goto out1;
39432 }
39433 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39434 index 0dff12a..2ef47b3 100644
39435 --- a/drivers/video/fbmem.c
39436 +++ b/drivers/video/fbmem.c
39437 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39438 image->dx += image->width + 8;
39439 }
39440 } else if (rotate == FB_ROTATE_UD) {
39441 - for (x = 0; x < num && image->dx >= 0; x++) {
39442 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39443 info->fbops->fb_imageblit(info, image);
39444 image->dx -= image->width + 8;
39445 }
39446 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39447 image->dy += image->height + 8;
39448 }
39449 } else if (rotate == FB_ROTATE_CCW) {
39450 - for (x = 0; x < num && image->dy >= 0; x++) {
39451 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39452 info->fbops->fb_imageblit(info, image);
39453 image->dy -= image->height + 8;
39454 }
39455 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39456 return -EFAULT;
39457 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39458 return -EINVAL;
39459 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39460 + if (con2fb.framebuffer >= FB_MAX)
39461 return -EINVAL;
39462 if (!registered_fb[con2fb.framebuffer])
39463 request_module("fb%d", con2fb.framebuffer);
39464 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39465 index 5a5d092..265c5ed 100644
39466 --- a/drivers/video/geode/gx1fb_core.c
39467 +++ b/drivers/video/geode/gx1fb_core.c
39468 @@ -29,7 +29,7 @@ static int crt_option = 1;
39469 static char panel_option[32] = "";
39470
39471 /* Modes relevant to the GX1 (taken from modedb.c) */
39472 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39473 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39474 /* 640x480-60 VESA */
39475 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39476 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39477 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39478 index 0fad23f..0e9afa4 100644
39479 --- a/drivers/video/gxt4500.c
39480 +++ b/drivers/video/gxt4500.c
39481 @@ -156,7 +156,7 @@ struct gxt4500_par {
39482 static char *mode_option;
39483
39484 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39485 -static const struct fb_videomode defaultmode __devinitdata = {
39486 +static const struct fb_videomode defaultmode __devinitconst = {
39487 .refresh = 60,
39488 .xres = 1280,
39489 .yres = 1024,
39490 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39491 return 0;
39492 }
39493
39494 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39495 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39496 .id = "IBM GXT4500P",
39497 .type = FB_TYPE_PACKED_PIXELS,
39498 .visual = FB_VISUAL_PSEUDOCOLOR,
39499 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39500 index 7672d2e..b56437f 100644
39501 --- a/drivers/video/i810/i810_accel.c
39502 +++ b/drivers/video/i810/i810_accel.c
39503 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39504 }
39505 }
39506 printk("ringbuffer lockup!!!\n");
39507 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39508 i810_report_error(mmio);
39509 par->dev_flags |= LOCKUP;
39510 info->pixmap.scan_align = 1;
39511 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39512 index b83f361..2b05a91 100644
39513 --- a/drivers/video/i810/i810_main.c
39514 +++ b/drivers/video/i810/i810_main.c
39515 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39516 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39517
39518 /* PCI */
39519 -static const char *i810_pci_list[] __devinitdata = {
39520 +static const char *i810_pci_list[] __devinitconst = {
39521 "Intel(R) 810 Framebuffer Device" ,
39522 "Intel(R) 810-DC100 Framebuffer Device" ,
39523 "Intel(R) 810E Framebuffer Device" ,
39524 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39525 index de36693..3c63fc2 100644
39526 --- a/drivers/video/jz4740_fb.c
39527 +++ b/drivers/video/jz4740_fb.c
39528 @@ -136,7 +136,7 @@ struct jzfb {
39529 uint32_t pseudo_palette[16];
39530 };
39531
39532 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39533 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39534 .id = "JZ4740 FB",
39535 .type = FB_TYPE_PACKED_PIXELS,
39536 .visual = FB_VISUAL_TRUECOLOR,
39537 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39538 index 3c14e43..eafa544 100644
39539 --- a/drivers/video/logo/logo_linux_clut224.ppm
39540 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39541 @@ -1,1604 +1,1123 @@
39542 P3
39543 -# Standard 224-color Linux logo
39544 80 80
39545 255
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 6 6 6 6 6 6 10 10 10 10 10 10
39556 - 10 10 10 6 6 6 6 6 6 6 6 6
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 6 6 6 10 10 10 14 14 14
39575 - 22 22 22 26 26 26 30 30 30 34 34 34
39576 - 30 30 30 30 30 30 26 26 26 18 18 18
39577 - 14 14 14 10 10 10 6 6 6 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 1 0 0 1 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 6 6 6 14 14 14 26 26 26 42 42 42
39595 - 54 54 54 66 66 66 78 78 78 78 78 78
39596 - 78 78 78 74 74 74 66 66 66 54 54 54
39597 - 42 42 42 26 26 26 18 18 18 10 10 10
39598 - 6 6 6 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 1 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 10 10 10
39614 - 22 22 22 42 42 42 66 66 66 86 86 86
39615 - 66 66 66 38 38 38 38 38 38 22 22 22
39616 - 26 26 26 34 34 34 54 54 54 66 66 66
39617 - 86 86 86 70 70 70 46 46 46 26 26 26
39618 - 14 14 14 6 6 6 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 1 0 0 1 0 0 1 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 10 10 10 26 26 26
39634 - 50 50 50 82 82 82 58 58 58 6 6 6
39635 - 2 2 6 2 2 6 2 2 6 2 2 6
39636 - 2 2 6 2 2 6 2 2 6 2 2 6
39637 - 6 6 6 54 54 54 86 86 86 66 66 66
39638 - 38 38 38 18 18 18 6 6 6 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 6 6 6 22 22 22 50 50 50
39654 - 78 78 78 34 34 34 2 2 6 2 2 6
39655 - 2 2 6 2 2 6 2 2 6 2 2 6
39656 - 2 2 6 2 2 6 2 2 6 2 2 6
39657 - 2 2 6 2 2 6 6 6 6 70 70 70
39658 - 78 78 78 46 46 46 22 22 22 6 6 6
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 1 0 0 1 0 0 1 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 6 6 6 18 18 18 42 42 42 82 82 82
39674 - 26 26 26 2 2 6 2 2 6 2 2 6
39675 - 2 2 6 2 2 6 2 2 6 2 2 6
39676 - 2 2 6 2 2 6 2 2 6 14 14 14
39677 - 46 46 46 34 34 34 6 6 6 2 2 6
39678 - 42 42 42 78 78 78 42 42 42 18 18 18
39679 - 6 6 6 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 1 0 0 0 0 0 1 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 10 10 10 30 30 30 66 66 66 58 58 58
39694 - 2 2 6 2 2 6 2 2 6 2 2 6
39695 - 2 2 6 2 2 6 2 2 6 2 2 6
39696 - 2 2 6 2 2 6 2 2 6 26 26 26
39697 - 86 86 86 101 101 101 46 46 46 10 10 10
39698 - 2 2 6 58 58 58 70 70 70 34 34 34
39699 - 10 10 10 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 1 0 0 1 0 0 1 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 14 14 14 42 42 42 86 86 86 10 10 10
39714 - 2 2 6 2 2 6 2 2 6 2 2 6
39715 - 2 2 6 2 2 6 2 2 6 2 2 6
39716 - 2 2 6 2 2 6 2 2 6 30 30 30
39717 - 94 94 94 94 94 94 58 58 58 26 26 26
39718 - 2 2 6 6 6 6 78 78 78 54 54 54
39719 - 22 22 22 6 6 6 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 6 6 6
39733 - 22 22 22 62 62 62 62 62 62 2 2 6
39734 - 2 2 6 2 2 6 2 2 6 2 2 6
39735 - 2 2 6 2 2 6 2 2 6 2 2 6
39736 - 2 2 6 2 2 6 2 2 6 26 26 26
39737 - 54 54 54 38 38 38 18 18 18 10 10 10
39738 - 2 2 6 2 2 6 34 34 34 82 82 82
39739 - 38 38 38 14 14 14 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 1 0 0 1 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 6 6 6
39753 - 30 30 30 78 78 78 30 30 30 2 2 6
39754 - 2 2 6 2 2 6 2 2 6 2 2 6
39755 - 2 2 6 2 2 6 2 2 6 2 2 6
39756 - 2 2 6 2 2 6 2 2 6 10 10 10
39757 - 10 10 10 2 2 6 2 2 6 2 2 6
39758 - 2 2 6 2 2 6 2 2 6 78 78 78
39759 - 50 50 50 18 18 18 6 6 6 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 1 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 10 10 10
39773 - 38 38 38 86 86 86 14 14 14 2 2 6
39774 - 2 2 6 2 2 6 2 2 6 2 2 6
39775 - 2 2 6 2 2 6 2 2 6 2 2 6
39776 - 2 2 6 2 2 6 2 2 6 2 2 6
39777 - 2 2 6 2 2 6 2 2 6 2 2 6
39778 - 2 2 6 2 2 6 2 2 6 54 54 54
39779 - 66 66 66 26 26 26 6 6 6 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 1 0 0 1 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 14 14 14
39793 - 42 42 42 82 82 82 2 2 6 2 2 6
39794 - 2 2 6 6 6 6 10 10 10 2 2 6
39795 - 2 2 6 2 2 6 2 2 6 2 2 6
39796 - 2 2 6 2 2 6 2 2 6 6 6 6
39797 - 14 14 14 10 10 10 2 2 6 2 2 6
39798 - 2 2 6 2 2 6 2 2 6 18 18 18
39799 - 82 82 82 34 34 34 10 10 10 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 1 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 14 14 14
39813 - 46 46 46 86 86 86 2 2 6 2 2 6
39814 - 6 6 6 6 6 6 22 22 22 34 34 34
39815 - 6 6 6 2 2 6 2 2 6 2 2 6
39816 - 2 2 6 2 2 6 18 18 18 34 34 34
39817 - 10 10 10 50 50 50 22 22 22 2 2 6
39818 - 2 2 6 2 2 6 2 2 6 10 10 10
39819 - 86 86 86 42 42 42 14 14 14 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 1 0 0 1 0 0 1 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 14 14 14
39833 - 46 46 46 86 86 86 2 2 6 2 2 6
39834 - 38 38 38 116 116 116 94 94 94 22 22 22
39835 - 22 22 22 2 2 6 2 2 6 2 2 6
39836 - 14 14 14 86 86 86 138 138 138 162 162 162
39837 -154 154 154 38 38 38 26 26 26 6 6 6
39838 - 2 2 6 2 2 6 2 2 6 2 2 6
39839 - 86 86 86 46 46 46 14 14 14 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 14 14 14
39853 - 46 46 46 86 86 86 2 2 6 14 14 14
39854 -134 134 134 198 198 198 195 195 195 116 116 116
39855 - 10 10 10 2 2 6 2 2 6 6 6 6
39856 -101 98 89 187 187 187 210 210 210 218 218 218
39857 -214 214 214 134 134 134 14 14 14 6 6 6
39858 - 2 2 6 2 2 6 2 2 6 2 2 6
39859 - 86 86 86 50 50 50 18 18 18 6 6 6
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 1 0 0 0
39867 - 0 0 1 0 0 1 0 0 1 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 14 14 14
39873 - 46 46 46 86 86 86 2 2 6 54 54 54
39874 -218 218 218 195 195 195 226 226 226 246 246 246
39875 - 58 58 58 2 2 6 2 2 6 30 30 30
39876 -210 210 210 253 253 253 174 174 174 123 123 123
39877 -221 221 221 234 234 234 74 74 74 2 2 6
39878 - 2 2 6 2 2 6 2 2 6 2 2 6
39879 - 70 70 70 58 58 58 22 22 22 6 6 6
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 14 14 14
39893 - 46 46 46 82 82 82 2 2 6 106 106 106
39894 -170 170 170 26 26 26 86 86 86 226 226 226
39895 -123 123 123 10 10 10 14 14 14 46 46 46
39896 -231 231 231 190 190 190 6 6 6 70 70 70
39897 - 90 90 90 238 238 238 158 158 158 2 2 6
39898 - 2 2 6 2 2 6 2 2 6 2 2 6
39899 - 70 70 70 58 58 58 22 22 22 6 6 6
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 1 0 0 0
39907 - 0 0 1 0 0 1 0 0 1 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 14 14 14
39913 - 42 42 42 86 86 86 6 6 6 116 116 116
39914 -106 106 106 6 6 6 70 70 70 149 149 149
39915 -128 128 128 18 18 18 38 38 38 54 54 54
39916 -221 221 221 106 106 106 2 2 6 14 14 14
39917 - 46 46 46 190 190 190 198 198 198 2 2 6
39918 - 2 2 6 2 2 6 2 2 6 2 2 6
39919 - 74 74 74 62 62 62 22 22 22 6 6 6
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 1 0 0 0
39927 - 0 0 1 0 0 0 0 0 1 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 14 14 14
39933 - 42 42 42 94 94 94 14 14 14 101 101 101
39934 -128 128 128 2 2 6 18 18 18 116 116 116
39935 -118 98 46 121 92 8 121 92 8 98 78 10
39936 -162 162 162 106 106 106 2 2 6 2 2 6
39937 - 2 2 6 195 195 195 195 195 195 6 6 6
39938 - 2 2 6 2 2 6 2 2 6 2 2 6
39939 - 74 74 74 62 62 62 22 22 22 6 6 6
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 1 0 0 1
39947 - 0 0 1 0 0 0 0 0 1 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 10 10 10
39953 - 38 38 38 90 90 90 14 14 14 58 58 58
39954 -210 210 210 26 26 26 54 38 6 154 114 10
39955 -226 170 11 236 186 11 225 175 15 184 144 12
39956 -215 174 15 175 146 61 37 26 9 2 2 6
39957 - 70 70 70 246 246 246 138 138 138 2 2 6
39958 - 2 2 6 2 2 6 2 2 6 2 2 6
39959 - 70 70 70 66 66 66 26 26 26 6 6 6
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39973 - 38 38 38 86 86 86 14 14 14 10 10 10
39974 -195 195 195 188 164 115 192 133 9 225 175 15
39975 -239 182 13 234 190 10 232 195 16 232 200 30
39976 -245 207 45 241 208 19 232 195 16 184 144 12
39977 -218 194 134 211 206 186 42 42 42 2 2 6
39978 - 2 2 6 2 2 6 2 2 6 2 2 6
39979 - 50 50 50 74 74 74 30 30 30 6 6 6
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 10 10 10
39993 - 34 34 34 86 86 86 14 14 14 2 2 6
39994 -121 87 25 192 133 9 219 162 10 239 182 13
39995 -236 186 11 232 195 16 241 208 19 244 214 54
39996 -246 218 60 246 218 38 246 215 20 241 208 19
39997 -241 208 19 226 184 13 121 87 25 2 2 6
39998 - 2 2 6 2 2 6 2 2 6 2 2 6
39999 - 50 50 50 82 82 82 34 34 34 10 10 10
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 10 10 10
40013 - 34 34 34 82 82 82 30 30 30 61 42 6
40014 -180 123 7 206 145 10 230 174 11 239 182 13
40015 -234 190 10 238 202 15 241 208 19 246 218 74
40016 -246 218 38 246 215 20 246 215 20 246 215 20
40017 -226 184 13 215 174 15 184 144 12 6 6 6
40018 - 2 2 6 2 2 6 2 2 6 2 2 6
40019 - 26 26 26 94 94 94 42 42 42 14 14 14
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 10 10 10
40033 - 30 30 30 78 78 78 50 50 50 104 69 6
40034 -192 133 9 216 158 10 236 178 12 236 186 11
40035 -232 195 16 241 208 19 244 214 54 245 215 43
40036 -246 215 20 246 215 20 241 208 19 198 155 10
40037 -200 144 11 216 158 10 156 118 10 2 2 6
40038 - 2 2 6 2 2 6 2 2 6 2 2 6
40039 - 6 6 6 90 90 90 54 54 54 18 18 18
40040 - 6 6 6 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 10 10 10
40053 - 30 30 30 78 78 78 46 46 46 22 22 22
40054 -137 92 6 210 162 10 239 182 13 238 190 10
40055 -238 202 15 241 208 19 246 215 20 246 215 20
40056 -241 208 19 203 166 17 185 133 11 210 150 10
40057 -216 158 10 210 150 10 102 78 10 2 2 6
40058 - 6 6 6 54 54 54 14 14 14 2 2 6
40059 - 2 2 6 62 62 62 74 74 74 30 30 30
40060 - 10 10 10 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 10 10 10
40073 - 34 34 34 78 78 78 50 50 50 6 6 6
40074 - 94 70 30 139 102 15 190 146 13 226 184 13
40075 -232 200 30 232 195 16 215 174 15 190 146 13
40076 -168 122 10 192 133 9 210 150 10 213 154 11
40077 -202 150 34 182 157 106 101 98 89 2 2 6
40078 - 2 2 6 78 78 78 116 116 116 58 58 58
40079 - 2 2 6 22 22 22 90 90 90 46 46 46
40080 - 18 18 18 6 6 6 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 10 10 10
40093 - 38 38 38 86 86 86 50 50 50 6 6 6
40094 -128 128 128 174 154 114 156 107 11 168 122 10
40095 -198 155 10 184 144 12 197 138 11 200 144 11
40096 -206 145 10 206 145 10 197 138 11 188 164 115
40097 -195 195 195 198 198 198 174 174 174 14 14 14
40098 - 2 2 6 22 22 22 116 116 116 116 116 116
40099 - 22 22 22 2 2 6 74 74 74 70 70 70
40100 - 30 30 30 10 10 10 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 6 6 6 18 18 18
40113 - 50 50 50 101 101 101 26 26 26 10 10 10
40114 -138 138 138 190 190 190 174 154 114 156 107 11
40115 -197 138 11 200 144 11 197 138 11 192 133 9
40116 -180 123 7 190 142 34 190 178 144 187 187 187
40117 -202 202 202 221 221 221 214 214 214 66 66 66
40118 - 2 2 6 2 2 6 50 50 50 62 62 62
40119 - 6 6 6 2 2 6 10 10 10 90 90 90
40120 - 50 50 50 18 18 18 6 6 6 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 10 10 10 34 34 34
40133 - 74 74 74 74 74 74 2 2 6 6 6 6
40134 -144 144 144 198 198 198 190 190 190 178 166 146
40135 -154 121 60 156 107 11 156 107 11 168 124 44
40136 -174 154 114 187 187 187 190 190 190 210 210 210
40137 -246 246 246 253 253 253 253 253 253 182 182 182
40138 - 6 6 6 2 2 6 2 2 6 2 2 6
40139 - 2 2 6 2 2 6 2 2 6 62 62 62
40140 - 74 74 74 34 34 34 14 14 14 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 10 10 10 22 22 22 54 54 54
40153 - 94 94 94 18 18 18 2 2 6 46 46 46
40154 -234 234 234 221 221 221 190 190 190 190 190 190
40155 -190 190 190 187 187 187 187 187 187 190 190 190
40156 -190 190 190 195 195 195 214 214 214 242 242 242
40157 -253 253 253 253 253 253 253 253 253 253 253 253
40158 - 82 82 82 2 2 6 2 2 6 2 2 6
40159 - 2 2 6 2 2 6 2 2 6 14 14 14
40160 - 86 86 86 54 54 54 22 22 22 6 6 6
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 6 6 6 18 18 18 46 46 46 90 90 90
40173 - 46 46 46 18 18 18 6 6 6 182 182 182
40174 -253 253 253 246 246 246 206 206 206 190 190 190
40175 -190 190 190 190 190 190 190 190 190 190 190 190
40176 -206 206 206 231 231 231 250 250 250 253 253 253
40177 -253 253 253 253 253 253 253 253 253 253 253 253
40178 -202 202 202 14 14 14 2 2 6 2 2 6
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 42 42 42 86 86 86 42 42 42 18 18 18
40181 - 6 6 6 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 6 6 6
40192 - 14 14 14 38 38 38 74 74 74 66 66 66
40193 - 2 2 6 6 6 6 90 90 90 250 250 250
40194 -253 253 253 253 253 253 238 238 238 198 198 198
40195 -190 190 190 190 190 190 195 195 195 221 221 221
40196 -246 246 246 253 253 253 253 253 253 253 253 253
40197 -253 253 253 253 253 253 253 253 253 253 253 253
40198 -253 253 253 82 82 82 2 2 6 2 2 6
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 2 2 6 78 78 78 70 70 70 34 34 34
40201 - 14 14 14 6 6 6 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 14 14 14
40212 - 34 34 34 66 66 66 78 78 78 6 6 6
40213 - 2 2 6 18 18 18 218 218 218 253 253 253
40214 -253 253 253 253 253 253 253 253 253 246 246 246
40215 -226 226 226 231 231 231 246 246 246 253 253 253
40216 -253 253 253 253 253 253 253 253 253 253 253 253
40217 -253 253 253 253 253 253 253 253 253 253 253 253
40218 -253 253 253 178 178 178 2 2 6 2 2 6
40219 - 2 2 6 2 2 6 2 2 6 2 2 6
40220 - 2 2 6 18 18 18 90 90 90 62 62 62
40221 - 30 30 30 10 10 10 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 10 10 10 26 26 26
40232 - 58 58 58 90 90 90 18 18 18 2 2 6
40233 - 2 2 6 110 110 110 253 253 253 253 253 253
40234 -253 253 253 253 253 253 253 253 253 253 253 253
40235 -250 250 250 253 253 253 253 253 253 253 253 253
40236 -253 253 253 253 253 253 253 253 253 253 253 253
40237 -253 253 253 253 253 253 253 253 253 253 253 253
40238 -253 253 253 231 231 231 18 18 18 2 2 6
40239 - 2 2 6 2 2 6 2 2 6 2 2 6
40240 - 2 2 6 2 2 6 18 18 18 94 94 94
40241 - 54 54 54 26 26 26 10 10 10 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 6 6 6 22 22 22 50 50 50
40252 - 90 90 90 26 26 26 2 2 6 2 2 6
40253 - 14 14 14 195 195 195 250 250 250 253 253 253
40254 -253 253 253 253 253 253 253 253 253 253 253 253
40255 -253 253 253 253 253 253 253 253 253 253 253 253
40256 -253 253 253 253 253 253 253 253 253 253 253 253
40257 -253 253 253 253 253 253 253 253 253 253 253 253
40258 -250 250 250 242 242 242 54 54 54 2 2 6
40259 - 2 2 6 2 2 6 2 2 6 2 2 6
40260 - 2 2 6 2 2 6 2 2 6 38 38 38
40261 - 86 86 86 50 50 50 22 22 22 6 6 6
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 6 6 6 14 14 14 38 38 38 82 82 82
40272 - 34 34 34 2 2 6 2 2 6 2 2 6
40273 - 42 42 42 195 195 195 246 246 246 253 253 253
40274 -253 253 253 253 253 253 253 253 253 250 250 250
40275 -242 242 242 242 242 242 250 250 250 253 253 253
40276 -253 253 253 253 253 253 253 253 253 253 253 253
40277 -253 253 253 250 250 250 246 246 246 238 238 238
40278 -226 226 226 231 231 231 101 101 101 6 6 6
40279 - 2 2 6 2 2 6 2 2 6 2 2 6
40280 - 2 2 6 2 2 6 2 2 6 2 2 6
40281 - 38 38 38 82 82 82 42 42 42 14 14 14
40282 - 6 6 6 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 10 10 10 26 26 26 62 62 62 66 66 66
40292 - 2 2 6 2 2 6 2 2 6 6 6 6
40293 - 70 70 70 170 170 170 206 206 206 234 234 234
40294 -246 246 246 250 250 250 250 250 250 238 238 238
40295 -226 226 226 231 231 231 238 238 238 250 250 250
40296 -250 250 250 250 250 250 246 246 246 231 231 231
40297 -214 214 214 206 206 206 202 202 202 202 202 202
40298 -198 198 198 202 202 202 182 182 182 18 18 18
40299 - 2 2 6 2 2 6 2 2 6 2 2 6
40300 - 2 2 6 2 2 6 2 2 6 2 2 6
40301 - 2 2 6 62 62 62 66 66 66 30 30 30
40302 - 10 10 10 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 14 14 14 42 42 42 82 82 82 18 18 18
40312 - 2 2 6 2 2 6 2 2 6 10 10 10
40313 - 94 94 94 182 182 182 218 218 218 242 242 242
40314 -250 250 250 253 253 253 253 253 253 250 250 250
40315 -234 234 234 253 253 253 253 253 253 253 253 253
40316 -253 253 253 253 253 253 253 253 253 246 246 246
40317 -238 238 238 226 226 226 210 210 210 202 202 202
40318 -195 195 195 195 195 195 210 210 210 158 158 158
40319 - 6 6 6 14 14 14 50 50 50 14 14 14
40320 - 2 2 6 2 2 6 2 2 6 2 2 6
40321 - 2 2 6 6 6 6 86 86 86 46 46 46
40322 - 18 18 18 6 6 6 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 6 6 6
40331 - 22 22 22 54 54 54 70 70 70 2 2 6
40332 - 2 2 6 10 10 10 2 2 6 22 22 22
40333 -166 166 166 231 231 231 250 250 250 253 253 253
40334 -253 253 253 253 253 253 253 253 253 250 250 250
40335 -242 242 242 253 253 253 253 253 253 253 253 253
40336 -253 253 253 253 253 253 253 253 253 253 253 253
40337 -253 253 253 253 253 253 253 253 253 246 246 246
40338 -231 231 231 206 206 206 198 198 198 226 226 226
40339 - 94 94 94 2 2 6 6 6 6 38 38 38
40340 - 30 30 30 2 2 6 2 2 6 2 2 6
40341 - 2 2 6 2 2 6 62 62 62 66 66 66
40342 - 26 26 26 10 10 10 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 10 10 10
40351 - 30 30 30 74 74 74 50 50 50 2 2 6
40352 - 26 26 26 26 26 26 2 2 6 106 106 106
40353 -238 238 238 253 253 253 253 253 253 253 253 253
40354 -253 253 253 253 253 253 253 253 253 253 253 253
40355 -253 253 253 253 253 253 253 253 253 253 253 253
40356 -253 253 253 253 253 253 253 253 253 253 253 253
40357 -253 253 253 253 253 253 253 253 253 253 253 253
40358 -253 253 253 246 246 246 218 218 218 202 202 202
40359 -210 210 210 14 14 14 2 2 6 2 2 6
40360 - 30 30 30 22 22 22 2 2 6 2 2 6
40361 - 2 2 6 2 2 6 18 18 18 86 86 86
40362 - 42 42 42 14 14 14 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 0 0 0 0 0 0
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 14 14 14
40371 - 42 42 42 90 90 90 22 22 22 2 2 6
40372 - 42 42 42 2 2 6 18 18 18 218 218 218
40373 -253 253 253 253 253 253 253 253 253 253 253 253
40374 -253 253 253 253 253 253 253 253 253 253 253 253
40375 -253 253 253 253 253 253 253 253 253 253 253 253
40376 -253 253 253 253 253 253 253 253 253 253 253 253
40377 -253 253 253 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 250 250 250 221 221 221
40379 -218 218 218 101 101 101 2 2 6 14 14 14
40380 - 18 18 18 38 38 38 10 10 10 2 2 6
40381 - 2 2 6 2 2 6 2 2 6 78 78 78
40382 - 58 58 58 22 22 22 6 6 6 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 0 0 0 0 0 0
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 6 6 6 18 18 18
40391 - 54 54 54 82 82 82 2 2 6 26 26 26
40392 - 22 22 22 2 2 6 123 123 123 253 253 253
40393 -253 253 253 253 253 253 253 253 253 253 253 253
40394 -253 253 253 253 253 253 253 253 253 253 253 253
40395 -253 253 253 253 253 253 253 253 253 253 253 253
40396 -253 253 253 253 253 253 253 253 253 253 253 253
40397 -253 253 253 253 253 253 253 253 253 253 253 253
40398 -253 253 253 253 253 253 253 253 253 250 250 250
40399 -238 238 238 198 198 198 6 6 6 38 38 38
40400 - 58 58 58 26 26 26 38 38 38 2 2 6
40401 - 2 2 6 2 2 6 2 2 6 46 46 46
40402 - 78 78 78 30 30 30 10 10 10 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 0 0 0 0 0 0
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 10 10 10 30 30 30
40411 - 74 74 74 58 58 58 2 2 6 42 42 42
40412 - 2 2 6 22 22 22 231 231 231 253 253 253
40413 -253 253 253 253 253 253 253 253 253 253 253 253
40414 -253 253 253 253 253 253 253 253 253 250 250 250
40415 -253 253 253 253 253 253 253 253 253 253 253 253
40416 -253 253 253 253 253 253 253 253 253 253 253 253
40417 -253 253 253 253 253 253 253 253 253 253 253 253
40418 -253 253 253 253 253 253 253 253 253 253 253 253
40419 -253 253 253 246 246 246 46 46 46 38 38 38
40420 - 42 42 42 14 14 14 38 38 38 14 14 14
40421 - 2 2 6 2 2 6 2 2 6 6 6 6
40422 - 86 86 86 46 46 46 14 14 14 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 0 0 0
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 6 6 6 14 14 14 42 42 42
40431 - 90 90 90 18 18 18 18 18 18 26 26 26
40432 - 2 2 6 116 116 116 253 253 253 253 253 253
40433 -253 253 253 253 253 253 253 253 253 253 253 253
40434 -253 253 253 253 253 253 250 250 250 238 238 238
40435 -253 253 253 253 253 253 253 253 253 253 253 253
40436 -253 253 253 253 253 253 253 253 253 253 253 253
40437 -253 253 253 253 253 253 253 253 253 253 253 253
40438 -253 253 253 253 253 253 253 253 253 253 253 253
40439 -253 253 253 253 253 253 94 94 94 6 6 6
40440 - 2 2 6 2 2 6 10 10 10 34 34 34
40441 - 2 2 6 2 2 6 2 2 6 2 2 6
40442 - 74 74 74 58 58 58 22 22 22 6 6 6
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 0 0 0 0 0 0 0 0 0 0 0 0
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 10 10 10 26 26 26 66 66 66
40451 - 82 82 82 2 2 6 38 38 38 6 6 6
40452 - 14 14 14 210 210 210 253 253 253 253 253 253
40453 -253 253 253 253 253 253 253 253 253 253 253 253
40454 -253 253 253 253 253 253 246 246 246 242 242 242
40455 -253 253 253 253 253 253 253 253 253 253 253 253
40456 -253 253 253 253 253 253 253 253 253 253 253 253
40457 -253 253 253 253 253 253 253 253 253 253 253 253
40458 -253 253 253 253 253 253 253 253 253 253 253 253
40459 -253 253 253 253 253 253 144 144 144 2 2 6
40460 - 2 2 6 2 2 6 2 2 6 46 46 46
40461 - 2 2 6 2 2 6 2 2 6 2 2 6
40462 - 42 42 42 74 74 74 30 30 30 10 10 10
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 0 0 0
40466 - 0 0 0 0 0 0 0 0 0 0 0 0
40467 - 0 0 0 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 6 6 6 14 14 14 42 42 42 90 90 90
40471 - 26 26 26 6 6 6 42 42 42 2 2 6
40472 - 74 74 74 250 250 250 253 253 253 253 253 253
40473 -253 253 253 253 253 253 253 253 253 253 253 253
40474 -253 253 253 253 253 253 242 242 242 242 242 242
40475 -253 253 253 253 253 253 253 253 253 253 253 253
40476 -253 253 253 253 253 253 253 253 253 253 253 253
40477 -253 253 253 253 253 253 253 253 253 253 253 253
40478 -253 253 253 253 253 253 253 253 253 253 253 253
40479 -253 253 253 253 253 253 182 182 182 2 2 6
40480 - 2 2 6 2 2 6 2 2 6 46 46 46
40481 - 2 2 6 2 2 6 2 2 6 2 2 6
40482 - 10 10 10 86 86 86 38 38 38 10 10 10
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 0 0 0
40486 - 0 0 0 0 0 0 0 0 0 0 0 0
40487 - 0 0 0 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 10 10 10 26 26 26 66 66 66 82 82 82
40491 - 2 2 6 22 22 22 18 18 18 2 2 6
40492 -149 149 149 253 253 253 253 253 253 253 253 253
40493 -253 253 253 253 253 253 253 253 253 253 253 253
40494 -253 253 253 253 253 253 234 234 234 242 242 242
40495 -253 253 253 253 253 253 253 253 253 253 253 253
40496 -253 253 253 253 253 253 253 253 253 253 253 253
40497 -253 253 253 253 253 253 253 253 253 253 253 253
40498 -253 253 253 253 253 253 253 253 253 253 253 253
40499 -253 253 253 253 253 253 206 206 206 2 2 6
40500 - 2 2 6 2 2 6 2 2 6 38 38 38
40501 - 2 2 6 2 2 6 2 2 6 2 2 6
40502 - 6 6 6 86 86 86 46 46 46 14 14 14
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 0 0 0
40506 - 0 0 0 0 0 0 0 0 0 0 0 0
40507 - 0 0 0 0 0 0 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 6 6 6
40510 - 18 18 18 46 46 46 86 86 86 18 18 18
40511 - 2 2 6 34 34 34 10 10 10 6 6 6
40512 -210 210 210 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 253 253 253 253 253 253
40514 -253 253 253 253 253 253 234 234 234 242 242 242
40515 -253 253 253 253 253 253 253 253 253 253 253 253
40516 -253 253 253 253 253 253 253 253 253 253 253 253
40517 -253 253 253 253 253 253 253 253 253 253 253 253
40518 -253 253 253 253 253 253 253 253 253 253 253 253
40519 -253 253 253 253 253 253 221 221 221 6 6 6
40520 - 2 2 6 2 2 6 6 6 6 30 30 30
40521 - 2 2 6 2 2 6 2 2 6 2 2 6
40522 - 2 2 6 82 82 82 54 54 54 18 18 18
40523 - 6 6 6 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 0 0 0
40526 - 0 0 0 0 0 0 0 0 0 0 0 0
40527 - 0 0 0 0 0 0 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 10 10 10
40530 - 26 26 26 66 66 66 62 62 62 2 2 6
40531 - 2 2 6 38 38 38 10 10 10 26 26 26
40532 -238 238 238 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 253 253 253 253 253 253
40534 -253 253 253 253 253 253 231 231 231 238 238 238
40535 -253 253 253 253 253 253 253 253 253 253 253 253
40536 -253 253 253 253 253 253 253 253 253 253 253 253
40537 -253 253 253 253 253 253 253 253 253 253 253 253
40538 -253 253 253 253 253 253 253 253 253 253 253 253
40539 -253 253 253 253 253 253 231 231 231 6 6 6
40540 - 2 2 6 2 2 6 10 10 10 30 30 30
40541 - 2 2 6 2 2 6 2 2 6 2 2 6
40542 - 2 2 6 66 66 66 58 58 58 22 22 22
40543 - 6 6 6 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 0 0 0
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 0 0 0 0 0 0 0 0 0 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 10 10 10
40550 - 38 38 38 78 78 78 6 6 6 2 2 6
40551 - 2 2 6 46 46 46 14 14 14 42 42 42
40552 -246 246 246 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 253 253 253 253 253 253
40554 -253 253 253 253 253 253 231 231 231 242 242 242
40555 -253 253 253 253 253 253 253 253 253 253 253 253
40556 -253 253 253 253 253 253 253 253 253 253 253 253
40557 -253 253 253 253 253 253 253 253 253 253 253 253
40558 -253 253 253 253 253 253 253 253 253 253 253 253
40559 -253 253 253 253 253 253 234 234 234 10 10 10
40560 - 2 2 6 2 2 6 22 22 22 14 14 14
40561 - 2 2 6 2 2 6 2 2 6 2 2 6
40562 - 2 2 6 66 66 66 62 62 62 22 22 22
40563 - 6 6 6 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 0 0 0 0 0 0
40566 - 0 0 0 0 0 0 0 0 0 0 0 0
40567 - 0 0 0 0 0 0 0 0 0 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 6 6 6 18 18 18
40570 - 50 50 50 74 74 74 2 2 6 2 2 6
40571 - 14 14 14 70 70 70 34 34 34 62 62 62
40572 -250 250 250 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 253 253 253
40574 -253 253 253 253 253 253 231 231 231 246 246 246
40575 -253 253 253 253 253 253 253 253 253 253 253 253
40576 -253 253 253 253 253 253 253 253 253 253 253 253
40577 -253 253 253 253 253 253 253 253 253 253 253 253
40578 -253 253 253 253 253 253 253 253 253 253 253 253
40579 -253 253 253 253 253 253 234 234 234 14 14 14
40580 - 2 2 6 2 2 6 30 30 30 2 2 6
40581 - 2 2 6 2 2 6 2 2 6 2 2 6
40582 - 2 2 6 66 66 66 62 62 62 22 22 22
40583 - 6 6 6 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 0 0 0 0 0 0 0 0 0
40586 - 0 0 0 0 0 0 0 0 0 0 0 0
40587 - 0 0 0 0 0 0 0 0 0 0 0 0
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 6 6 6 18 18 18
40590 - 54 54 54 62 62 62 2 2 6 2 2 6
40591 - 2 2 6 30 30 30 46 46 46 70 70 70
40592 -250 250 250 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 253 253 253 253 253 253
40594 -253 253 253 253 253 253 231 231 231 246 246 246
40595 -253 253 253 253 253 253 253 253 253 253 253 253
40596 -253 253 253 253 253 253 253 253 253 253 253 253
40597 -253 253 253 253 253 253 253 253 253 253 253 253
40598 -253 253 253 253 253 253 253 253 253 253 253 253
40599 -253 253 253 253 253 253 226 226 226 10 10 10
40600 - 2 2 6 6 6 6 30 30 30 2 2 6
40601 - 2 2 6 2 2 6 2 2 6 2 2 6
40602 - 2 2 6 66 66 66 58 58 58 22 22 22
40603 - 6 6 6 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 0 0 0 0 0 0
40606 - 0 0 0 0 0 0 0 0 0 0 0 0
40607 - 0 0 0 0 0 0 0 0 0 0 0 0
40608 - 0 0 0 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 6 6 6 22 22 22
40610 - 58 58 58 62 62 62 2 2 6 2 2 6
40611 - 2 2 6 2 2 6 30 30 30 78 78 78
40612 -250 250 250 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 253 253 253 253 253 253
40614 -253 253 253 253 253 253 231 231 231 246 246 246
40615 -253 253 253 253 253 253 253 253 253 253 253 253
40616 -253 253 253 253 253 253 253 253 253 253 253 253
40617 -253 253 253 253 253 253 253 253 253 253 253 253
40618 -253 253 253 253 253 253 253 253 253 253 253 253
40619 -253 253 253 253 253 253 206 206 206 2 2 6
40620 - 22 22 22 34 34 34 18 14 6 22 22 22
40621 - 26 26 26 18 18 18 6 6 6 2 2 6
40622 - 2 2 6 82 82 82 54 54 54 18 18 18
40623 - 6 6 6 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 0 0 0 0 0 0
40626 - 0 0 0 0 0 0 0 0 0 0 0 0
40627 - 0 0 0 0 0 0 0 0 0 0 0 0
40628 - 0 0 0 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 6 6 6 26 26 26
40630 - 62 62 62 106 106 106 74 54 14 185 133 11
40631 -210 162 10 121 92 8 6 6 6 62 62 62
40632 -238 238 238 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 231 231 231 246 246 246
40635 -253 253 253 253 253 253 253 253 253 253 253 253
40636 -253 253 253 253 253 253 253 253 253 253 253 253
40637 -253 253 253 253 253 253 253 253 253 253 253 253
40638 -253 253 253 253 253 253 253 253 253 253 253 253
40639 -253 253 253 253 253 253 158 158 158 18 18 18
40640 - 14 14 14 2 2 6 2 2 6 2 2 6
40641 - 6 6 6 18 18 18 66 66 66 38 38 38
40642 - 6 6 6 94 94 94 50 50 50 18 18 18
40643 - 6 6 6 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 0 0 0
40646 - 0 0 0 0 0 0 0 0 0 0 0 0
40647 - 0 0 0 0 0 0 0 0 0 0 0 0
40648 - 0 0 0 0 0 0 0 0 0 6 6 6
40649 - 10 10 10 10 10 10 18 18 18 38 38 38
40650 - 78 78 78 142 134 106 216 158 10 242 186 14
40651 -246 190 14 246 190 14 156 118 10 10 10 10
40652 - 90 90 90 238 238 238 253 253 253 253 253 253
40653 -253 253 253 253 253 253 253 253 253 253 253 253
40654 -253 253 253 253 253 253 231 231 231 250 250 250
40655 -253 253 253 253 253 253 253 253 253 253 253 253
40656 -253 253 253 253 253 253 253 253 253 253 253 253
40657 -253 253 253 253 253 253 253 253 253 253 253 253
40658 -253 253 253 253 253 253 253 253 253 246 230 190
40659 -238 204 91 238 204 91 181 142 44 37 26 9
40660 - 2 2 6 2 2 6 2 2 6 2 2 6
40661 - 2 2 6 2 2 6 38 38 38 46 46 46
40662 - 26 26 26 106 106 106 54 54 54 18 18 18
40663 - 6 6 6 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 0 0 0
40666 - 0 0 0 0 0 0 0 0 0 0 0 0
40667 - 0 0 0 0 0 0 0 0 0 0 0 0
40668 - 0 0 0 6 6 6 14 14 14 22 22 22
40669 - 30 30 30 38 38 38 50 50 50 70 70 70
40670 -106 106 106 190 142 34 226 170 11 242 186 14
40671 -246 190 14 246 190 14 246 190 14 154 114 10
40672 - 6 6 6 74 74 74 226 226 226 253 253 253
40673 -253 253 253 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 231 231 231 250 250 250
40675 -253 253 253 253 253 253 253 253 253 253 253 253
40676 -253 253 253 253 253 253 253 253 253 253 253 253
40677 -253 253 253 253 253 253 253 253 253 253 253 253
40678 -253 253 253 253 253 253 253 253 253 228 184 62
40679 -241 196 14 241 208 19 232 195 16 38 30 10
40680 - 2 2 6 2 2 6 2 2 6 2 2 6
40681 - 2 2 6 6 6 6 30 30 30 26 26 26
40682 -203 166 17 154 142 90 66 66 66 26 26 26
40683 - 6 6 6 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 0 0 0
40685 - 0 0 0 0 0 0 0 0 0 0 0 0
40686 - 0 0 0 0 0 0 0 0 0 0 0 0
40687 - 0 0 0 0 0 0 0 0 0 0 0 0
40688 - 6 6 6 18 18 18 38 38 38 58 58 58
40689 - 78 78 78 86 86 86 101 101 101 123 123 123
40690 -175 146 61 210 150 10 234 174 13 246 186 14
40691 -246 190 14 246 190 14 246 190 14 238 190 10
40692 -102 78 10 2 2 6 46 46 46 198 198 198
40693 -253 253 253 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 234 234 234 242 242 242
40695 -253 253 253 253 253 253 253 253 253 253 253 253
40696 -253 253 253 253 253 253 253 253 253 253 253 253
40697 -253 253 253 253 253 253 253 253 253 253 253 253
40698 -253 253 253 253 253 253 253 253 253 224 178 62
40699 -242 186 14 241 196 14 210 166 10 22 18 6
40700 - 2 2 6 2 2 6 2 2 6 2 2 6
40701 - 2 2 6 2 2 6 6 6 6 121 92 8
40702 -238 202 15 232 195 16 82 82 82 34 34 34
40703 - 10 10 10 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 0 0 0 0 0 0 0 0 0 0 0 0
40707 - 0 0 0 0 0 0 0 0 0 0 0 0
40708 - 14 14 14 38 38 38 70 70 70 154 122 46
40709 -190 142 34 200 144 11 197 138 11 197 138 11
40710 -213 154 11 226 170 11 242 186 14 246 190 14
40711 -246 190 14 246 190 14 246 190 14 246 190 14
40712 -225 175 15 46 32 6 2 2 6 22 22 22
40713 -158 158 158 250 250 250 253 253 253 253 253 253
40714 -253 253 253 253 253 253 253 253 253 253 253 253
40715 -253 253 253 253 253 253 253 253 253 253 253 253
40716 -253 253 253 253 253 253 253 253 253 253 253 253
40717 -253 253 253 253 253 253 253 253 253 253 253 253
40718 -253 253 253 250 250 250 242 242 242 224 178 62
40719 -239 182 13 236 186 11 213 154 11 46 32 6
40720 - 2 2 6 2 2 6 2 2 6 2 2 6
40721 - 2 2 6 2 2 6 61 42 6 225 175 15
40722 -238 190 10 236 186 11 112 100 78 42 42 42
40723 - 14 14 14 0 0 0 0 0 0 0 0 0
40724 - 0 0 0 0 0 0 0 0 0 0 0 0
40725 - 0 0 0 0 0 0 0 0 0 0 0 0
40726 - 0 0 0 0 0 0 0 0 0 0 0 0
40727 - 0 0 0 0 0 0 0 0 0 6 6 6
40728 - 22 22 22 54 54 54 154 122 46 213 154 11
40729 -226 170 11 230 174 11 226 170 11 226 170 11
40730 -236 178 12 242 186 14 246 190 14 246 190 14
40731 -246 190 14 246 190 14 246 190 14 246 190 14
40732 -241 196 14 184 144 12 10 10 10 2 2 6
40733 - 6 6 6 116 116 116 242 242 242 253 253 253
40734 -253 253 253 253 253 253 253 253 253 253 253 253
40735 -253 253 253 253 253 253 253 253 253 253 253 253
40736 -253 253 253 253 253 253 253 253 253 253 253 253
40737 -253 253 253 253 253 253 253 253 253 253 253 253
40738 -253 253 253 231 231 231 198 198 198 214 170 54
40739 -236 178 12 236 178 12 210 150 10 137 92 6
40740 - 18 14 6 2 2 6 2 2 6 2 2 6
40741 - 6 6 6 70 47 6 200 144 11 236 178 12
40742 -239 182 13 239 182 13 124 112 88 58 58 58
40743 - 22 22 22 6 6 6 0 0 0 0 0 0
40744 - 0 0 0 0 0 0 0 0 0 0 0 0
40745 - 0 0 0 0 0 0 0 0 0 0 0 0
40746 - 0 0 0 0 0 0 0 0 0 0 0 0
40747 - 0 0 0 0 0 0 0 0 0 10 10 10
40748 - 30 30 30 70 70 70 180 133 36 226 170 11
40749 -239 182 13 242 186 14 242 186 14 246 186 14
40750 -246 190 14 246 190 14 246 190 14 246 190 14
40751 -246 190 14 246 190 14 246 190 14 246 190 14
40752 -246 190 14 232 195 16 98 70 6 2 2 6
40753 - 2 2 6 2 2 6 66 66 66 221 221 221
40754 -253 253 253 253 253 253 253 253 253 253 253 253
40755 -253 253 253 253 253 253 253 253 253 253 253 253
40756 -253 253 253 253 253 253 253 253 253 253 253 253
40757 -253 253 253 253 253 253 253 253 253 253 253 253
40758 -253 253 253 206 206 206 198 198 198 214 166 58
40759 -230 174 11 230 174 11 216 158 10 192 133 9
40760 -163 110 8 116 81 8 102 78 10 116 81 8
40761 -167 114 7 197 138 11 226 170 11 239 182 13
40762 -242 186 14 242 186 14 162 146 94 78 78 78
40763 - 34 34 34 14 14 14 6 6 6 0 0 0
40764 - 0 0 0 0 0 0 0 0 0 0 0 0
40765 - 0 0 0 0 0 0 0 0 0 0 0 0
40766 - 0 0 0 0 0 0 0 0 0 0 0 0
40767 - 0 0 0 0 0 0 0 0 0 6 6 6
40768 - 30 30 30 78 78 78 190 142 34 226 170 11
40769 -239 182 13 246 190 14 246 190 14 246 190 14
40770 -246 190 14 246 190 14 246 190 14 246 190 14
40771 -246 190 14 246 190 14 246 190 14 246 190 14
40772 -246 190 14 241 196 14 203 166 17 22 18 6
40773 - 2 2 6 2 2 6 2 2 6 38 38 38
40774 -218 218 218 253 253 253 253 253 253 253 253 253
40775 -253 253 253 253 253 253 253 253 253 253 253 253
40776 -253 253 253 253 253 253 253 253 253 253 253 253
40777 -253 253 253 253 253 253 253 253 253 253 253 253
40778 -250 250 250 206 206 206 198 198 198 202 162 69
40779 -226 170 11 236 178 12 224 166 10 210 150 10
40780 -200 144 11 197 138 11 192 133 9 197 138 11
40781 -210 150 10 226 170 11 242 186 14 246 190 14
40782 -246 190 14 246 186 14 225 175 15 124 112 88
40783 - 62 62 62 30 30 30 14 14 14 6 6 6
40784 - 0 0 0 0 0 0 0 0 0 0 0 0
40785 - 0 0 0 0 0 0 0 0 0 0 0 0
40786 - 0 0 0 0 0 0 0 0 0 0 0 0
40787 - 0 0 0 0 0 0 0 0 0 10 10 10
40788 - 30 30 30 78 78 78 174 135 50 224 166 10
40789 -239 182 13 246 190 14 246 190 14 246 190 14
40790 -246 190 14 246 190 14 246 190 14 246 190 14
40791 -246 190 14 246 190 14 246 190 14 246 190 14
40792 -246 190 14 246 190 14 241 196 14 139 102 15
40793 - 2 2 6 2 2 6 2 2 6 2 2 6
40794 - 78 78 78 250 250 250 253 253 253 253 253 253
40795 -253 253 253 253 253 253 253 253 253 253 253 253
40796 -253 253 253 253 253 253 253 253 253 253 253 253
40797 -253 253 253 253 253 253 253 253 253 253 253 253
40798 -250 250 250 214 214 214 198 198 198 190 150 46
40799 -219 162 10 236 178 12 234 174 13 224 166 10
40800 -216 158 10 213 154 11 213 154 11 216 158 10
40801 -226 170 11 239 182 13 246 190 14 246 190 14
40802 -246 190 14 246 190 14 242 186 14 206 162 42
40803 -101 101 101 58 58 58 30 30 30 14 14 14
40804 - 6 6 6 0 0 0 0 0 0 0 0 0
40805 - 0 0 0 0 0 0 0 0 0 0 0 0
40806 - 0 0 0 0 0 0 0 0 0 0 0 0
40807 - 0 0 0 0 0 0 0 0 0 10 10 10
40808 - 30 30 30 74 74 74 174 135 50 216 158 10
40809 -236 178 12 246 190 14 246 190 14 246 190 14
40810 -246 190 14 246 190 14 246 190 14 246 190 14
40811 -246 190 14 246 190 14 246 190 14 246 190 14
40812 -246 190 14 246 190 14 241 196 14 226 184 13
40813 - 61 42 6 2 2 6 2 2 6 2 2 6
40814 - 22 22 22 238 238 238 253 253 253 253 253 253
40815 -253 253 253 253 253 253 253 253 253 253 253 253
40816 -253 253 253 253 253 253 253 253 253 253 253 253
40817 -253 253 253 253 253 253 253 253 253 253 253 253
40818 -253 253 253 226 226 226 187 187 187 180 133 36
40819 -216 158 10 236 178 12 239 182 13 236 178 12
40820 -230 174 11 226 170 11 226 170 11 230 174 11
40821 -236 178 12 242 186 14 246 190 14 246 190 14
40822 -246 190 14 246 190 14 246 186 14 239 182 13
40823 -206 162 42 106 106 106 66 66 66 34 34 34
40824 - 14 14 14 6 6 6 0 0 0 0 0 0
40825 - 0 0 0 0 0 0 0 0 0 0 0 0
40826 - 0 0 0 0 0 0 0 0 0 0 0 0
40827 - 0 0 0 0 0 0 0 0 0 6 6 6
40828 - 26 26 26 70 70 70 163 133 67 213 154 11
40829 -236 178 12 246 190 14 246 190 14 246 190 14
40830 -246 190 14 246 190 14 246 190 14 246 190 14
40831 -246 190 14 246 190 14 246 190 14 246 190 14
40832 -246 190 14 246 190 14 246 190 14 241 196 14
40833 -190 146 13 18 14 6 2 2 6 2 2 6
40834 - 46 46 46 246 246 246 253 253 253 253 253 253
40835 -253 253 253 253 253 253 253 253 253 253 253 253
40836 -253 253 253 253 253 253 253 253 253 253 253 253
40837 -253 253 253 253 253 253 253 253 253 253 253 253
40838 -253 253 253 221 221 221 86 86 86 156 107 11
40839 -216 158 10 236 178 12 242 186 14 246 186 14
40840 -242 186 14 239 182 13 239 182 13 242 186 14
40841 -242 186 14 246 186 14 246 190 14 246 190 14
40842 -246 190 14 246 190 14 246 190 14 246 190 14
40843 -242 186 14 225 175 15 142 122 72 66 66 66
40844 - 30 30 30 10 10 10 0 0 0 0 0 0
40845 - 0 0 0 0 0 0 0 0 0 0 0 0
40846 - 0 0 0 0 0 0 0 0 0 0 0 0
40847 - 0 0 0 0 0 0 0 0 0 6 6 6
40848 - 26 26 26 70 70 70 163 133 67 210 150 10
40849 -236 178 12 246 190 14 246 190 14 246 190 14
40850 -246 190 14 246 190 14 246 190 14 246 190 14
40851 -246 190 14 246 190 14 246 190 14 246 190 14
40852 -246 190 14 246 190 14 246 190 14 246 190 14
40853 -232 195 16 121 92 8 34 34 34 106 106 106
40854 -221 221 221 253 253 253 253 253 253 253 253 253
40855 -253 253 253 253 253 253 253 253 253 253 253 253
40856 -253 253 253 253 253 253 253 253 253 253 253 253
40857 -253 253 253 253 253 253 253 253 253 253 253 253
40858 -242 242 242 82 82 82 18 14 6 163 110 8
40859 -216 158 10 236 178 12 242 186 14 246 190 14
40860 -246 190 14 246 190 14 246 190 14 246 190 14
40861 -246 190 14 246 190 14 246 190 14 246 190 14
40862 -246 190 14 246 190 14 246 190 14 246 190 14
40863 -246 190 14 246 190 14 242 186 14 163 133 67
40864 - 46 46 46 18 18 18 6 6 6 0 0 0
40865 - 0 0 0 0 0 0 0 0 0 0 0 0
40866 - 0 0 0 0 0 0 0 0 0 0 0 0
40867 - 0 0 0 0 0 0 0 0 0 10 10 10
40868 - 30 30 30 78 78 78 163 133 67 210 150 10
40869 -236 178 12 246 186 14 246 190 14 246 190 14
40870 -246 190 14 246 190 14 246 190 14 246 190 14
40871 -246 190 14 246 190 14 246 190 14 246 190 14
40872 -246 190 14 246 190 14 246 190 14 246 190 14
40873 -241 196 14 215 174 15 190 178 144 253 253 253
40874 -253 253 253 253 253 253 253 253 253 253 253 253
40875 -253 253 253 253 253 253 253 253 253 253 253 253
40876 -253 253 253 253 253 253 253 253 253 253 253 253
40877 -253 253 253 253 253 253 253 253 253 218 218 218
40878 - 58 58 58 2 2 6 22 18 6 167 114 7
40879 -216 158 10 236 178 12 246 186 14 246 190 14
40880 -246 190 14 246 190 14 246 190 14 246 190 14
40881 -246 190 14 246 190 14 246 190 14 246 190 14
40882 -246 190 14 246 190 14 246 190 14 246 190 14
40883 -246 190 14 246 186 14 242 186 14 190 150 46
40884 - 54 54 54 22 22 22 6 6 6 0 0 0
40885 - 0 0 0 0 0 0 0 0 0 0 0 0
40886 - 0 0 0 0 0 0 0 0 0 0 0 0
40887 - 0 0 0 0 0 0 0 0 0 14 14 14
40888 - 38 38 38 86 86 86 180 133 36 213 154 11
40889 -236 178 12 246 186 14 246 190 14 246 190 14
40890 -246 190 14 246 190 14 246 190 14 246 190 14
40891 -246 190 14 246 190 14 246 190 14 246 190 14
40892 -246 190 14 246 190 14 246 190 14 246 190 14
40893 -246 190 14 232 195 16 190 146 13 214 214 214
40894 -253 253 253 253 253 253 253 253 253 253 253 253
40895 -253 253 253 253 253 253 253 253 253 253 253 253
40896 -253 253 253 253 253 253 253 253 253 253 253 253
40897 -253 253 253 250 250 250 170 170 170 26 26 26
40898 - 2 2 6 2 2 6 37 26 9 163 110 8
40899 -219 162 10 239 182 13 246 186 14 246 190 14
40900 -246 190 14 246 190 14 246 190 14 246 190 14
40901 -246 190 14 246 190 14 246 190 14 246 190 14
40902 -246 190 14 246 190 14 246 190 14 246 190 14
40903 -246 186 14 236 178 12 224 166 10 142 122 72
40904 - 46 46 46 18 18 18 6 6 6 0 0 0
40905 - 0 0 0 0 0 0 0 0 0 0 0 0
40906 - 0 0 0 0 0 0 0 0 0 0 0 0
40907 - 0 0 0 0 0 0 6 6 6 18 18 18
40908 - 50 50 50 109 106 95 192 133 9 224 166 10
40909 -242 186 14 246 190 14 246 190 14 246 190 14
40910 -246 190 14 246 190 14 246 190 14 246 190 14
40911 -246 190 14 246 190 14 246 190 14 246 190 14
40912 -246 190 14 246 190 14 246 190 14 246 190 14
40913 -242 186 14 226 184 13 210 162 10 142 110 46
40914 -226 226 226 253 253 253 253 253 253 253 253 253
40915 -253 253 253 253 253 253 253 253 253 253 253 253
40916 -253 253 253 253 253 253 253 253 253 253 253 253
40917 -198 198 198 66 66 66 2 2 6 2 2 6
40918 - 2 2 6 2 2 6 50 34 6 156 107 11
40919 -219 162 10 239 182 13 246 186 14 246 190 14
40920 -246 190 14 246 190 14 246 190 14 246 190 14
40921 -246 190 14 246 190 14 246 190 14 246 190 14
40922 -246 190 14 246 190 14 246 190 14 242 186 14
40923 -234 174 13 213 154 11 154 122 46 66 66 66
40924 - 30 30 30 10 10 10 0 0 0 0 0 0
40925 - 0 0 0 0 0 0 0 0 0 0 0 0
40926 - 0 0 0 0 0 0 0 0 0 0 0 0
40927 - 0 0 0 0 0 0 6 6 6 22 22 22
40928 - 58 58 58 154 121 60 206 145 10 234 174 13
40929 -242 186 14 246 186 14 246 190 14 246 190 14
40930 -246 190 14 246 190 14 246 190 14 246 190 14
40931 -246 190 14 246 190 14 246 190 14 246 190 14
40932 -246 190 14 246 190 14 246 190 14 246 190 14
40933 -246 186 14 236 178 12 210 162 10 163 110 8
40934 - 61 42 6 138 138 138 218 218 218 250 250 250
40935 -253 253 253 253 253 253 253 253 253 250 250 250
40936 -242 242 242 210 210 210 144 144 144 66 66 66
40937 - 6 6 6 2 2 6 2 2 6 2 2 6
40938 - 2 2 6 2 2 6 61 42 6 163 110 8
40939 -216 158 10 236 178 12 246 190 14 246 190 14
40940 -246 190 14 246 190 14 246 190 14 246 190 14
40941 -246 190 14 246 190 14 246 190 14 246 190 14
40942 -246 190 14 239 182 13 230 174 11 216 158 10
40943 -190 142 34 124 112 88 70 70 70 38 38 38
40944 - 18 18 18 6 6 6 0 0 0 0 0 0
40945 - 0 0 0 0 0 0 0 0 0 0 0 0
40946 - 0 0 0 0 0 0 0 0 0 0 0 0
40947 - 0 0 0 0 0 0 6 6 6 22 22 22
40948 - 62 62 62 168 124 44 206 145 10 224 166 10
40949 -236 178 12 239 182 13 242 186 14 242 186 14
40950 -246 186 14 246 190 14 246 190 14 246 190 14
40951 -246 190 14 246 190 14 246 190 14 246 190 14
40952 -246 190 14 246 190 14 246 190 14 246 190 14
40953 -246 190 14 236 178 12 216 158 10 175 118 6
40954 - 80 54 7 2 2 6 6 6 6 30 30 30
40955 - 54 54 54 62 62 62 50 50 50 38 38 38
40956 - 14 14 14 2 2 6 2 2 6 2 2 6
40957 - 2 2 6 2 2 6 2 2 6 2 2 6
40958 - 2 2 6 6 6 6 80 54 7 167 114 7
40959 -213 154 11 236 178 12 246 190 14 246 190 14
40960 -246 190 14 246 190 14 246 190 14 246 190 14
40961 -246 190 14 242 186 14 239 182 13 239 182 13
40962 -230 174 11 210 150 10 174 135 50 124 112 88
40963 - 82 82 82 54 54 54 34 34 34 18 18 18
40964 - 6 6 6 0 0 0 0 0 0 0 0 0
40965 - 0 0 0 0 0 0 0 0 0 0 0 0
40966 - 0 0 0 0 0 0 0 0 0 0 0 0
40967 - 0 0 0 0 0 0 6 6 6 18 18 18
40968 - 50 50 50 158 118 36 192 133 9 200 144 11
40969 -216 158 10 219 162 10 224 166 10 226 170 11
40970 -230 174 11 236 178 12 239 182 13 239 182 13
40971 -242 186 14 246 186 14 246 190 14 246 190 14
40972 -246 190 14 246 190 14 246 190 14 246 190 14
40973 -246 186 14 230 174 11 210 150 10 163 110 8
40974 -104 69 6 10 10 10 2 2 6 2 2 6
40975 - 2 2 6 2 2 6 2 2 6 2 2 6
40976 - 2 2 6 2 2 6 2 2 6 2 2 6
40977 - 2 2 6 2 2 6 2 2 6 2 2 6
40978 - 2 2 6 6 6 6 91 60 6 167 114 7
40979 -206 145 10 230 174 11 242 186 14 246 190 14
40980 -246 190 14 246 190 14 246 186 14 242 186 14
40981 -239 182 13 230 174 11 224 166 10 213 154 11
40982 -180 133 36 124 112 88 86 86 86 58 58 58
40983 - 38 38 38 22 22 22 10 10 10 6 6 6
40984 - 0 0 0 0 0 0 0 0 0 0 0 0
40985 - 0 0 0 0 0 0 0 0 0 0 0 0
40986 - 0 0 0 0 0 0 0 0 0 0 0 0
40987 - 0 0 0 0 0 0 0 0 0 14 14 14
40988 - 34 34 34 70 70 70 138 110 50 158 118 36
40989 -167 114 7 180 123 7 192 133 9 197 138 11
40990 -200 144 11 206 145 10 213 154 11 219 162 10
40991 -224 166 10 230 174 11 239 182 13 242 186 14
40992 -246 186 14 246 186 14 246 186 14 246 186 14
40993 -239 182 13 216 158 10 185 133 11 152 99 6
40994 -104 69 6 18 14 6 2 2 6 2 2 6
40995 - 2 2 6 2 2 6 2 2 6 2 2 6
40996 - 2 2 6 2 2 6 2 2 6 2 2 6
40997 - 2 2 6 2 2 6 2 2 6 2 2 6
40998 - 2 2 6 6 6 6 80 54 7 152 99 6
40999 -192 133 9 219 162 10 236 178 12 239 182 13
41000 -246 186 14 242 186 14 239 182 13 236 178 12
41001 -224 166 10 206 145 10 192 133 9 154 121 60
41002 - 94 94 94 62 62 62 42 42 42 22 22 22
41003 - 14 14 14 6 6 6 0 0 0 0 0 0
41004 - 0 0 0 0 0 0 0 0 0 0 0 0
41005 - 0 0 0 0 0 0 0 0 0 0 0 0
41006 - 0 0 0 0 0 0 0 0 0 0 0 0
41007 - 0 0 0 0 0 0 0 0 0 6 6 6
41008 - 18 18 18 34 34 34 58 58 58 78 78 78
41009 -101 98 89 124 112 88 142 110 46 156 107 11
41010 -163 110 8 167 114 7 175 118 6 180 123 7
41011 -185 133 11 197 138 11 210 150 10 219 162 10
41012 -226 170 11 236 178 12 236 178 12 234 174 13
41013 -219 162 10 197 138 11 163 110 8 130 83 6
41014 - 91 60 6 10 10 10 2 2 6 2 2 6
41015 - 18 18 18 38 38 38 38 38 38 38 38 38
41016 - 38 38 38 38 38 38 38 38 38 38 38 38
41017 - 38 38 38 38 38 38 26 26 26 2 2 6
41018 - 2 2 6 6 6 6 70 47 6 137 92 6
41019 -175 118 6 200 144 11 219 162 10 230 174 11
41020 -234 174 13 230 174 11 219 162 10 210 150 10
41021 -192 133 9 163 110 8 124 112 88 82 82 82
41022 - 50 50 50 30 30 30 14 14 14 6 6 6
41023 - 0 0 0 0 0 0 0 0 0 0 0 0
41024 - 0 0 0 0 0 0 0 0 0 0 0 0
41025 - 0 0 0 0 0 0 0 0 0 0 0 0
41026 - 0 0 0 0 0 0 0 0 0 0 0 0
41027 - 0 0 0 0 0 0 0 0 0 0 0 0
41028 - 6 6 6 14 14 14 22 22 22 34 34 34
41029 - 42 42 42 58 58 58 74 74 74 86 86 86
41030 -101 98 89 122 102 70 130 98 46 121 87 25
41031 -137 92 6 152 99 6 163 110 8 180 123 7
41032 -185 133 11 197 138 11 206 145 10 200 144 11
41033 -180 123 7 156 107 11 130 83 6 104 69 6
41034 - 50 34 6 54 54 54 110 110 110 101 98 89
41035 - 86 86 86 82 82 82 78 78 78 78 78 78
41036 - 78 78 78 78 78 78 78 78 78 78 78 78
41037 - 78 78 78 82 82 82 86 86 86 94 94 94
41038 -106 106 106 101 101 101 86 66 34 124 80 6
41039 -156 107 11 180 123 7 192 133 9 200 144 11
41040 -206 145 10 200 144 11 192 133 9 175 118 6
41041 -139 102 15 109 106 95 70 70 70 42 42 42
41042 - 22 22 22 10 10 10 0 0 0 0 0 0
41043 - 0 0 0 0 0 0 0 0 0 0 0 0
41044 - 0 0 0 0 0 0 0 0 0 0 0 0
41045 - 0 0 0 0 0 0 0 0 0 0 0 0
41046 - 0 0 0 0 0 0 0 0 0 0 0 0
41047 - 0 0 0 0 0 0 0 0 0 0 0 0
41048 - 0 0 0 0 0 0 6 6 6 10 10 10
41049 - 14 14 14 22 22 22 30 30 30 38 38 38
41050 - 50 50 50 62 62 62 74 74 74 90 90 90
41051 -101 98 89 112 100 78 121 87 25 124 80 6
41052 -137 92 6 152 99 6 152 99 6 152 99 6
41053 -138 86 6 124 80 6 98 70 6 86 66 30
41054 -101 98 89 82 82 82 58 58 58 46 46 46
41055 - 38 38 38 34 34 34 34 34 34 34 34 34
41056 - 34 34 34 34 34 34 34 34 34 34 34 34
41057 - 34 34 34 34 34 34 38 38 38 42 42 42
41058 - 54 54 54 82 82 82 94 86 76 91 60 6
41059 -134 86 6 156 107 11 167 114 7 175 118 6
41060 -175 118 6 167 114 7 152 99 6 121 87 25
41061 -101 98 89 62 62 62 34 34 34 18 18 18
41062 - 6 6 6 0 0 0 0 0 0 0 0 0
41063 - 0 0 0 0 0 0 0 0 0 0 0 0
41064 - 0 0 0 0 0 0 0 0 0 0 0 0
41065 - 0 0 0 0 0 0 0 0 0 0 0 0
41066 - 0 0 0 0 0 0 0 0 0 0 0 0
41067 - 0 0 0 0 0 0 0 0 0 0 0 0
41068 - 0 0 0 0 0 0 0 0 0 0 0 0
41069 - 0 0 0 6 6 6 6 6 6 10 10 10
41070 - 18 18 18 22 22 22 30 30 30 42 42 42
41071 - 50 50 50 66 66 66 86 86 86 101 98 89
41072 -106 86 58 98 70 6 104 69 6 104 69 6
41073 -104 69 6 91 60 6 82 62 34 90 90 90
41074 - 62 62 62 38 38 38 22 22 22 14 14 14
41075 - 10 10 10 10 10 10 10 10 10 10 10 10
41076 - 10 10 10 10 10 10 6 6 6 10 10 10
41077 - 10 10 10 10 10 10 10 10 10 14 14 14
41078 - 22 22 22 42 42 42 70 70 70 89 81 66
41079 - 80 54 7 104 69 6 124 80 6 137 92 6
41080 -134 86 6 116 81 8 100 82 52 86 86 86
41081 - 58 58 58 30 30 30 14 14 14 6 6 6
41082 - 0 0 0 0 0 0 0 0 0 0 0 0
41083 - 0 0 0 0 0 0 0 0 0 0 0 0
41084 - 0 0 0 0 0 0 0 0 0 0 0 0
41085 - 0 0 0 0 0 0 0 0 0 0 0 0
41086 - 0 0 0 0 0 0 0 0 0 0 0 0
41087 - 0 0 0 0 0 0 0 0 0 0 0 0
41088 - 0 0 0 0 0 0 0 0 0 0 0 0
41089 - 0 0 0 0 0 0 0 0 0 0 0 0
41090 - 0 0 0 6 6 6 10 10 10 14 14 14
41091 - 18 18 18 26 26 26 38 38 38 54 54 54
41092 - 70 70 70 86 86 86 94 86 76 89 81 66
41093 - 89 81 66 86 86 86 74 74 74 50 50 50
41094 - 30 30 30 14 14 14 6 6 6 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 - 6 6 6 18 18 18 34 34 34 58 58 58
41099 - 82 82 82 89 81 66 89 81 66 89 81 66
41100 - 94 86 66 94 86 76 74 74 74 50 50 50
41101 - 26 26 26 14 14 14 6 6 6 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 0 0 0 0 0 0 0 0 0
41105 - 0 0 0 0 0 0 0 0 0 0 0 0
41106 - 0 0 0 0 0 0 0 0 0 0 0 0
41107 - 0 0 0 0 0 0 0 0 0 0 0 0
41108 - 0 0 0 0 0 0 0 0 0 0 0 0
41109 - 0 0 0 0 0 0 0 0 0 0 0 0
41110 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 6 6 6 6 6 6 14 14 14 18 18 18
41112 - 30 30 30 38 38 38 46 46 46 54 54 54
41113 - 50 50 50 42 42 42 30 30 30 18 18 18
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 6 6 6 14 14 14 26 26 26
41119 - 38 38 38 50 50 50 58 58 58 58 58 58
41120 - 54 54 54 42 42 42 30 30 30 18 18 18
41121 - 10 10 10 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 0 0 0 0
41124 - 0 0 0 0 0 0 0 0 0 0 0 0
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
41129 - 0 0 0 0 0 0 0 0 0 0 0 0
41130 - 0 0 0 0 0 0 0 0 0 0 0 0
41131 - 0 0 0 0 0 0 0 0 0 6 6 6
41132 - 6 6 6 10 10 10 14 14 14 18 18 18
41133 - 18 18 18 14 14 14 10 10 10 6 6 6
41134 - 0 0 0 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 - 14 14 14 18 18 18 22 22 22 22 22 22
41140 - 18 18 18 14 14 14 10 10 10 6 6 6
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 0 0 0 0 0 0
41143 - 0 0 0 0 0 0 0 0 0 0 0 0
41144 - 0 0 0 0 0 0 0 0 0 0 0 0
41145 - 0 0 0 0 0 0 0 0 0 0 0 0
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41235 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41240 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41249 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41250 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41254 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41255 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41256 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41263 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41264 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41268 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41269 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41270 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41276 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41277 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41278 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41281 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41282 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41283 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41284 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41285 +4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41290 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41291 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41292 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41293 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41295 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41296 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41297 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41298 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41303 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41304 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41305 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41306 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41307 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41308 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41309 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41310 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41311 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41312 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41313 +4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41317 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41318 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41319 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41320 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41321 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41322 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41323 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41324 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41325 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41326 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41331 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41332 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41333 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41334 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41335 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41336 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41337 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41338 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41339 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41340 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41345 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41346 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41347 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41348 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41349 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41350 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41351 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41352 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41353 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41354 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41359 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41360 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41361 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41362 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41363 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41364 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41365 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41366 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41367 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41368 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41369 +4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41372 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41373 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41374 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41375 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41376 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41377 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41378 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41379 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41380 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41381 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41382 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41383 +4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41386 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41387 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41388 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41389 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41390 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41391 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41392 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41393 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41394 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41395 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41396 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41397 +0 0 0 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41399 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41400 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41401 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41402 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41403 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41404 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41405 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41406 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41407 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41408 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41409 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41410 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41411 +2 0 0 0 0 0
41412 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41413 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41414 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41415 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41416 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41417 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41418 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41419 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41420 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41421 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41422 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41423 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41424 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41425 +37 38 37 0 0 0
41426 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41427 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41428 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41429 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41430 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41431 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41432 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41433 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41434 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41435 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41436 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41437 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41438 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41439 +85 115 134 4 0 0
41440 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41441 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41442 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41443 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41444 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41445 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41446 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41447 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41448 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41449 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41450 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41451 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41452 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41453 +60 73 81 4 0 0
41454 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41455 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41456 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41457 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41458 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41459 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41460 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41461 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41462 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41463 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41464 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41465 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41466 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41467 +16 19 21 4 0 0
41468 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41469 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41470 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41471 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41472 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41473 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41474 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41475 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41476 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41477 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41478 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41479 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41480 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41481 +4 0 0 4 3 3
41482 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41483 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41484 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41486 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41487 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41488 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41489 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41490 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41491 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41492 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41493 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41494 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41495 +3 2 2 4 4 4
41496 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41497 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41498 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41499 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41500 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41501 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41502 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41503 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41504 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41505 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41506 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41507 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41508 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41509 +4 4 4 4 4 4
41510 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41511 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41512 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41513 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41514 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41515 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41516 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41517 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41518 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41519 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41520 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41521 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41522 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41523 +4 4 4 4 4 4
41524 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41525 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41526 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41527 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41528 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41529 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41530 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41531 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41532 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41533 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41534 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41535 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41536 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41537 +5 5 5 5 5 5
41538 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41539 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41540 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41541 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41542 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41543 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41544 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41545 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41546 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41547 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41548 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41549 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41550 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41551 +5 5 5 4 4 4
41552 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41553 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41554 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41555 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41556 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41557 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41558 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41559 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41560 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41561 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41562 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41563 +4 0 0 4 0 0 5 5 5 5 5 5 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
41566 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41567 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41568 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41569 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41570 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41571 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41572 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41573 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41574 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41575 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41576 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41577 +3 3 3 5 5 5 6 6 6 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
41580 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41581 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41582 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41583 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41584 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41585 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41586 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41587 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41588 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41589 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41590 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
41594 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41595 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41596 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41597 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41598 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41599 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41600 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41601 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41602 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41603 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41604 +6 6 6 4 0 0 4 0 0 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
41608 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41609 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41610 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41611 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41612 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41613 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41614 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41615 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41616 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41617 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41618 +4 0 0 4 3 3 5 5 5 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
41622 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41623 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41624 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41625 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41626 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41627 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41628 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41629 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41630 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41631 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41632 +6 6 6 4 0 0 6 6 6 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
41636 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41637 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41638 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41639 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41640 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41641 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41642 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41643 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41644 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41645 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41646 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4
41650 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41651 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41652 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41653 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41654 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41655 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41656 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41657 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41658 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41659 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41660 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4
41664 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41665 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41666 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41667 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41668 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41669 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41670 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41671 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41672 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41673 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41674 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4
41678 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41679 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41680 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41681 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41682 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41683 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41684 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41685 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41686 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41687 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41688 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4
41692 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41693 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41694 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41695 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41696 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41697 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41698 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41699 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41700 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41701 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41702 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4
41706 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41707 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41708 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41709 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41710 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41711 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41712 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41713 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41714 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41715 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41716 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4
41720 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41721 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41722 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41723 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41724 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41725 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41726 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41727 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41728 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41729 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41730 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4
41734 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41735 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41736 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41737 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41738 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41739 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41740 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41741 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41742 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41743 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41744 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4
41748 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41749 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41750 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41751 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41752 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41753 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41754 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41755 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41756 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41757 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41758 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4
41762 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41763 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41764 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41765 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41766 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41767 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41768 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41769 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41770 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41771 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41772 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4
41776 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41777 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41778 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41779 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41780 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41781 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41782 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41783 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41784 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41785 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41786 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4
41790 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41791 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41792 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41793 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41794 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41795 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41796 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41797 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41798 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41799 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41800 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4
41804 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41805 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41806 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41807 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41808 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41809 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41810 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41811 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41812 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41813 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41814 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4
41818 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41819 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41820 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41821 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41822 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41823 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41824 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41825 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41826 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41827 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41828 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4
41832 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41833 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41834 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41835 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41836 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41837 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41838 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41839 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41840 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41841 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41842 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4
41846 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41847 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41848 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41849 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41850 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41851 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41852 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41853 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41854 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41855 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41856 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4
41860 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41861 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41862 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41863 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41864 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41865 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41866 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41867 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41868 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41869 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41870 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4
41874 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41875 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41876 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41877 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41878 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41879 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41880 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41881 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41882 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41883 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41884 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887 +4 4 4 4 4 4
41888 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41889 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41890 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41891 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41892 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41893 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41894 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41895 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41896 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41897 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41898 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41901 +4 4 4 4 4 4
41902 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41903 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41904 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41905 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41906 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41907 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41908 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41909 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41910 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41911 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41912 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41915 +4 4 4 4 4 4
41916 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41917 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41918 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41919 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41920 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41921 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41922 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41923 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41924 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41925 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41926 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 4 4 4 4
41930 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41931 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41932 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41933 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41934 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41935 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41936 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41938 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41939 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41940 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943 +4 4 4 4 4 4
41944 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41945 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41946 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41947 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41948 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41949 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41950 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41951 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41952 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41953 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41954 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957 +4 4 4 4 4 4
41958 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41959 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41960 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41961 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41962 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41963 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41964 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41965 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41966 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41967 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971 +4 4 4 4 4 4
41972 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41973 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41974 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41975 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41976 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41977 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41978 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41979 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41980 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41981 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985 +4 4 4 4 4 4
41986 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41987 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41988 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41989 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41990 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41991 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41992 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41993 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41994 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41995 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999 +4 4 4 4 4 4
42000 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42001 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42002 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42003 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42004 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42005 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42006 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42007 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42008 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42009 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013 +4 4 4 4 4 4
42014 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42015 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42016 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42017 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42018 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42019 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42020 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42021 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42022 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027 +4 4 4 4 4 4
42028 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42029 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42030 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42031 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42032 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42033 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42034 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42035 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42036 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041 +4 4 4 4 4 4
42042 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42043 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42044 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42045 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42046 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42047 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42048 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42049 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42050 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055 +4 4 4 4 4 4
42056 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42057 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42058 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42059 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42060 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42061 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42062 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42063 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 4 4 4 4
42070 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42071 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42072 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42073 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42074 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42075 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42076 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42077 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083 +4 4 4 4 4 4
42084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42085 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42086 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42087 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42088 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42089 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42090 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42091 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42100 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42101 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42102 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42103 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42104 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42105 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111 +4 4 4 4 4 4
42112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42114 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42115 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42116 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42117 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42118 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42119 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125 +4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42128 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42129 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42130 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42131 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42132 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42133 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139 +4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 4 4 4 4 4 4 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 5 5 5
42143 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42144 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42145 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42146 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153 +4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42158 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42159 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42160 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167 +4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42172 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42173 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42174 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181 +4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42186 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42187 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42188 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195 +4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 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 5 5 5
42200 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42201 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42202 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209 +4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42215 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42216 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223 +4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42229 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42230 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237 +4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42243 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42257 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265 +4 4 4 4 4 4
42266 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42267 index 38fcfff..0072dcd 100644
42268 --- a/drivers/video/udlfb.c
42269 +++ b/drivers/video/udlfb.c
42270 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42271 dlfb_urb_completion(urb);
42272
42273 error:
42274 - atomic_add(bytes_sent, &dev->bytes_sent);
42275 - atomic_add(bytes_identical, &dev->bytes_identical);
42276 - atomic_add(width*height*2, &dev->bytes_rendered);
42277 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42278 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42279 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42280 end_cycles = get_cycles();
42281 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42282 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42283 >> 10)), /* Kcycles */
42284 &dev->cpu_kcycles_used);
42285
42286 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42287 dlfb_urb_completion(urb);
42288
42289 error:
42290 - atomic_add(bytes_sent, &dev->bytes_sent);
42291 - atomic_add(bytes_identical, &dev->bytes_identical);
42292 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42293 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42294 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42295 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42296 end_cycles = get_cycles();
42297 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42298 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42299 >> 10)), /* Kcycles */
42300 &dev->cpu_kcycles_used);
42301 }
42302 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42303 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42304 struct dlfb_data *dev = fb_info->par;
42305 return snprintf(buf, PAGE_SIZE, "%u\n",
42306 - atomic_read(&dev->bytes_rendered));
42307 + atomic_read_unchecked(&dev->bytes_rendered));
42308 }
42309
42310 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42311 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42312 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42313 struct dlfb_data *dev = fb_info->par;
42314 return snprintf(buf, PAGE_SIZE, "%u\n",
42315 - atomic_read(&dev->bytes_identical));
42316 + atomic_read_unchecked(&dev->bytes_identical));
42317 }
42318
42319 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42320 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42321 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42322 struct dlfb_data *dev = fb_info->par;
42323 return snprintf(buf, PAGE_SIZE, "%u\n",
42324 - atomic_read(&dev->bytes_sent));
42325 + atomic_read_unchecked(&dev->bytes_sent));
42326 }
42327
42328 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42329 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42330 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42331 struct dlfb_data *dev = fb_info->par;
42332 return snprintf(buf, PAGE_SIZE, "%u\n",
42333 - atomic_read(&dev->cpu_kcycles_used));
42334 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42335 }
42336
42337 static ssize_t edid_show(
42338 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42339 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42340 struct dlfb_data *dev = fb_info->par;
42341
42342 - atomic_set(&dev->bytes_rendered, 0);
42343 - atomic_set(&dev->bytes_identical, 0);
42344 - atomic_set(&dev->bytes_sent, 0);
42345 - atomic_set(&dev->cpu_kcycles_used, 0);
42346 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42347 + atomic_set_unchecked(&dev->bytes_identical, 0);
42348 + atomic_set_unchecked(&dev->bytes_sent, 0);
42349 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42350
42351 return count;
42352 }
42353 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42354 index b0e2a42..e2df3ad 100644
42355 --- a/drivers/video/uvesafb.c
42356 +++ b/drivers/video/uvesafb.c
42357 @@ -19,6 +19,7 @@
42358 #include <linux/io.h>
42359 #include <linux/mutex.h>
42360 #include <linux/slab.h>
42361 +#include <linux/moduleloader.h>
42362 #include <video/edid.h>
42363 #include <video/uvesafb.h>
42364 #ifdef CONFIG_X86
42365 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42366 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42367 par->pmi_setpal = par->ypan = 0;
42368 } else {
42369 +
42370 +#ifdef CONFIG_PAX_KERNEXEC
42371 +#ifdef CONFIG_MODULES
42372 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42373 +#endif
42374 + if (!par->pmi_code) {
42375 + par->pmi_setpal = par->ypan = 0;
42376 + return 0;
42377 + }
42378 +#endif
42379 +
42380 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42381 + task->t.regs.edi);
42382 +
42383 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42384 + pax_open_kernel();
42385 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42386 + pax_close_kernel();
42387 +
42388 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42389 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42390 +#else
42391 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42392 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42393 +#endif
42394 +
42395 printk(KERN_INFO "uvesafb: protected mode interface info at "
42396 "%04x:%04x\n",
42397 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42398 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42399 par->ypan = ypan;
42400
42401 if (par->pmi_setpal || par->ypan) {
42402 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42403 if (__supported_pte_mask & _PAGE_NX) {
42404 par->pmi_setpal = par->ypan = 0;
42405 printk(KERN_WARNING "uvesafb: NX protection is actively."
42406 "We have better not to use the PMI.\n");
42407 - } else {
42408 + } else
42409 +#endif
42410 uvesafb_vbe_getpmi(task, par);
42411 - }
42412 }
42413 #else
42414 /* The protected mode interface is not available on non-x86. */
42415 @@ -1836,6 +1860,11 @@ out:
42416 if (par->vbe_modes)
42417 kfree(par->vbe_modes);
42418
42419 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42420 + if (par->pmi_code)
42421 + module_free_exec(NULL, par->pmi_code);
42422 +#endif
42423 +
42424 framebuffer_release(info);
42425 return err;
42426 }
42427 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42428 kfree(par->vbe_state_orig);
42429 if (par->vbe_state_saved)
42430 kfree(par->vbe_state_saved);
42431 +
42432 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42433 + if (par->pmi_code)
42434 + module_free_exec(NULL, par->pmi_code);
42435 +#endif
42436 +
42437 }
42438
42439 framebuffer_release(info);
42440 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42441 index 501b340..86bd4cf 100644
42442 --- a/drivers/video/vesafb.c
42443 +++ b/drivers/video/vesafb.c
42444 @@ -9,6 +9,7 @@
42445 */
42446
42447 #include <linux/module.h>
42448 +#include <linux/moduleloader.h>
42449 #include <linux/kernel.h>
42450 #include <linux/errno.h>
42451 #include <linux/string.h>
42452 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42453 static int vram_total __initdata; /* Set total amount of memory */
42454 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42455 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42456 -static void (*pmi_start)(void) __read_mostly;
42457 -static void (*pmi_pal) (void) __read_mostly;
42458 +static void (*pmi_start)(void) __read_only;
42459 +static void (*pmi_pal) (void) __read_only;
42460 static int depth __read_mostly;
42461 static int vga_compat __read_mostly;
42462 /* --------------------------------------------------------------------- */
42463 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42464 unsigned int size_vmode;
42465 unsigned int size_remap;
42466 unsigned int size_total;
42467 + void *pmi_code = NULL;
42468
42469 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42470 return -ENODEV;
42471 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42472 size_remap = size_total;
42473 vesafb_fix.smem_len = size_remap;
42474
42475 -#ifndef __i386__
42476 - screen_info.vesapm_seg = 0;
42477 -#endif
42478 -
42479 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42480 printk(KERN_WARNING
42481 "vesafb: cannot reserve video memory at 0x%lx\n",
42482 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42483 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42484 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42485
42486 +#ifdef __i386__
42487 +
42488 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42489 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42490 + if (!pmi_code)
42491 +#elif !defined(CONFIG_PAX_KERNEXEC)
42492 + if (0)
42493 +#endif
42494 +
42495 +#endif
42496 + screen_info.vesapm_seg = 0;
42497 +
42498 if (screen_info.vesapm_seg) {
42499 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42500 - screen_info.vesapm_seg,screen_info.vesapm_off);
42501 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42502 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42503 }
42504
42505 if (screen_info.vesapm_seg < 0xc000)
42506 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42507
42508 if (ypan || pmi_setpal) {
42509 unsigned short *pmi_base;
42510 +
42511 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42512 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42513 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42514 +
42515 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42516 + pax_open_kernel();
42517 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42518 +#else
42519 + pmi_code = pmi_base;
42520 +#endif
42521 +
42522 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42523 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42524 +
42525 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42526 + pmi_start = ktva_ktla(pmi_start);
42527 + pmi_pal = ktva_ktla(pmi_pal);
42528 + pax_close_kernel();
42529 +#endif
42530 +
42531 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42532 if (pmi_base[3]) {
42533 printk(KERN_INFO "vesafb: pmi: ports = ");
42534 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42535 info->node, info->fix.id);
42536 return 0;
42537 err:
42538 +
42539 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42540 + module_free_exec(NULL, pmi_code);
42541 +#endif
42542 +
42543 if (info->screen_base)
42544 iounmap(info->screen_base);
42545 framebuffer_release(info);
42546 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42547 index 88714ae..16c2e11 100644
42548 --- a/drivers/video/via/via_clock.h
42549 +++ b/drivers/video/via/via_clock.h
42550 @@ -56,7 +56,7 @@ struct via_clock {
42551
42552 void (*set_engine_pll_state)(u8 state);
42553 void (*set_engine_pll)(struct via_pll_config config);
42554 -};
42555 +} __no_const;
42556
42557
42558 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42559 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42560 index 453db0c..604973e 100644
42561 --- a/drivers/virtio/virtio_mmio.c
42562 +++ b/drivers/virtio/virtio_mmio.c
42563 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42564
42565 resources[0].end = memparse(device, &str) - 1;
42566
42567 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42568 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42569 &base, &resources[1].start, &consumed,
42570 &vm_cmdline_id, &consumed);
42571
42572 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42573 index e56c934..fc22f4b 100644
42574 --- a/drivers/xen/xen-pciback/conf_space.h
42575 +++ b/drivers/xen/xen-pciback/conf_space.h
42576 @@ -44,15 +44,15 @@ struct config_field {
42577 struct {
42578 conf_dword_write write;
42579 conf_dword_read read;
42580 - } dw;
42581 + } __no_const dw;
42582 struct {
42583 conf_word_write write;
42584 conf_word_read read;
42585 - } w;
42586 + } __no_const w;
42587 struct {
42588 conf_byte_write write;
42589 conf_byte_read read;
42590 - } b;
42591 + } __no_const b;
42592 } u;
42593 struct list_head list;
42594 };
42595 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42596 index cbf9dbb..35c3af7 100644
42597 --- a/fs/9p/vfs_inode.c
42598 +++ b/fs/9p/vfs_inode.c
42599 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42600 void
42601 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42602 {
42603 - char *s = nd_get_link(nd);
42604 + const char *s = nd_get_link(nd);
42605
42606 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42607 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42608 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42609 index 0225742..1cd4732 100644
42610 --- a/fs/Kconfig.binfmt
42611 +++ b/fs/Kconfig.binfmt
42612 @@ -89,7 +89,7 @@ config HAVE_AOUT
42613
42614 config BINFMT_AOUT
42615 tristate "Kernel support for a.out and ECOFF binaries"
42616 - depends on HAVE_AOUT
42617 + depends on HAVE_AOUT && BROKEN
42618 ---help---
42619 A.out (Assembler.OUTput) is a set of formats for libraries and
42620 executables used in the earliest versions of UNIX. Linux used
42621 diff --git a/fs/aio.c b/fs/aio.c
42622 index 71f613c..9d01f1f 100644
42623 --- a/fs/aio.c
42624 +++ b/fs/aio.c
42625 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42626 size += sizeof(struct io_event) * nr_events;
42627 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42628
42629 - if (nr_pages < 0)
42630 + if (nr_pages <= 0)
42631 return -EINVAL;
42632
42633 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42634 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42635 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42636 {
42637 ssize_t ret;
42638 + struct iovec iovstack;
42639
42640 #ifdef CONFIG_COMPAT
42641 if (compat)
42642 ret = compat_rw_copy_check_uvector(type,
42643 (struct compat_iovec __user *)kiocb->ki_buf,
42644 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42645 + kiocb->ki_nbytes, 1, &iovstack,
42646 &kiocb->ki_iovec);
42647 else
42648 #endif
42649 ret = rw_copy_check_uvector(type,
42650 (struct iovec __user *)kiocb->ki_buf,
42651 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42652 + kiocb->ki_nbytes, 1, &iovstack,
42653 &kiocb->ki_iovec);
42654 if (ret < 0)
42655 goto out;
42656 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42657 if (ret < 0)
42658 goto out;
42659
42660 + if (kiocb->ki_iovec == &iovstack) {
42661 + kiocb->ki_inline_vec = iovstack;
42662 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42663 + }
42664 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42665 kiocb->ki_cur_seg = 0;
42666 /* ki_nbytes/left now reflect bytes instead of segs */
42667 diff --git a/fs/attr.c b/fs/attr.c
42668 index 29e38a1..2bc037b 100644
42669 --- a/fs/attr.c
42670 +++ b/fs/attr.c
42671 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42672 unsigned long limit;
42673
42674 limit = rlimit(RLIMIT_FSIZE);
42675 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42676 if (limit != RLIM_INFINITY && offset > limit)
42677 goto out_sig;
42678 if (offset > inode->i_sb->s_maxbytes)
42679 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42680 index da8876d..4456166 100644
42681 --- a/fs/autofs4/waitq.c
42682 +++ b/fs/autofs4/waitq.c
42683 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42684 {
42685 unsigned long sigpipe, flags;
42686 mm_segment_t fs;
42687 - const char *data = (const char *)addr;
42688 + const char __user *data = (const char __force_user *)addr;
42689 ssize_t wr = 0;
42690
42691 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42692 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42693 return 1;
42694 }
42695
42696 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42697 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42698 +#endif
42699 +
42700 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42701 enum autofs_notify notify)
42702 {
42703 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42704
42705 /* If this is a direct mount request create a dummy name */
42706 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42707 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42708 + /* this name does get written to userland via autofs4_write() */
42709 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42710 +#else
42711 qstr.len = sprintf(name, "%p", dentry);
42712 +#endif
42713 else {
42714 qstr.len = autofs4_getpath(sbi, dentry, &name);
42715 if (!qstr.len) {
42716 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42717 index cf7f3c6..f61080d 100644
42718 --- a/fs/befs/linuxvfs.c
42719 +++ b/fs/befs/linuxvfs.c
42720 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42721 {
42722 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42723 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42724 - char *link = nd_get_link(nd);
42725 + const char *link = nd_get_link(nd);
42726 if (!IS_ERR(link))
42727 kfree(link);
42728 }
42729 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42730 index d146e18..12d1bd1 100644
42731 --- a/fs/binfmt_aout.c
42732 +++ b/fs/binfmt_aout.c
42733 @@ -16,6 +16,7 @@
42734 #include <linux/string.h>
42735 #include <linux/fs.h>
42736 #include <linux/file.h>
42737 +#include <linux/security.h>
42738 #include <linux/stat.h>
42739 #include <linux/fcntl.h>
42740 #include <linux/ptrace.h>
42741 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42742 #endif
42743 # define START_STACK(u) ((void __user *)u.start_stack)
42744
42745 + memset(&dump, 0, sizeof(dump));
42746 +
42747 fs = get_fs();
42748 set_fs(KERNEL_DS);
42749 has_dumped = 1;
42750 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42751
42752 /* If the size of the dump file exceeds the rlimit, then see what would happen
42753 if we wrote the stack, but not the data area. */
42754 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42755 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42756 dump.u_dsize = 0;
42757
42758 /* Make sure we have enough room to write the stack and data areas. */
42759 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42760 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42761 dump.u_ssize = 0;
42762
42763 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42764 rlim = rlimit(RLIMIT_DATA);
42765 if (rlim >= RLIM_INFINITY)
42766 rlim = ~0;
42767 +
42768 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42769 if (ex.a_data + ex.a_bss > rlim)
42770 return -ENOMEM;
42771
42772 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42773
42774 install_exec_creds(bprm);
42775
42776 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42777 + current->mm->pax_flags = 0UL;
42778 +#endif
42779 +
42780 +#ifdef CONFIG_PAX_PAGEEXEC
42781 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42782 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42783 +
42784 +#ifdef CONFIG_PAX_EMUTRAMP
42785 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42786 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42787 +#endif
42788 +
42789 +#ifdef CONFIG_PAX_MPROTECT
42790 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42791 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42792 +#endif
42793 +
42794 + }
42795 +#endif
42796 +
42797 if (N_MAGIC(ex) == OMAGIC) {
42798 unsigned long text_addr, map_size;
42799 loff_t pos;
42800 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42801 }
42802
42803 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42804 - PROT_READ | PROT_WRITE | PROT_EXEC,
42805 + PROT_READ | PROT_WRITE,
42806 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42807 fd_offset + ex.a_text);
42808 if (error != N_DATADDR(ex)) {
42809 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42810 index 0225fdd..9f0ef53 100644
42811 --- a/fs/binfmt_elf.c
42812 +++ b/fs/binfmt_elf.c
42813 @@ -32,6 +32,7 @@
42814 #include <linux/elf.h>
42815 #include <linux/utsname.h>
42816 #include <linux/coredump.h>
42817 +#include <linux/xattr.h>
42818 #include <asm/uaccess.h>
42819 #include <asm/param.h>
42820 #include <asm/page.h>
42821 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42822 #define elf_core_dump NULL
42823 #endif
42824
42825 +#ifdef CONFIG_PAX_MPROTECT
42826 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42827 +#endif
42828 +
42829 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42830 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42831 #else
42832 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42833 .load_binary = load_elf_binary,
42834 .load_shlib = load_elf_library,
42835 .core_dump = elf_core_dump,
42836 +
42837 +#ifdef CONFIG_PAX_MPROTECT
42838 + .handle_mprotect= elf_handle_mprotect,
42839 +#endif
42840 +
42841 .min_coredump = ELF_EXEC_PAGESIZE,
42842 };
42843
42844 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42845
42846 static int set_brk(unsigned long start, unsigned long end)
42847 {
42848 + unsigned long e = end;
42849 +
42850 start = ELF_PAGEALIGN(start);
42851 end = ELF_PAGEALIGN(end);
42852 if (end > start) {
42853 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42854 if (BAD_ADDR(addr))
42855 return addr;
42856 }
42857 - current->mm->start_brk = current->mm->brk = end;
42858 + current->mm->start_brk = current->mm->brk = e;
42859 return 0;
42860 }
42861
42862 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42863 elf_addr_t __user *u_rand_bytes;
42864 const char *k_platform = ELF_PLATFORM;
42865 const char *k_base_platform = ELF_BASE_PLATFORM;
42866 - unsigned char k_rand_bytes[16];
42867 + u32 k_rand_bytes[4];
42868 int items;
42869 elf_addr_t *elf_info;
42870 int ei_index = 0;
42871 const struct cred *cred = current_cred();
42872 struct vm_area_struct *vma;
42873 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42874
42875 /*
42876 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42877 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42878 * Generate 16 random bytes for userspace PRNG seeding.
42879 */
42880 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42881 - u_rand_bytes = (elf_addr_t __user *)
42882 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42883 + srandom32(k_rand_bytes[0] ^ random32());
42884 + srandom32(k_rand_bytes[1] ^ random32());
42885 + srandom32(k_rand_bytes[2] ^ random32());
42886 + srandom32(k_rand_bytes[3] ^ random32());
42887 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42888 + u_rand_bytes = (elf_addr_t __user *) p;
42889 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42890 return -EFAULT;
42891
42892 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42893 return -EFAULT;
42894 current->mm->env_end = p;
42895
42896 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42897 +
42898 /* Put the elf_info on the stack in the right place. */
42899 sp = (elf_addr_t __user *)envp + 1;
42900 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42901 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42902 return -EFAULT;
42903 return 0;
42904 }
42905 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42906 {
42907 struct elf_phdr *elf_phdata;
42908 struct elf_phdr *eppnt;
42909 - unsigned long load_addr = 0;
42910 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42911 int load_addr_set = 0;
42912 unsigned long last_bss = 0, elf_bss = 0;
42913 - unsigned long error = ~0UL;
42914 + unsigned long error = -EINVAL;
42915 unsigned long total_size;
42916 int retval, i, size;
42917
42918 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42919 goto out_close;
42920 }
42921
42922 +#ifdef CONFIG_PAX_SEGMEXEC
42923 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42924 + pax_task_size = SEGMEXEC_TASK_SIZE;
42925 +#endif
42926 +
42927 eppnt = elf_phdata;
42928 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42929 if (eppnt->p_type == PT_LOAD) {
42930 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42931 k = load_addr + eppnt->p_vaddr;
42932 if (BAD_ADDR(k) ||
42933 eppnt->p_filesz > eppnt->p_memsz ||
42934 - eppnt->p_memsz > TASK_SIZE ||
42935 - TASK_SIZE - eppnt->p_memsz < k) {
42936 + eppnt->p_memsz > pax_task_size ||
42937 + pax_task_size - eppnt->p_memsz < k) {
42938 error = -ENOMEM;
42939 goto out_close;
42940 }
42941 @@ -523,6 +547,311 @@ out:
42942 return error;
42943 }
42944
42945 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42946 +#ifdef CONFIG_PAX_SOFTMODE
42947 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42948 +{
42949 + unsigned long pax_flags = 0UL;
42950 +
42951 +#ifdef CONFIG_PAX_PAGEEXEC
42952 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42953 + pax_flags |= MF_PAX_PAGEEXEC;
42954 +#endif
42955 +
42956 +#ifdef CONFIG_PAX_SEGMEXEC
42957 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42958 + pax_flags |= MF_PAX_SEGMEXEC;
42959 +#endif
42960 +
42961 +#ifdef CONFIG_PAX_EMUTRAMP
42962 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42963 + pax_flags |= MF_PAX_EMUTRAMP;
42964 +#endif
42965 +
42966 +#ifdef CONFIG_PAX_MPROTECT
42967 + if (elf_phdata->p_flags & PF_MPROTECT)
42968 + pax_flags |= MF_PAX_MPROTECT;
42969 +#endif
42970 +
42971 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42972 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42973 + pax_flags |= MF_PAX_RANDMMAP;
42974 +#endif
42975 +
42976 + return pax_flags;
42977 +}
42978 +#endif
42979 +
42980 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42981 +{
42982 + unsigned long pax_flags = 0UL;
42983 +
42984 +#ifdef CONFIG_PAX_PAGEEXEC
42985 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42986 + pax_flags |= MF_PAX_PAGEEXEC;
42987 +#endif
42988 +
42989 +#ifdef CONFIG_PAX_SEGMEXEC
42990 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42991 + pax_flags |= MF_PAX_SEGMEXEC;
42992 +#endif
42993 +
42994 +#ifdef CONFIG_PAX_EMUTRAMP
42995 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42996 + pax_flags |= MF_PAX_EMUTRAMP;
42997 +#endif
42998 +
42999 +#ifdef CONFIG_PAX_MPROTECT
43000 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43001 + pax_flags |= MF_PAX_MPROTECT;
43002 +#endif
43003 +
43004 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43005 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43006 + pax_flags |= MF_PAX_RANDMMAP;
43007 +#endif
43008 +
43009 + return pax_flags;
43010 +}
43011 +#endif
43012 +
43013 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43014 +#ifdef CONFIG_PAX_SOFTMODE
43015 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43016 +{
43017 + unsigned long pax_flags = 0UL;
43018 +
43019 +#ifdef CONFIG_PAX_PAGEEXEC
43020 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43021 + pax_flags |= MF_PAX_PAGEEXEC;
43022 +#endif
43023 +
43024 +#ifdef CONFIG_PAX_SEGMEXEC
43025 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43026 + pax_flags |= MF_PAX_SEGMEXEC;
43027 +#endif
43028 +
43029 +#ifdef CONFIG_PAX_EMUTRAMP
43030 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43031 + pax_flags |= MF_PAX_EMUTRAMP;
43032 +#endif
43033 +
43034 +#ifdef CONFIG_PAX_MPROTECT
43035 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43036 + pax_flags |= MF_PAX_MPROTECT;
43037 +#endif
43038 +
43039 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43040 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43041 + pax_flags |= MF_PAX_RANDMMAP;
43042 +#endif
43043 +
43044 + return pax_flags;
43045 +}
43046 +#endif
43047 +
43048 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43049 +{
43050 + unsigned long pax_flags = 0UL;
43051 +
43052 +#ifdef CONFIG_PAX_PAGEEXEC
43053 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43054 + pax_flags |= MF_PAX_PAGEEXEC;
43055 +#endif
43056 +
43057 +#ifdef CONFIG_PAX_SEGMEXEC
43058 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43059 + pax_flags |= MF_PAX_SEGMEXEC;
43060 +#endif
43061 +
43062 +#ifdef CONFIG_PAX_EMUTRAMP
43063 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43064 + pax_flags |= MF_PAX_EMUTRAMP;
43065 +#endif
43066 +
43067 +#ifdef CONFIG_PAX_MPROTECT
43068 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43069 + pax_flags |= MF_PAX_MPROTECT;
43070 +#endif
43071 +
43072 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43073 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43074 + pax_flags |= MF_PAX_RANDMMAP;
43075 +#endif
43076 +
43077 + return pax_flags;
43078 +}
43079 +#endif
43080 +
43081 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43082 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43083 +{
43084 + unsigned long pax_flags = 0UL;
43085 +
43086 +#ifdef CONFIG_PAX_EI_PAX
43087 +
43088 +#ifdef CONFIG_PAX_PAGEEXEC
43089 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43090 + pax_flags |= MF_PAX_PAGEEXEC;
43091 +#endif
43092 +
43093 +#ifdef CONFIG_PAX_SEGMEXEC
43094 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43095 + pax_flags |= MF_PAX_SEGMEXEC;
43096 +#endif
43097 +
43098 +#ifdef CONFIG_PAX_EMUTRAMP
43099 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43100 + pax_flags |= MF_PAX_EMUTRAMP;
43101 +#endif
43102 +
43103 +#ifdef CONFIG_PAX_MPROTECT
43104 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43105 + pax_flags |= MF_PAX_MPROTECT;
43106 +#endif
43107 +
43108 +#ifdef CONFIG_PAX_ASLR
43109 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43110 + pax_flags |= MF_PAX_RANDMMAP;
43111 +#endif
43112 +
43113 +#else
43114 +
43115 +#ifdef CONFIG_PAX_PAGEEXEC
43116 + pax_flags |= MF_PAX_PAGEEXEC;
43117 +#endif
43118 +
43119 +#ifdef CONFIG_PAX_SEGMEXEC
43120 + pax_flags |= MF_PAX_SEGMEXEC;
43121 +#endif
43122 +
43123 +#ifdef CONFIG_PAX_MPROTECT
43124 + pax_flags |= MF_PAX_MPROTECT;
43125 +#endif
43126 +
43127 +#ifdef CONFIG_PAX_RANDMMAP
43128 + if (randomize_va_space)
43129 + pax_flags |= MF_PAX_RANDMMAP;
43130 +#endif
43131 +
43132 +#endif
43133 +
43134 + return pax_flags;
43135 +}
43136 +
43137 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43138 +{
43139 +
43140 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43141 + unsigned long i;
43142 +
43143 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43144 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43145 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43146 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43147 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43148 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43149 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43150 + return ~0UL;
43151 +
43152 +#ifdef CONFIG_PAX_SOFTMODE
43153 + if (pax_softmode)
43154 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43155 + else
43156 +#endif
43157 +
43158 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43159 + break;
43160 + }
43161 +#endif
43162 +
43163 + return ~0UL;
43164 +}
43165 +
43166 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43167 +{
43168 +
43169 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43170 + ssize_t xattr_size, i;
43171 + unsigned char xattr_value[5];
43172 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43173 +
43174 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43175 + if (xattr_size <= 0)
43176 + return ~0UL;
43177 +
43178 + for (i = 0; i < xattr_size; i++)
43179 + switch (xattr_value[i]) {
43180 + default:
43181 + return ~0UL;
43182 +
43183 +#define parse_flag(option1, option2, flag) \
43184 + case option1: \
43185 + pax_flags_hardmode |= MF_PAX_##flag; \
43186 + break; \
43187 + case option2: \
43188 + pax_flags_softmode |= MF_PAX_##flag; \
43189 + break;
43190 +
43191 + parse_flag('p', 'P', PAGEEXEC);
43192 + parse_flag('e', 'E', EMUTRAMP);
43193 + parse_flag('m', 'M', MPROTECT);
43194 + parse_flag('r', 'R', RANDMMAP);
43195 + parse_flag('s', 'S', SEGMEXEC);
43196 +
43197 +#undef parse_flag
43198 + }
43199 +
43200 + if (pax_flags_hardmode & pax_flags_softmode)
43201 + return ~0UL;
43202 +
43203 +#ifdef CONFIG_PAX_SOFTMODE
43204 + if (pax_softmode)
43205 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43206 + else
43207 +#endif
43208 +
43209 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43210 +#else
43211 + return ~0UL;
43212 +#endif
43213 +
43214 +}
43215 +
43216 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43217 +{
43218 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43219 +
43220 + pax_flags = pax_parse_ei_pax(elf_ex);
43221 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43222 + xattr_pax_flags = pax_parse_xattr_pax(file);
43223 +
43224 + if (pt_pax_flags == ~0UL)
43225 + pt_pax_flags = xattr_pax_flags;
43226 + else if (xattr_pax_flags == ~0UL)
43227 + xattr_pax_flags = pt_pax_flags;
43228 + if (pt_pax_flags != xattr_pax_flags)
43229 + return -EINVAL;
43230 + if (pt_pax_flags != ~0UL)
43231 + pax_flags = pt_pax_flags;
43232 +
43233 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43234 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43235 + if ((__supported_pte_mask & _PAGE_NX))
43236 + pax_flags &= ~MF_PAX_SEGMEXEC;
43237 + else
43238 + pax_flags &= ~MF_PAX_PAGEEXEC;
43239 + }
43240 +#endif
43241 +
43242 + if (0 > pax_check_flags(&pax_flags))
43243 + return -EINVAL;
43244 +
43245 + current->mm->pax_flags = pax_flags;
43246 + return 0;
43247 +}
43248 +#endif
43249 +
43250 /*
43251 * These are the functions used to load ELF style executables and shared
43252 * libraries. There is no binary dependent code anywhere else.
43253 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43254 {
43255 unsigned int random_variable = 0;
43256
43257 +#ifdef CONFIG_PAX_RANDUSTACK
43258 + if (randomize_va_space)
43259 + return stack_top - current->mm->delta_stack;
43260 +#endif
43261 +
43262 if ((current->flags & PF_RANDOMIZE) &&
43263 !(current->personality & ADDR_NO_RANDOMIZE)) {
43264 random_variable = get_random_int() & STACK_RND_MASK;
43265 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43266 unsigned long load_addr = 0, load_bias = 0;
43267 int load_addr_set = 0;
43268 char * elf_interpreter = NULL;
43269 - unsigned long error;
43270 + unsigned long error = 0;
43271 struct elf_phdr *elf_ppnt, *elf_phdata;
43272 unsigned long elf_bss, elf_brk;
43273 int retval, i;
43274 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43275 unsigned long start_code, end_code, start_data, end_data;
43276 unsigned long reloc_func_desc __maybe_unused = 0;
43277 int executable_stack = EXSTACK_DEFAULT;
43278 - unsigned long def_flags = 0;
43279 struct {
43280 struct elfhdr elf_ex;
43281 struct elfhdr interp_elf_ex;
43282 } *loc;
43283 + unsigned long pax_task_size = TASK_SIZE;
43284
43285 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43286 if (!loc) {
43287 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43288 goto out_free_dentry;
43289
43290 /* OK, This is the point of no return */
43291 - current->mm->def_flags = def_flags;
43292 +
43293 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43294 + current->mm->pax_flags = 0UL;
43295 +#endif
43296 +
43297 +#ifdef CONFIG_PAX_DLRESOLVE
43298 + current->mm->call_dl_resolve = 0UL;
43299 +#endif
43300 +
43301 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43302 + current->mm->call_syscall = 0UL;
43303 +#endif
43304 +
43305 +#ifdef CONFIG_PAX_ASLR
43306 + current->mm->delta_mmap = 0UL;
43307 + current->mm->delta_stack = 0UL;
43308 +#endif
43309 +
43310 + current->mm->def_flags = 0;
43311 +
43312 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43313 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43314 + send_sig(SIGKILL, current, 0);
43315 + goto out_free_dentry;
43316 + }
43317 +#endif
43318 +
43319 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43320 + pax_set_initial_flags(bprm);
43321 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43322 + if (pax_set_initial_flags_func)
43323 + (pax_set_initial_flags_func)(bprm);
43324 +#endif
43325 +
43326 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43327 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43328 + current->mm->context.user_cs_limit = PAGE_SIZE;
43329 + current->mm->def_flags |= VM_PAGEEXEC;
43330 + }
43331 +#endif
43332 +
43333 +#ifdef CONFIG_PAX_SEGMEXEC
43334 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43335 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43336 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43337 + pax_task_size = SEGMEXEC_TASK_SIZE;
43338 + current->mm->def_flags |= VM_NOHUGEPAGE;
43339 + }
43340 +#endif
43341 +
43342 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43343 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43344 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43345 + put_cpu();
43346 + }
43347 +#endif
43348
43349 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43350 may depend on the personality. */
43351 SET_PERSONALITY(loc->elf_ex);
43352 +
43353 +#ifdef CONFIG_PAX_ASLR
43354 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43355 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43356 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43357 + }
43358 +#endif
43359 +
43360 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43361 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43362 + executable_stack = EXSTACK_DISABLE_X;
43363 + current->personality &= ~READ_IMPLIES_EXEC;
43364 + } else
43365 +#endif
43366 +
43367 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43368 current->personality |= READ_IMPLIES_EXEC;
43369
43370 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43371 #else
43372 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43373 #endif
43374 +
43375 +#ifdef CONFIG_PAX_RANDMMAP
43376 + /* PaX: randomize base address at the default exe base if requested */
43377 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43378 +#ifdef CONFIG_SPARC64
43379 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43380 +#else
43381 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43382 +#endif
43383 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43384 + elf_flags |= MAP_FIXED;
43385 + }
43386 +#endif
43387 +
43388 }
43389
43390 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43391 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43392 * allowed task size. Note that p_filesz must always be
43393 * <= p_memsz so it is only necessary to check p_memsz.
43394 */
43395 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43396 - elf_ppnt->p_memsz > TASK_SIZE ||
43397 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43398 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43399 + elf_ppnt->p_memsz > pax_task_size ||
43400 + pax_task_size - elf_ppnt->p_memsz < k) {
43401 /* set_brk can never work. Avoid overflows. */
43402 send_sig(SIGKILL, current, 0);
43403 retval = -EINVAL;
43404 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43405 goto out_free_dentry;
43406 }
43407 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43408 - send_sig(SIGSEGV, current, 0);
43409 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43410 - goto out_free_dentry;
43411 + /*
43412 + * This bss-zeroing can fail if the ELF
43413 + * file specifies odd protections. So
43414 + * we don't check the return value
43415 + */
43416 }
43417
43418 +#ifdef CONFIG_PAX_RANDMMAP
43419 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43420 + unsigned long start, size;
43421 +
43422 + start = ELF_PAGEALIGN(elf_brk);
43423 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43424 + down_read(&current->mm->mmap_sem);
43425 + retval = -ENOMEM;
43426 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43427 + unsigned long prot = PROT_NONE;
43428 +
43429 + up_read(&current->mm->mmap_sem);
43430 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43431 +// if (current->personality & ADDR_NO_RANDOMIZE)
43432 +// prot = PROT_READ;
43433 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43434 + retval = IS_ERR_VALUE(start) ? start : 0;
43435 + } else
43436 + up_read(&current->mm->mmap_sem);
43437 + if (retval == 0)
43438 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43439 + if (retval < 0) {
43440 + send_sig(SIGKILL, current, 0);
43441 + goto out_free_dentry;
43442 + }
43443 + }
43444 +#endif
43445 +
43446 if (elf_interpreter) {
43447 unsigned long uninitialized_var(interp_map_addr);
43448
43449 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43450 * Decide what to dump of a segment, part, all or none.
43451 */
43452 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43453 - unsigned long mm_flags)
43454 + unsigned long mm_flags, long signr)
43455 {
43456 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43457
43458 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43459 if (vma->vm_file == NULL)
43460 return 0;
43461
43462 - if (FILTER(MAPPED_PRIVATE))
43463 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43464 goto whole;
43465
43466 /*
43467 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43468 {
43469 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43470 int i = 0;
43471 - do
43472 + do {
43473 i += 2;
43474 - while (auxv[i - 2] != AT_NULL);
43475 + } while (auxv[i - 2] != AT_NULL);
43476 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43477 }
43478
43479 @@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43480 }
43481
43482 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43483 - unsigned long mm_flags)
43484 + struct coredump_params *cprm)
43485 {
43486 struct vm_area_struct *vma;
43487 size_t size = 0;
43488
43489 for (vma = first_vma(current, gate_vma); vma != NULL;
43490 vma = next_vma(vma, gate_vma))
43491 - size += vma_dump_size(vma, mm_flags);
43492 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43493 return size;
43494 }
43495
43496 @@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43497
43498 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43499
43500 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43501 + offset += elf_core_vma_data_size(gate_vma, cprm);
43502 offset += elf_core_extra_data_size();
43503 e_shoff = offset;
43504
43505 @@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43506 offset = dataoff;
43507
43508 size += sizeof(*elf);
43509 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43510 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43511 goto end_coredump;
43512
43513 size += sizeof(*phdr4note);
43514 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43515 if (size > cprm->limit
43516 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43517 goto end_coredump;
43518 @@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43519 phdr.p_offset = offset;
43520 phdr.p_vaddr = vma->vm_start;
43521 phdr.p_paddr = 0;
43522 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43523 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43524 phdr.p_memsz = vma->vm_end - vma->vm_start;
43525 offset += phdr.p_filesz;
43526 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43527 @@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43528 phdr.p_align = ELF_EXEC_PAGESIZE;
43529
43530 size += sizeof(phdr);
43531 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43532 if (size > cprm->limit
43533 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43534 goto end_coredump;
43535 @@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43536 unsigned long addr;
43537 unsigned long end;
43538
43539 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43540 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43541
43542 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43543 struct page *page;
43544 @@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43545 page = get_dump_page(addr);
43546 if (page) {
43547 void *kaddr = kmap(page);
43548 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43549 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43550 !dump_write(cprm->file, kaddr,
43551 PAGE_SIZE);
43552 @@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43553
43554 if (e_phnum == PN_XNUM) {
43555 size += sizeof(*shdr4extnum);
43556 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43557 if (size > cprm->limit
43558 || !dump_write(cprm->file, shdr4extnum,
43559 sizeof(*shdr4extnum)))
43560 @@ -2092,6 +2545,97 @@ out:
43561
43562 #endif /* CONFIG_ELF_CORE */
43563
43564 +#ifdef CONFIG_PAX_MPROTECT
43565 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43566 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43567 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43568 + *
43569 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43570 + * basis because we want to allow the common case and not the special ones.
43571 + */
43572 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43573 +{
43574 + struct elfhdr elf_h;
43575 + struct elf_phdr elf_p;
43576 + unsigned long i;
43577 + unsigned long oldflags;
43578 + bool is_textrel_rw, is_textrel_rx, is_relro;
43579 +
43580 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43581 + return;
43582 +
43583 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43584 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43585 +
43586 +#ifdef CONFIG_PAX_ELFRELOCS
43587 + /* possible TEXTREL */
43588 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43589 + 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);
43590 +#else
43591 + is_textrel_rw = false;
43592 + is_textrel_rx = false;
43593 +#endif
43594 +
43595 + /* possible RELRO */
43596 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43597 +
43598 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43599 + return;
43600 +
43601 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43602 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43603 +
43604 +#ifdef CONFIG_PAX_ETEXECRELOCS
43605 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43606 +#else
43607 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43608 +#endif
43609 +
43610 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43611 + !elf_check_arch(&elf_h) ||
43612 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43613 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43614 + return;
43615 +
43616 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43617 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43618 + return;
43619 + switch (elf_p.p_type) {
43620 + case PT_DYNAMIC:
43621 + if (!is_textrel_rw && !is_textrel_rx)
43622 + continue;
43623 + i = 0UL;
43624 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43625 + elf_dyn dyn;
43626 +
43627 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43628 + return;
43629 + if (dyn.d_tag == DT_NULL)
43630 + return;
43631 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43632 + gr_log_textrel(vma);
43633 + if (is_textrel_rw)
43634 + vma->vm_flags |= VM_MAYWRITE;
43635 + else
43636 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43637 + vma->vm_flags &= ~VM_MAYWRITE;
43638 + return;
43639 + }
43640 + i++;
43641 + }
43642 + return;
43643 +
43644 + case PT_GNU_RELRO:
43645 + if (!is_relro)
43646 + continue;
43647 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43648 + vma->vm_flags &= ~VM_MAYWRITE;
43649 + return;
43650 + }
43651 + }
43652 +}
43653 +#endif
43654 +
43655 static int __init init_elf_binfmt(void)
43656 {
43657 register_binfmt(&elf_format);
43658 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43659 index 178cb70..8972997 100644
43660 --- a/fs/binfmt_flat.c
43661 +++ b/fs/binfmt_flat.c
43662 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43663 realdatastart = (unsigned long) -ENOMEM;
43664 printk("Unable to allocate RAM for process data, errno %d\n",
43665 (int)-realdatastart);
43666 + down_write(&current->mm->mmap_sem);
43667 vm_munmap(textpos, text_len);
43668 + up_write(&current->mm->mmap_sem);
43669 ret = realdatastart;
43670 goto err;
43671 }
43672 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43673 }
43674 if (IS_ERR_VALUE(result)) {
43675 printk("Unable to read data+bss, errno %d\n", (int)-result);
43676 + down_write(&current->mm->mmap_sem);
43677 vm_munmap(textpos, text_len);
43678 vm_munmap(realdatastart, len);
43679 + up_write(&current->mm->mmap_sem);
43680 ret = result;
43681 goto err;
43682 }
43683 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43684 }
43685 if (IS_ERR_VALUE(result)) {
43686 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43687 + down_write(&current->mm->mmap_sem);
43688 vm_munmap(textpos, text_len + data_len + extra +
43689 MAX_SHARED_LIBS * sizeof(unsigned long));
43690 + up_write(&current->mm->mmap_sem);
43691 ret = result;
43692 goto err;
43693 }
43694 diff --git a/fs/bio.c b/fs/bio.c
43695 index 71072ab..439851b 100644
43696 --- a/fs/bio.c
43697 +++ b/fs/bio.c
43698 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43699 /*
43700 * Overflow, abort
43701 */
43702 - if (end < start)
43703 + if (end < start || end - start > INT_MAX - nr_pages)
43704 return ERR_PTR(-EINVAL);
43705
43706 nr_pages += end - start;
43707 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43708 /*
43709 * Overflow, abort
43710 */
43711 - if (end < start)
43712 + if (end < start || end - start > INT_MAX - nr_pages)
43713 return ERR_PTR(-EINVAL);
43714
43715 nr_pages += end - start;
43716 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43717 const int read = bio_data_dir(bio) == READ;
43718 struct bio_map_data *bmd = bio->bi_private;
43719 int i;
43720 - char *p = bmd->sgvecs[0].iov_base;
43721 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43722
43723 __bio_for_each_segment(bvec, bio, i, 0) {
43724 char *addr = page_address(bvec->bv_page);
43725 diff --git a/fs/block_dev.c b/fs/block_dev.c
43726 index 38e721b..7a9c5bc 100644
43727 --- a/fs/block_dev.c
43728 +++ b/fs/block_dev.c
43729 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43730 else if (bdev->bd_contains == bdev)
43731 return true; /* is a whole device which isn't held */
43732
43733 - else if (whole->bd_holder == bd_may_claim)
43734 + else if (whole->bd_holder == (void *)bd_may_claim)
43735 return true; /* is a partition of a device that is being partitioned */
43736 else if (whole->bd_holder != NULL)
43737 return false; /* is a partition of a held device */
43738 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43739 index 9197e2e..7f731f8 100644
43740 --- a/fs/btrfs/check-integrity.c
43741 +++ b/fs/btrfs/check-integrity.c
43742 @@ -155,7 +155,7 @@ struct btrfsic_block {
43743 union {
43744 bio_end_io_t *bio;
43745 bh_end_io_t *bh;
43746 - } orig_bio_bh_end_io;
43747 + } __no_const orig_bio_bh_end_io;
43748 int submit_bio_bh_rw;
43749 u64 flush_gen; /* only valid if !never_written */
43750 };
43751 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43752 index 6d183f6..f47cc7a 100644
43753 --- a/fs/btrfs/ctree.c
43754 +++ b/fs/btrfs/ctree.c
43755 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43756 free_extent_buffer(buf);
43757 add_root_to_dirty_list(root);
43758 } else {
43759 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43760 - parent_start = parent->start;
43761 - else
43762 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43763 + if (parent)
43764 + parent_start = parent->start;
43765 + else
43766 + parent_start = 0;
43767 + } else
43768 parent_start = 0;
43769
43770 WARN_ON(trans->transid != btrfs_header_generation(parent));
43771 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43772 index ec154f9..bf617a7 100644
43773 --- a/fs/btrfs/inode.c
43774 +++ b/fs/btrfs/inode.c
43775 @@ -7126,7 +7126,7 @@ fail:
43776 return -ENOMEM;
43777 }
43778
43779 -static int btrfs_getattr(struct vfsmount *mnt,
43780 +int btrfs_getattr(struct vfsmount *mnt,
43781 struct dentry *dentry, struct kstat *stat)
43782 {
43783 struct inode *inode = dentry->d_inode;
43784 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43785 return 0;
43786 }
43787
43788 +EXPORT_SYMBOL(btrfs_getattr);
43789 +
43790 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43791 +{
43792 + return BTRFS_I(inode)->root->anon_dev;
43793 +}
43794 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43795 +
43796 /*
43797 * If a file is moved, it will inherit the cow and compression flags of the new
43798 * directory.
43799 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43800 index 9df50fa..6cd20d0 100644
43801 --- a/fs/btrfs/ioctl.c
43802 +++ b/fs/btrfs/ioctl.c
43803 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43804 for (i = 0; i < num_types; i++) {
43805 struct btrfs_space_info *tmp;
43806
43807 + /* Don't copy in more than we allocated */
43808 if (!slot_count)
43809 break;
43810
43811 + slot_count--;
43812 +
43813 info = NULL;
43814 rcu_read_lock();
43815 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43816 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43817 memcpy(dest, &space, sizeof(space));
43818 dest++;
43819 space_args.total_spaces++;
43820 - slot_count--;
43821 }
43822 - if (!slot_count)
43823 - break;
43824 }
43825 up_read(&info->groups_sem);
43826 }
43827 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43828 index 4da0865..01c4778 100644
43829 --- a/fs/btrfs/relocation.c
43830 +++ b/fs/btrfs/relocation.c
43831 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43832 }
43833 spin_unlock(&rc->reloc_root_tree.lock);
43834
43835 - BUG_ON((struct btrfs_root *)node->data != root);
43836 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43837
43838 if (!del) {
43839 spin_lock(&rc->reloc_root_tree.lock);
43840 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43841 index 622f469..e8d2d55 100644
43842 --- a/fs/cachefiles/bind.c
43843 +++ b/fs/cachefiles/bind.c
43844 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43845 args);
43846
43847 /* start by checking things over */
43848 - ASSERT(cache->fstop_percent >= 0 &&
43849 - cache->fstop_percent < cache->fcull_percent &&
43850 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43851 cache->fcull_percent < cache->frun_percent &&
43852 cache->frun_percent < 100);
43853
43854 - ASSERT(cache->bstop_percent >= 0 &&
43855 - cache->bstop_percent < cache->bcull_percent &&
43856 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43857 cache->bcull_percent < cache->brun_percent &&
43858 cache->brun_percent < 100);
43859
43860 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43861 index 0a1467b..6a53245 100644
43862 --- a/fs/cachefiles/daemon.c
43863 +++ b/fs/cachefiles/daemon.c
43864 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43865 if (n > buflen)
43866 return -EMSGSIZE;
43867
43868 - if (copy_to_user(_buffer, buffer, n) != 0)
43869 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43870 return -EFAULT;
43871
43872 return n;
43873 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43874 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43875 return -EIO;
43876
43877 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43878 + if (datalen > PAGE_SIZE - 1)
43879 return -EOPNOTSUPP;
43880
43881 /* drag the command string into the kernel so we can parse it */
43882 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43883 if (args[0] != '%' || args[1] != '\0')
43884 return -EINVAL;
43885
43886 - if (fstop < 0 || fstop >= cache->fcull_percent)
43887 + if (fstop >= cache->fcull_percent)
43888 return cachefiles_daemon_range_error(cache, args);
43889
43890 cache->fstop_percent = fstop;
43891 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43892 if (args[0] != '%' || args[1] != '\0')
43893 return -EINVAL;
43894
43895 - if (bstop < 0 || bstop >= cache->bcull_percent)
43896 + if (bstop >= cache->bcull_percent)
43897 return cachefiles_daemon_range_error(cache, args);
43898
43899 cache->bstop_percent = bstop;
43900 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43901 index bd6bc1b..b627b53 100644
43902 --- a/fs/cachefiles/internal.h
43903 +++ b/fs/cachefiles/internal.h
43904 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43905 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43906 struct rb_root active_nodes; /* active nodes (can't be culled) */
43907 rwlock_t active_lock; /* lock for active_nodes */
43908 - atomic_t gravecounter; /* graveyard uniquifier */
43909 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43910 unsigned frun_percent; /* when to stop culling (% files) */
43911 unsigned fcull_percent; /* when to start culling (% files) */
43912 unsigned fstop_percent; /* when to stop allocating (% files) */
43913 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43914 * proc.c
43915 */
43916 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43917 -extern atomic_t cachefiles_lookup_histogram[HZ];
43918 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43919 -extern atomic_t cachefiles_create_histogram[HZ];
43920 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43921 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43922 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43923
43924 extern int __init cachefiles_proc_init(void);
43925 extern void cachefiles_proc_cleanup(void);
43926 static inline
43927 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43928 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43929 {
43930 unsigned long jif = jiffies - start_jif;
43931 if (jif >= HZ)
43932 jif = HZ - 1;
43933 - atomic_inc(&histogram[jif]);
43934 + atomic_inc_unchecked(&histogram[jif]);
43935 }
43936
43937 #else
43938 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43939 index b0b5f7c..039bb26 100644
43940 --- a/fs/cachefiles/namei.c
43941 +++ b/fs/cachefiles/namei.c
43942 @@ -318,7 +318,7 @@ try_again:
43943 /* first step is to make up a grave dentry in the graveyard */
43944 sprintf(nbuffer, "%08x%08x",
43945 (uint32_t) get_seconds(),
43946 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43947 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43948
43949 /* do the multiway lock magic */
43950 trap = lock_rename(cache->graveyard, dir);
43951 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43952 index eccd339..4c1d995 100644
43953 --- a/fs/cachefiles/proc.c
43954 +++ b/fs/cachefiles/proc.c
43955 @@ -14,9 +14,9 @@
43956 #include <linux/seq_file.h>
43957 #include "internal.h"
43958
43959 -atomic_t cachefiles_lookup_histogram[HZ];
43960 -atomic_t cachefiles_mkdir_histogram[HZ];
43961 -atomic_t cachefiles_create_histogram[HZ];
43962 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43963 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43964 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43965
43966 /*
43967 * display the latency histogram
43968 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43969 return 0;
43970 default:
43971 index = (unsigned long) v - 3;
43972 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43973 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43974 - z = atomic_read(&cachefiles_create_histogram[index]);
43975 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43976 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43977 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43978 if (x == 0 && y == 0 && z == 0)
43979 return 0;
43980
43981 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43982 index c994691..2a1537f 100644
43983 --- a/fs/cachefiles/rdwr.c
43984 +++ b/fs/cachefiles/rdwr.c
43985 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43986 old_fs = get_fs();
43987 set_fs(KERNEL_DS);
43988 ret = file->f_op->write(
43989 - file, (const void __user *) data, len, &pos);
43990 + file, (const void __force_user *) data, len, &pos);
43991 set_fs(old_fs);
43992 kunmap(page);
43993 if (ret != len)
43994 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43995 index e5b7731..b9c59fb 100644
43996 --- a/fs/ceph/dir.c
43997 +++ b/fs/ceph/dir.c
43998 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43999 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44000 struct ceph_mds_client *mdsc = fsc->mdsc;
44001 unsigned frag = fpos_frag(filp->f_pos);
44002 - int off = fpos_off(filp->f_pos);
44003 + unsigned int off = fpos_off(filp->f_pos);
44004 int err;
44005 u32 ftype;
44006 struct ceph_mds_reply_info_parsed *rinfo;
44007 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44008 index d9ea6ed..1e6c8ac 100644
44009 --- a/fs/cifs/cifs_debug.c
44010 +++ b/fs/cifs/cifs_debug.c
44011 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44012
44013 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44014 #ifdef CONFIG_CIFS_STATS2
44015 - atomic_set(&totBufAllocCount, 0);
44016 - atomic_set(&totSmBufAllocCount, 0);
44017 + atomic_set_unchecked(&totBufAllocCount, 0);
44018 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44019 #endif /* CONFIG_CIFS_STATS2 */
44020 spin_lock(&cifs_tcp_ses_lock);
44021 list_for_each(tmp1, &cifs_tcp_ses_list) {
44022 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44023 tcon = list_entry(tmp3,
44024 struct cifs_tcon,
44025 tcon_list);
44026 - atomic_set(&tcon->num_smbs_sent, 0);
44027 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44028 if (server->ops->clear_stats)
44029 server->ops->clear_stats(tcon);
44030 }
44031 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44032 smBufAllocCount.counter, cifs_min_small);
44033 #ifdef CONFIG_CIFS_STATS2
44034 seq_printf(m, "Total Large %d Small %d Allocations\n",
44035 - atomic_read(&totBufAllocCount),
44036 - atomic_read(&totSmBufAllocCount));
44037 + atomic_read_unchecked(&totBufAllocCount),
44038 + atomic_read_unchecked(&totSmBufAllocCount));
44039 #endif /* CONFIG_CIFS_STATS2 */
44040
44041 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44042 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44043 if (tcon->need_reconnect)
44044 seq_puts(m, "\tDISCONNECTED ");
44045 seq_printf(m, "\nSMBs: %d",
44046 - atomic_read(&tcon->num_smbs_sent));
44047 + atomic_read_unchecked(&tcon->num_smbs_sent));
44048 if (server->ops->print_stats)
44049 server->ops->print_stats(m, tcon);
44050 }
44051 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44052 index db8a404..c712e2e 100644
44053 --- a/fs/cifs/cifsfs.c
44054 +++ b/fs/cifs/cifsfs.c
44055 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44056 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44057 cifs_req_cachep = kmem_cache_create("cifs_request",
44058 CIFSMaxBufSize + max_hdr_size, 0,
44059 - SLAB_HWCACHE_ALIGN, NULL);
44060 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44061 if (cifs_req_cachep == NULL)
44062 return -ENOMEM;
44063
44064 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44065 efficient to alloc 1 per page off the slab compared to 17K (5page)
44066 alloc of large cifs buffers even when page debugging is on */
44067 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44068 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44069 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44070 NULL);
44071 if (cifs_sm_req_cachep == NULL) {
44072 mempool_destroy(cifs_req_poolp);
44073 @@ -1115,8 +1115,8 @@ init_cifs(void)
44074 atomic_set(&bufAllocCount, 0);
44075 atomic_set(&smBufAllocCount, 0);
44076 #ifdef CONFIG_CIFS_STATS2
44077 - atomic_set(&totBufAllocCount, 0);
44078 - atomic_set(&totSmBufAllocCount, 0);
44079 + atomic_set_unchecked(&totBufAllocCount, 0);
44080 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44081 #endif /* CONFIG_CIFS_STATS2 */
44082
44083 atomic_set(&midCount, 0);
44084 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44085 index 977dc0e..ba48ab9 100644
44086 --- a/fs/cifs/cifsglob.h
44087 +++ b/fs/cifs/cifsglob.h
44088 @@ -590,35 +590,35 @@ struct cifs_tcon {
44089 __u16 Flags; /* optional support bits */
44090 enum statusEnum tidStatus;
44091 #ifdef CONFIG_CIFS_STATS
44092 - atomic_t num_smbs_sent;
44093 + atomic_unchecked_t num_smbs_sent;
44094 union {
44095 struct {
44096 - atomic_t num_writes;
44097 - atomic_t num_reads;
44098 - atomic_t num_flushes;
44099 - atomic_t num_oplock_brks;
44100 - atomic_t num_opens;
44101 - atomic_t num_closes;
44102 - atomic_t num_deletes;
44103 - atomic_t num_mkdirs;
44104 - atomic_t num_posixopens;
44105 - atomic_t num_posixmkdirs;
44106 - atomic_t num_rmdirs;
44107 - atomic_t num_renames;
44108 - atomic_t num_t2renames;
44109 - atomic_t num_ffirst;
44110 - atomic_t num_fnext;
44111 - atomic_t num_fclose;
44112 - atomic_t num_hardlinks;
44113 - atomic_t num_symlinks;
44114 - atomic_t num_locks;
44115 - atomic_t num_acl_get;
44116 - atomic_t num_acl_set;
44117 + atomic_unchecked_t num_writes;
44118 + atomic_unchecked_t num_reads;
44119 + atomic_unchecked_t num_flushes;
44120 + atomic_unchecked_t num_oplock_brks;
44121 + atomic_unchecked_t num_opens;
44122 + atomic_unchecked_t num_closes;
44123 + atomic_unchecked_t num_deletes;
44124 + atomic_unchecked_t num_mkdirs;
44125 + atomic_unchecked_t num_posixopens;
44126 + atomic_unchecked_t num_posixmkdirs;
44127 + atomic_unchecked_t num_rmdirs;
44128 + atomic_unchecked_t num_renames;
44129 + atomic_unchecked_t num_t2renames;
44130 + atomic_unchecked_t num_ffirst;
44131 + atomic_unchecked_t num_fnext;
44132 + atomic_unchecked_t num_fclose;
44133 + atomic_unchecked_t num_hardlinks;
44134 + atomic_unchecked_t num_symlinks;
44135 + atomic_unchecked_t num_locks;
44136 + atomic_unchecked_t num_acl_get;
44137 + atomic_unchecked_t num_acl_set;
44138 } cifs_stats;
44139 #ifdef CONFIG_CIFS_SMB2
44140 struct {
44141 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44142 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44143 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44144 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44145 } smb2_stats;
44146 #endif /* CONFIG_CIFS_SMB2 */
44147 } stats;
44148 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44149 }
44150
44151 #ifdef CONFIG_CIFS_STATS
44152 -#define cifs_stats_inc atomic_inc
44153 +#define cifs_stats_inc atomic_inc_unchecked
44154
44155 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44156 unsigned int bytes)
44157 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44158 /* Various Debug counters */
44159 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44160 #ifdef CONFIG_CIFS_STATS2
44161 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44162 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44163 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44164 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44165 #endif
44166 GLOBAL_EXTERN atomic_t smBufAllocCount;
44167 GLOBAL_EXTERN atomic_t midCount;
44168 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44169 index e6ce3b1..adc21fd 100644
44170 --- a/fs/cifs/link.c
44171 +++ b/fs/cifs/link.c
44172 @@ -602,7 +602,7 @@ symlink_exit:
44173
44174 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44175 {
44176 - char *p = nd_get_link(nd);
44177 + const char *p = nd_get_link(nd);
44178 if (!IS_ERR(p))
44179 kfree(p);
44180 }
44181 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44182 index ce41fee..ac0d27a 100644
44183 --- a/fs/cifs/misc.c
44184 +++ b/fs/cifs/misc.c
44185 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44186 memset(ret_buf, 0, buf_size + 3);
44187 atomic_inc(&bufAllocCount);
44188 #ifdef CONFIG_CIFS_STATS2
44189 - atomic_inc(&totBufAllocCount);
44190 + atomic_inc_unchecked(&totBufAllocCount);
44191 #endif /* CONFIG_CIFS_STATS2 */
44192 }
44193
44194 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44195 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44196 atomic_inc(&smBufAllocCount);
44197 #ifdef CONFIG_CIFS_STATS2
44198 - atomic_inc(&totSmBufAllocCount);
44199 + atomic_inc_unchecked(&totSmBufAllocCount);
44200 #endif /* CONFIG_CIFS_STATS2 */
44201
44202 }
44203 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44204 index 3129ac7..cc4a948 100644
44205 --- a/fs/cifs/smb1ops.c
44206 +++ b/fs/cifs/smb1ops.c
44207 @@ -524,27 +524,27 @@ static void
44208 cifs_clear_stats(struct cifs_tcon *tcon)
44209 {
44210 #ifdef CONFIG_CIFS_STATS
44211 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44212 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44213 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44214 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44215 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44216 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44217 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44218 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44219 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44220 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44221 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44222 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44223 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44224 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44225 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44226 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44227 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44228 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44229 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44230 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44231 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44232 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44233 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44234 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44235 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44236 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44237 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44238 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44239 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44240 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44241 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44242 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44243 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44244 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44245 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44246 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44247 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44253 #endif
44254 }
44255
44256 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44257 {
44258 #ifdef CONFIG_CIFS_STATS
44259 seq_printf(m, " Oplocks breaks: %d",
44260 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44261 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44262 seq_printf(m, "\nReads: %d Bytes: %llu",
44263 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44264 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44265 (long long)(tcon->bytes_read));
44266 seq_printf(m, "\nWrites: %d Bytes: %llu",
44267 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44268 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44269 (long long)(tcon->bytes_written));
44270 seq_printf(m, "\nFlushes: %d",
44271 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44272 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44273 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44274 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44275 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44276 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44277 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44278 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44279 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44280 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44281 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44282 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44283 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44284 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44285 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44286 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44287 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44288 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44289 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44290 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44291 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44292 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44293 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44294 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44295 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44296 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44297 seq_printf(m, "\nRenames: %d T2 Renames %d",
44298 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44299 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44300 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44301 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44302 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44303 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44304 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44305 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44307 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44308 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44309 #endif
44310 }
44311
44312 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44313 index 826209b..fa460f4 100644
44314 --- a/fs/cifs/smb2ops.c
44315 +++ b/fs/cifs/smb2ops.c
44316 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44317 #ifdef CONFIG_CIFS_STATS
44318 int i;
44319 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44320 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44321 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44322 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44323 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44324 }
44325 #endif
44326 }
44327 @@ -229,66 +229,66 @@ static void
44328 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44329 {
44330 #ifdef CONFIG_CIFS_STATS
44331 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44332 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44333 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44334 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44335 seq_printf(m, "\nNegotiates: %d sent %d failed",
44336 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44337 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44338 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44339 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44340 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44341 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44342 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44343 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44344 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44345 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44346 seq_printf(m, "\nLogoffs: %d sent %d failed",
44347 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44348 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44349 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44350 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44351 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44352 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44353 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44354 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44355 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44356 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44357 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44358 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44359 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44360 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44361 seq_printf(m, "\nCreates: %d sent %d failed",
44362 - atomic_read(&sent[SMB2_CREATE_HE]),
44363 - atomic_read(&failed[SMB2_CREATE_HE]));
44364 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44365 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44366 seq_printf(m, "\nCloses: %d sent %d failed",
44367 - atomic_read(&sent[SMB2_CLOSE_HE]),
44368 - atomic_read(&failed[SMB2_CLOSE_HE]));
44369 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44370 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44371 seq_printf(m, "\nFlushes: %d sent %d failed",
44372 - atomic_read(&sent[SMB2_FLUSH_HE]),
44373 - atomic_read(&failed[SMB2_FLUSH_HE]));
44374 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44375 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44376 seq_printf(m, "\nReads: %d sent %d failed",
44377 - atomic_read(&sent[SMB2_READ_HE]),
44378 - atomic_read(&failed[SMB2_READ_HE]));
44379 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44380 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44381 seq_printf(m, "\nWrites: %d sent %d failed",
44382 - atomic_read(&sent[SMB2_WRITE_HE]),
44383 - atomic_read(&failed[SMB2_WRITE_HE]));
44384 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44385 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44386 seq_printf(m, "\nLocks: %d sent %d failed",
44387 - atomic_read(&sent[SMB2_LOCK_HE]),
44388 - atomic_read(&failed[SMB2_LOCK_HE]));
44389 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44390 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44391 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44392 - atomic_read(&sent[SMB2_IOCTL_HE]),
44393 - atomic_read(&failed[SMB2_IOCTL_HE]));
44394 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44395 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44396 seq_printf(m, "\nCancels: %d sent %d failed",
44397 - atomic_read(&sent[SMB2_CANCEL_HE]),
44398 - atomic_read(&failed[SMB2_CANCEL_HE]));
44399 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44400 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44401 seq_printf(m, "\nEchos: %d sent %d failed",
44402 - atomic_read(&sent[SMB2_ECHO_HE]),
44403 - atomic_read(&failed[SMB2_ECHO_HE]));
44404 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44405 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44406 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44407 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44408 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44409 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44410 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44411 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44412 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44413 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44414 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44415 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44416 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44417 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44418 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44419 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44420 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44421 seq_printf(m, "\nSetInfos: %d sent %d failed",
44422 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44423 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44424 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44425 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44426 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44427 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44428 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44429 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44430 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44431 #endif
44432 }
44433
44434 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44435 index 958ae0e..505c9d0 100644
44436 --- a/fs/coda/cache.c
44437 +++ b/fs/coda/cache.c
44438 @@ -24,7 +24,7 @@
44439 #include "coda_linux.h"
44440 #include "coda_cache.h"
44441
44442 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44443 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44444
44445 /* replace or extend an acl cache hit */
44446 void coda_cache_enter(struct inode *inode, int mask)
44447 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44448 struct coda_inode_info *cii = ITOC(inode);
44449
44450 spin_lock(&cii->c_lock);
44451 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44452 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44453 if (cii->c_uid != current_fsuid()) {
44454 cii->c_uid = current_fsuid();
44455 cii->c_cached_perm = mask;
44456 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44457 {
44458 struct coda_inode_info *cii = ITOC(inode);
44459 spin_lock(&cii->c_lock);
44460 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44461 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44462 spin_unlock(&cii->c_lock);
44463 }
44464
44465 /* remove all acl caches */
44466 void coda_cache_clear_all(struct super_block *sb)
44467 {
44468 - atomic_inc(&permission_epoch);
44469 + atomic_inc_unchecked(&permission_epoch);
44470 }
44471
44472
44473 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44474 spin_lock(&cii->c_lock);
44475 hit = (mask & cii->c_cached_perm) == mask &&
44476 cii->c_uid == current_fsuid() &&
44477 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44478 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44479 spin_unlock(&cii->c_lock);
44480
44481 return hit;
44482 diff --git a/fs/compat.c b/fs/compat.c
44483 index 1bdb350..9f28287 100644
44484 --- a/fs/compat.c
44485 +++ b/fs/compat.c
44486 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44487
44488 set_fs(KERNEL_DS);
44489 /* The __user pointer cast is valid because of the set_fs() */
44490 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44491 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44492 set_fs(oldfs);
44493 /* truncating is ok because it's a user address */
44494 if (!ret)
44495 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44496 goto out;
44497
44498 ret = -EINVAL;
44499 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44500 + if (nr_segs > UIO_MAXIOV)
44501 goto out;
44502 if (nr_segs > fast_segs) {
44503 ret = -ENOMEM;
44504 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44505
44506 struct compat_readdir_callback {
44507 struct compat_old_linux_dirent __user *dirent;
44508 + struct file * file;
44509 int result;
44510 };
44511
44512 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44513 buf->result = -EOVERFLOW;
44514 return -EOVERFLOW;
44515 }
44516 +
44517 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44518 + return 0;
44519 +
44520 buf->result++;
44521 dirent = buf->dirent;
44522 if (!access_ok(VERIFY_WRITE, dirent,
44523 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44524
44525 buf.result = 0;
44526 buf.dirent = dirent;
44527 + buf.file = file;
44528
44529 error = vfs_readdir(file, compat_fillonedir, &buf);
44530 if (buf.result)
44531 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44532 struct compat_getdents_callback {
44533 struct compat_linux_dirent __user *current_dir;
44534 struct compat_linux_dirent __user *previous;
44535 + struct file * file;
44536 int count;
44537 int error;
44538 };
44539 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44540 buf->error = -EOVERFLOW;
44541 return -EOVERFLOW;
44542 }
44543 +
44544 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44545 + return 0;
44546 +
44547 dirent = buf->previous;
44548 if (dirent) {
44549 if (__put_user(offset, &dirent->d_off))
44550 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44551 buf.previous = NULL;
44552 buf.count = count;
44553 buf.error = 0;
44554 + buf.file = file;
44555
44556 error = vfs_readdir(file, compat_filldir, &buf);
44557 if (error >= 0)
44558 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44559 struct compat_getdents_callback64 {
44560 struct linux_dirent64 __user *current_dir;
44561 struct linux_dirent64 __user *previous;
44562 + struct file * file;
44563 int count;
44564 int error;
44565 };
44566 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44567 buf->error = -EINVAL; /* only used if we fail.. */
44568 if (reclen > buf->count)
44569 return -EINVAL;
44570 +
44571 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44572 + return 0;
44573 +
44574 dirent = buf->previous;
44575
44576 if (dirent) {
44577 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44578 buf.previous = NULL;
44579 buf.count = count;
44580 buf.error = 0;
44581 + buf.file = file;
44582
44583 error = vfs_readdir(file, compat_filldir64, &buf);
44584 if (error >= 0)
44585 error = buf.error;
44586 lastdirent = buf.previous;
44587 if (lastdirent) {
44588 - typeof(lastdirent->d_off) d_off = file->f_pos;
44589 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44590 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44591 error = -EFAULT;
44592 else
44593 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44594 index 112e45a..b59845b 100644
44595 --- a/fs/compat_binfmt_elf.c
44596 +++ b/fs/compat_binfmt_elf.c
44597 @@ -30,11 +30,13 @@
44598 #undef elf_phdr
44599 #undef elf_shdr
44600 #undef elf_note
44601 +#undef elf_dyn
44602 #undef elf_addr_t
44603 #define elfhdr elf32_hdr
44604 #define elf_phdr elf32_phdr
44605 #define elf_shdr elf32_shdr
44606 #define elf_note elf32_note
44607 +#define elf_dyn Elf32_Dyn
44608 #define elf_addr_t Elf32_Addr
44609
44610 /*
44611 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44612 index debdfe0..75d31d4 100644
44613 --- a/fs/compat_ioctl.c
44614 +++ b/fs/compat_ioctl.c
44615 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44616
44617 err = get_user(palp, &up->palette);
44618 err |= get_user(length, &up->length);
44619 + if (err)
44620 + return -EFAULT;
44621
44622 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44623 err = put_user(compat_ptr(palp), &up_native->palette);
44624 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44625 return -EFAULT;
44626 if (__get_user(udata, &ss32->iomem_base))
44627 return -EFAULT;
44628 - ss.iomem_base = compat_ptr(udata);
44629 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44630 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44631 __get_user(ss.port_high, &ss32->port_high))
44632 return -EFAULT;
44633 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44634 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44635 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44636 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44637 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44638 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44639 return -EFAULT;
44640
44641 return ioctl_preallocate(file, p);
44642 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44643 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44644 {
44645 unsigned int a, b;
44646 - a = *(unsigned int *)p;
44647 - b = *(unsigned int *)q;
44648 + a = *(const unsigned int *)p;
44649 + b = *(const unsigned int *)q;
44650 if (a > b)
44651 return 1;
44652 if (a < b)
44653 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44654 index 7414ae2..d98ad6d 100644
44655 --- a/fs/configfs/dir.c
44656 +++ b/fs/configfs/dir.c
44657 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44658 }
44659 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44660 struct configfs_dirent *next;
44661 - const char * name;
44662 + const unsigned char * name;
44663 + char d_name[sizeof(next->s_dentry->d_iname)];
44664 int len;
44665 struct inode *inode = NULL;
44666
44667 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44668 continue;
44669
44670 name = configfs_get_name(next);
44671 - len = strlen(name);
44672 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44673 + len = next->s_dentry->d_name.len;
44674 + memcpy(d_name, name, len);
44675 + name = d_name;
44676 + } else
44677 + len = strlen(name);
44678
44679 /*
44680 * We'll have a dentry and an inode for
44681 diff --git a/fs/dcache.c b/fs/dcache.c
44682 index 693f95b..95f1223 100644
44683 --- a/fs/dcache.c
44684 +++ b/fs/dcache.c
44685 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44686 mempages -= reserve;
44687
44688 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44689 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44690 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44691
44692 dcache_init();
44693 inode_init();
44694 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44695 index 4733eab..71ef6fa 100644
44696 --- a/fs/debugfs/inode.c
44697 +++ b/fs/debugfs/inode.c
44698 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44699 */
44700 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44701 {
44702 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44703 + return __create_file(name, S_IFDIR | S_IRWXU,
44704 +#else
44705 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44706 +#endif
44707 parent, NULL, NULL);
44708 }
44709 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44710 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44711 index cc7709e..7e7211f 100644
44712 --- a/fs/ecryptfs/inode.c
44713 +++ b/fs/ecryptfs/inode.c
44714 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44715 old_fs = get_fs();
44716 set_fs(get_ds());
44717 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44718 - (char __user *)lower_buf,
44719 + (char __force_user *)lower_buf,
44720 PATH_MAX);
44721 set_fs(old_fs);
44722 if (rc < 0)
44723 @@ -706,7 +706,7 @@ out:
44724 static void
44725 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44726 {
44727 - char *buf = nd_get_link(nd);
44728 + const char *buf = nd_get_link(nd);
44729 if (!IS_ERR(buf)) {
44730 /* Free the char* */
44731 kfree(buf);
44732 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44733 index 412e6ed..4292d22 100644
44734 --- a/fs/ecryptfs/miscdev.c
44735 +++ b/fs/ecryptfs/miscdev.c
44736 @@ -315,7 +315,7 @@ check_list:
44737 goto out_unlock_msg_ctx;
44738 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44739 if (msg_ctx->msg) {
44740 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44741 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44742 goto out_unlock_msg_ctx;
44743 i += packet_length_size;
44744 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44745 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44746 index b2a34a1..162fa69 100644
44747 --- a/fs/ecryptfs/read_write.c
44748 +++ b/fs/ecryptfs/read_write.c
44749 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44750 return -EIO;
44751 fs_save = get_fs();
44752 set_fs(get_ds());
44753 - rc = vfs_write(lower_file, data, size, &offset);
44754 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44755 set_fs(fs_save);
44756 mark_inode_dirty_sync(ecryptfs_inode);
44757 return rc;
44758 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44759 return -EIO;
44760 fs_save = get_fs();
44761 set_fs(get_ds());
44762 - rc = vfs_read(lower_file, data, size, &offset);
44763 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44764 set_fs(fs_save);
44765 return rc;
44766 }
44767 diff --git a/fs/exec.c b/fs/exec.c
44768 index 574cf4d..dfe774a 100644
44769 --- a/fs/exec.c
44770 +++ b/fs/exec.c
44771 @@ -55,6 +55,15 @@
44772 #include <linux/pipe_fs_i.h>
44773 #include <linux/oom.h>
44774 #include <linux/compat.h>
44775 +#include <linux/random.h>
44776 +#include <linux/seq_file.h>
44777 +
44778 +#ifdef CONFIG_PAX_REFCOUNT
44779 +#include <linux/kallsyms.h>
44780 +#include <linux/kdebug.h>
44781 +#endif
44782 +
44783 +#include <trace/events/fs.h>
44784
44785 #include <asm/uaccess.h>
44786 #include <asm/mmu_context.h>
44787 @@ -66,6 +75,18 @@
44788
44789 #include <trace/events/sched.h>
44790
44791 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44792 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44793 +{
44794 + WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
44795 +}
44796 +#endif
44797 +
44798 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44799 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44800 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44801 +#endif
44802 +
44803 int core_uses_pid;
44804 char core_pattern[CORENAME_MAX_SIZE] = "core";
44805 unsigned int core_pipe_limit;
44806 @@ -75,7 +96,7 @@ struct core_name {
44807 char *corename;
44808 int used, size;
44809 };
44810 -static atomic_t call_count = ATOMIC_INIT(1);
44811 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44812
44813 /* The maximal length of core_pattern is also specified in sysctl.c */
44814
44815 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44816 int write)
44817 {
44818 struct page *page;
44819 - int ret;
44820
44821 -#ifdef CONFIG_STACK_GROWSUP
44822 - if (write) {
44823 - ret = expand_downwards(bprm->vma, pos);
44824 - if (ret < 0)
44825 - return NULL;
44826 - }
44827 -#endif
44828 - ret = get_user_pages(current, bprm->mm, pos,
44829 - 1, write, 1, &page, NULL);
44830 - if (ret <= 0)
44831 + if (0 > expand_downwards(bprm->vma, pos))
44832 + return NULL;
44833 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44834 return NULL;
44835
44836 if (write) {
44837 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44838 if (size <= ARG_MAX)
44839 return page;
44840
44841 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44842 + // only allow 512KB for argv+env on suid/sgid binaries
44843 + // to prevent easy ASLR exhaustion
44844 + if (((bprm->cred->euid != current_euid()) ||
44845 + (bprm->cred->egid != current_egid())) &&
44846 + (size > (512 * 1024))) {
44847 + put_page(page);
44848 + return NULL;
44849 + }
44850 +#endif
44851 +
44852 /*
44853 * Limit to 1/4-th the stack size for the argv+env strings.
44854 * This ensures that:
44855 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44856 vma->vm_end = STACK_TOP_MAX;
44857 vma->vm_start = vma->vm_end - PAGE_SIZE;
44858 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44859 +
44860 +#ifdef CONFIG_PAX_SEGMEXEC
44861 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44862 +#endif
44863 +
44864 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44865 INIT_LIST_HEAD(&vma->anon_vma_chain);
44866
44867 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44868 mm->stack_vm = mm->total_vm = 1;
44869 up_write(&mm->mmap_sem);
44870 bprm->p = vma->vm_end - sizeof(void *);
44871 +
44872 +#ifdef CONFIG_PAX_RANDUSTACK
44873 + if (randomize_va_space)
44874 + bprm->p ^= random32() & ~PAGE_MASK;
44875 +#endif
44876 +
44877 return 0;
44878 err:
44879 up_write(&mm->mmap_sem);
44880 @@ -395,19 +430,7 @@ err:
44881 return err;
44882 }
44883
44884 -struct user_arg_ptr {
44885 -#ifdef CONFIG_COMPAT
44886 - bool is_compat;
44887 -#endif
44888 - union {
44889 - const char __user *const __user *native;
44890 -#ifdef CONFIG_COMPAT
44891 - compat_uptr_t __user *compat;
44892 -#endif
44893 - } ptr;
44894 -};
44895 -
44896 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44897 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44898 {
44899 const char __user *native;
44900
44901 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44902 compat_uptr_t compat;
44903
44904 if (get_user(compat, argv.ptr.compat + nr))
44905 - return ERR_PTR(-EFAULT);
44906 + return (const char __force_user *)ERR_PTR(-EFAULT);
44907
44908 return compat_ptr(compat);
44909 }
44910 #endif
44911
44912 if (get_user(native, argv.ptr.native + nr))
44913 - return ERR_PTR(-EFAULT);
44914 + return (const char __force_user *)ERR_PTR(-EFAULT);
44915
44916 return native;
44917 }
44918 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44919 if (!p)
44920 break;
44921
44922 - if (IS_ERR(p))
44923 + if (IS_ERR((const char __force_kernel *)p))
44924 return -EFAULT;
44925
44926 if (i++ >= max)
44927 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44928
44929 ret = -EFAULT;
44930 str = get_user_arg_ptr(argv, argc);
44931 - if (IS_ERR(str))
44932 + if (IS_ERR((const char __force_kernel *)str))
44933 goto out;
44934
44935 len = strnlen_user(str, MAX_ARG_STRLEN);
44936 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44937 int r;
44938 mm_segment_t oldfs = get_fs();
44939 struct user_arg_ptr argv = {
44940 - .ptr.native = (const char __user *const __user *)__argv,
44941 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44942 };
44943
44944 set_fs(KERNEL_DS);
44945 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44946 unsigned long new_end = old_end - shift;
44947 struct mmu_gather tlb;
44948
44949 - BUG_ON(new_start > new_end);
44950 + if (new_start >= new_end || new_start < mmap_min_addr)
44951 + return -ENOMEM;
44952
44953 /*
44954 * ensure there are no vmas between where we want to go
44955 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44956 if (vma != find_vma(mm, new_start))
44957 return -EFAULT;
44958
44959 +#ifdef CONFIG_PAX_SEGMEXEC
44960 + BUG_ON(pax_find_mirror_vma(vma));
44961 +#endif
44962 +
44963 /*
44964 * cover the whole range: [new_start, old_end)
44965 */
44966 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44967 stack_top = arch_align_stack(stack_top);
44968 stack_top = PAGE_ALIGN(stack_top);
44969
44970 - if (unlikely(stack_top < mmap_min_addr) ||
44971 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44972 - return -ENOMEM;
44973 -
44974 stack_shift = vma->vm_end - stack_top;
44975
44976 bprm->p -= stack_shift;
44977 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44978 bprm->exec -= stack_shift;
44979
44980 down_write(&mm->mmap_sem);
44981 +
44982 + /* Move stack pages down in memory. */
44983 + if (stack_shift) {
44984 + ret = shift_arg_pages(vma, stack_shift);
44985 + if (ret)
44986 + goto out_unlock;
44987 + }
44988 +
44989 vm_flags = VM_STACK_FLAGS;
44990
44991 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44992 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44993 + vm_flags &= ~VM_EXEC;
44994 +
44995 +#ifdef CONFIG_PAX_MPROTECT
44996 + if (mm->pax_flags & MF_PAX_MPROTECT)
44997 + vm_flags &= ~VM_MAYEXEC;
44998 +#endif
44999 +
45000 + }
45001 +#endif
45002 +
45003 /*
45004 * Adjust stack execute permissions; explicitly enable for
45005 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45006 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45007 goto out_unlock;
45008 BUG_ON(prev != vma);
45009
45010 - /* Move stack pages down in memory. */
45011 - if (stack_shift) {
45012 - ret = shift_arg_pages(vma, stack_shift);
45013 - if (ret)
45014 - goto out_unlock;
45015 - }
45016 -
45017 /* mprotect_fixup is overkill to remove the temporary stack flags */
45018 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45019
45020 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45021
45022 fsnotify_open(file);
45023
45024 + trace_open_exec(name);
45025 +
45026 err = deny_write_access(file);
45027 if (err)
45028 goto exit;
45029 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45030 old_fs = get_fs();
45031 set_fs(get_ds());
45032 /* The cast to a user pointer is valid due to the set_fs() */
45033 - result = vfs_read(file, (void __user *)addr, count, &pos);
45034 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45035 set_fs(old_fs);
45036 return result;
45037 }
45038 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45039 }
45040 rcu_read_unlock();
45041
45042 - if (p->fs->users > n_fs) {
45043 + if (atomic_read(&p->fs->users) > n_fs) {
45044 bprm->unsafe |= LSM_UNSAFE_SHARE;
45045 } else {
45046 res = -EAGAIN;
45047 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45048
45049 EXPORT_SYMBOL(search_binary_handler);
45050
45051 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45052 +static DEFINE_PER_CPU(u64, exec_counter);
45053 +static int __init init_exec_counters(void)
45054 +{
45055 + unsigned int cpu;
45056 +
45057 + for_each_possible_cpu(cpu) {
45058 + per_cpu(exec_counter, cpu) = (u64)cpu;
45059 + }
45060 +
45061 + return 0;
45062 +}
45063 +early_initcall(init_exec_counters);
45064 +static inline void increment_exec_counter(void)
45065 +{
45066 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45067 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45068 +}
45069 +#else
45070 +static inline void increment_exec_counter(void) {}
45071 +#endif
45072 +
45073 /*
45074 * sys_execve() executes a new program.
45075 */
45076 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45077 struct user_arg_ptr envp,
45078 struct pt_regs *regs)
45079 {
45080 +#ifdef CONFIG_GRKERNSEC
45081 + struct file *old_exec_file;
45082 + struct acl_subject_label *old_acl;
45083 + struct rlimit old_rlim[RLIM_NLIMITS];
45084 +#endif
45085 struct linux_binprm *bprm;
45086 struct file *file;
45087 struct files_struct *displaced;
45088 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45089 int retval;
45090 const struct cred *cred = current_cred();
45091
45092 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45093 +
45094 /*
45095 * We move the actual failure in case of RLIMIT_NPROC excess from
45096 * set*uid() to execve() because too many poorly written programs
45097 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45098 if (IS_ERR(file))
45099 goto out_unmark;
45100
45101 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45102 + retval = -EPERM;
45103 + goto out_file;
45104 + }
45105 +
45106 sched_exec();
45107
45108 bprm->file = file;
45109 bprm->filename = filename;
45110 bprm->interp = filename;
45111
45112 + if (gr_process_user_ban()) {
45113 + retval = -EPERM;
45114 + goto out_file;
45115 + }
45116 +
45117 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45118 + retval = -EACCES;
45119 + goto out_file;
45120 + }
45121 +
45122 retval = bprm_mm_init(bprm);
45123 if (retval)
45124 goto out_file;
45125 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45126 if (retval < 0)
45127 goto out;
45128
45129 +#ifdef CONFIG_GRKERNSEC
45130 + old_acl = current->acl;
45131 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45132 + old_exec_file = current->exec_file;
45133 + get_file(file);
45134 + current->exec_file = file;
45135 +#endif
45136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45137 + /* limit suid stack to 8MB
45138 + we saved the old limits above and will restore them if this exec fails
45139 + */
45140 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45141 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45142 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45143 +#endif
45144 +
45145 + if (!gr_tpe_allow(file)) {
45146 + retval = -EACCES;
45147 + goto out_fail;
45148 + }
45149 +
45150 + if (gr_check_crash_exec(file)) {
45151 + retval = -EACCES;
45152 + goto out_fail;
45153 + }
45154 +
45155 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45156 + bprm->unsafe);
45157 + if (retval < 0)
45158 + goto out_fail;
45159 +
45160 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45161 if (retval < 0)
45162 - goto out;
45163 + goto out_fail;
45164
45165 bprm->exec = bprm->p;
45166 retval = copy_strings(bprm->envc, envp, bprm);
45167 if (retval < 0)
45168 - goto out;
45169 + goto out_fail;
45170
45171 retval = copy_strings(bprm->argc, argv, bprm);
45172 if (retval < 0)
45173 - goto out;
45174 + goto out_fail;
45175 +
45176 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45177 +
45178 + gr_handle_exec_args(bprm, argv);
45179
45180 retval = search_binary_handler(bprm,regs);
45181 if (retval < 0)
45182 - goto out;
45183 + goto out_fail;
45184 +#ifdef CONFIG_GRKERNSEC
45185 + if (old_exec_file)
45186 + fput(old_exec_file);
45187 +#endif
45188
45189 /* execve succeeded */
45190 +
45191 + increment_exec_counter();
45192 current->fs->in_exec = 0;
45193 current->in_execve = 0;
45194 acct_update_integrals(current);
45195 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45196 put_files_struct(displaced);
45197 return retval;
45198
45199 +out_fail:
45200 +#ifdef CONFIG_GRKERNSEC
45201 + current->acl = old_acl;
45202 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45203 + fput(current->exec_file);
45204 + current->exec_file = old_exec_file;
45205 +#endif
45206 +
45207 out:
45208 if (bprm->mm) {
45209 acct_arg_size(bprm, 0);
45210 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45211 {
45212 char *old_corename = cn->corename;
45213
45214 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45215 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45216 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45217
45218 if (!cn->corename) {
45219 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45220 int pid_in_pattern = 0;
45221 int err = 0;
45222
45223 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45224 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45225 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45226 cn->used = 0;
45227
45228 @@ -1830,6 +1962,250 @@ out:
45229 return ispipe;
45230 }
45231
45232 +int pax_check_flags(unsigned long *flags)
45233 +{
45234 + int retval = 0;
45235 +
45236 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45237 + if (*flags & MF_PAX_SEGMEXEC)
45238 + {
45239 + *flags &= ~MF_PAX_SEGMEXEC;
45240 + retval = -EINVAL;
45241 + }
45242 +#endif
45243 +
45244 + if ((*flags & MF_PAX_PAGEEXEC)
45245 +
45246 +#ifdef CONFIG_PAX_PAGEEXEC
45247 + && (*flags & MF_PAX_SEGMEXEC)
45248 +#endif
45249 +
45250 + )
45251 + {
45252 + *flags &= ~MF_PAX_PAGEEXEC;
45253 + retval = -EINVAL;
45254 + }
45255 +
45256 + if ((*flags & MF_PAX_MPROTECT)
45257 +
45258 +#ifdef CONFIG_PAX_MPROTECT
45259 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45260 +#endif
45261 +
45262 + )
45263 + {
45264 + *flags &= ~MF_PAX_MPROTECT;
45265 + retval = -EINVAL;
45266 + }
45267 +
45268 + if ((*flags & MF_PAX_EMUTRAMP)
45269 +
45270 +#ifdef CONFIG_PAX_EMUTRAMP
45271 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45272 +#endif
45273 +
45274 + )
45275 + {
45276 + *flags &= ~MF_PAX_EMUTRAMP;
45277 + retval = -EINVAL;
45278 + }
45279 +
45280 + return retval;
45281 +}
45282 +
45283 +EXPORT_SYMBOL(pax_check_flags);
45284 +
45285 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45286 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45287 +{
45288 + struct task_struct *tsk = current;
45289 + struct mm_struct *mm = current->mm;
45290 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45291 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45292 + char *path_exec = NULL;
45293 + char *path_fault = NULL;
45294 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45295 +
45296 + if (buffer_exec && buffer_fault) {
45297 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45298 +
45299 + down_read(&mm->mmap_sem);
45300 + vma = mm->mmap;
45301 + while (vma && (!vma_exec || !vma_fault)) {
45302 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45303 + vma_exec = vma;
45304 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45305 + vma_fault = vma;
45306 + vma = vma->vm_next;
45307 + }
45308 + if (vma_exec) {
45309 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45310 + if (IS_ERR(path_exec))
45311 + path_exec = "<path too long>";
45312 + else {
45313 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45314 + if (path_exec) {
45315 + *path_exec = 0;
45316 + path_exec = buffer_exec;
45317 + } else
45318 + path_exec = "<path too long>";
45319 + }
45320 + }
45321 + if (vma_fault) {
45322 + start = vma_fault->vm_start;
45323 + end = vma_fault->vm_end;
45324 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45325 + if (vma_fault->vm_file) {
45326 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45327 + if (IS_ERR(path_fault))
45328 + path_fault = "<path too long>";
45329 + else {
45330 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45331 + if (path_fault) {
45332 + *path_fault = 0;
45333 + path_fault = buffer_fault;
45334 + } else
45335 + path_fault = "<path too long>";
45336 + }
45337 + } else
45338 + path_fault = "<anonymous mapping>";
45339 + }
45340 + up_read(&mm->mmap_sem);
45341 + }
45342 + if (tsk->signal->curr_ip)
45343 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45344 + else
45345 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45346 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45347 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45348 + task_uid(tsk), task_euid(tsk), pc, sp);
45349 + free_page((unsigned long)buffer_exec);
45350 + free_page((unsigned long)buffer_fault);
45351 + pax_report_insns(regs, pc, sp);
45352 + do_coredump(SIGKILL, SIGKILL, regs);
45353 +}
45354 +#endif
45355 +
45356 +#ifdef CONFIG_PAX_REFCOUNT
45357 +void pax_report_refcount_overflow(struct pt_regs *regs)
45358 +{
45359 + if (current->signal->curr_ip)
45360 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45361 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45362 + else
45363 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45364 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45365 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45366 + show_regs(regs);
45367 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45368 +}
45369 +#endif
45370 +
45371 +#ifdef CONFIG_PAX_USERCOPY
45372 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45373 +static noinline int check_stack_object(const void *obj, unsigned long len)
45374 +{
45375 + const void * const stack = task_stack_page(current);
45376 + const void * const stackend = stack + THREAD_SIZE;
45377 +
45378 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45379 + const void *frame = NULL;
45380 + const void *oldframe;
45381 +#endif
45382 +
45383 + if (obj + len < obj)
45384 + return -1;
45385 +
45386 + if (obj + len <= stack || stackend <= obj)
45387 + return 0;
45388 +
45389 + if (obj < stack || stackend < obj + len)
45390 + return -1;
45391 +
45392 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45393 + oldframe = __builtin_frame_address(1);
45394 + if (oldframe)
45395 + frame = __builtin_frame_address(2);
45396 + /*
45397 + low ----------------------------------------------> high
45398 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45399 + ^----------------^
45400 + allow copies only within here
45401 + */
45402 + while (stack <= frame && frame < stackend) {
45403 + /* if obj + len extends past the last frame, this
45404 + check won't pass and the next frame will be 0,
45405 + causing us to bail out and correctly report
45406 + the copy as invalid
45407 + */
45408 + if (obj + len <= frame)
45409 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45410 + oldframe = frame;
45411 + frame = *(const void * const *)frame;
45412 + }
45413 + return -1;
45414 +#else
45415 + return 1;
45416 +#endif
45417 +}
45418 +
45419 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45420 +{
45421 + if (current->signal->curr_ip)
45422 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45423 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45424 + else
45425 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45426 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45427 + dump_stack();
45428 + gr_handle_kernel_exploit();
45429 + do_group_exit(SIGKILL);
45430 +}
45431 +#endif
45432 +
45433 +void check_object_size(const void *ptr, unsigned long n, bool to)
45434 +{
45435 +
45436 +#ifdef CONFIG_PAX_USERCOPY
45437 + const char *type;
45438 +
45439 + if (!n)
45440 + return;
45441 +
45442 + type = check_heap_object(ptr, n, to);
45443 + if (!type) {
45444 + if (check_stack_object(ptr, n) != -1)
45445 + return;
45446 + type = "<process stack>";
45447 + }
45448 +
45449 + pax_report_usercopy(ptr, n, to, type);
45450 +#endif
45451 +
45452 +}
45453 +EXPORT_SYMBOL(check_object_size);
45454 +
45455 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45456 +void pax_track_stack(void)
45457 +{
45458 + unsigned long sp = (unsigned long)&sp;
45459 + if (sp < current_thread_info()->lowest_stack &&
45460 + sp > (unsigned long)task_stack_page(current))
45461 + current_thread_info()->lowest_stack = sp;
45462 +}
45463 +EXPORT_SYMBOL(pax_track_stack);
45464 +#endif
45465 +
45466 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45467 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45468 +{
45469 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45470 + dump_stack();
45471 + do_group_exit(SIGKILL);
45472 +}
45473 +EXPORT_SYMBOL(report_size_overflow);
45474 +#endif
45475 +
45476 static int zap_process(struct task_struct *start, int exit_code)
45477 {
45478 struct task_struct *t;
45479 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45480 pipe = file->f_path.dentry->d_inode->i_pipe;
45481
45482 pipe_lock(pipe);
45483 - pipe->readers++;
45484 - pipe->writers--;
45485 + atomic_inc(&pipe->readers);
45486 + atomic_dec(&pipe->writers);
45487
45488 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45489 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45490 wake_up_interruptible_sync(&pipe->wait);
45491 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45492 pipe_wait(pipe);
45493 }
45494
45495 - pipe->readers--;
45496 - pipe->writers++;
45497 + atomic_dec(&pipe->readers);
45498 + atomic_inc(&pipe->writers);
45499 pipe_unlock(pipe);
45500
45501 }
45502 @@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45503 int flag = 0;
45504 int ispipe;
45505 bool need_nonrelative = false;
45506 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45507 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45508 struct coredump_params cprm = {
45509 .signr = signr,
45510 .regs = regs,
45511 @@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45512
45513 audit_core_dumps(signr);
45514
45515 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45516 + gr_handle_brute_attach(current, cprm.mm_flags);
45517 +
45518 binfmt = mm->binfmt;
45519 if (!binfmt || !binfmt->core_dump)
45520 goto fail;
45521 @@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45522 }
45523 cprm.limit = RLIM_INFINITY;
45524
45525 - dump_count = atomic_inc_return(&core_dump_count);
45526 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45527 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45528 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45529 task_tgid_vnr(current), current->comm);
45530 @@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45531 } else {
45532 struct inode *inode;
45533
45534 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45535 +
45536 if (cprm.limit < binfmt->min_coredump)
45537 goto fail_unlock;
45538
45539 @@ -2268,7 +2649,7 @@ close_fail:
45540 filp_close(cprm.file, NULL);
45541 fail_dropcount:
45542 if (ispipe)
45543 - atomic_dec(&core_dump_count);
45544 + atomic_dec_unchecked(&core_dump_count);
45545 fail_unlock:
45546 kfree(cn.corename);
45547 fail_corename:
45548 @@ -2287,7 +2668,7 @@ fail:
45549 */
45550 int dump_write(struct file *file, const void *addr, int nr)
45551 {
45552 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45553 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45554 }
45555 EXPORT_SYMBOL(dump_write);
45556
45557 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45558 index 376aa77..59a129c 100644
45559 --- a/fs/ext2/balloc.c
45560 +++ b/fs/ext2/balloc.c
45561 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45562
45563 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45564 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45565 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45566 + if (free_blocks < root_blocks + 1 &&
45567 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45568 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45569 - !in_group_p (sbi->s_resgid))) {
45570 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45571 return 0;
45572 }
45573 return 1;
45574 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45575 index 90d901f..159975f 100644
45576 --- a/fs/ext3/balloc.c
45577 +++ b/fs/ext3/balloc.c
45578 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45579
45580 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45581 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45582 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45583 + if (free_blocks < root_blocks + 1 &&
45584 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45585 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45586 - !in_group_p (sbi->s_resgid))) {
45587 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45588 return 0;
45589 }
45590 return 1;
45591 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45592 index 1b50890..e56c5ad 100644
45593 --- a/fs/ext4/balloc.c
45594 +++ b/fs/ext4/balloc.c
45595 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45596 /* Hm, nope. Are (enough) root reserved clusters available? */
45597 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45598 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45599 - capable(CAP_SYS_RESOURCE) ||
45600 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45601 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45602 + capable_nolog(CAP_SYS_RESOURCE)) {
45603
45604 if (free_clusters >= (nclusters + dirty_clusters))
45605 return 1;
45606 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45607 index c3411d4..30e4f1b 100644
45608 --- a/fs/ext4/ext4.h
45609 +++ b/fs/ext4/ext4.h
45610 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45611 unsigned long s_mb_last_start;
45612
45613 /* stats for buddy allocator */
45614 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45615 - atomic_t s_bal_success; /* we found long enough chunks */
45616 - atomic_t s_bal_allocated; /* in blocks */
45617 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45618 - atomic_t s_bal_goals; /* goal hits */
45619 - atomic_t s_bal_breaks; /* too long searches */
45620 - atomic_t s_bal_2orders; /* 2^order hits */
45621 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45622 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45623 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45624 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45625 + atomic_unchecked_t s_bal_goals; /* goal hits */
45626 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45627 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45628 spinlock_t s_bal_lock;
45629 unsigned long s_mb_buddies_generated;
45630 unsigned long long s_mb_generation_time;
45631 - atomic_t s_mb_lost_chunks;
45632 - atomic_t s_mb_preallocated;
45633 - atomic_t s_mb_discarded;
45634 + atomic_unchecked_t s_mb_lost_chunks;
45635 + atomic_unchecked_t s_mb_preallocated;
45636 + atomic_unchecked_t s_mb_discarded;
45637 atomic_t s_lock_busy;
45638
45639 /* locality groups */
45640 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45641 index 8eae947..53fc27a 100644
45642 --- a/fs/ext4/mballoc.c
45643 +++ b/fs/ext4/mballoc.c
45644 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45645 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45646
45647 if (EXT4_SB(sb)->s_mb_stats)
45648 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45649 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45650
45651 break;
45652 }
45653 @@ -2040,7 +2040,7 @@ repeat:
45654 ac->ac_status = AC_STATUS_CONTINUE;
45655 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45656 cr = 3;
45657 - atomic_inc(&sbi->s_mb_lost_chunks);
45658 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45659 goto repeat;
45660 }
45661 }
45662 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45663 if (sbi->s_mb_stats) {
45664 ext4_msg(sb, KERN_INFO,
45665 "mballoc: %u blocks %u reqs (%u success)",
45666 - atomic_read(&sbi->s_bal_allocated),
45667 - atomic_read(&sbi->s_bal_reqs),
45668 - atomic_read(&sbi->s_bal_success));
45669 + atomic_read_unchecked(&sbi->s_bal_allocated),
45670 + atomic_read_unchecked(&sbi->s_bal_reqs),
45671 + atomic_read_unchecked(&sbi->s_bal_success));
45672 ext4_msg(sb, KERN_INFO,
45673 "mballoc: %u extents scanned, %u goal hits, "
45674 "%u 2^N hits, %u breaks, %u lost",
45675 - atomic_read(&sbi->s_bal_ex_scanned),
45676 - atomic_read(&sbi->s_bal_goals),
45677 - atomic_read(&sbi->s_bal_2orders),
45678 - atomic_read(&sbi->s_bal_breaks),
45679 - atomic_read(&sbi->s_mb_lost_chunks));
45680 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45681 + atomic_read_unchecked(&sbi->s_bal_goals),
45682 + atomic_read_unchecked(&sbi->s_bal_2orders),
45683 + atomic_read_unchecked(&sbi->s_bal_breaks),
45684 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45685 ext4_msg(sb, KERN_INFO,
45686 "mballoc: %lu generated and it took %Lu",
45687 sbi->s_mb_buddies_generated,
45688 sbi->s_mb_generation_time);
45689 ext4_msg(sb, KERN_INFO,
45690 "mballoc: %u preallocated, %u discarded",
45691 - atomic_read(&sbi->s_mb_preallocated),
45692 - atomic_read(&sbi->s_mb_discarded));
45693 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45694 + atomic_read_unchecked(&sbi->s_mb_discarded));
45695 }
45696
45697 free_percpu(sbi->s_locality_groups);
45698 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45699 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45700
45701 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45702 - atomic_inc(&sbi->s_bal_reqs);
45703 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45704 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45705 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45706 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45707 - atomic_inc(&sbi->s_bal_success);
45708 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45709 + atomic_inc_unchecked(&sbi->s_bal_success);
45710 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45711 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45712 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45713 - atomic_inc(&sbi->s_bal_goals);
45714 + atomic_inc_unchecked(&sbi->s_bal_goals);
45715 if (ac->ac_found > sbi->s_mb_max_to_scan)
45716 - atomic_inc(&sbi->s_bal_breaks);
45717 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45718 }
45719
45720 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45721 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45722 trace_ext4_mb_new_inode_pa(ac, pa);
45723
45724 ext4_mb_use_inode_pa(ac, pa);
45725 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45726 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45727
45728 ei = EXT4_I(ac->ac_inode);
45729 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45730 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45731 trace_ext4_mb_new_group_pa(ac, pa);
45732
45733 ext4_mb_use_group_pa(ac, pa);
45734 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45735 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45736
45737 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45738 lg = ac->ac_lg;
45739 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45740 * from the bitmap and continue.
45741 */
45742 }
45743 - atomic_add(free, &sbi->s_mb_discarded);
45744 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45745
45746 return err;
45747 }
45748 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45749 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45750 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45751 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45752 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45753 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45754 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45755
45756 return 0;
45757 diff --git a/fs/fcntl.c b/fs/fcntl.c
45758 index 887b5ba..0e3f2c3 100644
45759 --- a/fs/fcntl.c
45760 +++ b/fs/fcntl.c
45761 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45762 if (err)
45763 return err;
45764
45765 + if (gr_handle_chroot_fowner(pid, type))
45766 + return -ENOENT;
45767 + if (gr_check_protected_task_fowner(pid, type))
45768 + return -EACCES;
45769 +
45770 f_modown(filp, pid, type, force);
45771 return 0;
45772 }
45773 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45774
45775 static int f_setown_ex(struct file *filp, unsigned long arg)
45776 {
45777 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45778 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45779 struct f_owner_ex owner;
45780 struct pid *pid;
45781 int type;
45782 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45783
45784 static int f_getown_ex(struct file *filp, unsigned long arg)
45785 {
45786 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45787 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45788 struct f_owner_ex owner;
45789 int ret = 0;
45790
45791 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45792 switch (cmd) {
45793 case F_DUPFD:
45794 case F_DUPFD_CLOEXEC:
45795 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45796 if (arg >= rlimit(RLIMIT_NOFILE))
45797 break;
45798 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45799 diff --git a/fs/fifo.c b/fs/fifo.c
45800 index cf6f434..3d7942c 100644
45801 --- a/fs/fifo.c
45802 +++ b/fs/fifo.c
45803 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45804 */
45805 filp->f_op = &read_pipefifo_fops;
45806 pipe->r_counter++;
45807 - if (pipe->readers++ == 0)
45808 + if (atomic_inc_return(&pipe->readers) == 1)
45809 wake_up_partner(inode);
45810
45811 - if (!pipe->writers) {
45812 + if (!atomic_read(&pipe->writers)) {
45813 if ((filp->f_flags & O_NONBLOCK)) {
45814 /* suppress POLLHUP until we have
45815 * seen a writer */
45816 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45817 * errno=ENXIO when there is no process reading the FIFO.
45818 */
45819 ret = -ENXIO;
45820 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45821 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45822 goto err;
45823
45824 filp->f_op = &write_pipefifo_fops;
45825 pipe->w_counter++;
45826 - if (!pipe->writers++)
45827 + if (atomic_inc_return(&pipe->writers) == 1)
45828 wake_up_partner(inode);
45829
45830 - if (!pipe->readers) {
45831 + if (!atomic_read(&pipe->readers)) {
45832 if (wait_for_partner(inode, &pipe->r_counter))
45833 goto err_wr;
45834 }
45835 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45836 */
45837 filp->f_op = &rdwr_pipefifo_fops;
45838
45839 - pipe->readers++;
45840 - pipe->writers++;
45841 + atomic_inc(&pipe->readers);
45842 + atomic_inc(&pipe->writers);
45843 pipe->r_counter++;
45844 pipe->w_counter++;
45845 - if (pipe->readers == 1 || pipe->writers == 1)
45846 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45847 wake_up_partner(inode);
45848 break;
45849
45850 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45851 return 0;
45852
45853 err_rd:
45854 - if (!--pipe->readers)
45855 + if (atomic_dec_and_test(&pipe->readers))
45856 wake_up_interruptible(&pipe->wait);
45857 ret = -ERESTARTSYS;
45858 goto err;
45859
45860 err_wr:
45861 - if (!--pipe->writers)
45862 + if (atomic_dec_and_test(&pipe->writers))
45863 wake_up_interruptible(&pipe->wait);
45864 ret = -ERESTARTSYS;
45865 goto err;
45866
45867 err:
45868 - if (!pipe->readers && !pipe->writers)
45869 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45870 free_pipe_info(inode);
45871
45872 err_nocleanup:
45873 diff --git a/fs/file.c b/fs/file.c
45874 index ba3f605..fade102 100644
45875 --- a/fs/file.c
45876 +++ b/fs/file.c
45877 @@ -15,6 +15,7 @@
45878 #include <linux/slab.h>
45879 #include <linux/vmalloc.h>
45880 #include <linux/file.h>
45881 +#include <linux/security.h>
45882 #include <linux/fdtable.h>
45883 #include <linux/bitops.h>
45884 #include <linux/interrupt.h>
45885 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45886 * N.B. For clone tasks sharing a files structure, this test
45887 * will limit the total number of files that can be opened.
45888 */
45889 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45890 if (nr >= rlimit(RLIMIT_NOFILE))
45891 return -EMFILE;
45892
45893 diff --git a/fs/filesystems.c b/fs/filesystems.c
45894 index 96f2428..f5eeb8e 100644
45895 --- a/fs/filesystems.c
45896 +++ b/fs/filesystems.c
45897 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45898 int len = dot ? dot - name : strlen(name);
45899
45900 fs = __get_fs_type(name, len);
45901 +
45902 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45903 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45904 +#else
45905 if (!fs && (request_module("%.*s", len, name) == 0))
45906 +#endif
45907 fs = __get_fs_type(name, len);
45908
45909 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45910 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45911 index 5df4775..9d9336f 100644
45912 --- a/fs/fs_struct.c
45913 +++ b/fs/fs_struct.c
45914 @@ -4,6 +4,7 @@
45915 #include <linux/path.h>
45916 #include <linux/slab.h>
45917 #include <linux/fs_struct.h>
45918 +#include <linux/grsecurity.h>
45919 #include "internal.h"
45920
45921 /*
45922 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45923 write_seqcount_begin(&fs->seq);
45924 old_root = fs->root;
45925 fs->root = *path;
45926 + gr_set_chroot_entries(current, path);
45927 write_seqcount_end(&fs->seq);
45928 spin_unlock(&fs->lock);
45929 if (old_root.dentry)
45930 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45931 return 1;
45932 }
45933
45934 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45935 +{
45936 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45937 + return 0;
45938 + *p = *new;
45939 +
45940 + /* This function is only called from pivot_root(). Leave our
45941 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45942 + pivoted root isn't treated as a chroot
45943 + */
45944 + //gr_set_chroot_entries(task, new);
45945 +
45946 + return 1;
45947 +}
45948 +
45949 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45950 {
45951 struct task_struct *g, *p;
45952 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45953 int hits = 0;
45954 spin_lock(&fs->lock);
45955 write_seqcount_begin(&fs->seq);
45956 - hits += replace_path(&fs->root, old_root, new_root);
45957 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45958 hits += replace_path(&fs->pwd, old_root, new_root);
45959 write_seqcount_end(&fs->seq);
45960 while (hits--) {
45961 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45962 task_lock(tsk);
45963 spin_lock(&fs->lock);
45964 tsk->fs = NULL;
45965 - kill = !--fs->users;
45966 + gr_clear_chroot_entries(tsk);
45967 + kill = !atomic_dec_return(&fs->users);
45968 spin_unlock(&fs->lock);
45969 task_unlock(tsk);
45970 if (kill)
45971 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45972 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45973 /* We don't need to lock fs - think why ;-) */
45974 if (fs) {
45975 - fs->users = 1;
45976 + atomic_set(&fs->users, 1);
45977 fs->in_exec = 0;
45978 spin_lock_init(&fs->lock);
45979 seqcount_init(&fs->seq);
45980 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45981 spin_lock(&old->lock);
45982 fs->root = old->root;
45983 path_get(&fs->root);
45984 + /* instead of calling gr_set_chroot_entries here,
45985 + we call it from every caller of this function
45986 + */
45987 fs->pwd = old->pwd;
45988 path_get(&fs->pwd);
45989 spin_unlock(&old->lock);
45990 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
45991
45992 task_lock(current);
45993 spin_lock(&fs->lock);
45994 - kill = !--fs->users;
45995 + kill = !atomic_dec_return(&fs->users);
45996 current->fs = new_fs;
45997 + gr_set_chroot_entries(current, &new_fs->root);
45998 spin_unlock(&fs->lock);
45999 task_unlock(current);
46000
46001 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46002
46003 int current_umask(void)
46004 {
46005 - return current->fs->umask;
46006 + return current->fs->umask | gr_acl_umask();
46007 }
46008 EXPORT_SYMBOL(current_umask);
46009
46010 /* to be mentioned only in INIT_TASK */
46011 struct fs_struct init_fs = {
46012 - .users = 1,
46013 + .users = ATOMIC_INIT(1),
46014 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46015 .seq = SEQCNT_ZERO,
46016 .umask = 0022,
46017 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46018 task_lock(current);
46019
46020 spin_lock(&init_fs.lock);
46021 - init_fs.users++;
46022 + atomic_inc(&init_fs.users);
46023 spin_unlock(&init_fs.lock);
46024
46025 spin_lock(&fs->lock);
46026 current->fs = &init_fs;
46027 - kill = !--fs->users;
46028 + gr_set_chroot_entries(current, &current->fs->root);
46029 + kill = !atomic_dec_return(&fs->users);
46030 spin_unlock(&fs->lock);
46031
46032 task_unlock(current);
46033 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46034 index 9905350..02eaec4 100644
46035 --- a/fs/fscache/cookie.c
46036 +++ b/fs/fscache/cookie.c
46037 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46038 parent ? (char *) parent->def->name : "<no-parent>",
46039 def->name, netfs_data);
46040
46041 - fscache_stat(&fscache_n_acquires);
46042 + fscache_stat_unchecked(&fscache_n_acquires);
46043
46044 /* if there's no parent cookie, then we don't create one here either */
46045 if (!parent) {
46046 - fscache_stat(&fscache_n_acquires_null);
46047 + fscache_stat_unchecked(&fscache_n_acquires_null);
46048 _leave(" [no parent]");
46049 return NULL;
46050 }
46051 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46052 /* allocate and initialise a cookie */
46053 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46054 if (!cookie) {
46055 - fscache_stat(&fscache_n_acquires_oom);
46056 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46057 _leave(" [ENOMEM]");
46058 return NULL;
46059 }
46060 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46061
46062 switch (cookie->def->type) {
46063 case FSCACHE_COOKIE_TYPE_INDEX:
46064 - fscache_stat(&fscache_n_cookie_index);
46065 + fscache_stat_unchecked(&fscache_n_cookie_index);
46066 break;
46067 case FSCACHE_COOKIE_TYPE_DATAFILE:
46068 - fscache_stat(&fscache_n_cookie_data);
46069 + fscache_stat_unchecked(&fscache_n_cookie_data);
46070 break;
46071 default:
46072 - fscache_stat(&fscache_n_cookie_special);
46073 + fscache_stat_unchecked(&fscache_n_cookie_special);
46074 break;
46075 }
46076
46077 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46078 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46079 atomic_dec(&parent->n_children);
46080 __fscache_cookie_put(cookie);
46081 - fscache_stat(&fscache_n_acquires_nobufs);
46082 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46083 _leave(" = NULL");
46084 return NULL;
46085 }
46086 }
46087
46088 - fscache_stat(&fscache_n_acquires_ok);
46089 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46090 _leave(" = %p", cookie);
46091 return cookie;
46092 }
46093 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46094 cache = fscache_select_cache_for_object(cookie->parent);
46095 if (!cache) {
46096 up_read(&fscache_addremove_sem);
46097 - fscache_stat(&fscache_n_acquires_no_cache);
46098 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46099 _leave(" = -ENOMEDIUM [no cache]");
46100 return -ENOMEDIUM;
46101 }
46102 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46103 object = cache->ops->alloc_object(cache, cookie);
46104 fscache_stat_d(&fscache_n_cop_alloc_object);
46105 if (IS_ERR(object)) {
46106 - fscache_stat(&fscache_n_object_no_alloc);
46107 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46108 ret = PTR_ERR(object);
46109 goto error;
46110 }
46111
46112 - fscache_stat(&fscache_n_object_alloc);
46113 + fscache_stat_unchecked(&fscache_n_object_alloc);
46114
46115 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46116
46117 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46118 struct fscache_object *object;
46119 struct hlist_node *_p;
46120
46121 - fscache_stat(&fscache_n_updates);
46122 + fscache_stat_unchecked(&fscache_n_updates);
46123
46124 if (!cookie) {
46125 - fscache_stat(&fscache_n_updates_null);
46126 + fscache_stat_unchecked(&fscache_n_updates_null);
46127 _leave(" [no cookie]");
46128 return;
46129 }
46130 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46131 struct fscache_object *object;
46132 unsigned long event;
46133
46134 - fscache_stat(&fscache_n_relinquishes);
46135 + fscache_stat_unchecked(&fscache_n_relinquishes);
46136 if (retire)
46137 - fscache_stat(&fscache_n_relinquishes_retire);
46138 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46139
46140 if (!cookie) {
46141 - fscache_stat(&fscache_n_relinquishes_null);
46142 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46143 _leave(" [no cookie]");
46144 return;
46145 }
46146 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46147
46148 /* wait for the cookie to finish being instantiated (or to fail) */
46149 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46150 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46151 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46152 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46153 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46154 }
46155 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46156 index f6aad48..88dcf26 100644
46157 --- a/fs/fscache/internal.h
46158 +++ b/fs/fscache/internal.h
46159 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46160 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46161 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46162
46163 -extern atomic_t fscache_n_op_pend;
46164 -extern atomic_t fscache_n_op_run;
46165 -extern atomic_t fscache_n_op_enqueue;
46166 -extern atomic_t fscache_n_op_deferred_release;
46167 -extern atomic_t fscache_n_op_release;
46168 -extern atomic_t fscache_n_op_gc;
46169 -extern atomic_t fscache_n_op_cancelled;
46170 -extern atomic_t fscache_n_op_rejected;
46171 +extern atomic_unchecked_t fscache_n_op_pend;
46172 +extern atomic_unchecked_t fscache_n_op_run;
46173 +extern atomic_unchecked_t fscache_n_op_enqueue;
46174 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46175 +extern atomic_unchecked_t fscache_n_op_release;
46176 +extern atomic_unchecked_t fscache_n_op_gc;
46177 +extern atomic_unchecked_t fscache_n_op_cancelled;
46178 +extern atomic_unchecked_t fscache_n_op_rejected;
46179
46180 -extern atomic_t fscache_n_attr_changed;
46181 -extern atomic_t fscache_n_attr_changed_ok;
46182 -extern atomic_t fscache_n_attr_changed_nobufs;
46183 -extern atomic_t fscache_n_attr_changed_nomem;
46184 -extern atomic_t fscache_n_attr_changed_calls;
46185 +extern atomic_unchecked_t fscache_n_attr_changed;
46186 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46187 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46188 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46189 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46190
46191 -extern atomic_t fscache_n_allocs;
46192 -extern atomic_t fscache_n_allocs_ok;
46193 -extern atomic_t fscache_n_allocs_wait;
46194 -extern atomic_t fscache_n_allocs_nobufs;
46195 -extern atomic_t fscache_n_allocs_intr;
46196 -extern atomic_t fscache_n_allocs_object_dead;
46197 -extern atomic_t fscache_n_alloc_ops;
46198 -extern atomic_t fscache_n_alloc_op_waits;
46199 +extern atomic_unchecked_t fscache_n_allocs;
46200 +extern atomic_unchecked_t fscache_n_allocs_ok;
46201 +extern atomic_unchecked_t fscache_n_allocs_wait;
46202 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46203 +extern atomic_unchecked_t fscache_n_allocs_intr;
46204 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46205 +extern atomic_unchecked_t fscache_n_alloc_ops;
46206 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46207
46208 -extern atomic_t fscache_n_retrievals;
46209 -extern atomic_t fscache_n_retrievals_ok;
46210 -extern atomic_t fscache_n_retrievals_wait;
46211 -extern atomic_t fscache_n_retrievals_nodata;
46212 -extern atomic_t fscache_n_retrievals_nobufs;
46213 -extern atomic_t fscache_n_retrievals_intr;
46214 -extern atomic_t fscache_n_retrievals_nomem;
46215 -extern atomic_t fscache_n_retrievals_object_dead;
46216 -extern atomic_t fscache_n_retrieval_ops;
46217 -extern atomic_t fscache_n_retrieval_op_waits;
46218 +extern atomic_unchecked_t fscache_n_retrievals;
46219 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46220 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46221 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46222 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46223 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46224 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46225 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46226 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46227 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46228
46229 -extern atomic_t fscache_n_stores;
46230 -extern atomic_t fscache_n_stores_ok;
46231 -extern atomic_t fscache_n_stores_again;
46232 -extern atomic_t fscache_n_stores_nobufs;
46233 -extern atomic_t fscache_n_stores_oom;
46234 -extern atomic_t fscache_n_store_ops;
46235 -extern atomic_t fscache_n_store_calls;
46236 -extern atomic_t fscache_n_store_pages;
46237 -extern atomic_t fscache_n_store_radix_deletes;
46238 -extern atomic_t fscache_n_store_pages_over_limit;
46239 +extern atomic_unchecked_t fscache_n_stores;
46240 +extern atomic_unchecked_t fscache_n_stores_ok;
46241 +extern atomic_unchecked_t fscache_n_stores_again;
46242 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46243 +extern atomic_unchecked_t fscache_n_stores_oom;
46244 +extern atomic_unchecked_t fscache_n_store_ops;
46245 +extern atomic_unchecked_t fscache_n_store_calls;
46246 +extern atomic_unchecked_t fscache_n_store_pages;
46247 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46248 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46249
46250 -extern atomic_t fscache_n_store_vmscan_not_storing;
46251 -extern atomic_t fscache_n_store_vmscan_gone;
46252 -extern atomic_t fscache_n_store_vmscan_busy;
46253 -extern atomic_t fscache_n_store_vmscan_cancelled;
46254 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46255 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46256 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46257 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46258
46259 -extern atomic_t fscache_n_marks;
46260 -extern atomic_t fscache_n_uncaches;
46261 +extern atomic_unchecked_t fscache_n_marks;
46262 +extern atomic_unchecked_t fscache_n_uncaches;
46263
46264 -extern atomic_t fscache_n_acquires;
46265 -extern atomic_t fscache_n_acquires_null;
46266 -extern atomic_t fscache_n_acquires_no_cache;
46267 -extern atomic_t fscache_n_acquires_ok;
46268 -extern atomic_t fscache_n_acquires_nobufs;
46269 -extern atomic_t fscache_n_acquires_oom;
46270 +extern atomic_unchecked_t fscache_n_acquires;
46271 +extern atomic_unchecked_t fscache_n_acquires_null;
46272 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46273 +extern atomic_unchecked_t fscache_n_acquires_ok;
46274 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46275 +extern atomic_unchecked_t fscache_n_acquires_oom;
46276
46277 -extern atomic_t fscache_n_updates;
46278 -extern atomic_t fscache_n_updates_null;
46279 -extern atomic_t fscache_n_updates_run;
46280 +extern atomic_unchecked_t fscache_n_updates;
46281 +extern atomic_unchecked_t fscache_n_updates_null;
46282 +extern atomic_unchecked_t fscache_n_updates_run;
46283
46284 -extern atomic_t fscache_n_relinquishes;
46285 -extern atomic_t fscache_n_relinquishes_null;
46286 -extern atomic_t fscache_n_relinquishes_waitcrt;
46287 -extern atomic_t fscache_n_relinquishes_retire;
46288 +extern atomic_unchecked_t fscache_n_relinquishes;
46289 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46290 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46291 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46292
46293 -extern atomic_t fscache_n_cookie_index;
46294 -extern atomic_t fscache_n_cookie_data;
46295 -extern atomic_t fscache_n_cookie_special;
46296 +extern atomic_unchecked_t fscache_n_cookie_index;
46297 +extern atomic_unchecked_t fscache_n_cookie_data;
46298 +extern atomic_unchecked_t fscache_n_cookie_special;
46299
46300 -extern atomic_t fscache_n_object_alloc;
46301 -extern atomic_t fscache_n_object_no_alloc;
46302 -extern atomic_t fscache_n_object_lookups;
46303 -extern atomic_t fscache_n_object_lookups_negative;
46304 -extern atomic_t fscache_n_object_lookups_positive;
46305 -extern atomic_t fscache_n_object_lookups_timed_out;
46306 -extern atomic_t fscache_n_object_created;
46307 -extern atomic_t fscache_n_object_avail;
46308 -extern atomic_t fscache_n_object_dead;
46309 +extern atomic_unchecked_t fscache_n_object_alloc;
46310 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46311 +extern atomic_unchecked_t fscache_n_object_lookups;
46312 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46313 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46314 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46315 +extern atomic_unchecked_t fscache_n_object_created;
46316 +extern atomic_unchecked_t fscache_n_object_avail;
46317 +extern atomic_unchecked_t fscache_n_object_dead;
46318
46319 -extern atomic_t fscache_n_checkaux_none;
46320 -extern atomic_t fscache_n_checkaux_okay;
46321 -extern atomic_t fscache_n_checkaux_update;
46322 -extern atomic_t fscache_n_checkaux_obsolete;
46323 +extern atomic_unchecked_t fscache_n_checkaux_none;
46324 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46325 +extern atomic_unchecked_t fscache_n_checkaux_update;
46326 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46327
46328 extern atomic_t fscache_n_cop_alloc_object;
46329 extern atomic_t fscache_n_cop_lookup_object;
46330 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46331 atomic_inc(stat);
46332 }
46333
46334 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46335 +{
46336 + atomic_inc_unchecked(stat);
46337 +}
46338 +
46339 static inline void fscache_stat_d(atomic_t *stat)
46340 {
46341 atomic_dec(stat);
46342 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46343
46344 #define __fscache_stat(stat) (NULL)
46345 #define fscache_stat(stat) do {} while (0)
46346 +#define fscache_stat_unchecked(stat) do {} while (0)
46347 #define fscache_stat_d(stat) do {} while (0)
46348 #endif
46349
46350 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46351 index b6b897c..0ffff9c 100644
46352 --- a/fs/fscache/object.c
46353 +++ b/fs/fscache/object.c
46354 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46355 /* update the object metadata on disk */
46356 case FSCACHE_OBJECT_UPDATING:
46357 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46358 - fscache_stat(&fscache_n_updates_run);
46359 + fscache_stat_unchecked(&fscache_n_updates_run);
46360 fscache_stat(&fscache_n_cop_update_object);
46361 object->cache->ops->update_object(object);
46362 fscache_stat_d(&fscache_n_cop_update_object);
46363 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46364 spin_lock(&object->lock);
46365 object->state = FSCACHE_OBJECT_DEAD;
46366 spin_unlock(&object->lock);
46367 - fscache_stat(&fscache_n_object_dead);
46368 + fscache_stat_unchecked(&fscache_n_object_dead);
46369 goto terminal_transit;
46370
46371 /* handle the parent cache of this object being withdrawn from
46372 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46373 spin_lock(&object->lock);
46374 object->state = FSCACHE_OBJECT_DEAD;
46375 spin_unlock(&object->lock);
46376 - fscache_stat(&fscache_n_object_dead);
46377 + fscache_stat_unchecked(&fscache_n_object_dead);
46378 goto terminal_transit;
46379
46380 /* complain about the object being woken up once it is
46381 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46382 parent->cookie->def->name, cookie->def->name,
46383 object->cache->tag->name);
46384
46385 - fscache_stat(&fscache_n_object_lookups);
46386 + fscache_stat_unchecked(&fscache_n_object_lookups);
46387 fscache_stat(&fscache_n_cop_lookup_object);
46388 ret = object->cache->ops->lookup_object(object);
46389 fscache_stat_d(&fscache_n_cop_lookup_object);
46390 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46391 if (ret == -ETIMEDOUT) {
46392 /* probably stuck behind another object, so move this one to
46393 * the back of the queue */
46394 - fscache_stat(&fscache_n_object_lookups_timed_out);
46395 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46396 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46397 }
46398
46399 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46400
46401 spin_lock(&object->lock);
46402 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46403 - fscache_stat(&fscache_n_object_lookups_negative);
46404 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46405
46406 /* transit here to allow write requests to begin stacking up
46407 * and read requests to begin returning ENODATA */
46408 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46409 * result, in which case there may be data available */
46410 spin_lock(&object->lock);
46411 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46412 - fscache_stat(&fscache_n_object_lookups_positive);
46413 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46414
46415 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46416
46417 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46418 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46419 } else {
46420 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46421 - fscache_stat(&fscache_n_object_created);
46422 + fscache_stat_unchecked(&fscache_n_object_created);
46423
46424 object->state = FSCACHE_OBJECT_AVAILABLE;
46425 spin_unlock(&object->lock);
46426 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46427 fscache_enqueue_dependents(object);
46428
46429 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46430 - fscache_stat(&fscache_n_object_avail);
46431 + fscache_stat_unchecked(&fscache_n_object_avail);
46432
46433 _leave("");
46434 }
46435 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46436 enum fscache_checkaux result;
46437
46438 if (!object->cookie->def->check_aux) {
46439 - fscache_stat(&fscache_n_checkaux_none);
46440 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46441 return FSCACHE_CHECKAUX_OKAY;
46442 }
46443
46444 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46445 switch (result) {
46446 /* entry okay as is */
46447 case FSCACHE_CHECKAUX_OKAY:
46448 - fscache_stat(&fscache_n_checkaux_okay);
46449 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46450 break;
46451
46452 /* entry requires update */
46453 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46454 - fscache_stat(&fscache_n_checkaux_update);
46455 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46456 break;
46457
46458 /* entry requires deletion */
46459 case FSCACHE_CHECKAUX_OBSOLETE:
46460 - fscache_stat(&fscache_n_checkaux_obsolete);
46461 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46462 break;
46463
46464 default:
46465 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46466 index 30afdfa..2256596 100644
46467 --- a/fs/fscache/operation.c
46468 +++ b/fs/fscache/operation.c
46469 @@ -17,7 +17,7 @@
46470 #include <linux/slab.h>
46471 #include "internal.h"
46472
46473 -atomic_t fscache_op_debug_id;
46474 +atomic_unchecked_t fscache_op_debug_id;
46475 EXPORT_SYMBOL(fscache_op_debug_id);
46476
46477 /**
46478 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46479 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46480 ASSERTCMP(atomic_read(&op->usage), >, 0);
46481
46482 - fscache_stat(&fscache_n_op_enqueue);
46483 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46484 switch (op->flags & FSCACHE_OP_TYPE) {
46485 case FSCACHE_OP_ASYNC:
46486 _debug("queue async");
46487 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46488 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46489 if (op->processor)
46490 fscache_enqueue_operation(op);
46491 - fscache_stat(&fscache_n_op_run);
46492 + fscache_stat_unchecked(&fscache_n_op_run);
46493 }
46494
46495 /*
46496 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46497 if (object->n_ops > 1) {
46498 atomic_inc(&op->usage);
46499 list_add_tail(&op->pend_link, &object->pending_ops);
46500 - fscache_stat(&fscache_n_op_pend);
46501 + fscache_stat_unchecked(&fscache_n_op_pend);
46502 } else if (!list_empty(&object->pending_ops)) {
46503 atomic_inc(&op->usage);
46504 list_add_tail(&op->pend_link, &object->pending_ops);
46505 - fscache_stat(&fscache_n_op_pend);
46506 + fscache_stat_unchecked(&fscache_n_op_pend);
46507 fscache_start_operations(object);
46508 } else {
46509 ASSERTCMP(object->n_in_progress, ==, 0);
46510 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46511 object->n_exclusive++; /* reads and writes must wait */
46512 atomic_inc(&op->usage);
46513 list_add_tail(&op->pend_link, &object->pending_ops);
46514 - fscache_stat(&fscache_n_op_pend);
46515 + fscache_stat_unchecked(&fscache_n_op_pend);
46516 ret = 0;
46517 } else {
46518 /* not allowed to submit ops in any other state */
46519 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46520 if (object->n_exclusive > 0) {
46521 atomic_inc(&op->usage);
46522 list_add_tail(&op->pend_link, &object->pending_ops);
46523 - fscache_stat(&fscache_n_op_pend);
46524 + fscache_stat_unchecked(&fscache_n_op_pend);
46525 } else if (!list_empty(&object->pending_ops)) {
46526 atomic_inc(&op->usage);
46527 list_add_tail(&op->pend_link, &object->pending_ops);
46528 - fscache_stat(&fscache_n_op_pend);
46529 + fscache_stat_unchecked(&fscache_n_op_pend);
46530 fscache_start_operations(object);
46531 } else {
46532 ASSERTCMP(object->n_exclusive, ==, 0);
46533 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46534 object->n_ops++;
46535 atomic_inc(&op->usage);
46536 list_add_tail(&op->pend_link, &object->pending_ops);
46537 - fscache_stat(&fscache_n_op_pend);
46538 + fscache_stat_unchecked(&fscache_n_op_pend);
46539 ret = 0;
46540 } else if (object->state == FSCACHE_OBJECT_DYING ||
46541 object->state == FSCACHE_OBJECT_LC_DYING ||
46542 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46543 - fscache_stat(&fscache_n_op_rejected);
46544 + fscache_stat_unchecked(&fscache_n_op_rejected);
46545 ret = -ENOBUFS;
46546 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46547 fscache_report_unexpected_submission(object, op, ostate);
46548 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46549
46550 ret = -EBUSY;
46551 if (!list_empty(&op->pend_link)) {
46552 - fscache_stat(&fscache_n_op_cancelled);
46553 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46554 list_del_init(&op->pend_link);
46555 object->n_ops--;
46556 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46557 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46558 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46559 BUG();
46560
46561 - fscache_stat(&fscache_n_op_release);
46562 + fscache_stat_unchecked(&fscache_n_op_release);
46563
46564 if (op->release) {
46565 op->release(op);
46566 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46567 * lock, and defer it otherwise */
46568 if (!spin_trylock(&object->lock)) {
46569 _debug("defer put");
46570 - fscache_stat(&fscache_n_op_deferred_release);
46571 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46572
46573 cache = object->cache;
46574 spin_lock(&cache->op_gc_list_lock);
46575 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46576
46577 _debug("GC DEFERRED REL OBJ%x OP%x",
46578 object->debug_id, op->debug_id);
46579 - fscache_stat(&fscache_n_op_gc);
46580 + fscache_stat_unchecked(&fscache_n_op_gc);
46581
46582 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46583
46584 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46585 index 3f7a59b..cf196cc 100644
46586 --- a/fs/fscache/page.c
46587 +++ b/fs/fscache/page.c
46588 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46589 val = radix_tree_lookup(&cookie->stores, page->index);
46590 if (!val) {
46591 rcu_read_unlock();
46592 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46593 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46594 __fscache_uncache_page(cookie, page);
46595 return true;
46596 }
46597 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46598 spin_unlock(&cookie->stores_lock);
46599
46600 if (xpage) {
46601 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46602 - fscache_stat(&fscache_n_store_radix_deletes);
46603 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46604 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46605 ASSERTCMP(xpage, ==, page);
46606 } else {
46607 - fscache_stat(&fscache_n_store_vmscan_gone);
46608 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46609 }
46610
46611 wake_up_bit(&cookie->flags, 0);
46612 @@ -107,7 +107,7 @@ page_busy:
46613 /* we might want to wait here, but that could deadlock the allocator as
46614 * the work threads writing to the cache may all end up sleeping
46615 * on memory allocation */
46616 - fscache_stat(&fscache_n_store_vmscan_busy);
46617 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46618 return false;
46619 }
46620 EXPORT_SYMBOL(__fscache_maybe_release_page);
46621 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46622 FSCACHE_COOKIE_STORING_TAG);
46623 if (!radix_tree_tag_get(&cookie->stores, page->index,
46624 FSCACHE_COOKIE_PENDING_TAG)) {
46625 - fscache_stat(&fscache_n_store_radix_deletes);
46626 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46627 xpage = radix_tree_delete(&cookie->stores, page->index);
46628 }
46629 spin_unlock(&cookie->stores_lock);
46630 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46631
46632 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46633
46634 - fscache_stat(&fscache_n_attr_changed_calls);
46635 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46636
46637 if (fscache_object_is_active(object)) {
46638 fscache_stat(&fscache_n_cop_attr_changed);
46639 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46640
46641 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46642
46643 - fscache_stat(&fscache_n_attr_changed);
46644 + fscache_stat_unchecked(&fscache_n_attr_changed);
46645
46646 op = kzalloc(sizeof(*op), GFP_KERNEL);
46647 if (!op) {
46648 - fscache_stat(&fscache_n_attr_changed_nomem);
46649 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46650 _leave(" = -ENOMEM");
46651 return -ENOMEM;
46652 }
46653 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46654 if (fscache_submit_exclusive_op(object, op) < 0)
46655 goto nobufs;
46656 spin_unlock(&cookie->lock);
46657 - fscache_stat(&fscache_n_attr_changed_ok);
46658 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46659 fscache_put_operation(op);
46660 _leave(" = 0");
46661 return 0;
46662 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46663 nobufs:
46664 spin_unlock(&cookie->lock);
46665 kfree(op);
46666 - fscache_stat(&fscache_n_attr_changed_nobufs);
46667 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46668 _leave(" = %d", -ENOBUFS);
46669 return -ENOBUFS;
46670 }
46671 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46672 /* allocate a retrieval operation and attempt to submit it */
46673 op = kzalloc(sizeof(*op), GFP_NOIO);
46674 if (!op) {
46675 - fscache_stat(&fscache_n_retrievals_nomem);
46676 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46677 return NULL;
46678 }
46679
46680 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46681 return 0;
46682 }
46683
46684 - fscache_stat(&fscache_n_retrievals_wait);
46685 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46686
46687 jif = jiffies;
46688 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46689 fscache_wait_bit_interruptible,
46690 TASK_INTERRUPTIBLE) != 0) {
46691 - fscache_stat(&fscache_n_retrievals_intr);
46692 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46693 _leave(" = -ERESTARTSYS");
46694 return -ERESTARTSYS;
46695 }
46696 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46697 */
46698 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46699 struct fscache_retrieval *op,
46700 - atomic_t *stat_op_waits,
46701 - atomic_t *stat_object_dead)
46702 + atomic_unchecked_t *stat_op_waits,
46703 + atomic_unchecked_t *stat_object_dead)
46704 {
46705 int ret;
46706
46707 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46708 goto check_if_dead;
46709
46710 _debug(">>> WT");
46711 - fscache_stat(stat_op_waits);
46712 + fscache_stat_unchecked(stat_op_waits);
46713 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46714 fscache_wait_bit_interruptible,
46715 TASK_INTERRUPTIBLE) < 0) {
46716 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46717
46718 check_if_dead:
46719 if (unlikely(fscache_object_is_dead(object))) {
46720 - fscache_stat(stat_object_dead);
46721 + fscache_stat_unchecked(stat_object_dead);
46722 return -ENOBUFS;
46723 }
46724 return 0;
46725 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46726
46727 _enter("%p,%p,,,", cookie, page);
46728
46729 - fscache_stat(&fscache_n_retrievals);
46730 + fscache_stat_unchecked(&fscache_n_retrievals);
46731
46732 if (hlist_empty(&cookie->backing_objects))
46733 goto nobufs;
46734 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46735 goto nobufs_unlock;
46736 spin_unlock(&cookie->lock);
46737
46738 - fscache_stat(&fscache_n_retrieval_ops);
46739 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46740
46741 /* pin the netfs read context in case we need to do the actual netfs
46742 * read because we've encountered a cache read failure */
46743 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46744
46745 error:
46746 if (ret == -ENOMEM)
46747 - fscache_stat(&fscache_n_retrievals_nomem);
46748 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46749 else if (ret == -ERESTARTSYS)
46750 - fscache_stat(&fscache_n_retrievals_intr);
46751 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46752 else if (ret == -ENODATA)
46753 - fscache_stat(&fscache_n_retrievals_nodata);
46754 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46755 else if (ret < 0)
46756 - fscache_stat(&fscache_n_retrievals_nobufs);
46757 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46758 else
46759 - fscache_stat(&fscache_n_retrievals_ok);
46760 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46761
46762 fscache_put_retrieval(op);
46763 _leave(" = %d", ret);
46764 @@ -429,7 +429,7 @@ nobufs_unlock:
46765 spin_unlock(&cookie->lock);
46766 kfree(op);
46767 nobufs:
46768 - fscache_stat(&fscache_n_retrievals_nobufs);
46769 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46770 _leave(" = -ENOBUFS");
46771 return -ENOBUFS;
46772 }
46773 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46774
46775 _enter("%p,,%d,,,", cookie, *nr_pages);
46776
46777 - fscache_stat(&fscache_n_retrievals);
46778 + fscache_stat_unchecked(&fscache_n_retrievals);
46779
46780 if (hlist_empty(&cookie->backing_objects))
46781 goto nobufs;
46782 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46783 goto nobufs_unlock;
46784 spin_unlock(&cookie->lock);
46785
46786 - fscache_stat(&fscache_n_retrieval_ops);
46787 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46788
46789 /* pin the netfs read context in case we need to do the actual netfs
46790 * read because we've encountered a cache read failure */
46791 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46792
46793 error:
46794 if (ret == -ENOMEM)
46795 - fscache_stat(&fscache_n_retrievals_nomem);
46796 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46797 else if (ret == -ERESTARTSYS)
46798 - fscache_stat(&fscache_n_retrievals_intr);
46799 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46800 else if (ret == -ENODATA)
46801 - fscache_stat(&fscache_n_retrievals_nodata);
46802 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46803 else if (ret < 0)
46804 - fscache_stat(&fscache_n_retrievals_nobufs);
46805 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46806 else
46807 - fscache_stat(&fscache_n_retrievals_ok);
46808 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46809
46810 fscache_put_retrieval(op);
46811 _leave(" = %d", ret);
46812 @@ -545,7 +545,7 @@ nobufs_unlock:
46813 spin_unlock(&cookie->lock);
46814 kfree(op);
46815 nobufs:
46816 - fscache_stat(&fscache_n_retrievals_nobufs);
46817 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46818 _leave(" = -ENOBUFS");
46819 return -ENOBUFS;
46820 }
46821 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46822
46823 _enter("%p,%p,,,", cookie, page);
46824
46825 - fscache_stat(&fscache_n_allocs);
46826 + fscache_stat_unchecked(&fscache_n_allocs);
46827
46828 if (hlist_empty(&cookie->backing_objects))
46829 goto nobufs;
46830 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46831 goto nobufs_unlock;
46832 spin_unlock(&cookie->lock);
46833
46834 - fscache_stat(&fscache_n_alloc_ops);
46835 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46836
46837 ret = fscache_wait_for_retrieval_activation(
46838 object, op,
46839 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46840
46841 error:
46842 if (ret == -ERESTARTSYS)
46843 - fscache_stat(&fscache_n_allocs_intr);
46844 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46845 else if (ret < 0)
46846 - fscache_stat(&fscache_n_allocs_nobufs);
46847 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46848 else
46849 - fscache_stat(&fscache_n_allocs_ok);
46850 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46851
46852 fscache_put_retrieval(op);
46853 _leave(" = %d", ret);
46854 @@ -625,7 +625,7 @@ nobufs_unlock:
46855 spin_unlock(&cookie->lock);
46856 kfree(op);
46857 nobufs:
46858 - fscache_stat(&fscache_n_allocs_nobufs);
46859 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46860 _leave(" = -ENOBUFS");
46861 return -ENOBUFS;
46862 }
46863 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46864
46865 spin_lock(&cookie->stores_lock);
46866
46867 - fscache_stat(&fscache_n_store_calls);
46868 + fscache_stat_unchecked(&fscache_n_store_calls);
46869
46870 /* find a page to store */
46871 page = NULL;
46872 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46873 page = results[0];
46874 _debug("gang %d [%lx]", n, page->index);
46875 if (page->index > op->store_limit) {
46876 - fscache_stat(&fscache_n_store_pages_over_limit);
46877 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46878 goto superseded;
46879 }
46880
46881 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46882 spin_unlock(&cookie->stores_lock);
46883 spin_unlock(&object->lock);
46884
46885 - fscache_stat(&fscache_n_store_pages);
46886 + fscache_stat_unchecked(&fscache_n_store_pages);
46887 fscache_stat(&fscache_n_cop_write_page);
46888 ret = object->cache->ops->write_page(op, page);
46889 fscache_stat_d(&fscache_n_cop_write_page);
46890 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46891 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46892 ASSERT(PageFsCache(page));
46893
46894 - fscache_stat(&fscache_n_stores);
46895 + fscache_stat_unchecked(&fscache_n_stores);
46896
46897 op = kzalloc(sizeof(*op), GFP_NOIO);
46898 if (!op)
46899 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46900 spin_unlock(&cookie->stores_lock);
46901 spin_unlock(&object->lock);
46902
46903 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46904 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46905 op->store_limit = object->store_limit;
46906
46907 if (fscache_submit_op(object, &op->op) < 0)
46908 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46909
46910 spin_unlock(&cookie->lock);
46911 radix_tree_preload_end();
46912 - fscache_stat(&fscache_n_store_ops);
46913 - fscache_stat(&fscache_n_stores_ok);
46914 + fscache_stat_unchecked(&fscache_n_store_ops);
46915 + fscache_stat_unchecked(&fscache_n_stores_ok);
46916
46917 /* the work queue now carries its own ref on the object */
46918 fscache_put_operation(&op->op);
46919 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46920 return 0;
46921
46922 already_queued:
46923 - fscache_stat(&fscache_n_stores_again);
46924 + fscache_stat_unchecked(&fscache_n_stores_again);
46925 already_pending:
46926 spin_unlock(&cookie->stores_lock);
46927 spin_unlock(&object->lock);
46928 spin_unlock(&cookie->lock);
46929 radix_tree_preload_end();
46930 kfree(op);
46931 - fscache_stat(&fscache_n_stores_ok);
46932 + fscache_stat_unchecked(&fscache_n_stores_ok);
46933 _leave(" = 0");
46934 return 0;
46935
46936 @@ -851,14 +851,14 @@ nobufs:
46937 spin_unlock(&cookie->lock);
46938 radix_tree_preload_end();
46939 kfree(op);
46940 - fscache_stat(&fscache_n_stores_nobufs);
46941 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46942 _leave(" = -ENOBUFS");
46943 return -ENOBUFS;
46944
46945 nomem_free:
46946 kfree(op);
46947 nomem:
46948 - fscache_stat(&fscache_n_stores_oom);
46949 + fscache_stat_unchecked(&fscache_n_stores_oom);
46950 _leave(" = -ENOMEM");
46951 return -ENOMEM;
46952 }
46953 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46954 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46955 ASSERTCMP(page, !=, NULL);
46956
46957 - fscache_stat(&fscache_n_uncaches);
46958 + fscache_stat_unchecked(&fscache_n_uncaches);
46959
46960 /* cache withdrawal may beat us to it */
46961 if (!PageFsCache(page))
46962 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46963 unsigned long loop;
46964
46965 #ifdef CONFIG_FSCACHE_STATS
46966 - atomic_add(pagevec->nr, &fscache_n_marks);
46967 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46968 #endif
46969
46970 for (loop = 0; loop < pagevec->nr; loop++) {
46971 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46972 index 4765190..2a067f2 100644
46973 --- a/fs/fscache/stats.c
46974 +++ b/fs/fscache/stats.c
46975 @@ -18,95 +18,95 @@
46976 /*
46977 * operation counters
46978 */
46979 -atomic_t fscache_n_op_pend;
46980 -atomic_t fscache_n_op_run;
46981 -atomic_t fscache_n_op_enqueue;
46982 -atomic_t fscache_n_op_requeue;
46983 -atomic_t fscache_n_op_deferred_release;
46984 -atomic_t fscache_n_op_release;
46985 -atomic_t fscache_n_op_gc;
46986 -atomic_t fscache_n_op_cancelled;
46987 -atomic_t fscache_n_op_rejected;
46988 +atomic_unchecked_t fscache_n_op_pend;
46989 +atomic_unchecked_t fscache_n_op_run;
46990 +atomic_unchecked_t fscache_n_op_enqueue;
46991 +atomic_unchecked_t fscache_n_op_requeue;
46992 +atomic_unchecked_t fscache_n_op_deferred_release;
46993 +atomic_unchecked_t fscache_n_op_release;
46994 +atomic_unchecked_t fscache_n_op_gc;
46995 +atomic_unchecked_t fscache_n_op_cancelled;
46996 +atomic_unchecked_t fscache_n_op_rejected;
46997
46998 -atomic_t fscache_n_attr_changed;
46999 -atomic_t fscache_n_attr_changed_ok;
47000 -atomic_t fscache_n_attr_changed_nobufs;
47001 -atomic_t fscache_n_attr_changed_nomem;
47002 -atomic_t fscache_n_attr_changed_calls;
47003 +atomic_unchecked_t fscache_n_attr_changed;
47004 +atomic_unchecked_t fscache_n_attr_changed_ok;
47005 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47006 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47007 +atomic_unchecked_t fscache_n_attr_changed_calls;
47008
47009 -atomic_t fscache_n_allocs;
47010 -atomic_t fscache_n_allocs_ok;
47011 -atomic_t fscache_n_allocs_wait;
47012 -atomic_t fscache_n_allocs_nobufs;
47013 -atomic_t fscache_n_allocs_intr;
47014 -atomic_t fscache_n_allocs_object_dead;
47015 -atomic_t fscache_n_alloc_ops;
47016 -atomic_t fscache_n_alloc_op_waits;
47017 +atomic_unchecked_t fscache_n_allocs;
47018 +atomic_unchecked_t fscache_n_allocs_ok;
47019 +atomic_unchecked_t fscache_n_allocs_wait;
47020 +atomic_unchecked_t fscache_n_allocs_nobufs;
47021 +atomic_unchecked_t fscache_n_allocs_intr;
47022 +atomic_unchecked_t fscache_n_allocs_object_dead;
47023 +atomic_unchecked_t fscache_n_alloc_ops;
47024 +atomic_unchecked_t fscache_n_alloc_op_waits;
47025
47026 -atomic_t fscache_n_retrievals;
47027 -atomic_t fscache_n_retrievals_ok;
47028 -atomic_t fscache_n_retrievals_wait;
47029 -atomic_t fscache_n_retrievals_nodata;
47030 -atomic_t fscache_n_retrievals_nobufs;
47031 -atomic_t fscache_n_retrievals_intr;
47032 -atomic_t fscache_n_retrievals_nomem;
47033 -atomic_t fscache_n_retrievals_object_dead;
47034 -atomic_t fscache_n_retrieval_ops;
47035 -atomic_t fscache_n_retrieval_op_waits;
47036 +atomic_unchecked_t fscache_n_retrievals;
47037 +atomic_unchecked_t fscache_n_retrievals_ok;
47038 +atomic_unchecked_t fscache_n_retrievals_wait;
47039 +atomic_unchecked_t fscache_n_retrievals_nodata;
47040 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47041 +atomic_unchecked_t fscache_n_retrievals_intr;
47042 +atomic_unchecked_t fscache_n_retrievals_nomem;
47043 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47044 +atomic_unchecked_t fscache_n_retrieval_ops;
47045 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47046
47047 -atomic_t fscache_n_stores;
47048 -atomic_t fscache_n_stores_ok;
47049 -atomic_t fscache_n_stores_again;
47050 -atomic_t fscache_n_stores_nobufs;
47051 -atomic_t fscache_n_stores_oom;
47052 -atomic_t fscache_n_store_ops;
47053 -atomic_t fscache_n_store_calls;
47054 -atomic_t fscache_n_store_pages;
47055 -atomic_t fscache_n_store_radix_deletes;
47056 -atomic_t fscache_n_store_pages_over_limit;
47057 +atomic_unchecked_t fscache_n_stores;
47058 +atomic_unchecked_t fscache_n_stores_ok;
47059 +atomic_unchecked_t fscache_n_stores_again;
47060 +atomic_unchecked_t fscache_n_stores_nobufs;
47061 +atomic_unchecked_t fscache_n_stores_oom;
47062 +atomic_unchecked_t fscache_n_store_ops;
47063 +atomic_unchecked_t fscache_n_store_calls;
47064 +atomic_unchecked_t fscache_n_store_pages;
47065 +atomic_unchecked_t fscache_n_store_radix_deletes;
47066 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47067
47068 -atomic_t fscache_n_store_vmscan_not_storing;
47069 -atomic_t fscache_n_store_vmscan_gone;
47070 -atomic_t fscache_n_store_vmscan_busy;
47071 -atomic_t fscache_n_store_vmscan_cancelled;
47072 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47073 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47074 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47075 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47076
47077 -atomic_t fscache_n_marks;
47078 -atomic_t fscache_n_uncaches;
47079 +atomic_unchecked_t fscache_n_marks;
47080 +atomic_unchecked_t fscache_n_uncaches;
47081
47082 -atomic_t fscache_n_acquires;
47083 -atomic_t fscache_n_acquires_null;
47084 -atomic_t fscache_n_acquires_no_cache;
47085 -atomic_t fscache_n_acquires_ok;
47086 -atomic_t fscache_n_acquires_nobufs;
47087 -atomic_t fscache_n_acquires_oom;
47088 +atomic_unchecked_t fscache_n_acquires;
47089 +atomic_unchecked_t fscache_n_acquires_null;
47090 +atomic_unchecked_t fscache_n_acquires_no_cache;
47091 +atomic_unchecked_t fscache_n_acquires_ok;
47092 +atomic_unchecked_t fscache_n_acquires_nobufs;
47093 +atomic_unchecked_t fscache_n_acquires_oom;
47094
47095 -atomic_t fscache_n_updates;
47096 -atomic_t fscache_n_updates_null;
47097 -atomic_t fscache_n_updates_run;
47098 +atomic_unchecked_t fscache_n_updates;
47099 +atomic_unchecked_t fscache_n_updates_null;
47100 +atomic_unchecked_t fscache_n_updates_run;
47101
47102 -atomic_t fscache_n_relinquishes;
47103 -atomic_t fscache_n_relinquishes_null;
47104 -atomic_t fscache_n_relinquishes_waitcrt;
47105 -atomic_t fscache_n_relinquishes_retire;
47106 +atomic_unchecked_t fscache_n_relinquishes;
47107 +atomic_unchecked_t fscache_n_relinquishes_null;
47108 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47109 +atomic_unchecked_t fscache_n_relinquishes_retire;
47110
47111 -atomic_t fscache_n_cookie_index;
47112 -atomic_t fscache_n_cookie_data;
47113 -atomic_t fscache_n_cookie_special;
47114 +atomic_unchecked_t fscache_n_cookie_index;
47115 +atomic_unchecked_t fscache_n_cookie_data;
47116 +atomic_unchecked_t fscache_n_cookie_special;
47117
47118 -atomic_t fscache_n_object_alloc;
47119 -atomic_t fscache_n_object_no_alloc;
47120 -atomic_t fscache_n_object_lookups;
47121 -atomic_t fscache_n_object_lookups_negative;
47122 -atomic_t fscache_n_object_lookups_positive;
47123 -atomic_t fscache_n_object_lookups_timed_out;
47124 -atomic_t fscache_n_object_created;
47125 -atomic_t fscache_n_object_avail;
47126 -atomic_t fscache_n_object_dead;
47127 +atomic_unchecked_t fscache_n_object_alloc;
47128 +atomic_unchecked_t fscache_n_object_no_alloc;
47129 +atomic_unchecked_t fscache_n_object_lookups;
47130 +atomic_unchecked_t fscache_n_object_lookups_negative;
47131 +atomic_unchecked_t fscache_n_object_lookups_positive;
47132 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47133 +atomic_unchecked_t fscache_n_object_created;
47134 +atomic_unchecked_t fscache_n_object_avail;
47135 +atomic_unchecked_t fscache_n_object_dead;
47136
47137 -atomic_t fscache_n_checkaux_none;
47138 -atomic_t fscache_n_checkaux_okay;
47139 -atomic_t fscache_n_checkaux_update;
47140 -atomic_t fscache_n_checkaux_obsolete;
47141 +atomic_unchecked_t fscache_n_checkaux_none;
47142 +atomic_unchecked_t fscache_n_checkaux_okay;
47143 +atomic_unchecked_t fscache_n_checkaux_update;
47144 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47145
47146 atomic_t fscache_n_cop_alloc_object;
47147 atomic_t fscache_n_cop_lookup_object;
47148 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47149 seq_puts(m, "FS-Cache statistics\n");
47150
47151 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47152 - atomic_read(&fscache_n_cookie_index),
47153 - atomic_read(&fscache_n_cookie_data),
47154 - atomic_read(&fscache_n_cookie_special));
47155 + atomic_read_unchecked(&fscache_n_cookie_index),
47156 + atomic_read_unchecked(&fscache_n_cookie_data),
47157 + atomic_read_unchecked(&fscache_n_cookie_special));
47158
47159 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47160 - atomic_read(&fscache_n_object_alloc),
47161 - atomic_read(&fscache_n_object_no_alloc),
47162 - atomic_read(&fscache_n_object_avail),
47163 - atomic_read(&fscache_n_object_dead));
47164 + atomic_read_unchecked(&fscache_n_object_alloc),
47165 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47166 + atomic_read_unchecked(&fscache_n_object_avail),
47167 + atomic_read_unchecked(&fscache_n_object_dead));
47168 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47169 - atomic_read(&fscache_n_checkaux_none),
47170 - atomic_read(&fscache_n_checkaux_okay),
47171 - atomic_read(&fscache_n_checkaux_update),
47172 - atomic_read(&fscache_n_checkaux_obsolete));
47173 + atomic_read_unchecked(&fscache_n_checkaux_none),
47174 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47175 + atomic_read_unchecked(&fscache_n_checkaux_update),
47176 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47177
47178 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47179 - atomic_read(&fscache_n_marks),
47180 - atomic_read(&fscache_n_uncaches));
47181 + atomic_read_unchecked(&fscache_n_marks),
47182 + atomic_read_unchecked(&fscache_n_uncaches));
47183
47184 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47185 " oom=%u\n",
47186 - atomic_read(&fscache_n_acquires),
47187 - atomic_read(&fscache_n_acquires_null),
47188 - atomic_read(&fscache_n_acquires_no_cache),
47189 - atomic_read(&fscache_n_acquires_ok),
47190 - atomic_read(&fscache_n_acquires_nobufs),
47191 - atomic_read(&fscache_n_acquires_oom));
47192 + atomic_read_unchecked(&fscache_n_acquires),
47193 + atomic_read_unchecked(&fscache_n_acquires_null),
47194 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47195 + atomic_read_unchecked(&fscache_n_acquires_ok),
47196 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47197 + atomic_read_unchecked(&fscache_n_acquires_oom));
47198
47199 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47200 - atomic_read(&fscache_n_object_lookups),
47201 - atomic_read(&fscache_n_object_lookups_negative),
47202 - atomic_read(&fscache_n_object_lookups_positive),
47203 - atomic_read(&fscache_n_object_created),
47204 - atomic_read(&fscache_n_object_lookups_timed_out));
47205 + atomic_read_unchecked(&fscache_n_object_lookups),
47206 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47207 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47208 + atomic_read_unchecked(&fscache_n_object_created),
47209 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47210
47211 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47212 - atomic_read(&fscache_n_updates),
47213 - atomic_read(&fscache_n_updates_null),
47214 - atomic_read(&fscache_n_updates_run));
47215 + atomic_read_unchecked(&fscache_n_updates),
47216 + atomic_read_unchecked(&fscache_n_updates_null),
47217 + atomic_read_unchecked(&fscache_n_updates_run));
47218
47219 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47220 - atomic_read(&fscache_n_relinquishes),
47221 - atomic_read(&fscache_n_relinquishes_null),
47222 - atomic_read(&fscache_n_relinquishes_waitcrt),
47223 - atomic_read(&fscache_n_relinquishes_retire));
47224 + atomic_read_unchecked(&fscache_n_relinquishes),
47225 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47226 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47227 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47228
47229 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47230 - atomic_read(&fscache_n_attr_changed),
47231 - atomic_read(&fscache_n_attr_changed_ok),
47232 - atomic_read(&fscache_n_attr_changed_nobufs),
47233 - atomic_read(&fscache_n_attr_changed_nomem),
47234 - atomic_read(&fscache_n_attr_changed_calls));
47235 + atomic_read_unchecked(&fscache_n_attr_changed),
47236 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47237 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47238 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47239 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47240
47241 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47242 - atomic_read(&fscache_n_allocs),
47243 - atomic_read(&fscache_n_allocs_ok),
47244 - atomic_read(&fscache_n_allocs_wait),
47245 - atomic_read(&fscache_n_allocs_nobufs),
47246 - atomic_read(&fscache_n_allocs_intr));
47247 + atomic_read_unchecked(&fscache_n_allocs),
47248 + atomic_read_unchecked(&fscache_n_allocs_ok),
47249 + atomic_read_unchecked(&fscache_n_allocs_wait),
47250 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47251 + atomic_read_unchecked(&fscache_n_allocs_intr));
47252 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47253 - atomic_read(&fscache_n_alloc_ops),
47254 - atomic_read(&fscache_n_alloc_op_waits),
47255 - atomic_read(&fscache_n_allocs_object_dead));
47256 + atomic_read_unchecked(&fscache_n_alloc_ops),
47257 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47258 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47259
47260 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47261 " int=%u oom=%u\n",
47262 - atomic_read(&fscache_n_retrievals),
47263 - atomic_read(&fscache_n_retrievals_ok),
47264 - atomic_read(&fscache_n_retrievals_wait),
47265 - atomic_read(&fscache_n_retrievals_nodata),
47266 - atomic_read(&fscache_n_retrievals_nobufs),
47267 - atomic_read(&fscache_n_retrievals_intr),
47268 - atomic_read(&fscache_n_retrievals_nomem));
47269 + atomic_read_unchecked(&fscache_n_retrievals),
47270 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47271 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47272 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47273 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47274 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47275 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47276 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47277 - atomic_read(&fscache_n_retrieval_ops),
47278 - atomic_read(&fscache_n_retrieval_op_waits),
47279 - atomic_read(&fscache_n_retrievals_object_dead));
47280 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47281 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47282 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47283
47284 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47285 - atomic_read(&fscache_n_stores),
47286 - atomic_read(&fscache_n_stores_ok),
47287 - atomic_read(&fscache_n_stores_again),
47288 - atomic_read(&fscache_n_stores_nobufs),
47289 - atomic_read(&fscache_n_stores_oom));
47290 + atomic_read_unchecked(&fscache_n_stores),
47291 + atomic_read_unchecked(&fscache_n_stores_ok),
47292 + atomic_read_unchecked(&fscache_n_stores_again),
47293 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47294 + atomic_read_unchecked(&fscache_n_stores_oom));
47295 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47296 - atomic_read(&fscache_n_store_ops),
47297 - atomic_read(&fscache_n_store_calls),
47298 - atomic_read(&fscache_n_store_pages),
47299 - atomic_read(&fscache_n_store_radix_deletes),
47300 - atomic_read(&fscache_n_store_pages_over_limit));
47301 + atomic_read_unchecked(&fscache_n_store_ops),
47302 + atomic_read_unchecked(&fscache_n_store_calls),
47303 + atomic_read_unchecked(&fscache_n_store_pages),
47304 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47305 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47306
47307 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47308 - atomic_read(&fscache_n_store_vmscan_not_storing),
47309 - atomic_read(&fscache_n_store_vmscan_gone),
47310 - atomic_read(&fscache_n_store_vmscan_busy),
47311 - atomic_read(&fscache_n_store_vmscan_cancelled));
47312 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47313 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47314 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47315 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47316
47317 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47318 - atomic_read(&fscache_n_op_pend),
47319 - atomic_read(&fscache_n_op_run),
47320 - atomic_read(&fscache_n_op_enqueue),
47321 - atomic_read(&fscache_n_op_cancelled),
47322 - atomic_read(&fscache_n_op_rejected));
47323 + atomic_read_unchecked(&fscache_n_op_pend),
47324 + atomic_read_unchecked(&fscache_n_op_run),
47325 + atomic_read_unchecked(&fscache_n_op_enqueue),
47326 + atomic_read_unchecked(&fscache_n_op_cancelled),
47327 + atomic_read_unchecked(&fscache_n_op_rejected));
47328 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47329 - atomic_read(&fscache_n_op_deferred_release),
47330 - atomic_read(&fscache_n_op_release),
47331 - atomic_read(&fscache_n_op_gc));
47332 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47333 + atomic_read_unchecked(&fscache_n_op_release),
47334 + atomic_read_unchecked(&fscache_n_op_gc));
47335
47336 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47337 atomic_read(&fscache_n_cop_alloc_object),
47338 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47339 index ee8d550..7189d8c 100644
47340 --- a/fs/fuse/cuse.c
47341 +++ b/fs/fuse/cuse.c
47342 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47343 INIT_LIST_HEAD(&cuse_conntbl[i]);
47344
47345 /* inherit and extend fuse_dev_operations */
47346 - cuse_channel_fops = fuse_dev_operations;
47347 - cuse_channel_fops.owner = THIS_MODULE;
47348 - cuse_channel_fops.open = cuse_channel_open;
47349 - cuse_channel_fops.release = cuse_channel_release;
47350 + pax_open_kernel();
47351 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47352 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47353 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47354 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47355 + pax_close_kernel();
47356
47357 cuse_class = class_create(THIS_MODULE, "cuse");
47358 if (IS_ERR(cuse_class))
47359 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47360 index f4246cf..b4aed1d 100644
47361 --- a/fs/fuse/dev.c
47362 +++ b/fs/fuse/dev.c
47363 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47364 ret = 0;
47365 pipe_lock(pipe);
47366
47367 - if (!pipe->readers) {
47368 + if (!atomic_read(&pipe->readers)) {
47369 send_sig(SIGPIPE, current, 0);
47370 if (!ret)
47371 ret = -EPIPE;
47372 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47373 index 324bc08..4fdd56e 100644
47374 --- a/fs/fuse/dir.c
47375 +++ b/fs/fuse/dir.c
47376 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47377 return link;
47378 }
47379
47380 -static void free_link(char *link)
47381 +static void free_link(const char *link)
47382 {
47383 if (!IS_ERR(link))
47384 free_page((unsigned long) link);
47385 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47386 index 753af3d..f7b021a 100644
47387 --- a/fs/gfs2/inode.c
47388 +++ b/fs/gfs2/inode.c
47389 @@ -1498,7 +1498,7 @@ out:
47390
47391 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47392 {
47393 - char *s = nd_get_link(nd);
47394 + const char *s = nd_get_link(nd);
47395 if (!IS_ERR(s))
47396 kfree(s);
47397 }
47398 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47399 index 8349a89..51a0254 100644
47400 --- a/fs/hugetlbfs/inode.c
47401 +++ b/fs/hugetlbfs/inode.c
47402 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47403 .kill_sb = kill_litter_super,
47404 };
47405
47406 -static struct vfsmount *hugetlbfs_vfsmount;
47407 +struct vfsmount *hugetlbfs_vfsmount;
47408
47409 static int can_do_hugetlb_shm(void)
47410 {
47411 diff --git a/fs/inode.c b/fs/inode.c
47412 index ac8d904..9f45d40 100644
47413 --- a/fs/inode.c
47414 +++ b/fs/inode.c
47415 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47416
47417 #ifdef CONFIG_SMP
47418 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47419 - static atomic_t shared_last_ino;
47420 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47421 + static atomic_unchecked_t shared_last_ino;
47422 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47423
47424 res = next - LAST_INO_BATCH;
47425 }
47426 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47427 index 4a6cf28..d3a29d3 100644
47428 --- a/fs/jffs2/erase.c
47429 +++ b/fs/jffs2/erase.c
47430 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47431 struct jffs2_unknown_node marker = {
47432 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47433 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47434 - .totlen = cpu_to_je32(c->cleanmarker_size)
47435 + .totlen = cpu_to_je32(c->cleanmarker_size),
47436 + .hdr_crc = cpu_to_je32(0)
47437 };
47438
47439 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47440 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47441 index a6597d6..41b30ec 100644
47442 --- a/fs/jffs2/wbuf.c
47443 +++ b/fs/jffs2/wbuf.c
47444 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47445 {
47446 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47447 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47448 - .totlen = constant_cpu_to_je32(8)
47449 + .totlen = constant_cpu_to_je32(8),
47450 + .hdr_crc = constant_cpu_to_je32(0)
47451 };
47452
47453 /*
47454 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47455 index c55c745..f67ee56 100644
47456 --- a/fs/jfs/super.c
47457 +++ b/fs/jfs/super.c
47458 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47459
47460 jfs_inode_cachep =
47461 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47462 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47463 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47464 init_once);
47465 if (jfs_inode_cachep == NULL)
47466 return -ENOMEM;
47467 diff --git a/fs/libfs.c b/fs/libfs.c
47468 index a74cb17..37fcbe4 100644
47469 --- a/fs/libfs.c
47470 +++ b/fs/libfs.c
47471 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47472
47473 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47474 struct dentry *next;
47475 + char d_name[sizeof(next->d_iname)];
47476 + const unsigned char *name;
47477 +
47478 next = list_entry(p, struct dentry, d_u.d_child);
47479 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47480 if (!simple_positive(next)) {
47481 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47482
47483 spin_unlock(&next->d_lock);
47484 spin_unlock(&dentry->d_lock);
47485 - if (filldir(dirent, next->d_name.name,
47486 + name = next->d_name.name;
47487 + if (name == next->d_iname) {
47488 + memcpy(d_name, name, next->d_name.len);
47489 + name = d_name;
47490 + }
47491 + if (filldir(dirent, name,
47492 next->d_name.len, filp->f_pos,
47493 next->d_inode->i_ino,
47494 dt_type(next->d_inode)) < 0)
47495 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47496 index 05d2912..760abfa 100644
47497 --- a/fs/lockd/clntproc.c
47498 +++ b/fs/lockd/clntproc.c
47499 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47500 /*
47501 * Cookie counter for NLM requests
47502 */
47503 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47504 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47505
47506 void nlmclnt_next_cookie(struct nlm_cookie *c)
47507 {
47508 - u32 cookie = atomic_inc_return(&nlm_cookie);
47509 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47510
47511 memcpy(c->data, &cookie, 4);
47512 c->len=4;
47513 diff --git a/fs/locks.c b/fs/locks.c
47514 index 7e81bfc..c3649aa 100644
47515 --- a/fs/locks.c
47516 +++ b/fs/locks.c
47517 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47518 return;
47519
47520 if (filp->f_op && filp->f_op->flock) {
47521 - struct file_lock fl = {
47522 + struct file_lock flock = {
47523 .fl_pid = current->tgid,
47524 .fl_file = filp,
47525 .fl_flags = FL_FLOCK,
47526 .fl_type = F_UNLCK,
47527 .fl_end = OFFSET_MAX,
47528 };
47529 - filp->f_op->flock(filp, F_SETLKW, &fl);
47530 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47531 - fl.fl_ops->fl_release_private(&fl);
47532 + filp->f_op->flock(filp, F_SETLKW, &flock);
47533 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47534 + flock.fl_ops->fl_release_private(&flock);
47535 }
47536
47537 lock_flocks();
47538 diff --git a/fs/namei.c b/fs/namei.c
47539 index 81bd546..80149d9 100644
47540 --- a/fs/namei.c
47541 +++ b/fs/namei.c
47542 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47543 if (ret != -EACCES)
47544 return ret;
47545
47546 +#ifdef CONFIG_GRKERNSEC
47547 + /* we'll block if we have to log due to a denied capability use */
47548 + if (mask & MAY_NOT_BLOCK)
47549 + return -ECHILD;
47550 +#endif
47551 +
47552 if (S_ISDIR(inode->i_mode)) {
47553 /* DACs are overridable for directories */
47554 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47555 - return 0;
47556 if (!(mask & MAY_WRITE))
47557 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47558 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47559 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47560 return 0;
47561 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47562 + return 0;
47563 return -EACCES;
47564 }
47565 /*
47566 + * Searching includes executable on directories, else just read.
47567 + */
47568 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47569 + if (mask == MAY_READ)
47570 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47571 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47572 + return 0;
47573 +
47574 + /*
47575 * Read/write DACs are always overridable.
47576 * Executable DACs are overridable when there is
47577 * at least one exec bit set.
47578 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47579 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47580 return 0;
47581
47582 - /*
47583 - * Searching includes executable on directories, else just read.
47584 - */
47585 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47586 - if (mask == MAY_READ)
47587 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47588 - return 0;
47589 -
47590 return -EACCES;
47591 }
47592
47593 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47594 {
47595 struct dentry *dentry = link->dentry;
47596 int error;
47597 - char *s;
47598 + const char *s;
47599
47600 BUG_ON(nd->flags & LOOKUP_RCU);
47601
47602 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47603 if (error)
47604 goto out_put_nd_path;
47605
47606 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47607 + dentry->d_inode, dentry, nd->path.mnt)) {
47608 + error = -EACCES;
47609 + goto out_put_nd_path;
47610 + }
47611 +
47612 nd->last_type = LAST_BIND;
47613 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47614 error = PTR_ERR(*p);
47615 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47616 break;
47617 res = walk_component(nd, path, &nd->last,
47618 nd->last_type, LOOKUP_FOLLOW);
47619 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47620 + res = -EACCES;
47621 put_link(nd, &link, cookie);
47622 } while (res > 0);
47623
47624 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47625 if (err)
47626 break;
47627 err = lookup_last(nd, &path);
47628 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47629 + err = -EACCES;
47630 put_link(nd, &link, cookie);
47631 }
47632 }
47633 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47634 if (!err)
47635 err = complete_walk(nd);
47636
47637 + if (!(nd->flags & LOOKUP_PARENT)) {
47638 +#ifdef CONFIG_GRKERNSEC
47639 + if (flags & LOOKUP_RCU) {
47640 + if (!err)
47641 + path_put(&nd->path);
47642 + err = -ECHILD;
47643 + } else
47644 +#endif
47645 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47646 + if (!err)
47647 + path_put(&nd->path);
47648 + err = -ENOENT;
47649 + }
47650 + }
47651 +
47652 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47653 if (!nd->inode->i_op->lookup) {
47654 path_put(&nd->path);
47655 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47656 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47657
47658 if (likely(!retval)) {
47659 + if (*name != '/' && nd->path.dentry && nd->inode) {
47660 +#ifdef CONFIG_GRKERNSEC
47661 + if (flags & LOOKUP_RCU)
47662 + return -ECHILD;
47663 +#endif
47664 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47665 + return -ENOENT;
47666 + }
47667 +
47668 if (unlikely(!audit_dummy_context())) {
47669 if (nd->path.dentry && nd->inode)
47670 audit_inode(name, nd->path.dentry);
47671 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47672 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47673 return -EPERM;
47674
47675 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47676 + return -EPERM;
47677 + if (gr_handle_rawio(inode))
47678 + return -EPERM;
47679 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47680 + return -EACCES;
47681 +
47682 return 0;
47683 }
47684
47685 @@ -2557,7 +2606,7 @@ looked_up:
47686 * cleared otherwise prior to returning.
47687 */
47688 static int lookup_open(struct nameidata *nd, struct path *path,
47689 - struct file *file,
47690 + struct path *link, struct file *file,
47691 const struct open_flags *op,
47692 bool got_write, int *opened)
47693 {
47694 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47695 /* Negative dentry, just create the file */
47696 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47697 umode_t mode = op->mode;
47698 +
47699 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47700 + error = -EACCES;
47701 + goto out_dput;
47702 + }
47703 +
47704 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47705 + error = -EACCES;
47706 + goto out_dput;
47707 + }
47708 +
47709 if (!IS_POSIXACL(dir->d_inode))
47710 mode &= ~current_umask();
47711 /*
47712 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47713 nd->flags & LOOKUP_EXCL);
47714 if (error)
47715 goto out_dput;
47716 + else
47717 + gr_handle_create(dentry, nd->path.mnt);
47718 }
47719 out_no_open:
47720 path->dentry = dentry;
47721 @@ -2627,7 +2689,7 @@ out_dput:
47722 /*
47723 * Handle the last step of open()
47724 */
47725 -static int do_last(struct nameidata *nd, struct path *path,
47726 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47727 struct file *file, const struct open_flags *op,
47728 int *opened, const char *pathname)
47729 {
47730 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47731 error = complete_walk(nd);
47732 if (error)
47733 return error;
47734 +#ifdef CONFIG_GRKERNSEC
47735 + if (nd->flags & LOOKUP_RCU) {
47736 + error = -ECHILD;
47737 + goto out;
47738 + }
47739 +#endif
47740 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47741 + error = -ENOENT;
47742 + goto out;
47743 + }
47744 audit_inode(pathname, nd->path.dentry);
47745 if (open_flag & O_CREAT) {
47746 error = -EISDIR;
47747 goto out;
47748 }
47749 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47750 + error = -EACCES;
47751 + goto out;
47752 + }
47753 goto finish_open;
47754 case LAST_BIND:
47755 error = complete_walk(nd);
47756 if (error)
47757 return error;
47758 +#ifdef CONFIG_GRKERNSEC
47759 + if (nd->flags & LOOKUP_RCU) {
47760 + error = -ECHILD;
47761 + goto out;
47762 + }
47763 +#endif
47764 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47765 + error = -ENOENT;
47766 + goto out;
47767 + }
47768 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47769 + error = -EACCES;
47770 + goto out;
47771 + }
47772 audit_inode(pathname, dir);
47773 goto finish_open;
47774 }
47775 @@ -2714,7 +2804,7 @@ retry_lookup:
47776 */
47777 }
47778 mutex_lock(&dir->d_inode->i_mutex);
47779 - error = lookup_open(nd, path, file, op, got_write, opened);
47780 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47781 mutex_unlock(&dir->d_inode->i_mutex);
47782
47783 if (error <= 0) {
47784 @@ -2738,11 +2828,28 @@ retry_lookup:
47785 goto finish_open_created;
47786 }
47787
47788 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47789 + error = -ENOENT;
47790 + goto exit_dput;
47791 + }
47792 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47793 + error = -EACCES;
47794 + goto exit_dput;
47795 + }
47796 +
47797 /*
47798 * create/update audit record if it already exists.
47799 */
47800 - if (path->dentry->d_inode)
47801 + if (path->dentry->d_inode) {
47802 + /* only check if O_CREAT is specified, all other checks need to go
47803 + into may_open */
47804 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47805 + error = -EACCES;
47806 + goto exit_dput;
47807 + }
47808 +
47809 audit_inode(pathname, path->dentry);
47810 + }
47811
47812 /*
47813 * If atomic_open() acquired write access it is dropped now due to
47814 @@ -2783,6 +2890,11 @@ finish_lookup:
47815 }
47816 }
47817 BUG_ON(inode != path->dentry->d_inode);
47818 + /* if we're resolving a symlink to another symlink */
47819 + if (link && gr_handle_symlink_owner(link, inode)) {
47820 + error = -EACCES;
47821 + goto out;
47822 + }
47823 return 1;
47824 }
47825
47826 @@ -2792,7 +2904,6 @@ finish_lookup:
47827 save_parent.dentry = nd->path.dentry;
47828 save_parent.mnt = mntget(path->mnt);
47829 nd->path.dentry = path->dentry;
47830 -
47831 }
47832 nd->inode = inode;
47833 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47834 @@ -2801,6 +2912,22 @@ finish_lookup:
47835 path_put(&save_parent);
47836 return error;
47837 }
47838 +
47839 +#ifdef CONFIG_GRKERNSEC
47840 + if (nd->flags & LOOKUP_RCU) {
47841 + error = -ECHILD;
47842 + goto out;
47843 + }
47844 +#endif
47845 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47846 + error = -ENOENT;
47847 + goto out;
47848 + }
47849 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47850 + error = -EACCES;
47851 + goto out;
47852 + }
47853 +
47854 error = -EISDIR;
47855 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47856 goto out;
47857 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47858 if (unlikely(error))
47859 goto out;
47860
47861 - error = do_last(nd, &path, file, op, &opened, pathname);
47862 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47863 while (unlikely(error > 0)) { /* trailing symlink */
47864 struct path link = path;
47865 void *cookie;
47866 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47867 error = follow_link(&link, nd, &cookie);
47868 if (unlikely(error))
47869 break;
47870 - error = do_last(nd, &path, file, op, &opened, pathname);
47871 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47872 put_link(nd, &link, cookie);
47873 }
47874 out:
47875 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47876 goto unlock;
47877
47878 error = -EEXIST;
47879 - if (dentry->d_inode)
47880 + if (dentry->d_inode) {
47881 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47882 + error = -ENOENT;
47883 + }
47884 goto fail;
47885 + }
47886 /*
47887 * Special case - lookup gave negative, but... we had foo/bar/
47888 * From the vfs_mknod() POV we just have a negative dentry -
47889 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47890 }
47891 EXPORT_SYMBOL(user_path_create);
47892
47893 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47894 +{
47895 + char *tmp = getname(pathname);
47896 + struct dentry *res;
47897 + if (IS_ERR(tmp))
47898 + return ERR_CAST(tmp);
47899 + res = kern_path_create(dfd, tmp, path, is_dir);
47900 + if (IS_ERR(res))
47901 + putname(tmp);
47902 + else
47903 + *to = tmp;
47904 + return res;
47905 +}
47906 +
47907 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47908 {
47909 int error = may_create(dir, dentry);
47910 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47911
47912 if (!IS_POSIXACL(path.dentry->d_inode))
47913 mode &= ~current_umask();
47914 +
47915 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47916 + error = -EPERM;
47917 + goto out;
47918 + }
47919 +
47920 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47921 + error = -EACCES;
47922 + goto out;
47923 + }
47924 +
47925 error = security_path_mknod(&path, dentry, mode, dev);
47926 if (error)
47927 goto out;
47928 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47929 break;
47930 }
47931 out:
47932 + if (!error)
47933 + gr_handle_create(dentry, path.mnt);
47934 done_path_create(&path, dentry);
47935 return error;
47936 }
47937 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47938
47939 if (!IS_POSIXACL(path.dentry->d_inode))
47940 mode &= ~current_umask();
47941 +
47942 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47943 + error = -EACCES;
47944 + goto out;
47945 + }
47946 +
47947 error = security_path_mkdir(&path, dentry, mode);
47948 if (!error)
47949 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47950 + if (!error)
47951 + gr_handle_create(dentry, path.mnt);
47952 +out:
47953 done_path_create(&path, dentry);
47954 return error;
47955 }
47956 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47957 char * name;
47958 struct dentry *dentry;
47959 struct nameidata nd;
47960 + ino_t saved_ino = 0;
47961 + dev_t saved_dev = 0;
47962
47963 error = user_path_parent(dfd, pathname, &nd, &name);
47964 if (error)
47965 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47966 error = -ENOENT;
47967 goto exit3;
47968 }
47969 +
47970 + saved_ino = dentry->d_inode->i_ino;
47971 + saved_dev = gr_get_dev_from_dentry(dentry);
47972 +
47973 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47974 + error = -EACCES;
47975 + goto exit3;
47976 + }
47977 +
47978 error = security_path_rmdir(&nd.path, dentry);
47979 if (error)
47980 goto exit3;
47981 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47982 + if (!error && (saved_dev || saved_ino))
47983 + gr_handle_delete(saved_ino, saved_dev);
47984 exit3:
47985 dput(dentry);
47986 exit2:
47987 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47988 struct dentry *dentry;
47989 struct nameidata nd;
47990 struct inode *inode = NULL;
47991 + ino_t saved_ino = 0;
47992 + dev_t saved_dev = 0;
47993
47994 error = user_path_parent(dfd, pathname, &nd, &name);
47995 if (error)
47996 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47997 if (!inode)
47998 goto slashes;
47999 ihold(inode);
48000 +
48001 + if (inode->i_nlink <= 1) {
48002 + saved_ino = inode->i_ino;
48003 + saved_dev = gr_get_dev_from_dentry(dentry);
48004 + }
48005 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48006 + error = -EACCES;
48007 + goto exit2;
48008 + }
48009 +
48010 error = security_path_unlink(&nd.path, dentry);
48011 if (error)
48012 goto exit2;
48013 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48014 + if (!error && (saved_ino || saved_dev))
48015 + gr_handle_delete(saved_ino, saved_dev);
48016 exit2:
48017 dput(dentry);
48018 }
48019 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48020 if (IS_ERR(dentry))
48021 goto out_putname;
48022
48023 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48024 + error = -EACCES;
48025 + goto out;
48026 + }
48027 +
48028 error = security_path_symlink(&path, dentry, from);
48029 if (!error)
48030 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48031 + if (!error)
48032 + gr_handle_create(dentry, path.mnt);
48033 +out:
48034 done_path_create(&path, dentry);
48035 out_putname:
48036 putname(from);
48037 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48038 {
48039 struct dentry *new_dentry;
48040 struct path old_path, new_path;
48041 + char *to = NULL;
48042 int how = 0;
48043 int error;
48044
48045 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48046 if (error)
48047 return error;
48048
48049 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48050 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48051 error = PTR_ERR(new_dentry);
48052 if (IS_ERR(new_dentry))
48053 goto out;
48054 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48055 error = may_linkat(&old_path);
48056 if (unlikely(error))
48057 goto out_dput;
48058 +
48059 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48060 + old_path.dentry->d_inode,
48061 + old_path.dentry->d_inode->i_mode, to)) {
48062 + error = -EACCES;
48063 + goto out_dput;
48064 + }
48065 +
48066 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48067 + old_path.dentry, old_path.mnt, to)) {
48068 + error = -EACCES;
48069 + goto out_dput;
48070 + }
48071 +
48072 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48073 if (error)
48074 goto out_dput;
48075 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48076 + if (!error)
48077 + gr_handle_create(new_dentry, new_path.mnt);
48078 out_dput:
48079 + putname(to);
48080 done_path_create(&new_path, new_dentry);
48081 out:
48082 path_put(&old_path);
48083 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48084 if (new_dentry == trap)
48085 goto exit5;
48086
48087 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48088 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48089 + to);
48090 + if (error)
48091 + goto exit5;
48092 +
48093 error = security_path_rename(&oldnd.path, old_dentry,
48094 &newnd.path, new_dentry);
48095 if (error)
48096 goto exit5;
48097 error = vfs_rename(old_dir->d_inode, old_dentry,
48098 new_dir->d_inode, new_dentry);
48099 + if (!error)
48100 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48101 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48102 exit5:
48103 dput(new_dentry);
48104 exit4:
48105 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48106
48107 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48108 {
48109 + char tmpbuf[64];
48110 + const char *newlink;
48111 int len;
48112
48113 len = PTR_ERR(link);
48114 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48115 len = strlen(link);
48116 if (len > (unsigned) buflen)
48117 len = buflen;
48118 - if (copy_to_user(buffer, link, len))
48119 +
48120 + if (len < sizeof(tmpbuf)) {
48121 + memcpy(tmpbuf, link, len);
48122 + newlink = tmpbuf;
48123 + } else
48124 + newlink = link;
48125 +
48126 + if (copy_to_user(buffer, newlink, len))
48127 len = -EFAULT;
48128 out:
48129 return len;
48130 diff --git a/fs/namespace.c b/fs/namespace.c
48131 index 7bdf790..eb79c4b 100644
48132 --- a/fs/namespace.c
48133 +++ b/fs/namespace.c
48134 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48135 if (!(sb->s_flags & MS_RDONLY))
48136 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48137 up_write(&sb->s_umount);
48138 +
48139 + gr_log_remount(mnt->mnt_devname, retval);
48140 +
48141 return retval;
48142 }
48143
48144 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48145 br_write_unlock(&vfsmount_lock);
48146 up_write(&namespace_sem);
48147 release_mounts(&umount_list);
48148 +
48149 + gr_log_unmount(mnt->mnt_devname, retval);
48150 +
48151 return retval;
48152 }
48153
48154 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48155 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48156 MS_STRICTATIME);
48157
48158 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48159 + retval = -EPERM;
48160 + goto dput_out;
48161 + }
48162 +
48163 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48164 + retval = -EPERM;
48165 + goto dput_out;
48166 + }
48167 +
48168 if (flags & MS_REMOUNT)
48169 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48170 data_page);
48171 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48172 dev_name, data_page);
48173 dput_out:
48174 path_put(&path);
48175 +
48176 + gr_log_mount(dev_name, dir_name, retval);
48177 +
48178 return retval;
48179 }
48180
48181 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48182 if (error)
48183 goto out2;
48184
48185 + if (gr_handle_chroot_pivot()) {
48186 + error = -EPERM;
48187 + goto out2;
48188 + }
48189 +
48190 get_fs_root(current->fs, &root);
48191 error = lock_mount(&old);
48192 if (error)
48193 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48194 index 9b47610..066975e 100644
48195 --- a/fs/nfs/inode.c
48196 +++ b/fs/nfs/inode.c
48197 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48198 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48199 }
48200
48201 -static atomic_long_t nfs_attr_generation_counter;
48202 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48203
48204 static unsigned long nfs_read_attr_generation_counter(void)
48205 {
48206 - return atomic_long_read(&nfs_attr_generation_counter);
48207 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48208 }
48209
48210 unsigned long nfs_inc_attr_generation_counter(void)
48211 {
48212 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48213 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48214 }
48215
48216 void nfs_fattr_init(struct nfs_fattr *fattr)
48217 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48218 index a9269f1..5490437 100644
48219 --- a/fs/nfsd/vfs.c
48220 +++ b/fs/nfsd/vfs.c
48221 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48222 } else {
48223 oldfs = get_fs();
48224 set_fs(KERNEL_DS);
48225 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48226 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48227 set_fs(oldfs);
48228 }
48229
48230 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48231
48232 /* Write the data. */
48233 oldfs = get_fs(); set_fs(KERNEL_DS);
48234 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48235 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48236 set_fs(oldfs);
48237 if (host_err < 0)
48238 goto out_nfserr;
48239 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48240 */
48241
48242 oldfs = get_fs(); set_fs(KERNEL_DS);
48243 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48244 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48245 set_fs(oldfs);
48246
48247 if (host_err < 0)
48248 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48249 index d438036..0ecadde 100644
48250 --- a/fs/notify/fanotify/fanotify_user.c
48251 +++ b/fs/notify/fanotify/fanotify_user.c
48252 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48253 goto out_close_fd;
48254
48255 ret = -EFAULT;
48256 - if (copy_to_user(buf, &fanotify_event_metadata,
48257 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48258 + copy_to_user(buf, &fanotify_event_metadata,
48259 fanotify_event_metadata.event_len))
48260 goto out_kill_access_response;
48261
48262 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48263 index c887b13..0fdf472 100644
48264 --- a/fs/notify/notification.c
48265 +++ b/fs/notify/notification.c
48266 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48267 * get set to 0 so it will never get 'freed'
48268 */
48269 static struct fsnotify_event *q_overflow_event;
48270 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48271 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48272
48273 /**
48274 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48275 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48276 */
48277 u32 fsnotify_get_cookie(void)
48278 {
48279 - return atomic_inc_return(&fsnotify_sync_cookie);
48280 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48281 }
48282 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48283
48284 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48285 index 99e3610..02c1068 100644
48286 --- a/fs/ntfs/dir.c
48287 +++ b/fs/ntfs/dir.c
48288 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48289 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48290 ~(s64)(ndir->itype.index.block_size - 1)));
48291 /* Bounds checks. */
48292 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48293 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48294 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48295 "inode 0x%lx or driver bug.", vdir->i_ino);
48296 goto err_out;
48297 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48298 index 1ecf464..e1ff8bf 100644
48299 --- a/fs/ntfs/file.c
48300 +++ b/fs/ntfs/file.c
48301 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48302 #endif /* NTFS_RW */
48303 };
48304
48305 -const struct file_operations ntfs_empty_file_ops = {};
48306 +const struct file_operations ntfs_empty_file_ops __read_only;
48307
48308 -const struct inode_operations ntfs_empty_inode_ops = {};
48309 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48310 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48311 index a9f78c7..ed8a381 100644
48312 --- a/fs/ocfs2/localalloc.c
48313 +++ b/fs/ocfs2/localalloc.c
48314 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48315 goto bail;
48316 }
48317
48318 - atomic_inc(&osb->alloc_stats.moves);
48319 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48320
48321 bail:
48322 if (handle)
48323 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48324 index d355e6e..578d905 100644
48325 --- a/fs/ocfs2/ocfs2.h
48326 +++ b/fs/ocfs2/ocfs2.h
48327 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48328
48329 struct ocfs2_alloc_stats
48330 {
48331 - atomic_t moves;
48332 - atomic_t local_data;
48333 - atomic_t bitmap_data;
48334 - atomic_t bg_allocs;
48335 - atomic_t bg_extends;
48336 + atomic_unchecked_t moves;
48337 + atomic_unchecked_t local_data;
48338 + atomic_unchecked_t bitmap_data;
48339 + atomic_unchecked_t bg_allocs;
48340 + atomic_unchecked_t bg_extends;
48341 };
48342
48343 enum ocfs2_local_alloc_state
48344 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48345 index f169da4..9112253 100644
48346 --- a/fs/ocfs2/suballoc.c
48347 +++ b/fs/ocfs2/suballoc.c
48348 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48349 mlog_errno(status);
48350 goto bail;
48351 }
48352 - atomic_inc(&osb->alloc_stats.bg_extends);
48353 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48354
48355 /* You should never ask for this much metadata */
48356 BUG_ON(bits_wanted >
48357 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48358 mlog_errno(status);
48359 goto bail;
48360 }
48361 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48362 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48363
48364 *suballoc_loc = res.sr_bg_blkno;
48365 *suballoc_bit_start = res.sr_bit_offset;
48366 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48367 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48368 res->sr_bits);
48369
48370 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48371 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48372
48373 BUG_ON(res->sr_bits != 1);
48374
48375 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48376 mlog_errno(status);
48377 goto bail;
48378 }
48379 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48380 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48381
48382 BUG_ON(res.sr_bits != 1);
48383
48384 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48385 cluster_start,
48386 num_clusters);
48387 if (!status)
48388 - atomic_inc(&osb->alloc_stats.local_data);
48389 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48390 } else {
48391 if (min_clusters > (osb->bitmap_cpg - 1)) {
48392 /* The only paths asking for contiguousness
48393 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48394 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48395 res.sr_bg_blkno,
48396 res.sr_bit_offset);
48397 - atomic_inc(&osb->alloc_stats.bitmap_data);
48398 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48399 *num_clusters = res.sr_bits;
48400 }
48401 }
48402 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48403 index 68f4541..89cfe6a 100644
48404 --- a/fs/ocfs2/super.c
48405 +++ b/fs/ocfs2/super.c
48406 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48407 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48408 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48409 "Stats",
48410 - atomic_read(&osb->alloc_stats.bitmap_data),
48411 - atomic_read(&osb->alloc_stats.local_data),
48412 - atomic_read(&osb->alloc_stats.bg_allocs),
48413 - atomic_read(&osb->alloc_stats.moves),
48414 - atomic_read(&osb->alloc_stats.bg_extends));
48415 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48416 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48417 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48418 + atomic_read_unchecked(&osb->alloc_stats.moves),
48419 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48420
48421 out += snprintf(buf + out, len - out,
48422 "%10s => State: %u Descriptor: %llu Size: %u bits "
48423 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48424 spin_lock_init(&osb->osb_xattr_lock);
48425 ocfs2_init_steal_slots(osb);
48426
48427 - atomic_set(&osb->alloc_stats.moves, 0);
48428 - atomic_set(&osb->alloc_stats.local_data, 0);
48429 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48430 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48431 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48432 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48433 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48434 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48435 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48436 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48437
48438 /* Copy the blockcheck stats from the superblock probe */
48439 osb->osb_ecc_stats = *stats;
48440 diff --git a/fs/open.c b/fs/open.c
48441 index e1f2cdb..3bd5f39 100644
48442 --- a/fs/open.c
48443 +++ b/fs/open.c
48444 @@ -31,6 +31,8 @@
48445 #include <linux/ima.h>
48446 #include <linux/dnotify.h>
48447
48448 +#define CREATE_TRACE_POINTS
48449 +#include <trace/events/fs.h>
48450 #include "internal.h"
48451
48452 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48453 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48454 error = locks_verify_truncate(inode, NULL, length);
48455 if (!error)
48456 error = security_path_truncate(&path);
48457 +
48458 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48459 + error = -EACCES;
48460 +
48461 if (!error)
48462 error = do_truncate(path.dentry, length, 0, NULL);
48463
48464 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48465 if (__mnt_is_readonly(path.mnt))
48466 res = -EROFS;
48467
48468 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48469 + res = -EACCES;
48470 +
48471 out_path_release:
48472 path_put(&path);
48473 out:
48474 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48475 if (error)
48476 goto dput_and_out;
48477
48478 + gr_log_chdir(path.dentry, path.mnt);
48479 +
48480 set_fs_pwd(current->fs, &path);
48481
48482 dput_and_out:
48483 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48484 goto out_putf;
48485
48486 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48487 +
48488 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48489 + error = -EPERM;
48490 +
48491 + if (!error)
48492 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48493 +
48494 if (!error)
48495 set_fs_pwd(current->fs, &file->f_path);
48496 out_putf:
48497 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48498 if (error)
48499 goto dput_and_out;
48500
48501 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48502 + goto dput_and_out;
48503 +
48504 set_fs_root(current->fs, &path);
48505 +
48506 + gr_handle_chroot_chdir(&path);
48507 +
48508 error = 0;
48509 dput_and_out:
48510 path_put(&path);
48511 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48512 if (error)
48513 return error;
48514 mutex_lock(&inode->i_mutex);
48515 +
48516 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48517 + error = -EACCES;
48518 + goto out_unlock;
48519 + }
48520 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48521 + error = -EACCES;
48522 + goto out_unlock;
48523 + }
48524 +
48525 error = security_path_chmod(path, mode);
48526 if (error)
48527 goto out_unlock;
48528 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48529 uid = make_kuid(current_user_ns(), user);
48530 gid = make_kgid(current_user_ns(), group);
48531
48532 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48533 + return -EACCES;
48534 +
48535 newattrs.ia_valid = ATTR_CTIME;
48536 if (user != (uid_t) -1) {
48537 if (!uid_valid(uid))
48538 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48539 } else {
48540 fsnotify_open(f);
48541 fd_install(fd, f);
48542 + trace_do_sys_open(tmp, flags, mode);
48543 }
48544 }
48545 putname(tmp);
48546 diff --git a/fs/pipe.c b/fs/pipe.c
48547 index 8d85d70..581036b 100644
48548 --- a/fs/pipe.c
48549 +++ b/fs/pipe.c
48550 @@ -438,9 +438,9 @@ redo:
48551 }
48552 if (bufs) /* More to do? */
48553 continue;
48554 - if (!pipe->writers)
48555 + if (!atomic_read(&pipe->writers))
48556 break;
48557 - if (!pipe->waiting_writers) {
48558 + if (!atomic_read(&pipe->waiting_writers)) {
48559 /* syscall merging: Usually we must not sleep
48560 * if O_NONBLOCK is set, or if we got some data.
48561 * But if a writer sleeps in kernel space, then
48562 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48563 mutex_lock(&inode->i_mutex);
48564 pipe = inode->i_pipe;
48565
48566 - if (!pipe->readers) {
48567 + if (!atomic_read(&pipe->readers)) {
48568 send_sig(SIGPIPE, current, 0);
48569 ret = -EPIPE;
48570 goto out;
48571 @@ -553,7 +553,7 @@ redo1:
48572 for (;;) {
48573 int bufs;
48574
48575 - if (!pipe->readers) {
48576 + if (!atomic_read(&pipe->readers)) {
48577 send_sig(SIGPIPE, current, 0);
48578 if (!ret)
48579 ret = -EPIPE;
48580 @@ -644,9 +644,9 @@ redo2:
48581 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48582 do_wakeup = 0;
48583 }
48584 - pipe->waiting_writers++;
48585 + atomic_inc(&pipe->waiting_writers);
48586 pipe_wait(pipe);
48587 - pipe->waiting_writers--;
48588 + atomic_dec(&pipe->waiting_writers);
48589 }
48590 out:
48591 mutex_unlock(&inode->i_mutex);
48592 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48593 mask = 0;
48594 if (filp->f_mode & FMODE_READ) {
48595 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48596 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48597 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48598 mask |= POLLHUP;
48599 }
48600
48601 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48602 * Most Unices do not set POLLERR for FIFOs but on Linux they
48603 * behave exactly like pipes for poll().
48604 */
48605 - if (!pipe->readers)
48606 + if (!atomic_read(&pipe->readers))
48607 mask |= POLLERR;
48608 }
48609
48610 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48611
48612 mutex_lock(&inode->i_mutex);
48613 pipe = inode->i_pipe;
48614 - pipe->readers -= decr;
48615 - pipe->writers -= decw;
48616 + atomic_sub(decr, &pipe->readers);
48617 + atomic_sub(decw, &pipe->writers);
48618
48619 - if (!pipe->readers && !pipe->writers) {
48620 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48621 free_pipe_info(inode);
48622 } else {
48623 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48624 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48625
48626 if (inode->i_pipe) {
48627 ret = 0;
48628 - inode->i_pipe->readers++;
48629 + atomic_inc(&inode->i_pipe->readers);
48630 }
48631
48632 mutex_unlock(&inode->i_mutex);
48633 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48634
48635 if (inode->i_pipe) {
48636 ret = 0;
48637 - inode->i_pipe->writers++;
48638 + atomic_inc(&inode->i_pipe->writers);
48639 }
48640
48641 mutex_unlock(&inode->i_mutex);
48642 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48643 if (inode->i_pipe) {
48644 ret = 0;
48645 if (filp->f_mode & FMODE_READ)
48646 - inode->i_pipe->readers++;
48647 + atomic_inc(&inode->i_pipe->readers);
48648 if (filp->f_mode & FMODE_WRITE)
48649 - inode->i_pipe->writers++;
48650 + atomic_inc(&inode->i_pipe->writers);
48651 }
48652
48653 mutex_unlock(&inode->i_mutex);
48654 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48655 inode->i_pipe = NULL;
48656 }
48657
48658 -static struct vfsmount *pipe_mnt __read_mostly;
48659 +struct vfsmount *pipe_mnt __read_mostly;
48660
48661 /*
48662 * pipefs_dname() is called from d_path().
48663 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48664 goto fail_iput;
48665 inode->i_pipe = pipe;
48666
48667 - pipe->readers = pipe->writers = 1;
48668 + atomic_set(&pipe->readers, 1);
48669 + atomic_set(&pipe->writers, 1);
48670 inode->i_fop = &rdwr_pipefifo_fops;
48671
48672 /*
48673 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48674 index 15af622..0e9f4467 100644
48675 --- a/fs/proc/Kconfig
48676 +++ b/fs/proc/Kconfig
48677 @@ -30,12 +30,12 @@ config PROC_FS
48678
48679 config PROC_KCORE
48680 bool "/proc/kcore support" if !ARM
48681 - depends on PROC_FS && MMU
48682 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48683
48684 config PROC_VMCORE
48685 bool "/proc/vmcore support"
48686 - depends on PROC_FS && CRASH_DUMP
48687 - default y
48688 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48689 + default n
48690 help
48691 Exports the dump image of crashed kernel in ELF format.
48692
48693 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48694 limited in memory.
48695
48696 config PROC_PAGE_MONITOR
48697 - default y
48698 - depends on PROC_FS && MMU
48699 + default n
48700 + depends on PROC_FS && MMU && !GRKERNSEC
48701 bool "Enable /proc page monitoring" if EXPERT
48702 help
48703 Various /proc files exist to monitor process memory utilization:
48704 diff --git a/fs/proc/array.c b/fs/proc/array.c
48705 index c1c207c..01ce725 100644
48706 --- a/fs/proc/array.c
48707 +++ b/fs/proc/array.c
48708 @@ -60,6 +60,7 @@
48709 #include <linux/tty.h>
48710 #include <linux/string.h>
48711 #include <linux/mman.h>
48712 +#include <linux/grsecurity.h>
48713 #include <linux/proc_fs.h>
48714 #include <linux/ioport.h>
48715 #include <linux/uaccess.h>
48716 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48717 seq_putc(m, '\n');
48718 }
48719
48720 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48721 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48722 +{
48723 + if (p->mm)
48724 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48725 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48726 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48727 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48728 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48729 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48730 + else
48731 + seq_printf(m, "PaX:\t-----\n");
48732 +}
48733 +#endif
48734 +
48735 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48736 struct pid *pid, struct task_struct *task)
48737 {
48738 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48739 task_cpus_allowed(m, task);
48740 cpuset_task_status_allowed(m, task);
48741 task_context_switch_counts(m, task);
48742 +
48743 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48744 + task_pax(m, task);
48745 +#endif
48746 +
48747 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48748 + task_grsec_rbac(m, task);
48749 +#endif
48750 +
48751 return 0;
48752 }
48753
48754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48755 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48756 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48757 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48758 +#endif
48759 +
48760 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48761 struct pid *pid, struct task_struct *task, int whole)
48762 {
48763 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48764 char tcomm[sizeof(task->comm)];
48765 unsigned long flags;
48766
48767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48768 + if (current->exec_id != m->exec_id) {
48769 + gr_log_badprocpid("stat");
48770 + return 0;
48771 + }
48772 +#endif
48773 +
48774 state = *get_task_state(task);
48775 vsize = eip = esp = 0;
48776 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48777 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48778 gtime = task->gtime;
48779 }
48780
48781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48782 + if (PAX_RAND_FLAGS(mm)) {
48783 + eip = 0;
48784 + esp = 0;
48785 + wchan = 0;
48786 + }
48787 +#endif
48788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48789 + wchan = 0;
48790 + eip =0;
48791 + esp =0;
48792 +#endif
48793 +
48794 /* scale priority and nice values from timeslices to -20..20 */
48795 /* to make it look like a "normal" Unix priority/nice value */
48796 priority = task_prio(task);
48797 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48798 seq_put_decimal_ull(m, ' ', vsize);
48799 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48800 seq_put_decimal_ull(m, ' ', rsslim);
48801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48802 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48803 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48804 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48805 +#else
48806 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48807 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48808 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48809 +#endif
48810 seq_put_decimal_ull(m, ' ', esp);
48811 seq_put_decimal_ull(m, ' ', eip);
48812 /* The signal information here is obsolete.
48813 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48814 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48815 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48816
48817 - if (mm && permitted) {
48818 + if (mm && permitted
48819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48820 + && !PAX_RAND_FLAGS(mm)
48821 +#endif
48822 + ) {
48823 seq_put_decimal_ull(m, ' ', mm->start_data);
48824 seq_put_decimal_ull(m, ' ', mm->end_data);
48825 seq_put_decimal_ull(m, ' ', mm->start_brk);
48826 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48827 struct pid *pid, struct task_struct *task)
48828 {
48829 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48830 - struct mm_struct *mm = get_task_mm(task);
48831 + struct mm_struct *mm;
48832
48833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48834 + if (current->exec_id != m->exec_id) {
48835 + gr_log_badprocpid("statm");
48836 + return 0;
48837 + }
48838 +#endif
48839 + mm = get_task_mm(task);
48840 if (mm) {
48841 size = task_statm(mm, &shared, &text, &data, &resident);
48842 mmput(mm);
48843 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48844 return 0;
48845 }
48846
48847 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48848 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48849 +{
48850 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48851 +}
48852 +#endif
48853 +
48854 #ifdef CONFIG_CHECKPOINT_RESTORE
48855 static struct pid *
48856 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48857 diff --git a/fs/proc/base.c b/fs/proc/base.c
48858 index 1b6c84c..66b738b 100644
48859 --- a/fs/proc/base.c
48860 +++ b/fs/proc/base.c
48861 @@ -110,6 +110,14 @@ struct pid_entry {
48862 union proc_op op;
48863 };
48864
48865 +struct getdents_callback {
48866 + struct linux_dirent __user * current_dir;
48867 + struct linux_dirent __user * previous;
48868 + struct file * file;
48869 + int count;
48870 + int error;
48871 +};
48872 +
48873 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48874 .name = (NAME), \
48875 .len = sizeof(NAME) - 1, \
48876 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48877 if (!mm->arg_end)
48878 goto out_mm; /* Shh! No looking before we're done */
48879
48880 + if (gr_acl_handle_procpidmem(task))
48881 + goto out_mm;
48882 +
48883 len = mm->arg_end - mm->arg_start;
48884
48885 if (len > PAGE_SIZE)
48886 @@ -236,12 +247,28 @@ out:
48887 return res;
48888 }
48889
48890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48891 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48892 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48893 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48894 +#endif
48895 +
48896 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48897 {
48898 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48899 int res = PTR_ERR(mm);
48900 if (mm && !IS_ERR(mm)) {
48901 unsigned int nwords = 0;
48902 +
48903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48904 + /* allow if we're currently ptracing this task */
48905 + if (PAX_RAND_FLAGS(mm) &&
48906 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48907 + mmput(mm);
48908 + return 0;
48909 + }
48910 +#endif
48911 +
48912 do {
48913 nwords += 2;
48914 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48915 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48916 }
48917
48918
48919 -#ifdef CONFIG_KALLSYMS
48920 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48921 /*
48922 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48923 * Returns the resolved symbol. If that fails, simply return the address.
48924 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48925 mutex_unlock(&task->signal->cred_guard_mutex);
48926 }
48927
48928 -#ifdef CONFIG_STACKTRACE
48929 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48930
48931 #define MAX_STACK_TRACE_DEPTH 64
48932
48933 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48934 return count;
48935 }
48936
48937 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48938 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48939 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48940 {
48941 long nr;
48942 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48943 /************************************************************************/
48944
48945 /* permission checks */
48946 -static int proc_fd_access_allowed(struct inode *inode)
48947 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48948 {
48949 struct task_struct *task;
48950 int allowed = 0;
48951 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48952 */
48953 task = get_proc_task(inode);
48954 if (task) {
48955 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48956 + if (log)
48957 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48958 + else
48959 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48960 put_task_struct(task);
48961 }
48962 return allowed;
48963 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48964 struct task_struct *task,
48965 int hide_pid_min)
48966 {
48967 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48968 + return false;
48969 +
48970 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48971 + rcu_read_lock();
48972 + {
48973 + const struct cred *tmpcred = current_cred();
48974 + const struct cred *cred = __task_cred(task);
48975 +
48976 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48977 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48978 + || in_group_p(grsec_proc_gid)
48979 +#endif
48980 + ) {
48981 + rcu_read_unlock();
48982 + return true;
48983 + }
48984 + }
48985 + rcu_read_unlock();
48986 +
48987 + if (!pid->hide_pid)
48988 + return false;
48989 +#endif
48990 +
48991 if (pid->hide_pid < hide_pid_min)
48992 return true;
48993 if (in_group_p(pid->pid_gid))
48994 return true;
48995 +
48996 return ptrace_may_access(task, PTRACE_MODE_READ);
48997 }
48998
48999 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49000 put_task_struct(task);
49001
49002 if (!has_perms) {
49003 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49004 + {
49005 +#else
49006 if (pid->hide_pid == 2) {
49007 +#endif
49008 /*
49009 * Let's make getdents(), stat(), and open()
49010 * consistent with each other. If a process
49011 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49012 if (!task)
49013 return -ESRCH;
49014
49015 + if (gr_acl_handle_procpidmem(task)) {
49016 + put_task_struct(task);
49017 + return -EPERM;
49018 + }
49019 +
49020 mm = mm_access(task, mode);
49021 put_task_struct(task);
49022
49023 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49024
49025 file->private_data = mm;
49026
49027 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49028 + file->f_version = current->exec_id;
49029 +#endif
49030 +
49031 return 0;
49032 }
49033
49034 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49035 ssize_t copied;
49036 char *page;
49037
49038 +#ifdef CONFIG_GRKERNSEC
49039 + if (write)
49040 + return -EPERM;
49041 +#endif
49042 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49043 + if (file->f_version != current->exec_id) {
49044 + gr_log_badprocpid("mem");
49045 + return 0;
49046 + }
49047 +#endif
49048 +
49049 if (!mm)
49050 return 0;
49051
49052 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49053 if (!mm)
49054 return 0;
49055
49056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49057 + if (file->f_version != current->exec_id) {
49058 + gr_log_badprocpid("environ");
49059 + return 0;
49060 + }
49061 +#endif
49062 +
49063 page = (char *)__get_free_page(GFP_TEMPORARY);
49064 if (!page)
49065 return -ENOMEM;
49066 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49067 int error = -EACCES;
49068
49069 /* Are we allowed to snoop on the tasks file descriptors? */
49070 - if (!proc_fd_access_allowed(inode))
49071 + if (!proc_fd_access_allowed(inode, 0))
49072 goto out;
49073
49074 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49075 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49076 struct path path;
49077
49078 /* Are we allowed to snoop on the tasks file descriptors? */
49079 - if (!proc_fd_access_allowed(inode))
49080 - goto out;
49081 + /* logging this is needed for learning on chromium to work properly,
49082 + but we don't want to flood the logs from 'ps' which does a readlink
49083 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49084 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49085 + */
49086 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49087 + if (!proc_fd_access_allowed(inode,0))
49088 + goto out;
49089 + } else {
49090 + if (!proc_fd_access_allowed(inode,1))
49091 + goto out;
49092 + }
49093
49094 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49095 if (error)
49096 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49097 rcu_read_lock();
49098 cred = __task_cred(task);
49099 inode->i_uid = cred->euid;
49100 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49101 + inode->i_gid = grsec_proc_gid;
49102 +#else
49103 inode->i_gid = cred->egid;
49104 +#endif
49105 rcu_read_unlock();
49106 }
49107 security_task_to_inode(task, inode);
49108 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49109 return -ENOENT;
49110 }
49111 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49112 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49113 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49114 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49115 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49116 +#endif
49117 task_dumpable(task)) {
49118 cred = __task_cred(task);
49119 stat->uid = cred->euid;
49120 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49121 + stat->gid = grsec_proc_gid;
49122 +#else
49123 stat->gid = cred->egid;
49124 +#endif
49125 }
49126 }
49127 rcu_read_unlock();
49128 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49129
49130 if (task) {
49131 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49133 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49135 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49136 +#endif
49137 task_dumpable(task)) {
49138 rcu_read_lock();
49139 cred = __task_cred(task);
49140 inode->i_uid = cred->euid;
49141 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49142 + inode->i_gid = grsec_proc_gid;
49143 +#else
49144 inode->i_gid = cred->egid;
49145 +#endif
49146 rcu_read_unlock();
49147 } else {
49148 inode->i_uid = GLOBAL_ROOT_UID;
49149 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49150 int fd = proc_fd(inode);
49151
49152 if (task) {
49153 - files = get_files_struct(task);
49154 + if (!gr_acl_handle_procpidmem(task))
49155 + files = get_files_struct(task);
49156 put_task_struct(task);
49157 }
49158 if (files) {
49159 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49160 */
49161 static int proc_fd_permission(struct inode *inode, int mask)
49162 {
49163 + struct task_struct *task;
49164 int rv = generic_permission(inode, mask);
49165 - if (rv == 0)
49166 - return 0;
49167 +
49168 if (task_pid(current) == proc_pid(inode))
49169 rv = 0;
49170 +
49171 + task = get_proc_task(inode);
49172 + if (task == NULL)
49173 + return rv;
49174 +
49175 + if (gr_acl_handle_procpidmem(task))
49176 + rv = -EACCES;
49177 +
49178 + put_task_struct(task);
49179 +
49180 return rv;
49181 }
49182
49183 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49184 if (!task)
49185 goto out_no_task;
49186
49187 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49188 + goto out;
49189 +
49190 /*
49191 * Yes, it does not scale. And it should not. Don't add
49192 * new entries into /proc/<tgid>/ without very good reasons.
49193 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49194 if (!task)
49195 goto out_no_task;
49196
49197 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49198 + goto out;
49199 +
49200 ret = 0;
49201 i = filp->f_pos;
49202 switch (i) {
49203 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49204 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49205 void *cookie)
49206 {
49207 - char *s = nd_get_link(nd);
49208 + const char *s = nd_get_link(nd);
49209 if (!IS_ERR(s))
49210 __putname(s);
49211 }
49212 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49213 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49214 #endif
49215 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49216 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49217 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49218 INF("syscall", S_IRUGO, proc_pid_syscall),
49219 #endif
49220 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49221 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49222 #ifdef CONFIG_SECURITY
49223 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49224 #endif
49225 -#ifdef CONFIG_KALLSYMS
49226 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49227 INF("wchan", S_IRUGO, proc_pid_wchan),
49228 #endif
49229 -#ifdef CONFIG_STACKTRACE
49230 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49231 ONE("stack", S_IRUGO, proc_pid_stack),
49232 #endif
49233 #ifdef CONFIG_SCHEDSTATS
49234 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49235 #ifdef CONFIG_HARDWALL
49236 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49237 #endif
49238 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49239 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49240 +#endif
49241 #ifdef CONFIG_USER_NS
49242 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49243 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49244 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49245 if (!inode)
49246 goto out;
49247
49248 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49249 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49250 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49251 + inode->i_gid = grsec_proc_gid;
49252 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49253 +#else
49254 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49255 +#endif
49256 inode->i_op = &proc_tgid_base_inode_operations;
49257 inode->i_fop = &proc_tgid_base_operations;
49258 inode->i_flags|=S_IMMUTABLE;
49259 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49260 if (!task)
49261 goto out;
49262
49263 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49264 + goto out_put_task;
49265 +
49266 result = proc_pid_instantiate(dir, dentry, task, NULL);
49267 +out_put_task:
49268 put_task_struct(task);
49269 out:
49270 return result;
49271 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49272 static int fake_filldir(void *buf, const char *name, int namelen,
49273 loff_t offset, u64 ino, unsigned d_type)
49274 {
49275 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49276 + __buf->error = -EINVAL;
49277 return 0;
49278 }
49279
49280 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49281 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49282 #endif
49283 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49284 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49285 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49286 INF("syscall", S_IRUGO, proc_pid_syscall),
49287 #endif
49288 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49289 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49290 #ifdef CONFIG_SECURITY
49291 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49292 #endif
49293 -#ifdef CONFIG_KALLSYMS
49294 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49295 INF("wchan", S_IRUGO, proc_pid_wchan),
49296 #endif
49297 -#ifdef CONFIG_STACKTRACE
49298 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49299 ONE("stack", S_IRUGO, proc_pid_stack),
49300 #endif
49301 #ifdef CONFIG_SCHEDSTATS
49302 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49303 index 82676e3..5f8518a 100644
49304 --- a/fs/proc/cmdline.c
49305 +++ b/fs/proc/cmdline.c
49306 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49307
49308 static int __init proc_cmdline_init(void)
49309 {
49310 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49311 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49312 +#else
49313 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49314 +#endif
49315 return 0;
49316 }
49317 module_init(proc_cmdline_init);
49318 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49319 index b143471..bb105e5 100644
49320 --- a/fs/proc/devices.c
49321 +++ b/fs/proc/devices.c
49322 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49323
49324 static int __init proc_devices_init(void)
49325 {
49326 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49327 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49328 +#else
49329 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49330 +#endif
49331 return 0;
49332 }
49333 module_init(proc_devices_init);
49334 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49335 index 7ac817b..c5c9eb0 100644
49336 --- a/fs/proc/inode.c
49337 +++ b/fs/proc/inode.c
49338 @@ -21,11 +21,17 @@
49339 #include <linux/seq_file.h>
49340 #include <linux/slab.h>
49341 #include <linux/mount.h>
49342 +#include <linux/grsecurity.h>
49343
49344 #include <asm/uaccess.h>
49345
49346 #include "internal.h"
49347
49348 +#ifdef CONFIG_PROC_SYSCTL
49349 +extern const struct inode_operations proc_sys_inode_operations;
49350 +extern const struct inode_operations proc_sys_dir_operations;
49351 +#endif
49352 +
49353 static void proc_evict_inode(struct inode *inode)
49354 {
49355 struct proc_dir_entry *de;
49356 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49357 ns_ops = PROC_I(inode)->ns_ops;
49358 if (ns_ops && ns_ops->put)
49359 ns_ops->put(PROC_I(inode)->ns);
49360 +
49361 +#ifdef CONFIG_PROC_SYSCTL
49362 + if (inode->i_op == &proc_sys_inode_operations ||
49363 + inode->i_op == &proc_sys_dir_operations)
49364 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49365 +#endif
49366 +
49367 }
49368
49369 static struct kmem_cache * proc_inode_cachep;
49370 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49371 if (de->mode) {
49372 inode->i_mode = de->mode;
49373 inode->i_uid = de->uid;
49374 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49375 + inode->i_gid = grsec_proc_gid;
49376 +#else
49377 inode->i_gid = de->gid;
49378 +#endif
49379 }
49380 if (de->size)
49381 inode->i_size = de->size;
49382 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49383 index e1167a1..bd24f20 100644
49384 --- a/fs/proc/internal.h
49385 +++ b/fs/proc/internal.h
49386 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49387 struct pid *pid, struct task_struct *task);
49388 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49389 struct pid *pid, struct task_struct *task);
49390 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49391 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49392 +#endif
49393 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49394
49395 extern const struct file_operations proc_tid_children_operations;
49396 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49397 index 86c67ee..cdca321 100644
49398 --- a/fs/proc/kcore.c
49399 +++ b/fs/proc/kcore.c
49400 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49401 * the addresses in the elf_phdr on our list.
49402 */
49403 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49404 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49405 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49406 + if (tsz > buflen)
49407 tsz = buflen;
49408 -
49409 +
49410 while (buflen) {
49411 struct kcore_list *m;
49412
49413 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49414 kfree(elf_buf);
49415 } else {
49416 if (kern_addr_valid(start)) {
49417 - unsigned long n;
49418 + char *elf_buf;
49419 + mm_segment_t oldfs;
49420
49421 - n = copy_to_user(buffer, (char *)start, tsz);
49422 - /*
49423 - * We cannot distinguish between fault on source
49424 - * and fault on destination. When this happens
49425 - * we clear too and hope it will trigger the
49426 - * EFAULT again.
49427 - */
49428 - if (n) {
49429 - if (clear_user(buffer + tsz - n,
49430 - n))
49431 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49432 + if (!elf_buf)
49433 + return -ENOMEM;
49434 + oldfs = get_fs();
49435 + set_fs(KERNEL_DS);
49436 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49437 + set_fs(oldfs);
49438 + if (copy_to_user(buffer, elf_buf, tsz)) {
49439 + kfree(elf_buf);
49440 return -EFAULT;
49441 + }
49442 }
49443 + set_fs(oldfs);
49444 + kfree(elf_buf);
49445 } else {
49446 if (clear_user(buffer, tsz))
49447 return -EFAULT;
49448 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49449
49450 static int open_kcore(struct inode *inode, struct file *filp)
49451 {
49452 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49453 + return -EPERM;
49454 +#endif
49455 if (!capable(CAP_SYS_RAWIO))
49456 return -EPERM;
49457 if (kcore_need_update)
49458 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49459 index 80e4645..53e5fcf 100644
49460 --- a/fs/proc/meminfo.c
49461 +++ b/fs/proc/meminfo.c
49462 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49463 vmi.used >> 10,
49464 vmi.largest_chunk >> 10
49465 #ifdef CONFIG_MEMORY_FAILURE
49466 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49467 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49468 #endif
49469 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49470 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49471 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49472 index b1822dd..df622cb 100644
49473 --- a/fs/proc/nommu.c
49474 +++ b/fs/proc/nommu.c
49475 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49476 if (len < 1)
49477 len = 1;
49478 seq_printf(m, "%*c", len, ' ');
49479 - seq_path(m, &file->f_path, "");
49480 + seq_path(m, &file->f_path, "\n\\");
49481 }
49482
49483 seq_putc(m, '\n');
49484 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49485 index fe72cd0..cb9b67d 100644
49486 --- a/fs/proc/proc_net.c
49487 +++ b/fs/proc/proc_net.c
49488 @@ -23,6 +23,7 @@
49489 #include <linux/nsproxy.h>
49490 #include <net/net_namespace.h>
49491 #include <linux/seq_file.h>
49492 +#include <linux/grsecurity.h>
49493
49494 #include "internal.h"
49495
49496 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49497 struct task_struct *task;
49498 struct nsproxy *ns;
49499 struct net *net = NULL;
49500 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49501 + const struct cred *cred = current_cred();
49502 +#endif
49503 +
49504 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49505 + if (cred->fsuid)
49506 + return net;
49507 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49508 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49509 + return net;
49510 +#endif
49511
49512 rcu_read_lock();
49513 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49514 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49515 index eb7cc91..7327a46 100644
49516 --- a/fs/proc/proc_sysctl.c
49517 +++ b/fs/proc/proc_sysctl.c
49518 @@ -12,11 +12,15 @@
49519 #include <linux/module.h>
49520 #include "internal.h"
49521
49522 +extern int gr_handle_chroot_sysctl(const int op);
49523 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49524 + const int op);
49525 +
49526 static const struct dentry_operations proc_sys_dentry_operations;
49527 static const struct file_operations proc_sys_file_operations;
49528 -static const struct inode_operations proc_sys_inode_operations;
49529 +const struct inode_operations proc_sys_inode_operations;
49530 static const struct file_operations proc_sys_dir_file_operations;
49531 -static const struct inode_operations proc_sys_dir_operations;
49532 +const struct inode_operations proc_sys_dir_operations;
49533
49534 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49535 {
49536 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49537
49538 err = NULL;
49539 d_set_d_op(dentry, &proc_sys_dentry_operations);
49540 +
49541 + gr_handle_proc_create(dentry, inode);
49542 +
49543 d_add(dentry, inode);
49544
49545 out:
49546 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49547 struct inode *inode = filp->f_path.dentry->d_inode;
49548 struct ctl_table_header *head = grab_header(inode);
49549 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49550 + int op = write ? MAY_WRITE : MAY_READ;
49551 ssize_t error;
49552 size_t res;
49553
49554 if (IS_ERR(head))
49555 return PTR_ERR(head);
49556
49557 +
49558 /*
49559 * At this point we know that the sysctl was not unregistered
49560 * and won't be until we finish.
49561 */
49562 error = -EPERM;
49563 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49564 + if (sysctl_perm(head->root, table, op))
49565 goto out;
49566
49567 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49568 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49569 if (!table->proc_handler)
49570 goto out;
49571
49572 +#ifdef CONFIG_GRKERNSEC
49573 + error = -EPERM;
49574 + if (gr_handle_chroot_sysctl(op))
49575 + goto out;
49576 + dget(filp->f_path.dentry);
49577 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49578 + dput(filp->f_path.dentry);
49579 + goto out;
49580 + }
49581 + dput(filp->f_path.dentry);
49582 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49583 + goto out;
49584 + if (write && !capable(CAP_SYS_ADMIN))
49585 + goto out;
49586 +#endif
49587 +
49588 /* careful: calling conventions are nasty here */
49589 res = count;
49590 error = table->proc_handler(table, write, buf, &res, ppos);
49591 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49592 return -ENOMEM;
49593 } else {
49594 d_set_d_op(child, &proc_sys_dentry_operations);
49595 +
49596 + gr_handle_proc_create(child, inode);
49597 +
49598 d_add(child, inode);
49599 }
49600 } else {
49601 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49602 if ((*pos)++ < file->f_pos)
49603 return 0;
49604
49605 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49606 + return 0;
49607 +
49608 if (unlikely(S_ISLNK(table->mode)))
49609 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49610 else
49611 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49612 if (IS_ERR(head))
49613 return PTR_ERR(head);
49614
49615 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49616 + return -ENOENT;
49617 +
49618 generic_fillattr(inode, stat);
49619 if (table)
49620 stat->mode = (stat->mode & S_IFMT) | table->mode;
49621 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49622 .llseek = generic_file_llseek,
49623 };
49624
49625 -static const struct inode_operations proc_sys_inode_operations = {
49626 +const struct inode_operations proc_sys_inode_operations = {
49627 .permission = proc_sys_permission,
49628 .setattr = proc_sys_setattr,
49629 .getattr = proc_sys_getattr,
49630 };
49631
49632 -static const struct inode_operations proc_sys_dir_operations = {
49633 +const struct inode_operations proc_sys_dir_operations = {
49634 .lookup = proc_sys_lookup,
49635 .permission = proc_sys_permission,
49636 .setattr = proc_sys_setattr,
49637 diff --git a/fs/proc/root.c b/fs/proc/root.c
49638 index 9a2d9fd..ddfc92a 100644
49639 --- a/fs/proc/root.c
49640 +++ b/fs/proc/root.c
49641 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49642 #ifdef CONFIG_PROC_DEVICETREE
49643 proc_device_tree_init();
49644 #endif
49645 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49646 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49647 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49648 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49649 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49650 +#endif
49651 +#else
49652 proc_mkdir("bus", NULL);
49653 +#endif
49654 proc_sys_init();
49655 }
49656
49657 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49658 index 4540b8f..1b9772f 100644
49659 --- a/fs/proc/task_mmu.c
49660 +++ b/fs/proc/task_mmu.c
49661 @@ -11,12 +11,19 @@
49662 #include <linux/rmap.h>
49663 #include <linux/swap.h>
49664 #include <linux/swapops.h>
49665 +#include <linux/grsecurity.h>
49666
49667 #include <asm/elf.h>
49668 #include <asm/uaccess.h>
49669 #include <asm/tlbflush.h>
49670 #include "internal.h"
49671
49672 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49673 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49674 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49675 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49676 +#endif
49677 +
49678 void task_mem(struct seq_file *m, struct mm_struct *mm)
49679 {
49680 unsigned long data, text, lib, swap;
49681 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49682 "VmExe:\t%8lu kB\n"
49683 "VmLib:\t%8lu kB\n"
49684 "VmPTE:\t%8lu kB\n"
49685 - "VmSwap:\t%8lu kB\n",
49686 - hiwater_vm << (PAGE_SHIFT-10),
49687 + "VmSwap:\t%8lu kB\n"
49688 +
49689 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49690 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49691 +#endif
49692 +
49693 + ,hiwater_vm << (PAGE_SHIFT-10),
49694 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49695 mm->locked_vm << (PAGE_SHIFT-10),
49696 mm->pinned_vm << (PAGE_SHIFT-10),
49697 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49698 data << (PAGE_SHIFT-10),
49699 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49700 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49701 - swap << (PAGE_SHIFT-10));
49702 + swap << (PAGE_SHIFT-10)
49703 +
49704 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49705 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49706 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49707 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49708 +#else
49709 + , mm->context.user_cs_base
49710 + , mm->context.user_cs_limit
49711 +#endif
49712 +#endif
49713 +
49714 + );
49715 }
49716
49717 unsigned long task_vsize(struct mm_struct *mm)
49718 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49719 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49720 }
49721
49722 - /* We don't show the stack guard page in /proc/maps */
49723 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49724 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49725 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49726 +#else
49727 start = vma->vm_start;
49728 - if (stack_guard_page_start(vma, start))
49729 - start += PAGE_SIZE;
49730 end = vma->vm_end;
49731 - if (stack_guard_page_end(vma, end))
49732 - end -= PAGE_SIZE;
49733 +#endif
49734
49735 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49736 start,
49737 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49738 flags & VM_WRITE ? 'w' : '-',
49739 flags & VM_EXEC ? 'x' : '-',
49740 flags & VM_MAYSHARE ? 's' : 'p',
49741 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49742 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49743 +#else
49744 pgoff,
49745 +#endif
49746 MAJOR(dev), MINOR(dev), ino, &len);
49747
49748 /*
49749 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49750 */
49751 if (file) {
49752 pad_len_spaces(m, len);
49753 - seq_path(m, &file->f_path, "\n");
49754 + seq_path(m, &file->f_path, "\n\\");
49755 goto done;
49756 }
49757
49758 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49759 * Thread stack in /proc/PID/task/TID/maps or
49760 * the main process stack.
49761 */
49762 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49763 - vma->vm_end >= mm->start_stack)) {
49764 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49765 + (vma->vm_start <= mm->start_stack &&
49766 + vma->vm_end >= mm->start_stack)) {
49767 name = "[stack]";
49768 } else {
49769 /* Thread stack in /proc/PID/maps */
49770 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49771 struct proc_maps_private *priv = m->private;
49772 struct task_struct *task = priv->task;
49773
49774 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49775 + if (current->exec_id != m->exec_id) {
49776 + gr_log_badprocpid("maps");
49777 + return 0;
49778 + }
49779 +#endif
49780 +
49781 show_map_vma(m, vma, is_pid);
49782
49783 if (m->count < m->size) /* vma is copied successfully */
49784 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49785 .private = &mss,
49786 };
49787
49788 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49789 + if (current->exec_id != m->exec_id) {
49790 + gr_log_badprocpid("smaps");
49791 + return 0;
49792 + }
49793 +#endif
49794 memset(&mss, 0, sizeof mss);
49795 - mss.vma = vma;
49796 - /* mmap_sem is held in m_start */
49797 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49798 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49799 -
49800 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49801 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49802 +#endif
49803 + mss.vma = vma;
49804 + /* mmap_sem is held in m_start */
49805 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49806 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49807 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49808 + }
49809 +#endif
49810 show_map_vma(m, vma, is_pid);
49811
49812 seq_printf(m,
49813 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49814 "KernelPageSize: %8lu kB\n"
49815 "MMUPageSize: %8lu kB\n"
49816 "Locked: %8lu kB\n",
49817 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49818 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49819 +#else
49820 (vma->vm_end - vma->vm_start) >> 10,
49821 +#endif
49822 mss.resident >> 10,
49823 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49824 mss.shared_clean >> 10,
49825 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49826 int n;
49827 char buffer[50];
49828
49829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49830 + if (current->exec_id != m->exec_id) {
49831 + gr_log_badprocpid("numa_maps");
49832 + return 0;
49833 + }
49834 +#endif
49835 +
49836 if (!mm)
49837 return 0;
49838
49839 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49840 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49841 mpol_cond_put(pol);
49842
49843 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49844 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49845 +#else
49846 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49847 +#endif
49848
49849 if (file) {
49850 seq_printf(m, " file=");
49851 - seq_path(m, &file->f_path, "\n\t= ");
49852 + seq_path(m, &file->f_path, "\n\t\\= ");
49853 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49854 seq_printf(m, " heap");
49855 } else {
49856 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49857 index 1ccfa53..0848f95 100644
49858 --- a/fs/proc/task_nommu.c
49859 +++ b/fs/proc/task_nommu.c
49860 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49861 else
49862 bytes += kobjsize(mm);
49863
49864 - if (current->fs && current->fs->users > 1)
49865 + if (current->fs && atomic_read(&current->fs->users) > 1)
49866 sbytes += kobjsize(current->fs);
49867 else
49868 bytes += kobjsize(current->fs);
49869 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49870
49871 if (file) {
49872 pad_len_spaces(m, len);
49873 - seq_path(m, &file->f_path, "");
49874 + seq_path(m, &file->f_path, "\n\\");
49875 } else if (mm) {
49876 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49877
49878 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49879 index d67908b..d13f6a6 100644
49880 --- a/fs/quota/netlink.c
49881 +++ b/fs/quota/netlink.c
49882 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49883 void quota_send_warning(short type, unsigned int id, dev_t dev,
49884 const char warntype)
49885 {
49886 - static atomic_t seq;
49887 + static atomic_unchecked_t seq;
49888 struct sk_buff *skb;
49889 void *msg_head;
49890 int ret;
49891 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49892 "VFS: Not enough memory to send quota warning.\n");
49893 return;
49894 }
49895 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49896 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49897 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49898 if (!msg_head) {
49899 printk(KERN_ERR
49900 diff --git a/fs/readdir.c b/fs/readdir.c
49901 index 39e3370..20d446d 100644
49902 --- a/fs/readdir.c
49903 +++ b/fs/readdir.c
49904 @@ -17,6 +17,7 @@
49905 #include <linux/security.h>
49906 #include <linux/syscalls.h>
49907 #include <linux/unistd.h>
49908 +#include <linux/namei.h>
49909
49910 #include <asm/uaccess.h>
49911
49912 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49913
49914 struct readdir_callback {
49915 struct old_linux_dirent __user * dirent;
49916 + struct file * file;
49917 int result;
49918 };
49919
49920 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49921 buf->result = -EOVERFLOW;
49922 return -EOVERFLOW;
49923 }
49924 +
49925 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49926 + return 0;
49927 +
49928 buf->result++;
49929 dirent = buf->dirent;
49930 if (!access_ok(VERIFY_WRITE, dirent,
49931 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49932
49933 buf.result = 0;
49934 buf.dirent = dirent;
49935 + buf.file = file;
49936
49937 error = vfs_readdir(file, fillonedir, &buf);
49938 if (buf.result)
49939 @@ -141,6 +148,7 @@ struct linux_dirent {
49940 struct getdents_callback {
49941 struct linux_dirent __user * current_dir;
49942 struct linux_dirent __user * previous;
49943 + struct file * file;
49944 int count;
49945 int error;
49946 };
49947 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49948 buf->error = -EOVERFLOW;
49949 return -EOVERFLOW;
49950 }
49951 +
49952 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49953 + return 0;
49954 +
49955 dirent = buf->previous;
49956 if (dirent) {
49957 if (__put_user(offset, &dirent->d_off))
49958 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49959 buf.previous = NULL;
49960 buf.count = count;
49961 buf.error = 0;
49962 + buf.file = file;
49963
49964 error = vfs_readdir(file, filldir, &buf);
49965 if (error >= 0)
49966 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49967 struct getdents_callback64 {
49968 struct linux_dirent64 __user * current_dir;
49969 struct linux_dirent64 __user * previous;
49970 + struct file *file;
49971 int count;
49972 int error;
49973 };
49974 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49975 buf->error = -EINVAL; /* only used if we fail.. */
49976 if (reclen > buf->count)
49977 return -EINVAL;
49978 +
49979 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49980 + return 0;
49981 +
49982 dirent = buf->previous;
49983 if (dirent) {
49984 if (__put_user(offset, &dirent->d_off))
49985 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49986
49987 buf.current_dir = dirent;
49988 buf.previous = NULL;
49989 + buf.file = file;
49990 buf.count = count;
49991 buf.error = 0;
49992
49993 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49994 error = buf.error;
49995 lastdirent = buf.previous;
49996 if (lastdirent) {
49997 - typeof(lastdirent->d_off) d_off = file->f_pos;
49998 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49999 if (__put_user(d_off, &lastdirent->d_off))
50000 error = -EFAULT;
50001 else
50002 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50003 index 2b7882b..1c5ef48 100644
50004 --- a/fs/reiserfs/do_balan.c
50005 +++ b/fs/reiserfs/do_balan.c
50006 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50007 return;
50008 }
50009
50010 - atomic_inc(&(fs_generation(tb->tb_sb)));
50011 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50012 do_balance_starts(tb);
50013
50014 /* balance leaf returns 0 except if combining L R and S into
50015 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50016 index e60e870..f40ac16 100644
50017 --- a/fs/reiserfs/procfs.c
50018 +++ b/fs/reiserfs/procfs.c
50019 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50020 "SMALL_TAILS " : "NO_TAILS ",
50021 replay_only(sb) ? "REPLAY_ONLY " : "",
50022 convert_reiserfs(sb) ? "CONV " : "",
50023 - atomic_read(&r->s_generation_counter),
50024 + atomic_read_unchecked(&r->s_generation_counter),
50025 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50026 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50027 SF(s_good_search_by_key_reada), SF(s_bmaps),
50028 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50029 index 33215f5..c5d427a 100644
50030 --- a/fs/reiserfs/reiserfs.h
50031 +++ b/fs/reiserfs/reiserfs.h
50032 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50033 /* Comment? -Hans */
50034 wait_queue_head_t s_wait;
50035 /* To be obsoleted soon by per buffer seals.. -Hans */
50036 - atomic_t s_generation_counter; // increased by one every time the
50037 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50038 // tree gets re-balanced
50039 unsigned long s_properties; /* File system properties. Currently holds
50040 on-disk FS format */
50041 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50042 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50043
50044 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50045 -#define get_generation(s) atomic_read (&fs_generation(s))
50046 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50047 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50048 #define __fs_changed(gen,s) (gen != get_generation (s))
50049 #define fs_changed(gen,s) \
50050 diff --git a/fs/select.c b/fs/select.c
50051 index db14c78..3aae1bd 100644
50052 --- a/fs/select.c
50053 +++ b/fs/select.c
50054 @@ -20,6 +20,7 @@
50055 #include <linux/export.h>
50056 #include <linux/slab.h>
50057 #include <linux/poll.h>
50058 +#include <linux/security.h>
50059 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50060 #include <linux/file.h>
50061 #include <linux/fdtable.h>
50062 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50063 struct poll_list *walk = head;
50064 unsigned long todo = nfds;
50065
50066 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50067 if (nfds > rlimit(RLIMIT_NOFILE))
50068 return -EINVAL;
50069
50070 diff --git a/fs/seq_file.c b/fs/seq_file.c
50071 index 14cf9de..adc4d5b 100644
50072 --- a/fs/seq_file.c
50073 +++ b/fs/seq_file.c
50074 @@ -9,6 +9,7 @@
50075 #include <linux/export.h>
50076 #include <linux/seq_file.h>
50077 #include <linux/slab.h>
50078 +#include <linux/sched.h>
50079
50080 #include <asm/uaccess.h>
50081 #include <asm/page.h>
50082 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50083 memset(p, 0, sizeof(*p));
50084 mutex_init(&p->lock);
50085 p->op = op;
50086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50087 + p->exec_id = current->exec_id;
50088 +#endif
50089
50090 /*
50091 * Wrappers around seq_open(e.g. swaps_open) need to be
50092 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50093 return 0;
50094 }
50095 if (!m->buf) {
50096 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50097 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50098 if (!m->buf)
50099 return -ENOMEM;
50100 }
50101 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50102 Eoverflow:
50103 m->op->stop(m, p);
50104 kfree(m->buf);
50105 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50106 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50107 return !m->buf ? -ENOMEM : -EAGAIN;
50108 }
50109
50110 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50111
50112 /* grab buffer if we didn't have one */
50113 if (!m->buf) {
50114 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50115 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50116 if (!m->buf)
50117 goto Enomem;
50118 }
50119 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50120 goto Fill;
50121 m->op->stop(m, p);
50122 kfree(m->buf);
50123 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50124 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50125 if (!m->buf)
50126 goto Enomem;
50127 m->count = 0;
50128 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50129 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50130 void *data)
50131 {
50132 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50133 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50134 int res = -ENOMEM;
50135
50136 if (op) {
50137 diff --git a/fs/splice.c b/fs/splice.c
50138 index 41514dd..6564a93 100644
50139 --- a/fs/splice.c
50140 +++ b/fs/splice.c
50141 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50142 pipe_lock(pipe);
50143
50144 for (;;) {
50145 - if (!pipe->readers) {
50146 + if (!atomic_read(&pipe->readers)) {
50147 send_sig(SIGPIPE, current, 0);
50148 if (!ret)
50149 ret = -EPIPE;
50150 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50151 do_wakeup = 0;
50152 }
50153
50154 - pipe->waiting_writers++;
50155 + atomic_inc(&pipe->waiting_writers);
50156 pipe_wait(pipe);
50157 - pipe->waiting_writers--;
50158 + atomic_dec(&pipe->waiting_writers);
50159 }
50160
50161 pipe_unlock(pipe);
50162 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50163 old_fs = get_fs();
50164 set_fs(get_ds());
50165 /* The cast to a user pointer is valid due to the set_fs() */
50166 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50167 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50168 set_fs(old_fs);
50169
50170 return res;
50171 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50172 old_fs = get_fs();
50173 set_fs(get_ds());
50174 /* The cast to a user pointer is valid due to the set_fs() */
50175 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50176 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50177 set_fs(old_fs);
50178
50179 return res;
50180 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50181 goto err;
50182
50183 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50184 - vec[i].iov_base = (void __user *) page_address(page);
50185 + vec[i].iov_base = (void __force_user *) page_address(page);
50186 vec[i].iov_len = this_len;
50187 spd.pages[i] = page;
50188 spd.nr_pages++;
50189 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50190 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50191 {
50192 while (!pipe->nrbufs) {
50193 - if (!pipe->writers)
50194 + if (!atomic_read(&pipe->writers))
50195 return 0;
50196
50197 - if (!pipe->waiting_writers && sd->num_spliced)
50198 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50199 return 0;
50200
50201 if (sd->flags & SPLICE_F_NONBLOCK)
50202 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50203 * out of the pipe right after the splice_to_pipe(). So set
50204 * PIPE_READERS appropriately.
50205 */
50206 - pipe->readers = 1;
50207 + atomic_set(&pipe->readers, 1);
50208
50209 current->splice_pipe = pipe;
50210 }
50211 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50212 ret = -ERESTARTSYS;
50213 break;
50214 }
50215 - if (!pipe->writers)
50216 + if (!atomic_read(&pipe->writers))
50217 break;
50218 - if (!pipe->waiting_writers) {
50219 + if (!atomic_read(&pipe->waiting_writers)) {
50220 if (flags & SPLICE_F_NONBLOCK) {
50221 ret = -EAGAIN;
50222 break;
50223 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50224 pipe_lock(pipe);
50225
50226 while (pipe->nrbufs >= pipe->buffers) {
50227 - if (!pipe->readers) {
50228 + if (!atomic_read(&pipe->readers)) {
50229 send_sig(SIGPIPE, current, 0);
50230 ret = -EPIPE;
50231 break;
50232 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50233 ret = -ERESTARTSYS;
50234 break;
50235 }
50236 - pipe->waiting_writers++;
50237 + atomic_inc(&pipe->waiting_writers);
50238 pipe_wait(pipe);
50239 - pipe->waiting_writers--;
50240 + atomic_dec(&pipe->waiting_writers);
50241 }
50242
50243 pipe_unlock(pipe);
50244 @@ -1828,14 +1828,14 @@ retry:
50245 pipe_double_lock(ipipe, opipe);
50246
50247 do {
50248 - if (!opipe->readers) {
50249 + if (!atomic_read(&opipe->readers)) {
50250 send_sig(SIGPIPE, current, 0);
50251 if (!ret)
50252 ret = -EPIPE;
50253 break;
50254 }
50255
50256 - if (!ipipe->nrbufs && !ipipe->writers)
50257 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50258 break;
50259
50260 /*
50261 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50262 pipe_double_lock(ipipe, opipe);
50263
50264 do {
50265 - if (!opipe->readers) {
50266 + if (!atomic_read(&opipe->readers)) {
50267 send_sig(SIGPIPE, current, 0);
50268 if (!ret)
50269 ret = -EPIPE;
50270 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50271 * return EAGAIN if we have the potential of some data in the
50272 * future, otherwise just return 0
50273 */
50274 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50275 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50276 ret = -EAGAIN;
50277
50278 pipe_unlock(ipipe);
50279 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50280 index 6b0bb00..75db2fe 100644
50281 --- a/fs/sysfs/dir.c
50282 +++ b/fs/sysfs/dir.c
50283 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50284 struct sysfs_dirent *sd;
50285 int rc;
50286
50287 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50288 + const char *parent_name = parent_sd->s_name;
50289 +
50290 + mode = S_IFDIR | S_IRWXU;
50291 +
50292 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50293 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50294 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50295 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50296 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50297 +#endif
50298 +
50299 /* allocate */
50300 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50301 if (!sd)
50302 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50303 index 00012e3..8392349 100644
50304 --- a/fs/sysfs/file.c
50305 +++ b/fs/sysfs/file.c
50306 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50307
50308 struct sysfs_open_dirent {
50309 atomic_t refcnt;
50310 - atomic_t event;
50311 + atomic_unchecked_t event;
50312 wait_queue_head_t poll;
50313 struct list_head buffers; /* goes through sysfs_buffer.list */
50314 };
50315 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50316 if (!sysfs_get_active(attr_sd))
50317 return -ENODEV;
50318
50319 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50320 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50321 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50322
50323 sysfs_put_active(attr_sd);
50324 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50325 return -ENOMEM;
50326
50327 atomic_set(&new_od->refcnt, 0);
50328 - atomic_set(&new_od->event, 1);
50329 + atomic_set_unchecked(&new_od->event, 1);
50330 init_waitqueue_head(&new_od->poll);
50331 INIT_LIST_HEAD(&new_od->buffers);
50332 goto retry;
50333 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50334
50335 sysfs_put_active(attr_sd);
50336
50337 - if (buffer->event != atomic_read(&od->event))
50338 + if (buffer->event != atomic_read_unchecked(&od->event))
50339 goto trigger;
50340
50341 return DEFAULT_POLLMASK;
50342 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50343
50344 od = sd->s_attr.open;
50345 if (od) {
50346 - atomic_inc(&od->event);
50347 + atomic_inc_unchecked(&od->event);
50348 wake_up_interruptible(&od->poll);
50349 }
50350
50351 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50352 index a7ac78f..02158e1 100644
50353 --- a/fs/sysfs/symlink.c
50354 +++ b/fs/sysfs/symlink.c
50355 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50356
50357 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50358 {
50359 - char *page = nd_get_link(nd);
50360 + const char *page = nd_get_link(nd);
50361 if (!IS_ERR(page))
50362 free_page((unsigned long)page);
50363 }
50364 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50365 index c175b4d..8f36a16 100644
50366 --- a/fs/udf/misc.c
50367 +++ b/fs/udf/misc.c
50368 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50369
50370 u8 udf_tag_checksum(const struct tag *t)
50371 {
50372 - u8 *data = (u8 *)t;
50373 + const u8 *data = (const u8 *)t;
50374 u8 checksum = 0;
50375 int i;
50376 for (i = 0; i < sizeof(struct tag); ++i)
50377 diff --git a/fs/utimes.c b/fs/utimes.c
50378 index fa4dbe4..e12d1b9 100644
50379 --- a/fs/utimes.c
50380 +++ b/fs/utimes.c
50381 @@ -1,6 +1,7 @@
50382 #include <linux/compiler.h>
50383 #include <linux/file.h>
50384 #include <linux/fs.h>
50385 +#include <linux/security.h>
50386 #include <linux/linkage.h>
50387 #include <linux/mount.h>
50388 #include <linux/namei.h>
50389 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50390 goto mnt_drop_write_and_out;
50391 }
50392 }
50393 +
50394 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50395 + error = -EACCES;
50396 + goto mnt_drop_write_and_out;
50397 + }
50398 +
50399 mutex_lock(&inode->i_mutex);
50400 error = notify_change(path->dentry, &newattrs);
50401 mutex_unlock(&inode->i_mutex);
50402 diff --git a/fs/xattr.c b/fs/xattr.c
50403 index 4d45b71..2ec08e10 100644
50404 --- a/fs/xattr.c
50405 +++ b/fs/xattr.c
50406 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50407 * Extended attribute SET operations
50408 */
50409 static long
50410 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50411 +setxattr(struct path *path, const char __user *name, const void __user *value,
50412 size_t size, int flags)
50413 {
50414 int error;
50415 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50416 }
50417 }
50418
50419 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50420 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50421 + error = -EACCES;
50422 + goto out;
50423 + }
50424 +
50425 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50426 out:
50427 if (vvalue)
50428 vfree(vvalue);
50429 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50430 return error;
50431 error = mnt_want_write(path.mnt);
50432 if (!error) {
50433 - error = setxattr(path.dentry, name, value, size, flags);
50434 + error = setxattr(&path, name, value, size, flags);
50435 mnt_drop_write(path.mnt);
50436 }
50437 path_put(&path);
50438 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50439 return error;
50440 error = mnt_want_write(path.mnt);
50441 if (!error) {
50442 - error = setxattr(path.dentry, name, value, size, flags);
50443 + error = setxattr(&path, name, value, size, flags);
50444 mnt_drop_write(path.mnt);
50445 }
50446 path_put(&path);
50447 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50448 {
50449 int fput_needed;
50450 struct file *f;
50451 - struct dentry *dentry;
50452 int error = -EBADF;
50453
50454 f = fget_light(fd, &fput_needed);
50455 if (!f)
50456 return error;
50457 - dentry = f->f_path.dentry;
50458 - audit_inode(NULL, dentry);
50459 + audit_inode(NULL, f->f_path.dentry);
50460 error = mnt_want_write_file(f);
50461 if (!error) {
50462 - error = setxattr(dentry, name, value, size, flags);
50463 + error = setxattr(&f->f_path, name, value, size, flags);
50464 mnt_drop_write_file(f);
50465 }
50466 fput_light(f, fput_needed);
50467 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50468 index 69d06b0..c0996e5 100644
50469 --- a/fs/xattr_acl.c
50470 +++ b/fs/xattr_acl.c
50471 @@ -17,8 +17,8 @@
50472 struct posix_acl *
50473 posix_acl_from_xattr(const void *value, size_t size)
50474 {
50475 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50476 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50477 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50478 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50479 int count;
50480 struct posix_acl *acl;
50481 struct posix_acl_entry *acl_e;
50482 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50483 index 848ffa7..1f249bf 100644
50484 --- a/fs/xfs/xfs_bmap.c
50485 +++ b/fs/xfs/xfs_bmap.c
50486 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50487 int nmap,
50488 int ret_nmap);
50489 #else
50490 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50491 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50492 #endif /* DEBUG */
50493
50494 STATIC int
50495 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50496 index 1b9fc3e..e1bdde0 100644
50497 --- a/fs/xfs/xfs_dir2_sf.c
50498 +++ b/fs/xfs/xfs_dir2_sf.c
50499 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50500 }
50501
50502 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50503 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50504 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50505 + char name[sfep->namelen];
50506 + memcpy(name, sfep->name, sfep->namelen);
50507 + if (filldir(dirent, name, sfep->namelen,
50508 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50509 + *offset = off & 0x7fffffff;
50510 + return 0;
50511 + }
50512 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50513 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50514 *offset = off & 0x7fffffff;
50515 return 0;
50516 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50517 index 0e0232c..fa5c3fe 100644
50518 --- a/fs/xfs/xfs_ioctl.c
50519 +++ b/fs/xfs/xfs_ioctl.c
50520 @@ -126,7 +126,7 @@ xfs_find_handle(
50521 }
50522
50523 error = -EFAULT;
50524 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50525 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50526 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50527 goto out_put;
50528
50529 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50530 index 4e00cf0..3374374 100644
50531 --- a/fs/xfs/xfs_iops.c
50532 +++ b/fs/xfs/xfs_iops.c
50533 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50534 struct nameidata *nd,
50535 void *p)
50536 {
50537 - char *s = nd_get_link(nd);
50538 + const char *s = nd_get_link(nd);
50539
50540 if (!IS_ERR(s))
50541 kfree(s);
50542 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50543 new file mode 100644
50544 index 0000000..d38b430
50545 --- /dev/null
50546 +++ b/grsecurity/Kconfig
50547 @@ -0,0 +1,947 @@
50548 +#
50549 +# grecurity configuration
50550 +#
50551 +menu "Memory Protections"
50552 +depends on GRKERNSEC
50553 +
50554 +config GRKERNSEC_KMEM
50555 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50556 + default y if GRKERNSEC_CONFIG_AUTO
50557 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50558 + help
50559 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50560 + be written to or read from to modify or leak the contents of the running
50561 + kernel. /dev/port will also not be allowed to be opened. If you have module
50562 + support disabled, enabling this will close up four ways that are
50563 + currently used to insert malicious code into the running kernel.
50564 + Even with all these features enabled, we still highly recommend that
50565 + you use the RBAC system, as it is still possible for an attacker to
50566 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50567 + If you are not using XFree86, you may be able to stop this additional
50568 + case by enabling the 'Disable privileged I/O' option. Though nothing
50569 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50570 + but only to video memory, which is the only writing we allow in this
50571 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50572 + not be allowed to mprotect it with PROT_WRITE later.
50573 + It is highly recommended that you say Y here if you meet all the
50574 + conditions above.
50575 +
50576 +config GRKERNSEC_VM86
50577 + bool "Restrict VM86 mode"
50578 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50579 + depends on X86_32
50580 +
50581 + help
50582 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50583 + make use of a special execution mode on 32bit x86 processors called
50584 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50585 + video cards and will still work with this option enabled. The purpose
50586 + of the option is to prevent exploitation of emulation errors in
50587 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50588 + Nearly all users should be able to enable this option.
50589 +
50590 +config GRKERNSEC_IO
50591 + bool "Disable privileged I/O"
50592 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50593 + depends on X86
50594 + select RTC_CLASS
50595 + select RTC_INTF_DEV
50596 + select RTC_DRV_CMOS
50597 +
50598 + help
50599 + If you say Y here, all ioperm and iopl calls will return an error.
50600 + Ioperm and iopl can be used to modify the running kernel.
50601 + Unfortunately, some programs need this access to operate properly,
50602 + the most notable of which are XFree86 and hwclock. hwclock can be
50603 + remedied by having RTC support in the kernel, so real-time
50604 + clock support is enabled if this option is enabled, to ensure
50605 + that hwclock operates correctly. XFree86 still will not
50606 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50607 + IF YOU USE XFree86. If you use XFree86 and you still want to
50608 + protect your kernel against modification, use the RBAC system.
50609 +
50610 +config GRKERNSEC_PROC_MEMMAP
50611 + bool "Harden ASLR against information leaks and entropy reduction"
50612 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50613 + depends on PAX_NOEXEC || PAX_ASLR
50614 + help
50615 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50616 + give no information about the addresses of its mappings if
50617 + PaX features that rely on random addresses are enabled on the task.
50618 + In addition to sanitizing this information and disabling other
50619 + dangerous sources of information, this option causes reads of sensitive
50620 + /proc/<pid> entries where the file descriptor was opened in a different
50621 + task than the one performing the read. Such attempts are logged.
50622 + This option also limits argv/env strings for suid/sgid binaries
50623 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50624 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50625 + binaries to prevent alternative mmap layouts from being abused.
50626 +
50627 + If you use PaX it is essential that you say Y here as it closes up
50628 + several holes that make full ASLR useless locally.
50629 +
50630 +config GRKERNSEC_BRUTE
50631 + bool "Deter exploit bruteforcing"
50632 + default y if GRKERNSEC_CONFIG_AUTO
50633 + help
50634 + If you say Y here, attempts to bruteforce exploits against forking
50635 + daemons such as apache or sshd, as well as against suid/sgid binaries
50636 + will be deterred. When a child of a forking daemon is killed by PaX
50637 + or crashes due to an illegal instruction or other suspicious signal,
50638 + the parent process will be delayed 30 seconds upon every subsequent
50639 + fork until the administrator is able to assess the situation and
50640 + restart the daemon.
50641 + In the suid/sgid case, the attempt is logged, the user has all their
50642 + processes terminated, and they are prevented from executing any further
50643 + processes for 15 minutes.
50644 + It is recommended that you also enable signal logging in the auditing
50645 + section so that logs are generated when a process triggers a suspicious
50646 + signal.
50647 + If the sysctl option is enabled, a sysctl option with name
50648 + "deter_bruteforce" is created.
50649 +
50650 +
50651 +config GRKERNSEC_MODHARDEN
50652 + bool "Harden module auto-loading"
50653 + default y if GRKERNSEC_CONFIG_AUTO
50654 + depends on MODULES
50655 + help
50656 + If you say Y here, module auto-loading in response to use of some
50657 + feature implemented by an unloaded module will be restricted to
50658 + root users. Enabling this option helps defend against attacks
50659 + by unprivileged users who abuse the auto-loading behavior to
50660 + cause a vulnerable module to load that is then exploited.
50661 +
50662 + If this option prevents a legitimate use of auto-loading for a
50663 + non-root user, the administrator can execute modprobe manually
50664 + with the exact name of the module mentioned in the alert log.
50665 + Alternatively, the administrator can add the module to the list
50666 + of modules loaded at boot by modifying init scripts.
50667 +
50668 + Modification of init scripts will most likely be needed on
50669 + Ubuntu servers with encrypted home directory support enabled,
50670 + as the first non-root user logging in will cause the ecb(aes),
50671 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50672 +
50673 +config GRKERNSEC_HIDESYM
50674 + bool "Hide kernel symbols"
50675 + default y if GRKERNSEC_CONFIG_AUTO
50676 + select PAX_USERCOPY_SLABS
50677 + help
50678 + If you say Y here, getting information on loaded modules, and
50679 + displaying all kernel symbols through a syscall will be restricted
50680 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50681 + /proc/kallsyms will be restricted to the root user. The RBAC
50682 + system can hide that entry even from root.
50683 +
50684 + This option also prevents leaking of kernel addresses through
50685 + several /proc entries.
50686 +
50687 + Note that this option is only effective provided the following
50688 + conditions are met:
50689 + 1) The kernel using grsecurity is not precompiled by some distribution
50690 + 2) You have also enabled GRKERNSEC_DMESG
50691 + 3) You are using the RBAC system and hiding other files such as your
50692 + kernel image and System.map. Alternatively, enabling this option
50693 + causes the permissions on /boot, /lib/modules, and the kernel
50694 + source directory to change at compile time to prevent
50695 + reading by non-root users.
50696 + If the above conditions are met, this option will aid in providing a
50697 + useful protection against local kernel exploitation of overflows
50698 + and arbitrary read/write vulnerabilities.
50699 +
50700 +config GRKERNSEC_KERN_LOCKOUT
50701 + bool "Active kernel exploit response"
50702 + default y if GRKERNSEC_CONFIG_AUTO
50703 + depends on X86 || ARM || PPC || SPARC
50704 + help
50705 + If you say Y here, when a PaX alert is triggered due to suspicious
50706 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50707 + or an OOPS occurs due to bad memory accesses, instead of just
50708 + terminating the offending process (and potentially allowing
50709 + a subsequent exploit from the same user), we will take one of two
50710 + actions:
50711 + If the user was root, we will panic the system
50712 + If the user was non-root, we will log the attempt, terminate
50713 + all processes owned by the user, then prevent them from creating
50714 + any new processes until the system is restarted
50715 + This deters repeated kernel exploitation/bruteforcing attempts
50716 + and is useful for later forensics.
50717 +
50718 +endmenu
50719 +menu "Role Based Access Control Options"
50720 +depends on GRKERNSEC
50721 +
50722 +config GRKERNSEC_RBAC_DEBUG
50723 + bool
50724 +
50725 +config GRKERNSEC_NO_RBAC
50726 + bool "Disable RBAC system"
50727 + help
50728 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50729 + preventing the RBAC system from being enabled. You should only say Y
50730 + here if you have no intention of using the RBAC system, so as to prevent
50731 + an attacker with root access from misusing the RBAC system to hide files
50732 + and processes when loadable module support and /dev/[k]mem have been
50733 + locked down.
50734 +
50735 +config GRKERNSEC_ACL_HIDEKERN
50736 + bool "Hide kernel processes"
50737 + help
50738 + If you say Y here, all kernel threads will be hidden to all
50739 + processes but those whose subject has the "view hidden processes"
50740 + flag.
50741 +
50742 +config GRKERNSEC_ACL_MAXTRIES
50743 + int "Maximum tries before password lockout"
50744 + default 3
50745 + help
50746 + This option enforces the maximum number of times a user can attempt
50747 + to authorize themselves with the grsecurity RBAC system before being
50748 + denied the ability to attempt authorization again for a specified time.
50749 + The lower the number, the harder it will be to brute-force a password.
50750 +
50751 +config GRKERNSEC_ACL_TIMEOUT
50752 + int "Time to wait after max password tries, in seconds"
50753 + default 30
50754 + help
50755 + This option specifies the time the user must wait after attempting to
50756 + authorize to the RBAC system with the maximum number of invalid
50757 + passwords. The higher the number, the harder it will be to brute-force
50758 + a password.
50759 +
50760 +endmenu
50761 +menu "Filesystem Protections"
50762 +depends on GRKERNSEC
50763 +
50764 +config GRKERNSEC_PROC
50765 + bool "Proc restrictions"
50766 + default y if GRKERNSEC_CONFIG_AUTO
50767 + help
50768 + If you say Y here, the permissions of the /proc filesystem
50769 + will be altered to enhance system security and privacy. You MUST
50770 + choose either a user only restriction or a user and group restriction.
50771 + Depending upon the option you choose, you can either restrict users to
50772 + see only the processes they themselves run, or choose a group that can
50773 + view all processes and files normally restricted to root if you choose
50774 + the "restrict to user only" option. NOTE: If you're running identd or
50775 + ntpd as a non-root user, you will have to run it as the group you
50776 + specify here.
50777 +
50778 +config GRKERNSEC_PROC_USER
50779 + bool "Restrict /proc to user only"
50780 + depends on GRKERNSEC_PROC
50781 + help
50782 + If you say Y here, non-root users will only be able to view their own
50783 + processes, and restricts them from viewing network-related information,
50784 + and viewing kernel symbol and module information.
50785 +
50786 +config GRKERNSEC_PROC_USERGROUP
50787 + bool "Allow special group"
50788 + default y if GRKERNSEC_CONFIG_AUTO
50789 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50790 + help
50791 + If you say Y here, you will be able to select a group that will be
50792 + able to view all processes and network-related information. If you've
50793 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50794 + remain hidden. This option is useful if you want to run identd as
50795 + a non-root user. The group you select may also be chosen at boot time
50796 + via "grsec_proc_gid=" on the kernel commandline.
50797 +
50798 +config GRKERNSEC_PROC_GID
50799 + int "GID for special group"
50800 + depends on GRKERNSEC_PROC_USERGROUP
50801 + default 1001
50802 +
50803 +config GRKERNSEC_PROC_ADD
50804 + bool "Additional restrictions"
50805 + default y if GRKERNSEC_CONFIG_AUTO
50806 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50807 + help
50808 + If you say Y here, additional restrictions will be placed on
50809 + /proc that keep normal users from viewing device information and
50810 + slabinfo information that could be useful for exploits.
50811 +
50812 +config GRKERNSEC_LINK
50813 + bool "Linking restrictions"
50814 + default y if GRKERNSEC_CONFIG_AUTO
50815 + help
50816 + If you say Y here, /tmp race exploits will be prevented, since users
50817 + will no longer be able to follow symlinks owned by other users in
50818 + world-writable +t directories (e.g. /tmp), unless the owner of the
50819 + symlink is the owner of the directory. users will also not be
50820 + able to hardlink to files they do not own. If the sysctl option is
50821 + enabled, a sysctl option with name "linking_restrictions" is created.
50822 +
50823 +config GRKERNSEC_SYMLINKOWN
50824 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50825 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50826 + help
50827 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50828 + that prevents it from being used as a security feature. As Apache
50829 + verifies the symlink by performing a stat() against the target of
50830 + the symlink before it is followed, an attacker can setup a symlink
50831 + to point to a same-owned file, then replace the symlink with one
50832 + that targets another user's file just after Apache "validates" the
50833 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50834 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50835 + will be in place for the group you specify. If the sysctl option
50836 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50837 + created.
50838 +
50839 +config GRKERNSEC_SYMLINKOWN_GID
50840 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50841 + depends on GRKERNSEC_SYMLINKOWN
50842 + default 1006
50843 + help
50844 + Setting this GID determines what group kernel-enforced
50845 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50846 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50847 +
50848 +config GRKERNSEC_FIFO
50849 + bool "FIFO restrictions"
50850 + default y if GRKERNSEC_CONFIG_AUTO
50851 + help
50852 + If you say Y here, users will not be able to write to FIFOs they don't
50853 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50854 + the FIFO is the same owner of the directory it's held in. If the sysctl
50855 + option is enabled, a sysctl option with name "fifo_restrictions" is
50856 + created.
50857 +
50858 +config GRKERNSEC_SYSFS_RESTRICT
50859 + bool "Sysfs/debugfs restriction"
50860 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50861 + depends on SYSFS
50862 + help
50863 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50864 + any filesystem normally mounted under it (e.g. debugfs) will be
50865 + mostly accessible only by root. These filesystems generally provide access
50866 + to hardware and debug information that isn't appropriate for unprivileged
50867 + users of the system. Sysfs and debugfs have also become a large source
50868 + of new vulnerabilities, ranging from infoleaks to local compromise.
50869 + There has been very little oversight with an eye toward security involved
50870 + in adding new exporters of information to these filesystems, so their
50871 + use is discouraged.
50872 + For reasons of compatibility, a few directories have been whitelisted
50873 + for access by non-root users:
50874 + /sys/fs/selinux
50875 + /sys/fs/fuse
50876 + /sys/devices/system/cpu
50877 +
50878 +config GRKERNSEC_ROFS
50879 + bool "Runtime read-only mount protection"
50880 + help
50881 + If you say Y here, a sysctl option with name "romount_protect" will
50882 + be created. By setting this option to 1 at runtime, filesystems
50883 + will be protected in the following ways:
50884 + * No new writable mounts will be allowed
50885 + * Existing read-only mounts won't be able to be remounted read/write
50886 + * Write operations will be denied on all block devices
50887 + This option acts independently of grsec_lock: once it is set to 1,
50888 + it cannot be turned off. Therefore, please be mindful of the resulting
50889 + behavior if this option is enabled in an init script on a read-only
50890 + filesystem. This feature is mainly intended for secure embedded systems.
50891 +
50892 +config GRKERNSEC_CHROOT
50893 + bool "Chroot jail restrictions"
50894 + default y if GRKERNSEC_CONFIG_AUTO
50895 + help
50896 + If you say Y here, you will be able to choose several options that will
50897 + make breaking out of a chrooted jail much more difficult. If you
50898 + encounter no software incompatibilities with the following options, it
50899 + is recommended that you enable each one.
50900 +
50901 +config GRKERNSEC_CHROOT_MOUNT
50902 + bool "Deny mounts"
50903 + default y if GRKERNSEC_CONFIG_AUTO
50904 + depends on GRKERNSEC_CHROOT
50905 + help
50906 + If you say Y here, processes inside a chroot will not be able to
50907 + mount or remount filesystems. If the sysctl option is enabled, a
50908 + sysctl option with name "chroot_deny_mount" is created.
50909 +
50910 +config GRKERNSEC_CHROOT_DOUBLE
50911 + bool "Deny double-chroots"
50912 + default y if GRKERNSEC_CONFIG_AUTO
50913 + depends on GRKERNSEC_CHROOT
50914 + help
50915 + If you say Y here, processes inside a chroot will not be able to chroot
50916 + again outside the chroot. This is a widely used method of breaking
50917 + out of a chroot jail and should not be allowed. If the sysctl
50918 + option is enabled, a sysctl option with name
50919 + "chroot_deny_chroot" is created.
50920 +
50921 +config GRKERNSEC_CHROOT_PIVOT
50922 + bool "Deny pivot_root in chroot"
50923 + default y if GRKERNSEC_CONFIG_AUTO
50924 + depends on GRKERNSEC_CHROOT
50925 + help
50926 + If you say Y here, processes inside a chroot will not be able to use
50927 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50928 + works similar to chroot in that it changes the root filesystem. This
50929 + function could be misused in a chrooted process to attempt to break out
50930 + of the chroot, and therefore should not be allowed. If the sysctl
50931 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50932 + created.
50933 +
50934 +config GRKERNSEC_CHROOT_CHDIR
50935 + bool "Enforce chdir(\"/\") on all chroots"
50936 + default y if GRKERNSEC_CONFIG_AUTO
50937 + depends on GRKERNSEC_CHROOT
50938 + help
50939 + If you say Y here, the current working directory of all newly-chrooted
50940 + applications will be set to the the root directory of the chroot.
50941 + The man page on chroot(2) states:
50942 + Note that this call does not change the current working
50943 + directory, so that `.' can be outside the tree rooted at
50944 + `/'. In particular, the super-user can escape from a
50945 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50946 +
50947 + It is recommended that you say Y here, since it's not known to break
50948 + any software. If the sysctl option is enabled, a sysctl option with
50949 + name "chroot_enforce_chdir" is created.
50950 +
50951 +config GRKERNSEC_CHROOT_CHMOD
50952 + bool "Deny (f)chmod +s"
50953 + default y if GRKERNSEC_CONFIG_AUTO
50954 + depends on GRKERNSEC_CHROOT
50955 + help
50956 + If you say Y here, processes inside a chroot will not be able to chmod
50957 + or fchmod files to make them have suid or sgid bits. This protects
50958 + against another published method of breaking a chroot. If the sysctl
50959 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50960 + created.
50961 +
50962 +config GRKERNSEC_CHROOT_FCHDIR
50963 + bool "Deny fchdir out of chroot"
50964 + default y if GRKERNSEC_CONFIG_AUTO
50965 + depends on GRKERNSEC_CHROOT
50966 + help
50967 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50968 + to a file descriptor of the chrooting process that points to a directory
50969 + outside the filesystem will be stopped. If the sysctl option
50970 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50971 +
50972 +config GRKERNSEC_CHROOT_MKNOD
50973 + bool "Deny mknod"
50974 + default y if GRKERNSEC_CONFIG_AUTO
50975 + depends on GRKERNSEC_CHROOT
50976 + help
50977 + If you say Y here, processes inside a chroot will not be allowed to
50978 + mknod. The problem with using mknod inside a chroot is that it
50979 + would allow an attacker to create a device entry that is the same
50980 + as one on the physical root of your system, which could range from
50981 + anything from the console device to a device for your harddrive (which
50982 + they could then use to wipe the drive or steal data). It is recommended
50983 + that you say Y here, unless you run into software incompatibilities.
50984 + If the sysctl option is enabled, a sysctl option with name
50985 + "chroot_deny_mknod" is created.
50986 +
50987 +config GRKERNSEC_CHROOT_SHMAT
50988 + bool "Deny shmat() out of chroot"
50989 + default y if GRKERNSEC_CONFIG_AUTO
50990 + depends on GRKERNSEC_CHROOT
50991 + help
50992 + If you say Y here, processes inside a chroot will not be able to attach
50993 + to shared memory segments that were created outside of the chroot jail.
50994 + It is recommended that you say Y here. If the sysctl option is enabled,
50995 + a sysctl option with name "chroot_deny_shmat" is created.
50996 +
50997 +config GRKERNSEC_CHROOT_UNIX
50998 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50999 + default y if GRKERNSEC_CONFIG_AUTO
51000 + depends on GRKERNSEC_CHROOT
51001 + help
51002 + If you say Y here, processes inside a chroot will not be able to
51003 + connect to abstract (meaning not belonging to a filesystem) Unix
51004 + domain sockets that were bound outside of a chroot. It is recommended
51005 + that you say Y here. If the sysctl option is enabled, a sysctl option
51006 + with name "chroot_deny_unix" is created.
51007 +
51008 +config GRKERNSEC_CHROOT_FINDTASK
51009 + bool "Protect outside processes"
51010 + default y if GRKERNSEC_CONFIG_AUTO
51011 + depends on GRKERNSEC_CHROOT
51012 + help
51013 + If you say Y here, processes inside a chroot will not be able to
51014 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51015 + getsid, or view any process outside of the chroot. If the sysctl
51016 + option is enabled, a sysctl option with name "chroot_findtask" is
51017 + created.
51018 +
51019 +config GRKERNSEC_CHROOT_NICE
51020 + bool "Restrict priority changes"
51021 + default y if GRKERNSEC_CONFIG_AUTO
51022 + depends on GRKERNSEC_CHROOT
51023 + help
51024 + If you say Y here, processes inside a chroot will not be able to raise
51025 + the priority of processes in the chroot, or alter the priority of
51026 + processes outside the chroot. This provides more security than simply
51027 + removing CAP_SYS_NICE from the process' capability set. If the
51028 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51029 + is created.
51030 +
51031 +config GRKERNSEC_CHROOT_SYSCTL
51032 + bool "Deny sysctl writes"
51033 + default y if GRKERNSEC_CONFIG_AUTO
51034 + depends on GRKERNSEC_CHROOT
51035 + help
51036 + If you say Y here, an attacker in a chroot will not be able to
51037 + write to sysctl entries, either by sysctl(2) or through a /proc
51038 + interface. It is strongly recommended that you say Y here. If the
51039 + sysctl option is enabled, a sysctl option with name
51040 + "chroot_deny_sysctl" is created.
51041 +
51042 +config GRKERNSEC_CHROOT_CAPS
51043 + bool "Capability restrictions"
51044 + default y if GRKERNSEC_CONFIG_AUTO
51045 + depends on GRKERNSEC_CHROOT
51046 + help
51047 + If you say Y here, the capabilities on all processes within a
51048 + chroot jail will be lowered to stop module insertion, raw i/o,
51049 + system and net admin tasks, rebooting the system, modifying immutable
51050 + files, modifying IPC owned by another, and changing the system time.
51051 + This is left an option because it can break some apps. Disable this
51052 + if your chrooted apps are having problems performing those kinds of
51053 + tasks. If the sysctl option is enabled, a sysctl option with
51054 + name "chroot_caps" is created.
51055 +
51056 +endmenu
51057 +menu "Kernel Auditing"
51058 +depends on GRKERNSEC
51059 +
51060 +config GRKERNSEC_AUDIT_GROUP
51061 + bool "Single group for auditing"
51062 + help
51063 + If you say Y here, the exec, chdir, and (un)mount logging features
51064 + will only operate on a group you specify. This option is recommended
51065 + if you only want to watch certain users instead of having a large
51066 + amount of logs from the entire system. If the sysctl option is enabled,
51067 + a sysctl option with name "audit_group" is created.
51068 +
51069 +config GRKERNSEC_AUDIT_GID
51070 + int "GID for auditing"
51071 + depends on GRKERNSEC_AUDIT_GROUP
51072 + default 1007
51073 +
51074 +config GRKERNSEC_EXECLOG
51075 + bool "Exec logging"
51076 + help
51077 + If you say Y here, all execve() calls will be logged (since the
51078 + other exec*() calls are frontends to execve(), all execution
51079 + will be logged). Useful for shell-servers that like to keep track
51080 + of their users. If the sysctl option is enabled, a sysctl option with
51081 + name "exec_logging" is created.
51082 + WARNING: This option when enabled will produce a LOT of logs, especially
51083 + on an active system.
51084 +
51085 +config GRKERNSEC_RESLOG
51086 + bool "Resource logging"
51087 + default y if GRKERNSEC_CONFIG_AUTO
51088 + help
51089 + If you say Y here, all attempts to overstep resource limits will
51090 + be logged with the resource name, the requested size, and the current
51091 + limit. It is highly recommended that you say Y here. If the sysctl
51092 + option is enabled, a sysctl option with name "resource_logging" is
51093 + created. If the RBAC system is enabled, the sysctl value is ignored.
51094 +
51095 +config GRKERNSEC_CHROOT_EXECLOG
51096 + bool "Log execs within chroot"
51097 + help
51098 + If you say Y here, all executions inside a chroot jail will be logged
51099 + to syslog. This can cause a large amount of logs if certain
51100 + applications (eg. djb's daemontools) are installed on the system, and
51101 + is therefore left as an option. If the sysctl option is enabled, a
51102 + sysctl option with name "chroot_execlog" is created.
51103 +
51104 +config GRKERNSEC_AUDIT_PTRACE
51105 + bool "Ptrace logging"
51106 + help
51107 + If you say Y here, all attempts to attach to a process via ptrace
51108 + will be logged. If the sysctl option is enabled, a sysctl option
51109 + with name "audit_ptrace" is created.
51110 +
51111 +config GRKERNSEC_AUDIT_CHDIR
51112 + bool "Chdir logging"
51113 + help
51114 + If you say Y here, all chdir() calls will be logged. If the sysctl
51115 + option is enabled, a sysctl option with name "audit_chdir" is created.
51116 +
51117 +config GRKERNSEC_AUDIT_MOUNT
51118 + bool "(Un)Mount logging"
51119 + help
51120 + If you say Y here, all mounts and unmounts will be logged. If the
51121 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51122 + created.
51123 +
51124 +config GRKERNSEC_SIGNAL
51125 + bool "Signal logging"
51126 + default y if GRKERNSEC_CONFIG_AUTO
51127 + help
51128 + If you say Y here, certain important signals will be logged, such as
51129 + SIGSEGV, which will as a result inform you of when a error in a program
51130 + occurred, which in some cases could mean a possible exploit attempt.
51131 + If the sysctl option is enabled, a sysctl option with name
51132 + "signal_logging" is created.
51133 +
51134 +config GRKERNSEC_FORKFAIL
51135 + bool "Fork failure logging"
51136 + help
51137 + If you say Y here, all failed fork() attempts will be logged.
51138 + This could suggest a fork bomb, or someone attempting to overstep
51139 + their process limit. If the sysctl option is enabled, a sysctl option
51140 + with name "forkfail_logging" is created.
51141 +
51142 +config GRKERNSEC_TIME
51143 + bool "Time change logging"
51144 + default y if GRKERNSEC_CONFIG_AUTO
51145 + help
51146 + If you say Y here, any changes of the system clock will be logged.
51147 + If the sysctl option is enabled, a sysctl option with name
51148 + "timechange_logging" is created.
51149 +
51150 +config GRKERNSEC_PROC_IPADDR
51151 + bool "/proc/<pid>/ipaddr support"
51152 + default y if GRKERNSEC_CONFIG_AUTO
51153 + help
51154 + If you say Y here, a new entry will be added to each /proc/<pid>
51155 + directory that contains the IP address of the person using the task.
51156 + The IP is carried across local TCP and AF_UNIX stream sockets.
51157 + This information can be useful for IDS/IPSes to perform remote response
51158 + to a local attack. The entry is readable by only the owner of the
51159 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51160 + the RBAC system), and thus does not create privacy concerns.
51161 +
51162 +config GRKERNSEC_RWXMAP_LOG
51163 + bool 'Denied RWX mmap/mprotect logging'
51164 + default y if GRKERNSEC_CONFIG_AUTO
51165 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51166 + help
51167 + If you say Y here, calls to mmap() and mprotect() with explicit
51168 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51169 + denied by the PAX_MPROTECT feature. If the sysctl option is
51170 + enabled, a sysctl option with name "rwxmap_logging" is created.
51171 +
51172 +config GRKERNSEC_AUDIT_TEXTREL
51173 + bool 'ELF text relocations logging (READ HELP)'
51174 + depends on PAX_MPROTECT
51175 + help
51176 + If you say Y here, text relocations will be logged with the filename
51177 + of the offending library or binary. The purpose of the feature is
51178 + to help Linux distribution developers get rid of libraries and
51179 + binaries that need text relocations which hinder the future progress
51180 + of PaX. Only Linux distribution developers should say Y here, and
51181 + never on a production machine, as this option creates an information
51182 + leak that could aid an attacker in defeating the randomization of
51183 + a single memory region. If the sysctl option is enabled, a sysctl
51184 + option with name "audit_textrel" is created.
51185 +
51186 +endmenu
51187 +
51188 +menu "Executable Protections"
51189 +depends on GRKERNSEC
51190 +
51191 +config GRKERNSEC_DMESG
51192 + bool "Dmesg(8) restriction"
51193 + default y if GRKERNSEC_CONFIG_AUTO
51194 + help
51195 + If you say Y here, non-root users will not be able to use dmesg(8)
51196 + to view up to the last 4kb of messages in the kernel's log buffer.
51197 + The kernel's log buffer often contains kernel addresses and other
51198 + identifying information useful to an attacker in fingerprinting a
51199 + system for a targeted exploit.
51200 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51201 + created.
51202 +
51203 +config GRKERNSEC_HARDEN_PTRACE
51204 + bool "Deter ptrace-based process snooping"
51205 + default y if GRKERNSEC_CONFIG_AUTO
51206 + help
51207 + If you say Y here, TTY sniffers and other malicious monitoring
51208 + programs implemented through ptrace will be defeated. If you
51209 + have been using the RBAC system, this option has already been
51210 + enabled for several years for all users, with the ability to make
51211 + fine-grained exceptions.
51212 +
51213 + This option only affects the ability of non-root users to ptrace
51214 + processes that are not a descendent of the ptracing process.
51215 + This means that strace ./binary and gdb ./binary will still work,
51216 + but attaching to arbitrary processes will not. If the sysctl
51217 + option is enabled, a sysctl option with name "harden_ptrace" is
51218 + created.
51219 +
51220 +config GRKERNSEC_PTRACE_READEXEC
51221 + bool "Require read access to ptrace sensitive binaries"
51222 + default y if GRKERNSEC_CONFIG_AUTO
51223 + help
51224 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51225 + binaries. This option is useful in environments that
51226 + remove the read bits (e.g. file mode 4711) from suid binaries to
51227 + prevent infoleaking of their contents. This option adds
51228 + consistency to the use of that file mode, as the binary could normally
51229 + be read out when run without privileges while ptracing.
51230 +
51231 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51232 + is created.
51233 +
51234 +config GRKERNSEC_SETXID
51235 + bool "Enforce consistent multithreaded privileges"
51236 + default y if GRKERNSEC_CONFIG_AUTO
51237 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51238 + help
51239 + If you say Y here, a change from a root uid to a non-root uid
51240 + in a multithreaded application will cause the resulting uids,
51241 + gids, supplementary groups, and capabilities in that thread
51242 + to be propagated to the other threads of the process. In most
51243 + cases this is unnecessary, as glibc will emulate this behavior
51244 + on behalf of the application. Other libcs do not act in the
51245 + same way, allowing the other threads of the process to continue
51246 + running with root privileges. If the sysctl option is enabled,
51247 + a sysctl option with name "consistent_setxid" is created.
51248 +
51249 +config GRKERNSEC_TPE
51250 + bool "Trusted Path Execution (TPE)"
51251 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51252 + help
51253 + If you say Y here, you will be able to choose a gid to add to the
51254 + supplementary groups of users you want to mark as "untrusted."
51255 + These users will not be able to execute any files that are not in
51256 + root-owned directories writable only by root. If the sysctl option
51257 + is enabled, a sysctl option with name "tpe" is created.
51258 +
51259 +config GRKERNSEC_TPE_ALL
51260 + bool "Partially restrict all non-root users"
51261 + depends on GRKERNSEC_TPE
51262 + help
51263 + If you say Y here, all non-root users will be covered under
51264 + a weaker TPE restriction. This is separate from, and in addition to,
51265 + the main TPE options that you have selected elsewhere. Thus, if a
51266 + "trusted" GID is chosen, this restriction applies to even that GID.
51267 + Under this restriction, all non-root users will only be allowed to
51268 + execute files in directories they own that are not group or
51269 + world-writable, or in directories owned by root and writable only by
51270 + root. If the sysctl option is enabled, a sysctl option with name
51271 + "tpe_restrict_all" is created.
51272 +
51273 +config GRKERNSEC_TPE_INVERT
51274 + bool "Invert GID option"
51275 + depends on GRKERNSEC_TPE
51276 + help
51277 + If you say Y here, the group you specify in the TPE configuration will
51278 + decide what group TPE restrictions will be *disabled* for. This
51279 + option is useful if you want TPE restrictions to be applied to most
51280 + users on the system. If the sysctl option is enabled, a sysctl option
51281 + with name "tpe_invert" is created. Unlike other sysctl options, this
51282 + entry will default to on for backward-compatibility.
51283 +
51284 +config GRKERNSEC_TPE_GID
51285 + int
51286 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51287 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51288 +
51289 +config GRKERNSEC_TPE_UNTRUSTED_GID
51290 + int "GID for TPE-untrusted users"
51291 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51292 + default 1005
51293 + help
51294 + Setting this GID determines what group TPE restrictions will be
51295 + *enabled* for. If the sysctl option is enabled, a sysctl option
51296 + with name "tpe_gid" is created.
51297 +
51298 +config GRKERNSEC_TPE_TRUSTED_GID
51299 + int "GID for TPE-trusted users"
51300 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51301 + default 1005
51302 + help
51303 + Setting this GID determines what group TPE restrictions will be
51304 + *disabled* for. If the sysctl option is enabled, a sysctl option
51305 + with name "tpe_gid" is created.
51306 +
51307 +endmenu
51308 +menu "Network Protections"
51309 +depends on GRKERNSEC
51310 +
51311 +config GRKERNSEC_RANDNET
51312 + bool "Larger entropy pools"
51313 + default y if GRKERNSEC_CONFIG_AUTO
51314 + help
51315 + If you say Y here, the entropy pools used for many features of Linux
51316 + and grsecurity will be doubled in size. Since several grsecurity
51317 + features use additional randomness, it is recommended that you say Y
51318 + here. Saying Y here has a similar effect as modifying
51319 + /proc/sys/kernel/random/poolsize.
51320 +
51321 +config GRKERNSEC_BLACKHOLE
51322 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51323 + default y if GRKERNSEC_CONFIG_AUTO
51324 + depends on NET
51325 + help
51326 + If you say Y here, neither TCP resets nor ICMP
51327 + destination-unreachable packets will be sent in response to packets
51328 + sent to ports for which no associated listening process exists.
51329 + This feature supports both IPV4 and IPV6 and exempts the
51330 + loopback interface from blackholing. Enabling this feature
51331 + makes a host more resilient to DoS attacks and reduces network
51332 + visibility against scanners.
51333 +
51334 + The blackhole feature as-implemented is equivalent to the FreeBSD
51335 + blackhole feature, as it prevents RST responses to all packets, not
51336 + just SYNs. Under most application behavior this causes no
51337 + problems, but applications (like haproxy) may not close certain
51338 + connections in a way that cleanly terminates them on the remote
51339 + end, leaving the remote host in LAST_ACK state. Because of this
51340 + side-effect and to prevent intentional LAST_ACK DoSes, this
51341 + feature also adds automatic mitigation against such attacks.
51342 + The mitigation drastically reduces the amount of time a socket
51343 + can spend in LAST_ACK state. If you're using haproxy and not
51344 + all servers it connects to have this option enabled, consider
51345 + disabling this feature on the haproxy host.
51346 +
51347 + If the sysctl option is enabled, two sysctl options with names
51348 + "ip_blackhole" and "lastack_retries" will be created.
51349 + While "ip_blackhole" takes the standard zero/non-zero on/off
51350 + toggle, "lastack_retries" uses the same kinds of values as
51351 + "tcp_retries1" and "tcp_retries2". The default value of 4
51352 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51353 + state.
51354 +
51355 +config GRKERNSEC_SOCKET
51356 + bool "Socket restrictions"
51357 + depends on NET
51358 + help
51359 + If you say Y here, you will be able to choose from several options.
51360 + If you assign a GID on your system and add it to the supplementary
51361 + groups of users you want to restrict socket access to, this patch
51362 + will perform up to three things, based on the option(s) you choose.
51363 +
51364 +config GRKERNSEC_SOCKET_ALL
51365 + bool "Deny any sockets to group"
51366 + depends on GRKERNSEC_SOCKET
51367 + help
51368 + If you say Y here, you will be able to choose a GID of whose users will
51369 + be unable to connect to other hosts from your machine or run server
51370 + applications from your machine. If the sysctl option is enabled, a
51371 + sysctl option with name "socket_all" is created.
51372 +
51373 +config GRKERNSEC_SOCKET_ALL_GID
51374 + int "GID to deny all sockets for"
51375 + depends on GRKERNSEC_SOCKET_ALL
51376 + default 1004
51377 + help
51378 + Here you can choose the GID to disable socket access for. Remember to
51379 + add the users you want socket access disabled for to the GID
51380 + specified here. If the sysctl option is enabled, a sysctl option
51381 + with name "socket_all_gid" is created.
51382 +
51383 +config GRKERNSEC_SOCKET_CLIENT
51384 + bool "Deny client sockets to group"
51385 + depends on GRKERNSEC_SOCKET
51386 + help
51387 + If you say Y here, you will be able to choose a GID of whose users will
51388 + be unable to connect to other hosts from your machine, but will be
51389 + able to run servers. If this option is enabled, all users in the group
51390 + you specify will have to use passive mode when initiating ftp transfers
51391 + from the shell on your machine. If the sysctl option is enabled, a
51392 + sysctl option with name "socket_client" is created.
51393 +
51394 +config GRKERNSEC_SOCKET_CLIENT_GID
51395 + int "GID to deny client sockets for"
51396 + depends on GRKERNSEC_SOCKET_CLIENT
51397 + default 1003
51398 + help
51399 + Here you can choose the GID to disable client socket access for.
51400 + Remember to add the users you want client socket access disabled for to
51401 + the GID specified here. If the sysctl option is enabled, a sysctl
51402 + option with name "socket_client_gid" is created.
51403 +
51404 +config GRKERNSEC_SOCKET_SERVER
51405 + bool "Deny server sockets to group"
51406 + depends on GRKERNSEC_SOCKET
51407 + help
51408 + If you say Y here, you will be able to choose a GID of whose users will
51409 + be unable to run server applications from your machine. If the sysctl
51410 + option is enabled, a sysctl option with name "socket_server" is created.
51411 +
51412 +config GRKERNSEC_SOCKET_SERVER_GID
51413 + int "GID to deny server sockets for"
51414 + depends on GRKERNSEC_SOCKET_SERVER
51415 + default 1002
51416 + help
51417 + Here you can choose the GID to disable server socket access for.
51418 + Remember to add the users you want server socket access disabled for to
51419 + the GID specified here. If the sysctl option is enabled, a sysctl
51420 + option with name "socket_server_gid" is created.
51421 +
51422 +endmenu
51423 +menu "Sysctl Support"
51424 +depends on GRKERNSEC && SYSCTL
51425 +
51426 +config GRKERNSEC_SYSCTL
51427 + bool "Sysctl support"
51428 + default y if GRKERNSEC_CONFIG_AUTO
51429 + help
51430 + If you say Y here, you will be able to change the options that
51431 + grsecurity runs with at bootup, without having to recompile your
51432 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51433 + to enable (1) or disable (0) various features. All the sysctl entries
51434 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51435 + All features enabled in the kernel configuration are disabled at boot
51436 + if you do not say Y to the "Turn on features by default" option.
51437 + All options should be set at startup, and the grsec_lock entry should
51438 + be set to a non-zero value after all the options are set.
51439 + *THIS IS EXTREMELY IMPORTANT*
51440 +
51441 +config GRKERNSEC_SYSCTL_DISTRO
51442 + bool "Extra sysctl support for distro makers (READ HELP)"
51443 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51444 + help
51445 + If you say Y here, additional sysctl options will be created
51446 + for features that affect processes running as root. Therefore,
51447 + it is critical when using this option that the grsec_lock entry be
51448 + enabled after boot. Only distros with prebuilt kernel packages
51449 + with this option enabled that can ensure grsec_lock is enabled
51450 + after boot should use this option.
51451 + *Failure to set grsec_lock after boot makes all grsec features
51452 + this option covers useless*
51453 +
51454 + Currently this option creates the following sysctl entries:
51455 + "Disable Privileged I/O": "disable_priv_io"
51456 +
51457 +config GRKERNSEC_SYSCTL_ON
51458 + bool "Turn on features by default"
51459 + default y if GRKERNSEC_CONFIG_AUTO
51460 + depends on GRKERNSEC_SYSCTL
51461 + help
51462 + If you say Y here, instead of having all features enabled in the
51463 + kernel configuration disabled at boot time, the features will be
51464 + enabled at boot time. It is recommended you say Y here unless
51465 + there is some reason you would want all sysctl-tunable features to
51466 + be disabled by default. As mentioned elsewhere, it is important
51467 + to enable the grsec_lock entry once you have finished modifying
51468 + the sysctl entries.
51469 +
51470 +endmenu
51471 +menu "Logging Options"
51472 +depends on GRKERNSEC
51473 +
51474 +config GRKERNSEC_FLOODTIME
51475 + int "Seconds in between log messages (minimum)"
51476 + default 10
51477 + help
51478 + This option allows you to enforce the number of seconds between
51479 + grsecurity log messages. The default should be suitable for most
51480 + people, however, if you choose to change it, choose a value small enough
51481 + to allow informative logs to be produced, but large enough to
51482 + prevent flooding.
51483 +
51484 +config GRKERNSEC_FLOODBURST
51485 + int "Number of messages in a burst (maximum)"
51486 + default 6
51487 + help
51488 + This option allows you to choose the maximum number of messages allowed
51489 + within the flood time interval you chose in a separate option. The
51490 + default should be suitable for most people, however if you find that
51491 + many of your logs are being interpreted as flooding, you may want to
51492 + raise this value.
51493 +
51494 +endmenu
51495 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51496 new file mode 100644
51497 index 0000000..1b9afa9
51498 --- /dev/null
51499 +++ b/grsecurity/Makefile
51500 @@ -0,0 +1,38 @@
51501 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51502 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51503 +# into an RBAC system
51504 +#
51505 +# All code in this directory and various hooks inserted throughout the kernel
51506 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51507 +# under the GPL v2 or higher
51508 +
51509 +KBUILD_CFLAGS += -Werror
51510 +
51511 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51512 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51513 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51514 +
51515 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51516 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51517 + gracl_learn.o grsec_log.o
51518 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51519 +
51520 +ifdef CONFIG_NET
51521 +obj-y += grsec_sock.o
51522 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51523 +endif
51524 +
51525 +ifndef CONFIG_GRKERNSEC
51526 +obj-y += grsec_disabled.o
51527 +endif
51528 +
51529 +ifdef CONFIG_GRKERNSEC_HIDESYM
51530 +extra-y := grsec_hidesym.o
51531 +$(obj)/grsec_hidesym.o:
51532 + @-chmod -f 500 /boot
51533 + @-chmod -f 500 /lib/modules
51534 + @-chmod -f 500 /lib64/modules
51535 + @-chmod -f 500 /lib32/modules
51536 + @-chmod -f 700 .
51537 + @echo ' grsec: protected kernel image paths'
51538 +endif
51539 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51540 new file mode 100644
51541 index 0000000..d20e40c
51542 --- /dev/null
51543 +++ b/grsecurity/gracl.c
51544 @@ -0,0 +1,4021 @@
51545 +#include <linux/kernel.h>
51546 +#include <linux/module.h>
51547 +#include <linux/sched.h>
51548 +#include <linux/mm.h>
51549 +#include <linux/file.h>
51550 +#include <linux/fs.h>
51551 +#include <linux/namei.h>
51552 +#include <linux/mount.h>
51553 +#include <linux/tty.h>
51554 +#include <linux/proc_fs.h>
51555 +#include <linux/lglock.h>
51556 +#include <linux/slab.h>
51557 +#include <linux/vmalloc.h>
51558 +#include <linux/types.h>
51559 +#include <linux/sysctl.h>
51560 +#include <linux/netdevice.h>
51561 +#include <linux/ptrace.h>
51562 +#include <linux/gracl.h>
51563 +#include <linux/gralloc.h>
51564 +#include <linux/security.h>
51565 +#include <linux/grinternal.h>
51566 +#include <linux/pid_namespace.h>
51567 +#include <linux/stop_machine.h>
51568 +#include <linux/fdtable.h>
51569 +#include <linux/percpu.h>
51570 +#include <linux/lglock.h>
51571 +#include "../fs/mount.h"
51572 +
51573 +#include <asm/uaccess.h>
51574 +#include <asm/errno.h>
51575 +#include <asm/mman.h>
51576 +
51577 +extern struct lglock vfsmount_lock;
51578 +
51579 +static struct acl_role_db acl_role_set;
51580 +static struct name_db name_set;
51581 +static struct inodev_db inodev_set;
51582 +
51583 +/* for keeping track of userspace pointers used for subjects, so we
51584 + can share references in the kernel as well
51585 +*/
51586 +
51587 +static struct path real_root;
51588 +
51589 +static struct acl_subj_map_db subj_map_set;
51590 +
51591 +static struct acl_role_label *default_role;
51592 +
51593 +static struct acl_role_label *role_list;
51594 +
51595 +static u16 acl_sp_role_value;
51596 +
51597 +extern char *gr_shared_page[4];
51598 +static DEFINE_MUTEX(gr_dev_mutex);
51599 +DEFINE_RWLOCK(gr_inode_lock);
51600 +
51601 +struct gr_arg *gr_usermode;
51602 +
51603 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51604 +
51605 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51606 +extern void gr_clear_learn_entries(void);
51607 +
51608 +#ifdef CONFIG_GRKERNSEC_RESLOG
51609 +extern void gr_log_resource(const struct task_struct *task,
51610 + const int res, const unsigned long wanted, const int gt);
51611 +#endif
51612 +
51613 +unsigned char *gr_system_salt;
51614 +unsigned char *gr_system_sum;
51615 +
51616 +static struct sprole_pw **acl_special_roles = NULL;
51617 +static __u16 num_sprole_pws = 0;
51618 +
51619 +static struct acl_role_label *kernel_role = NULL;
51620 +
51621 +static unsigned int gr_auth_attempts = 0;
51622 +static unsigned long gr_auth_expires = 0UL;
51623 +
51624 +#ifdef CONFIG_NET
51625 +extern struct vfsmount *sock_mnt;
51626 +#endif
51627 +
51628 +extern struct vfsmount *pipe_mnt;
51629 +extern struct vfsmount *shm_mnt;
51630 +#ifdef CONFIG_HUGETLBFS
51631 +extern struct vfsmount *hugetlbfs_vfsmount;
51632 +#endif
51633 +
51634 +static struct acl_object_label *fakefs_obj_rw;
51635 +static struct acl_object_label *fakefs_obj_rwx;
51636 +
51637 +extern int gr_init_uidset(void);
51638 +extern void gr_free_uidset(void);
51639 +extern void gr_remove_uid(uid_t uid);
51640 +extern int gr_find_uid(uid_t uid);
51641 +
51642 +__inline__ int
51643 +gr_acl_is_enabled(void)
51644 +{
51645 + return (gr_status & GR_READY);
51646 +}
51647 +
51648 +#ifdef CONFIG_BTRFS_FS
51649 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51650 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51651 +#endif
51652 +
51653 +static inline dev_t __get_dev(const struct dentry *dentry)
51654 +{
51655 +#ifdef CONFIG_BTRFS_FS
51656 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51657 + return get_btrfs_dev_from_inode(dentry->d_inode);
51658 + else
51659 +#endif
51660 + return dentry->d_inode->i_sb->s_dev;
51661 +}
51662 +
51663 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51664 +{
51665 + return __get_dev(dentry);
51666 +}
51667 +
51668 +static char gr_task_roletype_to_char(struct task_struct *task)
51669 +{
51670 + switch (task->role->roletype &
51671 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51672 + GR_ROLE_SPECIAL)) {
51673 + case GR_ROLE_DEFAULT:
51674 + return 'D';
51675 + case GR_ROLE_USER:
51676 + return 'U';
51677 + case GR_ROLE_GROUP:
51678 + return 'G';
51679 + case GR_ROLE_SPECIAL:
51680 + return 'S';
51681 + }
51682 +
51683 + return 'X';
51684 +}
51685 +
51686 +char gr_roletype_to_char(void)
51687 +{
51688 + return gr_task_roletype_to_char(current);
51689 +}
51690 +
51691 +__inline__ int
51692 +gr_acl_tpe_check(void)
51693 +{
51694 + if (unlikely(!(gr_status & GR_READY)))
51695 + return 0;
51696 + if (current->role->roletype & GR_ROLE_TPE)
51697 + return 1;
51698 + else
51699 + return 0;
51700 +}
51701 +
51702 +int
51703 +gr_handle_rawio(const struct inode *inode)
51704 +{
51705 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51706 + if (inode && S_ISBLK(inode->i_mode) &&
51707 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51708 + !capable(CAP_SYS_RAWIO))
51709 + return 1;
51710 +#endif
51711 + return 0;
51712 +}
51713 +
51714 +static int
51715 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51716 +{
51717 + if (likely(lena != lenb))
51718 + return 0;
51719 +
51720 + return !memcmp(a, b, lena);
51721 +}
51722 +
51723 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51724 +{
51725 + *buflen -= namelen;
51726 + if (*buflen < 0)
51727 + return -ENAMETOOLONG;
51728 + *buffer -= namelen;
51729 + memcpy(*buffer, str, namelen);
51730 + return 0;
51731 +}
51732 +
51733 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51734 +{
51735 + return prepend(buffer, buflen, name->name, name->len);
51736 +}
51737 +
51738 +static int prepend_path(const struct path *path, struct path *root,
51739 + char **buffer, int *buflen)
51740 +{
51741 + struct dentry *dentry = path->dentry;
51742 + struct vfsmount *vfsmnt = path->mnt;
51743 + struct mount *mnt = real_mount(vfsmnt);
51744 + bool slash = false;
51745 + int error = 0;
51746 +
51747 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51748 + struct dentry * parent;
51749 +
51750 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51751 + /* Global root? */
51752 + if (!mnt_has_parent(mnt)) {
51753 + goto out;
51754 + }
51755 + dentry = mnt->mnt_mountpoint;
51756 + mnt = mnt->mnt_parent;
51757 + vfsmnt = &mnt->mnt;
51758 + continue;
51759 + }
51760 + parent = dentry->d_parent;
51761 + prefetch(parent);
51762 + spin_lock(&dentry->d_lock);
51763 + error = prepend_name(buffer, buflen, &dentry->d_name);
51764 + spin_unlock(&dentry->d_lock);
51765 + if (!error)
51766 + error = prepend(buffer, buflen, "/", 1);
51767 + if (error)
51768 + break;
51769 +
51770 + slash = true;
51771 + dentry = parent;
51772 + }
51773 +
51774 +out:
51775 + if (!error && !slash)
51776 + error = prepend(buffer, buflen, "/", 1);
51777 +
51778 + return error;
51779 +}
51780 +
51781 +/* this must be called with vfsmount_lock and rename_lock held */
51782 +
51783 +static char *__our_d_path(const struct path *path, struct path *root,
51784 + char *buf, int buflen)
51785 +{
51786 + char *res = buf + buflen;
51787 + int error;
51788 +
51789 + prepend(&res, &buflen, "\0", 1);
51790 + error = prepend_path(path, root, &res, &buflen);
51791 + if (error)
51792 + return ERR_PTR(error);
51793 +
51794 + return res;
51795 +}
51796 +
51797 +static char *
51798 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51799 +{
51800 + char *retval;
51801 +
51802 + retval = __our_d_path(path, root, buf, buflen);
51803 + if (unlikely(IS_ERR(retval)))
51804 + retval = strcpy(buf, "<path too long>");
51805 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51806 + retval[1] = '\0';
51807 +
51808 + return retval;
51809 +}
51810 +
51811 +static char *
51812 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51813 + char *buf, int buflen)
51814 +{
51815 + struct path path;
51816 + char *res;
51817 +
51818 + path.dentry = (struct dentry *)dentry;
51819 + path.mnt = (struct vfsmount *)vfsmnt;
51820 +
51821 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51822 + by the RBAC system */
51823 + res = gen_full_path(&path, &real_root, buf, buflen);
51824 +
51825 + return res;
51826 +}
51827 +
51828 +static char *
51829 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51830 + char *buf, int buflen)
51831 +{
51832 + char *res;
51833 + struct path path;
51834 + struct path root;
51835 + struct task_struct *reaper = init_pid_ns.child_reaper;
51836 +
51837 + path.dentry = (struct dentry *)dentry;
51838 + path.mnt = (struct vfsmount *)vfsmnt;
51839 +
51840 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51841 + get_fs_root(reaper->fs, &root);
51842 +
51843 + write_seqlock(&rename_lock);
51844 + br_read_lock(&vfsmount_lock);
51845 + res = gen_full_path(&path, &root, buf, buflen);
51846 + br_read_unlock(&vfsmount_lock);
51847 + write_sequnlock(&rename_lock);
51848 +
51849 + path_put(&root);
51850 + return res;
51851 +}
51852 +
51853 +static char *
51854 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51855 +{
51856 + char *ret;
51857 + write_seqlock(&rename_lock);
51858 + br_read_lock(&vfsmount_lock);
51859 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51860 + PAGE_SIZE);
51861 + br_read_unlock(&vfsmount_lock);
51862 + write_sequnlock(&rename_lock);
51863 + return ret;
51864 +}
51865 +
51866 +static char *
51867 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51868 +{
51869 + char *ret;
51870 + char *buf;
51871 + int buflen;
51872 +
51873 + write_seqlock(&rename_lock);
51874 + br_read_lock(&vfsmount_lock);
51875 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51876 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51877 + buflen = (int)(ret - buf);
51878 + if (buflen >= 5)
51879 + prepend(&ret, &buflen, "/proc", 5);
51880 + else
51881 + ret = strcpy(buf, "<path too long>");
51882 + br_read_unlock(&vfsmount_lock);
51883 + write_sequnlock(&rename_lock);
51884 + return ret;
51885 +}
51886 +
51887 +char *
51888 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51889 +{
51890 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51891 + PAGE_SIZE);
51892 +}
51893 +
51894 +char *
51895 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51896 +{
51897 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51898 + PAGE_SIZE);
51899 +}
51900 +
51901 +char *
51902 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51903 +{
51904 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51905 + PAGE_SIZE);
51906 +}
51907 +
51908 +char *
51909 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51910 +{
51911 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51912 + PAGE_SIZE);
51913 +}
51914 +
51915 +char *
51916 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51917 +{
51918 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51919 + PAGE_SIZE);
51920 +}
51921 +
51922 +__inline__ __u32
51923 +to_gr_audit(const __u32 reqmode)
51924 +{
51925 + /* masks off auditable permission flags, then shifts them to create
51926 + auditing flags, and adds the special case of append auditing if
51927 + we're requesting write */
51928 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51929 +}
51930 +
51931 +struct acl_subject_label *
51932 +lookup_subject_map(const struct acl_subject_label *userp)
51933 +{
51934 + unsigned int index = shash(userp, subj_map_set.s_size);
51935 + struct subject_map *match;
51936 +
51937 + match = subj_map_set.s_hash[index];
51938 +
51939 + while (match && match->user != userp)
51940 + match = match->next;
51941 +
51942 + if (match != NULL)
51943 + return match->kernel;
51944 + else
51945 + return NULL;
51946 +}
51947 +
51948 +static void
51949 +insert_subj_map_entry(struct subject_map *subjmap)
51950 +{
51951 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51952 + struct subject_map **curr;
51953 +
51954 + subjmap->prev = NULL;
51955 +
51956 + curr = &subj_map_set.s_hash[index];
51957 + if (*curr != NULL)
51958 + (*curr)->prev = subjmap;
51959 +
51960 + subjmap->next = *curr;
51961 + *curr = subjmap;
51962 +
51963 + return;
51964 +}
51965 +
51966 +static struct acl_role_label *
51967 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51968 + const gid_t gid)
51969 +{
51970 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51971 + struct acl_role_label *match;
51972 + struct role_allowed_ip *ipp;
51973 + unsigned int x;
51974 + u32 curr_ip = task->signal->curr_ip;
51975 +
51976 + task->signal->saved_ip = curr_ip;
51977 +
51978 + match = acl_role_set.r_hash[index];
51979 +
51980 + while (match) {
51981 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51982 + for (x = 0; x < match->domain_child_num; x++) {
51983 + if (match->domain_children[x] == uid)
51984 + goto found;
51985 + }
51986 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51987 + break;
51988 + match = match->next;
51989 + }
51990 +found:
51991 + if (match == NULL) {
51992 + try_group:
51993 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51994 + match = acl_role_set.r_hash[index];
51995 +
51996 + while (match) {
51997 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51998 + for (x = 0; x < match->domain_child_num; x++) {
51999 + if (match->domain_children[x] == gid)
52000 + goto found2;
52001 + }
52002 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52003 + break;
52004 + match = match->next;
52005 + }
52006 +found2:
52007 + if (match == NULL)
52008 + match = default_role;
52009 + if (match->allowed_ips == NULL)
52010 + return match;
52011 + else {
52012 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52013 + if (likely
52014 + ((ntohl(curr_ip) & ipp->netmask) ==
52015 + (ntohl(ipp->addr) & ipp->netmask)))
52016 + return match;
52017 + }
52018 + match = default_role;
52019 + }
52020 + } else if (match->allowed_ips == NULL) {
52021 + return match;
52022 + } else {
52023 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52024 + if (likely
52025 + ((ntohl(curr_ip) & ipp->netmask) ==
52026 + (ntohl(ipp->addr) & ipp->netmask)))
52027 + return match;
52028 + }
52029 + goto try_group;
52030 + }
52031 +
52032 + return match;
52033 +}
52034 +
52035 +struct acl_subject_label *
52036 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52037 + const struct acl_role_label *role)
52038 +{
52039 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52040 + struct acl_subject_label *match;
52041 +
52042 + match = role->subj_hash[index];
52043 +
52044 + while (match && (match->inode != ino || match->device != dev ||
52045 + (match->mode & GR_DELETED))) {
52046 + match = match->next;
52047 + }
52048 +
52049 + if (match && !(match->mode & GR_DELETED))
52050 + return match;
52051 + else
52052 + return NULL;
52053 +}
52054 +
52055 +struct acl_subject_label *
52056 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52057 + const struct acl_role_label *role)
52058 +{
52059 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52060 + struct acl_subject_label *match;
52061 +
52062 + match = role->subj_hash[index];
52063 +
52064 + while (match && (match->inode != ino || match->device != dev ||
52065 + !(match->mode & GR_DELETED))) {
52066 + match = match->next;
52067 + }
52068 +
52069 + if (match && (match->mode & GR_DELETED))
52070 + return match;
52071 + else
52072 + return NULL;
52073 +}
52074 +
52075 +static struct acl_object_label *
52076 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52077 + const struct acl_subject_label *subj)
52078 +{
52079 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52080 + struct acl_object_label *match;
52081 +
52082 + match = subj->obj_hash[index];
52083 +
52084 + while (match && (match->inode != ino || match->device != dev ||
52085 + (match->mode & GR_DELETED))) {
52086 + match = match->next;
52087 + }
52088 +
52089 + if (match && !(match->mode & GR_DELETED))
52090 + return match;
52091 + else
52092 + return NULL;
52093 +}
52094 +
52095 +static struct acl_object_label *
52096 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52097 + const struct acl_subject_label *subj)
52098 +{
52099 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52100 + struct acl_object_label *match;
52101 +
52102 + match = subj->obj_hash[index];
52103 +
52104 + while (match && (match->inode != ino || match->device != dev ||
52105 + !(match->mode & GR_DELETED))) {
52106 + match = match->next;
52107 + }
52108 +
52109 + if (match && (match->mode & GR_DELETED))
52110 + return match;
52111 +
52112 + match = subj->obj_hash[index];
52113 +
52114 + while (match && (match->inode != ino || match->device != dev ||
52115 + (match->mode & GR_DELETED))) {
52116 + match = match->next;
52117 + }
52118 +
52119 + if (match && !(match->mode & GR_DELETED))
52120 + return match;
52121 + else
52122 + return NULL;
52123 +}
52124 +
52125 +static struct name_entry *
52126 +lookup_name_entry(const char *name)
52127 +{
52128 + unsigned int len = strlen(name);
52129 + unsigned int key = full_name_hash(name, len);
52130 + unsigned int index = key % name_set.n_size;
52131 + struct name_entry *match;
52132 +
52133 + match = name_set.n_hash[index];
52134 +
52135 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52136 + match = match->next;
52137 +
52138 + return match;
52139 +}
52140 +
52141 +static struct name_entry *
52142 +lookup_name_entry_create(const char *name)
52143 +{
52144 + unsigned int len = strlen(name);
52145 + unsigned int key = full_name_hash(name, len);
52146 + unsigned int index = key % name_set.n_size;
52147 + struct name_entry *match;
52148 +
52149 + match = name_set.n_hash[index];
52150 +
52151 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52152 + !match->deleted))
52153 + match = match->next;
52154 +
52155 + if (match && match->deleted)
52156 + return match;
52157 +
52158 + match = name_set.n_hash[index];
52159 +
52160 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52161 + match->deleted))
52162 + match = match->next;
52163 +
52164 + if (match && !match->deleted)
52165 + return match;
52166 + else
52167 + return NULL;
52168 +}
52169 +
52170 +static struct inodev_entry *
52171 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52172 +{
52173 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52174 + struct inodev_entry *match;
52175 +
52176 + match = inodev_set.i_hash[index];
52177 +
52178 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52179 + match = match->next;
52180 +
52181 + return match;
52182 +}
52183 +
52184 +static void
52185 +insert_inodev_entry(struct inodev_entry *entry)
52186 +{
52187 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52188 + inodev_set.i_size);
52189 + struct inodev_entry **curr;
52190 +
52191 + entry->prev = NULL;
52192 +
52193 + curr = &inodev_set.i_hash[index];
52194 + if (*curr != NULL)
52195 + (*curr)->prev = entry;
52196 +
52197 + entry->next = *curr;
52198 + *curr = entry;
52199 +
52200 + return;
52201 +}
52202 +
52203 +static void
52204 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52205 +{
52206 + unsigned int index =
52207 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52208 + struct acl_role_label **curr;
52209 + struct acl_role_label *tmp, *tmp2;
52210 +
52211 + curr = &acl_role_set.r_hash[index];
52212 +
52213 + /* simple case, slot is empty, just set it to our role */
52214 + if (*curr == NULL) {
52215 + *curr = role;
52216 + } else {
52217 + /* example:
52218 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52219 + 2 -> 3
52220 + */
52221 + /* first check to see if we can already be reached via this slot */
52222 + tmp = *curr;
52223 + while (tmp && tmp != role)
52224 + tmp = tmp->next;
52225 + if (tmp == role) {
52226 + /* we don't need to add ourselves to this slot's chain */
52227 + return;
52228 + }
52229 + /* we need to add ourselves to this chain, two cases */
52230 + if (role->next == NULL) {
52231 + /* simple case, append the current chain to our role */
52232 + role->next = *curr;
52233 + *curr = role;
52234 + } else {
52235 + /* 1 -> 2 -> 3 -> 4
52236 + 2 -> 3 -> 4
52237 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52238 + */
52239 + /* trickier case: walk our role's chain until we find
52240 + the role for the start of the current slot's chain */
52241 + tmp = role;
52242 + tmp2 = *curr;
52243 + while (tmp->next && tmp->next != tmp2)
52244 + tmp = tmp->next;
52245 + if (tmp->next == tmp2) {
52246 + /* from example above, we found 3, so just
52247 + replace this slot's chain with ours */
52248 + *curr = role;
52249 + } else {
52250 + /* we didn't find a subset of our role's chain
52251 + in the current slot's chain, so append their
52252 + chain to ours, and set us as the first role in
52253 + the slot's chain
52254 +
52255 + we could fold this case with the case above,
52256 + but making it explicit for clarity
52257 + */
52258 + tmp->next = tmp2;
52259 + *curr = role;
52260 + }
52261 + }
52262 + }
52263 +
52264 + return;
52265 +}
52266 +
52267 +static void
52268 +insert_acl_role_label(struct acl_role_label *role)
52269 +{
52270 + int i;
52271 +
52272 + if (role_list == NULL) {
52273 + role_list = role;
52274 + role->prev = NULL;
52275 + } else {
52276 + role->prev = role_list;
52277 + role_list = role;
52278 + }
52279 +
52280 + /* used for hash chains */
52281 + role->next = NULL;
52282 +
52283 + if (role->roletype & GR_ROLE_DOMAIN) {
52284 + for (i = 0; i < role->domain_child_num; i++)
52285 + __insert_acl_role_label(role, role->domain_children[i]);
52286 + } else
52287 + __insert_acl_role_label(role, role->uidgid);
52288 +}
52289 +
52290 +static int
52291 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52292 +{
52293 + struct name_entry **curr, *nentry;
52294 + struct inodev_entry *ientry;
52295 + unsigned int len = strlen(name);
52296 + unsigned int key = full_name_hash(name, len);
52297 + unsigned int index = key % name_set.n_size;
52298 +
52299 + curr = &name_set.n_hash[index];
52300 +
52301 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52302 + curr = &((*curr)->next);
52303 +
52304 + if (*curr != NULL)
52305 + return 1;
52306 +
52307 + nentry = acl_alloc(sizeof (struct name_entry));
52308 + if (nentry == NULL)
52309 + return 0;
52310 + ientry = acl_alloc(sizeof (struct inodev_entry));
52311 + if (ientry == NULL)
52312 + return 0;
52313 + ientry->nentry = nentry;
52314 +
52315 + nentry->key = key;
52316 + nentry->name = name;
52317 + nentry->inode = inode;
52318 + nentry->device = device;
52319 + nentry->len = len;
52320 + nentry->deleted = deleted;
52321 +
52322 + nentry->prev = NULL;
52323 + curr = &name_set.n_hash[index];
52324 + if (*curr != NULL)
52325 + (*curr)->prev = nentry;
52326 + nentry->next = *curr;
52327 + *curr = nentry;
52328 +
52329 + /* insert us into the table searchable by inode/dev */
52330 + insert_inodev_entry(ientry);
52331 +
52332 + return 1;
52333 +}
52334 +
52335 +static void
52336 +insert_acl_obj_label(struct acl_object_label *obj,
52337 + struct acl_subject_label *subj)
52338 +{
52339 + unsigned int index =
52340 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52341 + struct acl_object_label **curr;
52342 +
52343 +
52344 + obj->prev = NULL;
52345 +
52346 + curr = &subj->obj_hash[index];
52347 + if (*curr != NULL)
52348 + (*curr)->prev = obj;
52349 +
52350 + obj->next = *curr;
52351 + *curr = obj;
52352 +
52353 + return;
52354 +}
52355 +
52356 +static void
52357 +insert_acl_subj_label(struct acl_subject_label *obj,
52358 + struct acl_role_label *role)
52359 +{
52360 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52361 + struct acl_subject_label **curr;
52362 +
52363 + obj->prev = NULL;
52364 +
52365 + curr = &role->subj_hash[index];
52366 + if (*curr != NULL)
52367 + (*curr)->prev = obj;
52368 +
52369 + obj->next = *curr;
52370 + *curr = obj;
52371 +
52372 + return;
52373 +}
52374 +
52375 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52376 +
52377 +static void *
52378 +create_table(__u32 * len, int elementsize)
52379 +{
52380 + unsigned int table_sizes[] = {
52381 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52382 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52383 + 4194301, 8388593, 16777213, 33554393, 67108859
52384 + };
52385 + void *newtable = NULL;
52386 + unsigned int pwr = 0;
52387 +
52388 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52389 + table_sizes[pwr] <= *len)
52390 + pwr++;
52391 +
52392 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52393 + return newtable;
52394 +
52395 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52396 + newtable =
52397 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52398 + else
52399 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52400 +
52401 + *len = table_sizes[pwr];
52402 +
52403 + return newtable;
52404 +}
52405 +
52406 +static int
52407 +init_variables(const struct gr_arg *arg)
52408 +{
52409 + struct task_struct *reaper = init_pid_ns.child_reaper;
52410 + unsigned int stacksize;
52411 +
52412 + subj_map_set.s_size = arg->role_db.num_subjects;
52413 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52414 + name_set.n_size = arg->role_db.num_objects;
52415 + inodev_set.i_size = arg->role_db.num_objects;
52416 +
52417 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52418 + !name_set.n_size || !inodev_set.i_size)
52419 + return 1;
52420 +
52421 + if (!gr_init_uidset())
52422 + return 1;
52423 +
52424 + /* set up the stack that holds allocation info */
52425 +
52426 + stacksize = arg->role_db.num_pointers + 5;
52427 +
52428 + if (!acl_alloc_stack_init(stacksize))
52429 + return 1;
52430 +
52431 + /* grab reference for the real root dentry and vfsmount */
52432 + get_fs_root(reaper->fs, &real_root);
52433 +
52434 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52435 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52436 +#endif
52437 +
52438 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52439 + if (fakefs_obj_rw == NULL)
52440 + return 1;
52441 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52442 +
52443 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52444 + if (fakefs_obj_rwx == NULL)
52445 + return 1;
52446 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52447 +
52448 + subj_map_set.s_hash =
52449 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52450 + acl_role_set.r_hash =
52451 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52452 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52453 + inodev_set.i_hash =
52454 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52455 +
52456 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52457 + !name_set.n_hash || !inodev_set.i_hash)
52458 + return 1;
52459 +
52460 + memset(subj_map_set.s_hash, 0,
52461 + sizeof(struct subject_map *) * subj_map_set.s_size);
52462 + memset(acl_role_set.r_hash, 0,
52463 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52464 + memset(name_set.n_hash, 0,
52465 + sizeof (struct name_entry *) * name_set.n_size);
52466 + memset(inodev_set.i_hash, 0,
52467 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52468 +
52469 + return 0;
52470 +}
52471 +
52472 +/* free information not needed after startup
52473 + currently contains user->kernel pointer mappings for subjects
52474 +*/
52475 +
52476 +static void
52477 +free_init_variables(void)
52478 +{
52479 + __u32 i;
52480 +
52481 + if (subj_map_set.s_hash) {
52482 + for (i = 0; i < subj_map_set.s_size; i++) {
52483 + if (subj_map_set.s_hash[i]) {
52484 + kfree(subj_map_set.s_hash[i]);
52485 + subj_map_set.s_hash[i] = NULL;
52486 + }
52487 + }
52488 +
52489 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52490 + PAGE_SIZE)
52491 + kfree(subj_map_set.s_hash);
52492 + else
52493 + vfree(subj_map_set.s_hash);
52494 + }
52495 +
52496 + return;
52497 +}
52498 +
52499 +static void
52500 +free_variables(void)
52501 +{
52502 + struct acl_subject_label *s;
52503 + struct acl_role_label *r;
52504 + struct task_struct *task, *task2;
52505 + unsigned int x;
52506 +
52507 + gr_clear_learn_entries();
52508 +
52509 + read_lock(&tasklist_lock);
52510 + do_each_thread(task2, task) {
52511 + task->acl_sp_role = 0;
52512 + task->acl_role_id = 0;
52513 + task->acl = NULL;
52514 + task->role = NULL;
52515 + } while_each_thread(task2, task);
52516 + read_unlock(&tasklist_lock);
52517 +
52518 + /* release the reference to the real root dentry and vfsmount */
52519 + path_put(&real_root);
52520 + memset(&real_root, 0, sizeof(real_root));
52521 +
52522 + /* free all object hash tables */
52523 +
52524 + FOR_EACH_ROLE_START(r)
52525 + if (r->subj_hash == NULL)
52526 + goto next_role;
52527 + FOR_EACH_SUBJECT_START(r, s, x)
52528 + if (s->obj_hash == NULL)
52529 + break;
52530 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52531 + kfree(s->obj_hash);
52532 + else
52533 + vfree(s->obj_hash);
52534 + FOR_EACH_SUBJECT_END(s, x)
52535 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52536 + if (s->obj_hash == NULL)
52537 + break;
52538 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52539 + kfree(s->obj_hash);
52540 + else
52541 + vfree(s->obj_hash);
52542 + FOR_EACH_NESTED_SUBJECT_END(s)
52543 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52544 + kfree(r->subj_hash);
52545 + else
52546 + vfree(r->subj_hash);
52547 + r->subj_hash = NULL;
52548 +next_role:
52549 + FOR_EACH_ROLE_END(r)
52550 +
52551 + acl_free_all();
52552 +
52553 + if (acl_role_set.r_hash) {
52554 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52555 + PAGE_SIZE)
52556 + kfree(acl_role_set.r_hash);
52557 + else
52558 + vfree(acl_role_set.r_hash);
52559 + }
52560 + if (name_set.n_hash) {
52561 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52562 + PAGE_SIZE)
52563 + kfree(name_set.n_hash);
52564 + else
52565 + vfree(name_set.n_hash);
52566 + }
52567 +
52568 + if (inodev_set.i_hash) {
52569 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52570 + PAGE_SIZE)
52571 + kfree(inodev_set.i_hash);
52572 + else
52573 + vfree(inodev_set.i_hash);
52574 + }
52575 +
52576 + gr_free_uidset();
52577 +
52578 + memset(&name_set, 0, sizeof (struct name_db));
52579 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52580 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52581 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52582 +
52583 + default_role = NULL;
52584 + kernel_role = NULL;
52585 + role_list = NULL;
52586 +
52587 + return;
52588 +}
52589 +
52590 +static __u32
52591 +count_user_objs(struct acl_object_label *userp)
52592 +{
52593 + struct acl_object_label o_tmp;
52594 + __u32 num = 0;
52595 +
52596 + while (userp) {
52597 + if (copy_from_user(&o_tmp, userp,
52598 + sizeof (struct acl_object_label)))
52599 + break;
52600 +
52601 + userp = o_tmp.prev;
52602 + num++;
52603 + }
52604 +
52605 + return num;
52606 +}
52607 +
52608 +static struct acl_subject_label *
52609 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52610 +
52611 +static int
52612 +copy_user_glob(struct acl_object_label *obj)
52613 +{
52614 + struct acl_object_label *g_tmp, **guser;
52615 + unsigned int len;
52616 + char *tmp;
52617 +
52618 + if (obj->globbed == NULL)
52619 + return 0;
52620 +
52621 + guser = &obj->globbed;
52622 + while (*guser) {
52623 + g_tmp = (struct acl_object_label *)
52624 + acl_alloc(sizeof (struct acl_object_label));
52625 + if (g_tmp == NULL)
52626 + return -ENOMEM;
52627 +
52628 + if (copy_from_user(g_tmp, *guser,
52629 + sizeof (struct acl_object_label)))
52630 + return -EFAULT;
52631 +
52632 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52633 +
52634 + if (!len || len >= PATH_MAX)
52635 + return -EINVAL;
52636 +
52637 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52638 + return -ENOMEM;
52639 +
52640 + if (copy_from_user(tmp, g_tmp->filename, len))
52641 + return -EFAULT;
52642 + tmp[len-1] = '\0';
52643 + g_tmp->filename = tmp;
52644 +
52645 + *guser = g_tmp;
52646 + guser = &(g_tmp->next);
52647 + }
52648 +
52649 + return 0;
52650 +}
52651 +
52652 +static int
52653 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52654 + struct acl_role_label *role)
52655 +{
52656 + struct acl_object_label *o_tmp;
52657 + unsigned int len;
52658 + int ret;
52659 + char *tmp;
52660 +
52661 + while (userp) {
52662 + if ((o_tmp = (struct acl_object_label *)
52663 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52664 + return -ENOMEM;
52665 +
52666 + if (copy_from_user(o_tmp, userp,
52667 + sizeof (struct acl_object_label)))
52668 + return -EFAULT;
52669 +
52670 + userp = o_tmp->prev;
52671 +
52672 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52673 +
52674 + if (!len || len >= PATH_MAX)
52675 + return -EINVAL;
52676 +
52677 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52678 + return -ENOMEM;
52679 +
52680 + if (copy_from_user(tmp, o_tmp->filename, len))
52681 + return -EFAULT;
52682 + tmp[len-1] = '\0';
52683 + o_tmp->filename = tmp;
52684 +
52685 + insert_acl_obj_label(o_tmp, subj);
52686 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52687 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52688 + return -ENOMEM;
52689 +
52690 + ret = copy_user_glob(o_tmp);
52691 + if (ret)
52692 + return ret;
52693 +
52694 + if (o_tmp->nested) {
52695 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52696 + if (IS_ERR(o_tmp->nested))
52697 + return PTR_ERR(o_tmp->nested);
52698 +
52699 + /* insert into nested subject list */
52700 + o_tmp->nested->next = role->hash->first;
52701 + role->hash->first = o_tmp->nested;
52702 + }
52703 + }
52704 +
52705 + return 0;
52706 +}
52707 +
52708 +static __u32
52709 +count_user_subjs(struct acl_subject_label *userp)
52710 +{
52711 + struct acl_subject_label s_tmp;
52712 + __u32 num = 0;
52713 +
52714 + while (userp) {
52715 + if (copy_from_user(&s_tmp, userp,
52716 + sizeof (struct acl_subject_label)))
52717 + break;
52718 +
52719 + userp = s_tmp.prev;
52720 + /* do not count nested subjects against this count, since
52721 + they are not included in the hash table, but are
52722 + attached to objects. We have already counted
52723 + the subjects in userspace for the allocation
52724 + stack
52725 + */
52726 + if (!(s_tmp.mode & GR_NESTED))
52727 + num++;
52728 + }
52729 +
52730 + return num;
52731 +}
52732 +
52733 +static int
52734 +copy_user_allowedips(struct acl_role_label *rolep)
52735 +{
52736 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52737 +
52738 + ruserip = rolep->allowed_ips;
52739 +
52740 + while (ruserip) {
52741 + rlast = rtmp;
52742 +
52743 + if ((rtmp = (struct role_allowed_ip *)
52744 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52745 + return -ENOMEM;
52746 +
52747 + if (copy_from_user(rtmp, ruserip,
52748 + sizeof (struct role_allowed_ip)))
52749 + return -EFAULT;
52750 +
52751 + ruserip = rtmp->prev;
52752 +
52753 + if (!rlast) {
52754 + rtmp->prev = NULL;
52755 + rolep->allowed_ips = rtmp;
52756 + } else {
52757 + rlast->next = rtmp;
52758 + rtmp->prev = rlast;
52759 + }
52760 +
52761 + if (!ruserip)
52762 + rtmp->next = NULL;
52763 + }
52764 +
52765 + return 0;
52766 +}
52767 +
52768 +static int
52769 +copy_user_transitions(struct acl_role_label *rolep)
52770 +{
52771 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52772 +
52773 + unsigned int len;
52774 + char *tmp;
52775 +
52776 + rusertp = rolep->transitions;
52777 +
52778 + while (rusertp) {
52779 + rlast = rtmp;
52780 +
52781 + if ((rtmp = (struct role_transition *)
52782 + acl_alloc(sizeof (struct role_transition))) == NULL)
52783 + return -ENOMEM;
52784 +
52785 + if (copy_from_user(rtmp, rusertp,
52786 + sizeof (struct role_transition)))
52787 + return -EFAULT;
52788 +
52789 + rusertp = rtmp->prev;
52790 +
52791 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52792 +
52793 + if (!len || len >= GR_SPROLE_LEN)
52794 + return -EINVAL;
52795 +
52796 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52797 + return -ENOMEM;
52798 +
52799 + if (copy_from_user(tmp, rtmp->rolename, len))
52800 + return -EFAULT;
52801 + tmp[len-1] = '\0';
52802 + rtmp->rolename = tmp;
52803 +
52804 + if (!rlast) {
52805 + rtmp->prev = NULL;
52806 + rolep->transitions = rtmp;
52807 + } else {
52808 + rlast->next = rtmp;
52809 + rtmp->prev = rlast;
52810 + }
52811 +
52812 + if (!rusertp)
52813 + rtmp->next = NULL;
52814 + }
52815 +
52816 + return 0;
52817 +}
52818 +
52819 +static struct acl_subject_label *
52820 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52821 +{
52822 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52823 + unsigned int len;
52824 + char *tmp;
52825 + __u32 num_objs;
52826 + struct acl_ip_label **i_tmp, *i_utmp2;
52827 + struct gr_hash_struct ghash;
52828 + struct subject_map *subjmap;
52829 + unsigned int i_num;
52830 + int err;
52831 +
52832 + s_tmp = lookup_subject_map(userp);
52833 +
52834 + /* we've already copied this subject into the kernel, just return
52835 + the reference to it, and don't copy it over again
52836 + */
52837 + if (s_tmp)
52838 + return(s_tmp);
52839 +
52840 + if ((s_tmp = (struct acl_subject_label *)
52841 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52842 + return ERR_PTR(-ENOMEM);
52843 +
52844 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52845 + if (subjmap == NULL)
52846 + return ERR_PTR(-ENOMEM);
52847 +
52848 + subjmap->user = userp;
52849 + subjmap->kernel = s_tmp;
52850 + insert_subj_map_entry(subjmap);
52851 +
52852 + if (copy_from_user(s_tmp, userp,
52853 + sizeof (struct acl_subject_label)))
52854 + return ERR_PTR(-EFAULT);
52855 +
52856 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52857 +
52858 + if (!len || len >= PATH_MAX)
52859 + return ERR_PTR(-EINVAL);
52860 +
52861 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52862 + return ERR_PTR(-ENOMEM);
52863 +
52864 + if (copy_from_user(tmp, s_tmp->filename, len))
52865 + return ERR_PTR(-EFAULT);
52866 + tmp[len-1] = '\0';
52867 + s_tmp->filename = tmp;
52868 +
52869 + if (!strcmp(s_tmp->filename, "/"))
52870 + role->root_label = s_tmp;
52871 +
52872 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52873 + return ERR_PTR(-EFAULT);
52874 +
52875 + /* copy user and group transition tables */
52876 +
52877 + if (s_tmp->user_trans_num) {
52878 + uid_t *uidlist;
52879 +
52880 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52881 + if (uidlist == NULL)
52882 + return ERR_PTR(-ENOMEM);
52883 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52884 + return ERR_PTR(-EFAULT);
52885 +
52886 + s_tmp->user_transitions = uidlist;
52887 + }
52888 +
52889 + if (s_tmp->group_trans_num) {
52890 + gid_t *gidlist;
52891 +
52892 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52893 + if (gidlist == NULL)
52894 + return ERR_PTR(-ENOMEM);
52895 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52896 + return ERR_PTR(-EFAULT);
52897 +
52898 + s_tmp->group_transitions = gidlist;
52899 + }
52900 +
52901 + /* set up object hash table */
52902 + num_objs = count_user_objs(ghash.first);
52903 +
52904 + s_tmp->obj_hash_size = num_objs;
52905 + s_tmp->obj_hash =
52906 + (struct acl_object_label **)
52907 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52908 +
52909 + if (!s_tmp->obj_hash)
52910 + return ERR_PTR(-ENOMEM);
52911 +
52912 + memset(s_tmp->obj_hash, 0,
52913 + s_tmp->obj_hash_size *
52914 + sizeof (struct acl_object_label *));
52915 +
52916 + /* add in objects */
52917 + err = copy_user_objs(ghash.first, s_tmp, role);
52918 +
52919 + if (err)
52920 + return ERR_PTR(err);
52921 +
52922 + /* set pointer for parent subject */
52923 + if (s_tmp->parent_subject) {
52924 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52925 +
52926 + if (IS_ERR(s_tmp2))
52927 + return s_tmp2;
52928 +
52929 + s_tmp->parent_subject = s_tmp2;
52930 + }
52931 +
52932 + /* add in ip acls */
52933 +
52934 + if (!s_tmp->ip_num) {
52935 + s_tmp->ips = NULL;
52936 + goto insert;
52937 + }
52938 +
52939 + i_tmp =
52940 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52941 + sizeof (struct acl_ip_label *));
52942 +
52943 + if (!i_tmp)
52944 + return ERR_PTR(-ENOMEM);
52945 +
52946 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52947 + *(i_tmp + i_num) =
52948 + (struct acl_ip_label *)
52949 + acl_alloc(sizeof (struct acl_ip_label));
52950 + if (!*(i_tmp + i_num))
52951 + return ERR_PTR(-ENOMEM);
52952 +
52953 + if (copy_from_user
52954 + (&i_utmp2, s_tmp->ips + i_num,
52955 + sizeof (struct acl_ip_label *)))
52956 + return ERR_PTR(-EFAULT);
52957 +
52958 + if (copy_from_user
52959 + (*(i_tmp + i_num), i_utmp2,
52960 + sizeof (struct acl_ip_label)))
52961 + return ERR_PTR(-EFAULT);
52962 +
52963 + if ((*(i_tmp + i_num))->iface == NULL)
52964 + continue;
52965 +
52966 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52967 + if (!len || len >= IFNAMSIZ)
52968 + return ERR_PTR(-EINVAL);
52969 + tmp = acl_alloc(len);
52970 + if (tmp == NULL)
52971 + return ERR_PTR(-ENOMEM);
52972 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52973 + return ERR_PTR(-EFAULT);
52974 + (*(i_tmp + i_num))->iface = tmp;
52975 + }
52976 +
52977 + s_tmp->ips = i_tmp;
52978 +
52979 +insert:
52980 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52981 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52982 + return ERR_PTR(-ENOMEM);
52983 +
52984 + return s_tmp;
52985 +}
52986 +
52987 +static int
52988 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52989 +{
52990 + struct acl_subject_label s_pre;
52991 + struct acl_subject_label * ret;
52992 + int err;
52993 +
52994 + while (userp) {
52995 + if (copy_from_user(&s_pre, userp,
52996 + sizeof (struct acl_subject_label)))
52997 + return -EFAULT;
52998 +
52999 + /* do not add nested subjects here, add
53000 + while parsing objects
53001 + */
53002 +
53003 + if (s_pre.mode & GR_NESTED) {
53004 + userp = s_pre.prev;
53005 + continue;
53006 + }
53007 +
53008 + ret = do_copy_user_subj(userp, role);
53009 +
53010 + err = PTR_ERR(ret);
53011 + if (IS_ERR(ret))
53012 + return err;
53013 +
53014 + insert_acl_subj_label(ret, role);
53015 +
53016 + userp = s_pre.prev;
53017 + }
53018 +
53019 + return 0;
53020 +}
53021 +
53022 +static int
53023 +copy_user_acl(struct gr_arg *arg)
53024 +{
53025 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53026 + struct sprole_pw *sptmp;
53027 + struct gr_hash_struct *ghash;
53028 + uid_t *domainlist;
53029 + unsigned int r_num;
53030 + unsigned int len;
53031 + char *tmp;
53032 + int err = 0;
53033 + __u16 i;
53034 + __u32 num_subjs;
53035 +
53036 + /* we need a default and kernel role */
53037 + if (arg->role_db.num_roles < 2)
53038 + return -EINVAL;
53039 +
53040 + /* copy special role authentication info from userspace */
53041 +
53042 + num_sprole_pws = arg->num_sprole_pws;
53043 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53044 +
53045 + if (!acl_special_roles && num_sprole_pws)
53046 + return -ENOMEM;
53047 +
53048 + for (i = 0; i < num_sprole_pws; i++) {
53049 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53050 + if (!sptmp)
53051 + return -ENOMEM;
53052 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53053 + sizeof (struct sprole_pw)))
53054 + return -EFAULT;
53055 +
53056 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53057 +
53058 + if (!len || len >= GR_SPROLE_LEN)
53059 + return -EINVAL;
53060 +
53061 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53062 + return -ENOMEM;
53063 +
53064 + if (copy_from_user(tmp, sptmp->rolename, len))
53065 + return -EFAULT;
53066 +
53067 + tmp[len-1] = '\0';
53068 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53069 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53070 +#endif
53071 + sptmp->rolename = tmp;
53072 + acl_special_roles[i] = sptmp;
53073 + }
53074 +
53075 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53076 +
53077 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53078 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53079 +
53080 + if (!r_tmp)
53081 + return -ENOMEM;
53082 +
53083 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53084 + sizeof (struct acl_role_label *)))
53085 + return -EFAULT;
53086 +
53087 + if (copy_from_user(r_tmp, r_utmp2,
53088 + sizeof (struct acl_role_label)))
53089 + return -EFAULT;
53090 +
53091 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53092 +
53093 + if (!len || len >= PATH_MAX)
53094 + return -EINVAL;
53095 +
53096 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53097 + return -ENOMEM;
53098 +
53099 + if (copy_from_user(tmp, r_tmp->rolename, len))
53100 + return -EFAULT;
53101 +
53102 + tmp[len-1] = '\0';
53103 + r_tmp->rolename = tmp;
53104 +
53105 + if (!strcmp(r_tmp->rolename, "default")
53106 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53107 + default_role = r_tmp;
53108 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53109 + kernel_role = r_tmp;
53110 + }
53111 +
53112 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53113 + return -ENOMEM;
53114 +
53115 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53116 + return -EFAULT;
53117 +
53118 + r_tmp->hash = ghash;
53119 +
53120 + num_subjs = count_user_subjs(r_tmp->hash->first);
53121 +
53122 + r_tmp->subj_hash_size = num_subjs;
53123 + r_tmp->subj_hash =
53124 + (struct acl_subject_label **)
53125 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53126 +
53127 + if (!r_tmp->subj_hash)
53128 + return -ENOMEM;
53129 +
53130 + err = copy_user_allowedips(r_tmp);
53131 + if (err)
53132 + return err;
53133 +
53134 + /* copy domain info */
53135 + if (r_tmp->domain_children != NULL) {
53136 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53137 + if (domainlist == NULL)
53138 + return -ENOMEM;
53139 +
53140 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53141 + return -EFAULT;
53142 +
53143 + r_tmp->domain_children = domainlist;
53144 + }
53145 +
53146 + err = copy_user_transitions(r_tmp);
53147 + if (err)
53148 + return err;
53149 +
53150 + memset(r_tmp->subj_hash, 0,
53151 + r_tmp->subj_hash_size *
53152 + sizeof (struct acl_subject_label *));
53153 +
53154 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53155 +
53156 + if (err)
53157 + return err;
53158 +
53159 + /* set nested subject list to null */
53160 + r_tmp->hash->first = NULL;
53161 +
53162 + insert_acl_role_label(r_tmp);
53163 + }
53164 +
53165 + if (default_role == NULL || kernel_role == NULL)
53166 + return -EINVAL;
53167 +
53168 + return err;
53169 +}
53170 +
53171 +static int
53172 +gracl_init(struct gr_arg *args)
53173 +{
53174 + int error = 0;
53175 +
53176 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53177 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53178 +
53179 + if (init_variables(args)) {
53180 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53181 + error = -ENOMEM;
53182 + free_variables();
53183 + goto out;
53184 + }
53185 +
53186 + error = copy_user_acl(args);
53187 + free_init_variables();
53188 + if (error) {
53189 + free_variables();
53190 + goto out;
53191 + }
53192 +
53193 + if ((error = gr_set_acls(0))) {
53194 + free_variables();
53195 + goto out;
53196 + }
53197 +
53198 + pax_open_kernel();
53199 + gr_status |= GR_READY;
53200 + pax_close_kernel();
53201 +
53202 + out:
53203 + return error;
53204 +}
53205 +
53206 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53207 +
53208 +static int
53209 +glob_match(const char *p, const char *n)
53210 +{
53211 + char c;
53212 +
53213 + while ((c = *p++) != '\0') {
53214 + switch (c) {
53215 + case '?':
53216 + if (*n == '\0')
53217 + return 1;
53218 + else if (*n == '/')
53219 + return 1;
53220 + break;
53221 + case '\\':
53222 + if (*n != c)
53223 + return 1;
53224 + break;
53225 + case '*':
53226 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53227 + if (*n == '/')
53228 + return 1;
53229 + else if (c == '?') {
53230 + if (*n == '\0')
53231 + return 1;
53232 + else
53233 + ++n;
53234 + }
53235 + }
53236 + if (c == '\0') {
53237 + return 0;
53238 + } else {
53239 + const char *endp;
53240 +
53241 + if ((endp = strchr(n, '/')) == NULL)
53242 + endp = n + strlen(n);
53243 +
53244 + if (c == '[') {
53245 + for (--p; n < endp; ++n)
53246 + if (!glob_match(p, n))
53247 + return 0;
53248 + } else if (c == '/') {
53249 + while (*n != '\0' && *n != '/')
53250 + ++n;
53251 + if (*n == '/' && !glob_match(p, n + 1))
53252 + return 0;
53253 + } else {
53254 + for (--p; n < endp; ++n)
53255 + if (*n == c && !glob_match(p, n))
53256 + return 0;
53257 + }
53258 +
53259 + return 1;
53260 + }
53261 + case '[':
53262 + {
53263 + int not;
53264 + char cold;
53265 +
53266 + if (*n == '\0' || *n == '/')
53267 + return 1;
53268 +
53269 + not = (*p == '!' || *p == '^');
53270 + if (not)
53271 + ++p;
53272 +
53273 + c = *p++;
53274 + for (;;) {
53275 + unsigned char fn = (unsigned char)*n;
53276 +
53277 + if (c == '\0')
53278 + return 1;
53279 + else {
53280 + if (c == fn)
53281 + goto matched;
53282 + cold = c;
53283 + c = *p++;
53284 +
53285 + if (c == '-' && *p != ']') {
53286 + unsigned char cend = *p++;
53287 +
53288 + if (cend == '\0')
53289 + return 1;
53290 +
53291 + if (cold <= fn && fn <= cend)
53292 + goto matched;
53293 +
53294 + c = *p++;
53295 + }
53296 + }
53297 +
53298 + if (c == ']')
53299 + break;
53300 + }
53301 + if (!not)
53302 + return 1;
53303 + break;
53304 + matched:
53305 + while (c != ']') {
53306 + if (c == '\0')
53307 + return 1;
53308 +
53309 + c = *p++;
53310 + }
53311 + if (not)
53312 + return 1;
53313 + }
53314 + break;
53315 + default:
53316 + if (c != *n)
53317 + return 1;
53318 + }
53319 +
53320 + ++n;
53321 + }
53322 +
53323 + if (*n == '\0')
53324 + return 0;
53325 +
53326 + if (*n == '/')
53327 + return 0;
53328 +
53329 + return 1;
53330 +}
53331 +
53332 +static struct acl_object_label *
53333 +chk_glob_label(struct acl_object_label *globbed,
53334 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53335 +{
53336 + struct acl_object_label *tmp;
53337 +
53338 + if (*path == NULL)
53339 + *path = gr_to_filename_nolock(dentry, mnt);
53340 +
53341 + tmp = globbed;
53342 +
53343 + while (tmp) {
53344 + if (!glob_match(tmp->filename, *path))
53345 + return tmp;
53346 + tmp = tmp->next;
53347 + }
53348 +
53349 + return NULL;
53350 +}
53351 +
53352 +static struct acl_object_label *
53353 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53354 + const ino_t curr_ino, const dev_t curr_dev,
53355 + const struct acl_subject_label *subj, char **path, const int checkglob)
53356 +{
53357 + struct acl_subject_label *tmpsubj;
53358 + struct acl_object_label *retval;
53359 + struct acl_object_label *retval2;
53360 +
53361 + tmpsubj = (struct acl_subject_label *) subj;
53362 + read_lock(&gr_inode_lock);
53363 + do {
53364 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53365 + if (retval) {
53366 + if (checkglob && retval->globbed) {
53367 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53368 + if (retval2)
53369 + retval = retval2;
53370 + }
53371 + break;
53372 + }
53373 + } while ((tmpsubj = tmpsubj->parent_subject));
53374 + read_unlock(&gr_inode_lock);
53375 +
53376 + return retval;
53377 +}
53378 +
53379 +static __inline__ struct acl_object_label *
53380 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53381 + struct dentry *curr_dentry,
53382 + const struct acl_subject_label *subj, char **path, const int checkglob)
53383 +{
53384 + int newglob = checkglob;
53385 + ino_t inode;
53386 + dev_t device;
53387 +
53388 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53389 + as we don't want a / * rule to match instead of the / object
53390 + don't do this for create lookups that call this function though, since they're looking up
53391 + on the parent and thus need globbing checks on all paths
53392 + */
53393 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53394 + newglob = GR_NO_GLOB;
53395 +
53396 + spin_lock(&curr_dentry->d_lock);
53397 + inode = curr_dentry->d_inode->i_ino;
53398 + device = __get_dev(curr_dentry);
53399 + spin_unlock(&curr_dentry->d_lock);
53400 +
53401 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53402 +}
53403 +
53404 +static struct acl_object_label *
53405 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53406 + const struct acl_subject_label *subj, char *path, const int checkglob)
53407 +{
53408 + struct dentry *dentry = (struct dentry *) l_dentry;
53409 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53410 + struct mount *real_mnt = real_mount(mnt);
53411 + struct acl_object_label *retval;
53412 + struct dentry *parent;
53413 +
53414 + write_seqlock(&rename_lock);
53415 + br_read_lock(&vfsmount_lock);
53416 +
53417 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53418 +#ifdef CONFIG_NET
53419 + mnt == sock_mnt ||
53420 +#endif
53421 +#ifdef CONFIG_HUGETLBFS
53422 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53423 +#endif
53424 + /* ignore Eric Biederman */
53425 + IS_PRIVATE(l_dentry->d_inode))) {
53426 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53427 + goto out;
53428 + }
53429 +
53430 + for (;;) {
53431 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53432 + break;
53433 +
53434 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53435 + if (!mnt_has_parent(real_mnt))
53436 + break;
53437 +
53438 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53439 + if (retval != NULL)
53440 + goto out;
53441 +
53442 + dentry = real_mnt->mnt_mountpoint;
53443 + real_mnt = real_mnt->mnt_parent;
53444 + mnt = &real_mnt->mnt;
53445 + continue;
53446 + }
53447 +
53448 + parent = dentry->d_parent;
53449 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53450 + if (retval != NULL)
53451 + goto out;
53452 +
53453 + dentry = parent;
53454 + }
53455 +
53456 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53457 +
53458 + /* real_root is pinned so we don't have to hold a reference */
53459 + if (retval == NULL)
53460 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53461 +out:
53462 + br_read_unlock(&vfsmount_lock);
53463 + write_sequnlock(&rename_lock);
53464 +
53465 + BUG_ON(retval == NULL);
53466 +
53467 + return retval;
53468 +}
53469 +
53470 +static __inline__ struct acl_object_label *
53471 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53472 + const struct acl_subject_label *subj)
53473 +{
53474 + char *path = NULL;
53475 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53476 +}
53477 +
53478 +static __inline__ struct acl_object_label *
53479 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53480 + const struct acl_subject_label *subj)
53481 +{
53482 + char *path = NULL;
53483 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53484 +}
53485 +
53486 +static __inline__ struct acl_object_label *
53487 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53488 + const struct acl_subject_label *subj, char *path)
53489 +{
53490 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53491 +}
53492 +
53493 +static struct acl_subject_label *
53494 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53495 + const struct acl_role_label *role)
53496 +{
53497 + struct dentry *dentry = (struct dentry *) l_dentry;
53498 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53499 + struct mount *real_mnt = real_mount(mnt);
53500 + struct acl_subject_label *retval;
53501 + struct dentry *parent;
53502 +
53503 + write_seqlock(&rename_lock);
53504 + br_read_lock(&vfsmount_lock);
53505 +
53506 + for (;;) {
53507 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53508 + break;
53509 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53510 + if (!mnt_has_parent(real_mnt))
53511 + break;
53512 +
53513 + spin_lock(&dentry->d_lock);
53514 + read_lock(&gr_inode_lock);
53515 + retval =
53516 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53517 + __get_dev(dentry), role);
53518 + read_unlock(&gr_inode_lock);
53519 + spin_unlock(&dentry->d_lock);
53520 + if (retval != NULL)
53521 + goto out;
53522 +
53523 + dentry = real_mnt->mnt_mountpoint;
53524 + real_mnt = real_mnt->mnt_parent;
53525 + mnt = &real_mnt->mnt;
53526 + continue;
53527 + }
53528 +
53529 + spin_lock(&dentry->d_lock);
53530 + read_lock(&gr_inode_lock);
53531 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53532 + __get_dev(dentry), role);
53533 + read_unlock(&gr_inode_lock);
53534 + parent = dentry->d_parent;
53535 + spin_unlock(&dentry->d_lock);
53536 +
53537 + if (retval != NULL)
53538 + goto out;
53539 +
53540 + dentry = parent;
53541 + }
53542 +
53543 + spin_lock(&dentry->d_lock);
53544 + read_lock(&gr_inode_lock);
53545 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53546 + __get_dev(dentry), role);
53547 + read_unlock(&gr_inode_lock);
53548 + spin_unlock(&dentry->d_lock);
53549 +
53550 + if (unlikely(retval == NULL)) {
53551 + /* real_root is pinned, we don't need to hold a reference */
53552 + read_lock(&gr_inode_lock);
53553 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53554 + __get_dev(real_root.dentry), role);
53555 + read_unlock(&gr_inode_lock);
53556 + }
53557 +out:
53558 + br_read_unlock(&vfsmount_lock);
53559 + write_sequnlock(&rename_lock);
53560 +
53561 + BUG_ON(retval == NULL);
53562 +
53563 + return retval;
53564 +}
53565 +
53566 +static void
53567 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53568 +{
53569 + struct task_struct *task = current;
53570 + const struct cred *cred = current_cred();
53571 +
53572 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53573 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53574 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53575 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53576 +
53577 + return;
53578 +}
53579 +
53580 +static void
53581 +gr_log_learn_id_change(const char type, const unsigned int real,
53582 + const unsigned int effective, const unsigned int fs)
53583 +{
53584 + struct task_struct *task = current;
53585 + const struct cred *cred = current_cred();
53586 +
53587 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53588 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53589 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53590 + type, real, effective, fs, &task->signal->saved_ip);
53591 +
53592 + return;
53593 +}
53594 +
53595 +__u32
53596 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53597 + const struct vfsmount * mnt)
53598 +{
53599 + __u32 retval = mode;
53600 + struct acl_subject_label *curracl;
53601 + struct acl_object_label *currobj;
53602 +
53603 + if (unlikely(!(gr_status & GR_READY)))
53604 + return (mode & ~GR_AUDITS);
53605 +
53606 + curracl = current->acl;
53607 +
53608 + currobj = chk_obj_label(dentry, mnt, curracl);
53609 + retval = currobj->mode & mode;
53610 +
53611 + /* if we're opening a specified transfer file for writing
53612 + (e.g. /dev/initctl), then transfer our role to init
53613 + */
53614 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53615 + current->role->roletype & GR_ROLE_PERSIST)) {
53616 + struct task_struct *task = init_pid_ns.child_reaper;
53617 +
53618 + if (task->role != current->role) {
53619 + task->acl_sp_role = 0;
53620 + task->acl_role_id = current->acl_role_id;
53621 + task->role = current->role;
53622 + rcu_read_lock();
53623 + read_lock(&grsec_exec_file_lock);
53624 + gr_apply_subject_to_task(task);
53625 + read_unlock(&grsec_exec_file_lock);
53626 + rcu_read_unlock();
53627 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53628 + }
53629 + }
53630 +
53631 + if (unlikely
53632 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53633 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53634 + __u32 new_mode = mode;
53635 +
53636 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53637 +
53638 + retval = new_mode;
53639 +
53640 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53641 + new_mode |= GR_INHERIT;
53642 +
53643 + if (!(mode & GR_NOLEARN))
53644 + gr_log_learn(dentry, mnt, new_mode);
53645 + }
53646 +
53647 + return retval;
53648 +}
53649 +
53650 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53651 + const struct dentry *parent,
53652 + const struct vfsmount *mnt)
53653 +{
53654 + struct name_entry *match;
53655 + struct acl_object_label *matchpo;
53656 + struct acl_subject_label *curracl;
53657 + char *path;
53658 +
53659 + if (unlikely(!(gr_status & GR_READY)))
53660 + return NULL;
53661 +
53662 + preempt_disable();
53663 + path = gr_to_filename_rbac(new_dentry, mnt);
53664 + match = lookup_name_entry_create(path);
53665 +
53666 + curracl = current->acl;
53667 +
53668 + if (match) {
53669 + read_lock(&gr_inode_lock);
53670 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53671 + read_unlock(&gr_inode_lock);
53672 +
53673 + if (matchpo) {
53674 + preempt_enable();
53675 + return matchpo;
53676 + }
53677 + }
53678 +
53679 + // lookup parent
53680 +
53681 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53682 +
53683 + preempt_enable();
53684 + return matchpo;
53685 +}
53686 +
53687 +__u32
53688 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53689 + const struct vfsmount * mnt, const __u32 mode)
53690 +{
53691 + struct acl_object_label *matchpo;
53692 + __u32 retval;
53693 +
53694 + if (unlikely(!(gr_status & GR_READY)))
53695 + return (mode & ~GR_AUDITS);
53696 +
53697 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53698 +
53699 + retval = matchpo->mode & mode;
53700 +
53701 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53702 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53703 + __u32 new_mode = mode;
53704 +
53705 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53706 +
53707 + gr_log_learn(new_dentry, mnt, new_mode);
53708 + return new_mode;
53709 + }
53710 +
53711 + return retval;
53712 +}
53713 +
53714 +__u32
53715 +gr_check_link(const struct dentry * new_dentry,
53716 + const struct dentry * parent_dentry,
53717 + const struct vfsmount * parent_mnt,
53718 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53719 +{
53720 + struct acl_object_label *obj;
53721 + __u32 oldmode, newmode;
53722 + __u32 needmode;
53723 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53724 + GR_DELETE | GR_INHERIT;
53725 +
53726 + if (unlikely(!(gr_status & GR_READY)))
53727 + return (GR_CREATE | GR_LINK);
53728 +
53729 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53730 + oldmode = obj->mode;
53731 +
53732 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53733 + newmode = obj->mode;
53734 +
53735 + needmode = newmode & checkmodes;
53736 +
53737 + // old name for hardlink must have at least the permissions of the new name
53738 + if ((oldmode & needmode) != needmode)
53739 + goto bad;
53740 +
53741 + // if old name had restrictions/auditing, make sure the new name does as well
53742 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53743 +
53744 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53745 + if (is_privileged_binary(old_dentry))
53746 + needmode |= GR_SETID;
53747 +
53748 + if ((newmode & needmode) != needmode)
53749 + goto bad;
53750 +
53751 + // enforce minimum permissions
53752 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53753 + return newmode;
53754 +bad:
53755 + needmode = oldmode;
53756 + if (is_privileged_binary(old_dentry))
53757 + needmode |= GR_SETID;
53758 +
53759 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53760 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53761 + return (GR_CREATE | GR_LINK);
53762 + } else if (newmode & GR_SUPPRESS)
53763 + return GR_SUPPRESS;
53764 + else
53765 + return 0;
53766 +}
53767 +
53768 +int
53769 +gr_check_hidden_task(const struct task_struct *task)
53770 +{
53771 + if (unlikely(!(gr_status & GR_READY)))
53772 + return 0;
53773 +
53774 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53775 + return 1;
53776 +
53777 + return 0;
53778 +}
53779 +
53780 +int
53781 +gr_check_protected_task(const struct task_struct *task)
53782 +{
53783 + if (unlikely(!(gr_status & GR_READY) || !task))
53784 + return 0;
53785 +
53786 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53787 + task->acl != current->acl)
53788 + return 1;
53789 +
53790 + return 0;
53791 +}
53792 +
53793 +int
53794 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53795 +{
53796 + struct task_struct *p;
53797 + int ret = 0;
53798 +
53799 + if (unlikely(!(gr_status & GR_READY) || !pid))
53800 + return ret;
53801 +
53802 + read_lock(&tasklist_lock);
53803 + do_each_pid_task(pid, type, p) {
53804 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53805 + p->acl != current->acl) {
53806 + ret = 1;
53807 + goto out;
53808 + }
53809 + } while_each_pid_task(pid, type, p);
53810 +out:
53811 + read_unlock(&tasklist_lock);
53812 +
53813 + return ret;
53814 +}
53815 +
53816 +void
53817 +gr_copy_label(struct task_struct *tsk)
53818 +{
53819 + tsk->signal->used_accept = 0;
53820 + tsk->acl_sp_role = 0;
53821 + tsk->acl_role_id = current->acl_role_id;
53822 + tsk->acl = current->acl;
53823 + tsk->role = current->role;
53824 + tsk->signal->curr_ip = current->signal->curr_ip;
53825 + tsk->signal->saved_ip = current->signal->saved_ip;
53826 + if (current->exec_file)
53827 + get_file(current->exec_file);
53828 + tsk->exec_file = current->exec_file;
53829 + tsk->is_writable = current->is_writable;
53830 + if (unlikely(current->signal->used_accept)) {
53831 + current->signal->curr_ip = 0;
53832 + current->signal->saved_ip = 0;
53833 + }
53834 +
53835 + return;
53836 +}
53837 +
53838 +static void
53839 +gr_set_proc_res(struct task_struct *task)
53840 +{
53841 + struct acl_subject_label *proc;
53842 + unsigned short i;
53843 +
53844 + proc = task->acl;
53845 +
53846 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53847 + return;
53848 +
53849 + for (i = 0; i < RLIM_NLIMITS; i++) {
53850 + if (!(proc->resmask & (1 << i)))
53851 + continue;
53852 +
53853 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53854 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53855 + }
53856 +
53857 + return;
53858 +}
53859 +
53860 +extern int __gr_process_user_ban(struct user_struct *user);
53861 +
53862 +int
53863 +gr_check_user_change(int real, int effective, int fs)
53864 +{
53865 + unsigned int i;
53866 + __u16 num;
53867 + uid_t *uidlist;
53868 + int curuid;
53869 + int realok = 0;
53870 + int effectiveok = 0;
53871 + int fsok = 0;
53872 +
53873 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53874 + struct user_struct *user;
53875 +
53876 + if (real == -1)
53877 + goto skipit;
53878 +
53879 + user = find_user(real);
53880 + if (user == NULL)
53881 + goto skipit;
53882 +
53883 + if (__gr_process_user_ban(user)) {
53884 + /* for find_user */
53885 + free_uid(user);
53886 + return 1;
53887 + }
53888 +
53889 + /* for find_user */
53890 + free_uid(user);
53891 +
53892 +skipit:
53893 +#endif
53894 +
53895 + if (unlikely(!(gr_status & GR_READY)))
53896 + return 0;
53897 +
53898 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53899 + gr_log_learn_id_change('u', real, effective, fs);
53900 +
53901 + num = current->acl->user_trans_num;
53902 + uidlist = current->acl->user_transitions;
53903 +
53904 + if (uidlist == NULL)
53905 + return 0;
53906 +
53907 + if (real == -1)
53908 + realok = 1;
53909 + if (effective == -1)
53910 + effectiveok = 1;
53911 + if (fs == -1)
53912 + fsok = 1;
53913 +
53914 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53915 + for (i = 0; i < num; i++) {
53916 + curuid = (int)uidlist[i];
53917 + if (real == curuid)
53918 + realok = 1;
53919 + if (effective == curuid)
53920 + effectiveok = 1;
53921 + if (fs == curuid)
53922 + fsok = 1;
53923 + }
53924 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53925 + for (i = 0; i < num; i++) {
53926 + curuid = (int)uidlist[i];
53927 + if (real == curuid)
53928 + break;
53929 + if (effective == curuid)
53930 + break;
53931 + if (fs == curuid)
53932 + break;
53933 + }
53934 + /* not in deny list */
53935 + if (i == num) {
53936 + realok = 1;
53937 + effectiveok = 1;
53938 + fsok = 1;
53939 + }
53940 + }
53941 +
53942 + if (realok && effectiveok && fsok)
53943 + return 0;
53944 + else {
53945 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53946 + return 1;
53947 + }
53948 +}
53949 +
53950 +int
53951 +gr_check_group_change(int real, int effective, int fs)
53952 +{
53953 + unsigned int i;
53954 + __u16 num;
53955 + gid_t *gidlist;
53956 + int curgid;
53957 + int realok = 0;
53958 + int effectiveok = 0;
53959 + int fsok = 0;
53960 +
53961 + if (unlikely(!(gr_status & GR_READY)))
53962 + return 0;
53963 +
53964 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53965 + gr_log_learn_id_change('g', real, effective, fs);
53966 +
53967 + num = current->acl->group_trans_num;
53968 + gidlist = current->acl->group_transitions;
53969 +
53970 + if (gidlist == NULL)
53971 + return 0;
53972 +
53973 + if (real == -1)
53974 + realok = 1;
53975 + if (effective == -1)
53976 + effectiveok = 1;
53977 + if (fs == -1)
53978 + fsok = 1;
53979 +
53980 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53981 + for (i = 0; i < num; i++) {
53982 + curgid = (int)gidlist[i];
53983 + if (real == curgid)
53984 + realok = 1;
53985 + if (effective == curgid)
53986 + effectiveok = 1;
53987 + if (fs == curgid)
53988 + fsok = 1;
53989 + }
53990 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53991 + for (i = 0; i < num; i++) {
53992 + curgid = (int)gidlist[i];
53993 + if (real == curgid)
53994 + break;
53995 + if (effective == curgid)
53996 + break;
53997 + if (fs == curgid)
53998 + break;
53999 + }
54000 + /* not in deny list */
54001 + if (i == num) {
54002 + realok = 1;
54003 + effectiveok = 1;
54004 + fsok = 1;
54005 + }
54006 + }
54007 +
54008 + if (realok && effectiveok && fsok)
54009 + return 0;
54010 + else {
54011 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54012 + return 1;
54013 + }
54014 +}
54015 +
54016 +extern int gr_acl_is_capable(const int cap);
54017 +
54018 +void
54019 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54020 +{
54021 + struct acl_role_label *role = task->role;
54022 + struct acl_subject_label *subj = NULL;
54023 + struct acl_object_label *obj;
54024 + struct file *filp;
54025 +
54026 + if (unlikely(!(gr_status & GR_READY)))
54027 + return;
54028 +
54029 + filp = task->exec_file;
54030 +
54031 + /* kernel process, we'll give them the kernel role */
54032 + if (unlikely(!filp)) {
54033 + task->role = kernel_role;
54034 + task->acl = kernel_role->root_label;
54035 + return;
54036 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54037 + role = lookup_acl_role_label(task, uid, gid);
54038 +
54039 + /* don't change the role if we're not a privileged process */
54040 + if (role && task->role != role &&
54041 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54042 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54043 + return;
54044 +
54045 + /* perform subject lookup in possibly new role
54046 + we can use this result below in the case where role == task->role
54047 + */
54048 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54049 +
54050 + /* if we changed uid/gid, but result in the same role
54051 + and are using inheritance, don't lose the inherited subject
54052 + if current subject is other than what normal lookup
54053 + would result in, we arrived via inheritance, don't
54054 + lose subject
54055 + */
54056 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54057 + (subj == task->acl)))
54058 + task->acl = subj;
54059 +
54060 + task->role = role;
54061 +
54062 + task->is_writable = 0;
54063 +
54064 + /* ignore additional mmap checks for processes that are writable
54065 + by the default ACL */
54066 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54067 + if (unlikely(obj->mode & GR_WRITE))
54068 + task->is_writable = 1;
54069 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54070 + if (unlikely(obj->mode & GR_WRITE))
54071 + task->is_writable = 1;
54072 +
54073 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54074 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54075 +#endif
54076 +
54077 + gr_set_proc_res(task);
54078 +
54079 + return;
54080 +}
54081 +
54082 +int
54083 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54084 + const int unsafe_flags)
54085 +{
54086 + struct task_struct *task = current;
54087 + struct acl_subject_label *newacl;
54088 + struct acl_object_label *obj;
54089 + __u32 retmode;
54090 +
54091 + if (unlikely(!(gr_status & GR_READY)))
54092 + return 0;
54093 +
54094 + newacl = chk_subj_label(dentry, mnt, task->role);
54095 +
54096 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54097 + did an exec
54098 + */
54099 + rcu_read_lock();
54100 + read_lock(&tasklist_lock);
54101 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54102 + (task->parent->acl->mode & GR_POVERRIDE))) {
54103 + read_unlock(&tasklist_lock);
54104 + rcu_read_unlock();
54105 + goto skip_check;
54106 + }
54107 + read_unlock(&tasklist_lock);
54108 + rcu_read_unlock();
54109 +
54110 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54111 + !(task->role->roletype & GR_ROLE_GOD) &&
54112 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54113 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54114 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54115 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54116 + else
54117 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54118 + return -EACCES;
54119 + }
54120 +
54121 +skip_check:
54122 +
54123 + obj = chk_obj_label(dentry, mnt, task->acl);
54124 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54125 +
54126 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54127 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54128 + if (obj->nested)
54129 + task->acl = obj->nested;
54130 + else
54131 + task->acl = newacl;
54132 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54133 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54134 +
54135 + task->is_writable = 0;
54136 +
54137 + /* ignore additional mmap checks for processes that are writable
54138 + by the default ACL */
54139 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54140 + if (unlikely(obj->mode & GR_WRITE))
54141 + task->is_writable = 1;
54142 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54143 + if (unlikely(obj->mode & GR_WRITE))
54144 + task->is_writable = 1;
54145 +
54146 + gr_set_proc_res(task);
54147 +
54148 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54149 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54150 +#endif
54151 + return 0;
54152 +}
54153 +
54154 +/* always called with valid inodev ptr */
54155 +static void
54156 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54157 +{
54158 + struct acl_object_label *matchpo;
54159 + struct acl_subject_label *matchps;
54160 + struct acl_subject_label *subj;
54161 + struct acl_role_label *role;
54162 + unsigned int x;
54163 +
54164 + FOR_EACH_ROLE_START(role)
54165 + FOR_EACH_SUBJECT_START(role, subj, x)
54166 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54167 + matchpo->mode |= GR_DELETED;
54168 + FOR_EACH_SUBJECT_END(subj,x)
54169 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54170 + /* nested subjects aren't in the role's subj_hash table */
54171 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54172 + matchpo->mode |= GR_DELETED;
54173 + FOR_EACH_NESTED_SUBJECT_END(subj)
54174 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54175 + matchps->mode |= GR_DELETED;
54176 + FOR_EACH_ROLE_END(role)
54177 +
54178 + inodev->nentry->deleted = 1;
54179 +
54180 + return;
54181 +}
54182 +
54183 +void
54184 +gr_handle_delete(const ino_t ino, const dev_t dev)
54185 +{
54186 + struct inodev_entry *inodev;
54187 +
54188 + if (unlikely(!(gr_status & GR_READY)))
54189 + return;
54190 +
54191 + write_lock(&gr_inode_lock);
54192 + inodev = lookup_inodev_entry(ino, dev);
54193 + if (inodev != NULL)
54194 + do_handle_delete(inodev, ino, dev);
54195 + write_unlock(&gr_inode_lock);
54196 +
54197 + return;
54198 +}
54199 +
54200 +static void
54201 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54202 + const ino_t newinode, const dev_t newdevice,
54203 + struct acl_subject_label *subj)
54204 +{
54205 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54206 + struct acl_object_label *match;
54207 +
54208 + match = subj->obj_hash[index];
54209 +
54210 + while (match && (match->inode != oldinode ||
54211 + match->device != olddevice ||
54212 + !(match->mode & GR_DELETED)))
54213 + match = match->next;
54214 +
54215 + if (match && (match->inode == oldinode)
54216 + && (match->device == olddevice)
54217 + && (match->mode & GR_DELETED)) {
54218 + if (match->prev == NULL) {
54219 + subj->obj_hash[index] = match->next;
54220 + if (match->next != NULL)
54221 + match->next->prev = NULL;
54222 + } else {
54223 + match->prev->next = match->next;
54224 + if (match->next != NULL)
54225 + match->next->prev = match->prev;
54226 + }
54227 + match->prev = NULL;
54228 + match->next = NULL;
54229 + match->inode = newinode;
54230 + match->device = newdevice;
54231 + match->mode &= ~GR_DELETED;
54232 +
54233 + insert_acl_obj_label(match, subj);
54234 + }
54235 +
54236 + return;
54237 +}
54238 +
54239 +static void
54240 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54241 + const ino_t newinode, const dev_t newdevice,
54242 + struct acl_role_label *role)
54243 +{
54244 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54245 + struct acl_subject_label *match;
54246 +
54247 + match = role->subj_hash[index];
54248 +
54249 + while (match && (match->inode != oldinode ||
54250 + match->device != olddevice ||
54251 + !(match->mode & GR_DELETED)))
54252 + match = match->next;
54253 +
54254 + if (match && (match->inode == oldinode)
54255 + && (match->device == olddevice)
54256 + && (match->mode & GR_DELETED)) {
54257 + if (match->prev == NULL) {
54258 + role->subj_hash[index] = match->next;
54259 + if (match->next != NULL)
54260 + match->next->prev = NULL;
54261 + } else {
54262 + match->prev->next = match->next;
54263 + if (match->next != NULL)
54264 + match->next->prev = match->prev;
54265 + }
54266 + match->prev = NULL;
54267 + match->next = NULL;
54268 + match->inode = newinode;
54269 + match->device = newdevice;
54270 + match->mode &= ~GR_DELETED;
54271 +
54272 + insert_acl_subj_label(match, role);
54273 + }
54274 +
54275 + return;
54276 +}
54277 +
54278 +static void
54279 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54280 + const ino_t newinode, const dev_t newdevice)
54281 +{
54282 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54283 + struct inodev_entry *match;
54284 +
54285 + match = inodev_set.i_hash[index];
54286 +
54287 + while (match && (match->nentry->inode != oldinode ||
54288 + match->nentry->device != olddevice || !match->nentry->deleted))
54289 + match = match->next;
54290 +
54291 + if (match && (match->nentry->inode == oldinode)
54292 + && (match->nentry->device == olddevice) &&
54293 + match->nentry->deleted) {
54294 + if (match->prev == NULL) {
54295 + inodev_set.i_hash[index] = match->next;
54296 + if (match->next != NULL)
54297 + match->next->prev = NULL;
54298 + } else {
54299 + match->prev->next = match->next;
54300 + if (match->next != NULL)
54301 + match->next->prev = match->prev;
54302 + }
54303 + match->prev = NULL;
54304 + match->next = NULL;
54305 + match->nentry->inode = newinode;
54306 + match->nentry->device = newdevice;
54307 + match->nentry->deleted = 0;
54308 +
54309 + insert_inodev_entry(match);
54310 + }
54311 +
54312 + return;
54313 +}
54314 +
54315 +static void
54316 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54317 +{
54318 + struct acl_subject_label *subj;
54319 + struct acl_role_label *role;
54320 + unsigned int x;
54321 +
54322 + FOR_EACH_ROLE_START(role)
54323 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54324 +
54325 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54326 + if ((subj->inode == ino) && (subj->device == dev)) {
54327 + subj->inode = ino;
54328 + subj->device = dev;
54329 + }
54330 + /* nested subjects aren't in the role's subj_hash table */
54331 + update_acl_obj_label(matchn->inode, matchn->device,
54332 + ino, dev, subj);
54333 + FOR_EACH_NESTED_SUBJECT_END(subj)
54334 + FOR_EACH_SUBJECT_START(role, subj, x)
54335 + update_acl_obj_label(matchn->inode, matchn->device,
54336 + ino, dev, subj);
54337 + FOR_EACH_SUBJECT_END(subj,x)
54338 + FOR_EACH_ROLE_END(role)
54339 +
54340 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54341 +
54342 + return;
54343 +}
54344 +
54345 +static void
54346 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54347 + const struct vfsmount *mnt)
54348 +{
54349 + ino_t ino = dentry->d_inode->i_ino;
54350 + dev_t dev = __get_dev(dentry);
54351 +
54352 + __do_handle_create(matchn, ino, dev);
54353 +
54354 + return;
54355 +}
54356 +
54357 +void
54358 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54359 +{
54360 + struct name_entry *matchn;
54361 +
54362 + if (unlikely(!(gr_status & GR_READY)))
54363 + return;
54364 +
54365 + preempt_disable();
54366 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54367 +
54368 + if (unlikely((unsigned long)matchn)) {
54369 + write_lock(&gr_inode_lock);
54370 + do_handle_create(matchn, dentry, mnt);
54371 + write_unlock(&gr_inode_lock);
54372 + }
54373 + preempt_enable();
54374 +
54375 + return;
54376 +}
54377 +
54378 +void
54379 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54380 +{
54381 + struct name_entry *matchn;
54382 +
54383 + if (unlikely(!(gr_status & GR_READY)))
54384 + return;
54385 +
54386 + preempt_disable();
54387 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54388 +
54389 + if (unlikely((unsigned long)matchn)) {
54390 + write_lock(&gr_inode_lock);
54391 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54392 + write_unlock(&gr_inode_lock);
54393 + }
54394 + preempt_enable();
54395 +
54396 + return;
54397 +}
54398 +
54399 +void
54400 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54401 + struct dentry *old_dentry,
54402 + struct dentry *new_dentry,
54403 + struct vfsmount *mnt, const __u8 replace)
54404 +{
54405 + struct name_entry *matchn;
54406 + struct inodev_entry *inodev;
54407 + struct inode *inode = new_dentry->d_inode;
54408 + ino_t old_ino = old_dentry->d_inode->i_ino;
54409 + dev_t old_dev = __get_dev(old_dentry);
54410 +
54411 + /* vfs_rename swaps the name and parent link for old_dentry and
54412 + new_dentry
54413 + at this point, old_dentry has the new name, parent link, and inode
54414 + for the renamed file
54415 + if a file is being replaced by a rename, new_dentry has the inode
54416 + and name for the replaced file
54417 + */
54418 +
54419 + if (unlikely(!(gr_status & GR_READY)))
54420 + return;
54421 +
54422 + preempt_disable();
54423 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54424 +
54425 + /* we wouldn't have to check d_inode if it weren't for
54426 + NFS silly-renaming
54427 + */
54428 +
54429 + write_lock(&gr_inode_lock);
54430 + if (unlikely(replace && inode)) {
54431 + ino_t new_ino = inode->i_ino;
54432 + dev_t new_dev = __get_dev(new_dentry);
54433 +
54434 + inodev = lookup_inodev_entry(new_ino, new_dev);
54435 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54436 + do_handle_delete(inodev, new_ino, new_dev);
54437 + }
54438 +
54439 + inodev = lookup_inodev_entry(old_ino, old_dev);
54440 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54441 + do_handle_delete(inodev, old_ino, old_dev);
54442 +
54443 + if (unlikely((unsigned long)matchn))
54444 + do_handle_create(matchn, old_dentry, mnt);
54445 +
54446 + write_unlock(&gr_inode_lock);
54447 + preempt_enable();
54448 +
54449 + return;
54450 +}
54451 +
54452 +static int
54453 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54454 + unsigned char **sum)
54455 +{
54456 + struct acl_role_label *r;
54457 + struct role_allowed_ip *ipp;
54458 + struct role_transition *trans;
54459 + unsigned int i;
54460 + int found = 0;
54461 + u32 curr_ip = current->signal->curr_ip;
54462 +
54463 + current->signal->saved_ip = curr_ip;
54464 +
54465 + /* check transition table */
54466 +
54467 + for (trans = current->role->transitions; trans; trans = trans->next) {
54468 + if (!strcmp(rolename, trans->rolename)) {
54469 + found = 1;
54470 + break;
54471 + }
54472 + }
54473 +
54474 + if (!found)
54475 + return 0;
54476 +
54477 + /* handle special roles that do not require authentication
54478 + and check ip */
54479 +
54480 + FOR_EACH_ROLE_START(r)
54481 + if (!strcmp(rolename, r->rolename) &&
54482 + (r->roletype & GR_ROLE_SPECIAL)) {
54483 + found = 0;
54484 + if (r->allowed_ips != NULL) {
54485 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54486 + if ((ntohl(curr_ip) & ipp->netmask) ==
54487 + (ntohl(ipp->addr) & ipp->netmask))
54488 + found = 1;
54489 + }
54490 + } else
54491 + found = 2;
54492 + if (!found)
54493 + return 0;
54494 +
54495 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54496 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54497 + *salt = NULL;
54498 + *sum = NULL;
54499 + return 1;
54500 + }
54501 + }
54502 + FOR_EACH_ROLE_END(r)
54503 +
54504 + for (i = 0; i < num_sprole_pws; i++) {
54505 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54506 + *salt = acl_special_roles[i]->salt;
54507 + *sum = acl_special_roles[i]->sum;
54508 + return 1;
54509 + }
54510 + }
54511 +
54512 + return 0;
54513 +}
54514 +
54515 +static void
54516 +assign_special_role(char *rolename)
54517 +{
54518 + struct acl_object_label *obj;
54519 + struct acl_role_label *r;
54520 + struct acl_role_label *assigned = NULL;
54521 + struct task_struct *tsk;
54522 + struct file *filp;
54523 +
54524 + FOR_EACH_ROLE_START(r)
54525 + if (!strcmp(rolename, r->rolename) &&
54526 + (r->roletype & GR_ROLE_SPECIAL)) {
54527 + assigned = r;
54528 + break;
54529 + }
54530 + FOR_EACH_ROLE_END(r)
54531 +
54532 + if (!assigned)
54533 + return;
54534 +
54535 + read_lock(&tasklist_lock);
54536 + read_lock(&grsec_exec_file_lock);
54537 +
54538 + tsk = current->real_parent;
54539 + if (tsk == NULL)
54540 + goto out_unlock;
54541 +
54542 + filp = tsk->exec_file;
54543 + if (filp == NULL)
54544 + goto out_unlock;
54545 +
54546 + tsk->is_writable = 0;
54547 +
54548 + tsk->acl_sp_role = 1;
54549 + tsk->acl_role_id = ++acl_sp_role_value;
54550 + tsk->role = assigned;
54551 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54552 +
54553 + /* ignore additional mmap checks for processes that are writable
54554 + by the default ACL */
54555 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54556 + if (unlikely(obj->mode & GR_WRITE))
54557 + tsk->is_writable = 1;
54558 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54559 + if (unlikely(obj->mode & GR_WRITE))
54560 + tsk->is_writable = 1;
54561 +
54562 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54563 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54564 +#endif
54565 +
54566 +out_unlock:
54567 + read_unlock(&grsec_exec_file_lock);
54568 + read_unlock(&tasklist_lock);
54569 + return;
54570 +}
54571 +
54572 +int gr_check_secure_terminal(struct task_struct *task)
54573 +{
54574 + struct task_struct *p, *p2, *p3;
54575 + struct files_struct *files;
54576 + struct fdtable *fdt;
54577 + struct file *our_file = NULL, *file;
54578 + int i;
54579 +
54580 + if (task->signal->tty == NULL)
54581 + return 1;
54582 +
54583 + files = get_files_struct(task);
54584 + if (files != NULL) {
54585 + rcu_read_lock();
54586 + fdt = files_fdtable(files);
54587 + for (i=0; i < fdt->max_fds; i++) {
54588 + file = fcheck_files(files, i);
54589 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54590 + get_file(file);
54591 + our_file = file;
54592 + }
54593 + }
54594 + rcu_read_unlock();
54595 + put_files_struct(files);
54596 + }
54597 +
54598 + if (our_file == NULL)
54599 + return 1;
54600 +
54601 + read_lock(&tasklist_lock);
54602 + do_each_thread(p2, p) {
54603 + files = get_files_struct(p);
54604 + if (files == NULL ||
54605 + (p->signal && p->signal->tty == task->signal->tty)) {
54606 + if (files != NULL)
54607 + put_files_struct(files);
54608 + continue;
54609 + }
54610 + rcu_read_lock();
54611 + fdt = files_fdtable(files);
54612 + for (i=0; i < fdt->max_fds; i++) {
54613 + file = fcheck_files(files, i);
54614 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54615 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54616 + p3 = task;
54617 + while (p3->pid > 0) {
54618 + if (p3 == p)
54619 + break;
54620 + p3 = p3->real_parent;
54621 + }
54622 + if (p3 == p)
54623 + break;
54624 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54625 + gr_handle_alertkill(p);
54626 + rcu_read_unlock();
54627 + put_files_struct(files);
54628 + read_unlock(&tasklist_lock);
54629 + fput(our_file);
54630 + return 0;
54631 + }
54632 + }
54633 + rcu_read_unlock();
54634 + put_files_struct(files);
54635 + } while_each_thread(p2, p);
54636 + read_unlock(&tasklist_lock);
54637 +
54638 + fput(our_file);
54639 + return 1;
54640 +}
54641 +
54642 +static int gr_rbac_disable(void *unused)
54643 +{
54644 + pax_open_kernel();
54645 + gr_status &= ~GR_READY;
54646 + pax_close_kernel();
54647 +
54648 + return 0;
54649 +}
54650 +
54651 +ssize_t
54652 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54653 +{
54654 + struct gr_arg_wrapper uwrap;
54655 + unsigned char *sprole_salt = NULL;
54656 + unsigned char *sprole_sum = NULL;
54657 + int error = sizeof (struct gr_arg_wrapper);
54658 + int error2 = 0;
54659 +
54660 + mutex_lock(&gr_dev_mutex);
54661 +
54662 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54663 + error = -EPERM;
54664 + goto out;
54665 + }
54666 +
54667 + if (count != sizeof (struct gr_arg_wrapper)) {
54668 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54669 + error = -EINVAL;
54670 + goto out;
54671 + }
54672 +
54673 +
54674 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54675 + gr_auth_expires = 0;
54676 + gr_auth_attempts = 0;
54677 + }
54678 +
54679 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54680 + error = -EFAULT;
54681 + goto out;
54682 + }
54683 +
54684 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54685 + error = -EINVAL;
54686 + goto out;
54687 + }
54688 +
54689 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54690 + error = -EFAULT;
54691 + goto out;
54692 + }
54693 +
54694 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54695 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54696 + time_after(gr_auth_expires, get_seconds())) {
54697 + error = -EBUSY;
54698 + goto out;
54699 + }
54700 +
54701 + /* if non-root trying to do anything other than use a special role,
54702 + do not attempt authentication, do not count towards authentication
54703 + locking
54704 + */
54705 +
54706 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54707 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54708 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54709 + error = -EPERM;
54710 + goto out;
54711 + }
54712 +
54713 + /* ensure pw and special role name are null terminated */
54714 +
54715 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54716 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54717 +
54718 + /* Okay.
54719 + * We have our enough of the argument structure..(we have yet
54720 + * to copy_from_user the tables themselves) . Copy the tables
54721 + * only if we need them, i.e. for loading operations. */
54722 +
54723 + switch (gr_usermode->mode) {
54724 + case GR_STATUS:
54725 + if (gr_status & GR_READY) {
54726 + error = 1;
54727 + if (!gr_check_secure_terminal(current))
54728 + error = 3;
54729 + } else
54730 + error = 2;
54731 + goto out;
54732 + case GR_SHUTDOWN:
54733 + if ((gr_status & GR_READY)
54734 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54735 + stop_machine(gr_rbac_disable, NULL, NULL);
54736 + free_variables();
54737 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54738 + memset(gr_system_salt, 0, GR_SALT_LEN);
54739 + memset(gr_system_sum, 0, GR_SHA_LEN);
54740 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54741 + } else if (gr_status & GR_READY) {
54742 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54743 + error = -EPERM;
54744 + } else {
54745 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54746 + error = -EAGAIN;
54747 + }
54748 + break;
54749 + case GR_ENABLE:
54750 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54751 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54752 + else {
54753 + if (gr_status & GR_READY)
54754 + error = -EAGAIN;
54755 + else
54756 + error = error2;
54757 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54758 + }
54759 + break;
54760 + case GR_RELOAD:
54761 + if (!(gr_status & GR_READY)) {
54762 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54763 + error = -EAGAIN;
54764 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54765 + stop_machine(gr_rbac_disable, NULL, NULL);
54766 + free_variables();
54767 + error2 = gracl_init(gr_usermode);
54768 + if (!error2)
54769 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54770 + else {
54771 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54772 + error = error2;
54773 + }
54774 + } else {
54775 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54776 + error = -EPERM;
54777 + }
54778 + break;
54779 + case GR_SEGVMOD:
54780 + if (unlikely(!(gr_status & GR_READY))) {
54781 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54782 + error = -EAGAIN;
54783 + break;
54784 + }
54785 +
54786 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54787 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54788 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54789 + struct acl_subject_label *segvacl;
54790 + segvacl =
54791 + lookup_acl_subj_label(gr_usermode->segv_inode,
54792 + gr_usermode->segv_device,
54793 + current->role);
54794 + if (segvacl) {
54795 + segvacl->crashes = 0;
54796 + segvacl->expires = 0;
54797 + }
54798 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54799 + gr_remove_uid(gr_usermode->segv_uid);
54800 + }
54801 + } else {
54802 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54803 + error = -EPERM;
54804 + }
54805 + break;
54806 + case GR_SPROLE:
54807 + case GR_SPROLEPAM:
54808 + if (unlikely(!(gr_status & GR_READY))) {
54809 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54810 + error = -EAGAIN;
54811 + break;
54812 + }
54813 +
54814 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54815 + current->role->expires = 0;
54816 + current->role->auth_attempts = 0;
54817 + }
54818 +
54819 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54820 + time_after(current->role->expires, get_seconds())) {
54821 + error = -EBUSY;
54822 + goto out;
54823 + }
54824 +
54825 + if (lookup_special_role_auth
54826 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54827 + && ((!sprole_salt && !sprole_sum)
54828 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54829 + char *p = "";
54830 + assign_special_role(gr_usermode->sp_role);
54831 + read_lock(&tasklist_lock);
54832 + if (current->real_parent)
54833 + p = current->real_parent->role->rolename;
54834 + read_unlock(&tasklist_lock);
54835 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54836 + p, acl_sp_role_value);
54837 + } else {
54838 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54839 + error = -EPERM;
54840 + if(!(current->role->auth_attempts++))
54841 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54842 +
54843 + goto out;
54844 + }
54845 + break;
54846 + case GR_UNSPROLE:
54847 + if (unlikely(!(gr_status & GR_READY))) {
54848 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54849 + error = -EAGAIN;
54850 + break;
54851 + }
54852 +
54853 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54854 + char *p = "";
54855 + int i = 0;
54856 +
54857 + read_lock(&tasklist_lock);
54858 + if (current->real_parent) {
54859 + p = current->real_parent->role->rolename;
54860 + i = current->real_parent->acl_role_id;
54861 + }
54862 + read_unlock(&tasklist_lock);
54863 +
54864 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54865 + gr_set_acls(1);
54866 + } else {
54867 + error = -EPERM;
54868 + goto out;
54869 + }
54870 + break;
54871 + default:
54872 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54873 + error = -EINVAL;
54874 + break;
54875 + }
54876 +
54877 + if (error != -EPERM)
54878 + goto out;
54879 +
54880 + if(!(gr_auth_attempts++))
54881 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54882 +
54883 + out:
54884 + mutex_unlock(&gr_dev_mutex);
54885 + return error;
54886 +}
54887 +
54888 +/* must be called with
54889 + rcu_read_lock();
54890 + read_lock(&tasklist_lock);
54891 + read_lock(&grsec_exec_file_lock);
54892 +*/
54893 +int gr_apply_subject_to_task(struct task_struct *task)
54894 +{
54895 + struct acl_object_label *obj;
54896 + char *tmpname;
54897 + struct acl_subject_label *tmpsubj;
54898 + struct file *filp;
54899 + struct name_entry *nmatch;
54900 +
54901 + filp = task->exec_file;
54902 + if (filp == NULL)
54903 + return 0;
54904 +
54905 + /* the following is to apply the correct subject
54906 + on binaries running when the RBAC system
54907 + is enabled, when the binaries have been
54908 + replaced or deleted since their execution
54909 + -----
54910 + when the RBAC system starts, the inode/dev
54911 + from exec_file will be one the RBAC system
54912 + is unaware of. It only knows the inode/dev
54913 + of the present file on disk, or the absence
54914 + of it.
54915 + */
54916 + preempt_disable();
54917 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54918 +
54919 + nmatch = lookup_name_entry(tmpname);
54920 + preempt_enable();
54921 + tmpsubj = NULL;
54922 + if (nmatch) {
54923 + if (nmatch->deleted)
54924 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54925 + else
54926 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54927 + if (tmpsubj != NULL)
54928 + task->acl = tmpsubj;
54929 + }
54930 + if (tmpsubj == NULL)
54931 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54932 + task->role);
54933 + if (task->acl) {
54934 + task->is_writable = 0;
54935 + /* ignore additional mmap checks for processes that are writable
54936 + by the default ACL */
54937 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54938 + if (unlikely(obj->mode & GR_WRITE))
54939 + task->is_writable = 1;
54940 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54941 + if (unlikely(obj->mode & GR_WRITE))
54942 + task->is_writable = 1;
54943 +
54944 + gr_set_proc_res(task);
54945 +
54946 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54947 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54948 +#endif
54949 + } else {
54950 + return 1;
54951 + }
54952 +
54953 + return 0;
54954 +}
54955 +
54956 +int
54957 +gr_set_acls(const int type)
54958 +{
54959 + struct task_struct *task, *task2;
54960 + struct acl_role_label *role = current->role;
54961 + __u16 acl_role_id = current->acl_role_id;
54962 + const struct cred *cred;
54963 + int ret;
54964 +
54965 + rcu_read_lock();
54966 + read_lock(&tasklist_lock);
54967 + read_lock(&grsec_exec_file_lock);
54968 + do_each_thread(task2, task) {
54969 + /* check to see if we're called from the exit handler,
54970 + if so, only replace ACLs that have inherited the admin
54971 + ACL */
54972 +
54973 + if (type && (task->role != role ||
54974 + task->acl_role_id != acl_role_id))
54975 + continue;
54976 +
54977 + task->acl_role_id = 0;
54978 + task->acl_sp_role = 0;
54979 +
54980 + if (task->exec_file) {
54981 + cred = __task_cred(task);
54982 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54983 + ret = gr_apply_subject_to_task(task);
54984 + if (ret) {
54985 + read_unlock(&grsec_exec_file_lock);
54986 + read_unlock(&tasklist_lock);
54987 + rcu_read_unlock();
54988 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54989 + return ret;
54990 + }
54991 + } else {
54992 + // it's a kernel process
54993 + task->role = kernel_role;
54994 + task->acl = kernel_role->root_label;
54995 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54996 + task->acl->mode &= ~GR_PROCFIND;
54997 +#endif
54998 + }
54999 + } while_each_thread(task2, task);
55000 + read_unlock(&grsec_exec_file_lock);
55001 + read_unlock(&tasklist_lock);
55002 + rcu_read_unlock();
55003 +
55004 + return 0;
55005 +}
55006 +
55007 +void
55008 +gr_learn_resource(const struct task_struct *task,
55009 + const int res, const unsigned long wanted, const int gt)
55010 +{
55011 + struct acl_subject_label *acl;
55012 + const struct cred *cred;
55013 +
55014 + if (unlikely((gr_status & GR_READY) &&
55015 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55016 + goto skip_reslog;
55017 +
55018 +#ifdef CONFIG_GRKERNSEC_RESLOG
55019 + gr_log_resource(task, res, wanted, gt);
55020 +#endif
55021 + skip_reslog:
55022 +
55023 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55024 + return;
55025 +
55026 + acl = task->acl;
55027 +
55028 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55029 + !(acl->resmask & (1 << (unsigned short) res))))
55030 + return;
55031 +
55032 + if (wanted >= acl->res[res].rlim_cur) {
55033 + unsigned long res_add;
55034 +
55035 + res_add = wanted;
55036 + switch (res) {
55037 + case RLIMIT_CPU:
55038 + res_add += GR_RLIM_CPU_BUMP;
55039 + break;
55040 + case RLIMIT_FSIZE:
55041 + res_add += GR_RLIM_FSIZE_BUMP;
55042 + break;
55043 + case RLIMIT_DATA:
55044 + res_add += GR_RLIM_DATA_BUMP;
55045 + break;
55046 + case RLIMIT_STACK:
55047 + res_add += GR_RLIM_STACK_BUMP;
55048 + break;
55049 + case RLIMIT_CORE:
55050 + res_add += GR_RLIM_CORE_BUMP;
55051 + break;
55052 + case RLIMIT_RSS:
55053 + res_add += GR_RLIM_RSS_BUMP;
55054 + break;
55055 + case RLIMIT_NPROC:
55056 + res_add += GR_RLIM_NPROC_BUMP;
55057 + break;
55058 + case RLIMIT_NOFILE:
55059 + res_add += GR_RLIM_NOFILE_BUMP;
55060 + break;
55061 + case RLIMIT_MEMLOCK:
55062 + res_add += GR_RLIM_MEMLOCK_BUMP;
55063 + break;
55064 + case RLIMIT_AS:
55065 + res_add += GR_RLIM_AS_BUMP;
55066 + break;
55067 + case RLIMIT_LOCKS:
55068 + res_add += GR_RLIM_LOCKS_BUMP;
55069 + break;
55070 + case RLIMIT_SIGPENDING:
55071 + res_add += GR_RLIM_SIGPENDING_BUMP;
55072 + break;
55073 + case RLIMIT_MSGQUEUE:
55074 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55075 + break;
55076 + case RLIMIT_NICE:
55077 + res_add += GR_RLIM_NICE_BUMP;
55078 + break;
55079 + case RLIMIT_RTPRIO:
55080 + res_add += GR_RLIM_RTPRIO_BUMP;
55081 + break;
55082 + case RLIMIT_RTTIME:
55083 + res_add += GR_RLIM_RTTIME_BUMP;
55084 + break;
55085 + }
55086 +
55087 + acl->res[res].rlim_cur = res_add;
55088 +
55089 + if (wanted > acl->res[res].rlim_max)
55090 + acl->res[res].rlim_max = res_add;
55091 +
55092 + /* only log the subject filename, since resource logging is supported for
55093 + single-subject learning only */
55094 + rcu_read_lock();
55095 + cred = __task_cred(task);
55096 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55097 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55098 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55099 + "", (unsigned long) res, &task->signal->saved_ip);
55100 + rcu_read_unlock();
55101 + }
55102 +
55103 + return;
55104 +}
55105 +
55106 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55107 +void
55108 +pax_set_initial_flags(struct linux_binprm *bprm)
55109 +{
55110 + struct task_struct *task = current;
55111 + struct acl_subject_label *proc;
55112 + unsigned long flags;
55113 +
55114 + if (unlikely(!(gr_status & GR_READY)))
55115 + return;
55116 +
55117 + flags = pax_get_flags(task);
55118 +
55119 + proc = task->acl;
55120 +
55121 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55122 + flags &= ~MF_PAX_PAGEEXEC;
55123 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55124 + flags &= ~MF_PAX_SEGMEXEC;
55125 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55126 + flags &= ~MF_PAX_RANDMMAP;
55127 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55128 + flags &= ~MF_PAX_EMUTRAMP;
55129 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55130 + flags &= ~MF_PAX_MPROTECT;
55131 +
55132 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55133 + flags |= MF_PAX_PAGEEXEC;
55134 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55135 + flags |= MF_PAX_SEGMEXEC;
55136 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55137 + flags |= MF_PAX_RANDMMAP;
55138 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55139 + flags |= MF_PAX_EMUTRAMP;
55140 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55141 + flags |= MF_PAX_MPROTECT;
55142 +
55143 + pax_set_flags(task, flags);
55144 +
55145 + return;
55146 +}
55147 +#endif
55148 +
55149 +int
55150 +gr_handle_proc_ptrace(struct task_struct *task)
55151 +{
55152 + struct file *filp;
55153 + struct task_struct *tmp = task;
55154 + struct task_struct *curtemp = current;
55155 + __u32 retmode;
55156 +
55157 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55158 + if (unlikely(!(gr_status & GR_READY)))
55159 + return 0;
55160 +#endif
55161 +
55162 + read_lock(&tasklist_lock);
55163 + read_lock(&grsec_exec_file_lock);
55164 + filp = task->exec_file;
55165 +
55166 + while (tmp->pid > 0) {
55167 + if (tmp == curtemp)
55168 + break;
55169 + tmp = tmp->real_parent;
55170 + }
55171 +
55172 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55173 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55174 + read_unlock(&grsec_exec_file_lock);
55175 + read_unlock(&tasklist_lock);
55176 + return 1;
55177 + }
55178 +
55179 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55180 + if (!(gr_status & GR_READY)) {
55181 + read_unlock(&grsec_exec_file_lock);
55182 + read_unlock(&tasklist_lock);
55183 + return 0;
55184 + }
55185 +#endif
55186 +
55187 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55188 + read_unlock(&grsec_exec_file_lock);
55189 + read_unlock(&tasklist_lock);
55190 +
55191 + if (retmode & GR_NOPTRACE)
55192 + return 1;
55193 +
55194 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55195 + && (current->acl != task->acl || (current->acl != current->role->root_label
55196 + && current->pid != task->pid)))
55197 + return 1;
55198 +
55199 + return 0;
55200 +}
55201 +
55202 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55203 +{
55204 + if (unlikely(!(gr_status & GR_READY)))
55205 + return;
55206 +
55207 + if (!(current->role->roletype & GR_ROLE_GOD))
55208 + return;
55209 +
55210 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55211 + p->role->rolename, gr_task_roletype_to_char(p),
55212 + p->acl->filename);
55213 +}
55214 +
55215 +int
55216 +gr_handle_ptrace(struct task_struct *task, const long request)
55217 +{
55218 + struct task_struct *tmp = task;
55219 + struct task_struct *curtemp = current;
55220 + __u32 retmode;
55221 +
55222 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55223 + if (unlikely(!(gr_status & GR_READY)))
55224 + return 0;
55225 +#endif
55226 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55227 + read_lock(&tasklist_lock);
55228 + while (tmp->pid > 0) {
55229 + if (tmp == curtemp)
55230 + break;
55231 + tmp = tmp->real_parent;
55232 + }
55233 +
55234 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55235 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55236 + read_unlock(&tasklist_lock);
55237 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55238 + return 1;
55239 + }
55240 + read_unlock(&tasklist_lock);
55241 + }
55242 +
55243 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55244 + if (!(gr_status & GR_READY))
55245 + return 0;
55246 +#endif
55247 +
55248 + read_lock(&grsec_exec_file_lock);
55249 + if (unlikely(!task->exec_file)) {
55250 + read_unlock(&grsec_exec_file_lock);
55251 + return 0;
55252 + }
55253 +
55254 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55255 + read_unlock(&grsec_exec_file_lock);
55256 +
55257 + if (retmode & GR_NOPTRACE) {
55258 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55259 + return 1;
55260 + }
55261 +
55262 + if (retmode & GR_PTRACERD) {
55263 + switch (request) {
55264 + case PTRACE_SEIZE:
55265 + case PTRACE_POKETEXT:
55266 + case PTRACE_POKEDATA:
55267 + case PTRACE_POKEUSR:
55268 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55269 + case PTRACE_SETREGS:
55270 + case PTRACE_SETFPREGS:
55271 +#endif
55272 +#ifdef CONFIG_X86
55273 + case PTRACE_SETFPXREGS:
55274 +#endif
55275 +#ifdef CONFIG_ALTIVEC
55276 + case PTRACE_SETVRREGS:
55277 +#endif
55278 + return 1;
55279 + default:
55280 + return 0;
55281 + }
55282 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55283 + !(current->role->roletype & GR_ROLE_GOD) &&
55284 + (current->acl != task->acl)) {
55285 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55286 + return 1;
55287 + }
55288 +
55289 + return 0;
55290 +}
55291 +
55292 +static int is_writable_mmap(const struct file *filp)
55293 +{
55294 + struct task_struct *task = current;
55295 + struct acl_object_label *obj, *obj2;
55296 +
55297 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55298 + !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))) {
55299 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55300 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55301 + task->role->root_label);
55302 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55303 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55304 + return 1;
55305 + }
55306 + }
55307 + return 0;
55308 +}
55309 +
55310 +int
55311 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55312 +{
55313 + __u32 mode;
55314 +
55315 + if (unlikely(!file || !(prot & PROT_EXEC)))
55316 + return 1;
55317 +
55318 + if (is_writable_mmap(file))
55319 + return 0;
55320 +
55321 + mode =
55322 + gr_search_file(file->f_path.dentry,
55323 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55324 + file->f_path.mnt);
55325 +
55326 + if (!gr_tpe_allow(file))
55327 + return 0;
55328 +
55329 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55330 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55331 + return 0;
55332 + } else if (unlikely(!(mode & GR_EXEC))) {
55333 + return 0;
55334 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55335 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55336 + return 1;
55337 + }
55338 +
55339 + return 1;
55340 +}
55341 +
55342 +int
55343 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55344 +{
55345 + __u32 mode;
55346 +
55347 + if (unlikely(!file || !(prot & PROT_EXEC)))
55348 + return 1;
55349 +
55350 + if (is_writable_mmap(file))
55351 + return 0;
55352 +
55353 + mode =
55354 + gr_search_file(file->f_path.dentry,
55355 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55356 + file->f_path.mnt);
55357 +
55358 + if (!gr_tpe_allow(file))
55359 + return 0;
55360 +
55361 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55362 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55363 + return 0;
55364 + } else if (unlikely(!(mode & GR_EXEC))) {
55365 + return 0;
55366 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55367 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55368 + return 1;
55369 + }
55370 +
55371 + return 1;
55372 +}
55373 +
55374 +void
55375 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55376 +{
55377 + unsigned long runtime;
55378 + unsigned long cputime;
55379 + unsigned int wday, cday;
55380 + __u8 whr, chr;
55381 + __u8 wmin, cmin;
55382 + __u8 wsec, csec;
55383 + struct timespec timeval;
55384 +
55385 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55386 + !(task->acl->mode & GR_PROCACCT)))
55387 + return;
55388 +
55389 + do_posix_clock_monotonic_gettime(&timeval);
55390 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55391 + wday = runtime / (3600 * 24);
55392 + runtime -= wday * (3600 * 24);
55393 + whr = runtime / 3600;
55394 + runtime -= whr * 3600;
55395 + wmin = runtime / 60;
55396 + runtime -= wmin * 60;
55397 + wsec = runtime;
55398 +
55399 + cputime = (task->utime + task->stime) / HZ;
55400 + cday = cputime / (3600 * 24);
55401 + cputime -= cday * (3600 * 24);
55402 + chr = cputime / 3600;
55403 + cputime -= chr * 3600;
55404 + cmin = cputime / 60;
55405 + cputime -= cmin * 60;
55406 + csec = cputime;
55407 +
55408 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55409 +
55410 + return;
55411 +}
55412 +
55413 +void gr_set_kernel_label(struct task_struct *task)
55414 +{
55415 + if (gr_status & GR_READY) {
55416 + task->role = kernel_role;
55417 + task->acl = kernel_role->root_label;
55418 + }
55419 + return;
55420 +}
55421 +
55422 +#ifdef CONFIG_TASKSTATS
55423 +int gr_is_taskstats_denied(int pid)
55424 +{
55425 + struct task_struct *task;
55426 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55427 + const struct cred *cred;
55428 +#endif
55429 + int ret = 0;
55430 +
55431 + /* restrict taskstats viewing to un-chrooted root users
55432 + who have the 'view' subject flag if the RBAC system is enabled
55433 + */
55434 +
55435 + rcu_read_lock();
55436 + read_lock(&tasklist_lock);
55437 + task = find_task_by_vpid(pid);
55438 + if (task) {
55439 +#ifdef CONFIG_GRKERNSEC_CHROOT
55440 + if (proc_is_chrooted(task))
55441 + ret = -EACCES;
55442 +#endif
55443 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55444 + cred = __task_cred(task);
55445 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55446 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55447 + ret = -EACCES;
55448 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55449 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55450 + ret = -EACCES;
55451 +#endif
55452 +#endif
55453 + if (gr_status & GR_READY) {
55454 + if (!(task->acl->mode & GR_VIEW))
55455 + ret = -EACCES;
55456 + }
55457 + } else
55458 + ret = -ENOENT;
55459 +
55460 + read_unlock(&tasklist_lock);
55461 + rcu_read_unlock();
55462 +
55463 + return ret;
55464 +}
55465 +#endif
55466 +
55467 +/* AUXV entries are filled via a descendant of search_binary_handler
55468 + after we've already applied the subject for the target
55469 +*/
55470 +int gr_acl_enable_at_secure(void)
55471 +{
55472 + if (unlikely(!(gr_status & GR_READY)))
55473 + return 0;
55474 +
55475 + if (current->acl->mode & GR_ATSECURE)
55476 + return 1;
55477 +
55478 + return 0;
55479 +}
55480 +
55481 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55482 +{
55483 + struct task_struct *task = current;
55484 + struct dentry *dentry = file->f_path.dentry;
55485 + struct vfsmount *mnt = file->f_path.mnt;
55486 + struct acl_object_label *obj, *tmp;
55487 + struct acl_subject_label *subj;
55488 + unsigned int bufsize;
55489 + int is_not_root;
55490 + char *path;
55491 + dev_t dev = __get_dev(dentry);
55492 +
55493 + if (unlikely(!(gr_status & GR_READY)))
55494 + return 1;
55495 +
55496 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55497 + return 1;
55498 +
55499 + /* ignore Eric Biederman */
55500 + if (IS_PRIVATE(dentry->d_inode))
55501 + return 1;
55502 +
55503 + subj = task->acl;
55504 + read_lock(&gr_inode_lock);
55505 + do {
55506 + obj = lookup_acl_obj_label(ino, dev, subj);
55507 + if (obj != NULL) {
55508 + read_unlock(&gr_inode_lock);
55509 + return (obj->mode & GR_FIND) ? 1 : 0;
55510 + }
55511 + } while ((subj = subj->parent_subject));
55512 + read_unlock(&gr_inode_lock);
55513 +
55514 + /* this is purely an optimization since we're looking for an object
55515 + for the directory we're doing a readdir on
55516 + if it's possible for any globbed object to match the entry we're
55517 + filling into the directory, then the object we find here will be
55518 + an anchor point with attached globbed objects
55519 + */
55520 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55521 + if (obj->globbed == NULL)
55522 + return (obj->mode & GR_FIND) ? 1 : 0;
55523 +
55524 + is_not_root = ((obj->filename[0] == '/') &&
55525 + (obj->filename[1] == '\0')) ? 0 : 1;
55526 + bufsize = PAGE_SIZE - namelen - is_not_root;
55527 +
55528 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55529 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55530 + return 1;
55531 +
55532 + preempt_disable();
55533 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55534 + bufsize);
55535 +
55536 + bufsize = strlen(path);
55537 +
55538 + /* if base is "/", don't append an additional slash */
55539 + if (is_not_root)
55540 + *(path + bufsize) = '/';
55541 + memcpy(path + bufsize + is_not_root, name, namelen);
55542 + *(path + bufsize + namelen + is_not_root) = '\0';
55543 +
55544 + tmp = obj->globbed;
55545 + while (tmp) {
55546 + if (!glob_match(tmp->filename, path)) {
55547 + preempt_enable();
55548 + return (tmp->mode & GR_FIND) ? 1 : 0;
55549 + }
55550 + tmp = tmp->next;
55551 + }
55552 + preempt_enable();
55553 + return (obj->mode & GR_FIND) ? 1 : 0;
55554 +}
55555 +
55556 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55557 +EXPORT_SYMBOL(gr_acl_is_enabled);
55558 +#endif
55559 +EXPORT_SYMBOL(gr_learn_resource);
55560 +EXPORT_SYMBOL(gr_set_kernel_label);
55561 +#ifdef CONFIG_SECURITY
55562 +EXPORT_SYMBOL(gr_check_user_change);
55563 +EXPORT_SYMBOL(gr_check_group_change);
55564 +#endif
55565 +
55566 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55567 new file mode 100644
55568 index 0000000..34fefda
55569 --- /dev/null
55570 +++ b/grsecurity/gracl_alloc.c
55571 @@ -0,0 +1,105 @@
55572 +#include <linux/kernel.h>
55573 +#include <linux/mm.h>
55574 +#include <linux/slab.h>
55575 +#include <linux/vmalloc.h>
55576 +#include <linux/gracl.h>
55577 +#include <linux/grsecurity.h>
55578 +
55579 +static unsigned long alloc_stack_next = 1;
55580 +static unsigned long alloc_stack_size = 1;
55581 +static void **alloc_stack;
55582 +
55583 +static __inline__ int
55584 +alloc_pop(void)
55585 +{
55586 + if (alloc_stack_next == 1)
55587 + return 0;
55588 +
55589 + kfree(alloc_stack[alloc_stack_next - 2]);
55590 +
55591 + alloc_stack_next--;
55592 +
55593 + return 1;
55594 +}
55595 +
55596 +static __inline__ int
55597 +alloc_push(void *buf)
55598 +{
55599 + if (alloc_stack_next >= alloc_stack_size)
55600 + return 1;
55601 +
55602 + alloc_stack[alloc_stack_next - 1] = buf;
55603 +
55604 + alloc_stack_next++;
55605 +
55606 + return 0;
55607 +}
55608 +
55609 +void *
55610 +acl_alloc(unsigned long len)
55611 +{
55612 + void *ret = NULL;
55613 +
55614 + if (!len || len > PAGE_SIZE)
55615 + goto out;
55616 +
55617 + ret = kmalloc(len, GFP_KERNEL);
55618 +
55619 + if (ret) {
55620 + if (alloc_push(ret)) {
55621 + kfree(ret);
55622 + ret = NULL;
55623 + }
55624 + }
55625 +
55626 +out:
55627 + return ret;
55628 +}
55629 +
55630 +void *
55631 +acl_alloc_num(unsigned long num, unsigned long len)
55632 +{
55633 + if (!len || (num > (PAGE_SIZE / len)))
55634 + return NULL;
55635 +
55636 + return acl_alloc(num * len);
55637 +}
55638 +
55639 +void
55640 +acl_free_all(void)
55641 +{
55642 + if (gr_acl_is_enabled() || !alloc_stack)
55643 + return;
55644 +
55645 + while (alloc_pop()) ;
55646 +
55647 + if (alloc_stack) {
55648 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55649 + kfree(alloc_stack);
55650 + else
55651 + vfree(alloc_stack);
55652 + }
55653 +
55654 + alloc_stack = NULL;
55655 + alloc_stack_size = 1;
55656 + alloc_stack_next = 1;
55657 +
55658 + return;
55659 +}
55660 +
55661 +int
55662 +acl_alloc_stack_init(unsigned long size)
55663 +{
55664 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55665 + alloc_stack =
55666 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55667 + else
55668 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55669 +
55670 + alloc_stack_size = size;
55671 +
55672 + if (!alloc_stack)
55673 + return 0;
55674 + else
55675 + return 1;
55676 +}
55677 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55678 new file mode 100644
55679 index 0000000..6d21049
55680 --- /dev/null
55681 +++ b/grsecurity/gracl_cap.c
55682 @@ -0,0 +1,110 @@
55683 +#include <linux/kernel.h>
55684 +#include <linux/module.h>
55685 +#include <linux/sched.h>
55686 +#include <linux/gracl.h>
55687 +#include <linux/grsecurity.h>
55688 +#include <linux/grinternal.h>
55689 +
55690 +extern const char *captab_log[];
55691 +extern int captab_log_entries;
55692 +
55693 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55694 +{
55695 + struct acl_subject_label *curracl;
55696 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55697 + kernel_cap_t cap_audit = __cap_empty_set;
55698 +
55699 + if (!gr_acl_is_enabled())
55700 + return 1;
55701 +
55702 + curracl = task->acl;
55703 +
55704 + cap_drop = curracl->cap_lower;
55705 + cap_mask = curracl->cap_mask;
55706 + cap_audit = curracl->cap_invert_audit;
55707 +
55708 + while ((curracl = curracl->parent_subject)) {
55709 + /* if the cap isn't specified in the current computed mask but is specified in the
55710 + current level subject, and is lowered in the current level subject, then add
55711 + it to the set of dropped capabilities
55712 + otherwise, add the current level subject's mask to the current computed mask
55713 + */
55714 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55715 + cap_raise(cap_mask, cap);
55716 + if (cap_raised(curracl->cap_lower, cap))
55717 + cap_raise(cap_drop, cap);
55718 + if (cap_raised(curracl->cap_invert_audit, cap))
55719 + cap_raise(cap_audit, cap);
55720 + }
55721 + }
55722 +
55723 + if (!cap_raised(cap_drop, cap)) {
55724 + if (cap_raised(cap_audit, cap))
55725 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55726 + return 1;
55727 + }
55728 +
55729 + curracl = task->acl;
55730 +
55731 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55732 + && cap_raised(cred->cap_effective, cap)) {
55733 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55734 + task->role->roletype, cred->uid,
55735 + cred->gid, task->exec_file ?
55736 + gr_to_filename(task->exec_file->f_path.dentry,
55737 + task->exec_file->f_path.mnt) : curracl->filename,
55738 + curracl->filename, 0UL,
55739 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55740 + return 1;
55741 + }
55742 +
55743 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55744 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55745 +
55746 + return 0;
55747 +}
55748 +
55749 +int
55750 +gr_acl_is_capable(const int cap)
55751 +{
55752 + return gr_task_acl_is_capable(current, current_cred(), cap);
55753 +}
55754 +
55755 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55756 +{
55757 + struct acl_subject_label *curracl;
55758 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55759 +
55760 + if (!gr_acl_is_enabled())
55761 + return 1;
55762 +
55763 + curracl = task->acl;
55764 +
55765 + cap_drop = curracl->cap_lower;
55766 + cap_mask = curracl->cap_mask;
55767 +
55768 + while ((curracl = curracl->parent_subject)) {
55769 + /* if the cap isn't specified in the current computed mask but is specified in the
55770 + current level subject, and is lowered in the current level subject, then add
55771 + it to the set of dropped capabilities
55772 + otherwise, add the current level subject's mask to the current computed mask
55773 + */
55774 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55775 + cap_raise(cap_mask, cap);
55776 + if (cap_raised(curracl->cap_lower, cap))
55777 + cap_raise(cap_drop, cap);
55778 + }
55779 + }
55780 +
55781 + if (!cap_raised(cap_drop, cap))
55782 + return 1;
55783 +
55784 + return 0;
55785 +}
55786 +
55787 +int
55788 +gr_acl_is_capable_nolog(const int cap)
55789 +{
55790 + return gr_task_acl_is_capable_nolog(current, cap);
55791 +}
55792 +
55793 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55794 new file mode 100644
55795 index 0000000..d28e241
55796 --- /dev/null
55797 +++ b/grsecurity/gracl_fs.c
55798 @@ -0,0 +1,437 @@
55799 +#include <linux/kernel.h>
55800 +#include <linux/sched.h>
55801 +#include <linux/types.h>
55802 +#include <linux/fs.h>
55803 +#include <linux/file.h>
55804 +#include <linux/stat.h>
55805 +#include <linux/grsecurity.h>
55806 +#include <linux/grinternal.h>
55807 +#include <linux/gracl.h>
55808 +
55809 +umode_t
55810 +gr_acl_umask(void)
55811 +{
55812 + if (unlikely(!gr_acl_is_enabled()))
55813 + return 0;
55814 +
55815 + return current->role->umask;
55816 +}
55817 +
55818 +__u32
55819 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55820 + const struct vfsmount * mnt)
55821 +{
55822 + __u32 mode;
55823 +
55824 + if (unlikely(!dentry->d_inode))
55825 + return GR_FIND;
55826 +
55827 + mode =
55828 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55829 +
55830 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55831 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55832 + return mode;
55833 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55834 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55835 + return 0;
55836 + } else if (unlikely(!(mode & GR_FIND)))
55837 + return 0;
55838 +
55839 + return GR_FIND;
55840 +}
55841 +
55842 +__u32
55843 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55844 + int acc_mode)
55845 +{
55846 + __u32 reqmode = GR_FIND;
55847 + __u32 mode;
55848 +
55849 + if (unlikely(!dentry->d_inode))
55850 + return reqmode;
55851 +
55852 + if (acc_mode & MAY_APPEND)
55853 + reqmode |= GR_APPEND;
55854 + else if (acc_mode & MAY_WRITE)
55855 + reqmode |= GR_WRITE;
55856 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55857 + reqmode |= GR_READ;
55858 +
55859 + mode =
55860 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55861 + mnt);
55862 +
55863 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55864 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55865 + reqmode & GR_READ ? " reading" : "",
55866 + reqmode & GR_WRITE ? " writing" : reqmode &
55867 + GR_APPEND ? " appending" : "");
55868 + return reqmode;
55869 + } else
55870 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55871 + {
55872 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55873 + reqmode & GR_READ ? " reading" : "",
55874 + reqmode & GR_WRITE ? " writing" : reqmode &
55875 + GR_APPEND ? " appending" : "");
55876 + return 0;
55877 + } else if (unlikely((mode & reqmode) != reqmode))
55878 + return 0;
55879 +
55880 + return reqmode;
55881 +}
55882 +
55883 +__u32
55884 +gr_acl_handle_creat(const struct dentry * dentry,
55885 + const struct dentry * p_dentry,
55886 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55887 + const int imode)
55888 +{
55889 + __u32 reqmode = GR_WRITE | GR_CREATE;
55890 + __u32 mode;
55891 +
55892 + if (acc_mode & MAY_APPEND)
55893 + reqmode |= GR_APPEND;
55894 + // if a directory was required or the directory already exists, then
55895 + // don't count this open as a read
55896 + if ((acc_mode & MAY_READ) &&
55897 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55898 + reqmode |= GR_READ;
55899 + if ((open_flags & O_CREAT) &&
55900 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55901 + reqmode |= GR_SETID;
55902 +
55903 + mode =
55904 + gr_check_create(dentry, p_dentry, p_mnt,
55905 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55906 +
55907 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55908 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55909 + reqmode & GR_READ ? " reading" : "",
55910 + reqmode & GR_WRITE ? " writing" : reqmode &
55911 + GR_APPEND ? " appending" : "");
55912 + return reqmode;
55913 + } else
55914 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55915 + {
55916 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55917 + reqmode & GR_READ ? " reading" : "",
55918 + reqmode & GR_WRITE ? " writing" : reqmode &
55919 + GR_APPEND ? " appending" : "");
55920 + return 0;
55921 + } else if (unlikely((mode & reqmode) != reqmode))
55922 + return 0;
55923 +
55924 + return reqmode;
55925 +}
55926 +
55927 +__u32
55928 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55929 + const int fmode)
55930 +{
55931 + __u32 mode, reqmode = GR_FIND;
55932 +
55933 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55934 + reqmode |= GR_EXEC;
55935 + if (fmode & S_IWOTH)
55936 + reqmode |= GR_WRITE;
55937 + if (fmode & S_IROTH)
55938 + reqmode |= GR_READ;
55939 +
55940 + mode =
55941 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55942 + mnt);
55943 +
55944 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55945 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55946 + reqmode & GR_READ ? " reading" : "",
55947 + reqmode & GR_WRITE ? " writing" : "",
55948 + reqmode & GR_EXEC ? " executing" : "");
55949 + return reqmode;
55950 + } else
55951 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55952 + {
55953 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55954 + reqmode & GR_READ ? " reading" : "",
55955 + reqmode & GR_WRITE ? " writing" : "",
55956 + reqmode & GR_EXEC ? " executing" : "");
55957 + return 0;
55958 + } else if (unlikely((mode & reqmode) != reqmode))
55959 + return 0;
55960 +
55961 + return reqmode;
55962 +}
55963 +
55964 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55965 +{
55966 + __u32 mode;
55967 +
55968 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55969 +
55970 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55971 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55972 + return mode;
55973 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55974 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55975 + return 0;
55976 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55977 + return 0;
55978 +
55979 + return (reqmode);
55980 +}
55981 +
55982 +__u32
55983 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55984 +{
55985 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55986 +}
55987 +
55988 +__u32
55989 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55990 +{
55991 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55992 +}
55993 +
55994 +__u32
55995 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55996 +{
55997 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55998 +}
55999 +
56000 +__u32
56001 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56002 +{
56003 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56004 +}
56005 +
56006 +__u32
56007 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56008 + umode_t *modeptr)
56009 +{
56010 + umode_t mode;
56011 +
56012 + *modeptr &= ~gr_acl_umask();
56013 + mode = *modeptr;
56014 +
56015 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56016 + return 1;
56017 +
56018 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56019 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56020 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56021 + GR_CHMOD_ACL_MSG);
56022 + } else {
56023 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56024 + }
56025 +}
56026 +
56027 +__u32
56028 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56029 +{
56030 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56031 +}
56032 +
56033 +__u32
56034 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56035 +{
56036 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56037 +}
56038 +
56039 +__u32
56040 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56041 +{
56042 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56043 +}
56044 +
56045 +__u32
56046 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56047 +{
56048 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56049 + GR_UNIXCONNECT_ACL_MSG);
56050 +}
56051 +
56052 +/* hardlinks require at minimum create and link permission,
56053 + any additional privilege required is based on the
56054 + privilege of the file being linked to
56055 +*/
56056 +__u32
56057 +gr_acl_handle_link(const struct dentry * new_dentry,
56058 + const struct dentry * parent_dentry,
56059 + const struct vfsmount * parent_mnt,
56060 + const struct dentry * old_dentry,
56061 + const struct vfsmount * old_mnt, const char *to)
56062 +{
56063 + __u32 mode;
56064 + __u32 needmode = GR_CREATE | GR_LINK;
56065 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56066 +
56067 + mode =
56068 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56069 + old_mnt);
56070 +
56071 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56072 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56073 + return mode;
56074 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56075 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56076 + return 0;
56077 + } else if (unlikely((mode & needmode) != needmode))
56078 + return 0;
56079 +
56080 + return 1;
56081 +}
56082 +
56083 +__u32
56084 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56085 + const struct dentry * parent_dentry,
56086 + const struct vfsmount * parent_mnt, const char *from)
56087 +{
56088 + __u32 needmode = GR_WRITE | GR_CREATE;
56089 + __u32 mode;
56090 +
56091 + mode =
56092 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56093 + GR_CREATE | GR_AUDIT_CREATE |
56094 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56095 +
56096 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56097 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56098 + return mode;
56099 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56100 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56101 + return 0;
56102 + } else if (unlikely((mode & needmode) != needmode))
56103 + return 0;
56104 +
56105 + return (GR_WRITE | GR_CREATE);
56106 +}
56107 +
56108 +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)
56109 +{
56110 + __u32 mode;
56111 +
56112 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56113 +
56114 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56115 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56116 + return mode;
56117 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56118 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56119 + return 0;
56120 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56121 + return 0;
56122 +
56123 + return (reqmode);
56124 +}
56125 +
56126 +__u32
56127 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56128 + const struct dentry * parent_dentry,
56129 + const struct vfsmount * parent_mnt,
56130 + const int mode)
56131 +{
56132 + __u32 reqmode = GR_WRITE | GR_CREATE;
56133 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56134 + reqmode |= GR_SETID;
56135 +
56136 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56137 + reqmode, GR_MKNOD_ACL_MSG);
56138 +}
56139 +
56140 +__u32
56141 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56142 + const struct dentry *parent_dentry,
56143 + const struct vfsmount *parent_mnt)
56144 +{
56145 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56146 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56147 +}
56148 +
56149 +#define RENAME_CHECK_SUCCESS(old, new) \
56150 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56151 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56152 +
56153 +int
56154 +gr_acl_handle_rename(struct dentry *new_dentry,
56155 + struct dentry *parent_dentry,
56156 + const struct vfsmount *parent_mnt,
56157 + struct dentry *old_dentry,
56158 + struct inode *old_parent_inode,
56159 + struct vfsmount *old_mnt, const char *newname)
56160 +{
56161 + __u32 comp1, comp2;
56162 + int error = 0;
56163 +
56164 + if (unlikely(!gr_acl_is_enabled()))
56165 + return 0;
56166 +
56167 + if (!new_dentry->d_inode) {
56168 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56169 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56170 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56171 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56172 + GR_DELETE | GR_AUDIT_DELETE |
56173 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56174 + GR_SUPPRESS, old_mnt);
56175 + } else {
56176 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56177 + GR_CREATE | GR_DELETE |
56178 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56179 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56180 + GR_SUPPRESS, parent_mnt);
56181 + comp2 =
56182 + gr_search_file(old_dentry,
56183 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56184 + GR_DELETE | GR_AUDIT_DELETE |
56185 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56186 + }
56187 +
56188 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56189 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56190 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56191 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56192 + && !(comp2 & GR_SUPPRESS)) {
56193 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56194 + error = -EACCES;
56195 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56196 + error = -EACCES;
56197 +
56198 + return error;
56199 +}
56200 +
56201 +void
56202 +gr_acl_handle_exit(void)
56203 +{
56204 + u16 id;
56205 + char *rolename;
56206 + struct file *exec_file;
56207 +
56208 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56209 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56210 + id = current->acl_role_id;
56211 + rolename = current->role->rolename;
56212 + gr_set_acls(1);
56213 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56214 + }
56215 +
56216 + write_lock(&grsec_exec_file_lock);
56217 + exec_file = current->exec_file;
56218 + current->exec_file = NULL;
56219 + write_unlock(&grsec_exec_file_lock);
56220 +
56221 + if (exec_file)
56222 + fput(exec_file);
56223 +}
56224 +
56225 +int
56226 +gr_acl_handle_procpidmem(const struct task_struct *task)
56227 +{
56228 + if (unlikely(!gr_acl_is_enabled()))
56229 + return 0;
56230 +
56231 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56232 + return -EACCES;
56233 +
56234 + return 0;
56235 +}
56236 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56237 new file mode 100644
56238 index 0000000..58800a7
56239 --- /dev/null
56240 +++ b/grsecurity/gracl_ip.c
56241 @@ -0,0 +1,384 @@
56242 +#include <linux/kernel.h>
56243 +#include <asm/uaccess.h>
56244 +#include <asm/errno.h>
56245 +#include <net/sock.h>
56246 +#include <linux/file.h>
56247 +#include <linux/fs.h>
56248 +#include <linux/net.h>
56249 +#include <linux/in.h>
56250 +#include <linux/skbuff.h>
56251 +#include <linux/ip.h>
56252 +#include <linux/udp.h>
56253 +#include <linux/types.h>
56254 +#include <linux/sched.h>
56255 +#include <linux/netdevice.h>
56256 +#include <linux/inetdevice.h>
56257 +#include <linux/gracl.h>
56258 +#include <linux/grsecurity.h>
56259 +#include <linux/grinternal.h>
56260 +
56261 +#define GR_BIND 0x01
56262 +#define GR_CONNECT 0x02
56263 +#define GR_INVERT 0x04
56264 +#define GR_BINDOVERRIDE 0x08
56265 +#define GR_CONNECTOVERRIDE 0x10
56266 +#define GR_SOCK_FAMILY 0x20
56267 +
56268 +static const char * gr_protocols[IPPROTO_MAX] = {
56269 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56270 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56271 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56272 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56273 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56274 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56275 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56276 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56277 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56278 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56279 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56280 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56281 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56282 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56283 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56284 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56285 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56286 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56287 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56288 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56289 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56290 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56291 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56292 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56293 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56294 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56295 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56296 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56297 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56298 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56299 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56300 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56301 + };
56302 +
56303 +static const char * gr_socktypes[SOCK_MAX] = {
56304 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56305 + "unknown:7", "unknown:8", "unknown:9", "packet"
56306 + };
56307 +
56308 +static const char * gr_sockfamilies[AF_MAX+1] = {
56309 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56310 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56311 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56312 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56313 + };
56314 +
56315 +const char *
56316 +gr_proto_to_name(unsigned char proto)
56317 +{
56318 + return gr_protocols[proto];
56319 +}
56320 +
56321 +const char *
56322 +gr_socktype_to_name(unsigned char type)
56323 +{
56324 + return gr_socktypes[type];
56325 +}
56326 +
56327 +const char *
56328 +gr_sockfamily_to_name(unsigned char family)
56329 +{
56330 + return gr_sockfamilies[family];
56331 +}
56332 +
56333 +int
56334 +gr_search_socket(const int domain, const int type, const int protocol)
56335 +{
56336 + struct acl_subject_label *curr;
56337 + const struct cred *cred = current_cred();
56338 +
56339 + if (unlikely(!gr_acl_is_enabled()))
56340 + goto exit;
56341 +
56342 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56343 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56344 + goto exit; // let the kernel handle it
56345 +
56346 + curr = current->acl;
56347 +
56348 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56349 + /* the family is allowed, if this is PF_INET allow it only if
56350 + the extra sock type/protocol checks pass */
56351 + if (domain == PF_INET)
56352 + goto inet_check;
56353 + goto exit;
56354 + } else {
56355 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56356 + __u32 fakeip = 0;
56357 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56358 + current->role->roletype, cred->uid,
56359 + cred->gid, current->exec_file ?
56360 + gr_to_filename(current->exec_file->f_path.dentry,
56361 + current->exec_file->f_path.mnt) :
56362 + curr->filename, curr->filename,
56363 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56364 + &current->signal->saved_ip);
56365 + goto exit;
56366 + }
56367 + goto exit_fail;
56368 + }
56369 +
56370 +inet_check:
56371 + /* the rest of this checking is for IPv4 only */
56372 + if (!curr->ips)
56373 + goto exit;
56374 +
56375 + if ((curr->ip_type & (1 << type)) &&
56376 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56377 + goto exit;
56378 +
56379 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56380 + /* we don't place acls on raw sockets , and sometimes
56381 + dgram/ip sockets are opened for ioctl and not
56382 + bind/connect, so we'll fake a bind learn log */
56383 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56384 + __u32 fakeip = 0;
56385 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56386 + current->role->roletype, cred->uid,
56387 + cred->gid, current->exec_file ?
56388 + gr_to_filename(current->exec_file->f_path.dentry,
56389 + current->exec_file->f_path.mnt) :
56390 + curr->filename, curr->filename,
56391 + &fakeip, 0, type,
56392 + protocol, GR_CONNECT, &current->signal->saved_ip);
56393 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56394 + __u32 fakeip = 0;
56395 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56396 + current->role->roletype, cred->uid,
56397 + cred->gid, current->exec_file ?
56398 + gr_to_filename(current->exec_file->f_path.dentry,
56399 + current->exec_file->f_path.mnt) :
56400 + curr->filename, curr->filename,
56401 + &fakeip, 0, type,
56402 + protocol, GR_BIND, &current->signal->saved_ip);
56403 + }
56404 + /* we'll log when they use connect or bind */
56405 + goto exit;
56406 + }
56407 +
56408 +exit_fail:
56409 + if (domain == PF_INET)
56410 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56411 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56412 + else
56413 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56414 + gr_socktype_to_name(type), protocol);
56415 +
56416 + return 0;
56417 +exit:
56418 + return 1;
56419 +}
56420 +
56421 +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)
56422 +{
56423 + if ((ip->mode & mode) &&
56424 + (ip_port >= ip->low) &&
56425 + (ip_port <= ip->high) &&
56426 + ((ntohl(ip_addr) & our_netmask) ==
56427 + (ntohl(our_addr) & our_netmask))
56428 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56429 + && (ip->type & (1 << type))) {
56430 + if (ip->mode & GR_INVERT)
56431 + return 2; // specifically denied
56432 + else
56433 + return 1; // allowed
56434 + }
56435 +
56436 + return 0; // not specifically allowed, may continue parsing
56437 +}
56438 +
56439 +static int
56440 +gr_search_connectbind(const int full_mode, struct sock *sk,
56441 + struct sockaddr_in *addr, const int type)
56442 +{
56443 + char iface[IFNAMSIZ] = {0};
56444 + struct acl_subject_label *curr;
56445 + struct acl_ip_label *ip;
56446 + struct inet_sock *isk;
56447 + struct net_device *dev;
56448 + struct in_device *idev;
56449 + unsigned long i;
56450 + int ret;
56451 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56452 + __u32 ip_addr = 0;
56453 + __u32 our_addr;
56454 + __u32 our_netmask;
56455 + char *p;
56456 + __u16 ip_port = 0;
56457 + const struct cred *cred = current_cred();
56458 +
56459 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56460 + return 0;
56461 +
56462 + curr = current->acl;
56463 + isk = inet_sk(sk);
56464 +
56465 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56466 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56467 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56468 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56469 + struct sockaddr_in saddr;
56470 + int err;
56471 +
56472 + saddr.sin_family = AF_INET;
56473 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56474 + saddr.sin_port = isk->inet_sport;
56475 +
56476 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56477 + if (err)
56478 + return err;
56479 +
56480 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56481 + if (err)
56482 + return err;
56483 + }
56484 +
56485 + if (!curr->ips)
56486 + return 0;
56487 +
56488 + ip_addr = addr->sin_addr.s_addr;
56489 + ip_port = ntohs(addr->sin_port);
56490 +
56491 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56492 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56493 + current->role->roletype, cred->uid,
56494 + cred->gid, current->exec_file ?
56495 + gr_to_filename(current->exec_file->f_path.dentry,
56496 + current->exec_file->f_path.mnt) :
56497 + curr->filename, curr->filename,
56498 + &ip_addr, ip_port, type,
56499 + sk->sk_protocol, mode, &current->signal->saved_ip);
56500 + return 0;
56501 + }
56502 +
56503 + for (i = 0; i < curr->ip_num; i++) {
56504 + ip = *(curr->ips + i);
56505 + if (ip->iface != NULL) {
56506 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56507 + p = strchr(iface, ':');
56508 + if (p != NULL)
56509 + *p = '\0';
56510 + dev = dev_get_by_name(sock_net(sk), iface);
56511 + if (dev == NULL)
56512 + continue;
56513 + idev = in_dev_get(dev);
56514 + if (idev == NULL) {
56515 + dev_put(dev);
56516 + continue;
56517 + }
56518 + rcu_read_lock();
56519 + for_ifa(idev) {
56520 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56521 + our_addr = ifa->ifa_address;
56522 + our_netmask = 0xffffffff;
56523 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56524 + if (ret == 1) {
56525 + rcu_read_unlock();
56526 + in_dev_put(idev);
56527 + dev_put(dev);
56528 + return 0;
56529 + } else if (ret == 2) {
56530 + rcu_read_unlock();
56531 + in_dev_put(idev);
56532 + dev_put(dev);
56533 + goto denied;
56534 + }
56535 + }
56536 + } endfor_ifa(idev);
56537 + rcu_read_unlock();
56538 + in_dev_put(idev);
56539 + dev_put(dev);
56540 + } else {
56541 + our_addr = ip->addr;
56542 + our_netmask = ip->netmask;
56543 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56544 + if (ret == 1)
56545 + return 0;
56546 + else if (ret == 2)
56547 + goto denied;
56548 + }
56549 + }
56550 +
56551 +denied:
56552 + if (mode == GR_BIND)
56553 + 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));
56554 + else if (mode == GR_CONNECT)
56555 + 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));
56556 +
56557 + return -EACCES;
56558 +}
56559 +
56560 +int
56561 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56562 +{
56563 + /* always allow disconnection of dgram sockets with connect */
56564 + if (addr->sin_family == AF_UNSPEC)
56565 + return 0;
56566 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56567 +}
56568 +
56569 +int
56570 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56571 +{
56572 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56573 +}
56574 +
56575 +int gr_search_listen(struct socket *sock)
56576 +{
56577 + struct sock *sk = sock->sk;
56578 + struct sockaddr_in addr;
56579 +
56580 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56581 + addr.sin_port = inet_sk(sk)->inet_sport;
56582 +
56583 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56584 +}
56585 +
56586 +int gr_search_accept(struct socket *sock)
56587 +{
56588 + struct sock *sk = sock->sk;
56589 + struct sockaddr_in addr;
56590 +
56591 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56592 + addr.sin_port = inet_sk(sk)->inet_sport;
56593 +
56594 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56595 +}
56596 +
56597 +int
56598 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56599 +{
56600 + if (addr)
56601 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56602 + else {
56603 + struct sockaddr_in sin;
56604 + const struct inet_sock *inet = inet_sk(sk);
56605 +
56606 + sin.sin_addr.s_addr = inet->inet_daddr;
56607 + sin.sin_port = inet->inet_dport;
56608 +
56609 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56610 + }
56611 +}
56612 +
56613 +int
56614 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56615 +{
56616 + struct sockaddr_in sin;
56617 +
56618 + if (unlikely(skb->len < sizeof (struct udphdr)))
56619 + return 0; // skip this packet
56620 +
56621 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56622 + sin.sin_port = udp_hdr(skb)->source;
56623 +
56624 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56625 +}
56626 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56627 new file mode 100644
56628 index 0000000..25f54ef
56629 --- /dev/null
56630 +++ b/grsecurity/gracl_learn.c
56631 @@ -0,0 +1,207 @@
56632 +#include <linux/kernel.h>
56633 +#include <linux/mm.h>
56634 +#include <linux/sched.h>
56635 +#include <linux/poll.h>
56636 +#include <linux/string.h>
56637 +#include <linux/file.h>
56638 +#include <linux/types.h>
56639 +#include <linux/vmalloc.h>
56640 +#include <linux/grinternal.h>
56641 +
56642 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56643 + size_t count, loff_t *ppos);
56644 +extern int gr_acl_is_enabled(void);
56645 +
56646 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56647 +static int gr_learn_attached;
56648 +
56649 +/* use a 512k buffer */
56650 +#define LEARN_BUFFER_SIZE (512 * 1024)
56651 +
56652 +static DEFINE_SPINLOCK(gr_learn_lock);
56653 +static DEFINE_MUTEX(gr_learn_user_mutex);
56654 +
56655 +/* we need to maintain two buffers, so that the kernel context of grlearn
56656 + uses a semaphore around the userspace copying, and the other kernel contexts
56657 + use a spinlock when copying into the buffer, since they cannot sleep
56658 +*/
56659 +static char *learn_buffer;
56660 +static char *learn_buffer_user;
56661 +static int learn_buffer_len;
56662 +static int learn_buffer_user_len;
56663 +
56664 +static ssize_t
56665 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56666 +{
56667 + DECLARE_WAITQUEUE(wait, current);
56668 + ssize_t retval = 0;
56669 +
56670 + add_wait_queue(&learn_wait, &wait);
56671 + set_current_state(TASK_INTERRUPTIBLE);
56672 + do {
56673 + mutex_lock(&gr_learn_user_mutex);
56674 + spin_lock(&gr_learn_lock);
56675 + if (learn_buffer_len)
56676 + break;
56677 + spin_unlock(&gr_learn_lock);
56678 + mutex_unlock(&gr_learn_user_mutex);
56679 + if (file->f_flags & O_NONBLOCK) {
56680 + retval = -EAGAIN;
56681 + goto out;
56682 + }
56683 + if (signal_pending(current)) {
56684 + retval = -ERESTARTSYS;
56685 + goto out;
56686 + }
56687 +
56688 + schedule();
56689 + } while (1);
56690 +
56691 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56692 + learn_buffer_user_len = learn_buffer_len;
56693 + retval = learn_buffer_len;
56694 + learn_buffer_len = 0;
56695 +
56696 + spin_unlock(&gr_learn_lock);
56697 +
56698 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56699 + retval = -EFAULT;
56700 +
56701 + mutex_unlock(&gr_learn_user_mutex);
56702 +out:
56703 + set_current_state(TASK_RUNNING);
56704 + remove_wait_queue(&learn_wait, &wait);
56705 + return retval;
56706 +}
56707 +
56708 +static unsigned int
56709 +poll_learn(struct file * file, poll_table * wait)
56710 +{
56711 + poll_wait(file, &learn_wait, wait);
56712 +
56713 + if (learn_buffer_len)
56714 + return (POLLIN | POLLRDNORM);
56715 +
56716 + return 0;
56717 +}
56718 +
56719 +void
56720 +gr_clear_learn_entries(void)
56721 +{
56722 + char *tmp;
56723 +
56724 + mutex_lock(&gr_learn_user_mutex);
56725 + spin_lock(&gr_learn_lock);
56726 + tmp = learn_buffer;
56727 + learn_buffer = NULL;
56728 + spin_unlock(&gr_learn_lock);
56729 + if (tmp)
56730 + vfree(tmp);
56731 + if (learn_buffer_user != NULL) {
56732 + vfree(learn_buffer_user);
56733 + learn_buffer_user = NULL;
56734 + }
56735 + learn_buffer_len = 0;
56736 + mutex_unlock(&gr_learn_user_mutex);
56737 +
56738 + return;
56739 +}
56740 +
56741 +void
56742 +gr_add_learn_entry(const char *fmt, ...)
56743 +{
56744 + va_list args;
56745 + unsigned int len;
56746 +
56747 + if (!gr_learn_attached)
56748 + return;
56749 +
56750 + spin_lock(&gr_learn_lock);
56751 +
56752 + /* leave a gap at the end so we know when it's "full" but don't have to
56753 + compute the exact length of the string we're trying to append
56754 + */
56755 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56756 + spin_unlock(&gr_learn_lock);
56757 + wake_up_interruptible(&learn_wait);
56758 + return;
56759 + }
56760 + if (learn_buffer == NULL) {
56761 + spin_unlock(&gr_learn_lock);
56762 + return;
56763 + }
56764 +
56765 + va_start(args, fmt);
56766 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56767 + va_end(args);
56768 +
56769 + learn_buffer_len += len + 1;
56770 +
56771 + spin_unlock(&gr_learn_lock);
56772 + wake_up_interruptible(&learn_wait);
56773 +
56774 + return;
56775 +}
56776 +
56777 +static int
56778 +open_learn(struct inode *inode, struct file *file)
56779 +{
56780 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56781 + return -EBUSY;
56782 + if (file->f_mode & FMODE_READ) {
56783 + int retval = 0;
56784 + mutex_lock(&gr_learn_user_mutex);
56785 + if (learn_buffer == NULL)
56786 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56787 + if (learn_buffer_user == NULL)
56788 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56789 + if (learn_buffer == NULL) {
56790 + retval = -ENOMEM;
56791 + goto out_error;
56792 + }
56793 + if (learn_buffer_user == NULL) {
56794 + retval = -ENOMEM;
56795 + goto out_error;
56796 + }
56797 + learn_buffer_len = 0;
56798 + learn_buffer_user_len = 0;
56799 + gr_learn_attached = 1;
56800 +out_error:
56801 + mutex_unlock(&gr_learn_user_mutex);
56802 + return retval;
56803 + }
56804 + return 0;
56805 +}
56806 +
56807 +static int
56808 +close_learn(struct inode *inode, struct file *file)
56809 +{
56810 + if (file->f_mode & FMODE_READ) {
56811 + char *tmp = NULL;
56812 + mutex_lock(&gr_learn_user_mutex);
56813 + spin_lock(&gr_learn_lock);
56814 + tmp = learn_buffer;
56815 + learn_buffer = NULL;
56816 + spin_unlock(&gr_learn_lock);
56817 + if (tmp)
56818 + vfree(tmp);
56819 + if (learn_buffer_user != NULL) {
56820 + vfree(learn_buffer_user);
56821 + learn_buffer_user = NULL;
56822 + }
56823 + learn_buffer_len = 0;
56824 + learn_buffer_user_len = 0;
56825 + gr_learn_attached = 0;
56826 + mutex_unlock(&gr_learn_user_mutex);
56827 + }
56828 +
56829 + return 0;
56830 +}
56831 +
56832 +const struct file_operations grsec_fops = {
56833 + .read = read_learn,
56834 + .write = write_grsec_handler,
56835 + .open = open_learn,
56836 + .release = close_learn,
56837 + .poll = poll_learn,
56838 +};
56839 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56840 new file mode 100644
56841 index 0000000..39645c9
56842 --- /dev/null
56843 +++ b/grsecurity/gracl_res.c
56844 @@ -0,0 +1,68 @@
56845 +#include <linux/kernel.h>
56846 +#include <linux/sched.h>
56847 +#include <linux/gracl.h>
56848 +#include <linux/grinternal.h>
56849 +
56850 +static const char *restab_log[] = {
56851 + [RLIMIT_CPU] = "RLIMIT_CPU",
56852 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56853 + [RLIMIT_DATA] = "RLIMIT_DATA",
56854 + [RLIMIT_STACK] = "RLIMIT_STACK",
56855 + [RLIMIT_CORE] = "RLIMIT_CORE",
56856 + [RLIMIT_RSS] = "RLIMIT_RSS",
56857 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56858 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56859 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56860 + [RLIMIT_AS] = "RLIMIT_AS",
56861 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56862 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56863 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56864 + [RLIMIT_NICE] = "RLIMIT_NICE",
56865 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56866 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56867 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56868 +};
56869 +
56870 +void
56871 +gr_log_resource(const struct task_struct *task,
56872 + const int res, const unsigned long wanted, const int gt)
56873 +{
56874 + const struct cred *cred;
56875 + unsigned long rlim;
56876 +
56877 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56878 + return;
56879 +
56880 + // not yet supported resource
56881 + if (unlikely(!restab_log[res]))
56882 + return;
56883 +
56884 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56885 + rlim = task_rlimit_max(task, res);
56886 + else
56887 + rlim = task_rlimit(task, res);
56888 +
56889 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56890 + return;
56891 +
56892 + rcu_read_lock();
56893 + cred = __task_cred(task);
56894 +
56895 + if (res == RLIMIT_NPROC &&
56896 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56897 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56898 + goto out_rcu_unlock;
56899 + else if (res == RLIMIT_MEMLOCK &&
56900 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56901 + goto out_rcu_unlock;
56902 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56903 + goto out_rcu_unlock;
56904 + rcu_read_unlock();
56905 +
56906 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56907 +
56908 + return;
56909 +out_rcu_unlock:
56910 + rcu_read_unlock();
56911 + return;
56912 +}
56913 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56914 new file mode 100644
56915 index 0000000..25197e9
56916 --- /dev/null
56917 +++ b/grsecurity/gracl_segv.c
56918 @@ -0,0 +1,299 @@
56919 +#include <linux/kernel.h>
56920 +#include <linux/mm.h>
56921 +#include <asm/uaccess.h>
56922 +#include <asm/errno.h>
56923 +#include <asm/mman.h>
56924 +#include <net/sock.h>
56925 +#include <linux/file.h>
56926 +#include <linux/fs.h>
56927 +#include <linux/net.h>
56928 +#include <linux/in.h>
56929 +#include <linux/slab.h>
56930 +#include <linux/types.h>
56931 +#include <linux/sched.h>
56932 +#include <linux/timer.h>
56933 +#include <linux/gracl.h>
56934 +#include <linux/grsecurity.h>
56935 +#include <linux/grinternal.h>
56936 +
56937 +static struct crash_uid *uid_set;
56938 +static unsigned short uid_used;
56939 +static DEFINE_SPINLOCK(gr_uid_lock);
56940 +extern rwlock_t gr_inode_lock;
56941 +extern struct acl_subject_label *
56942 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56943 + struct acl_role_label *role);
56944 +
56945 +#ifdef CONFIG_BTRFS_FS
56946 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56947 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56948 +#endif
56949 +
56950 +static inline dev_t __get_dev(const struct dentry *dentry)
56951 +{
56952 +#ifdef CONFIG_BTRFS_FS
56953 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56954 + return get_btrfs_dev_from_inode(dentry->d_inode);
56955 + else
56956 +#endif
56957 + return dentry->d_inode->i_sb->s_dev;
56958 +}
56959 +
56960 +int
56961 +gr_init_uidset(void)
56962 +{
56963 + uid_set =
56964 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56965 + uid_used = 0;
56966 +
56967 + return uid_set ? 1 : 0;
56968 +}
56969 +
56970 +void
56971 +gr_free_uidset(void)
56972 +{
56973 + if (uid_set)
56974 + kfree(uid_set);
56975 +
56976 + return;
56977 +}
56978 +
56979 +int
56980 +gr_find_uid(const uid_t uid)
56981 +{
56982 + struct crash_uid *tmp = uid_set;
56983 + uid_t buid;
56984 + int low = 0, high = uid_used - 1, mid;
56985 +
56986 + while (high >= low) {
56987 + mid = (low + high) >> 1;
56988 + buid = tmp[mid].uid;
56989 + if (buid == uid)
56990 + return mid;
56991 + if (buid > uid)
56992 + high = mid - 1;
56993 + if (buid < uid)
56994 + low = mid + 1;
56995 + }
56996 +
56997 + return -1;
56998 +}
56999 +
57000 +static __inline__ void
57001 +gr_insertsort(void)
57002 +{
57003 + unsigned short i, j;
57004 + struct crash_uid index;
57005 +
57006 + for (i = 1; i < uid_used; i++) {
57007 + index = uid_set[i];
57008 + j = i;
57009 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57010 + uid_set[j] = uid_set[j - 1];
57011 + j--;
57012 + }
57013 + uid_set[j] = index;
57014 + }
57015 +
57016 + return;
57017 +}
57018 +
57019 +static __inline__ void
57020 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57021 +{
57022 + int loc;
57023 +
57024 + if (uid_used == GR_UIDTABLE_MAX)
57025 + return;
57026 +
57027 + loc = gr_find_uid(uid);
57028 +
57029 + if (loc >= 0) {
57030 + uid_set[loc].expires = expires;
57031 + return;
57032 + }
57033 +
57034 + uid_set[uid_used].uid = uid;
57035 + uid_set[uid_used].expires = expires;
57036 + uid_used++;
57037 +
57038 + gr_insertsort();
57039 +
57040 + return;
57041 +}
57042 +
57043 +void
57044 +gr_remove_uid(const unsigned short loc)
57045 +{
57046 + unsigned short i;
57047 +
57048 + for (i = loc + 1; i < uid_used; i++)
57049 + uid_set[i - 1] = uid_set[i];
57050 +
57051 + uid_used--;
57052 +
57053 + return;
57054 +}
57055 +
57056 +int
57057 +gr_check_crash_uid(const uid_t uid)
57058 +{
57059 + int loc;
57060 + int ret = 0;
57061 +
57062 + if (unlikely(!gr_acl_is_enabled()))
57063 + return 0;
57064 +
57065 + spin_lock(&gr_uid_lock);
57066 + loc = gr_find_uid(uid);
57067 +
57068 + if (loc < 0)
57069 + goto out_unlock;
57070 +
57071 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57072 + gr_remove_uid(loc);
57073 + else
57074 + ret = 1;
57075 +
57076 +out_unlock:
57077 + spin_unlock(&gr_uid_lock);
57078 + return ret;
57079 +}
57080 +
57081 +static __inline__ int
57082 +proc_is_setxid(const struct cred *cred)
57083 +{
57084 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57085 + !uid_eq(cred->uid, cred->fsuid))
57086 + return 1;
57087 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57088 + !uid_eq(cred->gid, cred->fsgid))
57089 + return 1;
57090 +
57091 + return 0;
57092 +}
57093 +
57094 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57095 +
57096 +void
57097 +gr_handle_crash(struct task_struct *task, const int sig)
57098 +{
57099 + struct acl_subject_label *curr;
57100 + struct task_struct *tsk, *tsk2;
57101 + const struct cred *cred;
57102 + const struct cred *cred2;
57103 +
57104 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57105 + return;
57106 +
57107 + if (unlikely(!gr_acl_is_enabled()))
57108 + return;
57109 +
57110 + curr = task->acl;
57111 +
57112 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57113 + return;
57114 +
57115 + if (time_before_eq(curr->expires, get_seconds())) {
57116 + curr->expires = 0;
57117 + curr->crashes = 0;
57118 + }
57119 +
57120 + curr->crashes++;
57121 +
57122 + if (!curr->expires)
57123 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57124 +
57125 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57126 + time_after(curr->expires, get_seconds())) {
57127 + rcu_read_lock();
57128 + cred = __task_cred(task);
57129 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57130 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57131 + spin_lock(&gr_uid_lock);
57132 + gr_insert_uid(cred->uid, curr->expires);
57133 + spin_unlock(&gr_uid_lock);
57134 + curr->expires = 0;
57135 + curr->crashes = 0;
57136 + read_lock(&tasklist_lock);
57137 + do_each_thread(tsk2, tsk) {
57138 + cred2 = __task_cred(tsk);
57139 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57140 + gr_fake_force_sig(SIGKILL, tsk);
57141 + } while_each_thread(tsk2, tsk);
57142 + read_unlock(&tasklist_lock);
57143 + } else {
57144 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57145 + read_lock(&tasklist_lock);
57146 + read_lock(&grsec_exec_file_lock);
57147 + do_each_thread(tsk2, tsk) {
57148 + if (likely(tsk != task)) {
57149 + // if this thread has the same subject as the one that triggered
57150 + // RES_CRASH and it's the same binary, kill it
57151 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57152 + gr_fake_force_sig(SIGKILL, tsk);
57153 + }
57154 + } while_each_thread(tsk2, tsk);
57155 + read_unlock(&grsec_exec_file_lock);
57156 + read_unlock(&tasklist_lock);
57157 + }
57158 + rcu_read_unlock();
57159 + }
57160 +
57161 + return;
57162 +}
57163 +
57164 +int
57165 +gr_check_crash_exec(const struct file *filp)
57166 +{
57167 + struct acl_subject_label *curr;
57168 +
57169 + if (unlikely(!gr_acl_is_enabled()))
57170 + return 0;
57171 +
57172 + read_lock(&gr_inode_lock);
57173 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57174 + __get_dev(filp->f_path.dentry),
57175 + current->role);
57176 + read_unlock(&gr_inode_lock);
57177 +
57178 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57179 + (!curr->crashes && !curr->expires))
57180 + return 0;
57181 +
57182 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57183 + time_after(curr->expires, get_seconds()))
57184 + return 1;
57185 + else if (time_before_eq(curr->expires, get_seconds())) {
57186 + curr->crashes = 0;
57187 + curr->expires = 0;
57188 + }
57189 +
57190 + return 0;
57191 +}
57192 +
57193 +void
57194 +gr_handle_alertkill(struct task_struct *task)
57195 +{
57196 + struct acl_subject_label *curracl;
57197 + __u32 curr_ip;
57198 + struct task_struct *p, *p2;
57199 +
57200 + if (unlikely(!gr_acl_is_enabled()))
57201 + return;
57202 +
57203 + curracl = task->acl;
57204 + curr_ip = task->signal->curr_ip;
57205 +
57206 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57207 + read_lock(&tasklist_lock);
57208 + do_each_thread(p2, p) {
57209 + if (p->signal->curr_ip == curr_ip)
57210 + gr_fake_force_sig(SIGKILL, p);
57211 + } while_each_thread(p2, p);
57212 + read_unlock(&tasklist_lock);
57213 + } else if (curracl->mode & GR_KILLPROC)
57214 + gr_fake_force_sig(SIGKILL, task);
57215 +
57216 + return;
57217 +}
57218 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57219 new file mode 100644
57220 index 0000000..9d83a69
57221 --- /dev/null
57222 +++ b/grsecurity/gracl_shm.c
57223 @@ -0,0 +1,40 @@
57224 +#include <linux/kernel.h>
57225 +#include <linux/mm.h>
57226 +#include <linux/sched.h>
57227 +#include <linux/file.h>
57228 +#include <linux/ipc.h>
57229 +#include <linux/gracl.h>
57230 +#include <linux/grsecurity.h>
57231 +#include <linux/grinternal.h>
57232 +
57233 +int
57234 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57235 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57236 +{
57237 + struct task_struct *task;
57238 +
57239 + if (!gr_acl_is_enabled())
57240 + return 1;
57241 +
57242 + rcu_read_lock();
57243 + read_lock(&tasklist_lock);
57244 +
57245 + task = find_task_by_vpid(shm_cprid);
57246 +
57247 + if (unlikely(!task))
57248 + task = find_task_by_vpid(shm_lapid);
57249 +
57250 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57251 + (task->pid == shm_lapid)) &&
57252 + (task->acl->mode & GR_PROTSHM) &&
57253 + (task->acl != current->acl))) {
57254 + read_unlock(&tasklist_lock);
57255 + rcu_read_unlock();
57256 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57257 + return 0;
57258 + }
57259 + read_unlock(&tasklist_lock);
57260 + rcu_read_unlock();
57261 +
57262 + return 1;
57263 +}
57264 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57265 new file mode 100644
57266 index 0000000..bc0be01
57267 --- /dev/null
57268 +++ b/grsecurity/grsec_chdir.c
57269 @@ -0,0 +1,19 @@
57270 +#include <linux/kernel.h>
57271 +#include <linux/sched.h>
57272 +#include <linux/fs.h>
57273 +#include <linux/file.h>
57274 +#include <linux/grsecurity.h>
57275 +#include <linux/grinternal.h>
57276 +
57277 +void
57278 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57279 +{
57280 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57281 + if ((grsec_enable_chdir && grsec_enable_group &&
57282 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57283 + !grsec_enable_group)) {
57284 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57285 + }
57286 +#endif
57287 + return;
57288 +}
57289 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57290 new file mode 100644
57291 index 0000000..9807ee2
57292 --- /dev/null
57293 +++ b/grsecurity/grsec_chroot.c
57294 @@ -0,0 +1,368 @@
57295 +#include <linux/kernel.h>
57296 +#include <linux/module.h>
57297 +#include <linux/sched.h>
57298 +#include <linux/file.h>
57299 +#include <linux/fs.h>
57300 +#include <linux/mount.h>
57301 +#include <linux/types.h>
57302 +#include "../fs/mount.h"
57303 +#include <linux/grsecurity.h>
57304 +#include <linux/grinternal.h>
57305 +
57306 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57307 +{
57308 +#ifdef CONFIG_GRKERNSEC
57309 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57310 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57311 + task->gr_is_chrooted = 1;
57312 + else
57313 + task->gr_is_chrooted = 0;
57314 +
57315 + task->gr_chroot_dentry = path->dentry;
57316 +#endif
57317 + return;
57318 +}
57319 +
57320 +void gr_clear_chroot_entries(struct task_struct *task)
57321 +{
57322 +#ifdef CONFIG_GRKERNSEC
57323 + task->gr_is_chrooted = 0;
57324 + task->gr_chroot_dentry = NULL;
57325 +#endif
57326 + return;
57327 +}
57328 +
57329 +int
57330 +gr_handle_chroot_unix(const pid_t pid)
57331 +{
57332 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57333 + struct task_struct *p;
57334 +
57335 + if (unlikely(!grsec_enable_chroot_unix))
57336 + return 1;
57337 +
57338 + if (likely(!proc_is_chrooted(current)))
57339 + return 1;
57340 +
57341 + rcu_read_lock();
57342 + read_lock(&tasklist_lock);
57343 + p = find_task_by_vpid_unrestricted(pid);
57344 + if (unlikely(p && !have_same_root(current, p))) {
57345 + read_unlock(&tasklist_lock);
57346 + rcu_read_unlock();
57347 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57348 + return 0;
57349 + }
57350 + read_unlock(&tasklist_lock);
57351 + rcu_read_unlock();
57352 +#endif
57353 + return 1;
57354 +}
57355 +
57356 +int
57357 +gr_handle_chroot_nice(void)
57358 +{
57359 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57360 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57361 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57362 + return -EPERM;
57363 + }
57364 +#endif
57365 + return 0;
57366 +}
57367 +
57368 +int
57369 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57370 +{
57371 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57372 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57373 + && proc_is_chrooted(current)) {
57374 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57375 + return -EACCES;
57376 + }
57377 +#endif
57378 + return 0;
57379 +}
57380 +
57381 +int
57382 +gr_handle_chroot_rawio(const struct inode *inode)
57383 +{
57384 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57385 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57386 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57387 + return 1;
57388 +#endif
57389 + return 0;
57390 +}
57391 +
57392 +int
57393 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57394 +{
57395 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57396 + struct task_struct *p;
57397 + int ret = 0;
57398 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57399 + return ret;
57400 +
57401 + read_lock(&tasklist_lock);
57402 + do_each_pid_task(pid, type, p) {
57403 + if (!have_same_root(current, p)) {
57404 + ret = 1;
57405 + goto out;
57406 + }
57407 + } while_each_pid_task(pid, type, p);
57408 +out:
57409 + read_unlock(&tasklist_lock);
57410 + return ret;
57411 +#endif
57412 + return 0;
57413 +}
57414 +
57415 +int
57416 +gr_pid_is_chrooted(struct task_struct *p)
57417 +{
57418 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57419 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57420 + return 0;
57421 +
57422 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57423 + !have_same_root(current, p)) {
57424 + return 1;
57425 + }
57426 +#endif
57427 + return 0;
57428 +}
57429 +
57430 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57431 +
57432 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57433 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57434 +{
57435 + struct path path, currentroot;
57436 + int ret = 0;
57437 +
57438 + path.dentry = (struct dentry *)u_dentry;
57439 + path.mnt = (struct vfsmount *)u_mnt;
57440 + get_fs_root(current->fs, &currentroot);
57441 + if (path_is_under(&path, &currentroot))
57442 + ret = 1;
57443 + path_put(&currentroot);
57444 +
57445 + return ret;
57446 +}
57447 +#endif
57448 +
57449 +int
57450 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57451 +{
57452 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57453 + if (!grsec_enable_chroot_fchdir)
57454 + return 1;
57455 +
57456 + if (!proc_is_chrooted(current))
57457 + return 1;
57458 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57459 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57460 + return 0;
57461 + }
57462 +#endif
57463 + return 1;
57464 +}
57465 +
57466 +int
57467 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57468 + const time_t shm_createtime)
57469 +{
57470 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57471 + struct task_struct *p;
57472 + time_t starttime;
57473 +
57474 + if (unlikely(!grsec_enable_chroot_shmat))
57475 + return 1;
57476 +
57477 + if (likely(!proc_is_chrooted(current)))
57478 + return 1;
57479 +
57480 + rcu_read_lock();
57481 + read_lock(&tasklist_lock);
57482 +
57483 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57484 + starttime = p->start_time.tv_sec;
57485 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57486 + if (have_same_root(current, p)) {
57487 + goto allow;
57488 + } else {
57489 + read_unlock(&tasklist_lock);
57490 + rcu_read_unlock();
57491 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57492 + return 0;
57493 + }
57494 + }
57495 + /* creator exited, pid reuse, fall through to next check */
57496 + }
57497 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57498 + if (unlikely(!have_same_root(current, p))) {
57499 + read_unlock(&tasklist_lock);
57500 + rcu_read_unlock();
57501 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57502 + return 0;
57503 + }
57504 + }
57505 +
57506 +allow:
57507 + read_unlock(&tasklist_lock);
57508 + rcu_read_unlock();
57509 +#endif
57510 + return 1;
57511 +}
57512 +
57513 +void
57514 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57515 +{
57516 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57517 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57518 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57519 +#endif
57520 + return;
57521 +}
57522 +
57523 +int
57524 +gr_handle_chroot_mknod(const struct dentry *dentry,
57525 + const struct vfsmount *mnt, const int mode)
57526 +{
57527 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57528 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57529 + proc_is_chrooted(current)) {
57530 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57531 + return -EPERM;
57532 + }
57533 +#endif
57534 + return 0;
57535 +}
57536 +
57537 +int
57538 +gr_handle_chroot_mount(const struct dentry *dentry,
57539 + const struct vfsmount *mnt, const char *dev_name)
57540 +{
57541 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57542 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57543 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57544 + return -EPERM;
57545 + }
57546 +#endif
57547 + return 0;
57548 +}
57549 +
57550 +int
57551 +gr_handle_chroot_pivot(void)
57552 +{
57553 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57554 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57555 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57556 + return -EPERM;
57557 + }
57558 +#endif
57559 + return 0;
57560 +}
57561 +
57562 +int
57563 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57564 +{
57565 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57566 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57567 + !gr_is_outside_chroot(dentry, mnt)) {
57568 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57569 + return -EPERM;
57570 + }
57571 +#endif
57572 + return 0;
57573 +}
57574 +
57575 +extern const char *captab_log[];
57576 +extern int captab_log_entries;
57577 +
57578 +int
57579 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57580 +{
57581 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57582 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57583 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57584 + if (cap_raised(chroot_caps, cap)) {
57585 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57586 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57587 + }
57588 + return 0;
57589 + }
57590 + }
57591 +#endif
57592 + return 1;
57593 +}
57594 +
57595 +int
57596 +gr_chroot_is_capable(const int cap)
57597 +{
57598 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57599 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57600 +#endif
57601 + return 1;
57602 +}
57603 +
57604 +int
57605 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57606 +{
57607 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57608 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57609 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57610 + if (cap_raised(chroot_caps, cap)) {
57611 + return 0;
57612 + }
57613 + }
57614 +#endif
57615 + return 1;
57616 +}
57617 +
57618 +int
57619 +gr_chroot_is_capable_nolog(const int cap)
57620 +{
57621 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57622 + return gr_task_chroot_is_capable_nolog(current, cap);
57623 +#endif
57624 + return 1;
57625 +}
57626 +
57627 +int
57628 +gr_handle_chroot_sysctl(const int op)
57629 +{
57630 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57631 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57632 + proc_is_chrooted(current))
57633 + return -EACCES;
57634 +#endif
57635 + return 0;
57636 +}
57637 +
57638 +void
57639 +gr_handle_chroot_chdir(struct path *path)
57640 +{
57641 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57642 + if (grsec_enable_chroot_chdir)
57643 + set_fs_pwd(current->fs, path);
57644 +#endif
57645 + return;
57646 +}
57647 +
57648 +int
57649 +gr_handle_chroot_chmod(const struct dentry *dentry,
57650 + const struct vfsmount *mnt, const int mode)
57651 +{
57652 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57653 + /* allow chmod +s on directories, but not files */
57654 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57655 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57656 + proc_is_chrooted(current)) {
57657 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57658 + return -EPERM;
57659 + }
57660 +#endif
57661 + return 0;
57662 +}
57663 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57664 new file mode 100644
57665 index 0000000..213ad8b
57666 --- /dev/null
57667 +++ b/grsecurity/grsec_disabled.c
57668 @@ -0,0 +1,437 @@
57669 +#include <linux/kernel.h>
57670 +#include <linux/module.h>
57671 +#include <linux/sched.h>
57672 +#include <linux/file.h>
57673 +#include <linux/fs.h>
57674 +#include <linux/kdev_t.h>
57675 +#include <linux/net.h>
57676 +#include <linux/in.h>
57677 +#include <linux/ip.h>
57678 +#include <linux/skbuff.h>
57679 +#include <linux/sysctl.h>
57680 +
57681 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57682 +void
57683 +pax_set_initial_flags(struct linux_binprm *bprm)
57684 +{
57685 + return;
57686 +}
57687 +#endif
57688 +
57689 +#ifdef CONFIG_SYSCTL
57690 +__u32
57691 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57692 +{
57693 + return 0;
57694 +}
57695 +#endif
57696 +
57697 +#ifdef CONFIG_TASKSTATS
57698 +int gr_is_taskstats_denied(int pid)
57699 +{
57700 + return 0;
57701 +}
57702 +#endif
57703 +
57704 +int
57705 +gr_acl_is_enabled(void)
57706 +{
57707 + return 0;
57708 +}
57709 +
57710 +void
57711 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57712 +{
57713 + return;
57714 +}
57715 +
57716 +int
57717 +gr_handle_rawio(const struct inode *inode)
57718 +{
57719 + return 0;
57720 +}
57721 +
57722 +void
57723 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57724 +{
57725 + return;
57726 +}
57727 +
57728 +int
57729 +gr_handle_ptrace(struct task_struct *task, const long request)
57730 +{
57731 + return 0;
57732 +}
57733 +
57734 +int
57735 +gr_handle_proc_ptrace(struct task_struct *task)
57736 +{
57737 + return 0;
57738 +}
57739 +
57740 +void
57741 +gr_learn_resource(const struct task_struct *task,
57742 + const int res, const unsigned long wanted, const int gt)
57743 +{
57744 + return;
57745 +}
57746 +
57747 +int
57748 +gr_set_acls(const int type)
57749 +{
57750 + return 0;
57751 +}
57752 +
57753 +int
57754 +gr_check_hidden_task(const struct task_struct *tsk)
57755 +{
57756 + return 0;
57757 +}
57758 +
57759 +int
57760 +gr_check_protected_task(const struct task_struct *task)
57761 +{
57762 + return 0;
57763 +}
57764 +
57765 +int
57766 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57767 +{
57768 + return 0;
57769 +}
57770 +
57771 +void
57772 +gr_copy_label(struct task_struct *tsk)
57773 +{
57774 + return;
57775 +}
57776 +
57777 +void
57778 +gr_set_pax_flags(struct task_struct *task)
57779 +{
57780 + return;
57781 +}
57782 +
57783 +int
57784 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57785 + const int unsafe_share)
57786 +{
57787 + return 0;
57788 +}
57789 +
57790 +void
57791 +gr_handle_delete(const ino_t ino, const dev_t dev)
57792 +{
57793 + return;
57794 +}
57795 +
57796 +void
57797 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57798 +{
57799 + return;
57800 +}
57801 +
57802 +void
57803 +gr_handle_crash(struct task_struct *task, const int sig)
57804 +{
57805 + return;
57806 +}
57807 +
57808 +int
57809 +gr_check_crash_exec(const struct file *filp)
57810 +{
57811 + return 0;
57812 +}
57813 +
57814 +int
57815 +gr_check_crash_uid(const uid_t uid)
57816 +{
57817 + return 0;
57818 +}
57819 +
57820 +void
57821 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57822 + struct dentry *old_dentry,
57823 + struct dentry *new_dentry,
57824 + struct vfsmount *mnt, const __u8 replace)
57825 +{
57826 + return;
57827 +}
57828 +
57829 +int
57830 +gr_search_socket(const int family, const int type, const int protocol)
57831 +{
57832 + return 1;
57833 +}
57834 +
57835 +int
57836 +gr_search_connectbind(const int mode, const struct socket *sock,
57837 + const struct sockaddr_in *addr)
57838 +{
57839 + return 0;
57840 +}
57841 +
57842 +void
57843 +gr_handle_alertkill(struct task_struct *task)
57844 +{
57845 + return;
57846 +}
57847 +
57848 +__u32
57849 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57850 +{
57851 + return 1;
57852 +}
57853 +
57854 +__u32
57855 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57856 + const struct vfsmount * mnt)
57857 +{
57858 + return 1;
57859 +}
57860 +
57861 +__u32
57862 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57863 + int acc_mode)
57864 +{
57865 + return 1;
57866 +}
57867 +
57868 +__u32
57869 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57870 +{
57871 + return 1;
57872 +}
57873 +
57874 +__u32
57875 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57876 +{
57877 + return 1;
57878 +}
57879 +
57880 +int
57881 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57882 + unsigned int *vm_flags)
57883 +{
57884 + return 1;
57885 +}
57886 +
57887 +__u32
57888 +gr_acl_handle_truncate(const struct dentry * dentry,
57889 + const struct vfsmount * mnt)
57890 +{
57891 + return 1;
57892 +}
57893 +
57894 +__u32
57895 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57896 +{
57897 + return 1;
57898 +}
57899 +
57900 +__u32
57901 +gr_acl_handle_access(const struct dentry * dentry,
57902 + const struct vfsmount * mnt, const int fmode)
57903 +{
57904 + return 1;
57905 +}
57906 +
57907 +__u32
57908 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57909 + umode_t *mode)
57910 +{
57911 + return 1;
57912 +}
57913 +
57914 +__u32
57915 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57916 +{
57917 + return 1;
57918 +}
57919 +
57920 +__u32
57921 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57922 +{
57923 + return 1;
57924 +}
57925 +
57926 +void
57927 +grsecurity_init(void)
57928 +{
57929 + return;
57930 +}
57931 +
57932 +umode_t gr_acl_umask(void)
57933 +{
57934 + return 0;
57935 +}
57936 +
57937 +__u32
57938 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57939 + const struct dentry * parent_dentry,
57940 + const struct vfsmount * parent_mnt,
57941 + const int mode)
57942 +{
57943 + return 1;
57944 +}
57945 +
57946 +__u32
57947 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57948 + const struct dentry * parent_dentry,
57949 + const struct vfsmount * parent_mnt)
57950 +{
57951 + return 1;
57952 +}
57953 +
57954 +__u32
57955 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57956 + const struct dentry * parent_dentry,
57957 + const struct vfsmount * parent_mnt, const char *from)
57958 +{
57959 + return 1;
57960 +}
57961 +
57962 +__u32
57963 +gr_acl_handle_link(const struct dentry * new_dentry,
57964 + const struct dentry * parent_dentry,
57965 + const struct vfsmount * parent_mnt,
57966 + const struct dentry * old_dentry,
57967 + const struct vfsmount * old_mnt, const char *to)
57968 +{
57969 + return 1;
57970 +}
57971 +
57972 +int
57973 +gr_acl_handle_rename(const struct dentry *new_dentry,
57974 + const struct dentry *parent_dentry,
57975 + const struct vfsmount *parent_mnt,
57976 + const struct dentry *old_dentry,
57977 + const struct inode *old_parent_inode,
57978 + const struct vfsmount *old_mnt, const char *newname)
57979 +{
57980 + return 0;
57981 +}
57982 +
57983 +int
57984 +gr_acl_handle_filldir(const struct file *file, const char *name,
57985 + const int namelen, const ino_t ino)
57986 +{
57987 + return 1;
57988 +}
57989 +
57990 +int
57991 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57992 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57993 +{
57994 + return 1;
57995 +}
57996 +
57997 +int
57998 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57999 +{
58000 + return 0;
58001 +}
58002 +
58003 +int
58004 +gr_search_accept(const struct socket *sock)
58005 +{
58006 + return 0;
58007 +}
58008 +
58009 +int
58010 +gr_search_listen(const struct socket *sock)
58011 +{
58012 + return 0;
58013 +}
58014 +
58015 +int
58016 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58017 +{
58018 + return 0;
58019 +}
58020 +
58021 +__u32
58022 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58023 +{
58024 + return 1;
58025 +}
58026 +
58027 +__u32
58028 +gr_acl_handle_creat(const struct dentry * dentry,
58029 + const struct dentry * p_dentry,
58030 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58031 + const int imode)
58032 +{
58033 + return 1;
58034 +}
58035 +
58036 +void
58037 +gr_acl_handle_exit(void)
58038 +{
58039 + return;
58040 +}
58041 +
58042 +int
58043 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58044 +{
58045 + return 1;
58046 +}
58047 +
58048 +void
58049 +gr_set_role_label(const uid_t uid, const gid_t gid)
58050 +{
58051 + return;
58052 +}
58053 +
58054 +int
58055 +gr_acl_handle_procpidmem(const struct task_struct *task)
58056 +{
58057 + return 0;
58058 +}
58059 +
58060 +int
58061 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58062 +{
58063 + return 0;
58064 +}
58065 +
58066 +int
58067 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58068 +{
58069 + return 0;
58070 +}
58071 +
58072 +void
58073 +gr_set_kernel_label(struct task_struct *task)
58074 +{
58075 + return;
58076 +}
58077 +
58078 +int
58079 +gr_check_user_change(int real, int effective, int fs)
58080 +{
58081 + return 0;
58082 +}
58083 +
58084 +int
58085 +gr_check_group_change(int real, int effective, int fs)
58086 +{
58087 + return 0;
58088 +}
58089 +
58090 +int gr_acl_enable_at_secure(void)
58091 +{
58092 + return 0;
58093 +}
58094 +
58095 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58096 +{
58097 + return dentry->d_inode->i_sb->s_dev;
58098 +}
58099 +
58100 +EXPORT_SYMBOL(gr_learn_resource);
58101 +EXPORT_SYMBOL(gr_set_kernel_label);
58102 +#ifdef CONFIG_SECURITY
58103 +EXPORT_SYMBOL(gr_check_user_change);
58104 +EXPORT_SYMBOL(gr_check_group_change);
58105 +#endif
58106 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58107 new file mode 100644
58108 index 0000000..abfa971
58109 --- /dev/null
58110 +++ b/grsecurity/grsec_exec.c
58111 @@ -0,0 +1,174 @@
58112 +#include <linux/kernel.h>
58113 +#include <linux/sched.h>
58114 +#include <linux/file.h>
58115 +#include <linux/binfmts.h>
58116 +#include <linux/fs.h>
58117 +#include <linux/types.h>
58118 +#include <linux/grdefs.h>
58119 +#include <linux/grsecurity.h>
58120 +#include <linux/grinternal.h>
58121 +#include <linux/capability.h>
58122 +#include <linux/module.h>
58123 +
58124 +#include <asm/uaccess.h>
58125 +
58126 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58127 +static char gr_exec_arg_buf[132];
58128 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58129 +#endif
58130 +
58131 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58132 +
58133 +void
58134 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58135 +{
58136 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58137 + char *grarg = gr_exec_arg_buf;
58138 + unsigned int i, x, execlen = 0;
58139 + char c;
58140 +
58141 + if (!((grsec_enable_execlog && grsec_enable_group &&
58142 + in_group_p(grsec_audit_gid))
58143 + || (grsec_enable_execlog && !grsec_enable_group)))
58144 + return;
58145 +
58146 + mutex_lock(&gr_exec_arg_mutex);
58147 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58148 +
58149 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58150 + const char __user *p;
58151 + unsigned int len;
58152 +
58153 + p = get_user_arg_ptr(argv, i);
58154 + if (IS_ERR(p))
58155 + goto log;
58156 +
58157 + len = strnlen_user(p, 128 - execlen);
58158 + if (len > 128 - execlen)
58159 + len = 128 - execlen;
58160 + else if (len > 0)
58161 + len--;
58162 + if (copy_from_user(grarg + execlen, p, len))
58163 + goto log;
58164 +
58165 + /* rewrite unprintable characters */
58166 + for (x = 0; x < len; x++) {
58167 + c = *(grarg + execlen + x);
58168 + if (c < 32 || c > 126)
58169 + *(grarg + execlen + x) = ' ';
58170 + }
58171 +
58172 + execlen += len;
58173 + *(grarg + execlen) = ' ';
58174 + *(grarg + execlen + 1) = '\0';
58175 + execlen++;
58176 + }
58177 +
58178 + log:
58179 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58180 + bprm->file->f_path.mnt, grarg);
58181 + mutex_unlock(&gr_exec_arg_mutex);
58182 +#endif
58183 + return;
58184 +}
58185 +
58186 +#ifdef CONFIG_GRKERNSEC
58187 +extern int gr_acl_is_capable(const int cap);
58188 +extern int gr_acl_is_capable_nolog(const int cap);
58189 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58190 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58191 +extern int gr_chroot_is_capable(const int cap);
58192 +extern int gr_chroot_is_capable_nolog(const int cap);
58193 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58194 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58195 +#endif
58196 +
58197 +const char *captab_log[] = {
58198 + "CAP_CHOWN",
58199 + "CAP_DAC_OVERRIDE",
58200 + "CAP_DAC_READ_SEARCH",
58201 + "CAP_FOWNER",
58202 + "CAP_FSETID",
58203 + "CAP_KILL",
58204 + "CAP_SETGID",
58205 + "CAP_SETUID",
58206 + "CAP_SETPCAP",
58207 + "CAP_LINUX_IMMUTABLE",
58208 + "CAP_NET_BIND_SERVICE",
58209 + "CAP_NET_BROADCAST",
58210 + "CAP_NET_ADMIN",
58211 + "CAP_NET_RAW",
58212 + "CAP_IPC_LOCK",
58213 + "CAP_IPC_OWNER",
58214 + "CAP_SYS_MODULE",
58215 + "CAP_SYS_RAWIO",
58216 + "CAP_SYS_CHROOT",
58217 + "CAP_SYS_PTRACE",
58218 + "CAP_SYS_PACCT",
58219 + "CAP_SYS_ADMIN",
58220 + "CAP_SYS_BOOT",
58221 + "CAP_SYS_NICE",
58222 + "CAP_SYS_RESOURCE",
58223 + "CAP_SYS_TIME",
58224 + "CAP_SYS_TTY_CONFIG",
58225 + "CAP_MKNOD",
58226 + "CAP_LEASE",
58227 + "CAP_AUDIT_WRITE",
58228 + "CAP_AUDIT_CONTROL",
58229 + "CAP_SETFCAP",
58230 + "CAP_MAC_OVERRIDE",
58231 + "CAP_MAC_ADMIN",
58232 + "CAP_SYSLOG",
58233 + "CAP_WAKE_ALARM"
58234 +};
58235 +
58236 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58237 +
58238 +int gr_is_capable(const int cap)
58239 +{
58240 +#ifdef CONFIG_GRKERNSEC
58241 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58242 + return 1;
58243 + return 0;
58244 +#else
58245 + return 1;
58246 +#endif
58247 +}
58248 +
58249 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58250 +{
58251 +#ifdef CONFIG_GRKERNSEC
58252 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58253 + return 1;
58254 + return 0;
58255 +#else
58256 + return 1;
58257 +#endif
58258 +}
58259 +
58260 +int gr_is_capable_nolog(const int cap)
58261 +{
58262 +#ifdef CONFIG_GRKERNSEC
58263 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58264 + return 1;
58265 + return 0;
58266 +#else
58267 + return 1;
58268 +#endif
58269 +}
58270 +
58271 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58272 +{
58273 +#ifdef CONFIG_GRKERNSEC
58274 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58275 + return 1;
58276 + return 0;
58277 +#else
58278 + return 1;
58279 +#endif
58280 +}
58281 +
58282 +EXPORT_SYMBOL(gr_is_capable);
58283 +EXPORT_SYMBOL(gr_is_capable_nolog);
58284 +EXPORT_SYMBOL(gr_task_is_capable);
58285 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58286 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58287 new file mode 100644
58288 index 0000000..d3ee748
58289 --- /dev/null
58290 +++ b/grsecurity/grsec_fifo.c
58291 @@ -0,0 +1,24 @@
58292 +#include <linux/kernel.h>
58293 +#include <linux/sched.h>
58294 +#include <linux/fs.h>
58295 +#include <linux/file.h>
58296 +#include <linux/grinternal.h>
58297 +
58298 +int
58299 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58300 + const struct dentry *dir, const int flag, const int acc_mode)
58301 +{
58302 +#ifdef CONFIG_GRKERNSEC_FIFO
58303 + const struct cred *cred = current_cred();
58304 +
58305 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58306 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58307 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58308 + (cred->fsuid != dentry->d_inode->i_uid)) {
58309 + if (!inode_permission(dentry->d_inode, acc_mode))
58310 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58311 + return -EACCES;
58312 + }
58313 +#endif
58314 + return 0;
58315 +}
58316 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58317 new file mode 100644
58318 index 0000000..8ca18bf
58319 --- /dev/null
58320 +++ b/grsecurity/grsec_fork.c
58321 @@ -0,0 +1,23 @@
58322 +#include <linux/kernel.h>
58323 +#include <linux/sched.h>
58324 +#include <linux/grsecurity.h>
58325 +#include <linux/grinternal.h>
58326 +#include <linux/errno.h>
58327 +
58328 +void
58329 +gr_log_forkfail(const int retval)
58330 +{
58331 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58332 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58333 + switch (retval) {
58334 + case -EAGAIN:
58335 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58336 + break;
58337 + case -ENOMEM:
58338 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58339 + break;
58340 + }
58341 + }
58342 +#endif
58343 + return;
58344 +}
58345 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58346 new file mode 100644
58347 index 0000000..05a6015
58348 --- /dev/null
58349 +++ b/grsecurity/grsec_init.c
58350 @@ -0,0 +1,283 @@
58351 +#include <linux/kernel.h>
58352 +#include <linux/sched.h>
58353 +#include <linux/mm.h>
58354 +#include <linux/gracl.h>
58355 +#include <linux/slab.h>
58356 +#include <linux/vmalloc.h>
58357 +#include <linux/percpu.h>
58358 +#include <linux/module.h>
58359 +
58360 +int grsec_enable_ptrace_readexec;
58361 +int grsec_enable_setxid;
58362 +int grsec_enable_symlinkown;
58363 +int grsec_symlinkown_gid;
58364 +int grsec_enable_brute;
58365 +int grsec_enable_link;
58366 +int grsec_enable_dmesg;
58367 +int grsec_enable_harden_ptrace;
58368 +int grsec_enable_fifo;
58369 +int grsec_enable_execlog;
58370 +int grsec_enable_signal;
58371 +int grsec_enable_forkfail;
58372 +int grsec_enable_audit_ptrace;
58373 +int grsec_enable_time;
58374 +int grsec_enable_audit_textrel;
58375 +int grsec_enable_group;
58376 +int grsec_audit_gid;
58377 +int grsec_enable_chdir;
58378 +int grsec_enable_mount;
58379 +int grsec_enable_rofs;
58380 +int grsec_enable_chroot_findtask;
58381 +int grsec_enable_chroot_mount;
58382 +int grsec_enable_chroot_shmat;
58383 +int grsec_enable_chroot_fchdir;
58384 +int grsec_enable_chroot_double;
58385 +int grsec_enable_chroot_pivot;
58386 +int grsec_enable_chroot_chdir;
58387 +int grsec_enable_chroot_chmod;
58388 +int grsec_enable_chroot_mknod;
58389 +int grsec_enable_chroot_nice;
58390 +int grsec_enable_chroot_execlog;
58391 +int grsec_enable_chroot_caps;
58392 +int grsec_enable_chroot_sysctl;
58393 +int grsec_enable_chroot_unix;
58394 +int grsec_enable_tpe;
58395 +int grsec_tpe_gid;
58396 +int grsec_enable_blackhole;
58397 +#ifdef CONFIG_IPV6_MODULE
58398 +EXPORT_SYMBOL(grsec_enable_blackhole);
58399 +#endif
58400 +int grsec_lastack_retries;
58401 +int grsec_enable_tpe_all;
58402 +int grsec_enable_tpe_invert;
58403 +int grsec_enable_socket_all;
58404 +int grsec_socket_all_gid;
58405 +int grsec_enable_socket_client;
58406 +int grsec_socket_client_gid;
58407 +int grsec_enable_socket_server;
58408 +int grsec_socket_server_gid;
58409 +int grsec_resource_logging;
58410 +int grsec_disable_privio;
58411 +int grsec_enable_log_rwxmaps;
58412 +int grsec_lock;
58413 +
58414 +DEFINE_SPINLOCK(grsec_alert_lock);
58415 +unsigned long grsec_alert_wtime = 0;
58416 +unsigned long grsec_alert_fyet = 0;
58417 +
58418 +DEFINE_SPINLOCK(grsec_audit_lock);
58419 +
58420 +DEFINE_RWLOCK(grsec_exec_file_lock);
58421 +
58422 +char *gr_shared_page[4];
58423 +
58424 +char *gr_alert_log_fmt;
58425 +char *gr_audit_log_fmt;
58426 +char *gr_alert_log_buf;
58427 +char *gr_audit_log_buf;
58428 +
58429 +extern struct gr_arg *gr_usermode;
58430 +extern unsigned char *gr_system_salt;
58431 +extern unsigned char *gr_system_sum;
58432 +
58433 +void __init
58434 +grsecurity_init(void)
58435 +{
58436 + int j;
58437 + /* create the per-cpu shared pages */
58438 +
58439 +#ifdef CONFIG_X86
58440 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58441 +#endif
58442 +
58443 + for (j = 0; j < 4; j++) {
58444 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58445 + if (gr_shared_page[j] == NULL) {
58446 + panic("Unable to allocate grsecurity shared page");
58447 + return;
58448 + }
58449 + }
58450 +
58451 + /* allocate log buffers */
58452 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58453 + if (!gr_alert_log_fmt) {
58454 + panic("Unable to allocate grsecurity alert log format buffer");
58455 + return;
58456 + }
58457 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58458 + if (!gr_audit_log_fmt) {
58459 + panic("Unable to allocate grsecurity audit log format buffer");
58460 + return;
58461 + }
58462 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58463 + if (!gr_alert_log_buf) {
58464 + panic("Unable to allocate grsecurity alert log buffer");
58465 + return;
58466 + }
58467 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58468 + if (!gr_audit_log_buf) {
58469 + panic("Unable to allocate grsecurity audit log buffer");
58470 + return;
58471 + }
58472 +
58473 + /* allocate memory for authentication structure */
58474 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58475 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58476 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58477 +
58478 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58479 + panic("Unable to allocate grsecurity authentication structure");
58480 + return;
58481 + }
58482 +
58483 +
58484 +#ifdef CONFIG_GRKERNSEC_IO
58485 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58486 + grsec_disable_privio = 1;
58487 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58488 + grsec_disable_privio = 1;
58489 +#else
58490 + grsec_disable_privio = 0;
58491 +#endif
58492 +#endif
58493 +
58494 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58495 + /* for backward compatibility, tpe_invert always defaults to on if
58496 + enabled in the kernel
58497 + */
58498 + grsec_enable_tpe_invert = 1;
58499 +#endif
58500 +
58501 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58502 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58503 + grsec_lock = 1;
58504 +#endif
58505 +
58506 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58507 + grsec_enable_audit_textrel = 1;
58508 +#endif
58509 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58510 + grsec_enable_log_rwxmaps = 1;
58511 +#endif
58512 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58513 + grsec_enable_group = 1;
58514 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58515 +#endif
58516 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58517 + grsec_enable_ptrace_readexec = 1;
58518 +#endif
58519 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58520 + grsec_enable_chdir = 1;
58521 +#endif
58522 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58523 + grsec_enable_harden_ptrace = 1;
58524 +#endif
58525 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58526 + grsec_enable_mount = 1;
58527 +#endif
58528 +#ifdef CONFIG_GRKERNSEC_LINK
58529 + grsec_enable_link = 1;
58530 +#endif
58531 +#ifdef CONFIG_GRKERNSEC_BRUTE
58532 + grsec_enable_brute = 1;
58533 +#endif
58534 +#ifdef CONFIG_GRKERNSEC_DMESG
58535 + grsec_enable_dmesg = 1;
58536 +#endif
58537 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58538 + grsec_enable_blackhole = 1;
58539 + grsec_lastack_retries = 4;
58540 +#endif
58541 +#ifdef CONFIG_GRKERNSEC_FIFO
58542 + grsec_enable_fifo = 1;
58543 +#endif
58544 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58545 + grsec_enable_execlog = 1;
58546 +#endif
58547 +#ifdef CONFIG_GRKERNSEC_SETXID
58548 + grsec_enable_setxid = 1;
58549 +#endif
58550 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58551 + grsec_enable_signal = 1;
58552 +#endif
58553 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58554 + grsec_enable_forkfail = 1;
58555 +#endif
58556 +#ifdef CONFIG_GRKERNSEC_TIME
58557 + grsec_enable_time = 1;
58558 +#endif
58559 +#ifdef CONFIG_GRKERNSEC_RESLOG
58560 + grsec_resource_logging = 1;
58561 +#endif
58562 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58563 + grsec_enable_chroot_findtask = 1;
58564 +#endif
58565 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58566 + grsec_enable_chroot_unix = 1;
58567 +#endif
58568 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58569 + grsec_enable_chroot_mount = 1;
58570 +#endif
58571 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58572 + grsec_enable_chroot_fchdir = 1;
58573 +#endif
58574 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58575 + grsec_enable_chroot_shmat = 1;
58576 +#endif
58577 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58578 + grsec_enable_audit_ptrace = 1;
58579 +#endif
58580 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58581 + grsec_enable_chroot_double = 1;
58582 +#endif
58583 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58584 + grsec_enable_chroot_pivot = 1;
58585 +#endif
58586 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58587 + grsec_enable_chroot_chdir = 1;
58588 +#endif
58589 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58590 + grsec_enable_chroot_chmod = 1;
58591 +#endif
58592 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58593 + grsec_enable_chroot_mknod = 1;
58594 +#endif
58595 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58596 + grsec_enable_chroot_nice = 1;
58597 +#endif
58598 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58599 + grsec_enable_chroot_execlog = 1;
58600 +#endif
58601 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58602 + grsec_enable_chroot_caps = 1;
58603 +#endif
58604 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58605 + grsec_enable_chroot_sysctl = 1;
58606 +#endif
58607 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58608 + grsec_enable_symlinkown = 1;
58609 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58610 +#endif
58611 +#ifdef CONFIG_GRKERNSEC_TPE
58612 + grsec_enable_tpe = 1;
58613 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58614 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58615 + grsec_enable_tpe_all = 1;
58616 +#endif
58617 +#endif
58618 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58619 + grsec_enable_socket_all = 1;
58620 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58621 +#endif
58622 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58623 + grsec_enable_socket_client = 1;
58624 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58625 +#endif
58626 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58627 + grsec_enable_socket_server = 1;
58628 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58629 +#endif
58630 +#endif
58631 +
58632 + return;
58633 +}
58634 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58635 new file mode 100644
58636 index 0000000..589481f
58637 --- /dev/null
58638 +++ b/grsecurity/grsec_link.c
58639 @@ -0,0 +1,58 @@
58640 +#include <linux/kernel.h>
58641 +#include <linux/sched.h>
58642 +#include <linux/fs.h>
58643 +#include <linux/file.h>
58644 +#include <linux/grinternal.h>
58645 +
58646 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58647 +{
58648 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58649 + const struct inode *link_inode = link->dentry->d_inode;
58650 +
58651 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58652 + /* ignore root-owned links, e.g. /proc/self */
58653 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58654 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58655 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58656 + return 1;
58657 + }
58658 +#endif
58659 + return 0;
58660 +}
58661 +
58662 +int
58663 +gr_handle_follow_link(const struct inode *parent,
58664 + const struct inode *inode,
58665 + const struct dentry *dentry, const struct vfsmount *mnt)
58666 +{
58667 +#ifdef CONFIG_GRKERNSEC_LINK
58668 + const struct cred *cred = current_cred();
58669 +
58670 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58671 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58672 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58673 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58674 + return -EACCES;
58675 + }
58676 +#endif
58677 + return 0;
58678 +}
58679 +
58680 +int
58681 +gr_handle_hardlink(const struct dentry *dentry,
58682 + const struct vfsmount *mnt,
58683 + struct inode *inode, const int mode, const char *to)
58684 +{
58685 +#ifdef CONFIG_GRKERNSEC_LINK
58686 + const struct cred *cred = current_cred();
58687 +
58688 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58689 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58690 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58691 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58692 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58693 + return -EPERM;
58694 + }
58695 +#endif
58696 + return 0;
58697 +}
58698 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58699 new file mode 100644
58700 index 0000000..a45d2e9
58701 --- /dev/null
58702 +++ b/grsecurity/grsec_log.c
58703 @@ -0,0 +1,322 @@
58704 +#include <linux/kernel.h>
58705 +#include <linux/sched.h>
58706 +#include <linux/file.h>
58707 +#include <linux/tty.h>
58708 +#include <linux/fs.h>
58709 +#include <linux/grinternal.h>
58710 +
58711 +#ifdef CONFIG_TREE_PREEMPT_RCU
58712 +#define DISABLE_PREEMPT() preempt_disable()
58713 +#define ENABLE_PREEMPT() preempt_enable()
58714 +#else
58715 +#define DISABLE_PREEMPT()
58716 +#define ENABLE_PREEMPT()
58717 +#endif
58718 +
58719 +#define BEGIN_LOCKS(x) \
58720 + DISABLE_PREEMPT(); \
58721 + rcu_read_lock(); \
58722 + read_lock(&tasklist_lock); \
58723 + read_lock(&grsec_exec_file_lock); \
58724 + if (x != GR_DO_AUDIT) \
58725 + spin_lock(&grsec_alert_lock); \
58726 + else \
58727 + spin_lock(&grsec_audit_lock)
58728 +
58729 +#define END_LOCKS(x) \
58730 + if (x != GR_DO_AUDIT) \
58731 + spin_unlock(&grsec_alert_lock); \
58732 + else \
58733 + spin_unlock(&grsec_audit_lock); \
58734 + read_unlock(&grsec_exec_file_lock); \
58735 + read_unlock(&tasklist_lock); \
58736 + rcu_read_unlock(); \
58737 + ENABLE_PREEMPT(); \
58738 + if (x == GR_DONT_AUDIT) \
58739 + gr_handle_alertkill(current)
58740 +
58741 +enum {
58742 + FLOODING,
58743 + NO_FLOODING
58744 +};
58745 +
58746 +extern char *gr_alert_log_fmt;
58747 +extern char *gr_audit_log_fmt;
58748 +extern char *gr_alert_log_buf;
58749 +extern char *gr_audit_log_buf;
58750 +
58751 +static int gr_log_start(int audit)
58752 +{
58753 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58754 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58755 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58756 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58757 + unsigned long curr_secs = get_seconds();
58758 +
58759 + if (audit == GR_DO_AUDIT)
58760 + goto set_fmt;
58761 +
58762 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58763 + grsec_alert_wtime = curr_secs;
58764 + grsec_alert_fyet = 0;
58765 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58766 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58767 + grsec_alert_fyet++;
58768 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58769 + grsec_alert_wtime = curr_secs;
58770 + grsec_alert_fyet++;
58771 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58772 + return FLOODING;
58773 + }
58774 + else return FLOODING;
58775 +
58776 +set_fmt:
58777 +#endif
58778 + memset(buf, 0, PAGE_SIZE);
58779 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58780 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58781 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58782 + } else if (current->signal->curr_ip) {
58783 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58784 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58785 + } else if (gr_acl_is_enabled()) {
58786 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58787 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58788 + } else {
58789 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58790 + strcpy(buf, fmt);
58791 + }
58792 +
58793 + return NO_FLOODING;
58794 +}
58795 +
58796 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58797 + __attribute__ ((format (printf, 2, 0)));
58798 +
58799 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58800 +{
58801 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58802 + unsigned int len = strlen(buf);
58803 +
58804 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58805 +
58806 + return;
58807 +}
58808 +
58809 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58810 + __attribute__ ((format (printf, 2, 3)));
58811 +
58812 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58813 +{
58814 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58815 + unsigned int len = strlen(buf);
58816 + va_list ap;
58817 +
58818 + va_start(ap, msg);
58819 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58820 + va_end(ap);
58821 +
58822 + return;
58823 +}
58824 +
58825 +static void gr_log_end(int audit, int append_default)
58826 +{
58827 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58828 +
58829 + if (append_default) {
58830 + unsigned int len = strlen(buf);
58831 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58832 + }
58833 +
58834 + printk("%s\n", buf);
58835 +
58836 + return;
58837 +}
58838 +
58839 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58840 +{
58841 + int logtype;
58842 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58843 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58844 + void *voidptr = NULL;
58845 + int num1 = 0, num2 = 0;
58846 + unsigned long ulong1 = 0, ulong2 = 0;
58847 + struct dentry *dentry = NULL;
58848 + struct vfsmount *mnt = NULL;
58849 + struct file *file = NULL;
58850 + struct task_struct *task = NULL;
58851 + const struct cred *cred, *pcred;
58852 + va_list ap;
58853 +
58854 + BEGIN_LOCKS(audit);
58855 + logtype = gr_log_start(audit);
58856 + if (logtype == FLOODING) {
58857 + END_LOCKS(audit);
58858 + return;
58859 + }
58860 + va_start(ap, argtypes);
58861 + switch (argtypes) {
58862 + case GR_TTYSNIFF:
58863 + task = va_arg(ap, struct task_struct *);
58864 + 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);
58865 + break;
58866 + case GR_SYSCTL_HIDDEN:
58867 + str1 = va_arg(ap, char *);
58868 + gr_log_middle_varargs(audit, msg, result, str1);
58869 + break;
58870 + case GR_RBAC:
58871 + dentry = va_arg(ap, struct dentry *);
58872 + mnt = va_arg(ap, struct vfsmount *);
58873 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58874 + break;
58875 + case GR_RBAC_STR:
58876 + dentry = va_arg(ap, struct dentry *);
58877 + mnt = va_arg(ap, struct vfsmount *);
58878 + str1 = va_arg(ap, char *);
58879 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58880 + break;
58881 + case GR_STR_RBAC:
58882 + str1 = va_arg(ap, char *);
58883 + dentry = va_arg(ap, struct dentry *);
58884 + mnt = va_arg(ap, struct vfsmount *);
58885 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58886 + break;
58887 + case GR_RBAC_MODE2:
58888 + dentry = va_arg(ap, struct dentry *);
58889 + mnt = va_arg(ap, struct vfsmount *);
58890 + str1 = va_arg(ap, char *);
58891 + str2 = va_arg(ap, char *);
58892 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58893 + break;
58894 + case GR_RBAC_MODE3:
58895 + dentry = va_arg(ap, struct dentry *);
58896 + mnt = va_arg(ap, struct vfsmount *);
58897 + str1 = va_arg(ap, char *);
58898 + str2 = va_arg(ap, char *);
58899 + str3 = va_arg(ap, char *);
58900 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58901 + break;
58902 + case GR_FILENAME:
58903 + dentry = va_arg(ap, struct dentry *);
58904 + mnt = va_arg(ap, struct vfsmount *);
58905 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58906 + break;
58907 + case GR_STR_FILENAME:
58908 + str1 = va_arg(ap, char *);
58909 + dentry = va_arg(ap, struct dentry *);
58910 + mnt = va_arg(ap, struct vfsmount *);
58911 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58912 + break;
58913 + case GR_FILENAME_STR:
58914 + dentry = va_arg(ap, struct dentry *);
58915 + mnt = va_arg(ap, struct vfsmount *);
58916 + str1 = va_arg(ap, char *);
58917 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58918 + break;
58919 + case GR_FILENAME_TWO_INT:
58920 + dentry = va_arg(ap, struct dentry *);
58921 + mnt = va_arg(ap, struct vfsmount *);
58922 + num1 = va_arg(ap, int);
58923 + num2 = va_arg(ap, int);
58924 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58925 + break;
58926 + case GR_FILENAME_TWO_INT_STR:
58927 + dentry = va_arg(ap, struct dentry *);
58928 + mnt = va_arg(ap, struct vfsmount *);
58929 + num1 = va_arg(ap, int);
58930 + num2 = va_arg(ap, int);
58931 + str1 = va_arg(ap, char *);
58932 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58933 + break;
58934 + case GR_TEXTREL:
58935 + file = va_arg(ap, struct file *);
58936 + ulong1 = va_arg(ap, unsigned long);
58937 + ulong2 = va_arg(ap, unsigned long);
58938 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58939 + break;
58940 + case GR_PTRACE:
58941 + task = va_arg(ap, struct task_struct *);
58942 + 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);
58943 + break;
58944 + case GR_RESOURCE:
58945 + task = va_arg(ap, struct task_struct *);
58946 + cred = __task_cred(task);
58947 + pcred = __task_cred(task->real_parent);
58948 + ulong1 = va_arg(ap, unsigned long);
58949 + str1 = va_arg(ap, char *);
58950 + ulong2 = va_arg(ap, unsigned long);
58951 + 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);
58952 + break;
58953 + case GR_CAP:
58954 + task = va_arg(ap, struct task_struct *);
58955 + cred = __task_cred(task);
58956 + pcred = __task_cred(task->real_parent);
58957 + str1 = va_arg(ap, char *);
58958 + 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);
58959 + break;
58960 + case GR_SIG:
58961 + str1 = va_arg(ap, char *);
58962 + voidptr = va_arg(ap, void *);
58963 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58964 + break;
58965 + case GR_SIG2:
58966 + task = va_arg(ap, struct task_struct *);
58967 + cred = __task_cred(task);
58968 + pcred = __task_cred(task->real_parent);
58969 + num1 = va_arg(ap, int);
58970 + 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);
58971 + break;
58972 + case GR_CRASH1:
58973 + task = va_arg(ap, struct task_struct *);
58974 + cred = __task_cred(task);
58975 + pcred = __task_cred(task->real_parent);
58976 + ulong1 = va_arg(ap, unsigned long);
58977 + 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);
58978 + break;
58979 + case GR_CRASH2:
58980 + task = va_arg(ap, struct task_struct *);
58981 + cred = __task_cred(task);
58982 + pcred = __task_cred(task->real_parent);
58983 + ulong1 = va_arg(ap, unsigned long);
58984 + 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);
58985 + break;
58986 + case GR_RWXMAP:
58987 + file = va_arg(ap, struct file *);
58988 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58989 + break;
58990 + case GR_PSACCT:
58991 + {
58992 + unsigned int wday, cday;
58993 + __u8 whr, chr;
58994 + __u8 wmin, cmin;
58995 + __u8 wsec, csec;
58996 + char cur_tty[64] = { 0 };
58997 + char parent_tty[64] = { 0 };
58998 +
58999 + task = va_arg(ap, struct task_struct *);
59000 + wday = va_arg(ap, unsigned int);
59001 + cday = va_arg(ap, unsigned int);
59002 + whr = va_arg(ap, int);
59003 + chr = va_arg(ap, int);
59004 + wmin = va_arg(ap, int);
59005 + cmin = va_arg(ap, int);
59006 + wsec = va_arg(ap, int);
59007 + csec = va_arg(ap, int);
59008 + ulong1 = va_arg(ap, unsigned long);
59009 + cred = __task_cred(task);
59010 + pcred = __task_cred(task->real_parent);
59011 +
59012 + 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);
59013 + }
59014 + break;
59015 + default:
59016 + gr_log_middle(audit, msg, ap);
59017 + }
59018 + va_end(ap);
59019 + // these don't need DEFAULTSECARGS printed on the end
59020 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59021 + gr_log_end(audit, 0);
59022 + else
59023 + gr_log_end(audit, 1);
59024 + END_LOCKS(audit);
59025 +}
59026 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59027 new file mode 100644
59028 index 0000000..f536303
59029 --- /dev/null
59030 +++ b/grsecurity/grsec_mem.c
59031 @@ -0,0 +1,40 @@
59032 +#include <linux/kernel.h>
59033 +#include <linux/sched.h>
59034 +#include <linux/mm.h>
59035 +#include <linux/mman.h>
59036 +#include <linux/grinternal.h>
59037 +
59038 +void
59039 +gr_handle_ioperm(void)
59040 +{
59041 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59042 + return;
59043 +}
59044 +
59045 +void
59046 +gr_handle_iopl(void)
59047 +{
59048 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59049 + return;
59050 +}
59051 +
59052 +void
59053 +gr_handle_mem_readwrite(u64 from, u64 to)
59054 +{
59055 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59056 + return;
59057 +}
59058 +
59059 +void
59060 +gr_handle_vm86(void)
59061 +{
59062 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59063 + return;
59064 +}
59065 +
59066 +void
59067 +gr_log_badprocpid(const char *entry)
59068 +{
59069 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59070 + return;
59071 +}
59072 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59073 new file mode 100644
59074 index 0000000..2131422
59075 --- /dev/null
59076 +++ b/grsecurity/grsec_mount.c
59077 @@ -0,0 +1,62 @@
59078 +#include <linux/kernel.h>
59079 +#include <linux/sched.h>
59080 +#include <linux/mount.h>
59081 +#include <linux/grsecurity.h>
59082 +#include <linux/grinternal.h>
59083 +
59084 +void
59085 +gr_log_remount(const char *devname, const int retval)
59086 +{
59087 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59088 + if (grsec_enable_mount && (retval >= 0))
59089 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59090 +#endif
59091 + return;
59092 +}
59093 +
59094 +void
59095 +gr_log_unmount(const char *devname, const int retval)
59096 +{
59097 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59098 + if (grsec_enable_mount && (retval >= 0))
59099 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59100 +#endif
59101 + return;
59102 +}
59103 +
59104 +void
59105 +gr_log_mount(const char *from, const char *to, const int retval)
59106 +{
59107 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59108 + if (grsec_enable_mount && (retval >= 0))
59109 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59110 +#endif
59111 + return;
59112 +}
59113 +
59114 +int
59115 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59116 +{
59117 +#ifdef CONFIG_GRKERNSEC_ROFS
59118 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59119 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59120 + return -EPERM;
59121 + } else
59122 + return 0;
59123 +#endif
59124 + return 0;
59125 +}
59126 +
59127 +int
59128 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59129 +{
59130 +#ifdef CONFIG_GRKERNSEC_ROFS
59131 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59132 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59133 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59134 + return -EPERM;
59135 + } else
59136 + return 0;
59137 +#endif
59138 + return 0;
59139 +}
59140 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59141 new file mode 100644
59142 index 0000000..a3b12a0
59143 --- /dev/null
59144 +++ b/grsecurity/grsec_pax.c
59145 @@ -0,0 +1,36 @@
59146 +#include <linux/kernel.h>
59147 +#include <linux/sched.h>
59148 +#include <linux/mm.h>
59149 +#include <linux/file.h>
59150 +#include <linux/grinternal.h>
59151 +#include <linux/grsecurity.h>
59152 +
59153 +void
59154 +gr_log_textrel(struct vm_area_struct * vma)
59155 +{
59156 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59157 + if (grsec_enable_audit_textrel)
59158 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59159 +#endif
59160 + return;
59161 +}
59162 +
59163 +void
59164 +gr_log_rwxmmap(struct file *file)
59165 +{
59166 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59167 + if (grsec_enable_log_rwxmaps)
59168 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59169 +#endif
59170 + return;
59171 +}
59172 +
59173 +void
59174 +gr_log_rwxmprotect(struct file *file)
59175 +{
59176 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59177 + if (grsec_enable_log_rwxmaps)
59178 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59179 +#endif
59180 + return;
59181 +}
59182 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59183 new file mode 100644
59184 index 0000000..f7f29aa
59185 --- /dev/null
59186 +++ b/grsecurity/grsec_ptrace.c
59187 @@ -0,0 +1,30 @@
59188 +#include <linux/kernel.h>
59189 +#include <linux/sched.h>
59190 +#include <linux/grinternal.h>
59191 +#include <linux/security.h>
59192 +
59193 +void
59194 +gr_audit_ptrace(struct task_struct *task)
59195 +{
59196 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59197 + if (grsec_enable_audit_ptrace)
59198 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59199 +#endif
59200 + return;
59201 +}
59202 +
59203 +int
59204 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59205 +{
59206 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59207 + const struct dentry *dentry = file->f_path.dentry;
59208 + const struct vfsmount *mnt = file->f_path.mnt;
59209 +
59210 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59211 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59212 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59213 + return -EACCES;
59214 + }
59215 +#endif
59216 + return 0;
59217 +}
59218 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59219 new file mode 100644
59220 index 0000000..b4ac94c
59221 --- /dev/null
59222 +++ b/grsecurity/grsec_sig.c
59223 @@ -0,0 +1,209 @@
59224 +#include <linux/kernel.h>
59225 +#include <linux/sched.h>
59226 +#include <linux/delay.h>
59227 +#include <linux/grsecurity.h>
59228 +#include <linux/grinternal.h>
59229 +#include <linux/hardirq.h>
59230 +
59231 +char *signames[] = {
59232 + [SIGSEGV] = "Segmentation fault",
59233 + [SIGILL] = "Illegal instruction",
59234 + [SIGABRT] = "Abort",
59235 + [SIGBUS] = "Invalid alignment/Bus error"
59236 +};
59237 +
59238 +void
59239 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59240 +{
59241 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59242 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59243 + (sig == SIGABRT) || (sig == SIGBUS))) {
59244 + if (t->pid == current->pid) {
59245 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59246 + } else {
59247 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59248 + }
59249 + }
59250 +#endif
59251 + return;
59252 +}
59253 +
59254 +int
59255 +gr_handle_signal(const struct task_struct *p, const int sig)
59256 +{
59257 +#ifdef CONFIG_GRKERNSEC
59258 + /* ignore the 0 signal for protected task checks */
59259 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59260 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59261 + return -EPERM;
59262 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59263 + return -EPERM;
59264 + }
59265 +#endif
59266 + return 0;
59267 +}
59268 +
59269 +#ifdef CONFIG_GRKERNSEC
59270 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59271 +
59272 +int gr_fake_force_sig(int sig, struct task_struct *t)
59273 +{
59274 + unsigned long int flags;
59275 + int ret, blocked, ignored;
59276 + struct k_sigaction *action;
59277 +
59278 + spin_lock_irqsave(&t->sighand->siglock, flags);
59279 + action = &t->sighand->action[sig-1];
59280 + ignored = action->sa.sa_handler == SIG_IGN;
59281 + blocked = sigismember(&t->blocked, sig);
59282 + if (blocked || ignored) {
59283 + action->sa.sa_handler = SIG_DFL;
59284 + if (blocked) {
59285 + sigdelset(&t->blocked, sig);
59286 + recalc_sigpending_and_wake(t);
59287 + }
59288 + }
59289 + if (action->sa.sa_handler == SIG_DFL)
59290 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59291 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59292 +
59293 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59294 +
59295 + return ret;
59296 +}
59297 +#endif
59298 +
59299 +#ifdef CONFIG_GRKERNSEC_BRUTE
59300 +#define GR_USER_BAN_TIME (15 * 60)
59301 +
59302 +static int __get_dumpable(unsigned long mm_flags)
59303 +{
59304 + int ret;
59305 +
59306 + ret = mm_flags & MMF_DUMPABLE_MASK;
59307 + return (ret >= 2) ? 2 : ret;
59308 +}
59309 +#endif
59310 +
59311 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59312 +{
59313 +#ifdef CONFIG_GRKERNSEC_BRUTE
59314 + kuid_t uid = GLOBAL_ROOT_UID;
59315 +
59316 + if (!grsec_enable_brute)
59317 + return;
59318 +
59319 + rcu_read_lock();
59320 + read_lock(&tasklist_lock);
59321 + read_lock(&grsec_exec_file_lock);
59322 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59323 + p->real_parent->brute = 1;
59324 + else {
59325 + const struct cred *cred = __task_cred(p), *cred2;
59326 + struct task_struct *tsk, *tsk2;
59327 +
59328 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59329 + struct user_struct *user;
59330 +
59331 + uid = cred->uid;
59332 +
59333 + /* this is put upon execution past expiration */
59334 + user = find_user(uid);
59335 + if (user == NULL)
59336 + goto unlock;
59337 + user->banned = 1;
59338 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59339 + if (user->ban_expires == ~0UL)
59340 + user->ban_expires--;
59341 +
59342 + do_each_thread(tsk2, tsk) {
59343 + cred2 = __task_cred(tsk);
59344 + if (tsk != p && uid_eq(cred2->uid, uid))
59345 + gr_fake_force_sig(SIGKILL, tsk);
59346 + } while_each_thread(tsk2, tsk);
59347 + }
59348 + }
59349 +unlock:
59350 + read_unlock(&grsec_exec_file_lock);
59351 + read_unlock(&tasklist_lock);
59352 + rcu_read_unlock();
59353 +
59354 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59355 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59356 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59357 +
59358 +#endif
59359 + return;
59360 +}
59361 +
59362 +void gr_handle_brute_check(void)
59363 +{
59364 +#ifdef CONFIG_GRKERNSEC_BRUTE
59365 + if (current->brute)
59366 + msleep(30 * 1000);
59367 +#endif
59368 + return;
59369 +}
59370 +
59371 +void gr_handle_kernel_exploit(void)
59372 +{
59373 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59374 + const struct cred *cred;
59375 + struct task_struct *tsk, *tsk2;
59376 + struct user_struct *user;
59377 + kuid_t uid;
59378 +
59379 + if (in_irq() || in_serving_softirq() || in_nmi())
59380 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59381 +
59382 + uid = current_uid();
59383 +
59384 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59385 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59386 + else {
59387 + /* kill all the processes of this user, hold a reference
59388 + to their creds struct, and prevent them from creating
59389 + another process until system reset
59390 + */
59391 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59392 + from_kuid_munged(&init_user_ns, uid));
59393 + /* we intentionally leak this ref */
59394 + user = get_uid(current->cred->user);
59395 + if (user) {
59396 + user->banned = 1;
59397 + user->ban_expires = ~0UL;
59398 + }
59399 +
59400 + read_lock(&tasklist_lock);
59401 + do_each_thread(tsk2, tsk) {
59402 + cred = __task_cred(tsk);
59403 + if (uid_eq(cred->uid, uid))
59404 + gr_fake_force_sig(SIGKILL, tsk);
59405 + } while_each_thread(tsk2, tsk);
59406 + read_unlock(&tasklist_lock);
59407 + }
59408 +#endif
59409 +}
59410 +
59411 +int __gr_process_user_ban(struct user_struct *user)
59412 +{
59413 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59414 + if (unlikely(user->banned)) {
59415 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59416 + user->banned = 0;
59417 + user->ban_expires = 0;
59418 + free_uid(user);
59419 + } else
59420 + return -EPERM;
59421 + }
59422 +#endif
59423 + return 0;
59424 +}
59425 +
59426 +int gr_process_user_ban(void)
59427 +{
59428 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59429 + return __gr_process_user_ban(current->cred->user);
59430 +#endif
59431 + return 0;
59432 +}
59433 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59434 new file mode 100644
59435 index 0000000..4030d57
59436 --- /dev/null
59437 +++ b/grsecurity/grsec_sock.c
59438 @@ -0,0 +1,244 @@
59439 +#include <linux/kernel.h>
59440 +#include <linux/module.h>
59441 +#include <linux/sched.h>
59442 +#include <linux/file.h>
59443 +#include <linux/net.h>
59444 +#include <linux/in.h>
59445 +#include <linux/ip.h>
59446 +#include <net/sock.h>
59447 +#include <net/inet_sock.h>
59448 +#include <linux/grsecurity.h>
59449 +#include <linux/grinternal.h>
59450 +#include <linux/gracl.h>
59451 +
59452 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59453 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59454 +
59455 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59456 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59457 +
59458 +#ifdef CONFIG_UNIX_MODULE
59459 +EXPORT_SYMBOL(gr_acl_handle_unix);
59460 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59461 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59462 +EXPORT_SYMBOL(gr_handle_create);
59463 +#endif
59464 +
59465 +#ifdef CONFIG_GRKERNSEC
59466 +#define gr_conn_table_size 32749
59467 +struct conn_table_entry {
59468 + struct conn_table_entry *next;
59469 + struct signal_struct *sig;
59470 +};
59471 +
59472 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59473 +DEFINE_SPINLOCK(gr_conn_table_lock);
59474 +
59475 +extern const char * gr_socktype_to_name(unsigned char type);
59476 +extern const char * gr_proto_to_name(unsigned char proto);
59477 +extern const char * gr_sockfamily_to_name(unsigned char family);
59478 +
59479 +static __inline__ int
59480 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59481 +{
59482 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59483 +}
59484 +
59485 +static __inline__ int
59486 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59487 + __u16 sport, __u16 dport)
59488 +{
59489 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59490 + sig->gr_sport == sport && sig->gr_dport == dport))
59491 + return 1;
59492 + else
59493 + return 0;
59494 +}
59495 +
59496 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59497 +{
59498 + struct conn_table_entry **match;
59499 + unsigned int index;
59500 +
59501 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59502 + sig->gr_sport, sig->gr_dport,
59503 + gr_conn_table_size);
59504 +
59505 + newent->sig = sig;
59506 +
59507 + match = &gr_conn_table[index];
59508 + newent->next = *match;
59509 + *match = newent;
59510 +
59511 + return;
59512 +}
59513 +
59514 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59515 +{
59516 + struct conn_table_entry *match, *last = NULL;
59517 + unsigned int index;
59518 +
59519 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59520 + sig->gr_sport, sig->gr_dport,
59521 + gr_conn_table_size);
59522 +
59523 + match = gr_conn_table[index];
59524 + while (match && !conn_match(match->sig,
59525 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59526 + sig->gr_dport)) {
59527 + last = match;
59528 + match = match->next;
59529 + }
59530 +
59531 + if (match) {
59532 + if (last)
59533 + last->next = match->next;
59534 + else
59535 + gr_conn_table[index] = NULL;
59536 + kfree(match);
59537 + }
59538 +
59539 + return;
59540 +}
59541 +
59542 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59543 + __u16 sport, __u16 dport)
59544 +{
59545 + struct conn_table_entry *match;
59546 + unsigned int index;
59547 +
59548 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59549 +
59550 + match = gr_conn_table[index];
59551 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59552 + match = match->next;
59553 +
59554 + if (match)
59555 + return match->sig;
59556 + else
59557 + return NULL;
59558 +}
59559 +
59560 +#endif
59561 +
59562 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59563 +{
59564 +#ifdef CONFIG_GRKERNSEC
59565 + struct signal_struct *sig = task->signal;
59566 + struct conn_table_entry *newent;
59567 +
59568 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59569 + if (newent == NULL)
59570 + return;
59571 + /* no bh lock needed since we are called with bh disabled */
59572 + spin_lock(&gr_conn_table_lock);
59573 + gr_del_task_from_ip_table_nolock(sig);
59574 + sig->gr_saddr = inet->inet_rcv_saddr;
59575 + sig->gr_daddr = inet->inet_daddr;
59576 + sig->gr_sport = inet->inet_sport;
59577 + sig->gr_dport = inet->inet_dport;
59578 + gr_add_to_task_ip_table_nolock(sig, newent);
59579 + spin_unlock(&gr_conn_table_lock);
59580 +#endif
59581 + return;
59582 +}
59583 +
59584 +void gr_del_task_from_ip_table(struct task_struct *task)
59585 +{
59586 +#ifdef CONFIG_GRKERNSEC
59587 + spin_lock_bh(&gr_conn_table_lock);
59588 + gr_del_task_from_ip_table_nolock(task->signal);
59589 + spin_unlock_bh(&gr_conn_table_lock);
59590 +#endif
59591 + return;
59592 +}
59593 +
59594 +void
59595 +gr_attach_curr_ip(const struct sock *sk)
59596 +{
59597 +#ifdef CONFIG_GRKERNSEC
59598 + struct signal_struct *p, *set;
59599 + const struct inet_sock *inet = inet_sk(sk);
59600 +
59601 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59602 + return;
59603 +
59604 + set = current->signal;
59605 +
59606 + spin_lock_bh(&gr_conn_table_lock);
59607 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59608 + inet->inet_dport, inet->inet_sport);
59609 + if (unlikely(p != NULL)) {
59610 + set->curr_ip = p->curr_ip;
59611 + set->used_accept = 1;
59612 + gr_del_task_from_ip_table_nolock(p);
59613 + spin_unlock_bh(&gr_conn_table_lock);
59614 + return;
59615 + }
59616 + spin_unlock_bh(&gr_conn_table_lock);
59617 +
59618 + set->curr_ip = inet->inet_daddr;
59619 + set->used_accept = 1;
59620 +#endif
59621 + return;
59622 +}
59623 +
59624 +int
59625 +gr_handle_sock_all(const int family, const int type, const int protocol)
59626 +{
59627 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59628 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59629 + (family != AF_UNIX)) {
59630 + if (family == AF_INET)
59631 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59632 + else
59633 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59634 + return -EACCES;
59635 + }
59636 +#endif
59637 + return 0;
59638 +}
59639 +
59640 +int
59641 +gr_handle_sock_server(const struct sockaddr *sck)
59642 +{
59643 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59644 + if (grsec_enable_socket_server &&
59645 + in_group_p(grsec_socket_server_gid) &&
59646 + sck && (sck->sa_family != AF_UNIX) &&
59647 + (sck->sa_family != AF_LOCAL)) {
59648 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59649 + return -EACCES;
59650 + }
59651 +#endif
59652 + return 0;
59653 +}
59654 +
59655 +int
59656 +gr_handle_sock_server_other(const struct sock *sck)
59657 +{
59658 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59659 + if (grsec_enable_socket_server &&
59660 + in_group_p(grsec_socket_server_gid) &&
59661 + sck && (sck->sk_family != AF_UNIX) &&
59662 + (sck->sk_family != AF_LOCAL)) {
59663 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59664 + return -EACCES;
59665 + }
59666 +#endif
59667 + return 0;
59668 +}
59669 +
59670 +int
59671 +gr_handle_sock_client(const struct sockaddr *sck)
59672 +{
59673 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59674 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59675 + sck && (sck->sa_family != AF_UNIX) &&
59676 + (sck->sa_family != AF_LOCAL)) {
59677 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59678 + return -EACCES;
59679 + }
59680 +#endif
59681 + return 0;
59682 +}
59683 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59684 new file mode 100644
59685 index 0000000..f55ef0f
59686 --- /dev/null
59687 +++ b/grsecurity/grsec_sysctl.c
59688 @@ -0,0 +1,469 @@
59689 +#include <linux/kernel.h>
59690 +#include <linux/sched.h>
59691 +#include <linux/sysctl.h>
59692 +#include <linux/grsecurity.h>
59693 +#include <linux/grinternal.h>
59694 +
59695 +int
59696 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59697 +{
59698 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59699 + if (dirname == NULL || name == NULL)
59700 + return 0;
59701 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59702 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59703 + return -EACCES;
59704 + }
59705 +#endif
59706 + return 0;
59707 +}
59708 +
59709 +#ifdef CONFIG_GRKERNSEC_ROFS
59710 +static int __maybe_unused one = 1;
59711 +#endif
59712 +
59713 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59714 +struct ctl_table grsecurity_table[] = {
59715 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59716 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59717 +#ifdef CONFIG_GRKERNSEC_IO
59718 + {
59719 + .procname = "disable_priv_io",
59720 + .data = &grsec_disable_privio,
59721 + .maxlen = sizeof(int),
59722 + .mode = 0600,
59723 + .proc_handler = &proc_dointvec,
59724 + },
59725 +#endif
59726 +#endif
59727 +#ifdef CONFIG_GRKERNSEC_LINK
59728 + {
59729 + .procname = "linking_restrictions",
59730 + .data = &grsec_enable_link,
59731 + .maxlen = sizeof(int),
59732 + .mode = 0600,
59733 + .proc_handler = &proc_dointvec,
59734 + },
59735 +#endif
59736 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59737 + {
59738 + .procname = "enforce_symlinksifowner",
59739 + .data = &grsec_enable_symlinkown,
59740 + .maxlen = sizeof(int),
59741 + .mode = 0600,
59742 + .proc_handler = &proc_dointvec,
59743 + },
59744 + {
59745 + .procname = "symlinkown_gid",
59746 + .data = &grsec_symlinkown_gid,
59747 + .maxlen = sizeof(int),
59748 + .mode = 0600,
59749 + .proc_handler = &proc_dointvec,
59750 + },
59751 +#endif
59752 +#ifdef CONFIG_GRKERNSEC_BRUTE
59753 + {
59754 + .procname = "deter_bruteforce",
59755 + .data = &grsec_enable_brute,
59756 + .maxlen = sizeof(int),
59757 + .mode = 0600,
59758 + .proc_handler = &proc_dointvec,
59759 + },
59760 +#endif
59761 +#ifdef CONFIG_GRKERNSEC_FIFO
59762 + {
59763 + .procname = "fifo_restrictions",
59764 + .data = &grsec_enable_fifo,
59765 + .maxlen = sizeof(int),
59766 + .mode = 0600,
59767 + .proc_handler = &proc_dointvec,
59768 + },
59769 +#endif
59770 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59771 + {
59772 + .procname = "ptrace_readexec",
59773 + .data = &grsec_enable_ptrace_readexec,
59774 + .maxlen = sizeof(int),
59775 + .mode = 0600,
59776 + .proc_handler = &proc_dointvec,
59777 + },
59778 +#endif
59779 +#ifdef CONFIG_GRKERNSEC_SETXID
59780 + {
59781 + .procname = "consistent_setxid",
59782 + .data = &grsec_enable_setxid,
59783 + .maxlen = sizeof(int),
59784 + .mode = 0600,
59785 + .proc_handler = &proc_dointvec,
59786 + },
59787 +#endif
59788 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59789 + {
59790 + .procname = "ip_blackhole",
59791 + .data = &grsec_enable_blackhole,
59792 + .maxlen = sizeof(int),
59793 + .mode = 0600,
59794 + .proc_handler = &proc_dointvec,
59795 + },
59796 + {
59797 + .procname = "lastack_retries",
59798 + .data = &grsec_lastack_retries,
59799 + .maxlen = sizeof(int),
59800 + .mode = 0600,
59801 + .proc_handler = &proc_dointvec,
59802 + },
59803 +#endif
59804 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59805 + {
59806 + .procname = "exec_logging",
59807 + .data = &grsec_enable_execlog,
59808 + .maxlen = sizeof(int),
59809 + .mode = 0600,
59810 + .proc_handler = &proc_dointvec,
59811 + },
59812 +#endif
59813 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59814 + {
59815 + .procname = "rwxmap_logging",
59816 + .data = &grsec_enable_log_rwxmaps,
59817 + .maxlen = sizeof(int),
59818 + .mode = 0600,
59819 + .proc_handler = &proc_dointvec,
59820 + },
59821 +#endif
59822 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59823 + {
59824 + .procname = "signal_logging",
59825 + .data = &grsec_enable_signal,
59826 + .maxlen = sizeof(int),
59827 + .mode = 0600,
59828 + .proc_handler = &proc_dointvec,
59829 + },
59830 +#endif
59831 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59832 + {
59833 + .procname = "forkfail_logging",
59834 + .data = &grsec_enable_forkfail,
59835 + .maxlen = sizeof(int),
59836 + .mode = 0600,
59837 + .proc_handler = &proc_dointvec,
59838 + },
59839 +#endif
59840 +#ifdef CONFIG_GRKERNSEC_TIME
59841 + {
59842 + .procname = "timechange_logging",
59843 + .data = &grsec_enable_time,
59844 + .maxlen = sizeof(int),
59845 + .mode = 0600,
59846 + .proc_handler = &proc_dointvec,
59847 + },
59848 +#endif
59849 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59850 + {
59851 + .procname = "chroot_deny_shmat",
59852 + .data = &grsec_enable_chroot_shmat,
59853 + .maxlen = sizeof(int),
59854 + .mode = 0600,
59855 + .proc_handler = &proc_dointvec,
59856 + },
59857 +#endif
59858 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59859 + {
59860 + .procname = "chroot_deny_unix",
59861 + .data = &grsec_enable_chroot_unix,
59862 + .maxlen = sizeof(int),
59863 + .mode = 0600,
59864 + .proc_handler = &proc_dointvec,
59865 + },
59866 +#endif
59867 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59868 + {
59869 + .procname = "chroot_deny_mount",
59870 + .data = &grsec_enable_chroot_mount,
59871 + .maxlen = sizeof(int),
59872 + .mode = 0600,
59873 + .proc_handler = &proc_dointvec,
59874 + },
59875 +#endif
59876 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59877 + {
59878 + .procname = "chroot_deny_fchdir",
59879 + .data = &grsec_enable_chroot_fchdir,
59880 + .maxlen = sizeof(int),
59881 + .mode = 0600,
59882 + .proc_handler = &proc_dointvec,
59883 + },
59884 +#endif
59885 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59886 + {
59887 + .procname = "chroot_deny_chroot",
59888 + .data = &grsec_enable_chroot_double,
59889 + .maxlen = sizeof(int),
59890 + .mode = 0600,
59891 + .proc_handler = &proc_dointvec,
59892 + },
59893 +#endif
59894 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59895 + {
59896 + .procname = "chroot_deny_pivot",
59897 + .data = &grsec_enable_chroot_pivot,
59898 + .maxlen = sizeof(int),
59899 + .mode = 0600,
59900 + .proc_handler = &proc_dointvec,
59901 + },
59902 +#endif
59903 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59904 + {
59905 + .procname = "chroot_enforce_chdir",
59906 + .data = &grsec_enable_chroot_chdir,
59907 + .maxlen = sizeof(int),
59908 + .mode = 0600,
59909 + .proc_handler = &proc_dointvec,
59910 + },
59911 +#endif
59912 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59913 + {
59914 + .procname = "chroot_deny_chmod",
59915 + .data = &grsec_enable_chroot_chmod,
59916 + .maxlen = sizeof(int),
59917 + .mode = 0600,
59918 + .proc_handler = &proc_dointvec,
59919 + },
59920 +#endif
59921 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59922 + {
59923 + .procname = "chroot_deny_mknod",
59924 + .data = &grsec_enable_chroot_mknod,
59925 + .maxlen = sizeof(int),
59926 + .mode = 0600,
59927 + .proc_handler = &proc_dointvec,
59928 + },
59929 +#endif
59930 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59931 + {
59932 + .procname = "chroot_restrict_nice",
59933 + .data = &grsec_enable_chroot_nice,
59934 + .maxlen = sizeof(int),
59935 + .mode = 0600,
59936 + .proc_handler = &proc_dointvec,
59937 + },
59938 +#endif
59939 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59940 + {
59941 + .procname = "chroot_execlog",
59942 + .data = &grsec_enable_chroot_execlog,
59943 + .maxlen = sizeof(int),
59944 + .mode = 0600,
59945 + .proc_handler = &proc_dointvec,
59946 + },
59947 +#endif
59948 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59949 + {
59950 + .procname = "chroot_caps",
59951 + .data = &grsec_enable_chroot_caps,
59952 + .maxlen = sizeof(int),
59953 + .mode = 0600,
59954 + .proc_handler = &proc_dointvec,
59955 + },
59956 +#endif
59957 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59958 + {
59959 + .procname = "chroot_deny_sysctl",
59960 + .data = &grsec_enable_chroot_sysctl,
59961 + .maxlen = sizeof(int),
59962 + .mode = 0600,
59963 + .proc_handler = &proc_dointvec,
59964 + },
59965 +#endif
59966 +#ifdef CONFIG_GRKERNSEC_TPE
59967 + {
59968 + .procname = "tpe",
59969 + .data = &grsec_enable_tpe,
59970 + .maxlen = sizeof(int),
59971 + .mode = 0600,
59972 + .proc_handler = &proc_dointvec,
59973 + },
59974 + {
59975 + .procname = "tpe_gid",
59976 + .data = &grsec_tpe_gid,
59977 + .maxlen = sizeof(int),
59978 + .mode = 0600,
59979 + .proc_handler = &proc_dointvec,
59980 + },
59981 +#endif
59982 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59983 + {
59984 + .procname = "tpe_invert",
59985 + .data = &grsec_enable_tpe_invert,
59986 + .maxlen = sizeof(int),
59987 + .mode = 0600,
59988 + .proc_handler = &proc_dointvec,
59989 + },
59990 +#endif
59991 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59992 + {
59993 + .procname = "tpe_restrict_all",
59994 + .data = &grsec_enable_tpe_all,
59995 + .maxlen = sizeof(int),
59996 + .mode = 0600,
59997 + .proc_handler = &proc_dointvec,
59998 + },
59999 +#endif
60000 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60001 + {
60002 + .procname = "socket_all",
60003 + .data = &grsec_enable_socket_all,
60004 + .maxlen = sizeof(int),
60005 + .mode = 0600,
60006 + .proc_handler = &proc_dointvec,
60007 + },
60008 + {
60009 + .procname = "socket_all_gid",
60010 + .data = &grsec_socket_all_gid,
60011 + .maxlen = sizeof(int),
60012 + .mode = 0600,
60013 + .proc_handler = &proc_dointvec,
60014 + },
60015 +#endif
60016 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60017 + {
60018 + .procname = "socket_client",
60019 + .data = &grsec_enable_socket_client,
60020 + .maxlen = sizeof(int),
60021 + .mode = 0600,
60022 + .proc_handler = &proc_dointvec,
60023 + },
60024 + {
60025 + .procname = "socket_client_gid",
60026 + .data = &grsec_socket_client_gid,
60027 + .maxlen = sizeof(int),
60028 + .mode = 0600,
60029 + .proc_handler = &proc_dointvec,
60030 + },
60031 +#endif
60032 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60033 + {
60034 + .procname = "socket_server",
60035 + .data = &grsec_enable_socket_server,
60036 + .maxlen = sizeof(int),
60037 + .mode = 0600,
60038 + .proc_handler = &proc_dointvec,
60039 + },
60040 + {
60041 + .procname = "socket_server_gid",
60042 + .data = &grsec_socket_server_gid,
60043 + .maxlen = sizeof(int),
60044 + .mode = 0600,
60045 + .proc_handler = &proc_dointvec,
60046 + },
60047 +#endif
60048 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60049 + {
60050 + .procname = "audit_group",
60051 + .data = &grsec_enable_group,
60052 + .maxlen = sizeof(int),
60053 + .mode = 0600,
60054 + .proc_handler = &proc_dointvec,
60055 + },
60056 + {
60057 + .procname = "audit_gid",
60058 + .data = &grsec_audit_gid,
60059 + .maxlen = sizeof(int),
60060 + .mode = 0600,
60061 + .proc_handler = &proc_dointvec,
60062 + },
60063 +#endif
60064 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60065 + {
60066 + .procname = "audit_chdir",
60067 + .data = &grsec_enable_chdir,
60068 + .maxlen = sizeof(int),
60069 + .mode = 0600,
60070 + .proc_handler = &proc_dointvec,
60071 + },
60072 +#endif
60073 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60074 + {
60075 + .procname = "audit_mount",
60076 + .data = &grsec_enable_mount,
60077 + .maxlen = sizeof(int),
60078 + .mode = 0600,
60079 + .proc_handler = &proc_dointvec,
60080 + },
60081 +#endif
60082 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60083 + {
60084 + .procname = "audit_textrel",
60085 + .data = &grsec_enable_audit_textrel,
60086 + .maxlen = sizeof(int),
60087 + .mode = 0600,
60088 + .proc_handler = &proc_dointvec,
60089 + },
60090 +#endif
60091 +#ifdef CONFIG_GRKERNSEC_DMESG
60092 + {
60093 + .procname = "dmesg",
60094 + .data = &grsec_enable_dmesg,
60095 + .maxlen = sizeof(int),
60096 + .mode = 0600,
60097 + .proc_handler = &proc_dointvec,
60098 + },
60099 +#endif
60100 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60101 + {
60102 + .procname = "chroot_findtask",
60103 + .data = &grsec_enable_chroot_findtask,
60104 + .maxlen = sizeof(int),
60105 + .mode = 0600,
60106 + .proc_handler = &proc_dointvec,
60107 + },
60108 +#endif
60109 +#ifdef CONFIG_GRKERNSEC_RESLOG
60110 + {
60111 + .procname = "resource_logging",
60112 + .data = &grsec_resource_logging,
60113 + .maxlen = sizeof(int),
60114 + .mode = 0600,
60115 + .proc_handler = &proc_dointvec,
60116 + },
60117 +#endif
60118 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60119 + {
60120 + .procname = "audit_ptrace",
60121 + .data = &grsec_enable_audit_ptrace,
60122 + .maxlen = sizeof(int),
60123 + .mode = 0600,
60124 + .proc_handler = &proc_dointvec,
60125 + },
60126 +#endif
60127 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60128 + {
60129 + .procname = "harden_ptrace",
60130 + .data = &grsec_enable_harden_ptrace,
60131 + .maxlen = sizeof(int),
60132 + .mode = 0600,
60133 + .proc_handler = &proc_dointvec,
60134 + },
60135 +#endif
60136 + {
60137 + .procname = "grsec_lock",
60138 + .data = &grsec_lock,
60139 + .maxlen = sizeof(int),
60140 + .mode = 0600,
60141 + .proc_handler = &proc_dointvec,
60142 + },
60143 +#endif
60144 +#ifdef CONFIG_GRKERNSEC_ROFS
60145 + {
60146 + .procname = "romount_protect",
60147 + .data = &grsec_enable_rofs,
60148 + .maxlen = sizeof(int),
60149 + .mode = 0600,
60150 + .proc_handler = &proc_dointvec_minmax,
60151 + .extra1 = &one,
60152 + .extra2 = &one,
60153 + },
60154 +#endif
60155 + { }
60156 +};
60157 +#endif
60158 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60159 new file mode 100644
60160 index 0000000..0dc13c3
60161 --- /dev/null
60162 +++ b/grsecurity/grsec_time.c
60163 @@ -0,0 +1,16 @@
60164 +#include <linux/kernel.h>
60165 +#include <linux/sched.h>
60166 +#include <linux/grinternal.h>
60167 +#include <linux/module.h>
60168 +
60169 +void
60170 +gr_log_timechange(void)
60171 +{
60172 +#ifdef CONFIG_GRKERNSEC_TIME
60173 + if (grsec_enable_time)
60174 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60175 +#endif
60176 + return;
60177 +}
60178 +
60179 +EXPORT_SYMBOL(gr_log_timechange);
60180 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60181 new file mode 100644
60182 index 0000000..07e0dc0
60183 --- /dev/null
60184 +++ b/grsecurity/grsec_tpe.c
60185 @@ -0,0 +1,73 @@
60186 +#include <linux/kernel.h>
60187 +#include <linux/sched.h>
60188 +#include <linux/file.h>
60189 +#include <linux/fs.h>
60190 +#include <linux/grinternal.h>
60191 +
60192 +extern int gr_acl_tpe_check(void);
60193 +
60194 +int
60195 +gr_tpe_allow(const struct file *file)
60196 +{
60197 +#ifdef CONFIG_GRKERNSEC
60198 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60199 + const struct cred *cred = current_cred();
60200 + char *msg = NULL;
60201 + char *msg2 = NULL;
60202 +
60203 + // never restrict root
60204 + if (!cred->uid)
60205 + return 1;
60206 +
60207 + if (grsec_enable_tpe) {
60208 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60209 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60210 + msg = "not being in trusted group";
60211 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60212 + msg = "being in untrusted group";
60213 +#else
60214 + if (in_group_p(grsec_tpe_gid))
60215 + msg = "being in untrusted group";
60216 +#endif
60217 + }
60218 + if (!msg && gr_acl_tpe_check())
60219 + msg = "being in untrusted role";
60220 +
60221 + // not in any affected group/role
60222 + if (!msg)
60223 + goto next_check;
60224 +
60225 + if (inode->i_uid)
60226 + msg2 = "file in non-root-owned directory";
60227 + else if (inode->i_mode & S_IWOTH)
60228 + msg2 = "file in world-writable directory";
60229 + else if (inode->i_mode & S_IWGRP)
60230 + msg2 = "file in group-writable directory";
60231 +
60232 + if (msg && msg2) {
60233 + char fullmsg[70] = {0};
60234 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60235 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60236 + return 0;
60237 + }
60238 + msg = NULL;
60239 +next_check:
60240 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60241 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60242 + return 1;
60243 +
60244 + if (inode->i_uid && (inode->i_uid != cred->uid))
60245 + msg = "directory not owned by user";
60246 + else if (inode->i_mode & S_IWOTH)
60247 + msg = "file in world-writable directory";
60248 + else if (inode->i_mode & S_IWGRP)
60249 + msg = "file in group-writable directory";
60250 +
60251 + if (msg) {
60252 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60253 + return 0;
60254 + }
60255 +#endif
60256 +#endif
60257 + return 1;
60258 +}
60259 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60260 new file mode 100644
60261 index 0000000..9f7b1ac
60262 --- /dev/null
60263 +++ b/grsecurity/grsum.c
60264 @@ -0,0 +1,61 @@
60265 +#include <linux/err.h>
60266 +#include <linux/kernel.h>
60267 +#include <linux/sched.h>
60268 +#include <linux/mm.h>
60269 +#include <linux/scatterlist.h>
60270 +#include <linux/crypto.h>
60271 +#include <linux/gracl.h>
60272 +
60273 +
60274 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60275 +#error "crypto and sha256 must be built into the kernel"
60276 +#endif
60277 +
60278 +int
60279 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60280 +{
60281 + char *p;
60282 + struct crypto_hash *tfm;
60283 + struct hash_desc desc;
60284 + struct scatterlist sg;
60285 + unsigned char temp_sum[GR_SHA_LEN];
60286 + volatile int retval = 0;
60287 + volatile int dummy = 0;
60288 + unsigned int i;
60289 +
60290 + sg_init_table(&sg, 1);
60291 +
60292 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60293 + if (IS_ERR(tfm)) {
60294 + /* should never happen, since sha256 should be built in */
60295 + return 1;
60296 + }
60297 +
60298 + desc.tfm = tfm;
60299 + desc.flags = 0;
60300 +
60301 + crypto_hash_init(&desc);
60302 +
60303 + p = salt;
60304 + sg_set_buf(&sg, p, GR_SALT_LEN);
60305 + crypto_hash_update(&desc, &sg, sg.length);
60306 +
60307 + p = entry->pw;
60308 + sg_set_buf(&sg, p, strlen(p));
60309 +
60310 + crypto_hash_update(&desc, &sg, sg.length);
60311 +
60312 + crypto_hash_final(&desc, temp_sum);
60313 +
60314 + memset(entry->pw, 0, GR_PW_LEN);
60315 +
60316 + for (i = 0; i < GR_SHA_LEN; i++)
60317 + if (sum[i] != temp_sum[i])
60318 + retval = 1;
60319 + else
60320 + dummy = 1; // waste a cycle
60321 +
60322 + crypto_free_hash(tfm);
60323 +
60324 + return retval;
60325 +}
60326 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60327 index bde976e..a1cc32a 100644
60328 --- a/include/acpi/acpi_bus.h
60329 +++ b/include/acpi/acpi_bus.h
60330 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60331 acpi_op_bind bind;
60332 acpi_op_unbind unbind;
60333 acpi_op_notify notify;
60334 -};
60335 +} __no_const;
60336
60337 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60338
60339 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60340 index 77ff547..181834f 100644
60341 --- a/include/asm-generic/4level-fixup.h
60342 +++ b/include/asm-generic/4level-fixup.h
60343 @@ -13,8 +13,10 @@
60344 #define pmd_alloc(mm, pud, address) \
60345 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60346 NULL: pmd_offset(pud, address))
60347 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60348
60349 #define pud_alloc(mm, pgd, address) (pgd)
60350 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60351 #define pud_offset(pgd, start) (pgd)
60352 #define pud_none(pud) 0
60353 #define pud_bad(pud) 0
60354 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60355 index b7babf0..3ba8aee 100644
60356 --- a/include/asm-generic/atomic-long.h
60357 +++ b/include/asm-generic/atomic-long.h
60358 @@ -22,6 +22,12 @@
60359
60360 typedef atomic64_t atomic_long_t;
60361
60362 +#ifdef CONFIG_PAX_REFCOUNT
60363 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60364 +#else
60365 +typedef atomic64_t atomic_long_unchecked_t;
60366 +#endif
60367 +
60368 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60369
60370 static inline long atomic_long_read(atomic_long_t *l)
60371 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60372 return (long)atomic64_read(v);
60373 }
60374
60375 +#ifdef CONFIG_PAX_REFCOUNT
60376 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60377 +{
60378 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60379 +
60380 + return (long)atomic64_read_unchecked(v);
60381 +}
60382 +#endif
60383 +
60384 static inline void atomic_long_set(atomic_long_t *l, long i)
60385 {
60386 atomic64_t *v = (atomic64_t *)l;
60387 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60388 atomic64_set(v, i);
60389 }
60390
60391 +#ifdef CONFIG_PAX_REFCOUNT
60392 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60393 +{
60394 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60395 +
60396 + atomic64_set_unchecked(v, i);
60397 +}
60398 +#endif
60399 +
60400 static inline void atomic_long_inc(atomic_long_t *l)
60401 {
60402 atomic64_t *v = (atomic64_t *)l;
60403 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60404 atomic64_inc(v);
60405 }
60406
60407 +#ifdef CONFIG_PAX_REFCOUNT
60408 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60409 +{
60410 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60411 +
60412 + atomic64_inc_unchecked(v);
60413 +}
60414 +#endif
60415 +
60416 static inline void atomic_long_dec(atomic_long_t *l)
60417 {
60418 atomic64_t *v = (atomic64_t *)l;
60419 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60420 atomic64_dec(v);
60421 }
60422
60423 +#ifdef CONFIG_PAX_REFCOUNT
60424 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60425 +{
60426 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60427 +
60428 + atomic64_dec_unchecked(v);
60429 +}
60430 +#endif
60431 +
60432 static inline void atomic_long_add(long i, atomic_long_t *l)
60433 {
60434 atomic64_t *v = (atomic64_t *)l;
60435 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60436 atomic64_add(i, v);
60437 }
60438
60439 +#ifdef CONFIG_PAX_REFCOUNT
60440 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60441 +{
60442 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60443 +
60444 + atomic64_add_unchecked(i, v);
60445 +}
60446 +#endif
60447 +
60448 static inline void atomic_long_sub(long i, atomic_long_t *l)
60449 {
60450 atomic64_t *v = (atomic64_t *)l;
60451 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60452 atomic64_sub(i, v);
60453 }
60454
60455 +#ifdef CONFIG_PAX_REFCOUNT
60456 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60457 +{
60458 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60459 +
60460 + atomic64_sub_unchecked(i, v);
60461 +}
60462 +#endif
60463 +
60464 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60465 {
60466 atomic64_t *v = (atomic64_t *)l;
60467 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60468 return (long)atomic64_inc_return(v);
60469 }
60470
60471 +#ifdef CONFIG_PAX_REFCOUNT
60472 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60473 +{
60474 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60475 +
60476 + return (long)atomic64_inc_return_unchecked(v);
60477 +}
60478 +#endif
60479 +
60480 static inline long atomic_long_dec_return(atomic_long_t *l)
60481 {
60482 atomic64_t *v = (atomic64_t *)l;
60483 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60484
60485 typedef atomic_t atomic_long_t;
60486
60487 +#ifdef CONFIG_PAX_REFCOUNT
60488 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60489 +#else
60490 +typedef atomic_t atomic_long_unchecked_t;
60491 +#endif
60492 +
60493 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60494 static inline long atomic_long_read(atomic_long_t *l)
60495 {
60496 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60497 return (long)atomic_read(v);
60498 }
60499
60500 +#ifdef CONFIG_PAX_REFCOUNT
60501 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60502 +{
60503 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60504 +
60505 + return (long)atomic_read_unchecked(v);
60506 +}
60507 +#endif
60508 +
60509 static inline void atomic_long_set(atomic_long_t *l, long i)
60510 {
60511 atomic_t *v = (atomic_t *)l;
60512 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60513 atomic_set(v, i);
60514 }
60515
60516 +#ifdef CONFIG_PAX_REFCOUNT
60517 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60518 +{
60519 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60520 +
60521 + atomic_set_unchecked(v, i);
60522 +}
60523 +#endif
60524 +
60525 static inline void atomic_long_inc(atomic_long_t *l)
60526 {
60527 atomic_t *v = (atomic_t *)l;
60528 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60529 atomic_inc(v);
60530 }
60531
60532 +#ifdef CONFIG_PAX_REFCOUNT
60533 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60534 +{
60535 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60536 +
60537 + atomic_inc_unchecked(v);
60538 +}
60539 +#endif
60540 +
60541 static inline void atomic_long_dec(atomic_long_t *l)
60542 {
60543 atomic_t *v = (atomic_t *)l;
60544 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60545 atomic_dec(v);
60546 }
60547
60548 +#ifdef CONFIG_PAX_REFCOUNT
60549 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60550 +{
60551 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60552 +
60553 + atomic_dec_unchecked(v);
60554 +}
60555 +#endif
60556 +
60557 static inline void atomic_long_add(long i, atomic_long_t *l)
60558 {
60559 atomic_t *v = (atomic_t *)l;
60560 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60561 atomic_add(i, v);
60562 }
60563
60564 +#ifdef CONFIG_PAX_REFCOUNT
60565 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60566 +{
60567 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60568 +
60569 + atomic_add_unchecked(i, v);
60570 +}
60571 +#endif
60572 +
60573 static inline void atomic_long_sub(long i, atomic_long_t *l)
60574 {
60575 atomic_t *v = (atomic_t *)l;
60576 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60577 atomic_sub(i, v);
60578 }
60579
60580 +#ifdef CONFIG_PAX_REFCOUNT
60581 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60582 +{
60583 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60584 +
60585 + atomic_sub_unchecked(i, v);
60586 +}
60587 +#endif
60588 +
60589 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60590 {
60591 atomic_t *v = (atomic_t *)l;
60592 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60593 return (long)atomic_inc_return(v);
60594 }
60595
60596 +#ifdef CONFIG_PAX_REFCOUNT
60597 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60598 +{
60599 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60600 +
60601 + return (long)atomic_inc_return_unchecked(v);
60602 +}
60603 +#endif
60604 +
60605 static inline long atomic_long_dec_return(atomic_long_t *l)
60606 {
60607 atomic_t *v = (atomic_t *)l;
60608 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60609
60610 #endif /* BITS_PER_LONG == 64 */
60611
60612 +#ifdef CONFIG_PAX_REFCOUNT
60613 +static inline void pax_refcount_needs_these_functions(void)
60614 +{
60615 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60616 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60617 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60618 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60619 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60620 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60621 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60622 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60623 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60624 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60625 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60626 +#ifdef CONFIG_X86
60627 + atomic_clear_mask_unchecked(0, NULL);
60628 + atomic_set_mask_unchecked(0, NULL);
60629 +#endif
60630 +
60631 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60632 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60633 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60634 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60635 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60636 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60637 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60638 +}
60639 +#else
60640 +#define atomic_read_unchecked(v) atomic_read(v)
60641 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60642 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60643 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60644 +#define atomic_inc_unchecked(v) atomic_inc(v)
60645 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60646 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60647 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60648 +#define atomic_dec_unchecked(v) atomic_dec(v)
60649 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60650 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60651 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60652 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60653 +
60654 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60655 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60656 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60657 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60658 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60659 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60660 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60661 +#endif
60662 +
60663 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60664 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60665 index 1ced641..c896ee8 100644
60666 --- a/include/asm-generic/atomic.h
60667 +++ b/include/asm-generic/atomic.h
60668 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60669 * Atomically clears the bits set in @mask from @v
60670 */
60671 #ifndef atomic_clear_mask
60672 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60673 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60674 {
60675 unsigned long flags;
60676
60677 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60678 index b18ce4f..2ee2843 100644
60679 --- a/include/asm-generic/atomic64.h
60680 +++ b/include/asm-generic/atomic64.h
60681 @@ -16,6 +16,8 @@ typedef struct {
60682 long long counter;
60683 } atomic64_t;
60684
60685 +typedef atomic64_t atomic64_unchecked_t;
60686 +
60687 #define ATOMIC64_INIT(i) { (i) }
60688
60689 extern long long atomic64_read(const atomic64_t *v);
60690 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60691 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60692 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60693
60694 +#define atomic64_read_unchecked(v) atomic64_read(v)
60695 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60696 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60697 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60698 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60699 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60700 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60701 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60702 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60703 +
60704 #endif /* _ASM_GENERIC_ATOMIC64_H */
60705 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60706 index 1bfcfe5..e04c5c9 100644
60707 --- a/include/asm-generic/cache.h
60708 +++ b/include/asm-generic/cache.h
60709 @@ -6,7 +6,7 @@
60710 * cache lines need to provide their own cache.h.
60711 */
60712
60713 -#define L1_CACHE_SHIFT 5
60714 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60715 +#define L1_CACHE_SHIFT 5UL
60716 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60717
60718 #endif /* __ASM_GENERIC_CACHE_H */
60719 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60720 index 0d68a1e..b74a761 100644
60721 --- a/include/asm-generic/emergency-restart.h
60722 +++ b/include/asm-generic/emergency-restart.h
60723 @@ -1,7 +1,7 @@
60724 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60725 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60726
60727 -static inline void machine_emergency_restart(void)
60728 +static inline __noreturn void machine_emergency_restart(void)
60729 {
60730 machine_restart(NULL);
60731 }
60732 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60733 index 90f99c7..00ce236 100644
60734 --- a/include/asm-generic/kmap_types.h
60735 +++ b/include/asm-generic/kmap_types.h
60736 @@ -2,9 +2,9 @@
60737 #define _ASM_GENERIC_KMAP_TYPES_H
60738
60739 #ifdef __WITH_KM_FENCE
60740 -# define KM_TYPE_NR 41
60741 +# define KM_TYPE_NR 42
60742 #else
60743 -# define KM_TYPE_NR 20
60744 +# define KM_TYPE_NR 21
60745 #endif
60746
60747 #endif
60748 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60749 index 9ceb03b..2efbcbd 100644
60750 --- a/include/asm-generic/local.h
60751 +++ b/include/asm-generic/local.h
60752 @@ -39,6 +39,7 @@ typedef struct
60753 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60754 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60755 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60756 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60757
60758 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60759 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60760 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60761 index 725612b..9cc513a 100644
60762 --- a/include/asm-generic/pgtable-nopmd.h
60763 +++ b/include/asm-generic/pgtable-nopmd.h
60764 @@ -1,14 +1,19 @@
60765 #ifndef _PGTABLE_NOPMD_H
60766 #define _PGTABLE_NOPMD_H
60767
60768 -#ifndef __ASSEMBLY__
60769 -
60770 #include <asm-generic/pgtable-nopud.h>
60771
60772 -struct mm_struct;
60773 -
60774 #define __PAGETABLE_PMD_FOLDED
60775
60776 +#define PMD_SHIFT PUD_SHIFT
60777 +#define PTRS_PER_PMD 1
60778 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60779 +#define PMD_MASK (~(PMD_SIZE-1))
60780 +
60781 +#ifndef __ASSEMBLY__
60782 +
60783 +struct mm_struct;
60784 +
60785 /*
60786 * Having the pmd type consist of a pud gets the size right, and allows
60787 * us to conceptually access the pud entry that this pmd is folded into
60788 @@ -16,11 +21,6 @@ struct mm_struct;
60789 */
60790 typedef struct { pud_t pud; } pmd_t;
60791
60792 -#define PMD_SHIFT PUD_SHIFT
60793 -#define PTRS_PER_PMD 1
60794 -#define PMD_SIZE (1UL << PMD_SHIFT)
60795 -#define PMD_MASK (~(PMD_SIZE-1))
60796 -
60797 /*
60798 * The "pud_xxx()" functions here are trivial for a folded two-level
60799 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60800 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60801 index 810431d..0ec4804f 100644
60802 --- a/include/asm-generic/pgtable-nopud.h
60803 +++ b/include/asm-generic/pgtable-nopud.h
60804 @@ -1,10 +1,15 @@
60805 #ifndef _PGTABLE_NOPUD_H
60806 #define _PGTABLE_NOPUD_H
60807
60808 -#ifndef __ASSEMBLY__
60809 -
60810 #define __PAGETABLE_PUD_FOLDED
60811
60812 +#define PUD_SHIFT PGDIR_SHIFT
60813 +#define PTRS_PER_PUD 1
60814 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60815 +#define PUD_MASK (~(PUD_SIZE-1))
60816 +
60817 +#ifndef __ASSEMBLY__
60818 +
60819 /*
60820 * Having the pud type consist of a pgd gets the size right, and allows
60821 * us to conceptually access the pgd entry that this pud is folded into
60822 @@ -12,11 +17,6 @@
60823 */
60824 typedef struct { pgd_t pgd; } pud_t;
60825
60826 -#define PUD_SHIFT PGDIR_SHIFT
60827 -#define PTRS_PER_PUD 1
60828 -#define PUD_SIZE (1UL << PUD_SHIFT)
60829 -#define PUD_MASK (~(PUD_SIZE-1))
60830 -
60831 /*
60832 * The "pgd_xxx()" functions here are trivial for a folded two-level
60833 * setup: the pud is never bad, and a pud always exists (as it's folded
60834 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60835 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60836
60837 #define pgd_populate(mm, pgd, pud) do { } while (0)
60838 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60839 /*
60840 * (puds are folded into pgds so this doesn't get actually called,
60841 * but the define is needed for a generic inline function.)
60842 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60843 index ff4947b..f48183f 100644
60844 --- a/include/asm-generic/pgtable.h
60845 +++ b/include/asm-generic/pgtable.h
60846 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60847 #endif
60848 }
60849
60850 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60851 +static inline unsigned long pax_open_kernel(void) { return 0; }
60852 +#endif
60853 +
60854 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60855 +static inline unsigned long pax_close_kernel(void) { return 0; }
60856 +#endif
60857 +
60858 #endif /* CONFIG_MMU */
60859
60860 #endif /* !__ASSEMBLY__ */
60861 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60862 index 4e2e1cc..12c266b 100644
60863 --- a/include/asm-generic/vmlinux.lds.h
60864 +++ b/include/asm-generic/vmlinux.lds.h
60865 @@ -218,6 +218,7 @@
60866 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60867 VMLINUX_SYMBOL(__start_rodata) = .; \
60868 *(.rodata) *(.rodata.*) \
60869 + *(.data..read_only) \
60870 *(__vermagic) /* Kernel version magic */ \
60871 . = ALIGN(8); \
60872 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60873 @@ -716,17 +717,18 @@
60874 * section in the linker script will go there too. @phdr should have
60875 * a leading colon.
60876 *
60877 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60878 + * Note that this macros defines per_cpu_load as an absolute symbol.
60879 * If there is no need to put the percpu section at a predetermined
60880 * address, use PERCPU_SECTION.
60881 */
60882 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60883 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60884 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60885 + per_cpu_load = .; \
60886 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60887 - LOAD_OFFSET) { \
60888 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60889 PERCPU_INPUT(cacheline) \
60890 } phdr \
60891 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60892 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60893
60894 /**
60895 * PERCPU_SECTION - define output section for percpu area, simple version
60896 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60897 index d6b67bb..a272c29 100644
60898 --- a/include/drm/drmP.h
60899 +++ b/include/drm/drmP.h
60900 @@ -72,6 +72,7 @@
60901 #include <linux/workqueue.h>
60902 #include <linux/poll.h>
60903 #include <asm/pgalloc.h>
60904 +#include <asm/local.h>
60905 #include "drm.h"
60906
60907 #include <linux/idr.h>
60908 @@ -1067,7 +1068,7 @@ struct drm_device {
60909
60910 /** \name Usage Counters */
60911 /*@{ */
60912 - int open_count; /**< Outstanding files open */
60913 + local_t open_count; /**< Outstanding files open */
60914 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60915 atomic_t vma_count; /**< Outstanding vma areas open */
60916 int buf_use; /**< Buffers in use -- cannot alloc */
60917 @@ -1078,7 +1079,7 @@ struct drm_device {
60918 /*@{ */
60919 unsigned long counters;
60920 enum drm_stat_type types[15];
60921 - atomic_t counts[15];
60922 + atomic_unchecked_t counts[15];
60923 /*@} */
60924
60925 struct list_head filelist;
60926 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60927 index e01cc80..319855d 100644
60928 --- a/include/drm/drm_crtc_helper.h
60929 +++ b/include/drm/drm_crtc_helper.h
60930 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60931
60932 /* disable crtc when not in use - more explicit than dpms off */
60933 void (*disable)(struct drm_crtc *crtc);
60934 -};
60935 +} __no_const;
60936
60937 /**
60938 * drm_encoder_helper_funcs - helper operations for encoders
60939 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60940 struct drm_connector *connector);
60941 /* disable encoder when not in use - more explicit than dpms off */
60942 void (*disable)(struct drm_encoder *encoder);
60943 -};
60944 +} __no_const;
60945
60946 /**
60947 * drm_connector_helper_funcs - helper operations for connectors
60948 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60949 index d6d1da4..fdd1ac5 100644
60950 --- a/include/drm/ttm/ttm_memory.h
60951 +++ b/include/drm/ttm/ttm_memory.h
60952 @@ -48,7 +48,7 @@
60953
60954 struct ttm_mem_shrink {
60955 int (*do_shrink) (struct ttm_mem_shrink *);
60956 -};
60957 +} __no_const;
60958
60959 /**
60960 * struct ttm_mem_global - Global memory accounting structure.
60961 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60962 index e86dfca..40cc55f 100644
60963 --- a/include/linux/a.out.h
60964 +++ b/include/linux/a.out.h
60965 @@ -39,6 +39,14 @@ enum machine_type {
60966 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60967 };
60968
60969 +/* Constants for the N_FLAGS field */
60970 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60971 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60972 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60973 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60974 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60975 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60976 +
60977 #if !defined (N_MAGIC)
60978 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60979 #endif
60980 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60981 index 06fd4bb..1caec0d 100644
60982 --- a/include/linux/atmdev.h
60983 +++ b/include/linux/atmdev.h
60984 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60985 #endif
60986
60987 struct k_atm_aal_stats {
60988 -#define __HANDLE_ITEM(i) atomic_t i
60989 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60990 __AAL_STAT_ITEMS
60991 #undef __HANDLE_ITEM
60992 };
60993 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60994 index 366422b..1fa7f84 100644
60995 --- a/include/linux/binfmts.h
60996 +++ b/include/linux/binfmts.h
60997 @@ -89,6 +89,7 @@ struct linux_binfmt {
60998 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60999 int (*load_shlib)(struct file *);
61000 int (*core_dump)(struct coredump_params *cprm);
61001 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61002 unsigned long min_coredump; /* minimal dump size */
61003 };
61004
61005 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61006 index 4a2ab7c..a2de7a8 100644
61007 --- a/include/linux/blkdev.h
61008 +++ b/include/linux/blkdev.h
61009 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61010 /* this callback is with swap_lock and sometimes page table lock held */
61011 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61012 struct module *owner;
61013 -};
61014 +} __do_const;
61015
61016 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61017 unsigned long);
61018 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61019 index 4d1a074..88f929a 100644
61020 --- a/include/linux/blktrace_api.h
61021 +++ b/include/linux/blktrace_api.h
61022 @@ -162,7 +162,7 @@ struct blk_trace {
61023 struct dentry *dir;
61024 struct dentry *dropped_file;
61025 struct dentry *msg_file;
61026 - atomic_t dropped;
61027 + atomic_unchecked_t dropped;
61028 };
61029
61030 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61031 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61032 index 83195fb..0b0f77d 100644
61033 --- a/include/linux/byteorder/little_endian.h
61034 +++ b/include/linux/byteorder/little_endian.h
61035 @@ -42,51 +42,51 @@
61036
61037 static inline __le64 __cpu_to_le64p(const __u64 *p)
61038 {
61039 - return (__force __le64)*p;
61040 + return (__force const __le64)*p;
61041 }
61042 static inline __u64 __le64_to_cpup(const __le64 *p)
61043 {
61044 - return (__force __u64)*p;
61045 + return (__force const __u64)*p;
61046 }
61047 static inline __le32 __cpu_to_le32p(const __u32 *p)
61048 {
61049 - return (__force __le32)*p;
61050 + return (__force const __le32)*p;
61051 }
61052 static inline __u32 __le32_to_cpup(const __le32 *p)
61053 {
61054 - return (__force __u32)*p;
61055 + return (__force const __u32)*p;
61056 }
61057 static inline __le16 __cpu_to_le16p(const __u16 *p)
61058 {
61059 - return (__force __le16)*p;
61060 + return (__force const __le16)*p;
61061 }
61062 static inline __u16 __le16_to_cpup(const __le16 *p)
61063 {
61064 - return (__force __u16)*p;
61065 + return (__force const __u16)*p;
61066 }
61067 static inline __be64 __cpu_to_be64p(const __u64 *p)
61068 {
61069 - return (__force __be64)__swab64p(p);
61070 + return (__force const __be64)__swab64p(p);
61071 }
61072 static inline __u64 __be64_to_cpup(const __be64 *p)
61073 {
61074 - return __swab64p((__u64 *)p);
61075 + return __swab64p((const __u64 *)p);
61076 }
61077 static inline __be32 __cpu_to_be32p(const __u32 *p)
61078 {
61079 - return (__force __be32)__swab32p(p);
61080 + return (__force const __be32)__swab32p(p);
61081 }
61082 static inline __u32 __be32_to_cpup(const __be32 *p)
61083 {
61084 - return __swab32p((__u32 *)p);
61085 + return __swab32p((const __u32 *)p);
61086 }
61087 static inline __be16 __cpu_to_be16p(const __u16 *p)
61088 {
61089 - return (__force __be16)__swab16p(p);
61090 + return (__force const __be16)__swab16p(p);
61091 }
61092 static inline __u16 __be16_to_cpup(const __be16 *p)
61093 {
61094 - return __swab16p((__u16 *)p);
61095 + return __swab16p((const __u16 *)p);
61096 }
61097 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61098 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61099 diff --git a/include/linux/cache.h b/include/linux/cache.h
61100 index 4c57065..4307975 100644
61101 --- a/include/linux/cache.h
61102 +++ b/include/linux/cache.h
61103 @@ -16,6 +16,10 @@
61104 #define __read_mostly
61105 #endif
61106
61107 +#ifndef __read_only
61108 +#define __read_only __read_mostly
61109 +#endif
61110 +
61111 #ifndef ____cacheline_aligned
61112 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61113 #endif
61114 diff --git a/include/linux/capability.h b/include/linux/capability.h
61115 index d10b7ed..0288b79 100644
61116 --- a/include/linux/capability.h
61117 +++ b/include/linux/capability.h
61118 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61119 extern bool ns_capable(struct user_namespace *ns, int cap);
61120 extern bool nsown_capable(int cap);
61121 extern bool inode_capable(const struct inode *inode, int cap);
61122 +extern bool capable_nolog(int cap);
61123 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61124 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61125
61126 /* audit system wants to get cap info from files as well */
61127 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61128
61129 +extern int is_privileged_binary(const struct dentry *dentry);
61130 +
61131 #endif /* __KERNEL__ */
61132
61133 #endif /* !_LINUX_CAPABILITY_H */
61134 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61135 index 42e55de..1cd0e66 100644
61136 --- a/include/linux/cleancache.h
61137 +++ b/include/linux/cleancache.h
61138 @@ -31,7 +31,7 @@ struct cleancache_ops {
61139 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61140 void (*invalidate_inode)(int, struct cleancache_filekey);
61141 void (*invalidate_fs)(int);
61142 -};
61143 +} __no_const;
61144
61145 extern struct cleancache_ops
61146 cleancache_register_ops(struct cleancache_ops *ops);
61147 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61148 index 77335fa..6cbe7dd 100644
61149 --- a/include/linux/clk-provider.h
61150 +++ b/include/linux/clk-provider.h
61151 @@ -111,6 +111,7 @@ struct clk_ops {
61152 unsigned long);
61153 void (*init)(struct clk_hw *hw);
61154 };
61155 +typedef struct clk_ops __no_const clk_ops_no_const;
61156
61157 /**
61158 * struct clk_init_data - holds init data that's common to all clocks and is
61159 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61160 index 934bc34..1b47129 100644
61161 --- a/include/linux/compiler-gcc4.h
61162 +++ b/include/linux/compiler-gcc4.h
61163 @@ -32,6 +32,21 @@
61164 #define __linktime_error(message) __attribute__((__error__(message)))
61165
61166 #if __GNUC_MINOR__ >= 5
61167 +
61168 +#ifdef CONSTIFY_PLUGIN
61169 +#define __no_const __attribute__((no_const))
61170 +#define __do_const __attribute__((do_const))
61171 +#endif
61172 +
61173 +#ifdef SIZE_OVERFLOW_PLUGIN
61174 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61175 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61176 +#endif
61177 +
61178 +#ifdef LATENT_ENTROPY_PLUGIN
61179 +#define __latent_entropy __attribute__((latent_entropy))
61180 +#endif
61181 +
61182 /*
61183 * Mark a position in code as unreachable. This can be used to
61184 * suppress control flow warnings after asm blocks that transfer
61185 @@ -47,6 +62,11 @@
61186 #define __noclone __attribute__((__noclone__))
61187
61188 #endif
61189 +
61190 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61191 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61192 +#define __bos0(ptr) __bos((ptr), 0)
61193 +#define __bos1(ptr) __bos((ptr), 1)
61194 #endif
61195
61196 #if __GNUC_MINOR__ >= 6
61197 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61198 index f430e41..38be90f 100644
61199 --- a/include/linux/compiler.h
61200 +++ b/include/linux/compiler.h
61201 @@ -5,31 +5,62 @@
61202
61203 #ifdef __CHECKER__
61204 # define __user __attribute__((noderef, address_space(1)))
61205 +# define __force_user __force __user
61206 # define __kernel __attribute__((address_space(0)))
61207 +# define __force_kernel __force __kernel
61208 # define __safe __attribute__((safe))
61209 # define __force __attribute__((force))
61210 # define __nocast __attribute__((nocast))
61211 # define __iomem __attribute__((noderef, address_space(2)))
61212 +# define __force_iomem __force __iomem
61213 # define __acquires(x) __attribute__((context(x,0,1)))
61214 # define __releases(x) __attribute__((context(x,1,0)))
61215 # define __acquire(x) __context__(x,1)
61216 # define __release(x) __context__(x,-1)
61217 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61218 # define __percpu __attribute__((noderef, address_space(3)))
61219 +# define __force_percpu __force __percpu
61220 #ifdef CONFIG_SPARSE_RCU_POINTER
61221 # define __rcu __attribute__((noderef, address_space(4)))
61222 +# define __force_rcu __force __rcu
61223 #else
61224 # define __rcu
61225 +# define __force_rcu
61226 #endif
61227 extern void __chk_user_ptr(const volatile void __user *);
61228 extern void __chk_io_ptr(const volatile void __iomem *);
61229 +#elif defined(CHECKER_PLUGIN)
61230 +//# define __user
61231 +//# define __force_user
61232 +//# define __kernel
61233 +//# define __force_kernel
61234 +# define __safe
61235 +# define __force
61236 +# define __nocast
61237 +# define __iomem
61238 +# define __force_iomem
61239 +# define __chk_user_ptr(x) (void)0
61240 +# define __chk_io_ptr(x) (void)0
61241 +# define __builtin_warning(x, y...) (1)
61242 +# define __acquires(x)
61243 +# define __releases(x)
61244 +# define __acquire(x) (void)0
61245 +# define __release(x) (void)0
61246 +# define __cond_lock(x,c) (c)
61247 +# define __percpu
61248 +# define __force_percpu
61249 +# define __rcu
61250 +# define __force_rcu
61251 #else
61252 # define __user
61253 +# define __force_user
61254 # define __kernel
61255 +# define __force_kernel
61256 # define __safe
61257 # define __force
61258 # define __nocast
61259 # define __iomem
61260 +# define __force_iomem
61261 # define __chk_user_ptr(x) (void)0
61262 # define __chk_io_ptr(x) (void)0
61263 # define __builtin_warning(x, y...) (1)
61264 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61265 # define __release(x) (void)0
61266 # define __cond_lock(x,c) (c)
61267 # define __percpu
61268 +# define __force_percpu
61269 # define __rcu
61270 +# define __force_rcu
61271 #endif
61272
61273 #ifdef __KERNEL__
61274 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61275 # define __attribute_const__ /* unimplemented */
61276 #endif
61277
61278 +#ifndef __no_const
61279 +# define __no_const
61280 +#endif
61281 +
61282 +#ifndef __do_const
61283 +# define __do_const
61284 +#endif
61285 +
61286 +#ifndef __size_overflow
61287 +# define __size_overflow(...)
61288 +#endif
61289 +
61290 +#ifndef __intentional_overflow
61291 +# define __intentional_overflow(...)
61292 +#endif
61293 +
61294 +#ifndef __latent_entropy
61295 +# define __latent_entropy
61296 +#endif
61297 +
61298 /*
61299 * Tell gcc if a function is cold. The compiler will assume any path
61300 * directly leading to the call is unlikely.
61301 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61302 #define __cold
61303 #endif
61304
61305 +#ifndef __alloc_size
61306 +#define __alloc_size(...)
61307 +#endif
61308 +
61309 +#ifndef __bos
61310 +#define __bos(ptr, arg)
61311 +#endif
61312 +
61313 +#ifndef __bos0
61314 +#define __bos0(ptr)
61315 +#endif
61316 +
61317 +#ifndef __bos1
61318 +#define __bos1(ptr)
61319 +#endif
61320 +
61321 /* Simple shorthand for a section definition */
61322 #ifndef __section
61323 # define __section(S) __attribute__ ((__section__(#S)))
61324 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61325 * use is to mediate communication between process-level code and irq/NMI
61326 * handlers, all running on the same CPU.
61327 */
61328 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61329 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61330 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61331
61332 #endif /* __LINUX_COMPILER_H */
61333 diff --git a/include/linux/cred.h b/include/linux/cred.h
61334 index ebbed2c..908cc2c 100644
61335 --- a/include/linux/cred.h
61336 +++ b/include/linux/cred.h
61337 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61338 static inline void validate_process_creds(void)
61339 {
61340 }
61341 +static inline void validate_task_creds(struct task_struct *task)
61342 +{
61343 +}
61344 #endif
61345
61346 /**
61347 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61348 index b92eadf..b4ecdc1 100644
61349 --- a/include/linux/crypto.h
61350 +++ b/include/linux/crypto.h
61351 @@ -373,7 +373,7 @@ struct cipher_tfm {
61352 const u8 *key, unsigned int keylen);
61353 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61354 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61355 -};
61356 +} __no_const;
61357
61358 struct hash_tfm {
61359 int (*init)(struct hash_desc *desc);
61360 @@ -394,13 +394,13 @@ struct compress_tfm {
61361 int (*cot_decompress)(struct crypto_tfm *tfm,
61362 const u8 *src, unsigned int slen,
61363 u8 *dst, unsigned int *dlen);
61364 -};
61365 +} __no_const;
61366
61367 struct rng_tfm {
61368 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61369 unsigned int dlen);
61370 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61371 -};
61372 +} __no_const;
61373
61374 #define crt_ablkcipher crt_u.ablkcipher
61375 #define crt_aead crt_u.aead
61376 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61377 index 7925bf0..d5143d2 100644
61378 --- a/include/linux/decompress/mm.h
61379 +++ b/include/linux/decompress/mm.h
61380 @@ -77,7 +77,7 @@ static void free(void *where)
61381 * warnings when not needed (indeed large_malloc / large_free are not
61382 * needed by inflate */
61383
61384 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61385 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61386 #define free(a) kfree(a)
61387
61388 #define large_malloc(a) vmalloc(a)
61389 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61390 index 94af418..b1ca7a2 100644
61391 --- a/include/linux/dma-mapping.h
61392 +++ b/include/linux/dma-mapping.h
61393 @@ -54,7 +54,7 @@ struct dma_map_ops {
61394 u64 (*get_required_mask)(struct device *dev);
61395 #endif
61396 int is_phys;
61397 -};
61398 +} __do_const;
61399
61400 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61401
61402 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61403 index 9c02a45..89fdd73 100644
61404 --- a/include/linux/dmaengine.h
61405 +++ b/include/linux/dmaengine.h
61406 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61407 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61408 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61409
61410 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61411 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61412 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61413 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61414 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61415 struct dma_pinned_list *pinned_list, struct page *page,
61416 unsigned int offset, size_t len);
61417
61418 diff --git a/include/linux/efi.h b/include/linux/efi.h
61419 index ec45ccd..9923c32 100644
61420 --- a/include/linux/efi.h
61421 +++ b/include/linux/efi.h
61422 @@ -635,7 +635,7 @@ struct efivar_operations {
61423 efi_get_variable_t *get_variable;
61424 efi_get_next_variable_t *get_next_variable;
61425 efi_set_variable_t *set_variable;
61426 -};
61427 +} __no_const;
61428
61429 struct efivars {
61430 /*
61431 diff --git a/include/linux/elf.h b/include/linux/elf.h
61432 index 999b4f5..57753b4 100644
61433 --- a/include/linux/elf.h
61434 +++ b/include/linux/elf.h
61435 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61436 #define PT_GNU_EH_FRAME 0x6474e550
61437
61438 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61439 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61440 +
61441 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61442 +
61443 +/* Constants for the e_flags field */
61444 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61445 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61446 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61447 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61448 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61449 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61450
61451 /*
61452 * Extended Numbering
61453 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61454 #define DT_DEBUG 21
61455 #define DT_TEXTREL 22
61456 #define DT_JMPREL 23
61457 +#define DT_FLAGS 30
61458 + #define DF_TEXTREL 0x00000004
61459 #define DT_ENCODING 32
61460 #define OLD_DT_LOOS 0x60000000
61461 #define DT_LOOS 0x6000000d
61462 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61463 #define PF_W 0x2
61464 #define PF_X 0x1
61465
61466 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61467 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61468 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61469 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61470 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61471 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61472 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61473 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61474 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61475 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61476 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61477 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61478 +
61479 typedef struct elf32_phdr{
61480 Elf32_Word p_type;
61481 Elf32_Off p_offset;
61482 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61483 #define EI_OSABI 7
61484 #define EI_PAD 8
61485
61486 +#define EI_PAX 14
61487 +
61488 #define ELFMAG0 0x7f /* EI_MAG */
61489 #define ELFMAG1 'E'
61490 #define ELFMAG2 'L'
61491 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61492 #define elf_note elf32_note
61493 #define elf_addr_t Elf32_Off
61494 #define Elf_Half Elf32_Half
61495 +#define elf_dyn Elf32_Dyn
61496
61497 #else
61498
61499 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61500 #define elf_note elf64_note
61501 #define elf_addr_t Elf64_Off
61502 #define Elf_Half Elf64_Half
61503 +#define elf_dyn Elf64_Dyn
61504
61505 #endif
61506
61507 diff --git a/include/linux/filter.h b/include/linux/filter.h
61508 index 82b0135..917914d 100644
61509 --- a/include/linux/filter.h
61510 +++ b/include/linux/filter.h
61511 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61512
61513 struct sk_buff;
61514 struct sock;
61515 +struct bpf_jit_work;
61516
61517 struct sk_filter
61518 {
61519 @@ -153,6 +154,9 @@ struct sk_filter
61520 unsigned int len; /* Number of filter blocks */
61521 unsigned int (*bpf_func)(const struct sk_buff *skb,
61522 const struct sock_filter *filter);
61523 +#ifdef CONFIG_BPF_JIT
61524 + struct bpf_jit_work *work;
61525 +#endif
61526 struct rcu_head rcu;
61527 struct sock_filter insns[0];
61528 };
61529 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61530 index db04ec5..f6ed627 100644
61531 --- a/include/linux/firewire.h
61532 +++ b/include/linux/firewire.h
61533 @@ -430,7 +430,7 @@ struct fw_iso_context {
61534 union {
61535 fw_iso_callback_t sc;
61536 fw_iso_mc_callback_t mc;
61537 - } callback;
61538 + } __no_const callback;
61539 void *callback_data;
61540 };
61541
61542 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61543 index 0e4e2ee..4ff4312 100644
61544 --- a/include/linux/frontswap.h
61545 +++ b/include/linux/frontswap.h
61546 @@ -11,7 +11,7 @@ struct frontswap_ops {
61547 int (*load)(unsigned, pgoff_t, struct page *);
61548 void (*invalidate_page)(unsigned, pgoff_t);
61549 void (*invalidate_area)(unsigned);
61550 -};
61551 +} __no_const;
61552
61553 extern bool frontswap_enabled;
61554 extern struct frontswap_ops
61555 diff --git a/include/linux/fs.h b/include/linux/fs.h
61556 index aa11047..7d046d0 100644
61557 --- a/include/linux/fs.h
61558 +++ b/include/linux/fs.h
61559 @@ -1802,7 +1802,8 @@ struct file_operations {
61560 int (*setlease)(struct file *, long, struct file_lock **);
61561 long (*fallocate)(struct file *file, int mode, loff_t offset,
61562 loff_t len);
61563 -};
61564 +} __do_const;
61565 +typedef struct file_operations __no_const file_operations_no_const;
61566
61567 struct inode_operations {
61568 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61569 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61570 index 003dc0f..3c4ea97 100644
61571 --- a/include/linux/fs_struct.h
61572 +++ b/include/linux/fs_struct.h
61573 @@ -6,7 +6,7 @@
61574 #include <linux/seqlock.h>
61575
61576 struct fs_struct {
61577 - int users;
61578 + atomic_t users;
61579 spinlock_t lock;
61580 seqcount_t seq;
61581 int umask;
61582 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61583 index ce31408..b1ad003 100644
61584 --- a/include/linux/fscache-cache.h
61585 +++ b/include/linux/fscache-cache.h
61586 @@ -102,7 +102,7 @@ struct fscache_operation {
61587 fscache_operation_release_t release;
61588 };
61589
61590 -extern atomic_t fscache_op_debug_id;
61591 +extern atomic_unchecked_t fscache_op_debug_id;
61592 extern void fscache_op_work_func(struct work_struct *work);
61593
61594 extern void fscache_enqueue_operation(struct fscache_operation *);
61595 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61596 {
61597 INIT_WORK(&op->work, fscache_op_work_func);
61598 atomic_set(&op->usage, 1);
61599 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61600 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61601 op->processor = processor;
61602 op->release = release;
61603 INIT_LIST_HEAD(&op->pend_link);
61604 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61605 index a6dfe69..569586df 100644
61606 --- a/include/linux/fsnotify.h
61607 +++ b/include/linux/fsnotify.h
61608 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61609 */
61610 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61611 {
61612 - return kstrdup(name, GFP_KERNEL);
61613 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61614 }
61615
61616 /*
61617 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61618 index 63d966d..cdcb717 100644
61619 --- a/include/linux/fsnotify_backend.h
61620 +++ b/include/linux/fsnotify_backend.h
61621 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61622 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61623 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61624 };
61625 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61626
61627 /*
61628 * A group is a "thing" that wants to receive notification about filesystem
61629 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61630 index 642928c..e6c83a7 100644
61631 --- a/include/linux/ftrace_event.h
61632 +++ b/include/linux/ftrace_event.h
61633 @@ -97,7 +97,7 @@ struct trace_event_functions {
61634 trace_print_func raw;
61635 trace_print_func hex;
61636 trace_print_func binary;
61637 -};
61638 +} __no_const;
61639
61640 struct trace_event {
61641 struct hlist_node node;
61642 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61643 extern int trace_add_event_call(struct ftrace_event_call *call);
61644 extern void trace_remove_event_call(struct ftrace_event_call *call);
61645
61646 -#define is_signed_type(type) (((type)(-1)) < 0)
61647 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61648
61649 int trace_set_clr_event(const char *system, const char *event, int set);
61650
61651 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61652 index 4f440b3..342233a 100644
61653 --- a/include/linux/genhd.h
61654 +++ b/include/linux/genhd.h
61655 @@ -190,7 +190,7 @@ struct gendisk {
61656 struct kobject *slave_dir;
61657
61658 struct timer_rand_state *random;
61659 - atomic_t sync_io; /* RAID */
61660 + atomic_unchecked_t sync_io; /* RAID */
61661 struct disk_events *ev;
61662 #ifdef CONFIG_BLK_DEV_INTEGRITY
61663 struct blk_integrity *integrity;
61664 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61665 index 4883f39..26688a8 100644
61666 --- a/include/linux/gfp.h
61667 +++ b/include/linux/gfp.h
61668 @@ -39,6 +39,12 @@ struct vm_area_struct;
61669 #define ___GFP_OTHER_NODE 0x800000u
61670 #define ___GFP_WRITE 0x1000000u
61671
61672 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61673 +#define ___GFP_USERCOPY 0x2000000u
61674 +#else
61675 +#define ___GFP_USERCOPY 0
61676 +#endif
61677 +
61678 /*
61679 * GFP bitmasks..
61680 *
61681 @@ -93,6 +99,7 @@ struct vm_area_struct;
61682 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61683 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61684 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61685 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61686
61687 /*
61688 * This may seem redundant, but it's a way of annotating false positives vs.
61689 @@ -100,7 +107,7 @@ struct vm_area_struct;
61690 */
61691 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61692
61693 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61694 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61695 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61696
61697 /* This equals 0, but use constants in case they ever change */
61698 @@ -154,6 +161,8 @@ struct vm_area_struct;
61699 /* 4GB DMA on some platforms */
61700 #define GFP_DMA32 __GFP_DMA32
61701
61702 +#define GFP_USERCOPY __GFP_USERCOPY
61703 +
61704 /* Convert GFP flags to their corresponding migrate type */
61705 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61706 {
61707 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61708 new file mode 100644
61709 index 0000000..c938b1f
61710 --- /dev/null
61711 +++ b/include/linux/gracl.h
61712 @@ -0,0 +1,319 @@
61713 +#ifndef GR_ACL_H
61714 +#define GR_ACL_H
61715 +
61716 +#include <linux/grdefs.h>
61717 +#include <linux/resource.h>
61718 +#include <linux/capability.h>
61719 +#include <linux/dcache.h>
61720 +#include <asm/resource.h>
61721 +
61722 +/* Major status information */
61723 +
61724 +#define GR_VERSION "grsecurity 2.9.1"
61725 +#define GRSECURITY_VERSION 0x2901
61726 +
61727 +enum {
61728 + GR_SHUTDOWN = 0,
61729 + GR_ENABLE = 1,
61730 + GR_SPROLE = 2,
61731 + GR_RELOAD = 3,
61732 + GR_SEGVMOD = 4,
61733 + GR_STATUS = 5,
61734 + GR_UNSPROLE = 6,
61735 + GR_PASSSET = 7,
61736 + GR_SPROLEPAM = 8,
61737 +};
61738 +
61739 +/* Password setup definitions
61740 + * kernel/grhash.c */
61741 +enum {
61742 + GR_PW_LEN = 128,
61743 + GR_SALT_LEN = 16,
61744 + GR_SHA_LEN = 32,
61745 +};
61746 +
61747 +enum {
61748 + GR_SPROLE_LEN = 64,
61749 +};
61750 +
61751 +enum {
61752 + GR_NO_GLOB = 0,
61753 + GR_REG_GLOB,
61754 + GR_CREATE_GLOB
61755 +};
61756 +
61757 +#define GR_NLIMITS 32
61758 +
61759 +/* Begin Data Structures */
61760 +
61761 +struct sprole_pw {
61762 + unsigned char *rolename;
61763 + unsigned char salt[GR_SALT_LEN];
61764 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61765 +};
61766 +
61767 +struct name_entry {
61768 + __u32 key;
61769 + ino_t inode;
61770 + dev_t device;
61771 + char *name;
61772 + __u16 len;
61773 + __u8 deleted;
61774 + struct name_entry *prev;
61775 + struct name_entry *next;
61776 +};
61777 +
61778 +struct inodev_entry {
61779 + struct name_entry *nentry;
61780 + struct inodev_entry *prev;
61781 + struct inodev_entry *next;
61782 +};
61783 +
61784 +struct acl_role_db {
61785 + struct acl_role_label **r_hash;
61786 + __u32 r_size;
61787 +};
61788 +
61789 +struct inodev_db {
61790 + struct inodev_entry **i_hash;
61791 + __u32 i_size;
61792 +};
61793 +
61794 +struct name_db {
61795 + struct name_entry **n_hash;
61796 + __u32 n_size;
61797 +};
61798 +
61799 +struct crash_uid {
61800 + uid_t uid;
61801 + unsigned long expires;
61802 +};
61803 +
61804 +struct gr_hash_struct {
61805 + void **table;
61806 + void **nametable;
61807 + void *first;
61808 + __u32 table_size;
61809 + __u32 used_size;
61810 + int type;
61811 +};
61812 +
61813 +/* Userspace Grsecurity ACL data structures */
61814 +
61815 +struct acl_subject_label {
61816 + char *filename;
61817 + ino_t inode;
61818 + dev_t device;
61819 + __u32 mode;
61820 + kernel_cap_t cap_mask;
61821 + kernel_cap_t cap_lower;
61822 + kernel_cap_t cap_invert_audit;
61823 +
61824 + struct rlimit res[GR_NLIMITS];
61825 + __u32 resmask;
61826 +
61827 + __u8 user_trans_type;
61828 + __u8 group_trans_type;
61829 + uid_t *user_transitions;
61830 + gid_t *group_transitions;
61831 + __u16 user_trans_num;
61832 + __u16 group_trans_num;
61833 +
61834 + __u32 sock_families[2];
61835 + __u32 ip_proto[8];
61836 + __u32 ip_type;
61837 + struct acl_ip_label **ips;
61838 + __u32 ip_num;
61839 + __u32 inaddr_any_override;
61840 +
61841 + __u32 crashes;
61842 + unsigned long expires;
61843 +
61844 + struct acl_subject_label *parent_subject;
61845 + struct gr_hash_struct *hash;
61846 + struct acl_subject_label *prev;
61847 + struct acl_subject_label *next;
61848 +
61849 + struct acl_object_label **obj_hash;
61850 + __u32 obj_hash_size;
61851 + __u16 pax_flags;
61852 +};
61853 +
61854 +struct role_allowed_ip {
61855 + __u32 addr;
61856 + __u32 netmask;
61857 +
61858 + struct role_allowed_ip *prev;
61859 + struct role_allowed_ip *next;
61860 +};
61861 +
61862 +struct role_transition {
61863 + char *rolename;
61864 +
61865 + struct role_transition *prev;
61866 + struct role_transition *next;
61867 +};
61868 +
61869 +struct acl_role_label {
61870 + char *rolename;
61871 + uid_t uidgid;
61872 + __u16 roletype;
61873 +
61874 + __u16 auth_attempts;
61875 + unsigned long expires;
61876 +
61877 + struct acl_subject_label *root_label;
61878 + struct gr_hash_struct *hash;
61879 +
61880 + struct acl_role_label *prev;
61881 + struct acl_role_label *next;
61882 +
61883 + struct role_transition *transitions;
61884 + struct role_allowed_ip *allowed_ips;
61885 + uid_t *domain_children;
61886 + __u16 domain_child_num;
61887 +
61888 + umode_t umask;
61889 +
61890 + struct acl_subject_label **subj_hash;
61891 + __u32 subj_hash_size;
61892 +};
61893 +
61894 +struct user_acl_role_db {
61895 + struct acl_role_label **r_table;
61896 + __u32 num_pointers; /* Number of allocations to track */
61897 + __u32 num_roles; /* Number of roles */
61898 + __u32 num_domain_children; /* Number of domain children */
61899 + __u32 num_subjects; /* Number of subjects */
61900 + __u32 num_objects; /* Number of objects */
61901 +};
61902 +
61903 +struct acl_object_label {
61904 + char *filename;
61905 + ino_t inode;
61906 + dev_t device;
61907 + __u32 mode;
61908 +
61909 + struct acl_subject_label *nested;
61910 + struct acl_object_label *globbed;
61911 +
61912 + /* next two structures not used */
61913 +
61914 + struct acl_object_label *prev;
61915 + struct acl_object_label *next;
61916 +};
61917 +
61918 +struct acl_ip_label {
61919 + char *iface;
61920 + __u32 addr;
61921 + __u32 netmask;
61922 + __u16 low, high;
61923 + __u8 mode;
61924 + __u32 type;
61925 + __u32 proto[8];
61926 +
61927 + /* next two structures not used */
61928 +
61929 + struct acl_ip_label *prev;
61930 + struct acl_ip_label *next;
61931 +};
61932 +
61933 +struct gr_arg {
61934 + struct user_acl_role_db role_db;
61935 + unsigned char pw[GR_PW_LEN];
61936 + unsigned char salt[GR_SALT_LEN];
61937 + unsigned char sum[GR_SHA_LEN];
61938 + unsigned char sp_role[GR_SPROLE_LEN];
61939 + struct sprole_pw *sprole_pws;
61940 + dev_t segv_device;
61941 + ino_t segv_inode;
61942 + uid_t segv_uid;
61943 + __u16 num_sprole_pws;
61944 + __u16 mode;
61945 +};
61946 +
61947 +struct gr_arg_wrapper {
61948 + struct gr_arg *arg;
61949 + __u32 version;
61950 + __u32 size;
61951 +};
61952 +
61953 +struct subject_map {
61954 + struct acl_subject_label *user;
61955 + struct acl_subject_label *kernel;
61956 + struct subject_map *prev;
61957 + struct subject_map *next;
61958 +};
61959 +
61960 +struct acl_subj_map_db {
61961 + struct subject_map **s_hash;
61962 + __u32 s_size;
61963 +};
61964 +
61965 +/* End Data Structures Section */
61966 +
61967 +/* Hash functions generated by empirical testing by Brad Spengler
61968 + Makes good use of the low bits of the inode. Generally 0-1 times
61969 + in loop for successful match. 0-3 for unsuccessful match.
61970 + Shift/add algorithm with modulus of table size and an XOR*/
61971 +
61972 +static __inline__ unsigned int
61973 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61974 +{
61975 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61976 +}
61977 +
61978 + static __inline__ unsigned int
61979 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61980 +{
61981 + return ((const unsigned long)userp % sz);
61982 +}
61983 +
61984 +static __inline__ unsigned int
61985 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61986 +{
61987 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61988 +}
61989 +
61990 +static __inline__ unsigned int
61991 +nhash(const char *name, const __u16 len, const unsigned int sz)
61992 +{
61993 + return full_name_hash((const unsigned char *)name, len) % sz;
61994 +}
61995 +
61996 +#define FOR_EACH_ROLE_START(role) \
61997 + role = role_list; \
61998 + while (role) {
61999 +
62000 +#define FOR_EACH_ROLE_END(role) \
62001 + role = role->prev; \
62002 + }
62003 +
62004 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62005 + subj = NULL; \
62006 + iter = 0; \
62007 + while (iter < role->subj_hash_size) { \
62008 + if (subj == NULL) \
62009 + subj = role->subj_hash[iter]; \
62010 + if (subj == NULL) { \
62011 + iter++; \
62012 + continue; \
62013 + }
62014 +
62015 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62016 + subj = subj->next; \
62017 + if (subj == NULL) \
62018 + iter++; \
62019 + }
62020 +
62021 +
62022 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62023 + subj = role->hash->first; \
62024 + while (subj != NULL) {
62025 +
62026 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62027 + subj = subj->next; \
62028 + }
62029 +
62030 +#endif
62031 +
62032 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62033 new file mode 100644
62034 index 0000000..323ecf2
62035 --- /dev/null
62036 +++ b/include/linux/gralloc.h
62037 @@ -0,0 +1,9 @@
62038 +#ifndef __GRALLOC_H
62039 +#define __GRALLOC_H
62040 +
62041 +void acl_free_all(void);
62042 +int acl_alloc_stack_init(unsigned long size);
62043 +void *acl_alloc(unsigned long len);
62044 +void *acl_alloc_num(unsigned long num, unsigned long len);
62045 +
62046 +#endif
62047 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62048 new file mode 100644
62049 index 0000000..b30e9bc
62050 --- /dev/null
62051 +++ b/include/linux/grdefs.h
62052 @@ -0,0 +1,140 @@
62053 +#ifndef GRDEFS_H
62054 +#define GRDEFS_H
62055 +
62056 +/* Begin grsecurity status declarations */
62057 +
62058 +enum {
62059 + GR_READY = 0x01,
62060 + GR_STATUS_INIT = 0x00 // disabled state
62061 +};
62062 +
62063 +/* Begin ACL declarations */
62064 +
62065 +/* Role flags */
62066 +
62067 +enum {
62068 + GR_ROLE_USER = 0x0001,
62069 + GR_ROLE_GROUP = 0x0002,
62070 + GR_ROLE_DEFAULT = 0x0004,
62071 + GR_ROLE_SPECIAL = 0x0008,
62072 + GR_ROLE_AUTH = 0x0010,
62073 + GR_ROLE_NOPW = 0x0020,
62074 + GR_ROLE_GOD = 0x0040,
62075 + GR_ROLE_LEARN = 0x0080,
62076 + GR_ROLE_TPE = 0x0100,
62077 + GR_ROLE_DOMAIN = 0x0200,
62078 + GR_ROLE_PAM = 0x0400,
62079 + GR_ROLE_PERSIST = 0x0800
62080 +};
62081 +
62082 +/* ACL Subject and Object mode flags */
62083 +enum {
62084 + GR_DELETED = 0x80000000
62085 +};
62086 +
62087 +/* ACL Object-only mode flags */
62088 +enum {
62089 + GR_READ = 0x00000001,
62090 + GR_APPEND = 0x00000002,
62091 + GR_WRITE = 0x00000004,
62092 + GR_EXEC = 0x00000008,
62093 + GR_FIND = 0x00000010,
62094 + GR_INHERIT = 0x00000020,
62095 + GR_SETID = 0x00000040,
62096 + GR_CREATE = 0x00000080,
62097 + GR_DELETE = 0x00000100,
62098 + GR_LINK = 0x00000200,
62099 + GR_AUDIT_READ = 0x00000400,
62100 + GR_AUDIT_APPEND = 0x00000800,
62101 + GR_AUDIT_WRITE = 0x00001000,
62102 + GR_AUDIT_EXEC = 0x00002000,
62103 + GR_AUDIT_FIND = 0x00004000,
62104 + GR_AUDIT_INHERIT= 0x00008000,
62105 + GR_AUDIT_SETID = 0x00010000,
62106 + GR_AUDIT_CREATE = 0x00020000,
62107 + GR_AUDIT_DELETE = 0x00040000,
62108 + GR_AUDIT_LINK = 0x00080000,
62109 + GR_PTRACERD = 0x00100000,
62110 + GR_NOPTRACE = 0x00200000,
62111 + GR_SUPPRESS = 0x00400000,
62112 + GR_NOLEARN = 0x00800000,
62113 + GR_INIT_TRANSFER= 0x01000000
62114 +};
62115 +
62116 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62117 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62118 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62119 +
62120 +/* ACL subject-only mode flags */
62121 +enum {
62122 + GR_KILL = 0x00000001,
62123 + GR_VIEW = 0x00000002,
62124 + GR_PROTECTED = 0x00000004,
62125 + GR_LEARN = 0x00000008,
62126 + GR_OVERRIDE = 0x00000010,
62127 + /* just a placeholder, this mode is only used in userspace */
62128 + GR_DUMMY = 0x00000020,
62129 + GR_PROTSHM = 0x00000040,
62130 + GR_KILLPROC = 0x00000080,
62131 + GR_KILLIPPROC = 0x00000100,
62132 + /* just a placeholder, this mode is only used in userspace */
62133 + GR_NOTROJAN = 0x00000200,
62134 + GR_PROTPROCFD = 0x00000400,
62135 + GR_PROCACCT = 0x00000800,
62136 + GR_RELAXPTRACE = 0x00001000,
62137 + GR_NESTED = 0x00002000,
62138 + GR_INHERITLEARN = 0x00004000,
62139 + GR_PROCFIND = 0x00008000,
62140 + GR_POVERRIDE = 0x00010000,
62141 + GR_KERNELAUTH = 0x00020000,
62142 + GR_ATSECURE = 0x00040000,
62143 + GR_SHMEXEC = 0x00080000
62144 +};
62145 +
62146 +enum {
62147 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62148 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62149 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62150 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62151 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62152 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62153 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62154 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62155 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62156 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62157 +};
62158 +
62159 +enum {
62160 + GR_ID_USER = 0x01,
62161 + GR_ID_GROUP = 0x02,
62162 +};
62163 +
62164 +enum {
62165 + GR_ID_ALLOW = 0x01,
62166 + GR_ID_DENY = 0x02,
62167 +};
62168 +
62169 +#define GR_CRASH_RES 31
62170 +#define GR_UIDTABLE_MAX 500
62171 +
62172 +/* begin resource learning section */
62173 +enum {
62174 + GR_RLIM_CPU_BUMP = 60,
62175 + GR_RLIM_FSIZE_BUMP = 50000,
62176 + GR_RLIM_DATA_BUMP = 10000,
62177 + GR_RLIM_STACK_BUMP = 1000,
62178 + GR_RLIM_CORE_BUMP = 10000,
62179 + GR_RLIM_RSS_BUMP = 500000,
62180 + GR_RLIM_NPROC_BUMP = 1,
62181 + GR_RLIM_NOFILE_BUMP = 5,
62182 + GR_RLIM_MEMLOCK_BUMP = 50000,
62183 + GR_RLIM_AS_BUMP = 500000,
62184 + GR_RLIM_LOCKS_BUMP = 2,
62185 + GR_RLIM_SIGPENDING_BUMP = 5,
62186 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62187 + GR_RLIM_NICE_BUMP = 1,
62188 + GR_RLIM_RTPRIO_BUMP = 1,
62189 + GR_RLIM_RTTIME_BUMP = 1000000
62190 +};
62191 +
62192 +#endif
62193 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62194 new file mode 100644
62195 index 0000000..c9292f7
62196 --- /dev/null
62197 +++ b/include/linux/grinternal.h
62198 @@ -0,0 +1,223 @@
62199 +#ifndef __GRINTERNAL_H
62200 +#define __GRINTERNAL_H
62201 +
62202 +#ifdef CONFIG_GRKERNSEC
62203 +
62204 +#include <linux/fs.h>
62205 +#include <linux/mnt_namespace.h>
62206 +#include <linux/nsproxy.h>
62207 +#include <linux/gracl.h>
62208 +#include <linux/grdefs.h>
62209 +#include <linux/grmsg.h>
62210 +
62211 +void gr_add_learn_entry(const char *fmt, ...)
62212 + __attribute__ ((format (printf, 1, 2)));
62213 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62214 + const struct vfsmount *mnt);
62215 +__u32 gr_check_create(const struct dentry *new_dentry,
62216 + const struct dentry *parent,
62217 + const struct vfsmount *mnt, const __u32 mode);
62218 +int gr_check_protected_task(const struct task_struct *task);
62219 +__u32 to_gr_audit(const __u32 reqmode);
62220 +int gr_set_acls(const int type);
62221 +int gr_apply_subject_to_task(struct task_struct *task);
62222 +int gr_acl_is_enabled(void);
62223 +char gr_roletype_to_char(void);
62224 +
62225 +void gr_handle_alertkill(struct task_struct *task);
62226 +char *gr_to_filename(const struct dentry *dentry,
62227 + const struct vfsmount *mnt);
62228 +char *gr_to_filename1(const struct dentry *dentry,
62229 + const struct vfsmount *mnt);
62230 +char *gr_to_filename2(const struct dentry *dentry,
62231 + const struct vfsmount *mnt);
62232 +char *gr_to_filename3(const struct dentry *dentry,
62233 + const struct vfsmount *mnt);
62234 +
62235 +extern int grsec_enable_ptrace_readexec;
62236 +extern int grsec_enable_harden_ptrace;
62237 +extern int grsec_enable_link;
62238 +extern int grsec_enable_fifo;
62239 +extern int grsec_enable_execve;
62240 +extern int grsec_enable_shm;
62241 +extern int grsec_enable_execlog;
62242 +extern int grsec_enable_signal;
62243 +extern int grsec_enable_audit_ptrace;
62244 +extern int grsec_enable_forkfail;
62245 +extern int grsec_enable_time;
62246 +extern int grsec_enable_rofs;
62247 +extern int grsec_enable_chroot_shmat;
62248 +extern int grsec_enable_chroot_mount;
62249 +extern int grsec_enable_chroot_double;
62250 +extern int grsec_enable_chroot_pivot;
62251 +extern int grsec_enable_chroot_chdir;
62252 +extern int grsec_enable_chroot_chmod;
62253 +extern int grsec_enable_chroot_mknod;
62254 +extern int grsec_enable_chroot_fchdir;
62255 +extern int grsec_enable_chroot_nice;
62256 +extern int grsec_enable_chroot_execlog;
62257 +extern int grsec_enable_chroot_caps;
62258 +extern int grsec_enable_chroot_sysctl;
62259 +extern int grsec_enable_chroot_unix;
62260 +extern int grsec_enable_symlinkown;
62261 +extern int grsec_symlinkown_gid;
62262 +extern int grsec_enable_tpe;
62263 +extern int grsec_tpe_gid;
62264 +extern int grsec_enable_tpe_all;
62265 +extern int grsec_enable_tpe_invert;
62266 +extern int grsec_enable_socket_all;
62267 +extern int grsec_socket_all_gid;
62268 +extern int grsec_enable_socket_client;
62269 +extern int grsec_socket_client_gid;
62270 +extern int grsec_enable_socket_server;
62271 +extern int grsec_socket_server_gid;
62272 +extern int grsec_audit_gid;
62273 +extern int grsec_enable_group;
62274 +extern int grsec_enable_audit_textrel;
62275 +extern int grsec_enable_log_rwxmaps;
62276 +extern int grsec_enable_mount;
62277 +extern int grsec_enable_chdir;
62278 +extern int grsec_resource_logging;
62279 +extern int grsec_enable_blackhole;
62280 +extern int grsec_lastack_retries;
62281 +extern int grsec_enable_brute;
62282 +extern int grsec_lock;
62283 +
62284 +extern spinlock_t grsec_alert_lock;
62285 +extern unsigned long grsec_alert_wtime;
62286 +extern unsigned long grsec_alert_fyet;
62287 +
62288 +extern spinlock_t grsec_audit_lock;
62289 +
62290 +extern rwlock_t grsec_exec_file_lock;
62291 +
62292 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62293 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62294 + (tsk)->exec_file->f_vfsmnt) : "/")
62295 +
62296 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62297 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62298 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62299 +
62300 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62301 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62302 + (tsk)->exec_file->f_vfsmnt) : "/")
62303 +
62304 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62305 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62306 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62307 +
62308 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62309 +
62310 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62311 +
62312 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62313 + (task)->pid, (cred)->uid, \
62314 + (cred)->euid, (cred)->gid, (cred)->egid, \
62315 + gr_parent_task_fullpath(task), \
62316 + (task)->real_parent->comm, (task)->real_parent->pid, \
62317 + (pcred)->uid, (pcred)->euid, \
62318 + (pcred)->gid, (pcred)->egid
62319 +
62320 +#define GR_CHROOT_CAPS {{ \
62321 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62322 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62323 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62324 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62325 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62326 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62327 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62328 +
62329 +#define security_learn(normal_msg,args...) \
62330 +({ \
62331 + read_lock(&grsec_exec_file_lock); \
62332 + gr_add_learn_entry(normal_msg "\n", ## args); \
62333 + read_unlock(&grsec_exec_file_lock); \
62334 +})
62335 +
62336 +enum {
62337 + GR_DO_AUDIT,
62338 + GR_DONT_AUDIT,
62339 + /* used for non-audit messages that we shouldn't kill the task on */
62340 + GR_DONT_AUDIT_GOOD
62341 +};
62342 +
62343 +enum {
62344 + GR_TTYSNIFF,
62345 + GR_RBAC,
62346 + GR_RBAC_STR,
62347 + GR_STR_RBAC,
62348 + GR_RBAC_MODE2,
62349 + GR_RBAC_MODE3,
62350 + GR_FILENAME,
62351 + GR_SYSCTL_HIDDEN,
62352 + GR_NOARGS,
62353 + GR_ONE_INT,
62354 + GR_ONE_INT_TWO_STR,
62355 + GR_ONE_STR,
62356 + GR_STR_INT,
62357 + GR_TWO_STR_INT,
62358 + GR_TWO_INT,
62359 + GR_TWO_U64,
62360 + GR_THREE_INT,
62361 + GR_FIVE_INT_TWO_STR,
62362 + GR_TWO_STR,
62363 + GR_THREE_STR,
62364 + GR_FOUR_STR,
62365 + GR_STR_FILENAME,
62366 + GR_FILENAME_STR,
62367 + GR_FILENAME_TWO_INT,
62368 + GR_FILENAME_TWO_INT_STR,
62369 + GR_TEXTREL,
62370 + GR_PTRACE,
62371 + GR_RESOURCE,
62372 + GR_CAP,
62373 + GR_SIG,
62374 + GR_SIG2,
62375 + GR_CRASH1,
62376 + GR_CRASH2,
62377 + GR_PSACCT,
62378 + GR_RWXMAP
62379 +};
62380 +
62381 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62382 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62383 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62384 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62385 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62386 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62387 +#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)
62388 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62389 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62390 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62391 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62392 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62393 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62394 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62395 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62396 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62397 +#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)
62398 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62399 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62400 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62401 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62402 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62403 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62404 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62405 +#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)
62406 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62407 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62408 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62409 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62410 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62411 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62412 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62413 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62414 +#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)
62415 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62416 +
62417 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62418 +
62419 +#endif
62420 +
62421 +#endif
62422 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62423 new file mode 100644
62424 index 0000000..54f4e85
62425 --- /dev/null
62426 +++ b/include/linux/grmsg.h
62427 @@ -0,0 +1,110 @@
62428 +#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"
62429 +#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"
62430 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62431 +#define GR_STOPMOD_MSG "denied modification of module state by "
62432 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62433 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62434 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62435 +#define GR_IOPL_MSG "denied use of iopl() by "
62436 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62437 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62438 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62439 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62440 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62441 +#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"
62442 +#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"
62443 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62444 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62445 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62446 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62447 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62448 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62449 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62450 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62451 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62452 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62453 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62454 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62455 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62456 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62457 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62458 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62459 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62460 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62461 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62462 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62463 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62464 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62465 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62466 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62467 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62468 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62469 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62470 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62471 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62472 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62473 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62474 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62475 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62476 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62477 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62478 +#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"
62479 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62480 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62481 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62482 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62483 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62484 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62485 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62486 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62487 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62488 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62489 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62490 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62491 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62492 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62493 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62494 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62495 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62496 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62497 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62498 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62499 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62500 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62501 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62502 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62503 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62504 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62505 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62506 +#define GR_TIME_MSG "time set by "
62507 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62508 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62509 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62510 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62511 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62512 +#define GR_BIND_MSG "denied bind() by "
62513 +#define GR_CONNECT_MSG "denied connect() by "
62514 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62515 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62516 +#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"
62517 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62518 +#define GR_CAP_ACL_MSG "use of %s denied for "
62519 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62520 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62521 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62522 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62523 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62524 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62525 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62526 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62527 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62528 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62529 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62530 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62531 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62532 +#define GR_VM86_MSG "denied use of vm86 by "
62533 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62534 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62535 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62536 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62537 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62538 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62539 new file mode 100644
62540 index 0000000..f9b9a21
62541 --- /dev/null
62542 +++ b/include/linux/grsecurity.h
62543 @@ -0,0 +1,238 @@
62544 +#ifndef GR_SECURITY_H
62545 +#define GR_SECURITY_H
62546 +#include <linux/fs.h>
62547 +#include <linux/fs_struct.h>
62548 +#include <linux/binfmts.h>
62549 +#include <linux/gracl.h>
62550 +
62551 +/* notify of brain-dead configs */
62552 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62553 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62554 +#endif
62555 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62556 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62557 +#endif
62558 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62559 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62560 +#endif
62561 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62562 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62563 +#endif
62564 +
62565 +#include <linux/compat.h>
62566 +
62567 +struct user_arg_ptr {
62568 +#ifdef CONFIG_COMPAT
62569 + bool is_compat;
62570 +#endif
62571 + union {
62572 + const char __user *const __user *native;
62573 +#ifdef CONFIG_COMPAT
62574 + compat_uptr_t __user *compat;
62575 +#endif
62576 + } ptr;
62577 +};
62578 +
62579 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62580 +void gr_handle_brute_check(void);
62581 +void gr_handle_kernel_exploit(void);
62582 +int gr_process_user_ban(void);
62583 +
62584 +char gr_roletype_to_char(void);
62585 +
62586 +int gr_acl_enable_at_secure(void);
62587 +
62588 +int gr_check_user_change(int real, int effective, int fs);
62589 +int gr_check_group_change(int real, int effective, int fs);
62590 +
62591 +void gr_del_task_from_ip_table(struct task_struct *p);
62592 +
62593 +int gr_pid_is_chrooted(struct task_struct *p);
62594 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62595 +int gr_handle_chroot_nice(void);
62596 +int gr_handle_chroot_sysctl(const int op);
62597 +int gr_handle_chroot_setpriority(struct task_struct *p,
62598 + const int niceval);
62599 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62600 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62601 + const struct vfsmount *mnt);
62602 +void gr_handle_chroot_chdir(struct path *path);
62603 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62604 + const struct vfsmount *mnt, const int mode);
62605 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62606 + const struct vfsmount *mnt, const int mode);
62607 +int gr_handle_chroot_mount(const struct dentry *dentry,
62608 + const struct vfsmount *mnt,
62609 + const char *dev_name);
62610 +int gr_handle_chroot_pivot(void);
62611 +int gr_handle_chroot_unix(const pid_t pid);
62612 +
62613 +int gr_handle_rawio(const struct inode *inode);
62614 +
62615 +void gr_handle_ioperm(void);
62616 +void gr_handle_iopl(void);
62617 +
62618 +umode_t gr_acl_umask(void);
62619 +
62620 +int gr_tpe_allow(const struct file *file);
62621 +
62622 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62623 +void gr_clear_chroot_entries(struct task_struct *task);
62624 +
62625 +void gr_log_forkfail(const int retval);
62626 +void gr_log_timechange(void);
62627 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62628 +void gr_log_chdir(const struct dentry *dentry,
62629 + const struct vfsmount *mnt);
62630 +void gr_log_chroot_exec(const struct dentry *dentry,
62631 + const struct vfsmount *mnt);
62632 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62633 +void gr_log_remount(const char *devname, const int retval);
62634 +void gr_log_unmount(const char *devname, const int retval);
62635 +void gr_log_mount(const char *from, const char *to, const int retval);
62636 +void gr_log_textrel(struct vm_area_struct *vma);
62637 +void gr_log_rwxmmap(struct file *file);
62638 +void gr_log_rwxmprotect(struct file *file);
62639 +
62640 +int gr_handle_follow_link(const struct inode *parent,
62641 + const struct inode *inode,
62642 + const struct dentry *dentry,
62643 + const struct vfsmount *mnt);
62644 +int gr_handle_fifo(const struct dentry *dentry,
62645 + const struct vfsmount *mnt,
62646 + const struct dentry *dir, const int flag,
62647 + const int acc_mode);
62648 +int gr_handle_hardlink(const struct dentry *dentry,
62649 + const struct vfsmount *mnt,
62650 + struct inode *inode,
62651 + const int mode, const char *to);
62652 +
62653 +int gr_is_capable(const int cap);
62654 +int gr_is_capable_nolog(const int cap);
62655 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62656 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62657 +
62658 +void gr_learn_resource(const struct task_struct *task, const int limit,
62659 + const unsigned long wanted, const int gt);
62660 +void gr_copy_label(struct task_struct *tsk);
62661 +void gr_handle_crash(struct task_struct *task, const int sig);
62662 +int gr_handle_signal(const struct task_struct *p, const int sig);
62663 +int gr_check_crash_uid(const uid_t uid);
62664 +int gr_check_protected_task(const struct task_struct *task);
62665 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62666 +int gr_acl_handle_mmap(const struct file *file,
62667 + const unsigned long prot);
62668 +int gr_acl_handle_mprotect(const struct file *file,
62669 + const unsigned long prot);
62670 +int gr_check_hidden_task(const struct task_struct *tsk);
62671 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62672 + const struct vfsmount *mnt);
62673 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62674 + const struct vfsmount *mnt);
62675 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62676 + const struct vfsmount *mnt, const int fmode);
62677 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62678 + const struct vfsmount *mnt, umode_t *mode);
62679 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62680 + const struct vfsmount *mnt);
62681 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62682 + const struct vfsmount *mnt);
62683 +int gr_handle_ptrace(struct task_struct *task, const long request);
62684 +int gr_handle_proc_ptrace(struct task_struct *task);
62685 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62686 + const struct vfsmount *mnt);
62687 +int gr_check_crash_exec(const struct file *filp);
62688 +int gr_acl_is_enabled(void);
62689 +void gr_set_kernel_label(struct task_struct *task);
62690 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62691 + const gid_t gid);
62692 +int gr_set_proc_label(const struct dentry *dentry,
62693 + const struct vfsmount *mnt,
62694 + const int unsafe_flags);
62695 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62696 + const struct vfsmount *mnt);
62697 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62698 + const struct vfsmount *mnt, int acc_mode);
62699 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62700 + const struct dentry *p_dentry,
62701 + const struct vfsmount *p_mnt,
62702 + int open_flags, int acc_mode, const int imode);
62703 +void gr_handle_create(const struct dentry *dentry,
62704 + const struct vfsmount *mnt);
62705 +void gr_handle_proc_create(const struct dentry *dentry,
62706 + const struct inode *inode);
62707 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62708 + const struct dentry *parent_dentry,
62709 + const struct vfsmount *parent_mnt,
62710 + const int mode);
62711 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62712 + const struct dentry *parent_dentry,
62713 + const struct vfsmount *parent_mnt);
62714 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62715 + const struct vfsmount *mnt);
62716 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62717 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62718 + const struct vfsmount *mnt);
62719 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62720 + const struct dentry *parent_dentry,
62721 + const struct vfsmount *parent_mnt,
62722 + const char *from);
62723 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62724 + const struct dentry *parent_dentry,
62725 + const struct vfsmount *parent_mnt,
62726 + const struct dentry *old_dentry,
62727 + const struct vfsmount *old_mnt, const char *to);
62728 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62729 +int gr_acl_handle_rename(struct dentry *new_dentry,
62730 + struct dentry *parent_dentry,
62731 + const struct vfsmount *parent_mnt,
62732 + struct dentry *old_dentry,
62733 + struct inode *old_parent_inode,
62734 + struct vfsmount *old_mnt, const char *newname);
62735 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62736 + struct dentry *old_dentry,
62737 + struct dentry *new_dentry,
62738 + struct vfsmount *mnt, const __u8 replace);
62739 +__u32 gr_check_link(const struct dentry *new_dentry,
62740 + const struct dentry *parent_dentry,
62741 + const struct vfsmount *parent_mnt,
62742 + const struct dentry *old_dentry,
62743 + const struct vfsmount *old_mnt);
62744 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62745 + const unsigned int namelen, const ino_t ino);
62746 +
62747 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62748 + const struct vfsmount *mnt);
62749 +void gr_acl_handle_exit(void);
62750 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62751 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62752 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62753 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62754 +void gr_audit_ptrace(struct task_struct *task);
62755 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62756 +
62757 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62758 +
62759 +#ifdef CONFIG_GRKERNSEC
62760 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62761 +void gr_handle_vm86(void);
62762 +void gr_handle_mem_readwrite(u64 from, u64 to);
62763 +
62764 +void gr_log_badprocpid(const char *entry);
62765 +
62766 +extern int grsec_enable_dmesg;
62767 +extern int grsec_disable_privio;
62768 +
62769 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62770 +extern int grsec_proc_gid;
62771 +#endif
62772 +
62773 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62774 +extern int grsec_enable_chroot_findtask;
62775 +#endif
62776 +#ifdef CONFIG_GRKERNSEC_SETXID
62777 +extern int grsec_enable_setxid;
62778 +#endif
62779 +#endif
62780 +
62781 +#endif
62782 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62783 new file mode 100644
62784 index 0000000..e7ffaaf
62785 --- /dev/null
62786 +++ b/include/linux/grsock.h
62787 @@ -0,0 +1,19 @@
62788 +#ifndef __GRSOCK_H
62789 +#define __GRSOCK_H
62790 +
62791 +extern void gr_attach_curr_ip(const struct sock *sk);
62792 +extern int gr_handle_sock_all(const int family, const int type,
62793 + const int protocol);
62794 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62795 +extern int gr_handle_sock_server_other(const struct sock *sck);
62796 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62797 +extern int gr_search_connect(struct socket * sock,
62798 + struct sockaddr_in * addr);
62799 +extern int gr_search_bind(struct socket * sock,
62800 + struct sockaddr_in * addr);
62801 +extern int gr_search_listen(struct socket * sock);
62802 +extern int gr_search_accept(struct socket * sock);
62803 +extern int gr_search_socket(const int domain, const int type,
62804 + const int protocol);
62805 +
62806 +#endif
62807 diff --git a/include/linux/hid.h b/include/linux/hid.h
62808 index 42970de..5db3c92 100644
62809 --- a/include/linux/hid.h
62810 +++ b/include/linux/hid.h
62811 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62812 unsigned int code, int value);
62813
62814 int (*parse)(struct hid_device *hdev);
62815 -};
62816 +} __no_const;
62817
62818 #define PM_HINT_FULLON 1<<5
62819 #define PM_HINT_NORMAL 1<<1
62820 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62821 index ef788b5..ac41b7b 100644
62822 --- a/include/linux/highmem.h
62823 +++ b/include/linux/highmem.h
62824 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62825 kunmap_atomic(kaddr);
62826 }
62827
62828 +static inline void sanitize_highpage(struct page *page)
62829 +{
62830 + void *kaddr;
62831 + unsigned long flags;
62832 +
62833 + local_irq_save(flags);
62834 + kaddr = kmap_atomic(page);
62835 + clear_page(kaddr);
62836 + kunmap_atomic(kaddr);
62837 + local_irq_restore(flags);
62838 +}
62839 +
62840 static inline void zero_user_segments(struct page *page,
62841 unsigned start1, unsigned end1,
62842 unsigned start2, unsigned end2)
62843 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62844 index 5970266..1c48c3b 100644
62845 --- a/include/linux/i2c.h
62846 +++ b/include/linux/i2c.h
62847 @@ -369,6 +369,7 @@ struct i2c_algorithm {
62848 /* To determine what the adapter supports */
62849 u32 (*functionality) (struct i2c_adapter *);
62850 };
62851 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62852
62853 /*
62854 * i2c_adapter is the structure used to identify a physical i2c bus along
62855 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62856 index d23c3c2..eb63c81 100644
62857 --- a/include/linux/i2o.h
62858 +++ b/include/linux/i2o.h
62859 @@ -565,7 +565,7 @@ struct i2o_controller {
62860 struct i2o_device *exec; /* Executive */
62861 #if BITS_PER_LONG == 64
62862 spinlock_t context_list_lock; /* lock for context_list */
62863 - atomic_t context_list_counter; /* needed for unique contexts */
62864 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62865 struct list_head context_list; /* list of context id's
62866 and pointers */
62867 #endif
62868 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62869 index aa2e167..84024ce 100644
62870 --- a/include/linux/if_team.h
62871 +++ b/include/linux/if_team.h
62872 @@ -109,6 +109,7 @@ struct team_mode_ops {
62873 void (*port_enabled)(struct team *team, struct team_port *port);
62874 void (*port_disabled)(struct team *team, struct team_port *port);
62875 };
62876 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62877
62878 enum team_option_type {
62879 TEAM_OPTION_TYPE_U32,
62880 @@ -181,7 +182,7 @@ struct team {
62881 struct list_head option_inst_list; /* list of option instances */
62882
62883 const struct team_mode *mode;
62884 - struct team_mode_ops ops;
62885 + team_mode_ops_no_const ops;
62886 long mode_priv[TEAM_MODE_PRIV_LONGS];
62887 };
62888
62889 diff --git a/include/linux/init.h b/include/linux/init.h
62890 index 5e664f6..0a1225c 100644
62891 --- a/include/linux/init.h
62892 +++ b/include/linux/init.h
62893 @@ -39,9 +39,15 @@
62894 * Also note, that this data cannot be "const".
62895 */
62896
62897 +#ifdef MODULE
62898 +#define add_latent_entropy
62899 +#else
62900 +#define add_latent_entropy __latent_entropy
62901 +#endif
62902 +
62903 /* These are for everybody (although not all archs will actually
62904 discard it in modules) */
62905 -#define __init __section(.init.text) __cold notrace
62906 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62907 #define __initdata __section(.init.data)
62908 #define __initconst __section(.init.rodata)
62909 #define __exitdata __section(.exit.data)
62910 @@ -83,7 +89,7 @@
62911 #define __exit __section(.exit.text) __exitused __cold notrace
62912
62913 /* Used for HOTPLUG */
62914 -#define __devinit __section(.devinit.text) __cold notrace
62915 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62916 #define __devinitdata __section(.devinit.data)
62917 #define __devinitconst __section(.devinit.rodata)
62918 #define __devexit __section(.devexit.text) __exitused __cold notrace
62919 @@ -91,7 +97,7 @@
62920 #define __devexitconst __section(.devexit.rodata)
62921
62922 /* Used for HOTPLUG_CPU */
62923 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62924 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62925 #define __cpuinitdata __section(.cpuinit.data)
62926 #define __cpuinitconst __section(.cpuinit.rodata)
62927 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62928 @@ -99,7 +105,7 @@
62929 #define __cpuexitconst __section(.cpuexit.rodata)
62930
62931 /* Used for MEMORY_HOTPLUG */
62932 -#define __meminit __section(.meminit.text) __cold notrace
62933 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62934 #define __meminitdata __section(.meminit.data)
62935 #define __meminitconst __section(.meminit.rodata)
62936 #define __memexit __section(.memexit.text) __exitused __cold notrace
62937 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62938 index 89f1cb1..7986c0f 100644
62939 --- a/include/linux/init_task.h
62940 +++ b/include/linux/init_task.h
62941 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62942
62943 #define INIT_TASK_COMM "swapper"
62944
62945 +#ifdef CONFIG_X86
62946 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62947 +#else
62948 +#define INIT_TASK_THREAD_INFO
62949 +#endif
62950 +
62951 /*
62952 * INIT_TASK is used to set up the first task table, touch at
62953 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62954 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62955 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62956 .comm = INIT_TASK_COMM, \
62957 .thread = INIT_THREAD, \
62958 + INIT_TASK_THREAD_INFO \
62959 .fs = &init_fs, \
62960 .files = &init_files, \
62961 .signal = &init_signals, \
62962 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62963 index 78e2ada..745564d 100644
62964 --- a/include/linux/intel-iommu.h
62965 +++ b/include/linux/intel-iommu.h
62966 @@ -296,7 +296,7 @@ struct iommu_flush {
62967 u8 fm, u64 type);
62968 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62969 unsigned int size_order, u64 type);
62970 -};
62971 +} __no_const;
62972
62973 enum {
62974 SR_DMAR_FECTL_REG,
62975 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62976 index c5f856a..d29c117 100644
62977 --- a/include/linux/interrupt.h
62978 +++ b/include/linux/interrupt.h
62979 @@ -433,7 +433,7 @@ enum
62980 /* map softirq index to softirq name. update 'softirq_to_name' in
62981 * kernel/softirq.c when adding a new softirq.
62982 */
62983 -extern char *softirq_to_name[NR_SOFTIRQS];
62984 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62985
62986 /* softirq mask and active fields moved to irq_cpustat_t in
62987 * asm/hardirq.h to get better cache usage. KAO
62988 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62989
62990 struct softirq_action
62991 {
62992 - void (*action)(struct softirq_action *);
62993 + void (*action)(void);
62994 };
62995
62996 asmlinkage void do_softirq(void);
62997 asmlinkage void __do_softirq(void);
62998 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62999 +extern void open_softirq(int nr, void (*action)(void));
63000 extern void softirq_init(void);
63001 extern void __raise_softirq_irqoff(unsigned int nr);
63002
63003 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63004 index 6883e19..06992b1 100644
63005 --- a/include/linux/kallsyms.h
63006 +++ b/include/linux/kallsyms.h
63007 @@ -15,7 +15,8 @@
63008
63009 struct module;
63010
63011 -#ifdef CONFIG_KALLSYMS
63012 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63013 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63014 /* Lookup the address for a symbol. Returns 0 if not found. */
63015 unsigned long kallsyms_lookup_name(const char *name);
63016
63017 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63018 /* Stupid that this does nothing, but I didn't create this mess. */
63019 #define __print_symbol(fmt, addr)
63020 #endif /*CONFIG_KALLSYMS*/
63021 +#else /* when included by kallsyms.c, vsnprintf.c, or
63022 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63023 +extern void __print_symbol(const char *fmt, unsigned long address);
63024 +extern int sprint_backtrace(char *buffer, unsigned long address);
63025 +extern int sprint_symbol(char *buffer, unsigned long address);
63026 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63027 +const char *kallsyms_lookup(unsigned long addr,
63028 + unsigned long *symbolsize,
63029 + unsigned long *offset,
63030 + char **modname, char *namebuf);
63031 +#endif
63032
63033 /* This macro allows us to keep printk typechecking */
63034 static __printf(1, 2)
63035 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63036 index c4d2fc1..5df9c19 100644
63037 --- a/include/linux/kgdb.h
63038 +++ b/include/linux/kgdb.h
63039 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63040 extern int kgdb_io_module_registered;
63041
63042 extern atomic_t kgdb_setting_breakpoint;
63043 -extern atomic_t kgdb_cpu_doing_single_step;
63044 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63045
63046 extern struct task_struct *kgdb_usethread;
63047 extern struct task_struct *kgdb_contthread;
63048 @@ -252,7 +252,7 @@ struct kgdb_arch {
63049 void (*disable_hw_break)(struct pt_regs *regs);
63050 void (*remove_all_hw_break)(void);
63051 void (*correct_hw_break)(void);
63052 -};
63053 +} __do_const;
63054
63055 /**
63056 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63057 @@ -277,7 +277,7 @@ struct kgdb_io {
63058 void (*pre_exception) (void);
63059 void (*post_exception) (void);
63060 int is_console;
63061 -};
63062 +} __do_const;
63063
63064 extern struct kgdb_arch arch_kgdb_ops;
63065
63066 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63067 index 5398d58..5883a34 100644
63068 --- a/include/linux/kmod.h
63069 +++ b/include/linux/kmod.h
63070 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63071 * usually useless though. */
63072 extern __printf(2, 3)
63073 int __request_module(bool wait, const char *name, ...);
63074 +extern __printf(3, 4)
63075 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63076 #define request_module(mod...) __request_module(true, mod)
63077 #define request_module_nowait(mod...) __request_module(false, mod)
63078 #define try_then_request_module(x, mod...) \
63079 diff --git a/include/linux/kref.h b/include/linux/kref.h
63080 index 65af688..0592677 100644
63081 --- a/include/linux/kref.h
63082 +++ b/include/linux/kref.h
63083 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63084 static inline int kref_sub(struct kref *kref, unsigned int count,
63085 void (*release)(struct kref *kref))
63086 {
63087 - WARN_ON(release == NULL);
63088 + BUG_ON(release == NULL);
63089
63090 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63091 release(kref);
63092 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63093 index b70b48b..0d7153b 100644
63094 --- a/include/linux/kvm_host.h
63095 +++ b/include/linux/kvm_host.h
63096 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63097 void vcpu_load(struct kvm_vcpu *vcpu);
63098 void vcpu_put(struct kvm_vcpu *vcpu);
63099
63100 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63101 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63102 struct module *module);
63103 void kvm_exit(void);
63104
63105 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63106 struct kvm_guest_debug *dbg);
63107 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63108
63109 -int kvm_arch_init(void *opaque);
63110 +int kvm_arch_init(const void *opaque);
63111 void kvm_arch_exit(void);
63112
63113 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63114 diff --git a/include/linux/libata.h b/include/linux/libata.h
63115 index 64f90e1..32b945b 100644
63116 --- a/include/linux/libata.h
63117 +++ b/include/linux/libata.h
63118 @@ -909,7 +909,7 @@ struct ata_port_operations {
63119 * fields must be pointers.
63120 */
63121 const struct ata_port_operations *inherits;
63122 -};
63123 +} __do_const;
63124
63125 struct ata_port_info {
63126 unsigned long flags;
63127 diff --git a/include/linux/memory.h b/include/linux/memory.h
63128 index ff9a9f8..c715deb 100644
63129 --- a/include/linux/memory.h
63130 +++ b/include/linux/memory.h
63131 @@ -143,7 +143,7 @@ struct memory_accessor {
63132 size_t count);
63133 ssize_t (*write)(struct memory_accessor *, const char *buf,
63134 off_t offset, size_t count);
63135 -};
63136 +} __no_const;
63137
63138 /*
63139 * Kernel text modification mutex, used for code patching. Users of this lock
63140 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63141 index 1318ca6..7521340 100644
63142 --- a/include/linux/mfd/abx500.h
63143 +++ b/include/linux/mfd/abx500.h
63144 @@ -452,6 +452,7 @@ struct abx500_ops {
63145 int (*event_registers_startup_state_get) (struct device *, u8 *);
63146 int (*startup_irq_enabled) (struct device *, unsigned int);
63147 };
63148 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63149
63150 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63151 void abx500_remove_ops(struct device *dev);
63152 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63153 index 9b07725..3d55001 100644
63154 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63155 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63156 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63157 int (*enable) (struct ux500_charger *, int, int, int);
63158 int (*kick_wd) (struct ux500_charger *);
63159 int (*update_curr) (struct ux500_charger *, int);
63160 -};
63161 +} __no_const;
63162
63163 /**
63164 * struct ux500_charger - power supply ux500 charger sub class
63165 diff --git a/include/linux/mm.h b/include/linux/mm.h
63166 index 311be90..5f1638c 100644
63167 --- a/include/linux/mm.h
63168 +++ b/include/linux/mm.h
63169 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63170
63171 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63172 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63173 +
63174 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63175 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63176 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63177 +#else
63178 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63179 +#endif
63180 +
63181 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63182 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63183
63184 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63185 int set_page_dirty_lock(struct page *page);
63186 int clear_page_dirty_for_io(struct page *page);
63187
63188 -/* Is the vma a continuation of the stack vma above it? */
63189 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63190 -{
63191 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63192 -}
63193 -
63194 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63195 - unsigned long addr)
63196 -{
63197 - return (vma->vm_flags & VM_GROWSDOWN) &&
63198 - (vma->vm_start == addr) &&
63199 - !vma_growsdown(vma->vm_prev, addr);
63200 -}
63201 -
63202 -/* Is the vma a continuation of the stack vma below it? */
63203 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63204 -{
63205 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63206 -}
63207 -
63208 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63209 - unsigned long addr)
63210 -{
63211 - return (vma->vm_flags & VM_GROWSUP) &&
63212 - (vma->vm_end == addr) &&
63213 - !vma_growsup(vma->vm_next, addr);
63214 -}
63215 -
63216 extern pid_t
63217 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63218
63219 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63220 }
63221 #endif
63222
63223 +#ifdef CONFIG_MMU
63224 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63225 +#else
63226 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63227 +{
63228 + return __pgprot(0);
63229 +}
63230 +#endif
63231 +
63232 int vma_wants_writenotify(struct vm_area_struct *vma);
63233
63234 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63235 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63236 {
63237 return 0;
63238 }
63239 +
63240 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63241 + unsigned long address)
63242 +{
63243 + return 0;
63244 +}
63245 #else
63246 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63247 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63248 #endif
63249
63250 #ifdef __PAGETABLE_PMD_FOLDED
63251 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63252 {
63253 return 0;
63254 }
63255 +
63256 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63257 + unsigned long address)
63258 +{
63259 + return 0;
63260 +}
63261 #else
63262 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63263 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63264 #endif
63265
63266 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63267 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63268 NULL: pud_offset(pgd, address);
63269 }
63270
63271 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63272 +{
63273 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63274 + NULL: pud_offset(pgd, address);
63275 +}
63276 +
63277 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63278 {
63279 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63280 NULL: pmd_offset(pud, address);
63281 }
63282 +
63283 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63284 +{
63285 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63286 + NULL: pmd_offset(pud, address);
63287 +}
63288 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63289
63290 #if USE_SPLIT_PTLOCKS
63291 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63292 unsigned long, unsigned long,
63293 unsigned long, unsigned long);
63294 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63295 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63296
63297 /* These take the mm semaphore themselves */
63298 extern unsigned long vm_brk(unsigned long, unsigned long);
63299 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63300 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63301 struct vm_area_struct **pprev);
63302
63303 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63304 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63305 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63306 +
63307 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63308 NULL if none. Assume start_addr < end_addr. */
63309 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63310 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63311 return vma;
63312 }
63313
63314 -#ifdef CONFIG_MMU
63315 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63316 -#else
63317 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63318 -{
63319 - return __pgprot(0);
63320 -}
63321 -#endif
63322 -
63323 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63324 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63325 unsigned long pfn, unsigned long size, pgprot_t);
63326 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63327 extern int sysctl_memory_failure_early_kill;
63328 extern int sysctl_memory_failure_recovery;
63329 extern void shake_page(struct page *p, int access);
63330 -extern atomic_long_t mce_bad_pages;
63331 +extern atomic_long_unchecked_t mce_bad_pages;
63332 extern int soft_offline_page(struct page *page, int flags);
63333
63334 extern void dump_page(struct page *page);
63335 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63336 static inline bool page_is_guard(struct page *page) { return false; }
63337 #endif /* CONFIG_DEBUG_PAGEALLOC */
63338
63339 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63340 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63341 +#else
63342 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63343 +#endif
63344 +
63345 #endif /* __KERNEL__ */
63346 #endif /* _LINUX_MM_H */
63347 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63348 index bf78672..debc693 100644
63349 --- a/include/linux/mm_types.h
63350 +++ b/include/linux/mm_types.h
63351 @@ -279,6 +279,8 @@ struct vm_area_struct {
63352 #ifdef CONFIG_NUMA
63353 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63354 #endif
63355 +
63356 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63357 };
63358
63359 struct core_thread {
63360 @@ -353,7 +355,7 @@ struct mm_struct {
63361 unsigned long def_flags;
63362 unsigned long nr_ptes; /* Page table pages */
63363 unsigned long start_code, end_code, start_data, end_data;
63364 - unsigned long start_brk, brk, start_stack;
63365 + unsigned long brk_gap, start_brk, brk, start_stack;
63366 unsigned long arg_start, arg_end, env_start, env_end;
63367
63368 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63369 @@ -405,6 +407,24 @@ struct mm_struct {
63370 struct cpumask cpumask_allocation;
63371 #endif
63372 struct uprobes_state uprobes_state;
63373 +
63374 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63375 + unsigned long pax_flags;
63376 +#endif
63377 +
63378 +#ifdef CONFIG_PAX_DLRESOLVE
63379 + unsigned long call_dl_resolve;
63380 +#endif
63381 +
63382 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63383 + unsigned long call_syscall;
63384 +#endif
63385 +
63386 +#ifdef CONFIG_PAX_ASLR
63387 + unsigned long delta_mmap; /* randomized offset */
63388 + unsigned long delta_stack; /* randomized offset */
63389 +#endif
63390 +
63391 };
63392
63393 static inline void mm_init_cpumask(struct mm_struct *mm)
63394 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63395 index 1d1b1e1..2a13c78 100644
63396 --- a/include/linux/mmu_notifier.h
63397 +++ b/include/linux/mmu_notifier.h
63398 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63399 */
63400 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63401 ({ \
63402 - pte_t __pte; \
63403 + pte_t ___pte; \
63404 struct vm_area_struct *___vma = __vma; \
63405 unsigned long ___address = __address; \
63406 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63407 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63408 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63409 - __pte; \
63410 + ___pte; \
63411 })
63412
63413 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63414 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63415 index 2daa54f..bfdf2f5 100644
63416 --- a/include/linux/mmzone.h
63417 +++ b/include/linux/mmzone.h
63418 @@ -414,7 +414,7 @@ struct zone {
63419 unsigned long flags; /* zone flags, see below */
63420
63421 /* Zone statistics */
63422 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63423 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63424
63425 /*
63426 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63427 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63428 index 6955045..ebdb7cd 100644
63429 --- a/include/linux/mod_devicetable.h
63430 +++ b/include/linux/mod_devicetable.h
63431 @@ -12,7 +12,7 @@
63432 typedef unsigned long kernel_ulong_t;
63433 #endif
63434
63435 -#define PCI_ANY_ID (~0)
63436 +#define PCI_ANY_ID ((__u16)~0)
63437
63438 struct pci_device_id {
63439 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63440 @@ -139,7 +139,7 @@ struct usb_device_id {
63441 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63442 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63443
63444 -#define HID_ANY_ID (~0)
63445 +#define HID_ANY_ID (~0U)
63446 #define HID_BUS_ANY 0xffff
63447 #define HID_GROUP_ANY 0x0000
63448
63449 diff --git a/include/linux/module.h b/include/linux/module.h
63450 index fbcafe2..e5d9587 100644
63451 --- a/include/linux/module.h
63452 +++ b/include/linux/module.h
63453 @@ -17,6 +17,7 @@
63454 #include <linux/moduleparam.h>
63455 #include <linux/tracepoint.h>
63456 #include <linux/export.h>
63457 +#include <linux/fs.h>
63458
63459 #include <linux/percpu.h>
63460 #include <asm/module.h>
63461 @@ -273,19 +274,16 @@ struct module
63462 int (*init)(void);
63463
63464 /* If this is non-NULL, vfree after init() returns */
63465 - void *module_init;
63466 + void *module_init_rx, *module_init_rw;
63467
63468 /* Here is the actual code + data, vfree'd on unload. */
63469 - void *module_core;
63470 + void *module_core_rx, *module_core_rw;
63471
63472 /* Here are the sizes of the init and core sections */
63473 - unsigned int init_size, core_size;
63474 + unsigned int init_size_rw, core_size_rw;
63475
63476 /* The size of the executable code in each section. */
63477 - unsigned int init_text_size, core_text_size;
63478 -
63479 - /* Size of RO sections of the module (text+rodata) */
63480 - unsigned int init_ro_size, core_ro_size;
63481 + unsigned int init_size_rx, core_size_rx;
63482
63483 /* Arch-specific module values */
63484 struct mod_arch_specific arch;
63485 @@ -341,6 +339,10 @@ struct module
63486 #ifdef CONFIG_EVENT_TRACING
63487 struct ftrace_event_call **trace_events;
63488 unsigned int num_trace_events;
63489 + struct file_operations trace_id;
63490 + struct file_operations trace_enable;
63491 + struct file_operations trace_format;
63492 + struct file_operations trace_filter;
63493 #endif
63494 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63495 unsigned int num_ftrace_callsites;
63496 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63497 bool is_module_percpu_address(unsigned long addr);
63498 bool is_module_text_address(unsigned long addr);
63499
63500 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63501 +{
63502 +
63503 +#ifdef CONFIG_PAX_KERNEXEC
63504 + if (ktla_ktva(addr) >= (unsigned long)start &&
63505 + ktla_ktva(addr) < (unsigned long)start + size)
63506 + return 1;
63507 +#endif
63508 +
63509 + return ((void *)addr >= start && (void *)addr < start + size);
63510 +}
63511 +
63512 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63513 +{
63514 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63515 +}
63516 +
63517 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63518 +{
63519 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63520 +}
63521 +
63522 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63523 +{
63524 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63525 +}
63526 +
63527 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63528 +{
63529 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63530 +}
63531 +
63532 static inline int within_module_core(unsigned long addr, struct module *mod)
63533 {
63534 - return (unsigned long)mod->module_core <= addr &&
63535 - addr < (unsigned long)mod->module_core + mod->core_size;
63536 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63537 }
63538
63539 static inline int within_module_init(unsigned long addr, struct module *mod)
63540 {
63541 - return (unsigned long)mod->module_init <= addr &&
63542 - addr < (unsigned long)mod->module_init + mod->init_size;
63543 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63544 }
63545
63546 /* Search for module by name: must hold module_mutex. */
63547 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63548 index b2be02e..72d2f78 100644
63549 --- a/include/linux/moduleloader.h
63550 +++ b/include/linux/moduleloader.h
63551 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63552
63553 /* Allocator used for allocating struct module, core sections and init
63554 sections. Returns NULL on failure. */
63555 -void *module_alloc(unsigned long size);
63556 +void *module_alloc(unsigned long size) __size_overflow(1);
63557 +
63558 +#ifdef CONFIG_PAX_KERNEXEC
63559 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63560 +#else
63561 +#define module_alloc_exec(x) module_alloc(x)
63562 +#endif
63563
63564 /* Free memory returned from module_alloc. */
63565 void module_free(struct module *mod, void *module_region);
63566
63567 +#ifdef CONFIG_PAX_KERNEXEC
63568 +void module_free_exec(struct module *mod, void *module_region);
63569 +#else
63570 +#define module_free_exec(x, y) module_free((x), (y))
63571 +#endif
63572 +
63573 /* Apply the given relocation to the (simplified) ELF. Return -error
63574 or 0. */
63575 int apply_relocate(Elf_Shdr *sechdrs,
63576 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63577 index d6a5806..7c13347 100644
63578 --- a/include/linux/moduleparam.h
63579 +++ b/include/linux/moduleparam.h
63580 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63581 * @len is usually just sizeof(string).
63582 */
63583 #define module_param_string(name, string, len, perm) \
63584 - static const struct kparam_string __param_string_##name \
63585 + static const struct kparam_string __param_string_##name __used \
63586 = { len, string }; \
63587 __module_param_call(MODULE_PARAM_PREFIX, name, \
63588 &param_ops_string, \
63589 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63590 */
63591 #define module_param_array_named(name, array, type, nump, perm) \
63592 param_check_##type(name, &(array)[0]); \
63593 - static const struct kparam_array __param_arr_##name \
63594 + static const struct kparam_array __param_arr_##name __used \
63595 = { .max = ARRAY_SIZE(array), .num = nump, \
63596 .ops = &param_ops_##type, \
63597 .elemsize = sizeof(array[0]), .elem = array }; \
63598 diff --git a/include/linux/namei.h b/include/linux/namei.h
63599 index 4bf19d8..5268cea 100644
63600 --- a/include/linux/namei.h
63601 +++ b/include/linux/namei.h
63602 @@ -18,7 +18,7 @@ struct nameidata {
63603 unsigned seq;
63604 int last_type;
63605 unsigned depth;
63606 - char *saved_names[MAX_NESTED_LINKS + 1];
63607 + const char *saved_names[MAX_NESTED_LINKS + 1];
63608 };
63609
63610 /*
63611 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63612
63613 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63614
63615 -static inline void nd_set_link(struct nameidata *nd, char *path)
63616 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63617 {
63618 nd->saved_names[nd->depth] = path;
63619 }
63620
63621 -static inline char *nd_get_link(struct nameidata *nd)
63622 +static inline const char *nd_get_link(const struct nameidata *nd)
63623 {
63624 return nd->saved_names[nd->depth];
63625 }
63626 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63627 index 59dc05f3..c905a34 100644
63628 --- a/include/linux/netdevice.h
63629 +++ b/include/linux/netdevice.h
63630 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63631 struct net_device *dev,
63632 int idx);
63633 };
63634 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63635
63636 /*
63637 * The DEVICE structure.
63638 @@ -1087,7 +1088,7 @@ struct net_device {
63639 int iflink;
63640
63641 struct net_device_stats stats;
63642 - atomic_long_t rx_dropped; /* dropped packets by core network
63643 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63644 * Do not use this in drivers.
63645 */
63646
63647 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63648 new file mode 100644
63649 index 0000000..33f4af8
63650 --- /dev/null
63651 +++ b/include/linux/netfilter/xt_gradm.h
63652 @@ -0,0 +1,9 @@
63653 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63654 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63655 +
63656 +struct xt_gradm_mtinfo {
63657 + __u16 flags;
63658 + __u16 invflags;
63659 +};
63660 +
63661 +#endif
63662 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63663 index c65a18a..0c05f3a 100644
63664 --- a/include/linux/of_pdt.h
63665 +++ b/include/linux/of_pdt.h
63666 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63667
63668 /* return 0 on success; fill in 'len' with number of bytes in path */
63669 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63670 -};
63671 +} __no_const;
63672
63673 extern void *prom_early_alloc(unsigned long size);
63674
63675 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63676 index a4c5624..79d6d88 100644
63677 --- a/include/linux/oprofile.h
63678 +++ b/include/linux/oprofile.h
63679 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63680 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63681 char const * name, ulong * val);
63682
63683 -/** Create a file for read-only access to an atomic_t. */
63684 +/** Create a file for read-only access to an atomic_unchecked_t. */
63685 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63686 - char const * name, atomic_t * val);
63687 + char const * name, atomic_unchecked_t * val);
63688
63689 /** create a directory */
63690 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63691 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63692 index bdb4161..f373d41 100644
63693 --- a/include/linux/perf_event.h
63694 +++ b/include/linux/perf_event.h
63695 @@ -882,8 +882,8 @@ struct perf_event {
63696
63697 enum perf_event_active_state state;
63698 unsigned int attach_state;
63699 - local64_t count;
63700 - atomic64_t child_count;
63701 + local64_t count; /* PaX: fix it one day */
63702 + atomic64_unchecked_t child_count;
63703
63704 /*
63705 * These are the total time in nanoseconds that the event
63706 @@ -934,8 +934,8 @@ struct perf_event {
63707 * These accumulate total time (in nanoseconds) that children
63708 * events have been enabled and running, respectively.
63709 */
63710 - atomic64_t child_total_time_enabled;
63711 - atomic64_t child_total_time_running;
63712 + atomic64_unchecked_t child_total_time_enabled;
63713 + atomic64_unchecked_t child_total_time_running;
63714
63715 /*
63716 * Protect attach/detach and child_list:
63717 diff --git a/include/linux/personality.h b/include/linux/personality.h
63718 index 8fc7dd1a..c19d89e 100644
63719 --- a/include/linux/personality.h
63720 +++ b/include/linux/personality.h
63721 @@ -44,6 +44,7 @@ enum {
63722 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63723 ADDR_NO_RANDOMIZE | \
63724 ADDR_COMPAT_LAYOUT | \
63725 + ADDR_LIMIT_3GB | \
63726 MMAP_PAGE_ZERO)
63727
63728 /*
63729 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63730 index ad1a427..6419649 100644
63731 --- a/include/linux/pipe_fs_i.h
63732 +++ b/include/linux/pipe_fs_i.h
63733 @@ -45,9 +45,9 @@ struct pipe_buffer {
63734 struct pipe_inode_info {
63735 wait_queue_head_t wait;
63736 unsigned int nrbufs, curbuf, buffers;
63737 - unsigned int readers;
63738 - unsigned int writers;
63739 - unsigned int waiting_writers;
63740 + atomic_t readers;
63741 + atomic_t writers;
63742 + atomic_t waiting_writers;
63743 unsigned int r_counter;
63744 unsigned int w_counter;
63745 struct page *tmp_page;
63746 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63747 index f271860..6b3bec5 100644
63748 --- a/include/linux/pm_runtime.h
63749 +++ b/include/linux/pm_runtime.h
63750 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63751
63752 static inline void pm_runtime_mark_last_busy(struct device *dev)
63753 {
63754 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63755 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63756 }
63757
63758 #else /* !CONFIG_PM_RUNTIME */
63759 diff --git a/include/linux/poison.h b/include/linux/poison.h
63760 index 2110a81..13a11bb 100644
63761 --- a/include/linux/poison.h
63762 +++ b/include/linux/poison.h
63763 @@ -19,8 +19,8 @@
63764 * under normal circumstances, used to verify that nobody uses
63765 * non-initialized list entries.
63766 */
63767 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63768 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63769 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63770 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63771
63772 /********** include/linux/timer.h **********/
63773 /*
63774 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63775 index 5a710b9..0b0dab9 100644
63776 --- a/include/linux/preempt.h
63777 +++ b/include/linux/preempt.h
63778 @@ -126,7 +126,7 @@ struct preempt_ops {
63779 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63780 void (*sched_out)(struct preempt_notifier *notifier,
63781 struct task_struct *next);
63782 -};
63783 +} __no_const;
63784
63785 /**
63786 * preempt_notifier - key for installing preemption notifiers
63787 diff --git a/include/linux/printk.h b/include/linux/printk.h
63788 index 9afc01e..92c32e8 100644
63789 --- a/include/linux/printk.h
63790 +++ b/include/linux/printk.h
63791 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63792 extern int printk_needs_cpu(int cpu);
63793 extern void printk_tick(void);
63794
63795 +extern int kptr_restrict;
63796 +
63797 #ifdef CONFIG_PRINTK
63798 asmlinkage __printf(5, 0)
63799 int vprintk_emit(int facility, int level,
63800 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63801
63802 extern int printk_delay_msec;
63803 extern int dmesg_restrict;
63804 -extern int kptr_restrict;
63805
63806 void log_buf_kexec_setup(void);
63807 void __init setup_log_buf(int early);
63808 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63809 index 3fd2e87..d93a721 100644
63810 --- a/include/linux/proc_fs.h
63811 +++ b/include/linux/proc_fs.h
63812 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63813 return proc_create_data(name, mode, parent, proc_fops, NULL);
63814 }
63815
63816 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63817 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63818 +{
63819 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63820 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63821 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63822 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63823 +#else
63824 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63825 +#endif
63826 +}
63827 +
63828 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63829 umode_t mode, struct proc_dir_entry *base,
63830 read_proc_t *read_proc, void * data)
63831 @@ -258,7 +270,7 @@ union proc_op {
63832 int (*proc_show)(struct seq_file *m,
63833 struct pid_namespace *ns, struct pid *pid,
63834 struct task_struct *task);
63835 -};
63836 +} __no_const;
63837
63838 struct ctl_table_header;
63839 struct ctl_table;
63840 diff --git a/include/linux/random.h b/include/linux/random.h
63841 index ac621ce..c1215f3 100644
63842 --- a/include/linux/random.h
63843 +++ b/include/linux/random.h
63844 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63845 unsigned int value);
63846 extern void add_interrupt_randomness(int irq, int irq_flags);
63847
63848 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63849 +extern void transfer_latent_entropy(void);
63850 +#endif
63851 +
63852 extern void get_random_bytes(void *buf, int nbytes);
63853 extern void get_random_bytes_arch(void *buf, int nbytes);
63854 void generate_random_uuid(unsigned char uuid_out[16]);
63855 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63856
63857 u32 prandom32(struct rnd_state *);
63858
63859 +static inline unsigned long pax_get_random_long(void)
63860 +{
63861 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63862 +}
63863 +
63864 /*
63865 * Handle minimum values for seeds
63866 */
63867 static inline u32 __seed(u32 x, u32 m)
63868 {
63869 - return (x < m) ? x + m : x;
63870 + return (x <= m) ? x + m + 1 : x;
63871 }
63872
63873 /**
63874 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63875 index e0879a7..a12f962 100644
63876 --- a/include/linux/reboot.h
63877 +++ b/include/linux/reboot.h
63878 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63879 * Architecture-specific implementations of sys_reboot commands.
63880 */
63881
63882 -extern void machine_restart(char *cmd);
63883 -extern void machine_halt(void);
63884 -extern void machine_power_off(void);
63885 +extern void machine_restart(char *cmd) __noreturn;
63886 +extern void machine_halt(void) __noreturn;
63887 +extern void machine_power_off(void) __noreturn;
63888
63889 extern void machine_shutdown(void);
63890 struct pt_regs;
63891 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63892 */
63893
63894 extern void kernel_restart_prepare(char *cmd);
63895 -extern void kernel_restart(char *cmd);
63896 -extern void kernel_halt(void);
63897 -extern void kernel_power_off(void);
63898 +extern void kernel_restart(char *cmd) __noreturn;
63899 +extern void kernel_halt(void) __noreturn;
63900 +extern void kernel_power_off(void) __noreturn;
63901
63902 extern int C_A_D; /* for sysctl */
63903 void ctrl_alt_del(void);
63904 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63905 * Emergency restart, callable from an interrupt handler.
63906 */
63907
63908 -extern void emergency_restart(void);
63909 +extern void emergency_restart(void) __noreturn;
63910 #include <asm/emergency-restart.h>
63911
63912 #endif
63913 diff --git a/include/linux/relay.h b/include/linux/relay.h
63914 index 91cacc3..b55ff74 100644
63915 --- a/include/linux/relay.h
63916 +++ b/include/linux/relay.h
63917 @@ -160,7 +160,7 @@ struct rchan_callbacks
63918 * The callback should return 0 if successful, negative if not.
63919 */
63920 int (*remove_buf_file)(struct dentry *dentry);
63921 -};
63922 +} __no_const;
63923
63924 /*
63925 * CONFIG_RELAY kernel API, kernel/relay.c
63926 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63927 index 6fdf027..ff72610 100644
63928 --- a/include/linux/rfkill.h
63929 +++ b/include/linux/rfkill.h
63930 @@ -147,6 +147,7 @@ struct rfkill_ops {
63931 void (*query)(struct rfkill *rfkill, void *data);
63932 int (*set_block)(void *data, bool blocked);
63933 };
63934 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63935
63936 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63937 /**
63938 diff --git a/include/linux/rio.h b/include/linux/rio.h
63939 index a90ebad..fd87b5d 100644
63940 --- a/include/linux/rio.h
63941 +++ b/include/linux/rio.h
63942 @@ -321,7 +321,7 @@ struct rio_ops {
63943 int mbox, void *buffer, size_t len);
63944 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63945 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63946 -};
63947 +} __no_const;
63948
63949 #define RIO_RESOURCE_MEM 0x00000100
63950 #define RIO_RESOURCE_DOORBELL 0x00000200
63951 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63952 index 3fce545..b4fed6e 100644
63953 --- a/include/linux/rmap.h
63954 +++ b/include/linux/rmap.h
63955 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63956 void anon_vma_init(void); /* create anon_vma_cachep */
63957 int anon_vma_prepare(struct vm_area_struct *);
63958 void unlink_anon_vmas(struct vm_area_struct *);
63959 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63960 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63961 void anon_vma_moveto_tail(struct vm_area_struct *);
63962 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63963 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63964
63965 static inline void anon_vma_merge(struct vm_area_struct *vma,
63966 struct vm_area_struct *next)
63967 diff --git a/include/linux/sched.h b/include/linux/sched.h
63968 index 23bddac..5976055 100644
63969 --- a/include/linux/sched.h
63970 +++ b/include/linux/sched.h
63971 @@ -101,6 +101,7 @@ struct bio_list;
63972 struct fs_struct;
63973 struct perf_event_context;
63974 struct blk_plug;
63975 +struct linux_binprm;
63976
63977 /*
63978 * List of flags we want to share for kernel threads,
63979 @@ -384,10 +385,13 @@ struct user_namespace;
63980 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63981
63982 extern int sysctl_max_map_count;
63983 +extern unsigned long sysctl_heap_stack_gap;
63984
63985 #include <linux/aio.h>
63986
63987 #ifdef CONFIG_MMU
63988 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63989 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63990 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63991 extern unsigned long
63992 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63993 @@ -651,6 +655,17 @@ struct signal_struct {
63994 #ifdef CONFIG_TASKSTATS
63995 struct taskstats *stats;
63996 #endif
63997 +
63998 +#ifdef CONFIG_GRKERNSEC
63999 + u32 curr_ip;
64000 + u32 saved_ip;
64001 + u32 gr_saddr;
64002 + u32 gr_daddr;
64003 + u16 gr_sport;
64004 + u16 gr_dport;
64005 + u8 used_accept:1;
64006 +#endif
64007 +
64008 #ifdef CONFIG_AUDIT
64009 unsigned audit_tty;
64010 struct tty_audit_buf *tty_audit_buf;
64011 @@ -734,6 +749,11 @@ struct user_struct {
64012 struct key *session_keyring; /* UID's default session keyring */
64013 #endif
64014
64015 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64016 + unsigned int banned;
64017 + unsigned long ban_expires;
64018 +#endif
64019 +
64020 /* Hash table maintenance information */
64021 struct hlist_node uidhash_node;
64022 kuid_t uid;
64023 @@ -1356,8 +1376,8 @@ struct task_struct {
64024 struct list_head thread_group;
64025
64026 struct completion *vfork_done; /* for vfork() */
64027 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64028 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64029 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64030 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64031
64032 cputime_t utime, stime, utimescaled, stimescaled;
64033 cputime_t gtime;
64034 @@ -1373,11 +1393,6 @@ struct task_struct {
64035 struct task_cputime cputime_expires;
64036 struct list_head cpu_timers[3];
64037
64038 -/* process credentials */
64039 - const struct cred __rcu *real_cred; /* objective and real subjective task
64040 - * credentials (COW) */
64041 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64042 - * credentials (COW) */
64043 char comm[TASK_COMM_LEN]; /* executable name excluding path
64044 - access with [gs]et_task_comm (which lock
64045 it with task_lock())
64046 @@ -1394,6 +1409,10 @@ struct task_struct {
64047 #endif
64048 /* CPU-specific state of this task */
64049 struct thread_struct thread;
64050 +/* thread_info moved to task_struct */
64051 +#ifdef CONFIG_X86
64052 + struct thread_info tinfo;
64053 +#endif
64054 /* filesystem information */
64055 struct fs_struct *fs;
64056 /* open file information */
64057 @@ -1467,6 +1486,10 @@ struct task_struct {
64058 gfp_t lockdep_reclaim_gfp;
64059 #endif
64060
64061 +/* process credentials */
64062 + const struct cred __rcu *real_cred; /* objective and real subjective task
64063 + * credentials (COW) */
64064 +
64065 /* journalling filesystem info */
64066 void *journal_info;
64067
64068 @@ -1505,6 +1528,10 @@ struct task_struct {
64069 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64070 struct list_head cg_list;
64071 #endif
64072 +
64073 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64074 + * credentials (COW) */
64075 +
64076 #ifdef CONFIG_FUTEX
64077 struct robust_list_head __user *robust_list;
64078 #ifdef CONFIG_COMPAT
64079 @@ -1589,8 +1616,74 @@ struct task_struct {
64080 #ifdef CONFIG_UPROBES
64081 struct uprobe_task *utask;
64082 #endif
64083 +
64084 +#ifdef CONFIG_GRKERNSEC
64085 + /* grsecurity */
64086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64087 + u64 exec_id;
64088 +#endif
64089 +#ifdef CONFIG_GRKERNSEC_SETXID
64090 + const struct cred *delayed_cred;
64091 +#endif
64092 + struct dentry *gr_chroot_dentry;
64093 + struct acl_subject_label *acl;
64094 + struct acl_role_label *role;
64095 + struct file *exec_file;
64096 + u16 acl_role_id;
64097 + /* is this the task that authenticated to the special role */
64098 + u8 acl_sp_role;
64099 + u8 is_writable;
64100 + u8 brute;
64101 + u8 gr_is_chrooted;
64102 +#endif
64103 +
64104 };
64105
64106 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64107 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64108 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64109 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64110 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64111 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64112 +
64113 +#ifdef CONFIG_PAX_SOFTMODE
64114 +extern int pax_softmode;
64115 +#endif
64116 +
64117 +extern int pax_check_flags(unsigned long *);
64118 +
64119 +/* if tsk != current then task_lock must be held on it */
64120 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64121 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64122 +{
64123 + if (likely(tsk->mm))
64124 + return tsk->mm->pax_flags;
64125 + else
64126 + return 0UL;
64127 +}
64128 +
64129 +/* if tsk != current then task_lock must be held on it */
64130 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64131 +{
64132 + if (likely(tsk->mm)) {
64133 + tsk->mm->pax_flags = flags;
64134 + return 0;
64135 + }
64136 + return -EINVAL;
64137 +}
64138 +#endif
64139 +
64140 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64141 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64142 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64143 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64144 +#endif
64145 +
64146 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64147 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64148 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64149 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64150 +
64151 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64152 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64153
64154 @@ -2125,7 +2218,9 @@ void yield(void);
64155 extern struct exec_domain default_exec_domain;
64156
64157 union thread_union {
64158 +#ifndef CONFIG_X86
64159 struct thread_info thread_info;
64160 +#endif
64161 unsigned long stack[THREAD_SIZE/sizeof(long)];
64162 };
64163
64164 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64165 */
64166
64167 extern struct task_struct *find_task_by_vpid(pid_t nr);
64168 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64169 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64170 struct pid_namespace *ns);
64171
64172 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64173 extern void exit_itimers(struct signal_struct *);
64174 extern void flush_itimer_signals(void);
64175
64176 -extern void do_group_exit(int);
64177 +extern __noreturn void do_group_exit(int);
64178
64179 extern void daemonize(const char *, ...);
64180 extern int allow_signal(int);
64181 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64182
64183 #endif
64184
64185 -static inline int object_is_on_stack(void *obj)
64186 +static inline int object_starts_on_stack(void *obj)
64187 {
64188 - void *stack = task_stack_page(current);
64189 + const void *stack = task_stack_page(current);
64190
64191 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64192 }
64193 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64194 index 899fbb4..1cb4138 100644
64195 --- a/include/linux/screen_info.h
64196 +++ b/include/linux/screen_info.h
64197 @@ -43,7 +43,8 @@ struct screen_info {
64198 __u16 pages; /* 0x32 */
64199 __u16 vesa_attributes; /* 0x34 */
64200 __u32 capabilities; /* 0x36 */
64201 - __u8 _reserved[6]; /* 0x3a */
64202 + __u16 vesapm_size; /* 0x3a */
64203 + __u8 _reserved[4]; /* 0x3c */
64204 } __attribute__((packed));
64205
64206 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64207 diff --git a/include/linux/security.h b/include/linux/security.h
64208 index d143b8e..9f27b95 100644
64209 --- a/include/linux/security.h
64210 +++ b/include/linux/security.h
64211 @@ -26,6 +26,7 @@
64212 #include <linux/capability.h>
64213 #include <linux/slab.h>
64214 #include <linux/err.h>
64215 +#include <linux/grsecurity.h>
64216
64217 struct linux_binprm;
64218 struct cred;
64219 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64220 index 83c44ee..e8a9eba 100644
64221 --- a/include/linux/seq_file.h
64222 +++ b/include/linux/seq_file.h
64223 @@ -25,6 +25,9 @@ struct seq_file {
64224 struct mutex lock;
64225 const struct seq_operations *op;
64226 int poll_event;
64227 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64228 + u64 exec_id;
64229 +#endif
64230 void *private;
64231 };
64232
64233 @@ -34,6 +37,7 @@ struct seq_operations {
64234 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64235 int (*show) (struct seq_file *m, void *v);
64236 };
64237 +typedef struct seq_operations __no_const seq_operations_no_const;
64238
64239 #define SEQ_SKIP 1
64240
64241 diff --git a/include/linux/shm.h b/include/linux/shm.h
64242 index edd0868..f98feee 100644
64243 --- a/include/linux/shm.h
64244 +++ b/include/linux/shm.h
64245 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64246
64247 /* The task created the shm object. NULL if the task is dead. */
64248 struct task_struct *shm_creator;
64249 +#ifdef CONFIG_GRKERNSEC
64250 + time_t shm_createtime;
64251 + pid_t shm_lapid;
64252 +#endif
64253 };
64254
64255 /* shm_mode upper byte flags */
64256 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64257 index 7632c87..8fd660f 100644
64258 --- a/include/linux/skbuff.h
64259 +++ b/include/linux/skbuff.h
64260 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64261 extern struct sk_buff *__alloc_skb(unsigned int size,
64262 gfp_t priority, int flags, int node);
64263 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64264 -static inline struct sk_buff *alloc_skb(unsigned int size,
64265 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64266 gfp_t priority)
64267 {
64268 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64269 @@ -690,7 +690,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64270 */
64271 static inline int skb_queue_empty(const struct sk_buff_head *list)
64272 {
64273 - return list->next == (struct sk_buff *)list;
64274 + return list->next == (const struct sk_buff *)list;
64275 }
64276
64277 /**
64278 @@ -703,7 +703,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64279 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64280 const struct sk_buff *skb)
64281 {
64282 - return skb->next == (struct sk_buff *)list;
64283 + return skb->next == (const struct sk_buff *)list;
64284 }
64285
64286 /**
64287 @@ -716,7 +716,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64288 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64289 const struct sk_buff *skb)
64290 {
64291 - return skb->prev == (struct sk_buff *)list;
64292 + return skb->prev == (const struct sk_buff *)list;
64293 }
64294
64295 /**
64296 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64297 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64298 */
64299 #ifndef NET_SKB_PAD
64300 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64301 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64302 #endif
64303
64304 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64305 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64306 int noblock, int *err);
64307 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64308 struct poll_table_struct *wait);
64309 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64310 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64311 int offset, struct iovec *to,
64312 int size);
64313 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64314 diff --git a/include/linux/slab.h b/include/linux/slab.h
64315 index 0dd2dfa..2b8677c 100644
64316 --- a/include/linux/slab.h
64317 +++ b/include/linux/slab.h
64318 @@ -11,12 +11,20 @@
64319
64320 #include <linux/gfp.h>
64321 #include <linux/types.h>
64322 +#include <linux/err.h>
64323
64324 /*
64325 * Flags to pass to kmem_cache_create().
64326 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64327 */
64328 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64329 +
64330 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64331 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64332 +#else
64333 +#define SLAB_USERCOPY 0x00000000UL
64334 +#endif
64335 +
64336 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64337 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64338 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64339 @@ -87,10 +95,13 @@
64340 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64341 * Both make kfree a no-op.
64342 */
64343 -#define ZERO_SIZE_PTR ((void *)16)
64344 +#define ZERO_SIZE_PTR \
64345 +({ \
64346 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64347 + (void *)(-MAX_ERRNO-1L); \
64348 +})
64349
64350 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64351 - (unsigned long)ZERO_SIZE_PTR)
64352 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64353
64354 /*
64355 * Common fields provided in kmem_cache by all slab allocators
64356 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64357 void kfree(const void *);
64358 void kzfree(const void *);
64359 size_t ksize(const void *);
64360 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64361 +bool is_usercopy_object(const void *ptr);
64362
64363 /*
64364 * Allocator specific definitions. These are mainly used to establish optimized
64365 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64366 */
64367 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64368 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64369 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64370 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64371 #define kmalloc_track_caller(size, flags) \
64372 __kmalloc_track_caller(size, flags, _RET_IP_)
64373 #else
64374 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64375 */
64376 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64377 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64378 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64379 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64380 #define kmalloc_node_track_caller(size, flags, node) \
64381 __kmalloc_node_track_caller(size, flags, node, \
64382 _RET_IP_)
64383 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64384 index 0c634fa..8616300 100644
64385 --- a/include/linux/slab_def.h
64386 +++ b/include/linux/slab_def.h
64387 @@ -69,10 +69,10 @@ struct kmem_cache {
64388 unsigned long node_allocs;
64389 unsigned long node_frees;
64390 unsigned long node_overflow;
64391 - atomic_t allochit;
64392 - atomic_t allocmiss;
64393 - atomic_t freehit;
64394 - atomic_t freemiss;
64395 + atomic_unchecked_t allochit;
64396 + atomic_unchecked_t allocmiss;
64397 + atomic_unchecked_t freehit;
64398 + atomic_unchecked_t freemiss;
64399
64400 /*
64401 * If debugging is enabled, then the allocator can add additional
64402 @@ -105,11 +105,16 @@ struct cache_sizes {
64403 #ifdef CONFIG_ZONE_DMA
64404 struct kmem_cache *cs_dmacachep;
64405 #endif
64406 +
64407 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64408 + struct kmem_cache *cs_usercopycachep;
64409 +#endif
64410 +
64411 };
64412 extern struct cache_sizes malloc_sizes[];
64413
64414 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64415 -void *__kmalloc(size_t size, gfp_t flags);
64416 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64417
64418 #ifdef CONFIG_TRACING
64419 extern void *kmem_cache_alloc_trace(size_t size,
64420 @@ -152,6 +157,13 @@ found:
64421 cachep = malloc_sizes[i].cs_dmacachep;
64422 else
64423 #endif
64424 +
64425 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64426 + if (flags & GFP_USERCOPY)
64427 + cachep = malloc_sizes[i].cs_usercopycachep;
64428 + else
64429 +#endif
64430 +
64431 cachep = malloc_sizes[i].cs_cachep;
64432
64433 ret = kmem_cache_alloc_trace(size, cachep, flags);
64434 @@ -162,7 +174,7 @@ found:
64435 }
64436
64437 #ifdef CONFIG_NUMA
64438 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64439 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64440 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64441
64442 #ifdef CONFIG_TRACING
64443 @@ -205,6 +217,13 @@ found:
64444 cachep = malloc_sizes[i].cs_dmacachep;
64445 else
64446 #endif
64447 +
64448 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64449 + if (flags & GFP_USERCOPY)
64450 + cachep = malloc_sizes[i].cs_usercopycachep;
64451 + else
64452 +#endif
64453 +
64454 cachep = malloc_sizes[i].cs_cachep;
64455
64456 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64457 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64458 index 0ec00b3..22b4715 100644
64459 --- a/include/linux/slob_def.h
64460 +++ b/include/linux/slob_def.h
64461 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64462 return kmem_cache_alloc_node(cachep, flags, -1);
64463 }
64464
64465 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64466 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64467
64468 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64469 {
64470 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64471 return __kmalloc_node(size, flags, -1);
64472 }
64473
64474 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64475 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64476 {
64477 return kmalloc(size, flags);
64478 }
64479 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64480 index df448ad..b99e7f6 100644
64481 --- a/include/linux/slub_def.h
64482 +++ b/include/linux/slub_def.h
64483 @@ -91,7 +91,7 @@ struct kmem_cache {
64484 struct kmem_cache_order_objects max;
64485 struct kmem_cache_order_objects min;
64486 gfp_t allocflags; /* gfp flags to use on each alloc */
64487 - int refcount; /* Refcount for slab cache destroy */
64488 + atomic_t refcount; /* Refcount for slab cache destroy */
64489 void (*ctor)(void *);
64490 int inuse; /* Offset to metadata */
64491 int align; /* Alignment */
64492 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64493 * Sorry that the following has to be that ugly but some versions of GCC
64494 * have trouble with constant propagation and loops.
64495 */
64496 -static __always_inline int kmalloc_index(size_t size)
64497 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64498 {
64499 if (!size)
64500 return 0;
64501 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64502 }
64503
64504 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64505 -void *__kmalloc(size_t size, gfp_t flags);
64506 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64507
64508 static __always_inline void *
64509 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64510 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64511 }
64512 #endif
64513
64514 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64515 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64516 {
64517 unsigned int order = get_order(size);
64518 return kmalloc_order_trace(size, flags, order);
64519 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64520 }
64521
64522 #ifdef CONFIG_NUMA
64523 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64524 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64525 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64526
64527 #ifdef CONFIG_TRACING
64528 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64529 index de8832d..0147b46 100644
64530 --- a/include/linux/sonet.h
64531 +++ b/include/linux/sonet.h
64532 @@ -61,7 +61,7 @@ struct sonet_stats {
64533 #include <linux/atomic.h>
64534
64535 struct k_sonet_stats {
64536 -#define __HANDLE_ITEM(i) atomic_t i
64537 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64538 __SONET_ITEMS
64539 #undef __HANDLE_ITEM
64540 };
64541 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64542 index 523547e..2cb7140 100644
64543 --- a/include/linux/sunrpc/clnt.h
64544 +++ b/include/linux/sunrpc/clnt.h
64545 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64546 {
64547 switch (sap->sa_family) {
64548 case AF_INET:
64549 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64550 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64551 case AF_INET6:
64552 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64553 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64554 }
64555 return 0;
64556 }
64557 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64558 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64559 const struct sockaddr *src)
64560 {
64561 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64562 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64563 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64564
64565 dsin->sin_family = ssin->sin_family;
64566 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64567 if (sa->sa_family != AF_INET6)
64568 return 0;
64569
64570 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64571 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64572 }
64573
64574 #endif /* __KERNEL__ */
64575 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64576 index dc0c3cc..8503fb6 100644
64577 --- a/include/linux/sunrpc/sched.h
64578 +++ b/include/linux/sunrpc/sched.h
64579 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64580 void (*rpc_count_stats)(struct rpc_task *, void *);
64581 void (*rpc_release)(void *);
64582 };
64583 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64584
64585 struct rpc_task_setup {
64586 struct rpc_task *task;
64587 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64588 index 0b8e3e6..33e0a01 100644
64589 --- a/include/linux/sunrpc/svc_rdma.h
64590 +++ b/include/linux/sunrpc/svc_rdma.h
64591 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64592 extern unsigned int svcrdma_max_requests;
64593 extern unsigned int svcrdma_max_req_size;
64594
64595 -extern atomic_t rdma_stat_recv;
64596 -extern atomic_t rdma_stat_read;
64597 -extern atomic_t rdma_stat_write;
64598 -extern atomic_t rdma_stat_sq_starve;
64599 -extern atomic_t rdma_stat_rq_starve;
64600 -extern atomic_t rdma_stat_rq_poll;
64601 -extern atomic_t rdma_stat_rq_prod;
64602 -extern atomic_t rdma_stat_sq_poll;
64603 -extern atomic_t rdma_stat_sq_prod;
64604 +extern atomic_unchecked_t rdma_stat_recv;
64605 +extern atomic_unchecked_t rdma_stat_read;
64606 +extern atomic_unchecked_t rdma_stat_write;
64607 +extern atomic_unchecked_t rdma_stat_sq_starve;
64608 +extern atomic_unchecked_t rdma_stat_rq_starve;
64609 +extern atomic_unchecked_t rdma_stat_rq_poll;
64610 +extern atomic_unchecked_t rdma_stat_rq_prod;
64611 +extern atomic_unchecked_t rdma_stat_sq_poll;
64612 +extern atomic_unchecked_t rdma_stat_sq_prod;
64613
64614 #define RPCRDMA_VERSION 1
64615
64616 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64617 index c34b4c8..a65b67d 100644
64618 --- a/include/linux/sysctl.h
64619 +++ b/include/linux/sysctl.h
64620 @@ -155,7 +155,11 @@ enum
64621 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64622 };
64623
64624 -
64625 +#ifdef CONFIG_PAX_SOFTMODE
64626 +enum {
64627 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64628 +};
64629 +#endif
64630
64631 /* CTL_VM names: */
64632 enum
64633 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64634
64635 extern int proc_dostring(struct ctl_table *, int,
64636 void __user *, size_t *, loff_t *);
64637 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64638 + void __user *, size_t *, loff_t *);
64639 extern int proc_dointvec(struct ctl_table *, int,
64640 void __user *, size_t *, loff_t *);
64641 extern int proc_dointvec_minmax(struct ctl_table *, int,
64642 diff --git a/include/linux/tty.h b/include/linux/tty.h
64643 index 9f47ab5..73da944 100644
64644 --- a/include/linux/tty.h
64645 +++ b/include/linux/tty.h
64646 @@ -225,7 +225,7 @@ struct tty_port {
64647 const struct tty_port_operations *ops; /* Port operations */
64648 spinlock_t lock; /* Lock protecting tty field */
64649 int blocked_open; /* Waiting to open */
64650 - int count; /* Usage count */
64651 + atomic_t count; /* Usage count */
64652 wait_queue_head_t open_wait; /* Open waiters */
64653 wait_queue_head_t close_wait; /* Close waiters */
64654 wait_queue_head_t delta_msr_wait; /* Modem status change */
64655 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64656 struct tty_struct *tty, struct file *filp);
64657 static inline int tty_port_users(struct tty_port *port)
64658 {
64659 - return port->count + port->blocked_open;
64660 + return atomic_read(&port->count) + port->blocked_open;
64661 }
64662
64663 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64664 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64665 index fb79dd8d..07d4773 100644
64666 --- a/include/linux/tty_ldisc.h
64667 +++ b/include/linux/tty_ldisc.h
64668 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64669
64670 struct module *owner;
64671
64672 - int refcount;
64673 + atomic_t refcount;
64674 };
64675
64676 struct tty_ldisc {
64677 diff --git a/include/linux/types.h b/include/linux/types.h
64678 index bf0dd75..a1f23aaa 100644
64679 --- a/include/linux/types.h
64680 +++ b/include/linux/types.h
64681 @@ -220,10 +220,26 @@ typedef struct {
64682 int counter;
64683 } atomic_t;
64684
64685 +#ifdef CONFIG_PAX_REFCOUNT
64686 +typedef struct {
64687 + int counter;
64688 +} atomic_unchecked_t;
64689 +#else
64690 +typedef atomic_t atomic_unchecked_t;
64691 +#endif
64692 +
64693 #ifdef CONFIG_64BIT
64694 typedef struct {
64695 long counter;
64696 } atomic64_t;
64697 +
64698 +#ifdef CONFIG_PAX_REFCOUNT
64699 +typedef struct {
64700 + long counter;
64701 +} atomic64_unchecked_t;
64702 +#else
64703 +typedef atomic64_t atomic64_unchecked_t;
64704 +#endif
64705 #endif
64706
64707 struct list_head {
64708 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64709 index 5ca0951..ab496a5 100644
64710 --- a/include/linux/uaccess.h
64711 +++ b/include/linux/uaccess.h
64712 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64713 long ret; \
64714 mm_segment_t old_fs = get_fs(); \
64715 \
64716 - set_fs(KERNEL_DS); \
64717 pagefault_disable(); \
64718 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64719 - pagefault_enable(); \
64720 + set_fs(KERNEL_DS); \
64721 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64722 set_fs(old_fs); \
64723 + pagefault_enable(); \
64724 ret; \
64725 })
64726
64727 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64728 index 99c1b4d..bb94261 100644
64729 --- a/include/linux/unaligned/access_ok.h
64730 +++ b/include/linux/unaligned/access_ok.h
64731 @@ -6,32 +6,32 @@
64732
64733 static inline u16 get_unaligned_le16(const void *p)
64734 {
64735 - return le16_to_cpup((__le16 *)p);
64736 + return le16_to_cpup((const __le16 *)p);
64737 }
64738
64739 static inline u32 get_unaligned_le32(const void *p)
64740 {
64741 - return le32_to_cpup((__le32 *)p);
64742 + return le32_to_cpup((const __le32 *)p);
64743 }
64744
64745 static inline u64 get_unaligned_le64(const void *p)
64746 {
64747 - return le64_to_cpup((__le64 *)p);
64748 + return le64_to_cpup((const __le64 *)p);
64749 }
64750
64751 static inline u16 get_unaligned_be16(const void *p)
64752 {
64753 - return be16_to_cpup((__be16 *)p);
64754 + return be16_to_cpup((const __be16 *)p);
64755 }
64756
64757 static inline u32 get_unaligned_be32(const void *p)
64758 {
64759 - return be32_to_cpup((__be32 *)p);
64760 + return be32_to_cpup((const __be32 *)p);
64761 }
64762
64763 static inline u64 get_unaligned_be64(const void *p)
64764 {
64765 - return be64_to_cpup((__be64 *)p);
64766 + return be64_to_cpup((const __be64 *)p);
64767 }
64768
64769 static inline void put_unaligned_le16(u16 val, void *p)
64770 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64771 index c5d36c6..8478c90 100644
64772 --- a/include/linux/usb/renesas_usbhs.h
64773 +++ b/include/linux/usb/renesas_usbhs.h
64774 @@ -39,7 +39,7 @@ enum {
64775 */
64776 struct renesas_usbhs_driver_callback {
64777 int (*notify_hotplug)(struct platform_device *pdev);
64778 -};
64779 +} __no_const;
64780
64781 /*
64782 * callback functions for platform
64783 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64784 * VBUS control is needed for Host
64785 */
64786 int (*set_vbus)(struct platform_device *pdev, int enable);
64787 -};
64788 +} __no_const;
64789
64790 /*
64791 * parameters for renesas usbhs
64792 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64793 index 6f8fbcf..8259001 100644
64794 --- a/include/linux/vermagic.h
64795 +++ b/include/linux/vermagic.h
64796 @@ -25,9 +25,35 @@
64797 #define MODULE_ARCH_VERMAGIC ""
64798 #endif
64799
64800 +#ifdef CONFIG_PAX_REFCOUNT
64801 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64802 +#else
64803 +#define MODULE_PAX_REFCOUNT ""
64804 +#endif
64805 +
64806 +#ifdef CONSTIFY_PLUGIN
64807 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64808 +#else
64809 +#define MODULE_CONSTIFY_PLUGIN ""
64810 +#endif
64811 +
64812 +#ifdef STACKLEAK_PLUGIN
64813 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64814 +#else
64815 +#define MODULE_STACKLEAK_PLUGIN ""
64816 +#endif
64817 +
64818 +#ifdef CONFIG_GRKERNSEC
64819 +#define MODULE_GRSEC "GRSEC "
64820 +#else
64821 +#define MODULE_GRSEC ""
64822 +#endif
64823 +
64824 #define VERMAGIC_STRING \
64825 UTS_RELEASE " " \
64826 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64827 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64828 - MODULE_ARCH_VERMAGIC
64829 + MODULE_ARCH_VERMAGIC \
64830 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64831 + MODULE_GRSEC
64832
64833 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64834 index 6071e91..ca6a489 100644
64835 --- a/include/linux/vmalloc.h
64836 +++ b/include/linux/vmalloc.h
64837 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64838 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64839 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64840 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64841 +
64842 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64843 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64844 +#endif
64845 +
64846 /* bits [20..32] reserved for arch specific ioremap internals */
64847
64848 /*
64849 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64850 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64851 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64852 unsigned long start, unsigned long end, gfp_t gfp_mask,
64853 - pgprot_t prot, int node, const void *caller);
64854 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64855 extern void vfree(const void *addr);
64856
64857 extern void *vmap(struct page **pages, unsigned int count,
64858 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64859 extern void free_vm_area(struct vm_struct *area);
64860
64861 /* for /dev/kmem */
64862 -extern long vread(char *buf, char *addr, unsigned long count);
64863 -extern long vwrite(char *buf, char *addr, unsigned long count);
64864 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64865 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64866
64867 /*
64868 * Internals. Dont't use..
64869 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64870 index ad2cfd5..74c94ad 100644
64871 --- a/include/linux/vmstat.h
64872 +++ b/include/linux/vmstat.h
64873 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64874 /*
64875 * Zone based page accounting with per cpu differentials.
64876 */
64877 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64878 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64879
64880 static inline void zone_page_state_add(long x, struct zone *zone,
64881 enum zone_stat_item item)
64882 {
64883 - atomic_long_add(x, &zone->vm_stat[item]);
64884 - atomic_long_add(x, &vm_stat[item]);
64885 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64886 + atomic_long_add_unchecked(x, &vm_stat[item]);
64887 }
64888
64889 static inline unsigned long global_page_state(enum zone_stat_item item)
64890 {
64891 - long x = atomic_long_read(&vm_stat[item]);
64892 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64893 #ifdef CONFIG_SMP
64894 if (x < 0)
64895 x = 0;
64896 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64897 static inline unsigned long zone_page_state(struct zone *zone,
64898 enum zone_stat_item item)
64899 {
64900 - long x = atomic_long_read(&zone->vm_stat[item]);
64901 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64902 #ifdef CONFIG_SMP
64903 if (x < 0)
64904 x = 0;
64905 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64906 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64907 enum zone_stat_item item)
64908 {
64909 - long x = atomic_long_read(&zone->vm_stat[item]);
64910 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64911
64912 #ifdef CONFIG_SMP
64913 int cpu;
64914 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64915
64916 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64917 {
64918 - atomic_long_inc(&zone->vm_stat[item]);
64919 - atomic_long_inc(&vm_stat[item]);
64920 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64921 + atomic_long_inc_unchecked(&vm_stat[item]);
64922 }
64923
64924 static inline void __inc_zone_page_state(struct page *page,
64925 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64926
64927 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64928 {
64929 - atomic_long_dec(&zone->vm_stat[item]);
64930 - atomic_long_dec(&vm_stat[item]);
64931 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64932 + atomic_long_dec_unchecked(&vm_stat[item]);
64933 }
64934
64935 static inline void __dec_zone_page_state(struct page *page,
64936 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64937 index e5d1220..ef6e406 100644
64938 --- a/include/linux/xattr.h
64939 +++ b/include/linux/xattr.h
64940 @@ -57,6 +57,11 @@
64941 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64942 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64943
64944 +/* User namespace */
64945 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64946 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64947 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64948 +
64949 #ifdef __KERNEL__
64950
64951 #include <linux/types.h>
64952 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64953 index 944ecdf..a3994fc 100644
64954 --- a/include/media/saa7146_vv.h
64955 +++ b/include/media/saa7146_vv.h
64956 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64957 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64958
64959 /* the extension can override this */
64960 - struct v4l2_ioctl_ops vid_ops;
64961 - struct v4l2_ioctl_ops vbi_ops;
64962 + v4l2_ioctl_ops_no_const vid_ops;
64963 + v4l2_ioctl_ops_no_const vbi_ops;
64964 /* pointer to the saa7146 core ops */
64965 const struct v4l2_ioctl_ops *core_ops;
64966
64967 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64968 index 5c416cd..20021aa 100644
64969 --- a/include/media/v4l2-dev.h
64970 +++ b/include/media/v4l2-dev.h
64971 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64972 int (*mmap) (struct file *, struct vm_area_struct *);
64973 int (*open) (struct file *);
64974 int (*release) (struct file *);
64975 -};
64976 +} __do_const;
64977 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64978
64979 /*
64980 * Newer version of video_device, handled by videodev2.c
64981 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64982 index e614c9c..20602b7 100644
64983 --- a/include/media/v4l2-ioctl.h
64984 +++ b/include/media/v4l2-ioctl.h
64985 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
64986 long (*vidioc_default) (struct file *file, void *fh,
64987 bool valid_prio, int cmd, void *arg);
64988 };
64989 -
64990 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64991
64992 /* v4l debugging and diagnostics */
64993
64994 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64995 index bcb9cc3..f4ec722e 100644
64996 --- a/include/net/caif/caif_hsi.h
64997 +++ b/include/net/caif/caif_hsi.h
64998 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
64999 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65000 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65001 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65002 -};
65003 +} __no_const;
65004
65005 /* Structure implemented by HSI device. */
65006 struct cfhsi_ops {
65007 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65008 index 9e5425b..8136ffc 100644
65009 --- a/include/net/caif/cfctrl.h
65010 +++ b/include/net/caif/cfctrl.h
65011 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65012 void (*radioset_rsp)(void);
65013 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65014 struct cflayer *client_layer);
65015 -};
65016 +} __no_const;
65017
65018 /* Link Setup Parameters for CAIF-Links. */
65019 struct cfctrl_link_param {
65020 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65021 struct cfctrl {
65022 struct cfsrvl serv;
65023 struct cfctrl_rsp res;
65024 - atomic_t req_seq_no;
65025 - atomic_t rsp_seq_no;
65026 + atomic_unchecked_t req_seq_no;
65027 + atomic_unchecked_t rsp_seq_no;
65028 struct list_head list;
65029 /* Protects from simultaneous access to first_req list */
65030 spinlock_t info_list_lock;
65031 diff --git a/include/net/flow.h b/include/net/flow.h
65032 index e1dd508..2873851 100644
65033 --- a/include/net/flow.h
65034 +++ b/include/net/flow.h
65035 @@ -220,6 +220,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65036
65037 extern void flow_cache_flush(void);
65038 extern void flow_cache_flush_deferred(void);
65039 -extern atomic_t flow_cache_genid;
65040 +extern atomic_unchecked_t flow_cache_genid;
65041
65042 #endif
65043 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65044 index 53f464d..ba76aaa 100644
65045 --- a/include/net/inetpeer.h
65046 +++ b/include/net/inetpeer.h
65047 @@ -47,8 +47,8 @@ struct inet_peer {
65048 */
65049 union {
65050 struct {
65051 - atomic_t rid; /* Frag reception counter */
65052 - atomic_t ip_id_count; /* IP ID for the next packet */
65053 + atomic_unchecked_t rid; /* Frag reception counter */
65054 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65055 };
65056 struct rcu_head rcu;
65057 struct inet_peer *gc_next;
65058 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65059 more++;
65060 inet_peer_refcheck(p);
65061 do {
65062 - old = atomic_read(&p->ip_id_count);
65063 + old = atomic_read_unchecked(&p->ip_id_count);
65064 new = old + more;
65065 if (!new)
65066 new = 1;
65067 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65068 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65069 return new;
65070 }
65071
65072 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65073 index 9497be1..5a4fafe 100644
65074 --- a/include/net/ip_fib.h
65075 +++ b/include/net/ip_fib.h
65076 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65077
65078 #define FIB_RES_SADDR(net, res) \
65079 ((FIB_RES_NH(res).nh_saddr_genid == \
65080 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65081 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65082 FIB_RES_NH(res).nh_saddr : \
65083 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65084 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65085 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65086 index 95374d1..2300e36 100644
65087 --- a/include/net/ip_vs.h
65088 +++ b/include/net/ip_vs.h
65089 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65090 struct ip_vs_conn *control; /* Master control connection */
65091 atomic_t n_control; /* Number of controlled ones */
65092 struct ip_vs_dest *dest; /* real server */
65093 - atomic_t in_pkts; /* incoming packet counter */
65094 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65095
65096 /* packet transmitter for different forwarding methods. If it
65097 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65098 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65099 __be16 port; /* port number of the server */
65100 union nf_inet_addr addr; /* IP address of the server */
65101 volatile unsigned int flags; /* dest status flags */
65102 - atomic_t conn_flags; /* flags to copy to conn */
65103 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65104 atomic_t weight; /* server weight */
65105
65106 atomic_t refcnt; /* reference counter */
65107 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65108 index 69b610a..fe3962c 100644
65109 --- a/include/net/irda/ircomm_core.h
65110 +++ b/include/net/irda/ircomm_core.h
65111 @@ -51,7 +51,7 @@ typedef struct {
65112 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65113 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65114 struct ircomm_info *);
65115 -} call_t;
65116 +} __no_const call_t;
65117
65118 struct ircomm_cb {
65119 irda_queue_t queue;
65120 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65121 index 59ba38bc..d515662 100644
65122 --- a/include/net/irda/ircomm_tty.h
65123 +++ b/include/net/irda/ircomm_tty.h
65124 @@ -35,6 +35,7 @@
65125 #include <linux/termios.h>
65126 #include <linux/timer.h>
65127 #include <linux/tty.h> /* struct tty_struct */
65128 +#include <asm/local.h>
65129
65130 #include <net/irda/irias_object.h>
65131 #include <net/irda/ircomm_core.h>
65132 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65133 unsigned short close_delay;
65134 unsigned short closing_wait; /* time to wait before closing */
65135
65136 - int open_count;
65137 - int blocked_open; /* # of blocked opens */
65138 + local_t open_count;
65139 + local_t blocked_open; /* # of blocked opens */
65140
65141 /* Protect concurent access to :
65142 * o self->open_count
65143 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65144 index cc7c197..9f2da2a 100644
65145 --- a/include/net/iucv/af_iucv.h
65146 +++ b/include/net/iucv/af_iucv.h
65147 @@ -141,7 +141,7 @@ struct iucv_sock {
65148 struct iucv_sock_list {
65149 struct hlist_head head;
65150 rwlock_t lock;
65151 - atomic_t autobind_name;
65152 + atomic_unchecked_t autobind_name;
65153 };
65154
65155 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65156 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65157 index 344d898..2ae1302 100644
65158 --- a/include/net/neighbour.h
65159 +++ b/include/net/neighbour.h
65160 @@ -123,7 +123,7 @@ struct neigh_ops {
65161 void (*error_report)(struct neighbour *, struct sk_buff *);
65162 int (*output)(struct neighbour *, struct sk_buff *);
65163 int (*connected_output)(struct neighbour *, struct sk_buff *);
65164 -};
65165 +} __do_const;
65166
65167 struct pneigh_entry {
65168 struct pneigh_entry *next;
65169 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65170 index fd87963..312a11f 100644
65171 --- a/include/net/net_namespace.h
65172 +++ b/include/net/net_namespace.h
65173 @@ -102,7 +102,7 @@ struct net {
65174 #endif
65175 struct netns_ipvs *ipvs;
65176 struct sock *diag_nlsk;
65177 - atomic_t rt_genid;
65178 + atomic_unchecked_t rt_genid;
65179 };
65180
65181
65182 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65183
65184 static inline int rt_genid(struct net *net)
65185 {
65186 - return atomic_read(&net->rt_genid);
65187 + return atomic_read_unchecked(&net->rt_genid);
65188 }
65189
65190 static inline void rt_genid_bump(struct net *net)
65191 {
65192 - atomic_inc(&net->rt_genid);
65193 + atomic_inc_unchecked(&net->rt_genid);
65194 }
65195
65196 #endif /* __NET_NET_NAMESPACE_H */
65197 diff --git a/include/net/netdma.h b/include/net/netdma.h
65198 index 8ba8ce2..99b7fff 100644
65199 --- a/include/net/netdma.h
65200 +++ b/include/net/netdma.h
65201 @@ -24,7 +24,7 @@
65202 #include <linux/dmaengine.h>
65203 #include <linux/skbuff.h>
65204
65205 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65206 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65207 struct sk_buff *skb, int offset, struct iovec *to,
65208 size_t len, struct dma_pinned_list *pinned_list);
65209
65210 diff --git a/include/net/netlink.h b/include/net/netlink.h
65211 index 785f37a..c81dc0c 100644
65212 --- a/include/net/netlink.h
65213 +++ b/include/net/netlink.h
65214 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65215 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65216 {
65217 if (mark)
65218 - skb_trim(skb, (unsigned char *) mark - skb->data);
65219 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65220 }
65221
65222 /**
65223 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65224 index eb24dbc..567d6ed 100644
65225 --- a/include/net/netns/ipv4.h
65226 +++ b/include/net/netns/ipv4.h
65227 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65228 unsigned int sysctl_ping_group_range[2];
65229 long sysctl_tcp_mem[3];
65230
65231 - atomic_t dev_addr_genid;
65232 + atomic_unchecked_t dev_addr_genid;
65233
65234 #ifdef CONFIG_IP_MROUTE
65235 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65236 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65237 index ff49964..1411fee 100644
65238 --- a/include/net/sctp/sctp.h
65239 +++ b/include/net/sctp/sctp.h
65240 @@ -320,9 +320,9 @@ do { \
65241
65242 #else /* SCTP_DEBUG */
65243
65244 -#define SCTP_DEBUG_PRINTK(whatever...)
65245 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65246 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65247 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65248 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65249 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65250 #define SCTP_ENABLE_DEBUG
65251 #define SCTP_DISABLE_DEBUG
65252 #define SCTP_ASSERT(expr, str, func)
65253 diff --git a/include/net/sock.h b/include/net/sock.h
65254 index adb7da2..1100002 100644
65255 --- a/include/net/sock.h
65256 +++ b/include/net/sock.h
65257 @@ -305,7 +305,7 @@ struct sock {
65258 #ifdef CONFIG_RPS
65259 __u32 sk_rxhash;
65260 #endif
65261 - atomic_t sk_drops;
65262 + atomic_unchecked_t sk_drops;
65263 int sk_rcvbuf;
65264
65265 struct sk_filter __rcu *sk_filter;
65266 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65267 }
65268
65269 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65270 - char __user *from, char *to,
65271 + char __user *from, unsigned char *to,
65272 int copy, int offset)
65273 {
65274 if (skb->ip_summed == CHECKSUM_NONE) {
65275 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65276 }
65277 }
65278
65279 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65280 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65281
65282 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65283 {
65284 diff --git a/include/net/tcp.h b/include/net/tcp.h
65285 index 1f000ff..e5a8dfb 100644
65286 --- a/include/net/tcp.h
65287 +++ b/include/net/tcp.h
65288 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65289 extern void tcp_xmit_retransmit_queue(struct sock *);
65290 extern void tcp_simple_retransmit(struct sock *);
65291 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65292 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65293 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65294
65295 extern void tcp_send_probe0(struct sock *);
65296 extern void tcp_send_partial(struct sock *);
65297 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65298 struct inet6_skb_parm h6;
65299 #endif
65300 } header; /* For incoming frames */
65301 - __u32 seq; /* Starting sequence number */
65302 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65303 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65304 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65305 __u32 when; /* used to compute rtt's */
65306 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65307
65308 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65309
65310 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65311 /* 1 byte hole */
65312 - __u32 ack_seq; /* Sequence number ACK'd */
65313 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65314 };
65315
65316 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65317 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65318 char *name;
65319 sa_family_t family;
65320 const struct file_operations *seq_fops;
65321 - struct seq_operations seq_ops;
65322 + seq_operations_no_const seq_ops;
65323 };
65324
65325 struct tcp_iter_state {
65326 diff --git a/include/net/udp.h b/include/net/udp.h
65327 index 065f379..b661b40 100644
65328 --- a/include/net/udp.h
65329 +++ b/include/net/udp.h
65330 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65331 sa_family_t family;
65332 struct udp_table *udp_table;
65333 const struct file_operations *seq_fops;
65334 - struct seq_operations seq_ops;
65335 + seq_operations_no_const seq_ops;
65336 };
65337
65338 struct udp_iter_state {
65339 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65340 index 639dd13..15b206c 100644
65341 --- a/include/net/xfrm.h
65342 +++ b/include/net/xfrm.h
65343 @@ -514,7 +514,7 @@ struct xfrm_policy {
65344 struct timer_list timer;
65345
65346 struct flow_cache_object flo;
65347 - atomic_t genid;
65348 + atomic_unchecked_t genid;
65349 u32 priority;
65350 u32 index;
65351 struct xfrm_mark mark;
65352 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65353 index 1a046b1..ee0bef0 100644
65354 --- a/include/rdma/iw_cm.h
65355 +++ b/include/rdma/iw_cm.h
65356 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65357 int backlog);
65358
65359 int (*destroy_listen)(struct iw_cm_id *cm_id);
65360 -};
65361 +} __no_const;
65362
65363 /**
65364 * iw_create_cm_id - Create an IW CM identifier.
65365 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65366 index 399162b..b337f1a 100644
65367 --- a/include/scsi/libfc.h
65368 +++ b/include/scsi/libfc.h
65369 @@ -762,6 +762,7 @@ struct libfc_function_template {
65370 */
65371 void (*disc_stop_final) (struct fc_lport *);
65372 };
65373 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65374
65375 /**
65376 * struct fc_disc - Discovery context
65377 @@ -866,7 +867,7 @@ struct fc_lport {
65378 struct fc_vport *vport;
65379
65380 /* Operational Information */
65381 - struct libfc_function_template tt;
65382 + libfc_function_template_no_const tt;
65383 u8 link_up;
65384 u8 qfull;
65385 enum fc_lport_state state;
65386 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65387 index 9895f69..f1418f0 100644
65388 --- a/include/scsi/scsi_device.h
65389 +++ b/include/scsi/scsi_device.h
65390 @@ -166,9 +166,9 @@ struct scsi_device {
65391 unsigned int max_device_blocked; /* what device_blocked counts down from */
65392 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65393
65394 - atomic_t iorequest_cnt;
65395 - atomic_t iodone_cnt;
65396 - atomic_t ioerr_cnt;
65397 + atomic_unchecked_t iorequest_cnt;
65398 + atomic_unchecked_t iodone_cnt;
65399 + atomic_unchecked_t ioerr_cnt;
65400
65401 struct device sdev_gendev,
65402 sdev_dev;
65403 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65404 index b797e8f..8e2c3aa 100644
65405 --- a/include/scsi/scsi_transport_fc.h
65406 +++ b/include/scsi/scsi_transport_fc.h
65407 @@ -751,7 +751,8 @@ struct fc_function_template {
65408 unsigned long show_host_system_hostname:1;
65409
65410 unsigned long disable_target_scan:1;
65411 -};
65412 +} __do_const;
65413 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65414
65415
65416 /**
65417 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65418 index 030b87c..98a6954 100644
65419 --- a/include/sound/ak4xxx-adda.h
65420 +++ b/include/sound/ak4xxx-adda.h
65421 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65422 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65423 unsigned char val);
65424 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65425 -};
65426 +} __no_const;
65427
65428 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65429
65430 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65431 index 8c05e47..2b5df97 100644
65432 --- a/include/sound/hwdep.h
65433 +++ b/include/sound/hwdep.h
65434 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65435 struct snd_hwdep_dsp_status *status);
65436 int (*dsp_load)(struct snd_hwdep *hw,
65437 struct snd_hwdep_dsp_image *image);
65438 -};
65439 +} __no_const;
65440
65441 struct snd_hwdep {
65442 struct snd_card *card;
65443 diff --git a/include/sound/info.h b/include/sound/info.h
65444 index 9ca1a49..aba1728 100644
65445 --- a/include/sound/info.h
65446 +++ b/include/sound/info.h
65447 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65448 struct snd_info_buffer *buffer);
65449 void (*write)(struct snd_info_entry *entry,
65450 struct snd_info_buffer *buffer);
65451 -};
65452 +} __no_const;
65453
65454 struct snd_info_entry_ops {
65455 int (*open)(struct snd_info_entry *entry,
65456 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65457 index cdca2ab..10bbe05 100644
65458 --- a/include/sound/pcm.h
65459 +++ b/include/sound/pcm.h
65460 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65461 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65462 int (*ack)(struct snd_pcm_substream *substream);
65463 };
65464 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65465
65466 /*
65467 *
65468 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65469 index af1b49e..a5d55a5 100644
65470 --- a/include/sound/sb16_csp.h
65471 +++ b/include/sound/sb16_csp.h
65472 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65473 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65474 int (*csp_stop) (struct snd_sb_csp * p);
65475 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65476 -};
65477 +} __no_const;
65478
65479 /*
65480 * CSP private data
65481 diff --git a/include/sound/soc.h b/include/sound/soc.h
65482 index e063380..e8077d5 100644
65483 --- a/include/sound/soc.h
65484 +++ b/include/sound/soc.h
65485 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65486 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65487 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65488 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65489 -};
65490 +} __do_const;
65491
65492 struct snd_soc_platform {
65493 const char *name;
65494 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65495 struct snd_soc_dai_link *dai_link;
65496 struct mutex pcm_mutex;
65497 enum snd_soc_pcm_subclass pcm_subclass;
65498 - struct snd_pcm_ops ops;
65499 + snd_pcm_ops_no_const ops;
65500
65501 unsigned int dev_registered:1;
65502
65503 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65504 index fe8590c..aaed363 100644
65505 --- a/include/sound/tea575x-tuner.h
65506 +++ b/include/sound/tea575x-tuner.h
65507 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65508
65509 struct snd_tea575x {
65510 struct v4l2_device *v4l2_dev;
65511 - struct v4l2_file_operations fops;
65512 + v4l2_file_operations_no_const fops;
65513 struct video_device vd; /* video device */
65514 int radio_nr; /* radio_nr */
65515 bool tea5759; /* 5759 chip is present */
65516 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65517 index 5be8937..a8e46e9 100644
65518 --- a/include/target/target_core_base.h
65519 +++ b/include/target/target_core_base.h
65520 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65521 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65522 int (*t10_pr_register)(struct se_cmd *);
65523 int (*t10_pr_clear)(struct se_cmd *);
65524 -};
65525 +} __no_const;
65526
65527 struct t10_reservation {
65528 /* Reservation effects all target ports */
65529 @@ -758,7 +758,7 @@ struct se_device {
65530 spinlock_t stats_lock;
65531 /* Active commands on this virtual SE device */
65532 atomic_t simple_cmds;
65533 - atomic_t dev_ordered_id;
65534 + atomic_unchecked_t dev_ordered_id;
65535 atomic_t dev_ordered_sync;
65536 atomic_t dev_qf_count;
65537 struct se_obj dev_obj;
65538 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65539 new file mode 100644
65540 index 0000000..2efe49d
65541 --- /dev/null
65542 +++ b/include/trace/events/fs.h
65543 @@ -0,0 +1,53 @@
65544 +#undef TRACE_SYSTEM
65545 +#define TRACE_SYSTEM fs
65546 +
65547 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65548 +#define _TRACE_FS_H
65549 +
65550 +#include <linux/fs.h>
65551 +#include <linux/tracepoint.h>
65552 +
65553 +TRACE_EVENT(do_sys_open,
65554 +
65555 + TP_PROTO(char *filename, int flags, int mode),
65556 +
65557 + TP_ARGS(filename, flags, mode),
65558 +
65559 + TP_STRUCT__entry(
65560 + __string( filename, filename )
65561 + __field( int, flags )
65562 + __field( int, mode )
65563 + ),
65564 +
65565 + TP_fast_assign(
65566 + __assign_str(filename, filename);
65567 + __entry->flags = flags;
65568 + __entry->mode = mode;
65569 + ),
65570 +
65571 + TP_printk("\"%s\" %x %o",
65572 + __get_str(filename), __entry->flags, __entry->mode)
65573 +);
65574 +
65575 +TRACE_EVENT(open_exec,
65576 +
65577 + TP_PROTO(const char *filename),
65578 +
65579 + TP_ARGS(filename),
65580 +
65581 + TP_STRUCT__entry(
65582 + __string( filename, filename )
65583 + ),
65584 +
65585 + TP_fast_assign(
65586 + __assign_str(filename, filename);
65587 + ),
65588 +
65589 + TP_printk("\"%s\"",
65590 + __get_str(filename))
65591 +);
65592 +
65593 +#endif /* _TRACE_FS_H */
65594 +
65595 +/* This part must be outside protection */
65596 +#include <trace/define_trace.h>
65597 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65598 index 1c09820..7f5ec79 100644
65599 --- a/include/trace/events/irq.h
65600 +++ b/include/trace/events/irq.h
65601 @@ -36,7 +36,7 @@ struct softirq_action;
65602 */
65603 TRACE_EVENT(irq_handler_entry,
65604
65605 - TP_PROTO(int irq, struct irqaction *action),
65606 + TP_PROTO(int irq, const struct irqaction *action),
65607
65608 TP_ARGS(irq, action),
65609
65610 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65611 */
65612 TRACE_EVENT(irq_handler_exit,
65613
65614 - TP_PROTO(int irq, struct irqaction *action, int ret),
65615 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65616
65617 TP_ARGS(irq, action, ret),
65618
65619 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65620 index f9466fa..f4e2b81 100644
65621 --- a/include/video/udlfb.h
65622 +++ b/include/video/udlfb.h
65623 @@ -53,10 +53,10 @@ struct dlfb_data {
65624 u32 pseudo_palette[256];
65625 int blank_mode; /*one of FB_BLANK_ */
65626 /* blit-only rendering path metrics, exposed through sysfs */
65627 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65628 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65629 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65630 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65631 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65632 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65633 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65634 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65635 };
65636
65637 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65638 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65639 index 0993a22..32ba2fe 100644
65640 --- a/include/video/uvesafb.h
65641 +++ b/include/video/uvesafb.h
65642 @@ -177,6 +177,7 @@ struct uvesafb_par {
65643 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65644 u8 pmi_setpal; /* PMI for palette changes */
65645 u16 *pmi_base; /* protected mode interface location */
65646 + u8 *pmi_code; /* protected mode code location */
65647 void *pmi_start;
65648 void *pmi_pal;
65649 u8 *vbe_state_orig; /*
65650 diff --git a/init/Kconfig b/init/Kconfig
65651 index af6c7f8..5c188f8 100644
65652 --- a/init/Kconfig
65653 +++ b/init/Kconfig
65654 @@ -850,6 +850,7 @@ endif # CGROUPS
65655
65656 config CHECKPOINT_RESTORE
65657 bool "Checkpoint/restore support" if EXPERT
65658 + depends on !GRKERNSEC
65659 default n
65660 help
65661 Enables additional kernel features in a sake of checkpoint/restore.
65662 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65663 # Security modules
65664 depends on SECURITY_TOMOYO = n
65665 depends on SECURITY_APPARMOR = n
65666 + depends on GRKERNSEC = n
65667
65668 config UIDGID_STRICT_TYPE_CHECKS
65669 bool "Require conversions between uid/gids and their internal representation"
65670 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65671
65672 config COMPAT_BRK
65673 bool "Disable heap randomization"
65674 - default y
65675 + default n
65676 help
65677 Randomizing heap placement makes heap exploits harder, but it
65678 also breaks ancient binaries (including anything libc5 based).
65679 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65680 config STOP_MACHINE
65681 bool
65682 default y
65683 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65684 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65685 help
65686 Need stop_machine() primitive.
65687
65688 diff --git a/init/Makefile b/init/Makefile
65689 index 7bc47ee..6da2dc7 100644
65690 --- a/init/Makefile
65691 +++ b/init/Makefile
65692 @@ -2,6 +2,9 @@
65693 # Makefile for the linux kernel.
65694 #
65695
65696 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65697 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65698 +
65699 obj-y := main.o version.o mounts.o
65700 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65701 obj-y += noinitramfs.o
65702 diff --git a/init/do_mounts.c b/init/do_mounts.c
65703 index d3f0aee..c9322f5 100644
65704 --- a/init/do_mounts.c
65705 +++ b/init/do_mounts.c
65706 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65707 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65708 {
65709 struct super_block *s;
65710 - int err = sys_mount(name, "/root", fs, flags, data);
65711 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65712 if (err)
65713 return err;
65714
65715 - sys_chdir("/root");
65716 + sys_chdir((const char __force_user *)"/root");
65717 s = current->fs->pwd.dentry->d_sb;
65718 ROOT_DEV = s->s_dev;
65719 printk(KERN_INFO
65720 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65721 va_start(args, fmt);
65722 vsprintf(buf, fmt, args);
65723 va_end(args);
65724 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65725 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65726 if (fd >= 0) {
65727 sys_ioctl(fd, FDEJECT, 0);
65728 sys_close(fd);
65729 }
65730 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65731 - fd = sys_open("/dev/console", O_RDWR, 0);
65732 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65733 if (fd >= 0) {
65734 sys_ioctl(fd, TCGETS, (long)&termios);
65735 termios.c_lflag &= ~ICANON;
65736 sys_ioctl(fd, TCSETSF, (long)&termios);
65737 - sys_read(fd, &c, 1);
65738 + sys_read(fd, (char __user *)&c, 1);
65739 termios.c_lflag |= ICANON;
65740 sys_ioctl(fd, TCSETSF, (long)&termios);
65741 sys_close(fd);
65742 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65743 mount_root();
65744 out:
65745 devtmpfs_mount("dev");
65746 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65747 - sys_chroot(".");
65748 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65749 + sys_chroot((const char __force_user *)".");
65750 }
65751 diff --git a/init/do_mounts.h b/init/do_mounts.h
65752 index f5b978a..69dbfe8 100644
65753 --- a/init/do_mounts.h
65754 +++ b/init/do_mounts.h
65755 @@ -15,15 +15,15 @@ extern int root_mountflags;
65756
65757 static inline int create_dev(char *name, dev_t dev)
65758 {
65759 - sys_unlink(name);
65760 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65761 + sys_unlink((char __force_user *)name);
65762 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65763 }
65764
65765 #if BITS_PER_LONG == 32
65766 static inline u32 bstat(char *name)
65767 {
65768 struct stat64 stat;
65769 - if (sys_stat64(name, &stat) != 0)
65770 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65771 return 0;
65772 if (!S_ISBLK(stat.st_mode))
65773 return 0;
65774 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65775 static inline u32 bstat(char *name)
65776 {
65777 struct stat stat;
65778 - if (sys_newstat(name, &stat) != 0)
65779 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65780 return 0;
65781 if (!S_ISBLK(stat.st_mode))
65782 return 0;
65783 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65784 index 135959a2..28a3f43 100644
65785 --- a/init/do_mounts_initrd.c
65786 +++ b/init/do_mounts_initrd.c
65787 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65788 create_dev("/dev/root.old", Root_RAM0);
65789 /* mount initrd on rootfs' /root */
65790 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65791 - sys_mkdir("/old", 0700);
65792 - root_fd = sys_open("/", 0, 0);
65793 - old_fd = sys_open("/old", 0, 0);
65794 + sys_mkdir((const char __force_user *)"/old", 0700);
65795 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65796 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65797 /* move initrd over / and chdir/chroot in initrd root */
65798 - sys_chdir("/root");
65799 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65800 - sys_chroot(".");
65801 + sys_chdir((const char __force_user *)"/root");
65802 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65803 + sys_chroot((const char __force_user *)".");
65804
65805 /*
65806 * In case that a resume from disk is carried out by linuxrc or one of
65807 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65808
65809 /* move initrd to rootfs' /old */
65810 sys_fchdir(old_fd);
65811 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65812 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65813 /* switch root and cwd back to / of rootfs */
65814 sys_fchdir(root_fd);
65815 - sys_chroot(".");
65816 + sys_chroot((const char __force_user *)".");
65817 sys_close(old_fd);
65818 sys_close(root_fd);
65819
65820 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65821 - sys_chdir("/old");
65822 + sys_chdir((const char __force_user *)"/old");
65823 return;
65824 }
65825
65826 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65827 mount_root();
65828
65829 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65830 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65831 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65832 if (!error)
65833 printk("okay\n");
65834 else {
65835 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65836 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65837 if (error == -ENOENT)
65838 printk("/initrd does not exist. Ignored.\n");
65839 else
65840 printk("failed\n");
65841 printk(KERN_NOTICE "Unmounting old root\n");
65842 - sys_umount("/old", MNT_DETACH);
65843 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65844 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65845 if (fd < 0) {
65846 error = fd;
65847 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65848 * mounted in the normal path.
65849 */
65850 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65851 - sys_unlink("/initrd.image");
65852 + sys_unlink((const char __force_user *)"/initrd.image");
65853 handle_initrd();
65854 return 1;
65855 }
65856 }
65857 - sys_unlink("/initrd.image");
65858 + sys_unlink((const char __force_user *)"/initrd.image");
65859 return 0;
65860 }
65861 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65862 index 8cb6db5..d729f50 100644
65863 --- a/init/do_mounts_md.c
65864 +++ b/init/do_mounts_md.c
65865 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65866 partitioned ? "_d" : "", minor,
65867 md_setup_args[ent].device_names);
65868
65869 - fd = sys_open(name, 0, 0);
65870 + fd = sys_open((char __force_user *)name, 0, 0);
65871 if (fd < 0) {
65872 printk(KERN_ERR "md: open failed - cannot start "
65873 "array %s\n", name);
65874 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65875 * array without it
65876 */
65877 sys_close(fd);
65878 - fd = sys_open(name, 0, 0);
65879 + fd = sys_open((char __force_user *)name, 0, 0);
65880 sys_ioctl(fd, BLKRRPART, 0);
65881 }
65882 sys_close(fd);
65883 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65884
65885 wait_for_device_probe();
65886
65887 - fd = sys_open("/dev/md0", 0, 0);
65888 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65889 if (fd >= 0) {
65890 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65891 sys_close(fd);
65892 diff --git a/init/init_task.c b/init/init_task.c
65893 index 8b2f399..f0797c9 100644
65894 --- a/init/init_task.c
65895 +++ b/init/init_task.c
65896 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65897 * Initial thread structure. Alignment of this is handled by a special
65898 * linker map entry.
65899 */
65900 +#ifdef CONFIG_X86
65901 +union thread_union init_thread_union __init_task_data;
65902 +#else
65903 union thread_union init_thread_union __init_task_data =
65904 { INIT_THREAD_INFO(init_task) };
65905 +#endif
65906 diff --git a/init/initramfs.c b/init/initramfs.c
65907 index 84c6bf1..8899338 100644
65908 --- a/init/initramfs.c
65909 +++ b/init/initramfs.c
65910 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65911 }
65912 }
65913
65914 -static long __init do_utime(char *filename, time_t mtime)
65915 +static long __init do_utime(char __force_user *filename, time_t mtime)
65916 {
65917 struct timespec t[2];
65918
65919 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65920 struct dir_entry *de, *tmp;
65921 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65922 list_del(&de->list);
65923 - do_utime(de->name, de->mtime);
65924 + do_utime((char __force_user *)de->name, de->mtime);
65925 kfree(de->name);
65926 kfree(de);
65927 }
65928 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65929 if (nlink >= 2) {
65930 char *old = find_link(major, minor, ino, mode, collected);
65931 if (old)
65932 - return (sys_link(old, collected) < 0) ? -1 : 1;
65933 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65934 }
65935 return 0;
65936 }
65937 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65938 {
65939 struct stat st;
65940
65941 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65942 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65943 if (S_ISDIR(st.st_mode))
65944 - sys_rmdir(path);
65945 + sys_rmdir((char __force_user *)path);
65946 else
65947 - sys_unlink(path);
65948 + sys_unlink((char __force_user *)path);
65949 }
65950 }
65951
65952 @@ -315,7 +315,7 @@ static int __init do_name(void)
65953 int openflags = O_WRONLY|O_CREAT;
65954 if (ml != 1)
65955 openflags |= O_TRUNC;
65956 - wfd = sys_open(collected, openflags, mode);
65957 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65958
65959 if (wfd >= 0) {
65960 sys_fchown(wfd, uid, gid);
65961 @@ -327,17 +327,17 @@ static int __init do_name(void)
65962 }
65963 }
65964 } else if (S_ISDIR(mode)) {
65965 - sys_mkdir(collected, mode);
65966 - sys_chown(collected, uid, gid);
65967 - sys_chmod(collected, mode);
65968 + sys_mkdir((char __force_user *)collected, mode);
65969 + sys_chown((char __force_user *)collected, uid, gid);
65970 + sys_chmod((char __force_user *)collected, mode);
65971 dir_add(collected, mtime);
65972 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65973 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65974 if (maybe_link() == 0) {
65975 - sys_mknod(collected, mode, rdev);
65976 - sys_chown(collected, uid, gid);
65977 - sys_chmod(collected, mode);
65978 - do_utime(collected, mtime);
65979 + sys_mknod((char __force_user *)collected, mode, rdev);
65980 + sys_chown((char __force_user *)collected, uid, gid);
65981 + sys_chmod((char __force_user *)collected, mode);
65982 + do_utime((char __force_user *)collected, mtime);
65983 }
65984 }
65985 return 0;
65986 @@ -346,15 +346,15 @@ static int __init do_name(void)
65987 static int __init do_copy(void)
65988 {
65989 if (count >= body_len) {
65990 - sys_write(wfd, victim, body_len);
65991 + sys_write(wfd, (char __force_user *)victim, body_len);
65992 sys_close(wfd);
65993 - do_utime(vcollected, mtime);
65994 + do_utime((char __force_user *)vcollected, mtime);
65995 kfree(vcollected);
65996 eat(body_len);
65997 state = SkipIt;
65998 return 0;
65999 } else {
66000 - sys_write(wfd, victim, count);
66001 + sys_write(wfd, (char __force_user *)victim, count);
66002 body_len -= count;
66003 eat(count);
66004 return 1;
66005 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66006 {
66007 collected[N_ALIGN(name_len) + body_len] = '\0';
66008 clean_path(collected, 0);
66009 - sys_symlink(collected + N_ALIGN(name_len), collected);
66010 - sys_lchown(collected, uid, gid);
66011 - do_utime(collected, mtime);
66012 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66013 + sys_lchown((char __force_user *)collected, uid, gid);
66014 + do_utime((char __force_user *)collected, mtime);
66015 state = SkipIt;
66016 next_state = Reset;
66017 return 0;
66018 diff --git a/init/main.c b/init/main.c
66019 index b286730..9ff6135 100644
66020 --- a/init/main.c
66021 +++ b/init/main.c
66022 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66023 extern void tc_init(void);
66024 #endif
66025
66026 +extern void grsecurity_init(void);
66027 +
66028 /*
66029 * Debug helper: via this flag we know that we are in 'early bootup code'
66030 * where only the boot processor is running with IRQ disabled. This means
66031 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66032
66033 __setup("reset_devices", set_reset_devices);
66034
66035 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66036 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66037 +static int __init setup_grsec_proc_gid(char *str)
66038 +{
66039 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66040 + return 1;
66041 +}
66042 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66043 +#endif
66044 +
66045 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66046 +extern char pax_enter_kernel_user[];
66047 +extern char pax_exit_kernel_user[];
66048 +extern pgdval_t clone_pgd_mask;
66049 +#endif
66050 +
66051 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66052 +static int __init setup_pax_nouderef(char *str)
66053 +{
66054 +#ifdef CONFIG_X86_32
66055 + unsigned int cpu;
66056 + struct desc_struct *gdt;
66057 +
66058 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66059 + gdt = get_cpu_gdt_table(cpu);
66060 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66061 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66062 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66063 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66064 + }
66065 + loadsegment(ds, __KERNEL_DS);
66066 + loadsegment(es, __KERNEL_DS);
66067 + loadsegment(ss, __KERNEL_DS);
66068 +#else
66069 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66070 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66071 + clone_pgd_mask = ~(pgdval_t)0UL;
66072 +#endif
66073 +
66074 + return 0;
66075 +}
66076 +early_param("pax_nouderef", setup_pax_nouderef);
66077 +#endif
66078 +
66079 +#ifdef CONFIG_PAX_SOFTMODE
66080 +int pax_softmode;
66081 +
66082 +static int __init setup_pax_softmode(char *str)
66083 +{
66084 + get_option(&str, &pax_softmode);
66085 + return 1;
66086 +}
66087 +__setup("pax_softmode=", setup_pax_softmode);
66088 +#endif
66089 +
66090 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66091 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66092 static const char *panic_later, *panic_param;
66093 @@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66094 {
66095 int count = preempt_count();
66096 int ret;
66097 + const char *msg1 = "", *msg2 = "";
66098
66099 if (initcall_debug)
66100 ret = do_one_initcall_debug(fn);
66101 @@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66102 sprintf(msgbuf, "error code %d ", ret);
66103
66104 if (preempt_count() != count) {
66105 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66106 + msg1 = " preemption imbalance";
66107 preempt_count() = count;
66108 }
66109 if (irqs_disabled()) {
66110 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66111 + msg2 = " disabled interrupts";
66112 local_irq_enable();
66113 }
66114 - if (msgbuf[0]) {
66115 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66116 + if (msgbuf[0] || *msg1 || *msg2) {
66117 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66118 }
66119
66120 return ret;
66121 @@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66122 level, level,
66123 &repair_env_string);
66124
66125 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66126 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66127 do_one_initcall(*fn);
66128 +
66129 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66130 + transfer_latent_entropy();
66131 +#endif
66132 +
66133 + }
66134 }
66135
66136 static void __init do_initcalls(void)
66137 @@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66138 {
66139 initcall_t *fn;
66140
66141 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66142 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66143 do_one_initcall(*fn);
66144 +
66145 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66146 + transfer_latent_entropy();
66147 +#endif
66148 +
66149 + }
66150 }
66151
66152 static void run_init_process(const char *init_filename)
66153 @@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66154 do_basic_setup();
66155
66156 /* Open the /dev/console on the rootfs, this should never fail */
66157 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66158 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66159 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66160
66161 (void) sys_dup(0);
66162 @@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66163 if (!ramdisk_execute_command)
66164 ramdisk_execute_command = "/init";
66165
66166 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66167 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66168 ramdisk_execute_command = NULL;
66169 prepare_namespace();
66170 }
66171
66172 + grsecurity_init();
66173 +
66174 /*
66175 * Ok, we have completed the initial bootup, and
66176 * we're essentially up and running. Get rid of the
66177 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66178 index 9a08acc..e65ebe7 100644
66179 --- a/ipc/mqueue.c
66180 +++ b/ipc/mqueue.c
66181 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66182 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66183 info->attr.mq_msgsize);
66184
66185 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66186 spin_lock(&mq_lock);
66187 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66188 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66189 diff --git a/ipc/msg.c b/ipc/msg.c
66190 index 7385de2..a8180e08 100644
66191 --- a/ipc/msg.c
66192 +++ b/ipc/msg.c
66193 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66194 return security_msg_queue_associate(msq, msgflg);
66195 }
66196
66197 +static struct ipc_ops msg_ops = {
66198 + .getnew = newque,
66199 + .associate = msg_security,
66200 + .more_checks = NULL
66201 +};
66202 +
66203 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66204 {
66205 struct ipc_namespace *ns;
66206 - struct ipc_ops msg_ops;
66207 struct ipc_params msg_params;
66208
66209 ns = current->nsproxy->ipc_ns;
66210
66211 - msg_ops.getnew = newque;
66212 - msg_ops.associate = msg_security;
66213 - msg_ops.more_checks = NULL;
66214 -
66215 msg_params.key = key;
66216 msg_params.flg = msgflg;
66217
66218 diff --git a/ipc/sem.c b/ipc/sem.c
66219 index 5215a81..cfc0cac 100644
66220 --- a/ipc/sem.c
66221 +++ b/ipc/sem.c
66222 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66223 return 0;
66224 }
66225
66226 +static struct ipc_ops sem_ops = {
66227 + .getnew = newary,
66228 + .associate = sem_security,
66229 + .more_checks = sem_more_checks
66230 +};
66231 +
66232 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66233 {
66234 struct ipc_namespace *ns;
66235 - struct ipc_ops sem_ops;
66236 struct ipc_params sem_params;
66237
66238 ns = current->nsproxy->ipc_ns;
66239 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66240 if (nsems < 0 || nsems > ns->sc_semmsl)
66241 return -EINVAL;
66242
66243 - sem_ops.getnew = newary;
66244 - sem_ops.associate = sem_security;
66245 - sem_ops.more_checks = sem_more_checks;
66246 -
66247 sem_params.key = key;
66248 sem_params.flg = semflg;
66249 sem_params.u.nsems = nsems;
66250 diff --git a/ipc/shm.c b/ipc/shm.c
66251 index 00faa05..7040960 100644
66252 --- a/ipc/shm.c
66253 +++ b/ipc/shm.c
66254 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66255 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66256 #endif
66257
66258 +#ifdef CONFIG_GRKERNSEC
66259 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66260 + const time_t shm_createtime, const uid_t cuid,
66261 + const int shmid);
66262 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66263 + const time_t shm_createtime);
66264 +#endif
66265 +
66266 void shm_init_ns(struct ipc_namespace *ns)
66267 {
66268 ns->shm_ctlmax = SHMMAX;
66269 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66270 shp->shm_lprid = 0;
66271 shp->shm_atim = shp->shm_dtim = 0;
66272 shp->shm_ctim = get_seconds();
66273 +#ifdef CONFIG_GRKERNSEC
66274 + {
66275 + struct timespec timeval;
66276 + do_posix_clock_monotonic_gettime(&timeval);
66277 +
66278 + shp->shm_createtime = timeval.tv_sec;
66279 + }
66280 +#endif
66281 shp->shm_segsz = size;
66282 shp->shm_nattch = 0;
66283 shp->shm_file = file;
66284 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66285 return 0;
66286 }
66287
66288 +static struct ipc_ops shm_ops = {
66289 + .getnew = newseg,
66290 + .associate = shm_security,
66291 + .more_checks = shm_more_checks
66292 +};
66293 +
66294 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66295 {
66296 struct ipc_namespace *ns;
66297 - struct ipc_ops shm_ops;
66298 struct ipc_params shm_params;
66299
66300 ns = current->nsproxy->ipc_ns;
66301
66302 - shm_ops.getnew = newseg;
66303 - shm_ops.associate = shm_security;
66304 - shm_ops.more_checks = shm_more_checks;
66305 -
66306 shm_params.key = key;
66307 shm_params.flg = shmflg;
66308 shm_params.u.size = size;
66309 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66310 f_mode = FMODE_READ | FMODE_WRITE;
66311 }
66312 if (shmflg & SHM_EXEC) {
66313 +
66314 +#ifdef CONFIG_PAX_MPROTECT
66315 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66316 + goto out;
66317 +#endif
66318 +
66319 prot |= PROT_EXEC;
66320 acc_mode |= S_IXUGO;
66321 }
66322 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66323 if (err)
66324 goto out_unlock;
66325
66326 +#ifdef CONFIG_GRKERNSEC
66327 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66328 + shp->shm_perm.cuid, shmid) ||
66329 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66330 + err = -EACCES;
66331 + goto out_unlock;
66332 + }
66333 +#endif
66334 +
66335 path = shp->shm_file->f_path;
66336 path_get(&path);
66337 shp->shm_nattch++;
66338 +#ifdef CONFIG_GRKERNSEC
66339 + shp->shm_lapid = current->pid;
66340 +#endif
66341 size = i_size_read(path.dentry->d_inode);
66342 shm_unlock(shp);
66343
66344 diff --git a/kernel/acct.c b/kernel/acct.c
66345 index 02e6167..54824f7 100644
66346 --- a/kernel/acct.c
66347 +++ b/kernel/acct.c
66348 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66349 */
66350 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66351 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66352 - file->f_op->write(file, (char *)&ac,
66353 + file->f_op->write(file, (char __force_user *)&ac,
66354 sizeof(acct_t), &file->f_pos);
66355 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66356 set_fs(fs);
66357 diff --git a/kernel/audit.c b/kernel/audit.c
66358 index a8c84be..8bd034c 100644
66359 --- a/kernel/audit.c
66360 +++ b/kernel/audit.c
66361 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66362 3) suppressed due to audit_rate_limit
66363 4) suppressed due to audit_backlog_limit
66364 */
66365 -static atomic_t audit_lost = ATOMIC_INIT(0);
66366 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66367
66368 /* The netlink socket. */
66369 static struct sock *audit_sock;
66370 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66371 unsigned long now;
66372 int print;
66373
66374 - atomic_inc(&audit_lost);
66375 + atomic_inc_unchecked(&audit_lost);
66376
66377 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66378
66379 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66380 printk(KERN_WARNING
66381 "audit: audit_lost=%d audit_rate_limit=%d "
66382 "audit_backlog_limit=%d\n",
66383 - atomic_read(&audit_lost),
66384 + atomic_read_unchecked(&audit_lost),
66385 audit_rate_limit,
66386 audit_backlog_limit);
66387 audit_panic(message);
66388 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66389 status_set.pid = audit_pid;
66390 status_set.rate_limit = audit_rate_limit;
66391 status_set.backlog_limit = audit_backlog_limit;
66392 - status_set.lost = atomic_read(&audit_lost);
66393 + status_set.lost = atomic_read_unchecked(&audit_lost);
66394 status_set.backlog = skb_queue_len(&audit_skb_queue);
66395 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66396 &status_set, sizeof(status_set));
66397 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66398 index 4b96415..d8c16ee 100644
66399 --- a/kernel/auditsc.c
66400 +++ b/kernel/auditsc.c
66401 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66402 }
66403
66404 /* global counter which is incremented every time something logs in */
66405 -static atomic_t session_id = ATOMIC_INIT(0);
66406 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66407
66408 /**
66409 * audit_set_loginuid - set current task's audit_context loginuid
66410 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66411 return -EPERM;
66412 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66413
66414 - sessionid = atomic_inc_return(&session_id);
66415 + sessionid = atomic_inc_return_unchecked(&session_id);
66416 if (context && context->in_syscall) {
66417 struct audit_buffer *ab;
66418
66419 diff --git a/kernel/capability.c b/kernel/capability.c
66420 index 493d972..ea17248 100644
66421 --- a/kernel/capability.c
66422 +++ b/kernel/capability.c
66423 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66424 * before modification is attempted and the application
66425 * fails.
66426 */
66427 + if (tocopy > ARRAY_SIZE(kdata))
66428 + return -EFAULT;
66429 +
66430 if (copy_to_user(dataptr, kdata, tocopy
66431 * sizeof(struct __user_cap_data_struct))) {
66432 return -EFAULT;
66433 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66434 int ret;
66435
66436 rcu_read_lock();
66437 - ret = security_capable(__task_cred(t), ns, cap);
66438 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66439 + gr_task_is_capable(t, __task_cred(t), cap);
66440 rcu_read_unlock();
66441
66442 - return (ret == 0);
66443 + return ret;
66444 }
66445
66446 /**
66447 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66448 int ret;
66449
66450 rcu_read_lock();
66451 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66452 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66453 rcu_read_unlock();
66454
66455 - return (ret == 0);
66456 + return ret;
66457 }
66458
66459 /**
66460 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66461 BUG();
66462 }
66463
66464 - if (security_capable(current_cred(), ns, cap) == 0) {
66465 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66466 current->flags |= PF_SUPERPRIV;
66467 return true;
66468 }
66469 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66470 }
66471 EXPORT_SYMBOL(ns_capable);
66472
66473 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66474 +{
66475 + if (unlikely(!cap_valid(cap))) {
66476 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66477 + BUG();
66478 + }
66479 +
66480 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66481 + current->flags |= PF_SUPERPRIV;
66482 + return true;
66483 + }
66484 + return false;
66485 +}
66486 +EXPORT_SYMBOL(ns_capable_nolog);
66487 +
66488 /**
66489 * capable - Determine if the current task has a superior capability in effect
66490 * @cap: The capability to be tested for
66491 @@ -408,6 +427,12 @@ bool capable(int cap)
66492 }
66493 EXPORT_SYMBOL(capable);
66494
66495 +bool capable_nolog(int cap)
66496 +{
66497 + return ns_capable_nolog(&init_user_ns, cap);
66498 +}
66499 +EXPORT_SYMBOL(capable_nolog);
66500 +
66501 /**
66502 * nsown_capable - Check superior capability to one's own user_ns
66503 * @cap: The capability in question
66504 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66505
66506 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66507 }
66508 +
66509 +bool inode_capable_nolog(const struct inode *inode, int cap)
66510 +{
66511 + struct user_namespace *ns = current_user_ns();
66512 +
66513 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66514 +}
66515 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66516 index 7981850..370878f 100644
66517 --- a/kernel/cgroup.c
66518 +++ b/kernel/cgroup.c
66519 @@ -5411,7 +5411,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66520 struct css_set *cg = link->cg;
66521 struct task_struct *task;
66522 int count = 0;
66523 - seq_printf(seq, "css_set %p\n", cg);
66524 + seq_printf(seq, "css_set %pK\n", cg);
66525 list_for_each_entry(task, &cg->tasks, cg_list) {
66526 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66527 seq_puts(seq, " ...\n");
66528 diff --git a/kernel/compat.c b/kernel/compat.c
66529 index c28a306..b4d0cf3 100644
66530 --- a/kernel/compat.c
66531 +++ b/kernel/compat.c
66532 @@ -13,6 +13,7 @@
66533
66534 #include <linux/linkage.h>
66535 #include <linux/compat.h>
66536 +#include <linux/module.h>
66537 #include <linux/errno.h>
66538 #include <linux/time.h>
66539 #include <linux/signal.h>
66540 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66541 mm_segment_t oldfs;
66542 long ret;
66543
66544 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66545 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66546 oldfs = get_fs();
66547 set_fs(KERNEL_DS);
66548 ret = hrtimer_nanosleep_restart(restart);
66549 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66550 oldfs = get_fs();
66551 set_fs(KERNEL_DS);
66552 ret = hrtimer_nanosleep(&tu,
66553 - rmtp ? (struct timespec __user *)&rmt : NULL,
66554 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66555 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66556 set_fs(oldfs);
66557
66558 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66559 mm_segment_t old_fs = get_fs();
66560
66561 set_fs(KERNEL_DS);
66562 - ret = sys_sigpending((old_sigset_t __user *) &s);
66563 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66564 set_fs(old_fs);
66565 if (ret == 0)
66566 ret = put_user(s, set);
66567 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66568 mm_segment_t old_fs = get_fs();
66569
66570 set_fs(KERNEL_DS);
66571 - ret = sys_old_getrlimit(resource, &r);
66572 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66573 set_fs(old_fs);
66574
66575 if (!ret) {
66576 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66577 mm_segment_t old_fs = get_fs();
66578
66579 set_fs(KERNEL_DS);
66580 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66581 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66582 set_fs(old_fs);
66583
66584 if (ret)
66585 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66586 set_fs (KERNEL_DS);
66587 ret = sys_wait4(pid,
66588 (stat_addr ?
66589 - (unsigned int __user *) &status : NULL),
66590 - options, (struct rusage __user *) &r);
66591 + (unsigned int __force_user *) &status : NULL),
66592 + options, (struct rusage __force_user *) &r);
66593 set_fs (old_fs);
66594
66595 if (ret > 0) {
66596 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66597 memset(&info, 0, sizeof(info));
66598
66599 set_fs(KERNEL_DS);
66600 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66601 - uru ? (struct rusage __user *)&ru : NULL);
66602 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66603 + uru ? (struct rusage __force_user *)&ru : NULL);
66604 set_fs(old_fs);
66605
66606 if ((ret < 0) || (info.si_signo == 0))
66607 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66608 oldfs = get_fs();
66609 set_fs(KERNEL_DS);
66610 err = sys_timer_settime(timer_id, flags,
66611 - (struct itimerspec __user *) &newts,
66612 - (struct itimerspec __user *) &oldts);
66613 + (struct itimerspec __force_user *) &newts,
66614 + (struct itimerspec __force_user *) &oldts);
66615 set_fs(oldfs);
66616 if (!err && old && put_compat_itimerspec(old, &oldts))
66617 return -EFAULT;
66618 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66619 oldfs = get_fs();
66620 set_fs(KERNEL_DS);
66621 err = sys_timer_gettime(timer_id,
66622 - (struct itimerspec __user *) &ts);
66623 + (struct itimerspec __force_user *) &ts);
66624 set_fs(oldfs);
66625 if (!err && put_compat_itimerspec(setting, &ts))
66626 return -EFAULT;
66627 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66628 oldfs = get_fs();
66629 set_fs(KERNEL_DS);
66630 err = sys_clock_settime(which_clock,
66631 - (struct timespec __user *) &ts);
66632 + (struct timespec __force_user *) &ts);
66633 set_fs(oldfs);
66634 return err;
66635 }
66636 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66637 oldfs = get_fs();
66638 set_fs(KERNEL_DS);
66639 err = sys_clock_gettime(which_clock,
66640 - (struct timespec __user *) &ts);
66641 + (struct timespec __force_user *) &ts);
66642 set_fs(oldfs);
66643 if (!err && put_compat_timespec(&ts, tp))
66644 return -EFAULT;
66645 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66646
66647 oldfs = get_fs();
66648 set_fs(KERNEL_DS);
66649 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66650 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66651 set_fs(oldfs);
66652
66653 err = compat_put_timex(utp, &txc);
66654 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66655 oldfs = get_fs();
66656 set_fs(KERNEL_DS);
66657 err = sys_clock_getres(which_clock,
66658 - (struct timespec __user *) &ts);
66659 + (struct timespec __force_user *) &ts);
66660 set_fs(oldfs);
66661 if (!err && tp && put_compat_timespec(&ts, tp))
66662 return -EFAULT;
66663 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66664 long err;
66665 mm_segment_t oldfs;
66666 struct timespec tu;
66667 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66668 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66669
66670 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66671 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66672 oldfs = get_fs();
66673 set_fs(KERNEL_DS);
66674 err = clock_nanosleep_restart(restart);
66675 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66676 oldfs = get_fs();
66677 set_fs(KERNEL_DS);
66678 err = sys_clock_nanosleep(which_clock, flags,
66679 - (struct timespec __user *) &in,
66680 - (struct timespec __user *) &out);
66681 + (struct timespec __force_user *) &in,
66682 + (struct timespec __force_user *) &out);
66683 set_fs(oldfs);
66684
66685 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66686 diff --git a/kernel/configs.c b/kernel/configs.c
66687 index 42e8fa0..9e7406b 100644
66688 --- a/kernel/configs.c
66689 +++ b/kernel/configs.c
66690 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66691 struct proc_dir_entry *entry;
66692
66693 /* create the current config file */
66694 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66695 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66696 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66697 + &ikconfig_file_ops);
66698 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66699 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66700 + &ikconfig_file_ops);
66701 +#endif
66702 +#else
66703 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66704 &ikconfig_file_ops);
66705 +#endif
66706 +
66707 if (!entry)
66708 return -ENOMEM;
66709
66710 diff --git a/kernel/cred.c b/kernel/cred.c
66711 index de728ac..e3c267c 100644
66712 --- a/kernel/cred.c
66713 +++ b/kernel/cred.c
66714 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66715 validate_creds(cred);
66716 alter_cred_subscribers(cred, -1);
66717 put_cred(cred);
66718 +
66719 +#ifdef CONFIG_GRKERNSEC_SETXID
66720 + cred = (struct cred *) tsk->delayed_cred;
66721 + if (cred != NULL) {
66722 + tsk->delayed_cred = NULL;
66723 + validate_creds(cred);
66724 + alter_cred_subscribers(cred, -1);
66725 + put_cred(cred);
66726 + }
66727 +#endif
66728 }
66729
66730 /**
66731 @@ -469,7 +479,7 @@ error_put:
66732 * Always returns 0 thus allowing this function to be tail-called at the end
66733 * of, say, sys_setgid().
66734 */
66735 -int commit_creds(struct cred *new)
66736 +static int __commit_creds(struct cred *new)
66737 {
66738 struct task_struct *task = current;
66739 const struct cred *old = task->real_cred;
66740 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66741
66742 get_cred(new); /* we will require a ref for the subj creds too */
66743
66744 + gr_set_role_label(task, new->uid, new->gid);
66745 +
66746 /* dumpability changes */
66747 if (!uid_eq(old->euid, new->euid) ||
66748 !gid_eq(old->egid, new->egid) ||
66749 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66750 put_cred(old);
66751 return 0;
66752 }
66753 +#ifdef CONFIG_GRKERNSEC_SETXID
66754 +extern int set_user(struct cred *new);
66755 +
66756 +void gr_delayed_cred_worker(void)
66757 +{
66758 + const struct cred *new = current->delayed_cred;
66759 + struct cred *ncred;
66760 +
66761 + current->delayed_cred = NULL;
66762 +
66763 + if (current_uid() && new != NULL) {
66764 + // from doing get_cred on it when queueing this
66765 + put_cred(new);
66766 + return;
66767 + } else if (new == NULL)
66768 + return;
66769 +
66770 + ncred = prepare_creds();
66771 + if (!ncred)
66772 + goto die;
66773 + // uids
66774 + ncred->uid = new->uid;
66775 + ncred->euid = new->euid;
66776 + ncred->suid = new->suid;
66777 + ncred->fsuid = new->fsuid;
66778 + // gids
66779 + ncred->gid = new->gid;
66780 + ncred->egid = new->egid;
66781 + ncred->sgid = new->sgid;
66782 + ncred->fsgid = new->fsgid;
66783 + // groups
66784 + if (set_groups(ncred, new->group_info) < 0) {
66785 + abort_creds(ncred);
66786 + goto die;
66787 + }
66788 + // caps
66789 + ncred->securebits = new->securebits;
66790 + ncred->cap_inheritable = new->cap_inheritable;
66791 + ncred->cap_permitted = new->cap_permitted;
66792 + ncred->cap_effective = new->cap_effective;
66793 + ncred->cap_bset = new->cap_bset;
66794 +
66795 + if (set_user(ncred)) {
66796 + abort_creds(ncred);
66797 + goto die;
66798 + }
66799 +
66800 + // from doing get_cred on it when queueing this
66801 + put_cred(new);
66802 +
66803 + __commit_creds(ncred);
66804 + return;
66805 +die:
66806 + // from doing get_cred on it when queueing this
66807 + put_cred(new);
66808 + do_group_exit(SIGKILL);
66809 +}
66810 +#endif
66811 +
66812 +int commit_creds(struct cred *new)
66813 +{
66814 +#ifdef CONFIG_GRKERNSEC_SETXID
66815 + int ret;
66816 + int schedule_it = 0;
66817 + struct task_struct *t;
66818 +
66819 + /* we won't get called with tasklist_lock held for writing
66820 + and interrupts disabled as the cred struct in that case is
66821 + init_cred
66822 + */
66823 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66824 + !current_uid() && new->uid) {
66825 + schedule_it = 1;
66826 + }
66827 + ret = __commit_creds(new);
66828 + if (schedule_it) {
66829 + rcu_read_lock();
66830 + read_lock(&tasklist_lock);
66831 + for (t = next_thread(current); t != current;
66832 + t = next_thread(t)) {
66833 + if (t->delayed_cred == NULL) {
66834 + t->delayed_cred = get_cred(new);
66835 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66836 + set_tsk_need_resched(t);
66837 + }
66838 + }
66839 + read_unlock(&tasklist_lock);
66840 + rcu_read_unlock();
66841 + }
66842 + return ret;
66843 +#else
66844 + return __commit_creds(new);
66845 +#endif
66846 +}
66847 +
66848 EXPORT_SYMBOL(commit_creds);
66849
66850 /**
66851 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66852 index 0557f24..1a00d9a 100644
66853 --- a/kernel/debug/debug_core.c
66854 +++ b/kernel/debug/debug_core.c
66855 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66856 */
66857 static atomic_t masters_in_kgdb;
66858 static atomic_t slaves_in_kgdb;
66859 -static atomic_t kgdb_break_tasklet_var;
66860 +static atomic_unchecked_t kgdb_break_tasklet_var;
66861 atomic_t kgdb_setting_breakpoint;
66862
66863 struct task_struct *kgdb_usethread;
66864 @@ -132,7 +132,7 @@ int kgdb_single_step;
66865 static pid_t kgdb_sstep_pid;
66866
66867 /* to keep track of the CPU which is doing the single stepping*/
66868 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66869 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66870
66871 /*
66872 * If you are debugging a problem where roundup (the collection of
66873 @@ -540,7 +540,7 @@ return_normal:
66874 * kernel will only try for the value of sstep_tries before
66875 * giving up and continuing on.
66876 */
66877 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66878 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66879 (kgdb_info[cpu].task &&
66880 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66881 atomic_set(&kgdb_active, -1);
66882 @@ -634,8 +634,8 @@ cpu_master_loop:
66883 }
66884
66885 kgdb_restore:
66886 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66887 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66888 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66889 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66890 if (kgdb_info[sstep_cpu].task)
66891 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66892 else
66893 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66894 static void kgdb_tasklet_bpt(unsigned long ing)
66895 {
66896 kgdb_breakpoint();
66897 - atomic_set(&kgdb_break_tasklet_var, 0);
66898 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66899 }
66900
66901 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66902
66903 void kgdb_schedule_breakpoint(void)
66904 {
66905 - if (atomic_read(&kgdb_break_tasklet_var) ||
66906 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66907 atomic_read(&kgdb_active) != -1 ||
66908 atomic_read(&kgdb_setting_breakpoint))
66909 return;
66910 - atomic_inc(&kgdb_break_tasklet_var);
66911 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66912 tasklet_schedule(&kgdb_tasklet_breakpoint);
66913 }
66914 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66915 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66916 index 31df170..bc98840 100644
66917 --- a/kernel/debug/kdb/kdb_main.c
66918 +++ b/kernel/debug/kdb/kdb_main.c
66919 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66920 list_for_each_entry(mod, kdb_modules, list) {
66921
66922 kdb_printf("%-20s%8u 0x%p ", mod->name,
66923 - mod->core_size, (void *)mod);
66924 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66925 #ifdef CONFIG_MODULE_UNLOAD
66926 kdb_printf("%4ld ", module_refcount(mod));
66927 #endif
66928 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66929 kdb_printf(" (Loading)");
66930 else
66931 kdb_printf(" (Live)");
66932 - kdb_printf(" 0x%p", mod->module_core);
66933 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66934
66935 #ifdef CONFIG_MODULE_UNLOAD
66936 {
66937 diff --git a/kernel/events/core.c b/kernel/events/core.c
66938 index 7fee567..8affa2c 100644
66939 --- a/kernel/events/core.c
66940 +++ b/kernel/events/core.c
66941 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66942 return 0;
66943 }
66944
66945 -static atomic64_t perf_event_id;
66946 +static atomic64_unchecked_t perf_event_id;
66947
66948 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66949 enum event_type_t event_type);
66950 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66951
66952 static inline u64 perf_event_count(struct perf_event *event)
66953 {
66954 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66955 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66956 }
66957
66958 static u64 perf_event_read(struct perf_event *event)
66959 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66960 mutex_lock(&event->child_mutex);
66961 total += perf_event_read(event);
66962 *enabled += event->total_time_enabled +
66963 - atomic64_read(&event->child_total_time_enabled);
66964 + atomic64_read_unchecked(&event->child_total_time_enabled);
66965 *running += event->total_time_running +
66966 - atomic64_read(&event->child_total_time_running);
66967 + atomic64_read_unchecked(&event->child_total_time_running);
66968
66969 list_for_each_entry(child, &event->child_list, child_list) {
66970 total += perf_event_read(child);
66971 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66972 userpg->offset -= local64_read(&event->hw.prev_count);
66973
66974 userpg->time_enabled = enabled +
66975 - atomic64_read(&event->child_total_time_enabled);
66976 + atomic64_read_unchecked(&event->child_total_time_enabled);
66977
66978 userpg->time_running = running +
66979 - atomic64_read(&event->child_total_time_running);
66980 + atomic64_read_unchecked(&event->child_total_time_running);
66981
66982 arch_perf_update_userpage(userpg, now);
66983
66984 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66985 values[n++] = perf_event_count(event);
66986 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66987 values[n++] = enabled +
66988 - atomic64_read(&event->child_total_time_enabled);
66989 + atomic64_read_unchecked(&event->child_total_time_enabled);
66990 }
66991 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66992 values[n++] = running +
66993 - atomic64_read(&event->child_total_time_running);
66994 + atomic64_read_unchecked(&event->child_total_time_running);
66995 }
66996 if (read_format & PERF_FORMAT_ID)
66997 values[n++] = primary_event_id(event);
66998 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66999 * need to add enough zero bytes after the string to handle
67000 * the 64bit alignment we do later.
67001 */
67002 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67003 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67004 if (!buf) {
67005 name = strncpy(tmp, "//enomem", sizeof(tmp));
67006 goto got_name;
67007 }
67008 - name = d_path(&file->f_path, buf, PATH_MAX);
67009 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67010 if (IS_ERR(name)) {
67011 name = strncpy(tmp, "//toolong", sizeof(tmp));
67012 goto got_name;
67013 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67014 event->parent = parent_event;
67015
67016 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67017 - event->id = atomic64_inc_return(&perf_event_id);
67018 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67019
67020 event->state = PERF_EVENT_STATE_INACTIVE;
67021
67022 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67023 /*
67024 * Add back the child's count to the parent's count:
67025 */
67026 - atomic64_add(child_val, &parent_event->child_count);
67027 - atomic64_add(child_event->total_time_enabled,
67028 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67029 + atomic64_add_unchecked(child_event->total_time_enabled,
67030 &parent_event->child_total_time_enabled);
67031 - atomic64_add(child_event->total_time_running,
67032 + atomic64_add_unchecked(child_event->total_time_running,
67033 &parent_event->child_total_time_running);
67034
67035 /*
67036 diff --git a/kernel/exit.c b/kernel/exit.c
67037 index f65345f9..9c28dab 100644
67038 --- a/kernel/exit.c
67039 +++ b/kernel/exit.c
67040 @@ -59,6 +59,10 @@
67041 #include <asm/pgtable.h>
67042 #include <asm/mmu_context.h>
67043
67044 +#ifdef CONFIG_GRKERNSEC
67045 +extern rwlock_t grsec_exec_file_lock;
67046 +#endif
67047 +
67048 static void exit_mm(struct task_struct * tsk);
67049
67050 static void __unhash_process(struct task_struct *p, bool group_dead)
67051 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67052 struct task_struct *leader;
67053 int zap_leader;
67054 repeat:
67055 +#ifdef CONFIG_NET
67056 + gr_del_task_from_ip_table(p);
67057 +#endif
67058 +
67059 /* don't need to get the RCU readlock here - the process is dead and
67060 * can't be modifying its own credentials. But shut RCU-lockdep up */
67061 rcu_read_lock();
67062 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67063 * know it'll be handled, so that they don't get converted to
67064 * SIGKILL or just silently dropped.
67065 */
67066 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67067 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67068 recalc_sigpending();
67069 spin_unlock_irq(&current->sighand->siglock);
67070 return 0;
67071 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67072 vsnprintf(current->comm, sizeof(current->comm), name, args);
67073 va_end(args);
67074
67075 +#ifdef CONFIG_GRKERNSEC
67076 + write_lock(&grsec_exec_file_lock);
67077 + if (current->exec_file) {
67078 + fput(current->exec_file);
67079 + current->exec_file = NULL;
67080 + }
67081 + write_unlock(&grsec_exec_file_lock);
67082 +#endif
67083 +
67084 + gr_set_kernel_label(current);
67085 +
67086 /*
67087 * If we were started as result of loading a module, close all of the
67088 * user space pages. We don't need them, and if we didn't close them
67089 @@ -907,6 +926,8 @@ void do_exit(long code)
67090 struct task_struct *tsk = current;
67091 int group_dead;
67092
67093 + set_fs(USER_DS);
67094 +
67095 profile_task_exit(tsk);
67096
67097 WARN_ON(blk_needs_flush_plug(tsk));
67098 @@ -923,7 +944,6 @@ void do_exit(long code)
67099 * mm_release()->clear_child_tid() from writing to a user-controlled
67100 * kernel address.
67101 */
67102 - set_fs(USER_DS);
67103
67104 ptrace_event(PTRACE_EVENT_EXIT, code);
67105
67106 @@ -982,6 +1002,9 @@ void do_exit(long code)
67107 tsk->exit_code = code;
67108 taskstats_exit(tsk, group_dead);
67109
67110 + gr_acl_handle_psacct(tsk, code);
67111 + gr_acl_handle_exit();
67112 +
67113 exit_mm(tsk);
67114
67115 if (group_dead)
67116 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67117 * Take down every thread in the group. This is called by fatal signals
67118 * as well as by sys_exit_group (below).
67119 */
67120 -void
67121 +__noreturn void
67122 do_group_exit(int exit_code)
67123 {
67124 struct signal_struct *sig = current->signal;
67125 diff --git a/kernel/fork.c b/kernel/fork.c
67126 index 2c8857e..288c9c7 100644
67127 --- a/kernel/fork.c
67128 +++ b/kernel/fork.c
67129 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67130 *stackend = STACK_END_MAGIC; /* for overflow detection */
67131
67132 #ifdef CONFIG_CC_STACKPROTECTOR
67133 - tsk->stack_canary = get_random_int();
67134 + tsk->stack_canary = pax_get_random_long();
67135 #endif
67136
67137 /*
67138 @@ -343,13 +343,78 @@ free_tsk:
67139 }
67140
67141 #ifdef CONFIG_MMU
67142 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67143 +{
67144 + struct vm_area_struct *tmp;
67145 + unsigned long charge;
67146 + struct mempolicy *pol;
67147 + struct file *file;
67148 +
67149 + charge = 0;
67150 + if (mpnt->vm_flags & VM_ACCOUNT) {
67151 + unsigned long len = vma_pages(mpnt);
67152 +
67153 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67154 + goto fail_nomem;
67155 + charge = len;
67156 + }
67157 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67158 + if (!tmp)
67159 + goto fail_nomem;
67160 + *tmp = *mpnt;
67161 + tmp->vm_mm = mm;
67162 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67163 + pol = mpol_dup(vma_policy(mpnt));
67164 + if (IS_ERR(pol))
67165 + goto fail_nomem_policy;
67166 + vma_set_policy(tmp, pol);
67167 + if (anon_vma_fork(tmp, mpnt))
67168 + goto fail_nomem_anon_vma_fork;
67169 + tmp->vm_flags &= ~VM_LOCKED;
67170 + tmp->vm_next = tmp->vm_prev = NULL;
67171 + tmp->vm_mirror = NULL;
67172 + file = tmp->vm_file;
67173 + if (file) {
67174 + struct inode *inode = file->f_path.dentry->d_inode;
67175 + struct address_space *mapping = file->f_mapping;
67176 +
67177 + get_file(file);
67178 + if (tmp->vm_flags & VM_DENYWRITE)
67179 + atomic_dec(&inode->i_writecount);
67180 + mutex_lock(&mapping->i_mmap_mutex);
67181 + if (tmp->vm_flags & VM_SHARED)
67182 + mapping->i_mmap_writable++;
67183 + flush_dcache_mmap_lock(mapping);
67184 + /* insert tmp into the share list, just after mpnt */
67185 + vma_prio_tree_add(tmp, mpnt);
67186 + flush_dcache_mmap_unlock(mapping);
67187 + mutex_unlock(&mapping->i_mmap_mutex);
67188 + }
67189 +
67190 + /*
67191 + * Clear hugetlb-related page reserves for children. This only
67192 + * affects MAP_PRIVATE mappings. Faults generated by the child
67193 + * are not guaranteed to succeed, even if read-only
67194 + */
67195 + if (is_vm_hugetlb_page(tmp))
67196 + reset_vma_resv_huge_pages(tmp);
67197 +
67198 + return tmp;
67199 +
67200 +fail_nomem_anon_vma_fork:
67201 + mpol_put(pol);
67202 +fail_nomem_policy:
67203 + kmem_cache_free(vm_area_cachep, tmp);
67204 +fail_nomem:
67205 + vm_unacct_memory(charge);
67206 + return NULL;
67207 +}
67208 +
67209 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67210 {
67211 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67212 struct rb_node **rb_link, *rb_parent;
67213 int retval;
67214 - unsigned long charge;
67215 - struct mempolicy *pol;
67216
67217 down_write(&oldmm->mmap_sem);
67218 flush_cache_dup_mm(oldmm);
67219 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67220 mm->locked_vm = 0;
67221 mm->mmap = NULL;
67222 mm->mmap_cache = NULL;
67223 - mm->free_area_cache = oldmm->mmap_base;
67224 - mm->cached_hole_size = ~0UL;
67225 + mm->free_area_cache = oldmm->free_area_cache;
67226 + mm->cached_hole_size = oldmm->cached_hole_size;
67227 mm->map_count = 0;
67228 cpumask_clear(mm_cpumask(mm));
67229 mm->mm_rb = RB_ROOT;
67230 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67231
67232 prev = NULL;
67233 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67234 - struct file *file;
67235 -
67236 if (mpnt->vm_flags & VM_DONTCOPY) {
67237 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67238 -vma_pages(mpnt));
67239 continue;
67240 }
67241 - charge = 0;
67242 - if (mpnt->vm_flags & VM_ACCOUNT) {
67243 - unsigned long len = vma_pages(mpnt);
67244 -
67245 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67246 - goto fail_nomem;
67247 - charge = len;
67248 - }
67249 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67250 - if (!tmp)
67251 - goto fail_nomem;
67252 - *tmp = *mpnt;
67253 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67254 - pol = mpol_dup(vma_policy(mpnt));
67255 - retval = PTR_ERR(pol);
67256 - if (IS_ERR(pol))
67257 - goto fail_nomem_policy;
67258 - vma_set_policy(tmp, pol);
67259 - tmp->vm_mm = mm;
67260 - if (anon_vma_fork(tmp, mpnt))
67261 - goto fail_nomem_anon_vma_fork;
67262 - tmp->vm_flags &= ~VM_LOCKED;
67263 - tmp->vm_next = tmp->vm_prev = NULL;
67264 - file = tmp->vm_file;
67265 - if (file) {
67266 - struct inode *inode = file->f_path.dentry->d_inode;
67267 - struct address_space *mapping = file->f_mapping;
67268 -
67269 - get_file(file);
67270 - if (tmp->vm_flags & VM_DENYWRITE)
67271 - atomic_dec(&inode->i_writecount);
67272 - mutex_lock(&mapping->i_mmap_mutex);
67273 - if (tmp->vm_flags & VM_SHARED)
67274 - mapping->i_mmap_writable++;
67275 - flush_dcache_mmap_lock(mapping);
67276 - /* insert tmp into the share list, just after mpnt */
67277 - vma_prio_tree_add(tmp, mpnt);
67278 - flush_dcache_mmap_unlock(mapping);
67279 - mutex_unlock(&mapping->i_mmap_mutex);
67280 + tmp = dup_vma(mm, oldmm, mpnt);
67281 + if (!tmp) {
67282 + retval = -ENOMEM;
67283 + goto out;
67284 }
67285
67286 /*
67287 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67288 if (retval)
67289 goto out;
67290
67291 - if (file)
67292 + if (tmp->vm_file)
67293 uprobe_mmap(tmp);
67294 }
67295 +
67296 +#ifdef CONFIG_PAX_SEGMEXEC
67297 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67298 + struct vm_area_struct *mpnt_m;
67299 +
67300 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67301 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67302 +
67303 + if (!mpnt->vm_mirror)
67304 + continue;
67305 +
67306 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67307 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67308 + mpnt->vm_mirror = mpnt_m;
67309 + } else {
67310 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67311 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67312 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67313 + mpnt->vm_mirror->vm_mirror = mpnt;
67314 + }
67315 + }
67316 + BUG_ON(mpnt_m);
67317 + }
67318 +#endif
67319 +
67320 /* a new mm has just been created */
67321 arch_dup_mmap(oldmm, mm);
67322 retval = 0;
67323 @@ -466,14 +519,6 @@ out:
67324 flush_tlb_mm(oldmm);
67325 up_write(&oldmm->mmap_sem);
67326 return retval;
67327 -fail_nomem_anon_vma_fork:
67328 - mpol_put(pol);
67329 -fail_nomem_policy:
67330 - kmem_cache_free(vm_area_cachep, tmp);
67331 -fail_nomem:
67332 - retval = -ENOMEM;
67333 - vm_unacct_memory(charge);
67334 - goto out;
67335 }
67336
67337 static inline int mm_alloc_pgd(struct mm_struct *mm)
67338 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67339 return ERR_PTR(err);
67340
67341 mm = get_task_mm(task);
67342 - if (mm && mm != current->mm &&
67343 - !ptrace_may_access(task, mode)) {
67344 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67345 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67346 mmput(mm);
67347 mm = ERR_PTR(-EACCES);
67348 }
67349 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67350 spin_unlock(&fs->lock);
67351 return -EAGAIN;
67352 }
67353 - fs->users++;
67354 + atomic_inc(&fs->users);
67355 spin_unlock(&fs->lock);
67356 return 0;
67357 }
67358 tsk->fs = copy_fs_struct(fs);
67359 if (!tsk->fs)
67360 return -ENOMEM;
67361 + /* Carry through gr_chroot_dentry and is_chrooted instead
67362 + of recomputing it here. Already copied when the task struct
67363 + is duplicated. This allows pivot_root to not be treated as
67364 + a chroot
67365 + */
67366 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67367 +
67368 return 0;
67369 }
67370
67371 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67372 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67373 #endif
67374 retval = -EAGAIN;
67375 +
67376 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67377 +
67378 if (atomic_read(&p->real_cred->user->processes) >=
67379 task_rlimit(p, RLIMIT_NPROC)) {
67380 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67381 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67382 /* Need tasklist lock for parent etc handling! */
67383 write_lock_irq(&tasklist_lock);
67384
67385 + /* synchronizes with gr_set_acls() */
67386 + gr_copy_label(p);
67387 +
67388 /* CLONE_PARENT re-uses the old parent */
67389 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67390 p->real_parent = current->real_parent;
67391 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67392 bad_fork_free:
67393 free_task(p);
67394 fork_out:
67395 + gr_log_forkfail(retval);
67396 +
67397 return ERR_PTR(retval);
67398 }
67399
67400 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67401 if (clone_flags & CLONE_PARENT_SETTID)
67402 put_user(nr, parent_tidptr);
67403
67404 + gr_handle_brute_check();
67405 +
67406 if (clone_flags & CLONE_VFORK) {
67407 p->vfork_done = &vfork;
67408 init_completion(&vfork);
67409 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67410 return 0;
67411
67412 /* don't need lock here; in the worst case we'll do useless copy */
67413 - if (fs->users == 1)
67414 + if (atomic_read(&fs->users) == 1)
67415 return 0;
67416
67417 *new_fsp = copy_fs_struct(fs);
67418 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67419 fs = current->fs;
67420 spin_lock(&fs->lock);
67421 current->fs = new_fs;
67422 - if (--fs->users)
67423 + gr_set_chroot_entries(current, &current->fs->root);
67424 + if (atomic_dec_return(&fs->users))
67425 new_fs = NULL;
67426 else
67427 new_fs = fs;
67428 diff --git a/kernel/futex.c b/kernel/futex.c
67429 index 3717e7b..473c750 100644
67430 --- a/kernel/futex.c
67431 +++ b/kernel/futex.c
67432 @@ -54,6 +54,7 @@
67433 #include <linux/mount.h>
67434 #include <linux/pagemap.h>
67435 #include <linux/syscalls.h>
67436 +#include <linux/ptrace.h>
67437 #include <linux/signal.h>
67438 #include <linux/export.h>
67439 #include <linux/magic.h>
67440 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67441 struct page *page, *page_head;
67442 int err, ro = 0;
67443
67444 +#ifdef CONFIG_PAX_SEGMEXEC
67445 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67446 + return -EFAULT;
67447 +#endif
67448 +
67449 /*
67450 * The futex address must be "naturally" aligned.
67451 */
67452 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67453 {
67454 u32 curval;
67455 int i;
67456 + mm_segment_t oldfs;
67457
67458 /*
67459 * This will fail and we want it. Some arch implementations do
67460 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67461 * implementation, the non-functional ones will return
67462 * -ENOSYS.
67463 */
67464 + oldfs = get_fs();
67465 + set_fs(USER_DS);
67466 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67467 futex_cmpxchg_enabled = 1;
67468 + set_fs(oldfs);
67469
67470 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67471 plist_head_init(&futex_queues[i].chain);
67472 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67473 index 9b22d03..6295b62 100644
67474 --- a/kernel/gcov/base.c
67475 +++ b/kernel/gcov/base.c
67476 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67477 }
67478
67479 #ifdef CONFIG_MODULES
67480 -static inline int within(void *addr, void *start, unsigned long size)
67481 -{
67482 - return ((addr >= start) && (addr < start + size));
67483 -}
67484 -
67485 /* Update list and generate events when modules are unloaded. */
67486 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67487 void *data)
67488 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67489 prev = NULL;
67490 /* Remove entries located in module from linked list. */
67491 for (info = gcov_info_head; info; info = info->next) {
67492 - if (within(info, mod->module_core, mod->core_size)) {
67493 + if (within_module_core_rw((unsigned long)info, mod)) {
67494 if (prev)
67495 prev->next = info->next;
67496 else
67497 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67498 index 6db7a5e..25b6648 100644
67499 --- a/kernel/hrtimer.c
67500 +++ b/kernel/hrtimer.c
67501 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67502 local_irq_restore(flags);
67503 }
67504
67505 -static void run_hrtimer_softirq(struct softirq_action *h)
67506 +static void run_hrtimer_softirq(void)
67507 {
67508 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67509
67510 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67511 index 4304919..408c4c0 100644
67512 --- a/kernel/jump_label.c
67513 +++ b/kernel/jump_label.c
67514 @@ -13,6 +13,7 @@
67515 #include <linux/sort.h>
67516 #include <linux/err.h>
67517 #include <linux/static_key.h>
67518 +#include <linux/mm.h>
67519
67520 #ifdef HAVE_JUMP_LABEL
67521
67522 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67523
67524 size = (((unsigned long)stop - (unsigned long)start)
67525 / sizeof(struct jump_entry));
67526 + pax_open_kernel();
67527 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67528 + pax_close_kernel();
67529 }
67530
67531 static void jump_label_update(struct static_key *key, int enable);
67532 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67533 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67534 struct jump_entry *iter;
67535
67536 + pax_open_kernel();
67537 for (iter = iter_start; iter < iter_stop; iter++) {
67538 if (within_module_init(iter->code, mod))
67539 iter->code = 0;
67540 }
67541 + pax_close_kernel();
67542 }
67543
67544 static int
67545 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67546 index 2169fee..45c017a 100644
67547 --- a/kernel/kallsyms.c
67548 +++ b/kernel/kallsyms.c
67549 @@ -11,6 +11,9 @@
67550 * Changed the compression method from stem compression to "table lookup"
67551 * compression (see scripts/kallsyms.c for a more complete description)
67552 */
67553 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67554 +#define __INCLUDED_BY_HIDESYM 1
67555 +#endif
67556 #include <linux/kallsyms.h>
67557 #include <linux/module.h>
67558 #include <linux/init.h>
67559 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67560
67561 static inline int is_kernel_inittext(unsigned long addr)
67562 {
67563 + if (system_state != SYSTEM_BOOTING)
67564 + return 0;
67565 +
67566 if (addr >= (unsigned long)_sinittext
67567 && addr <= (unsigned long)_einittext)
67568 return 1;
67569 return 0;
67570 }
67571
67572 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67573 +#ifdef CONFIG_MODULES
67574 +static inline int is_module_text(unsigned long addr)
67575 +{
67576 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67577 + return 1;
67578 +
67579 + addr = ktla_ktva(addr);
67580 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67581 +}
67582 +#else
67583 +static inline int is_module_text(unsigned long addr)
67584 +{
67585 + return 0;
67586 +}
67587 +#endif
67588 +#endif
67589 +
67590 static inline int is_kernel_text(unsigned long addr)
67591 {
67592 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67593 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67594
67595 static inline int is_kernel(unsigned long addr)
67596 {
67597 +
67598 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67599 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67600 + return 1;
67601 +
67602 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67603 +#else
67604 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67605 +#endif
67606 +
67607 return 1;
67608 return in_gate_area_no_mm(addr);
67609 }
67610
67611 static int is_ksym_addr(unsigned long addr)
67612 {
67613 +
67614 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67615 + if (is_module_text(addr))
67616 + return 0;
67617 +#endif
67618 +
67619 if (all_var)
67620 return is_kernel(addr);
67621
67622 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67623
67624 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67625 {
67626 - iter->name[0] = '\0';
67627 iter->nameoff = get_symbol_offset(new_pos);
67628 iter->pos = new_pos;
67629 }
67630 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67631 {
67632 struct kallsym_iter *iter = m->private;
67633
67634 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67635 + if (current_uid())
67636 + return 0;
67637 +#endif
67638 +
67639 /* Some debugging symbols have no name. Ignore them. */
67640 if (!iter->name[0])
67641 return 0;
67642 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67643 */
67644 type = iter->exported ? toupper(iter->type) :
67645 tolower(iter->type);
67646 +
67647 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67648 type, iter->name, iter->module_name);
67649 } else
67650 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67651 struct kallsym_iter *iter;
67652 int ret;
67653
67654 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67655 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67656 if (!iter)
67657 return -ENOMEM;
67658 reset_iter(iter, 0);
67659 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67660 index 30b7b22..c726387 100644
67661 --- a/kernel/kcmp.c
67662 +++ b/kernel/kcmp.c
67663 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67664 struct task_struct *task1, *task2;
67665 int ret;
67666
67667 +#ifdef CONFIG_GRKERNSEC
67668 + return -ENOSYS;
67669 +#endif
67670 +
67671 rcu_read_lock();
67672
67673 /*
67674 diff --git a/kernel/kexec.c b/kernel/kexec.c
67675 index 0668d58..591b6fc 100644
67676 --- a/kernel/kexec.c
67677 +++ b/kernel/kexec.c
67678 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67679 unsigned long flags)
67680 {
67681 struct compat_kexec_segment in;
67682 - struct kexec_segment out, __user *ksegments;
67683 + struct kexec_segment out;
67684 + struct kexec_segment __user *ksegments;
67685 unsigned long i, result;
67686
67687 /* Don't allow clients that don't understand the native
67688 diff --git a/kernel/kmod.c b/kernel/kmod.c
67689 index 6f99aea..eb6e3a0 100644
67690 --- a/kernel/kmod.c
67691 +++ b/kernel/kmod.c
67692 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67693 kfree(info->argv);
67694 }
67695
67696 -static int call_modprobe(char *module_name, int wait)
67697 +static int call_modprobe(char *module_name, char *module_param, int wait)
67698 {
67699 static char *envp[] = {
67700 "HOME=/",
67701 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67702 NULL
67703 };
67704
67705 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67706 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67707 if (!argv)
67708 goto out;
67709
67710 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67711 argv[1] = "-q";
67712 argv[2] = "--";
67713 argv[3] = module_name; /* check free_modprobe_argv() */
67714 - argv[4] = NULL;
67715 + argv[4] = module_param;
67716 + argv[5] = NULL;
67717
67718 return call_usermodehelper_fns(modprobe_path, argv, envp,
67719 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67720 @@ -119,9 +120,8 @@ out:
67721 * If module auto-loading support is disabled then this function
67722 * becomes a no-operation.
67723 */
67724 -int __request_module(bool wait, const char *fmt, ...)
67725 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67726 {
67727 - va_list args;
67728 char module_name[MODULE_NAME_LEN];
67729 unsigned int max_modprobes;
67730 int ret;
67731 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67732 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67733 static int kmod_loop_msg;
67734
67735 - va_start(args, fmt);
67736 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67737 - va_end(args);
67738 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67739 if (ret >= MODULE_NAME_LEN)
67740 return -ENAMETOOLONG;
67741
67742 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67743 if (ret)
67744 return ret;
67745
67746 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67747 + if (!current_uid()) {
67748 + /* hack to workaround consolekit/udisks stupidity */
67749 + read_lock(&tasklist_lock);
67750 + if (!strcmp(current->comm, "mount") &&
67751 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67752 + read_unlock(&tasklist_lock);
67753 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67754 + return -EPERM;
67755 + }
67756 + read_unlock(&tasklist_lock);
67757 + }
67758 +#endif
67759 +
67760 /* If modprobe needs a service that is in a module, we get a recursive
67761 * loop. Limit the number of running kmod threads to max_threads/2 or
67762 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67763 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67764
67765 trace_module_request(module_name, wait, _RET_IP_);
67766
67767 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67768 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67769
67770 atomic_dec(&kmod_concurrent);
67771 return ret;
67772 }
67773 +
67774 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67775 +{
67776 + va_list args;
67777 + int ret;
67778 +
67779 + va_start(args, fmt);
67780 + ret = ____request_module(wait, module_param, fmt, args);
67781 + va_end(args);
67782 +
67783 + return ret;
67784 +}
67785 +
67786 +int __request_module(bool wait, const char *fmt, ...)
67787 +{
67788 + va_list args;
67789 + int ret;
67790 +
67791 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67792 + if (current_uid()) {
67793 + char module_param[MODULE_NAME_LEN];
67794 +
67795 + memset(module_param, 0, sizeof(module_param));
67796 +
67797 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67798 +
67799 + va_start(args, fmt);
67800 + ret = ____request_module(wait, module_param, fmt, args);
67801 + va_end(args);
67802 +
67803 + return ret;
67804 + }
67805 +#endif
67806 +
67807 + va_start(args, fmt);
67808 + ret = ____request_module(wait, NULL, fmt, args);
67809 + va_end(args);
67810 +
67811 + return ret;
67812 +}
67813 +
67814 EXPORT_SYMBOL(__request_module);
67815 #endif /* CONFIG_MODULES */
67816
67817 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67818 *
67819 * Thus the __user pointer cast is valid here.
67820 */
67821 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67822 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67823
67824 /*
67825 * If ret is 0, either ____call_usermodehelper failed and the
67826 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67827 index c62b854..6fc810d 100644
67828 --- a/kernel/kprobes.c
67829 +++ b/kernel/kprobes.c
67830 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67831 * kernel image and loaded module images reside. This is required
67832 * so x86_64 can correctly handle the %rip-relative fixups.
67833 */
67834 - kip->insns = module_alloc(PAGE_SIZE);
67835 + kip->insns = module_alloc_exec(PAGE_SIZE);
67836 if (!kip->insns) {
67837 kfree(kip);
67838 return NULL;
67839 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67840 */
67841 if (!list_is_singular(&kip->list)) {
67842 list_del(&kip->list);
67843 - module_free(NULL, kip->insns);
67844 + module_free_exec(NULL, kip->insns);
67845 kfree(kip);
67846 }
67847 return 1;
67848 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67849 {
67850 int i, err = 0;
67851 unsigned long offset = 0, size = 0;
67852 - char *modname, namebuf[128];
67853 + char *modname, namebuf[KSYM_NAME_LEN];
67854 const char *symbol_name;
67855 void *addr;
67856 struct kprobe_blackpoint *kb;
67857 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67858 kprobe_type = "k";
67859
67860 if (sym)
67861 - seq_printf(pi, "%p %s %s+0x%x %s ",
67862 + seq_printf(pi, "%pK %s %s+0x%x %s ",
67863 p->addr, kprobe_type, sym, offset,
67864 (modname ? modname : " "));
67865 else
67866 - seq_printf(pi, "%p %s %p ",
67867 + seq_printf(pi, "%pK %s %pK ",
67868 p->addr, kprobe_type, p->addr);
67869
67870 if (!pp)
67871 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67872 const char *sym = NULL;
67873 unsigned int i = *(loff_t *) v;
67874 unsigned long offset = 0;
67875 - char *modname, namebuf[128];
67876 + char *modname, namebuf[KSYM_NAME_LEN];
67877
67878 head = &kprobe_table[i];
67879 preempt_disable();
67880 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67881 index 4e316e1..5501eef 100644
67882 --- a/kernel/ksysfs.c
67883 +++ b/kernel/ksysfs.c
67884 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67885 {
67886 if (count+1 > UEVENT_HELPER_PATH_LEN)
67887 return -ENOENT;
67888 + if (!capable(CAP_SYS_ADMIN))
67889 + return -EPERM;
67890 memcpy(uevent_helper, buf, count);
67891 uevent_helper[count] = '\0';
67892 if (count && uevent_helper[count-1] == '\n')
67893 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67894 index ea9ee45..67ebc8f 100644
67895 --- a/kernel/lockdep.c
67896 +++ b/kernel/lockdep.c
67897 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67898 end = (unsigned long) &_end,
67899 addr = (unsigned long) obj;
67900
67901 +#ifdef CONFIG_PAX_KERNEXEC
67902 + start = ktla_ktva(start);
67903 +#endif
67904 +
67905 /*
67906 * static variable?
67907 */
67908 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67909 if (!static_obj(lock->key)) {
67910 debug_locks_off();
67911 printk("INFO: trying to register non-static key.\n");
67912 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67913 printk("the code is fine but needs lockdep annotation.\n");
67914 printk("turning off the locking correctness validator.\n");
67915 dump_stack();
67916 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67917 if (!class)
67918 return 0;
67919 }
67920 - atomic_inc((atomic_t *)&class->ops);
67921 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67922 if (very_verbose(class)) {
67923 printk("\nacquire class [%p] %s", class->key, class->name);
67924 if (class->name_version > 1)
67925 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67926 index 91c32a0..7b88d63 100644
67927 --- a/kernel/lockdep_proc.c
67928 +++ b/kernel/lockdep_proc.c
67929 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67930
67931 static void print_name(struct seq_file *m, struct lock_class *class)
67932 {
67933 - char str[128];
67934 + char str[KSYM_NAME_LEN];
67935 const char *name = class->name;
67936
67937 if (!name) {
67938 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67939 return 0;
67940 }
67941
67942 - seq_printf(m, "%p", class->key);
67943 + seq_printf(m, "%pK", class->key);
67944 #ifdef CONFIG_DEBUG_LOCKDEP
67945 seq_printf(m, " OPS:%8ld", class->ops);
67946 #endif
67947 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67948
67949 list_for_each_entry(entry, &class->locks_after, entry) {
67950 if (entry->distance == 1) {
67951 - seq_printf(m, " -> [%p] ", entry->class->key);
67952 + seq_printf(m, " -> [%pK] ", entry->class->key);
67953 print_name(m, entry->class);
67954 seq_puts(m, "\n");
67955 }
67956 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67957 if (!class->key)
67958 continue;
67959
67960 - seq_printf(m, "[%p] ", class->key);
67961 + seq_printf(m, "[%pK] ", class->key);
67962 print_name(m, class);
67963 seq_puts(m, "\n");
67964 }
67965 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67966 if (!i)
67967 seq_line(m, '-', 40-namelen, namelen);
67968
67969 - snprintf(ip, sizeof(ip), "[<%p>]",
67970 + snprintf(ip, sizeof(ip), "[<%pK>]",
67971 (void *)class->contention_point[i]);
67972 seq_printf(m, "%40s %14lu %29s %pS\n",
67973 name, stats->contention_point[i],
67974 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67975 if (!i)
67976 seq_line(m, '-', 40-namelen, namelen);
67977
67978 - snprintf(ip, sizeof(ip), "[<%p>]",
67979 + snprintf(ip, sizeof(ip), "[<%pK>]",
67980 (void *)class->contending_point[i]);
67981 seq_printf(m, "%40s %14lu %29s %pS\n",
67982 name, stats->contending_point[i],
67983 diff --git a/kernel/module.c b/kernel/module.c
67984 index 9ad9ee9..de7a157 100644
67985 --- a/kernel/module.c
67986 +++ b/kernel/module.c
67987 @@ -58,6 +58,7 @@
67988 #include <linux/jump_label.h>
67989 #include <linux/pfn.h>
67990 #include <linux/bsearch.h>
67991 +#include <linux/grsecurity.h>
67992
67993 #define CREATE_TRACE_POINTS
67994 #include <trace/events/module.h>
67995 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67996
67997 /* Bounds of module allocation, for speeding __module_address.
67998 * Protected by module_mutex. */
67999 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68000 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68001 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68002
68003 int register_module_notifier(struct notifier_block * nb)
68004 {
68005 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68006 return true;
68007
68008 list_for_each_entry_rcu(mod, &modules, list) {
68009 - struct symsearch arr[] = {
68010 + struct symsearch modarr[] = {
68011 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68012 NOT_GPL_ONLY, false },
68013 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68014 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68015 #endif
68016 };
68017
68018 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68019 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68020 return true;
68021 }
68022 return false;
68023 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68024 static int percpu_modalloc(struct module *mod,
68025 unsigned long size, unsigned long align)
68026 {
68027 - if (align > PAGE_SIZE) {
68028 + if (align-1 >= PAGE_SIZE) {
68029 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68030 mod->name, align, PAGE_SIZE);
68031 align = PAGE_SIZE;
68032 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68033 static ssize_t show_coresize(struct module_attribute *mattr,
68034 struct module_kobject *mk, char *buffer)
68035 {
68036 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68037 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68038 }
68039
68040 static struct module_attribute modinfo_coresize =
68041 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68042 static ssize_t show_initsize(struct module_attribute *mattr,
68043 struct module_kobject *mk, char *buffer)
68044 {
68045 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68046 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68047 }
68048
68049 static struct module_attribute modinfo_initsize =
68050 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68051 */
68052 #ifdef CONFIG_SYSFS
68053
68054 -#ifdef CONFIG_KALLSYMS
68055 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68056 static inline bool sect_empty(const Elf_Shdr *sect)
68057 {
68058 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68059 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68060
68061 static void unset_module_core_ro_nx(struct module *mod)
68062 {
68063 - set_page_attributes(mod->module_core + mod->core_text_size,
68064 - mod->module_core + mod->core_size,
68065 + set_page_attributes(mod->module_core_rw,
68066 + mod->module_core_rw + mod->core_size_rw,
68067 set_memory_x);
68068 - set_page_attributes(mod->module_core,
68069 - mod->module_core + mod->core_ro_size,
68070 + set_page_attributes(mod->module_core_rx,
68071 + mod->module_core_rx + mod->core_size_rx,
68072 set_memory_rw);
68073 }
68074
68075 static void unset_module_init_ro_nx(struct module *mod)
68076 {
68077 - set_page_attributes(mod->module_init + mod->init_text_size,
68078 - mod->module_init + mod->init_size,
68079 + set_page_attributes(mod->module_init_rw,
68080 + mod->module_init_rw + mod->init_size_rw,
68081 set_memory_x);
68082 - set_page_attributes(mod->module_init,
68083 - mod->module_init + mod->init_ro_size,
68084 + set_page_attributes(mod->module_init_rx,
68085 + mod->module_init_rx + mod->init_size_rx,
68086 set_memory_rw);
68087 }
68088
68089 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68090
68091 mutex_lock(&module_mutex);
68092 list_for_each_entry_rcu(mod, &modules, list) {
68093 - if ((mod->module_core) && (mod->core_text_size)) {
68094 - set_page_attributes(mod->module_core,
68095 - mod->module_core + mod->core_text_size,
68096 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68097 + set_page_attributes(mod->module_core_rx,
68098 + mod->module_core_rx + mod->core_size_rx,
68099 set_memory_rw);
68100 }
68101 - if ((mod->module_init) && (mod->init_text_size)) {
68102 - set_page_attributes(mod->module_init,
68103 - mod->module_init + mod->init_text_size,
68104 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68105 + set_page_attributes(mod->module_init_rx,
68106 + mod->module_init_rx + mod->init_size_rx,
68107 set_memory_rw);
68108 }
68109 }
68110 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68111
68112 mutex_lock(&module_mutex);
68113 list_for_each_entry_rcu(mod, &modules, list) {
68114 - if ((mod->module_core) && (mod->core_text_size)) {
68115 - set_page_attributes(mod->module_core,
68116 - mod->module_core + mod->core_text_size,
68117 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68118 + set_page_attributes(mod->module_core_rx,
68119 + mod->module_core_rx + mod->core_size_rx,
68120 set_memory_ro);
68121 }
68122 - if ((mod->module_init) && (mod->init_text_size)) {
68123 - set_page_attributes(mod->module_init,
68124 - mod->module_init + mod->init_text_size,
68125 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68126 + set_page_attributes(mod->module_init_rx,
68127 + mod->module_init_rx + mod->init_size_rx,
68128 set_memory_ro);
68129 }
68130 }
68131 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68132
68133 /* This may be NULL, but that's OK */
68134 unset_module_init_ro_nx(mod);
68135 - module_free(mod, mod->module_init);
68136 + module_free(mod, mod->module_init_rw);
68137 + module_free_exec(mod, mod->module_init_rx);
68138 kfree(mod->args);
68139 percpu_modfree(mod);
68140
68141 /* Free lock-classes: */
68142 - lockdep_free_key_range(mod->module_core, mod->core_size);
68143 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68144 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68145
68146 /* Finally, free the core (containing the module structure) */
68147 unset_module_core_ro_nx(mod);
68148 - module_free(mod, mod->module_core);
68149 + module_free_exec(mod, mod->module_core_rx);
68150 + module_free(mod, mod->module_core_rw);
68151
68152 #ifdef CONFIG_MPU
68153 update_protections(current->mm);
68154 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68155 int ret = 0;
68156 const struct kernel_symbol *ksym;
68157
68158 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68159 + int is_fs_load = 0;
68160 + int register_filesystem_found = 0;
68161 + char *p;
68162 +
68163 + p = strstr(mod->args, "grsec_modharden_fs");
68164 + if (p) {
68165 + char *endptr = p + strlen("grsec_modharden_fs");
68166 + /* copy \0 as well */
68167 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68168 + is_fs_load = 1;
68169 + }
68170 +#endif
68171 +
68172 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68173 const char *name = info->strtab + sym[i].st_name;
68174
68175 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68176 + /* it's a real shame this will never get ripped and copied
68177 + upstream! ;(
68178 + */
68179 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68180 + register_filesystem_found = 1;
68181 +#endif
68182 +
68183 switch (sym[i].st_shndx) {
68184 case SHN_COMMON:
68185 /* We compiled with -fno-common. These are not
68186 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68187 ksym = resolve_symbol_wait(mod, info, name);
68188 /* Ok if resolved. */
68189 if (ksym && !IS_ERR(ksym)) {
68190 + pax_open_kernel();
68191 sym[i].st_value = ksym->value;
68192 + pax_close_kernel();
68193 break;
68194 }
68195
68196 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68197 secbase = (unsigned long)mod_percpu(mod);
68198 else
68199 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68200 + pax_open_kernel();
68201 sym[i].st_value += secbase;
68202 + pax_close_kernel();
68203 break;
68204 }
68205 }
68206
68207 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68208 + if (is_fs_load && !register_filesystem_found) {
68209 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68210 + ret = -EPERM;
68211 + }
68212 +#endif
68213 +
68214 return ret;
68215 }
68216
68217 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68218 || s->sh_entsize != ~0UL
68219 || strstarts(sname, ".init"))
68220 continue;
68221 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68222 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68223 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68224 + else
68225 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68226 pr_debug("\t%s\n", sname);
68227 }
68228 - switch (m) {
68229 - case 0: /* executable */
68230 - mod->core_size = debug_align(mod->core_size);
68231 - mod->core_text_size = mod->core_size;
68232 - break;
68233 - case 1: /* RO: text and ro-data */
68234 - mod->core_size = debug_align(mod->core_size);
68235 - mod->core_ro_size = mod->core_size;
68236 - break;
68237 - case 3: /* whole core */
68238 - mod->core_size = debug_align(mod->core_size);
68239 - break;
68240 - }
68241 }
68242
68243 pr_debug("Init section allocation order:\n");
68244 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68245 || s->sh_entsize != ~0UL
68246 || !strstarts(sname, ".init"))
68247 continue;
68248 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68249 - | INIT_OFFSET_MASK);
68250 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68251 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68252 + else
68253 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68254 + s->sh_entsize |= INIT_OFFSET_MASK;
68255 pr_debug("\t%s\n", sname);
68256 }
68257 - switch (m) {
68258 - case 0: /* executable */
68259 - mod->init_size = debug_align(mod->init_size);
68260 - mod->init_text_size = mod->init_size;
68261 - break;
68262 - case 1: /* RO: text and ro-data */
68263 - mod->init_size = debug_align(mod->init_size);
68264 - mod->init_ro_size = mod->init_size;
68265 - break;
68266 - case 3: /* whole init */
68267 - mod->init_size = debug_align(mod->init_size);
68268 - break;
68269 - }
68270 }
68271 }
68272
68273 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68274
68275 /* Put symbol section at end of init part of module. */
68276 symsect->sh_flags |= SHF_ALLOC;
68277 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68278 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68279 info->index.sym) | INIT_OFFSET_MASK;
68280 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68281
68282 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68283 }
68284
68285 /* Append room for core symbols at end of core part. */
68286 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68287 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68288 - mod->core_size += strtab_size;
68289 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68290 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68291 + mod->core_size_rx += strtab_size;
68292
68293 /* Put string table section at end of init part of module. */
68294 strsect->sh_flags |= SHF_ALLOC;
68295 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68296 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68297 info->index.str) | INIT_OFFSET_MASK;
68298 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68299 }
68300 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68301 /* Make sure we get permanent strtab: don't use info->strtab. */
68302 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68303
68304 + pax_open_kernel();
68305 +
68306 /* Set types up while we still have access to sections. */
68307 for (i = 0; i < mod->num_symtab; i++)
68308 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68309
68310 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68311 - mod->core_strtab = s = mod->module_core + info->stroffs;
68312 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68313 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68314 src = mod->symtab;
68315 *dst = *src;
68316 *s++ = 0;
68317 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68318 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68319 }
68320 mod->core_num_syms = ndst;
68321 +
68322 + pax_close_kernel();
68323 }
68324 #else
68325 static inline void layout_symtab(struct module *mod, struct load_info *info)
68326 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68327 return size == 0 ? NULL : vmalloc_exec(size);
68328 }
68329
68330 -static void *module_alloc_update_bounds(unsigned long size)
68331 +static void *module_alloc_update_bounds_rw(unsigned long size)
68332 {
68333 void *ret = module_alloc(size);
68334
68335 if (ret) {
68336 mutex_lock(&module_mutex);
68337 /* Update module bounds. */
68338 - if ((unsigned long)ret < module_addr_min)
68339 - module_addr_min = (unsigned long)ret;
68340 - if ((unsigned long)ret + size > module_addr_max)
68341 - module_addr_max = (unsigned long)ret + size;
68342 + if ((unsigned long)ret < module_addr_min_rw)
68343 + module_addr_min_rw = (unsigned long)ret;
68344 + if ((unsigned long)ret + size > module_addr_max_rw)
68345 + module_addr_max_rw = (unsigned long)ret + size;
68346 + mutex_unlock(&module_mutex);
68347 + }
68348 + return ret;
68349 +}
68350 +
68351 +static void *module_alloc_update_bounds_rx(unsigned long size)
68352 +{
68353 + void *ret = module_alloc_exec(size);
68354 +
68355 + if (ret) {
68356 + mutex_lock(&module_mutex);
68357 + /* Update module bounds. */
68358 + if ((unsigned long)ret < module_addr_min_rx)
68359 + module_addr_min_rx = (unsigned long)ret;
68360 + if ((unsigned long)ret + size > module_addr_max_rx)
68361 + module_addr_max_rx = (unsigned long)ret + size;
68362 mutex_unlock(&module_mutex);
68363 }
68364 return ret;
68365 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68366 static int check_modinfo(struct module *mod, struct load_info *info)
68367 {
68368 const char *modmagic = get_modinfo(info, "vermagic");
68369 + const char *license = get_modinfo(info, "license");
68370 int err;
68371
68372 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68373 + if (!license || !license_is_gpl_compatible(license))
68374 + return -ENOEXEC;
68375 +#endif
68376 +
68377 /* This is allowed: modprobe --force will invalidate it. */
68378 if (!modmagic) {
68379 err = try_to_force_load(mod, "bad vermagic");
68380 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68381 }
68382
68383 /* Set up license info based on the info section */
68384 - set_license(mod, get_modinfo(info, "license"));
68385 + set_license(mod, license);
68386
68387 return 0;
68388 }
68389 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68390 void *ptr;
68391
68392 /* Do the allocs. */
68393 - ptr = module_alloc_update_bounds(mod->core_size);
68394 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68395 /*
68396 * The pointer to this block is stored in the module structure
68397 * which is inside the block. Just mark it as not being a
68398 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68399 if (!ptr)
68400 return -ENOMEM;
68401
68402 - memset(ptr, 0, mod->core_size);
68403 - mod->module_core = ptr;
68404 + memset(ptr, 0, mod->core_size_rw);
68405 + mod->module_core_rw = ptr;
68406
68407 - ptr = module_alloc_update_bounds(mod->init_size);
68408 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68409 /*
68410 * The pointer to this block is stored in the module structure
68411 * which is inside the block. This block doesn't need to be
68412 * scanned as it contains data and code that will be freed
68413 * after the module is initialized.
68414 */
68415 - kmemleak_ignore(ptr);
68416 - if (!ptr && mod->init_size) {
68417 - module_free(mod, mod->module_core);
68418 + kmemleak_not_leak(ptr);
68419 + if (!ptr && mod->init_size_rw) {
68420 + module_free(mod, mod->module_core_rw);
68421 return -ENOMEM;
68422 }
68423 - memset(ptr, 0, mod->init_size);
68424 - mod->module_init = ptr;
68425 + memset(ptr, 0, mod->init_size_rw);
68426 + mod->module_init_rw = ptr;
68427 +
68428 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68429 + kmemleak_not_leak(ptr);
68430 + if (!ptr) {
68431 + module_free(mod, mod->module_init_rw);
68432 + module_free(mod, mod->module_core_rw);
68433 + return -ENOMEM;
68434 + }
68435 +
68436 + pax_open_kernel();
68437 + memset(ptr, 0, mod->core_size_rx);
68438 + pax_close_kernel();
68439 + mod->module_core_rx = ptr;
68440 +
68441 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68442 + kmemleak_not_leak(ptr);
68443 + if (!ptr && mod->init_size_rx) {
68444 + module_free_exec(mod, mod->module_core_rx);
68445 + module_free(mod, mod->module_init_rw);
68446 + module_free(mod, mod->module_core_rw);
68447 + return -ENOMEM;
68448 + }
68449 +
68450 + pax_open_kernel();
68451 + memset(ptr, 0, mod->init_size_rx);
68452 + pax_close_kernel();
68453 + mod->module_init_rx = ptr;
68454
68455 /* Transfer each section which specifies SHF_ALLOC */
68456 pr_debug("final section addresses:\n");
68457 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68458 if (!(shdr->sh_flags & SHF_ALLOC))
68459 continue;
68460
68461 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68462 - dest = mod->module_init
68463 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68464 - else
68465 - dest = mod->module_core + shdr->sh_entsize;
68466 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68467 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68468 + dest = mod->module_init_rw
68469 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68470 + else
68471 + dest = mod->module_init_rx
68472 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68473 + } else {
68474 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68475 + dest = mod->module_core_rw + shdr->sh_entsize;
68476 + else
68477 + dest = mod->module_core_rx + shdr->sh_entsize;
68478 + }
68479 +
68480 + if (shdr->sh_type != SHT_NOBITS) {
68481 +
68482 +#ifdef CONFIG_PAX_KERNEXEC
68483 +#ifdef CONFIG_X86_64
68484 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68485 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68486 +#endif
68487 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68488 + pax_open_kernel();
68489 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68490 + pax_close_kernel();
68491 + } else
68492 +#endif
68493
68494 - if (shdr->sh_type != SHT_NOBITS)
68495 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68496 + }
68497 /* Update sh_addr to point to copy in image. */
68498 - shdr->sh_addr = (unsigned long)dest;
68499 +
68500 +#ifdef CONFIG_PAX_KERNEXEC
68501 + if (shdr->sh_flags & SHF_EXECINSTR)
68502 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68503 + else
68504 +#endif
68505 +
68506 + shdr->sh_addr = (unsigned long)dest;
68507 pr_debug("\t0x%lx %s\n",
68508 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68509 }
68510 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68511 * Do it before processing of module parameters, so the module
68512 * can provide parameter accessor functions of its own.
68513 */
68514 - if (mod->module_init)
68515 - flush_icache_range((unsigned long)mod->module_init,
68516 - (unsigned long)mod->module_init
68517 - + mod->init_size);
68518 - flush_icache_range((unsigned long)mod->module_core,
68519 - (unsigned long)mod->module_core + mod->core_size);
68520 + if (mod->module_init_rx)
68521 + flush_icache_range((unsigned long)mod->module_init_rx,
68522 + (unsigned long)mod->module_init_rx
68523 + + mod->init_size_rx);
68524 + flush_icache_range((unsigned long)mod->module_core_rx,
68525 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68526
68527 set_fs(old_fs);
68528 }
68529 @@ -2838,8 +2938,10 @@ out:
68530 static void module_deallocate(struct module *mod, struct load_info *info)
68531 {
68532 percpu_modfree(mod);
68533 - module_free(mod, mod->module_init);
68534 - module_free(mod, mod->module_core);
68535 + module_free_exec(mod, mod->module_init_rx);
68536 + module_free_exec(mod, mod->module_core_rx);
68537 + module_free(mod, mod->module_init_rw);
68538 + module_free(mod, mod->module_core_rw);
68539 }
68540
68541 int __weak module_finalize(const Elf_Ehdr *hdr,
68542 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68543 static int post_relocation(struct module *mod, const struct load_info *info)
68544 {
68545 /* Sort exception table now relocations are done. */
68546 + pax_open_kernel();
68547 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68548 + pax_close_kernel();
68549
68550 /* Copy relocated percpu area over. */
68551 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68552 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68553 if (err)
68554 goto free_unload;
68555
68556 + /* Now copy in args */
68557 + mod->args = strndup_user(uargs, ~0UL >> 1);
68558 + if (IS_ERR(mod->args)) {
68559 + err = PTR_ERR(mod->args);
68560 + goto free_unload;
68561 + }
68562 +
68563 /* Set up MODINFO_ATTR fields */
68564 setup_modinfo(mod, &info);
68565
68566 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68567 + {
68568 + char *p, *p2;
68569 +
68570 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68571 + 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);
68572 + err = -EPERM;
68573 + goto free_modinfo;
68574 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68575 + p += strlen("grsec_modharden_normal");
68576 + p2 = strstr(p, "_");
68577 + if (p2) {
68578 + *p2 = '\0';
68579 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68580 + *p2 = '_';
68581 + }
68582 + err = -EPERM;
68583 + goto free_modinfo;
68584 + }
68585 + }
68586 +#endif
68587 +
68588 /* Fix up syms, so that st_value is a pointer to location. */
68589 err = simplify_symbols(mod, &info);
68590 if (err < 0)
68591 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68592
68593 flush_module_icache(mod);
68594
68595 - /* Now copy in args */
68596 - mod->args = strndup_user(uargs, ~0UL >> 1);
68597 - if (IS_ERR(mod->args)) {
68598 - err = PTR_ERR(mod->args);
68599 - goto free_arch_cleanup;
68600 - }
68601 -
68602 /* Mark state as coming so strong_try_module_get() ignores us. */
68603 mod->state = MODULE_STATE_COMING;
68604
68605 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68606 unlock:
68607 mutex_unlock(&module_mutex);
68608 synchronize_sched();
68609 - kfree(mod->args);
68610 - free_arch_cleanup:
68611 module_arch_cleanup(mod);
68612 free_modinfo:
68613 free_modinfo(mod);
68614 + kfree(mod->args);
68615 free_unload:
68616 module_unload_free(mod);
68617 free_module:
68618 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68619 MODULE_STATE_COMING, mod);
68620
68621 /* Set RO and NX regions for core */
68622 - set_section_ro_nx(mod->module_core,
68623 - mod->core_text_size,
68624 - mod->core_ro_size,
68625 - mod->core_size);
68626 + set_section_ro_nx(mod->module_core_rx,
68627 + mod->core_size_rx,
68628 + mod->core_size_rx,
68629 + mod->core_size_rx);
68630
68631 /* Set RO and NX regions for init */
68632 - set_section_ro_nx(mod->module_init,
68633 - mod->init_text_size,
68634 - mod->init_ro_size,
68635 - mod->init_size);
68636 + set_section_ro_nx(mod->module_init_rx,
68637 + mod->init_size_rx,
68638 + mod->init_size_rx,
68639 + mod->init_size_rx);
68640
68641 do_mod_ctors(mod);
68642 /* Start the module */
68643 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68644 mod->strtab = mod->core_strtab;
68645 #endif
68646 unset_module_init_ro_nx(mod);
68647 - module_free(mod, mod->module_init);
68648 - mod->module_init = NULL;
68649 - mod->init_size = 0;
68650 - mod->init_ro_size = 0;
68651 - mod->init_text_size = 0;
68652 + module_free(mod, mod->module_init_rw);
68653 + module_free_exec(mod, mod->module_init_rx);
68654 + mod->module_init_rw = NULL;
68655 + mod->module_init_rx = NULL;
68656 + mod->init_size_rw = 0;
68657 + mod->init_size_rx = 0;
68658 mutex_unlock(&module_mutex);
68659
68660 return 0;
68661 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68662 unsigned long nextval;
68663
68664 /* At worse, next value is at end of module */
68665 - if (within_module_init(addr, mod))
68666 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68667 + if (within_module_init_rx(addr, mod))
68668 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68669 + else if (within_module_init_rw(addr, mod))
68670 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68671 + else if (within_module_core_rx(addr, mod))
68672 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68673 + else if (within_module_core_rw(addr, mod))
68674 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68675 else
68676 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68677 + return NULL;
68678
68679 /* Scan for closest preceding symbol, and next symbol. (ELF
68680 starts real symbols at 1). */
68681 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68682 char buf[8];
68683
68684 seq_printf(m, "%s %u",
68685 - mod->name, mod->init_size + mod->core_size);
68686 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68687 print_unload_info(m, mod);
68688
68689 /* Informative for users. */
68690 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68691 mod->state == MODULE_STATE_COMING ? "Loading":
68692 "Live");
68693 /* Used by oprofile and other similar tools. */
68694 - seq_printf(m, " 0x%pK", mod->module_core);
68695 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68696
68697 /* Taints info */
68698 if (mod->taints)
68699 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68700
68701 static int __init proc_modules_init(void)
68702 {
68703 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68704 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68705 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68706 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68707 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68708 +#else
68709 proc_create("modules", 0, NULL, &proc_modules_operations);
68710 +#endif
68711 +#else
68712 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68713 +#endif
68714 return 0;
68715 }
68716 module_init(proc_modules_init);
68717 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68718 {
68719 struct module *mod;
68720
68721 - if (addr < module_addr_min || addr > module_addr_max)
68722 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68723 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68724 return NULL;
68725
68726 list_for_each_entry_rcu(mod, &modules, list)
68727 - if (within_module_core(addr, mod)
68728 - || within_module_init(addr, mod))
68729 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68730 return mod;
68731 return NULL;
68732 }
68733 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68734 */
68735 struct module *__module_text_address(unsigned long addr)
68736 {
68737 - struct module *mod = __module_address(addr);
68738 + struct module *mod;
68739 +
68740 +#ifdef CONFIG_X86_32
68741 + addr = ktla_ktva(addr);
68742 +#endif
68743 +
68744 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68745 + return NULL;
68746 +
68747 + mod = __module_address(addr);
68748 +
68749 if (mod) {
68750 /* Make sure it's within the text section. */
68751 - if (!within(addr, mod->module_init, mod->init_text_size)
68752 - && !within(addr, mod->module_core, mod->core_text_size))
68753 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68754 mod = NULL;
68755 }
68756 return mod;
68757 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68758 index 7e3443f..b2a1e6b 100644
68759 --- a/kernel/mutex-debug.c
68760 +++ b/kernel/mutex-debug.c
68761 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68762 }
68763
68764 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68765 - struct thread_info *ti)
68766 + struct task_struct *task)
68767 {
68768 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68769
68770 /* Mark the current thread as blocked on the lock: */
68771 - ti->task->blocked_on = waiter;
68772 + task->blocked_on = waiter;
68773 }
68774
68775 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68776 - struct thread_info *ti)
68777 + struct task_struct *task)
68778 {
68779 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68780 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68781 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68782 - ti->task->blocked_on = NULL;
68783 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68784 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68785 + task->blocked_on = NULL;
68786
68787 list_del_init(&waiter->list);
68788 waiter->task = NULL;
68789 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68790 index 0799fd3..d06ae3b 100644
68791 --- a/kernel/mutex-debug.h
68792 +++ b/kernel/mutex-debug.h
68793 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68794 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68795 extern void debug_mutex_add_waiter(struct mutex *lock,
68796 struct mutex_waiter *waiter,
68797 - struct thread_info *ti);
68798 + struct task_struct *task);
68799 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68800 - struct thread_info *ti);
68801 + struct task_struct *task);
68802 extern void debug_mutex_unlock(struct mutex *lock);
68803 extern void debug_mutex_init(struct mutex *lock, const char *name,
68804 struct lock_class_key *key);
68805 diff --git a/kernel/mutex.c b/kernel/mutex.c
68806 index a307cc9..27fd2e9 100644
68807 --- a/kernel/mutex.c
68808 +++ b/kernel/mutex.c
68809 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68810 spin_lock_mutex(&lock->wait_lock, flags);
68811
68812 debug_mutex_lock_common(lock, &waiter);
68813 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68814 + debug_mutex_add_waiter(lock, &waiter, task);
68815
68816 /* add waiting tasks to the end of the waitqueue (FIFO): */
68817 list_add_tail(&waiter.list, &lock->wait_list);
68818 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68819 * TASK_UNINTERRUPTIBLE case.)
68820 */
68821 if (unlikely(signal_pending_state(state, task))) {
68822 - mutex_remove_waiter(lock, &waiter,
68823 - task_thread_info(task));
68824 + mutex_remove_waiter(lock, &waiter, task);
68825 mutex_release(&lock->dep_map, 1, ip);
68826 spin_unlock_mutex(&lock->wait_lock, flags);
68827
68828 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68829 done:
68830 lock_acquired(&lock->dep_map, ip);
68831 /* got the lock - rejoice! */
68832 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68833 + mutex_remove_waiter(lock, &waiter, task);
68834 mutex_set_owner(lock);
68835
68836 /* set it to 0 if there are no waiters left: */
68837 diff --git a/kernel/panic.c b/kernel/panic.c
68838 index e1b2822..5edc1d9 100644
68839 --- a/kernel/panic.c
68840 +++ b/kernel/panic.c
68841 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68842 const char *board;
68843
68844 printk(KERN_WARNING "------------[ cut here ]------------\n");
68845 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68846 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68847 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68848 if (board)
68849 printk(KERN_WARNING "Hardware name: %s\n", board);
68850 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68851 */
68852 void __stack_chk_fail(void)
68853 {
68854 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68855 + dump_stack();
68856 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68857 __builtin_return_address(0));
68858 }
68859 EXPORT_SYMBOL(__stack_chk_fail);
68860 diff --git a/kernel/pid.c b/kernel/pid.c
68861 index e86b291a..e8b0fb5 100644
68862 --- a/kernel/pid.c
68863 +++ b/kernel/pid.c
68864 @@ -33,6 +33,7 @@
68865 #include <linux/rculist.h>
68866 #include <linux/bootmem.h>
68867 #include <linux/hash.h>
68868 +#include <linux/security.h>
68869 #include <linux/pid_namespace.h>
68870 #include <linux/init_task.h>
68871 #include <linux/syscalls.h>
68872 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68873
68874 int pid_max = PID_MAX_DEFAULT;
68875
68876 -#define RESERVED_PIDS 300
68877 +#define RESERVED_PIDS 500
68878
68879 int pid_max_min = RESERVED_PIDS + 1;
68880 int pid_max_max = PID_MAX_LIMIT;
68881 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68882 */
68883 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68884 {
68885 + struct task_struct *task;
68886 +
68887 rcu_lockdep_assert(rcu_read_lock_held(),
68888 "find_task_by_pid_ns() needs rcu_read_lock()"
68889 " protection");
68890 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68891 +
68892 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68893 +
68894 + if (gr_pid_is_chrooted(task))
68895 + return NULL;
68896 +
68897 + return task;
68898 }
68899
68900 struct task_struct *find_task_by_vpid(pid_t vnr)
68901 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68902 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68903 }
68904
68905 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68906 +{
68907 + rcu_lockdep_assert(rcu_read_lock_held(),
68908 + "find_task_by_pid_ns() needs rcu_read_lock()"
68909 + " protection");
68910 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68911 +}
68912 +
68913 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68914 {
68915 struct pid *pid;
68916 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68917 index 125cb67..a4d1c30 100644
68918 --- a/kernel/posix-cpu-timers.c
68919 +++ b/kernel/posix-cpu-timers.c
68920 @@ -6,6 +6,7 @@
68921 #include <linux/posix-timers.h>
68922 #include <linux/errno.h>
68923 #include <linux/math64.h>
68924 +#include <linux/security.h>
68925 #include <asm/uaccess.h>
68926 #include <linux/kernel_stat.h>
68927 #include <trace/events/timer.h>
68928 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68929
68930 static __init int init_posix_cpu_timers(void)
68931 {
68932 - struct k_clock process = {
68933 + static struct k_clock process = {
68934 .clock_getres = process_cpu_clock_getres,
68935 .clock_get = process_cpu_clock_get,
68936 .timer_create = process_cpu_timer_create,
68937 .nsleep = process_cpu_nsleep,
68938 .nsleep_restart = process_cpu_nsleep_restart,
68939 };
68940 - struct k_clock thread = {
68941 + static struct k_clock thread = {
68942 .clock_getres = thread_cpu_clock_getres,
68943 .clock_get = thread_cpu_clock_get,
68944 .timer_create = thread_cpu_timer_create,
68945 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68946 index 69185ae..cc2847a 100644
68947 --- a/kernel/posix-timers.c
68948 +++ b/kernel/posix-timers.c
68949 @@ -43,6 +43,7 @@
68950 #include <linux/idr.h>
68951 #include <linux/posix-clock.h>
68952 #include <linux/posix-timers.h>
68953 +#include <linux/grsecurity.h>
68954 #include <linux/syscalls.h>
68955 #include <linux/wait.h>
68956 #include <linux/workqueue.h>
68957 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68958 * which we beg off on and pass to do_sys_settimeofday().
68959 */
68960
68961 -static struct k_clock posix_clocks[MAX_CLOCKS];
68962 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68963
68964 /*
68965 * These ones are defined below.
68966 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68967 */
68968 static __init int init_posix_timers(void)
68969 {
68970 - struct k_clock clock_realtime = {
68971 + static struct k_clock clock_realtime = {
68972 .clock_getres = hrtimer_get_res,
68973 .clock_get = posix_clock_realtime_get,
68974 .clock_set = posix_clock_realtime_set,
68975 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68976 .timer_get = common_timer_get,
68977 .timer_del = common_timer_del,
68978 };
68979 - struct k_clock clock_monotonic = {
68980 + static struct k_clock clock_monotonic = {
68981 .clock_getres = hrtimer_get_res,
68982 .clock_get = posix_ktime_get_ts,
68983 .nsleep = common_nsleep,
68984 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68985 .timer_get = common_timer_get,
68986 .timer_del = common_timer_del,
68987 };
68988 - struct k_clock clock_monotonic_raw = {
68989 + static struct k_clock clock_monotonic_raw = {
68990 .clock_getres = hrtimer_get_res,
68991 .clock_get = posix_get_monotonic_raw,
68992 };
68993 - struct k_clock clock_realtime_coarse = {
68994 + static struct k_clock clock_realtime_coarse = {
68995 .clock_getres = posix_get_coarse_res,
68996 .clock_get = posix_get_realtime_coarse,
68997 };
68998 - struct k_clock clock_monotonic_coarse = {
68999 + static struct k_clock clock_monotonic_coarse = {
69000 .clock_getres = posix_get_coarse_res,
69001 .clock_get = posix_get_monotonic_coarse,
69002 };
69003 - struct k_clock clock_boottime = {
69004 + static struct k_clock clock_boottime = {
69005 .clock_getres = hrtimer_get_res,
69006 .clock_get = posix_get_boottime,
69007 .nsleep = common_nsleep,
69008 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69009 return;
69010 }
69011
69012 - posix_clocks[clock_id] = *new_clock;
69013 + posix_clocks[clock_id] = new_clock;
69014 }
69015 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69016
69017 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69018 return (id & CLOCKFD_MASK) == CLOCKFD ?
69019 &clock_posix_dynamic : &clock_posix_cpu;
69020
69021 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69022 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69023 return NULL;
69024 - return &posix_clocks[id];
69025 + return posix_clocks[id];
69026 }
69027
69028 static int common_timer_create(struct k_itimer *new_timer)
69029 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69030 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69031 return -EFAULT;
69032
69033 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69034 + have their clock_set fptr set to a nosettime dummy function
69035 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69036 + call common_clock_set, which calls do_sys_settimeofday, which
69037 + we hook
69038 + */
69039 +
69040 return kc->clock_set(which_clock, &new_tp);
69041 }
69042
69043 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69044 index d523593..68197a4 100644
69045 --- a/kernel/power/poweroff.c
69046 +++ b/kernel/power/poweroff.c
69047 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69048 .enable_mask = SYSRQ_ENABLE_BOOT,
69049 };
69050
69051 -static int pm_sysrq_init(void)
69052 +static int __init pm_sysrq_init(void)
69053 {
69054 register_sysrq_key('o', &sysrq_poweroff_op);
69055 return 0;
69056 diff --git a/kernel/power/process.c b/kernel/power/process.c
69057 index 19db29f..33b52b6 100644
69058 --- a/kernel/power/process.c
69059 +++ b/kernel/power/process.c
69060 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69061 u64 elapsed_csecs64;
69062 unsigned int elapsed_csecs;
69063 bool wakeup = false;
69064 + bool timedout = false;
69065
69066 do_gettimeofday(&start);
69067
69068 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69069
69070 while (true) {
69071 todo = 0;
69072 + if (time_after(jiffies, end_time))
69073 + timedout = true;
69074 read_lock(&tasklist_lock);
69075 do_each_thread(g, p) {
69076 if (p == current || !freeze_task(p))
69077 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69078 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69079 * transition can't race with task state testing here.
69080 */
69081 - if (!task_is_stopped_or_traced(p) &&
69082 - !freezer_should_skip(p))
69083 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69084 todo++;
69085 + if (timedout) {
69086 + printk(KERN_ERR "Task refusing to freeze:\n");
69087 + sched_show_task(p);
69088 + }
69089 + }
69090 } while_each_thread(g, p);
69091 read_unlock(&tasklist_lock);
69092
69093 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69094 todo += wq_busy;
69095 }
69096
69097 - if (!todo || time_after(jiffies, end_time))
69098 + if (!todo || timedout)
69099 break;
69100
69101 if (pm_wakeup_pending()) {
69102 diff --git a/kernel/printk.c b/kernel/printk.c
69103 index 66a2ea3..10f3a01 100644
69104 --- a/kernel/printk.c
69105 +++ b/kernel/printk.c
69106 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69107 if (from_file && type != SYSLOG_ACTION_OPEN)
69108 return 0;
69109
69110 +#ifdef CONFIG_GRKERNSEC_DMESG
69111 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69112 + return -EPERM;
69113 +#endif
69114 +
69115 if (syslog_action_restricted(type)) {
69116 if (capable(CAP_SYSLOG))
69117 return 0;
69118 diff --git a/kernel/profile.c b/kernel/profile.c
69119 index 76b8e77..a2930e8 100644
69120 --- a/kernel/profile.c
69121 +++ b/kernel/profile.c
69122 @@ -39,7 +39,7 @@ struct profile_hit {
69123 /* Oprofile timer tick hook */
69124 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69125
69126 -static atomic_t *prof_buffer;
69127 +static atomic_unchecked_t *prof_buffer;
69128 static unsigned long prof_len, prof_shift;
69129
69130 int prof_on __read_mostly;
69131 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69132 hits[i].pc = 0;
69133 continue;
69134 }
69135 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69136 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69137 hits[i].hits = hits[i].pc = 0;
69138 }
69139 }
69140 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69141 * Add the current hit(s) and flush the write-queue out
69142 * to the global buffer:
69143 */
69144 - atomic_add(nr_hits, &prof_buffer[pc]);
69145 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69146 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69147 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69148 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69149 hits[i].pc = hits[i].hits = 0;
69150 }
69151 out:
69152 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69153 {
69154 unsigned long pc;
69155 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69156 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69157 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69158 }
69159 #endif /* !CONFIG_SMP */
69160
69161 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69162 return -EFAULT;
69163 buf++; p++; count--; read++;
69164 }
69165 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69166 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69167 if (copy_to_user(buf, (void *)pnt, count))
69168 return -EFAULT;
69169 read += count;
69170 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69171 }
69172 #endif
69173 profile_discard_flip_buffers();
69174 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69175 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69176 return count;
69177 }
69178
69179 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69180 index a232bb5..2a65ef9 100644
69181 --- a/kernel/ptrace.c
69182 +++ b/kernel/ptrace.c
69183 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69184
69185 if (seize)
69186 flags |= PT_SEIZED;
69187 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69188 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69189 flags |= PT_PTRACE_CAP;
69190 task->ptrace = flags;
69191
69192 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69193 break;
69194 return -EIO;
69195 }
69196 - if (copy_to_user(dst, buf, retval))
69197 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69198 return -EFAULT;
69199 copied += retval;
69200 src += retval;
69201 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69202 bool seized = child->ptrace & PT_SEIZED;
69203 int ret = -EIO;
69204 siginfo_t siginfo, *si;
69205 - void __user *datavp = (void __user *) data;
69206 + void __user *datavp = (__force void __user *) data;
69207 unsigned long __user *datalp = datavp;
69208 unsigned long flags;
69209
69210 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69211 goto out;
69212 }
69213
69214 + if (gr_handle_ptrace(child, request)) {
69215 + ret = -EPERM;
69216 + goto out_put_task_struct;
69217 + }
69218 +
69219 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69220 ret = ptrace_attach(child, request, addr, data);
69221 /*
69222 * Some architectures need to do book-keeping after
69223 * a ptrace attach.
69224 */
69225 - if (!ret)
69226 + if (!ret) {
69227 arch_ptrace_attach(child);
69228 + gr_audit_ptrace(child);
69229 + }
69230 goto out_put_task_struct;
69231 }
69232
69233 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69234 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69235 if (copied != sizeof(tmp))
69236 return -EIO;
69237 - return put_user(tmp, (unsigned long __user *)data);
69238 + return put_user(tmp, (__force unsigned long __user *)data);
69239 }
69240
69241 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69242 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69243 goto out;
69244 }
69245
69246 + if (gr_handle_ptrace(child, request)) {
69247 + ret = -EPERM;
69248 + goto out_put_task_struct;
69249 + }
69250 +
69251 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69252 ret = ptrace_attach(child, request, addr, data);
69253 /*
69254 * Some architectures need to do book-keeping after
69255 * a ptrace attach.
69256 */
69257 - if (!ret)
69258 + if (!ret) {
69259 arch_ptrace_attach(child);
69260 + gr_audit_ptrace(child);
69261 + }
69262 goto out_put_task_struct;
69263 }
69264
69265 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69266 index 547b1fe..65e874e 100644
69267 --- a/kernel/rcutiny.c
69268 +++ b/kernel/rcutiny.c
69269 @@ -46,7 +46,7 @@
69270 struct rcu_ctrlblk;
69271 static void invoke_rcu_callbacks(void);
69272 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69273 -static void rcu_process_callbacks(struct softirq_action *unused);
69274 +static void rcu_process_callbacks(void);
69275 static void __call_rcu(struct rcu_head *head,
69276 void (*func)(struct rcu_head *rcu),
69277 struct rcu_ctrlblk *rcp);
69278 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69279 rcu_is_callbacks_kthread()));
69280 }
69281
69282 -static void rcu_process_callbacks(struct softirq_action *unused)
69283 +static void rcu_process_callbacks(void)
69284 {
69285 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69286 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69287 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69288 index 918fd1e..85089bb 100644
69289 --- a/kernel/rcutiny_plugin.h
69290 +++ b/kernel/rcutiny_plugin.h
69291 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69292 have_rcu_kthread_work = morework;
69293 local_irq_restore(flags);
69294 if (work)
69295 - rcu_process_callbacks(NULL);
69296 + rcu_process_callbacks();
69297 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69298 }
69299
69300 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69301 index 25b1503..1988a74 100644
69302 --- a/kernel/rcutorture.c
69303 +++ b/kernel/rcutorture.c
69304 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69305 { 0 };
69306 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69307 { 0 };
69308 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69309 -static atomic_t n_rcu_torture_alloc;
69310 -static atomic_t n_rcu_torture_alloc_fail;
69311 -static atomic_t n_rcu_torture_free;
69312 -static atomic_t n_rcu_torture_mberror;
69313 -static atomic_t n_rcu_torture_error;
69314 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69315 +static atomic_unchecked_t n_rcu_torture_alloc;
69316 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69317 +static atomic_unchecked_t n_rcu_torture_free;
69318 +static atomic_unchecked_t n_rcu_torture_mberror;
69319 +static atomic_unchecked_t n_rcu_torture_error;
69320 static long n_rcu_torture_barrier_error;
69321 static long n_rcu_torture_boost_ktrerror;
69322 static long n_rcu_torture_boost_rterror;
69323 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69324
69325 spin_lock_bh(&rcu_torture_lock);
69326 if (list_empty(&rcu_torture_freelist)) {
69327 - atomic_inc(&n_rcu_torture_alloc_fail);
69328 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69329 spin_unlock_bh(&rcu_torture_lock);
69330 return NULL;
69331 }
69332 - atomic_inc(&n_rcu_torture_alloc);
69333 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69334 p = rcu_torture_freelist.next;
69335 list_del_init(p);
69336 spin_unlock_bh(&rcu_torture_lock);
69337 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69338 static void
69339 rcu_torture_free(struct rcu_torture *p)
69340 {
69341 - atomic_inc(&n_rcu_torture_free);
69342 + atomic_inc_unchecked(&n_rcu_torture_free);
69343 spin_lock_bh(&rcu_torture_lock);
69344 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69345 spin_unlock_bh(&rcu_torture_lock);
69346 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69347 i = rp->rtort_pipe_count;
69348 if (i > RCU_TORTURE_PIPE_LEN)
69349 i = RCU_TORTURE_PIPE_LEN;
69350 - atomic_inc(&rcu_torture_wcount[i]);
69351 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69352 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69353 rp->rtort_mbtest = 0;
69354 rcu_torture_free(rp);
69355 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69356 i = rp->rtort_pipe_count;
69357 if (i > RCU_TORTURE_PIPE_LEN)
69358 i = RCU_TORTURE_PIPE_LEN;
69359 - atomic_inc(&rcu_torture_wcount[i]);
69360 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69361 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69362 rp->rtort_mbtest = 0;
69363 list_del(&rp->rtort_free);
69364 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69365 i = old_rp->rtort_pipe_count;
69366 if (i > RCU_TORTURE_PIPE_LEN)
69367 i = RCU_TORTURE_PIPE_LEN;
69368 - atomic_inc(&rcu_torture_wcount[i]);
69369 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69370 old_rp->rtort_pipe_count++;
69371 cur_ops->deferred_free(old_rp);
69372 }
69373 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69374 }
69375 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69376 if (p->rtort_mbtest == 0)
69377 - atomic_inc(&n_rcu_torture_mberror);
69378 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69379 spin_lock(&rand_lock);
69380 cur_ops->read_delay(&rand);
69381 n_rcu_torture_timers++;
69382 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69383 }
69384 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69385 if (p->rtort_mbtest == 0)
69386 - atomic_inc(&n_rcu_torture_mberror);
69387 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69388 cur_ops->read_delay(&rand);
69389 preempt_disable();
69390 pipe_count = p->rtort_pipe_count;
69391 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69392 rcu_torture_current,
69393 rcu_torture_current_version,
69394 list_empty(&rcu_torture_freelist),
69395 - atomic_read(&n_rcu_torture_alloc),
69396 - atomic_read(&n_rcu_torture_alloc_fail),
69397 - atomic_read(&n_rcu_torture_free));
69398 + atomic_read_unchecked(&n_rcu_torture_alloc),
69399 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69400 + atomic_read_unchecked(&n_rcu_torture_free));
69401 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69402 - atomic_read(&n_rcu_torture_mberror),
69403 + atomic_read_unchecked(&n_rcu_torture_mberror),
69404 n_rcu_torture_boost_ktrerror,
69405 n_rcu_torture_boost_rterror);
69406 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69407 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69408 n_barrier_attempts,
69409 n_rcu_torture_barrier_error);
69410 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69411 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69412 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69413 n_rcu_torture_barrier_error != 0 ||
69414 n_rcu_torture_boost_ktrerror != 0 ||
69415 n_rcu_torture_boost_rterror != 0 ||
69416 n_rcu_torture_boost_failure != 0 ||
69417 i > 1) {
69418 cnt += sprintf(&page[cnt], "!!! ");
69419 - atomic_inc(&n_rcu_torture_error);
69420 + atomic_inc_unchecked(&n_rcu_torture_error);
69421 WARN_ON_ONCE(1);
69422 }
69423 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69424 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69425 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69426 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69427 cnt += sprintf(&page[cnt], " %d",
69428 - atomic_read(&rcu_torture_wcount[i]));
69429 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69430 }
69431 cnt += sprintf(&page[cnt], "\n");
69432 if (cur_ops->stats)
69433 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69434
69435 if (cur_ops->cleanup)
69436 cur_ops->cleanup();
69437 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69438 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69439 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69440 else if (n_online_successes != n_online_attempts ||
69441 n_offline_successes != n_offline_attempts)
69442 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69443
69444 rcu_torture_current = NULL;
69445 rcu_torture_current_version = 0;
69446 - atomic_set(&n_rcu_torture_alloc, 0);
69447 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69448 - atomic_set(&n_rcu_torture_free, 0);
69449 - atomic_set(&n_rcu_torture_mberror, 0);
69450 - atomic_set(&n_rcu_torture_error, 0);
69451 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69452 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69453 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69454 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69455 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69456 n_rcu_torture_barrier_error = 0;
69457 n_rcu_torture_boost_ktrerror = 0;
69458 n_rcu_torture_boost_rterror = 0;
69459 n_rcu_torture_boost_failure = 0;
69460 n_rcu_torture_boosts = 0;
69461 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69462 - atomic_set(&rcu_torture_wcount[i], 0);
69463 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69464 for_each_possible_cpu(cpu) {
69465 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69466 per_cpu(rcu_torture_count, cpu)[i] = 0;
69467 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69468 index f7bcd9e..8973e14 100644
69469 --- a/kernel/rcutree.c
69470 +++ b/kernel/rcutree.c
69471 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69472 rcu_prepare_for_idle(smp_processor_id());
69473 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69474 smp_mb__before_atomic_inc(); /* See above. */
69475 - atomic_inc(&rdtp->dynticks);
69476 + atomic_inc_unchecked(&rdtp->dynticks);
69477 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69478 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69479 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69480
69481 /*
69482 * The idle task is not permitted to enter the idle loop while
69483 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69484 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69485 {
69486 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69487 - atomic_inc(&rdtp->dynticks);
69488 + atomic_inc_unchecked(&rdtp->dynticks);
69489 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69490 smp_mb__after_atomic_inc(); /* See above. */
69491 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69492 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69493 rcu_cleanup_after_idle(smp_processor_id());
69494 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69495 if (!is_idle_task(current)) {
69496 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69497 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69498
69499 if (rdtp->dynticks_nmi_nesting == 0 &&
69500 - (atomic_read(&rdtp->dynticks) & 0x1))
69501 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69502 return;
69503 rdtp->dynticks_nmi_nesting++;
69504 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69505 - atomic_inc(&rdtp->dynticks);
69506 + atomic_inc_unchecked(&rdtp->dynticks);
69507 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69508 smp_mb__after_atomic_inc(); /* See above. */
69509 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69510 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69511 }
69512
69513 /**
69514 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69515 return;
69516 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69517 smp_mb__before_atomic_inc(); /* See above. */
69518 - atomic_inc(&rdtp->dynticks);
69519 + atomic_inc_unchecked(&rdtp->dynticks);
69520 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69521 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69522 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69523 }
69524
69525 /**
69526 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69527 int ret;
69528
69529 preempt_disable();
69530 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69531 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69532 preempt_enable();
69533 return ret;
69534 }
69535 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69536 */
69537 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69538 {
69539 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69540 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69541 return (rdp->dynticks_snap & 0x1) == 0;
69542 }
69543
69544 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69545 unsigned int curr;
69546 unsigned int snap;
69547
69548 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69549 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69550 snap = (unsigned int)rdp->dynticks_snap;
69551
69552 /*
69553 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69554 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69555 */
69556 if (till_stall_check < 3) {
69557 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69558 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69559 till_stall_check = 3;
69560 } else if (till_stall_check > 300) {
69561 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69562 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69563 till_stall_check = 300;
69564 }
69565 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69566 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69567 rsp->qlen += rdp->qlen;
69568 rdp->n_cbs_orphaned += rdp->qlen;
69569 rdp->qlen_lazy = 0;
69570 - ACCESS_ONCE(rdp->qlen) = 0;
69571 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69572 }
69573
69574 /*
69575 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69576 }
69577 smp_mb(); /* List handling before counting for rcu_barrier(). */
69578 rdp->qlen_lazy -= count_lazy;
69579 - ACCESS_ONCE(rdp->qlen) -= count;
69580 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69581 rdp->n_cbs_invoked += count;
69582
69583 /* Reinstate batch limit if we have worked down the excess. */
69584 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69585 /*
69586 * Do RCU core processing for the current CPU.
69587 */
69588 -static void rcu_process_callbacks(struct softirq_action *unused)
69589 +static void rcu_process_callbacks(void)
69590 {
69591 struct rcu_state *rsp;
69592
69593 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69594 rdp = this_cpu_ptr(rsp->rda);
69595
69596 /* Add the callback to our list. */
69597 - ACCESS_ONCE(rdp->qlen)++;
69598 + ACCESS_ONCE_RW(rdp->qlen)++;
69599 if (lazy)
69600 rdp->qlen_lazy++;
69601 else
69602 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69603 }
69604 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69605
69606 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69607 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69608 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69609 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69610
69611 static int synchronize_sched_expedited_cpu_stop(void *data)
69612 {
69613 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69614 int firstsnap, s, snap, trycount = 0;
69615
69616 /* Note that atomic_inc_return() implies full memory barrier. */
69617 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69618 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69619 get_online_cpus();
69620 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69621
69622 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69623 }
69624
69625 /* Check to see if someone else did our work for us. */
69626 - s = atomic_read(&sync_sched_expedited_done);
69627 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69628 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69629 smp_mb(); /* ensure test happens before caller kfree */
69630 return;
69631 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69632 * grace period works for us.
69633 */
69634 get_online_cpus();
69635 - snap = atomic_read(&sync_sched_expedited_started);
69636 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69637 smp_mb(); /* ensure read is before try_stop_cpus(). */
69638 }
69639
69640 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69641 * than we did beat us to the punch.
69642 */
69643 do {
69644 - s = atomic_read(&sync_sched_expedited_done);
69645 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69646 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69647 smp_mb(); /* ensure test happens before caller kfree */
69648 break;
69649 }
69650 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69651 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69652
69653 put_online_cpus();
69654 }
69655 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69656 * ACCESS_ONCE() to prevent the compiler from speculating
69657 * the increment to precede the early-exit check.
69658 */
69659 - ACCESS_ONCE(rsp->n_barrier_done)++;
69660 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69661 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69662 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69663 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69664 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69665
69666 /* Increment ->n_barrier_done to prevent duplicate work. */
69667 smp_mb(); /* Keep increment after above mechanism. */
69668 - ACCESS_ONCE(rsp->n_barrier_done)++;
69669 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69670 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69671 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69672 smp_mb(); /* Keep increment before caller's subsequent code. */
69673 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69674 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69675 init_callback_list(rdp);
69676 rdp->qlen_lazy = 0;
69677 - ACCESS_ONCE(rdp->qlen) = 0;
69678 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69679 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69680 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69681 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69682 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69683 rdp->cpu = cpu;
69684 rdp->rsp = rsp;
69685 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69686 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69687 rdp->n_force_qs_snap = rsp->n_force_qs;
69688 rdp->blimit = blimit;
69689 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69690 - atomic_set(&rdp->dynticks->dynticks,
69691 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69692 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69693 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69694 rcu_prepare_for_idle_init(cpu);
69695 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69696
69697 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69698 index 4d29169..d104a3c 100644
69699 --- a/kernel/rcutree.h
69700 +++ b/kernel/rcutree.h
69701 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69702 long long dynticks_nesting; /* Track irq/process nesting level. */
69703 /* Process level is worth LLONG_MAX/2. */
69704 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69705 - atomic_t dynticks; /* Even value for idle, else odd. */
69706 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69707 #ifdef CONFIG_RCU_FAST_NO_HZ
69708 int dyntick_drain; /* Prepare-for-idle state variable. */
69709 unsigned long dyntick_holdoff;
69710 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69711 index 7f3244c..417d606 100644
69712 --- a/kernel/rcutree_plugin.h
69713 +++ b/kernel/rcutree_plugin.h
69714 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69715
69716 /* Clean up and exit. */
69717 smp_mb(); /* ensure expedited GP seen before counter increment. */
69718 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69719 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69720 unlock_mb_ret:
69721 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69722 mb_ret:
69723 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69724 index abffb48..cbfa6d3 100644
69725 --- a/kernel/rcutree_trace.c
69726 +++ b/kernel/rcutree_trace.c
69727 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69728 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69729 rdp->qs_pending);
69730 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69731 - atomic_read(&rdp->dynticks->dynticks),
69732 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69733 rdp->dynticks->dynticks_nesting,
69734 rdp->dynticks->dynticks_nmi_nesting,
69735 rdp->dynticks_fqs);
69736 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69737 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69738 rdp->qs_pending);
69739 seq_printf(m, ",%d,%llx,%d,%lu",
69740 - atomic_read(&rdp->dynticks->dynticks),
69741 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69742 rdp->dynticks->dynticks_nesting,
69743 rdp->dynticks->dynticks_nmi_nesting,
69744 rdp->dynticks_fqs);
69745 diff --git a/kernel/resource.c b/kernel/resource.c
69746 index 34d4588..10baa6a 100644
69747 --- a/kernel/resource.c
69748 +++ b/kernel/resource.c
69749 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69750
69751 static int __init ioresources_init(void)
69752 {
69753 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69754 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69755 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69756 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69757 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69758 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69759 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69760 +#endif
69761 +#else
69762 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69763 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69764 +#endif
69765 return 0;
69766 }
69767 __initcall(ioresources_init);
69768 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69769 index 98ec494..4241d6d 100644
69770 --- a/kernel/rtmutex-tester.c
69771 +++ b/kernel/rtmutex-tester.c
69772 @@ -20,7 +20,7 @@
69773 #define MAX_RT_TEST_MUTEXES 8
69774
69775 static spinlock_t rttest_lock;
69776 -static atomic_t rttest_event;
69777 +static atomic_unchecked_t rttest_event;
69778
69779 struct test_thread_data {
69780 int opcode;
69781 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69782
69783 case RTTEST_LOCKCONT:
69784 td->mutexes[td->opdata] = 1;
69785 - td->event = atomic_add_return(1, &rttest_event);
69786 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69787 return 0;
69788
69789 case RTTEST_RESET:
69790 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69791 return 0;
69792
69793 case RTTEST_RESETEVENT:
69794 - atomic_set(&rttest_event, 0);
69795 + atomic_set_unchecked(&rttest_event, 0);
69796 return 0;
69797
69798 default:
69799 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69800 return ret;
69801
69802 td->mutexes[id] = 1;
69803 - td->event = atomic_add_return(1, &rttest_event);
69804 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69805 rt_mutex_lock(&mutexes[id]);
69806 - td->event = atomic_add_return(1, &rttest_event);
69807 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69808 td->mutexes[id] = 4;
69809 return 0;
69810
69811 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69812 return ret;
69813
69814 td->mutexes[id] = 1;
69815 - td->event = atomic_add_return(1, &rttest_event);
69816 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69817 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69818 - td->event = atomic_add_return(1, &rttest_event);
69819 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69820 td->mutexes[id] = ret ? 0 : 4;
69821 return ret ? -EINTR : 0;
69822
69823 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69824 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69825 return ret;
69826
69827 - td->event = atomic_add_return(1, &rttest_event);
69828 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69829 rt_mutex_unlock(&mutexes[id]);
69830 - td->event = atomic_add_return(1, &rttest_event);
69831 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69832 td->mutexes[id] = 0;
69833 return 0;
69834
69835 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69836 break;
69837
69838 td->mutexes[dat] = 2;
69839 - td->event = atomic_add_return(1, &rttest_event);
69840 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69841 break;
69842
69843 default:
69844 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69845 return;
69846
69847 td->mutexes[dat] = 3;
69848 - td->event = atomic_add_return(1, &rttest_event);
69849 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69850 break;
69851
69852 case RTTEST_LOCKNOWAIT:
69853 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69854 return;
69855
69856 td->mutexes[dat] = 1;
69857 - td->event = atomic_add_return(1, &rttest_event);
69858 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69859 return;
69860
69861 default:
69862 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69863 index 0984a21..939f183 100644
69864 --- a/kernel/sched/auto_group.c
69865 +++ b/kernel/sched/auto_group.c
69866 @@ -11,7 +11,7 @@
69867
69868 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69869 static struct autogroup autogroup_default;
69870 -static atomic_t autogroup_seq_nr;
69871 +static atomic_unchecked_t autogroup_seq_nr;
69872
69873 void __init autogroup_init(struct task_struct *init_task)
69874 {
69875 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69876
69877 kref_init(&ag->kref);
69878 init_rwsem(&ag->lock);
69879 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69880 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69881 ag->tg = tg;
69882 #ifdef CONFIG_RT_GROUP_SCHED
69883 /*
69884 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69885 index 1a48cdb..d3949ff 100644
69886 --- a/kernel/sched/core.c
69887 +++ b/kernel/sched/core.c
69888 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69889 /* convert nice value [19,-20] to rlimit style value [1,40] */
69890 int nice_rlim = 20 - nice;
69891
69892 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69893 +
69894 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69895 capable(CAP_SYS_NICE));
69896 }
69897 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69898 if (nice > 19)
69899 nice = 19;
69900
69901 - if (increment < 0 && !can_nice(current, nice))
69902 + if (increment < 0 && (!can_nice(current, nice) ||
69903 + gr_handle_chroot_nice()))
69904 return -EPERM;
69905
69906 retval = security_task_setnice(current, nice);
69907 @@ -4290,6 +4293,7 @@ recheck:
69908 unsigned long rlim_rtprio =
69909 task_rlimit(p, RLIMIT_RTPRIO);
69910
69911 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69912 /* can't set/change the rt policy */
69913 if (policy != p->policy && !rlim_rtprio)
69914 return -EPERM;
69915 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69916 index 96e2b18..bb31eec 100644
69917 --- a/kernel/sched/fair.c
69918 +++ b/kernel/sched/fair.c
69919 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69920 * run_rebalance_domains is triggered when needed from the scheduler tick.
69921 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69922 */
69923 -static void run_rebalance_domains(struct softirq_action *h)
69924 +static void run_rebalance_domains(void)
69925 {
69926 int this_cpu = smp_processor_id();
69927 struct rq *this_rq = cpu_rq(this_cpu);
69928 diff --git a/kernel/signal.c b/kernel/signal.c
69929 index be4f856..453401c 100644
69930 --- a/kernel/signal.c
69931 +++ b/kernel/signal.c
69932 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69933
69934 int print_fatal_signals __read_mostly;
69935
69936 -static void __user *sig_handler(struct task_struct *t, int sig)
69937 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69938 {
69939 return t->sighand->action[sig - 1].sa.sa_handler;
69940 }
69941
69942 -static int sig_handler_ignored(void __user *handler, int sig)
69943 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69944 {
69945 /* Is it explicitly or implicitly ignored? */
69946 return handler == SIG_IGN ||
69947 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69948
69949 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69950 {
69951 - void __user *handler;
69952 + __sighandler_t handler;
69953
69954 handler = sig_handler(t, sig);
69955
69956 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69957 atomic_inc(&user->sigpending);
69958 rcu_read_unlock();
69959
69960 + if (!override_rlimit)
69961 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69962 +
69963 if (override_rlimit ||
69964 atomic_read(&user->sigpending) <=
69965 task_rlimit(t, RLIMIT_SIGPENDING)) {
69966 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69967
69968 int unhandled_signal(struct task_struct *tsk, int sig)
69969 {
69970 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69971 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69972 if (is_global_init(tsk))
69973 return 1;
69974 if (handler != SIG_IGN && handler != SIG_DFL)
69975 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69976 }
69977 }
69978
69979 + /* allow glibc communication via tgkill to other threads in our
69980 + thread group */
69981 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69982 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69983 + && gr_handle_signal(t, sig))
69984 + return -EPERM;
69985 +
69986 return security_task_kill(t, info, sig, 0);
69987 }
69988
69989 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69990 return send_signal(sig, info, p, 1);
69991 }
69992
69993 -static int
69994 +int
69995 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69996 {
69997 return send_signal(sig, info, t, 0);
69998 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69999 unsigned long int flags;
70000 int ret, blocked, ignored;
70001 struct k_sigaction *action;
70002 + int is_unhandled = 0;
70003
70004 spin_lock_irqsave(&t->sighand->siglock, flags);
70005 action = &t->sighand->action[sig-1];
70006 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70007 }
70008 if (action->sa.sa_handler == SIG_DFL)
70009 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70010 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70011 + is_unhandled = 1;
70012 ret = specific_send_sig_info(sig, info, t);
70013 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70014
70015 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70016 + normal operation */
70017 + if (is_unhandled) {
70018 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70019 + gr_handle_crash(t, sig);
70020 + }
70021 +
70022 return ret;
70023 }
70024
70025 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70026 ret = check_kill_permission(sig, info, p);
70027 rcu_read_unlock();
70028
70029 - if (!ret && sig)
70030 + if (!ret && sig) {
70031 ret = do_send_sig_info(sig, info, p, true);
70032 + if (!ret)
70033 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70034 + }
70035
70036 return ret;
70037 }
70038 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70039 int error = -ESRCH;
70040
70041 rcu_read_lock();
70042 - p = find_task_by_vpid(pid);
70043 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70044 + /* allow glibc communication via tgkill to other threads in our
70045 + thread group */
70046 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70047 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70048 + p = find_task_by_vpid_unrestricted(pid);
70049 + else
70050 +#endif
70051 + p = find_task_by_vpid(pid);
70052 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70053 error = check_kill_permission(sig, info, p);
70054 /*
70055 diff --git a/kernel/softirq.c b/kernel/softirq.c
70056 index b73e681..645ab62 100644
70057 --- a/kernel/softirq.c
70058 +++ b/kernel/softirq.c
70059 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70060
70061 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70062
70063 -char *softirq_to_name[NR_SOFTIRQS] = {
70064 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70065 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70066 "TASKLET", "SCHED", "HRTIMER", "RCU"
70067 };
70068 @@ -243,7 +243,7 @@ restart:
70069 kstat_incr_softirqs_this_cpu(vec_nr);
70070
70071 trace_softirq_entry(vec_nr);
70072 - h->action(h);
70073 + h->action();
70074 trace_softirq_exit(vec_nr);
70075 if (unlikely(prev_count != preempt_count())) {
70076 printk(KERN_ERR "huh, entered softirq %u %s %p"
70077 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70078 or_softirq_pending(1UL << nr);
70079 }
70080
70081 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70082 +void open_softirq(int nr, void (*action)(void))
70083 {
70084 - softirq_vec[nr].action = action;
70085 + pax_open_kernel();
70086 + *(void **)&softirq_vec[nr].action = action;
70087 + pax_close_kernel();
70088 }
70089
70090 /*
70091 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70092
70093 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70094
70095 -static void tasklet_action(struct softirq_action *a)
70096 +static void tasklet_action(void)
70097 {
70098 struct tasklet_struct *list;
70099
70100 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70101 }
70102 }
70103
70104 -static void tasklet_hi_action(struct softirq_action *a)
70105 +static void tasklet_hi_action(void)
70106 {
70107 struct tasklet_struct *list;
70108
70109 diff --git a/kernel/srcu.c b/kernel/srcu.c
70110 index 2095be3..9a5b89d 100644
70111 --- a/kernel/srcu.c
70112 +++ b/kernel/srcu.c
70113 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70114 preempt_disable();
70115 idx = rcu_dereference_index_check(sp->completed,
70116 rcu_read_lock_sched_held()) & 0x1;
70117 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70118 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70119 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70120 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70121 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70122 preempt_enable();
70123 return idx;
70124 }
70125 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70126 {
70127 preempt_disable();
70128 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70129 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70130 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70131 preempt_enable();
70132 }
70133 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70134 diff --git a/kernel/sys.c b/kernel/sys.c
70135 index 6fab59a..4ad079b 100644
70136 --- a/kernel/sys.c
70137 +++ b/kernel/sys.c
70138 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70139 error = -EACCES;
70140 goto out;
70141 }
70142 +
70143 + if (gr_handle_chroot_setpriority(p, niceval)) {
70144 + error = -EACCES;
70145 + goto out;
70146 + }
70147 +
70148 no_nice = security_task_setnice(p, niceval);
70149 if (no_nice) {
70150 error = no_nice;
70151 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70152 goto error;
70153 }
70154
70155 + if (gr_check_group_change(new->gid, new->egid, -1))
70156 + goto error;
70157 +
70158 if (rgid != (gid_t) -1 ||
70159 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70160 new->sgid = new->egid;
70161 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70162 old = current_cred();
70163
70164 retval = -EPERM;
70165 +
70166 + if (gr_check_group_change(kgid, kgid, kgid))
70167 + goto error;
70168 +
70169 if (nsown_capable(CAP_SETGID))
70170 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70171 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70172 @@ -647,7 +660,7 @@ error:
70173 /*
70174 * change the user struct in a credentials set to match the new UID
70175 */
70176 -static int set_user(struct cred *new)
70177 +int set_user(struct cred *new)
70178 {
70179 struct user_struct *new_user;
70180
70181 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70182 goto error;
70183 }
70184
70185 + if (gr_check_user_change(new->uid, new->euid, -1))
70186 + goto error;
70187 +
70188 if (!uid_eq(new->uid, old->uid)) {
70189 retval = set_user(new);
70190 if (retval < 0)
70191 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70192 old = current_cred();
70193
70194 retval = -EPERM;
70195 +
70196 + if (gr_check_crash_uid(kuid))
70197 + goto error;
70198 + if (gr_check_user_change(kuid, kuid, kuid))
70199 + goto error;
70200 +
70201 if (nsown_capable(CAP_SETUID)) {
70202 new->suid = new->uid = kuid;
70203 if (!uid_eq(kuid, old->uid)) {
70204 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70205 goto error;
70206 }
70207
70208 + if (gr_check_user_change(kruid, keuid, -1))
70209 + goto error;
70210 +
70211 if (ruid != (uid_t) -1) {
70212 new->uid = kruid;
70213 if (!uid_eq(kruid, old->uid)) {
70214 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70215 goto error;
70216 }
70217
70218 + if (gr_check_group_change(krgid, kegid, -1))
70219 + goto error;
70220 +
70221 if (rgid != (gid_t) -1)
70222 new->gid = krgid;
70223 if (egid != (gid_t) -1)
70224 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70225 if (!uid_valid(kuid))
70226 return old_fsuid;
70227
70228 + if (gr_check_user_change(-1, -1, kuid))
70229 + goto error;
70230 +
70231 new = prepare_creds();
70232 if (!new)
70233 return old_fsuid;
70234 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70235 }
70236 }
70237
70238 +error:
70239 abort_creds(new);
70240 return old_fsuid;
70241
70242 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70243 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70244 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70245 nsown_capable(CAP_SETGID)) {
70246 + if (gr_check_group_change(-1, -1, kgid))
70247 + goto error;
70248 +
70249 if (!gid_eq(kgid, old->fsgid)) {
70250 new->fsgid = kgid;
70251 goto change_okay;
70252 }
70253 }
70254
70255 +error:
70256 abort_creds(new);
70257 return old_fsgid;
70258
70259 @@ -1265,13 +1301,13 @@ DECLARE_RWSEM(uts_sem);
70260 * Work around broken programs that cannot handle "Linux 3.0".
70261 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70262 */
70263 -static int override_release(char __user *release, int len)
70264 +static int override_release(char __user *release, size_t len)
70265 {
70266 int ret = 0;
70267 - char buf[65];
70268
70269 if (current->personality & UNAME26) {
70270 - char *rest = UTS_RELEASE;
70271 + char buf[65] = { 0 };
70272 + const char *rest = UTS_RELEASE;
70273 int ndots = 0;
70274 unsigned v;
70275
70276 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
70277 rest++;
70278 }
70279 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70280 + if (sizeof buf < len)
70281 + len = sizeof buf;
70282 snprintf(buf, len, "2.6.%u%s", v, rest);
70283 + buf[len - 1] = 0;
70284 ret = copy_to_user(release, buf, len);
70285 }
70286 return ret;
70287 @@ -1338,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70288 return -EFAULT;
70289
70290 down_read(&uts_sem);
70291 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70292 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70293 __OLD_UTS_LEN);
70294 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70295 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70296 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70297 __OLD_UTS_LEN);
70298 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70299 - error |= __copy_to_user(&name->release, &utsname()->release,
70300 + error |= __copy_to_user(name->release, &utsname()->release,
70301 __OLD_UTS_LEN);
70302 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70303 - error |= __copy_to_user(&name->version, &utsname()->version,
70304 + error |= __copy_to_user(name->version, &utsname()->version,
70305 __OLD_UTS_LEN);
70306 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70307 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70308 + error |= __copy_to_user(name->machine, &utsname()->machine,
70309 __OLD_UTS_LEN);
70310 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70311 up_read(&uts_sem);
70312 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70313 error = get_dumpable(me->mm);
70314 break;
70315 case PR_SET_DUMPABLE:
70316 - if (arg2 < 0 || arg2 > 1) {
70317 + if (arg2 > 1) {
70318 error = -EINVAL;
70319 break;
70320 }
70321 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70322 index 87174ef..68cbb82 100644
70323 --- a/kernel/sysctl.c
70324 +++ b/kernel/sysctl.c
70325 @@ -92,7 +92,6 @@
70326
70327
70328 #if defined(CONFIG_SYSCTL)
70329 -
70330 /* External variables not in a header file. */
70331 extern int sysctl_overcommit_memory;
70332 extern int sysctl_overcommit_ratio;
70333 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70334 void __user *buffer, size_t *lenp, loff_t *ppos);
70335 #endif
70336
70337 -#ifdef CONFIG_PRINTK
70338 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70339 void __user *buffer, size_t *lenp, loff_t *ppos);
70340 -#endif
70341
70342 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70343 void __user *buffer, size_t *lenp, loff_t *ppos);
70344 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70345
70346 #endif
70347
70348 +extern struct ctl_table grsecurity_table[];
70349 +
70350 static struct ctl_table kern_table[];
70351 static struct ctl_table vm_table[];
70352 static struct ctl_table fs_table[];
70353 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70354 int sysctl_legacy_va_layout;
70355 #endif
70356
70357 +#ifdef CONFIG_PAX_SOFTMODE
70358 +static ctl_table pax_table[] = {
70359 + {
70360 + .procname = "softmode",
70361 + .data = &pax_softmode,
70362 + .maxlen = sizeof(unsigned int),
70363 + .mode = 0600,
70364 + .proc_handler = &proc_dointvec,
70365 + },
70366 +
70367 + { }
70368 +};
70369 +#endif
70370 +
70371 /* The default sysctl tables: */
70372
70373 static struct ctl_table sysctl_base_table[] = {
70374 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70375 #endif
70376
70377 static struct ctl_table kern_table[] = {
70378 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70379 + {
70380 + .procname = "grsecurity",
70381 + .mode = 0500,
70382 + .child = grsecurity_table,
70383 + },
70384 +#endif
70385 +
70386 +#ifdef CONFIG_PAX_SOFTMODE
70387 + {
70388 + .procname = "pax",
70389 + .mode = 0500,
70390 + .child = pax_table,
70391 + },
70392 +#endif
70393 +
70394 {
70395 .procname = "sched_child_runs_first",
70396 .data = &sysctl_sched_child_runs_first,
70397 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70398 .data = &modprobe_path,
70399 .maxlen = KMOD_PATH_LEN,
70400 .mode = 0644,
70401 - .proc_handler = proc_dostring,
70402 + .proc_handler = proc_dostring_modpriv,
70403 },
70404 {
70405 .procname = "modules_disabled",
70406 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70407 .extra1 = &zero,
70408 .extra2 = &one,
70409 },
70410 +#endif
70411 {
70412 .procname = "kptr_restrict",
70413 .data = &kptr_restrict,
70414 .maxlen = sizeof(int),
70415 .mode = 0644,
70416 .proc_handler = proc_dointvec_minmax_sysadmin,
70417 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70418 + .extra1 = &two,
70419 +#else
70420 .extra1 = &zero,
70421 +#endif
70422 .extra2 = &two,
70423 },
70424 -#endif
70425 {
70426 .procname = "ngroups_max",
70427 .data = &ngroups_max,
70428 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70429 .proc_handler = proc_dointvec_minmax,
70430 .extra1 = &zero,
70431 },
70432 + {
70433 + .procname = "heap_stack_gap",
70434 + .data = &sysctl_heap_stack_gap,
70435 + .maxlen = sizeof(sysctl_heap_stack_gap),
70436 + .mode = 0644,
70437 + .proc_handler = proc_doulongvec_minmax,
70438 + },
70439 #else
70440 {
70441 .procname = "nr_trim_pages",
70442 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70443 buffer, lenp, ppos);
70444 }
70445
70446 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70447 + void __user *buffer, size_t *lenp, loff_t *ppos)
70448 +{
70449 + if (write && !capable(CAP_SYS_MODULE))
70450 + return -EPERM;
70451 +
70452 + return _proc_do_string(table->data, table->maxlen, write,
70453 + buffer, lenp, ppos);
70454 +}
70455 +
70456 static size_t proc_skip_spaces(char **buf)
70457 {
70458 size_t ret;
70459 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70460 len = strlen(tmp);
70461 if (len > *size)
70462 len = *size;
70463 + if (len > sizeof(tmp))
70464 + len = sizeof(tmp);
70465 if (copy_to_user(*buf, tmp, len))
70466 return -EFAULT;
70467 *size -= len;
70468 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70469 return err;
70470 }
70471
70472 -#ifdef CONFIG_PRINTK
70473 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70474 void __user *buffer, size_t *lenp, loff_t *ppos)
70475 {
70476 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70477
70478 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70479 }
70480 -#endif
70481
70482 struct do_proc_dointvec_minmax_conv_param {
70483 int *min;
70484 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70485 *i = val;
70486 } else {
70487 val = convdiv * (*i) / convmul;
70488 - if (!first)
70489 + if (!first) {
70490 err = proc_put_char(&buffer, &left, '\t');
70491 + if (err)
70492 + break;
70493 + }
70494 err = proc_put_long(&buffer, &left, val, false);
70495 if (err)
70496 break;
70497 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70498 return -ENOSYS;
70499 }
70500
70501 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70502 + void __user *buffer, size_t *lenp, loff_t *ppos)
70503 +{
70504 + return -ENOSYS;
70505 +}
70506 +
70507 int proc_dointvec(struct ctl_table *table, int write,
70508 void __user *buffer, size_t *lenp, loff_t *ppos)
70509 {
70510 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70511 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70512 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70513 EXPORT_SYMBOL(proc_dostring);
70514 +EXPORT_SYMBOL(proc_dostring_modpriv);
70515 EXPORT_SYMBOL(proc_doulongvec_minmax);
70516 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70517 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70518 index 65bdcf1..21eb831 100644
70519 --- a/kernel/sysctl_binary.c
70520 +++ b/kernel/sysctl_binary.c
70521 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70522 int i;
70523
70524 set_fs(KERNEL_DS);
70525 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70526 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70527 set_fs(old_fs);
70528 if (result < 0)
70529 goto out_kfree;
70530 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70531 }
70532
70533 set_fs(KERNEL_DS);
70534 - result = vfs_write(file, buffer, str - buffer, &pos);
70535 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70536 set_fs(old_fs);
70537 if (result < 0)
70538 goto out_kfree;
70539 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70540 int i;
70541
70542 set_fs(KERNEL_DS);
70543 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70544 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70545 set_fs(old_fs);
70546 if (result < 0)
70547 goto out_kfree;
70548 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70549 }
70550
70551 set_fs(KERNEL_DS);
70552 - result = vfs_write(file, buffer, str - buffer, &pos);
70553 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70554 set_fs(old_fs);
70555 if (result < 0)
70556 goto out_kfree;
70557 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70558 int i;
70559
70560 set_fs(KERNEL_DS);
70561 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70562 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70563 set_fs(old_fs);
70564 if (result < 0)
70565 goto out;
70566 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70567 __le16 dnaddr;
70568
70569 set_fs(KERNEL_DS);
70570 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70571 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70572 set_fs(old_fs);
70573 if (result < 0)
70574 goto out;
70575 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70576 le16_to_cpu(dnaddr) & 0x3ff);
70577
70578 set_fs(KERNEL_DS);
70579 - result = vfs_write(file, buf, len, &pos);
70580 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70581 set_fs(old_fs);
70582 if (result < 0)
70583 goto out;
70584 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70585 index d0a3279..db0ad99 100644
70586 --- a/kernel/taskstats.c
70587 +++ b/kernel/taskstats.c
70588 @@ -27,9 +27,12 @@
70589 #include <linux/cgroup.h>
70590 #include <linux/fs.h>
70591 #include <linux/file.h>
70592 +#include <linux/grsecurity.h>
70593 #include <net/genetlink.h>
70594 #include <linux/atomic.h>
70595
70596 +extern int gr_is_taskstats_denied(int pid);
70597 +
70598 /*
70599 * Maximum length of a cpumask that can be specified in
70600 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70601 @@ -561,6 +564,9 @@ err:
70602
70603 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70604 {
70605 + if (gr_is_taskstats_denied(current->pid))
70606 + return -EACCES;
70607 +
70608 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70609 return cmd_attr_register_cpumask(info);
70610 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70611 diff --git a/kernel/time.c b/kernel/time.c
70612 index ba744cf..267b7c5 100644
70613 --- a/kernel/time.c
70614 +++ b/kernel/time.c
70615 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70616 return error;
70617
70618 if (tz) {
70619 + /* we log in do_settimeofday called below, so don't log twice
70620 + */
70621 + if (!tv)
70622 + gr_log_timechange();
70623 +
70624 sys_tz = *tz;
70625 update_vsyscall_tz();
70626 if (firsttime) {
70627 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70628 index aa27d39..34d221c 100644
70629 --- a/kernel/time/alarmtimer.c
70630 +++ b/kernel/time/alarmtimer.c
70631 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70632 struct platform_device *pdev;
70633 int error = 0;
70634 int i;
70635 - struct k_clock alarm_clock = {
70636 + static struct k_clock alarm_clock = {
70637 .clock_getres = alarm_clock_getres,
70638 .clock_get = alarm_clock_get,
70639 .timer_create = alarm_timer_create,
70640 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70641 index f113755..ec24223 100644
70642 --- a/kernel/time/tick-broadcast.c
70643 +++ b/kernel/time/tick-broadcast.c
70644 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70645 * then clear the broadcast bit.
70646 */
70647 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70648 - int cpu = smp_processor_id();
70649 + cpu = smp_processor_id();
70650
70651 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70652 tick_broadcast_clear_oneshot(cpu);
70653 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70654 index f791637..00051de 100644
70655 --- a/kernel/time/timekeeping.c
70656 +++ b/kernel/time/timekeeping.c
70657 @@ -14,6 +14,7 @@
70658 #include <linux/init.h>
70659 #include <linux/mm.h>
70660 #include <linux/sched.h>
70661 +#include <linux/grsecurity.h>
70662 #include <linux/syscore_ops.h>
70663 #include <linux/clocksource.h>
70664 #include <linux/jiffies.h>
70665 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70666 if (!timespec_valid_strict(tv))
70667 return -EINVAL;
70668
70669 + gr_log_timechange();
70670 +
70671 write_seqlock_irqsave(&tk->lock, flags);
70672
70673 timekeeping_forward_now(tk);
70674 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70675 index af5a7e9..715611a 100644
70676 --- a/kernel/time/timer_list.c
70677 +++ b/kernel/time/timer_list.c
70678 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70679
70680 static void print_name_offset(struct seq_file *m, void *sym)
70681 {
70682 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70683 + SEQ_printf(m, "<%p>", NULL);
70684 +#else
70685 char symname[KSYM_NAME_LEN];
70686
70687 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70688 SEQ_printf(m, "<%pK>", sym);
70689 else
70690 SEQ_printf(m, "%s", symname);
70691 +#endif
70692 }
70693
70694 static void
70695 @@ -112,7 +116,11 @@ next_one:
70696 static void
70697 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70698 {
70699 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70700 + SEQ_printf(m, " .base: %p\n", NULL);
70701 +#else
70702 SEQ_printf(m, " .base: %pK\n", base);
70703 +#endif
70704 SEQ_printf(m, " .index: %d\n",
70705 base->index);
70706 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70707 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70708 {
70709 struct proc_dir_entry *pe;
70710
70711 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70712 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70713 +#else
70714 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70715 +#endif
70716 if (!pe)
70717 return -ENOMEM;
70718 return 0;
70719 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70720 index 0b537f2..40d6c20 100644
70721 --- a/kernel/time/timer_stats.c
70722 +++ b/kernel/time/timer_stats.c
70723 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70724 static unsigned long nr_entries;
70725 static struct entry entries[MAX_ENTRIES];
70726
70727 -static atomic_t overflow_count;
70728 +static atomic_unchecked_t overflow_count;
70729
70730 /*
70731 * The entries are in a hash-table, for fast lookup:
70732 @@ -140,7 +140,7 @@ static void reset_entries(void)
70733 nr_entries = 0;
70734 memset(entries, 0, sizeof(entries));
70735 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70736 - atomic_set(&overflow_count, 0);
70737 + atomic_set_unchecked(&overflow_count, 0);
70738 }
70739
70740 static struct entry *alloc_entry(void)
70741 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70742 if (likely(entry))
70743 entry->count++;
70744 else
70745 - atomic_inc(&overflow_count);
70746 + atomic_inc_unchecked(&overflow_count);
70747
70748 out_unlock:
70749 raw_spin_unlock_irqrestore(lock, flags);
70750 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70751
70752 static void print_name_offset(struct seq_file *m, unsigned long addr)
70753 {
70754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70755 + seq_printf(m, "<%p>", NULL);
70756 +#else
70757 char symname[KSYM_NAME_LEN];
70758
70759 if (lookup_symbol_name(addr, symname) < 0)
70760 - seq_printf(m, "<%p>", (void *)addr);
70761 + seq_printf(m, "<%pK>", (void *)addr);
70762 else
70763 seq_printf(m, "%s", symname);
70764 +#endif
70765 }
70766
70767 static int tstats_show(struct seq_file *m, void *v)
70768 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70769
70770 seq_puts(m, "Timer Stats Version: v0.2\n");
70771 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70772 - if (atomic_read(&overflow_count))
70773 + if (atomic_read_unchecked(&overflow_count))
70774 seq_printf(m, "Overflow: %d entries\n",
70775 - atomic_read(&overflow_count));
70776 + atomic_read_unchecked(&overflow_count));
70777
70778 for (i = 0; i < nr_entries; i++) {
70779 entry = entries + i;
70780 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70781 {
70782 struct proc_dir_entry *pe;
70783
70784 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70785 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70786 +#else
70787 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70788 +#endif
70789 if (!pe)
70790 return -ENOMEM;
70791 return 0;
70792 diff --git a/kernel/timer.c b/kernel/timer.c
70793 index 46ef2b1..ad081f144 100644
70794 --- a/kernel/timer.c
70795 +++ b/kernel/timer.c
70796 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70797 /*
70798 * This function runs timers and the timer-tq in bottom half context.
70799 */
70800 -static void run_timer_softirq(struct softirq_action *h)
70801 +static void run_timer_softirq(void)
70802 {
70803 struct tvec_base *base = __this_cpu_read(tvec_bases);
70804
70805 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70806 index c0bd030..62a1927 100644
70807 --- a/kernel/trace/blktrace.c
70808 +++ b/kernel/trace/blktrace.c
70809 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70810 struct blk_trace *bt = filp->private_data;
70811 char buf[16];
70812
70813 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70814 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70815
70816 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70817 }
70818 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70819 return 1;
70820
70821 bt = buf->chan->private_data;
70822 - atomic_inc(&bt->dropped);
70823 + atomic_inc_unchecked(&bt->dropped);
70824 return 0;
70825 }
70826
70827 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70828
70829 bt->dir = dir;
70830 bt->dev = dev;
70831 - atomic_set(&bt->dropped, 0);
70832 + atomic_set_unchecked(&bt->dropped, 0);
70833
70834 ret = -EIO;
70835 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70836 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70837 index b4f20fb..483c5fa 100644
70838 --- a/kernel/trace/ftrace.c
70839 +++ b/kernel/trace/ftrace.c
70840 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70841 if (unlikely(ftrace_disabled))
70842 return 0;
70843
70844 + ret = ftrace_arch_code_modify_prepare();
70845 + FTRACE_WARN_ON(ret);
70846 + if (ret)
70847 + return 0;
70848 +
70849 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70850 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70851 if (ret) {
70852 ftrace_bug(ret, ip);
70853 - return 0;
70854 }
70855 - return 1;
70856 + return ret ? 0 : 1;
70857 }
70858
70859 /*
70860 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70861
70862 int
70863 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70864 - void *data)
70865 + void *data)
70866 {
70867 struct ftrace_func_probe *entry;
70868 struct ftrace_page *pg;
70869 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70870 if (!count)
70871 return 0;
70872
70873 + pax_open_kernel();
70874 sort(start, count, sizeof(*start),
70875 ftrace_cmp_ips, ftrace_swap_ips);
70876 + pax_close_kernel();
70877
70878 start_pg = ftrace_allocate_pages(count);
70879 if (!start_pg)
70880 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70881 index 5c38c81..88012af 100644
70882 --- a/kernel/trace/trace.c
70883 +++ b/kernel/trace/trace.c
70884 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70885 };
70886 #endif
70887
70888 -static struct dentry *d_tracer;
70889 -
70890 struct dentry *tracing_init_dentry(void)
70891 {
70892 + static struct dentry *d_tracer;
70893 static int once;
70894
70895 if (d_tracer)
70896 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70897 return d_tracer;
70898 }
70899
70900 -static struct dentry *d_percpu;
70901 -
70902 struct dentry *tracing_dentry_percpu(void)
70903 {
70904 + static struct dentry *d_percpu;
70905 static int once;
70906 struct dentry *d_tracer;
70907
70908 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70909 index 29111da..d190fe2 100644
70910 --- a/kernel/trace/trace_events.c
70911 +++ b/kernel/trace/trace_events.c
70912 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70913 struct ftrace_module_file_ops {
70914 struct list_head list;
70915 struct module *mod;
70916 - struct file_operations id;
70917 - struct file_operations enable;
70918 - struct file_operations format;
70919 - struct file_operations filter;
70920 };
70921
70922 static struct ftrace_module_file_ops *
70923 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70924
70925 file_ops->mod = mod;
70926
70927 - file_ops->id = ftrace_event_id_fops;
70928 - file_ops->id.owner = mod;
70929 -
70930 - file_ops->enable = ftrace_enable_fops;
70931 - file_ops->enable.owner = mod;
70932 -
70933 - file_ops->filter = ftrace_event_filter_fops;
70934 - file_ops->filter.owner = mod;
70935 -
70936 - file_ops->format = ftrace_event_format_fops;
70937 - file_ops->format.owner = mod;
70938 + pax_open_kernel();
70939 + *(void **)&mod->trace_id.owner = mod;
70940 + *(void **)&mod->trace_enable.owner = mod;
70941 + *(void **)&mod->trace_filter.owner = mod;
70942 + *(void **)&mod->trace_format.owner = mod;
70943 + pax_close_kernel();
70944
70945 list_add(&file_ops->list, &ftrace_module_file_list);
70946
70947 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70948
70949 for_each_event(call, start, end) {
70950 __trace_add_event_call(*call, mod,
70951 - &file_ops->id, &file_ops->enable,
70952 - &file_ops->filter, &file_ops->format);
70953 + &mod->trace_id, &mod->trace_enable,
70954 + &mod->trace_filter, &mod->trace_format);
70955 }
70956 }
70957
70958 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70959 index fd3c8aa..5f324a6 100644
70960 --- a/kernel/trace/trace_mmiotrace.c
70961 +++ b/kernel/trace/trace_mmiotrace.c
70962 @@ -24,7 +24,7 @@ struct header_iter {
70963 static struct trace_array *mmio_trace_array;
70964 static bool overrun_detected;
70965 static unsigned long prev_overruns;
70966 -static atomic_t dropped_count;
70967 +static atomic_unchecked_t dropped_count;
70968
70969 static void mmio_reset_data(struct trace_array *tr)
70970 {
70971 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70972
70973 static unsigned long count_overruns(struct trace_iterator *iter)
70974 {
70975 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70976 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70977 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70978
70979 if (over > prev_overruns)
70980 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70981 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70982 sizeof(*entry), 0, pc);
70983 if (!event) {
70984 - atomic_inc(&dropped_count);
70985 + atomic_inc_unchecked(&dropped_count);
70986 return;
70987 }
70988 entry = ring_buffer_event_data(event);
70989 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70990 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70991 sizeof(*entry), 0, pc);
70992 if (!event) {
70993 - atomic_inc(&dropped_count);
70994 + atomic_inc_unchecked(&dropped_count);
70995 return;
70996 }
70997 entry = ring_buffer_event_data(event);
70998 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70999 index 123b189..97b81f5 100644
71000 --- a/kernel/trace/trace_output.c
71001 +++ b/kernel/trace/trace_output.c
71002 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71003
71004 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71005 if (!IS_ERR(p)) {
71006 - p = mangle_path(s->buffer + s->len, p, "\n");
71007 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71008 if (p) {
71009 s->len = p - s->buffer;
71010 return 1;
71011 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71012 index d4545f4..a9010a1 100644
71013 --- a/kernel/trace/trace_stack.c
71014 +++ b/kernel/trace/trace_stack.c
71015 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71016 return;
71017
71018 /* we do not handle interrupt stacks yet */
71019 - if (!object_is_on_stack(&this_size))
71020 + if (!object_starts_on_stack(&this_size))
71021 return;
71022
71023 local_irq_save(flags);
71024 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71025 index 872bd6d..31601a2 100644
71026 --- a/kernel/workqueue.c
71027 +++ b/kernel/workqueue.c
71028 @@ -1422,7 +1422,7 @@ retry:
71029 /* morph UNBOUND to REBIND atomically */
71030 worker_flags &= ~WORKER_UNBOUND;
71031 worker_flags |= WORKER_REBIND;
71032 - ACCESS_ONCE(worker->flags) = worker_flags;
71033 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71034
71035 idle_rebind.cnt++;
71036 worker->idle_rebind = &idle_rebind;
71037 @@ -1448,7 +1448,7 @@ retry:
71038 /* morph UNBOUND to REBIND atomically */
71039 worker_flags &= ~WORKER_UNBOUND;
71040 worker_flags |= WORKER_REBIND;
71041 - ACCESS_ONCE(worker->flags) = worker_flags;
71042 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71043
71044 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71045 work_data_bits(rebind_work)))
71046 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71047 index 2403a63..5c4be4c 100644
71048 --- a/lib/Kconfig.debug
71049 +++ b/lib/Kconfig.debug
71050 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71051 depends on DEBUG_KERNEL
71052 depends on STACKTRACE_SUPPORT
71053 depends on PROC_FS
71054 + depends on !GRKERNSEC_HIDESYM
71055 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71056 select KALLSYMS
71057 select KALLSYMS_ALL
71058 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71059
71060 config PROVIDE_OHCI1394_DMA_INIT
71061 bool "Remote debugging over FireWire early on boot"
71062 - depends on PCI && X86
71063 + depends on PCI && X86 && !GRKERNSEC
71064 help
71065 If you want to debug problems which hang or crash the kernel early
71066 on boot and the crashing machine has a FireWire port, you can use
71067 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71068
71069 config FIREWIRE_OHCI_REMOTE_DMA
71070 bool "Remote debugging over FireWire with firewire-ohci"
71071 - depends on FIREWIRE_OHCI
71072 + depends on FIREWIRE_OHCI && !GRKERNSEC
71073 help
71074 This option lets you use the FireWire bus for remote debugging
71075 with help of the firewire-ohci driver. It enables unfiltered
71076 diff --git a/lib/bitmap.c b/lib/bitmap.c
71077 index 06fdfa1..97c5c7d 100644
71078 --- a/lib/bitmap.c
71079 +++ b/lib/bitmap.c
71080 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71081 {
71082 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71083 u32 chunk;
71084 - const char __user __force *ubuf = (const char __user __force *)buf;
71085 + const char __user *ubuf = (const char __force_user *)buf;
71086
71087 bitmap_zero(maskp, nmaskbits);
71088
71089 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71090 {
71091 if (!access_ok(VERIFY_READ, ubuf, ulen))
71092 return -EFAULT;
71093 - return __bitmap_parse((const char __force *)ubuf,
71094 + return __bitmap_parse((const char __force_kernel *)ubuf,
71095 ulen, 1, maskp, nmaskbits);
71096
71097 }
71098 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71099 {
71100 unsigned a, b;
71101 int c, old_c, totaldigits;
71102 - const char __user __force *ubuf = (const char __user __force *)buf;
71103 + const char __user *ubuf = (const char __force_user *)buf;
71104 int exp_digit, in_range;
71105
71106 totaldigits = c = 0;
71107 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71108 {
71109 if (!access_ok(VERIFY_READ, ubuf, ulen))
71110 return -EFAULT;
71111 - return __bitmap_parselist((const char __force *)ubuf,
71112 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71113 ulen, 1, maskp, nmaskbits);
71114 }
71115 EXPORT_SYMBOL(bitmap_parselist_user);
71116 diff --git a/lib/bug.c b/lib/bug.c
71117 index a28c141..2bd3d95 100644
71118 --- a/lib/bug.c
71119 +++ b/lib/bug.c
71120 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71121 return BUG_TRAP_TYPE_NONE;
71122
71123 bug = find_bug(bugaddr);
71124 + if (!bug)
71125 + return BUG_TRAP_TYPE_NONE;
71126
71127 file = NULL;
71128 line = 0;
71129 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71130 index d11808c..dc2d6f8 100644
71131 --- a/lib/debugobjects.c
71132 +++ b/lib/debugobjects.c
71133 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71134 if (limit > 4)
71135 return;
71136
71137 - is_on_stack = object_is_on_stack(addr);
71138 + is_on_stack = object_starts_on_stack(addr);
71139 if (is_on_stack == onstack)
71140 return;
71141
71142 diff --git a/lib/devres.c b/lib/devres.c
71143 index 80b9c76..9e32279 100644
71144 --- a/lib/devres.c
71145 +++ b/lib/devres.c
71146 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71147 void devm_iounmap(struct device *dev, void __iomem *addr)
71148 {
71149 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71150 - (void *)addr));
71151 + (void __force *)addr));
71152 iounmap(addr);
71153 }
71154 EXPORT_SYMBOL(devm_iounmap);
71155 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71156 {
71157 ioport_unmap(addr);
71158 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71159 - devm_ioport_map_match, (void *)addr));
71160 + devm_ioport_map_match, (void __force *)addr));
71161 }
71162 EXPORT_SYMBOL(devm_ioport_unmap);
71163
71164 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71165 index 66ce414..6f0a0dd 100644
71166 --- a/lib/dma-debug.c
71167 +++ b/lib/dma-debug.c
71168 @@ -924,7 +924,7 @@ out:
71169
71170 static void check_for_stack(struct device *dev, void *addr)
71171 {
71172 - if (object_is_on_stack(addr))
71173 + if (object_starts_on_stack(addr))
71174 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71175 "stack [addr=%p]\n", addr);
71176 }
71177 diff --git a/lib/inflate.c b/lib/inflate.c
71178 index 013a761..c28f3fc 100644
71179 --- a/lib/inflate.c
71180 +++ b/lib/inflate.c
71181 @@ -269,7 +269,7 @@ static void free(void *where)
71182 malloc_ptr = free_mem_ptr;
71183 }
71184 #else
71185 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71186 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71187 #define free(a) kfree(a)
71188 #endif
71189
71190 diff --git a/lib/ioremap.c b/lib/ioremap.c
71191 index 0c9216c..863bd89 100644
71192 --- a/lib/ioremap.c
71193 +++ b/lib/ioremap.c
71194 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71195 unsigned long next;
71196
71197 phys_addr -= addr;
71198 - pmd = pmd_alloc(&init_mm, pud, addr);
71199 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71200 if (!pmd)
71201 return -ENOMEM;
71202 do {
71203 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71204 unsigned long next;
71205
71206 phys_addr -= addr;
71207 - pud = pud_alloc(&init_mm, pgd, addr);
71208 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71209 if (!pud)
71210 return -ENOMEM;
71211 do {
71212 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71213 index bd2bea9..6b3c95e 100644
71214 --- a/lib/is_single_threaded.c
71215 +++ b/lib/is_single_threaded.c
71216 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71217 struct task_struct *p, *t;
71218 bool ret;
71219
71220 + if (!mm)
71221 + return true;
71222 +
71223 if (atomic_read(&task->signal->live) != 1)
71224 return false;
71225
71226 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71227 index e796429..6e38f9f 100644
71228 --- a/lib/radix-tree.c
71229 +++ b/lib/radix-tree.c
71230 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71231 int nr;
71232 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71233 };
71234 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71235 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71236
71237 static inline void *ptr_to_indirect(void *ptr)
71238 {
71239 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71240 index 0e33754..50a0e63 100644
71241 --- a/lib/vsprintf.c
71242 +++ b/lib/vsprintf.c
71243 @@ -16,6 +16,9 @@
71244 * - scnprintf and vscnprintf
71245 */
71246
71247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71248 +#define __INCLUDED_BY_HIDESYM 1
71249 +#endif
71250 #include <stdarg.h>
71251 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71252 #include <linux/types.h>
71253 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71254 char sym[KSYM_SYMBOL_LEN];
71255 if (ext == 'B')
71256 sprint_backtrace(sym, value);
71257 - else if (ext != 'f' && ext != 's')
71258 + else if (ext != 'f' && ext != 's' && ext != 'a')
71259 sprint_symbol(sym, value);
71260 else
71261 sprint_symbol_no_offset(sym, value);
71262 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71263 return number(buf, end, *(const netdev_features_t *)addr, spec);
71264 }
71265
71266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71267 +int kptr_restrict __read_mostly = 2;
71268 +#else
71269 int kptr_restrict __read_mostly;
71270 +#endif
71271
71272 /*
71273 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71274 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71275 * - 'S' For symbolic direct pointers with offset
71276 * - 's' For symbolic direct pointers without offset
71277 * - 'B' For backtraced symbolic direct pointers with offset
71278 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71279 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71280 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71281 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71282 * - 'M' For a 6-byte MAC address, it prints the address in the
71283 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71284
71285 if (!ptr && *fmt != 'K') {
71286 /*
71287 - * Print (null) with the same width as a pointer so it makes
71288 + * Print (nil) with the same width as a pointer so it makes
71289 * tabular output look nice.
71290 */
71291 if (spec.field_width == -1)
71292 spec.field_width = default_width;
71293 - return string(buf, end, "(null)", spec);
71294 + return string(buf, end, "(nil)", spec);
71295 }
71296
71297 switch (*fmt) {
71298 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71299 /* Fallthrough */
71300 case 'S':
71301 case 's':
71302 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71303 + break;
71304 +#else
71305 + return symbol_string(buf, end, ptr, spec, *fmt);
71306 +#endif
71307 + case 'A':
71308 + case 'a':
71309 case 'B':
71310 return symbol_string(buf, end, ptr, spec, *fmt);
71311 case 'R':
71312 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71313 va_end(va);
71314 return buf;
71315 }
71316 + case 'P':
71317 + break;
71318 case 'K':
71319 /*
71320 * %pK cannot be used in IRQ context because its test
71321 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71322 }
71323 break;
71324 }
71325 +
71326 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71327 + /* 'P' = approved pointers to copy to userland,
71328 + as in the /proc/kallsyms case, as we make it display nothing
71329 + for non-root users, and the real contents for root users
71330 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71331 + above
71332 + */
71333 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71334 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71335 + dump_stack();
71336 + ptr = NULL;
71337 + }
71338 +#endif
71339 +
71340 spec.flags |= SMALL;
71341 if (spec.field_width == -1) {
71342 spec.field_width = default_width;
71343 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71344 typeof(type) value; \
71345 if (sizeof(type) == 8) { \
71346 args = PTR_ALIGN(args, sizeof(u32)); \
71347 - *(u32 *)&value = *(u32 *)args; \
71348 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71349 + *(u32 *)&value = *(const u32 *)args; \
71350 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71351 } else { \
71352 args = PTR_ALIGN(args, sizeof(type)); \
71353 - value = *(typeof(type) *)args; \
71354 + value = *(const typeof(type) *)args; \
71355 } \
71356 args += sizeof(type); \
71357 value; \
71358 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71359 case FORMAT_TYPE_STR: {
71360 const char *str_arg = args;
71361 args += strlen(str_arg) + 1;
71362 - str = string(str, end, (char *)str_arg, spec);
71363 + str = string(str, end, str_arg, spec);
71364 break;
71365 }
71366
71367 diff --git a/localversion-grsec b/localversion-grsec
71368 new file mode 100644
71369 index 0000000..7cd6065
71370 --- /dev/null
71371 +++ b/localversion-grsec
71372 @@ -0,0 +1 @@
71373 +-grsec
71374 diff --git a/mm/Kconfig b/mm/Kconfig
71375 index d5c8019..f513038 100644
71376 --- a/mm/Kconfig
71377 +++ b/mm/Kconfig
71378 @@ -251,10 +251,10 @@ config KSM
71379 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71380
71381 config DEFAULT_MMAP_MIN_ADDR
71382 - int "Low address space to protect from user allocation"
71383 + int "Low address space to protect from user allocation"
71384 depends on MMU
71385 - default 4096
71386 - help
71387 + default 65536
71388 + help
71389 This is the portion of low virtual memory which should be protected
71390 from userspace allocation. Keeping a user from writing to low pages
71391 can help reduce the impact of kernel NULL pointer bugs.
71392 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71393
71394 config HWPOISON_INJECT
71395 tristate "HWPoison pages injector"
71396 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71397 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71398 select PROC_PAGE_MONITOR
71399
71400 config NOMMU_INITIAL_TRIM_EXCESS
71401 diff --git a/mm/filemap.c b/mm/filemap.c
71402 index 3843445..4fe6833 100644
71403 --- a/mm/filemap.c
71404 +++ b/mm/filemap.c
71405 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71406 struct address_space *mapping = file->f_mapping;
71407
71408 if (!mapping->a_ops->readpage)
71409 - return -ENOEXEC;
71410 + return -ENODEV;
71411 file_accessed(file);
71412 vma->vm_ops = &generic_file_vm_ops;
71413 vma->vm_flags |= VM_CAN_NONLINEAR;
71414 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71415 *pos = i_size_read(inode);
71416
71417 if (limit != RLIM_INFINITY) {
71418 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71419 if (*pos >= limit) {
71420 send_sig(SIGXFSZ, current, 0);
71421 return -EFBIG;
71422 diff --git a/mm/fremap.c b/mm/fremap.c
71423 index 9ed4fd4..c42648d 100644
71424 --- a/mm/fremap.c
71425 +++ b/mm/fremap.c
71426 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71427 retry:
71428 vma = find_vma(mm, start);
71429
71430 +#ifdef CONFIG_PAX_SEGMEXEC
71431 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71432 + goto out;
71433 +#endif
71434 +
71435 /*
71436 * Make sure the vma is shared, that it supports prefaulting,
71437 * and that the remapped range is valid and fully within
71438 diff --git a/mm/highmem.c b/mm/highmem.c
71439 index d517cd1..006a1c5 100644
71440 --- a/mm/highmem.c
71441 +++ b/mm/highmem.c
71442 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71443 * So no dangers, even with speculative execution.
71444 */
71445 page = pte_page(pkmap_page_table[i]);
71446 + pax_open_kernel();
71447 pte_clear(&init_mm, (unsigned long)page_address(page),
71448 &pkmap_page_table[i]);
71449 -
71450 + pax_close_kernel();
71451 set_page_address(page, NULL);
71452 need_flush = 1;
71453 }
71454 @@ -198,9 +199,11 @@ start:
71455 }
71456 }
71457 vaddr = PKMAP_ADDR(last_pkmap_nr);
71458 +
71459 + pax_open_kernel();
71460 set_pte_at(&init_mm, vaddr,
71461 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71462 -
71463 + pax_close_kernel();
71464 pkmap_count[last_pkmap_nr] = 1;
71465 set_page_address(page, (void *)vaddr);
71466
71467 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71468 index 141dbb6..ebff057 100644
71469 --- a/mm/huge_memory.c
71470 +++ b/mm/huge_memory.c
71471 @@ -735,7 +735,7 @@ out:
71472 * run pte_offset_map on the pmd, if an huge pmd could
71473 * materialize from under us from a different thread.
71474 */
71475 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71476 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71477 return VM_FAULT_OOM;
71478 /* if an huge pmd materialized from under us just retry later */
71479 if (unlikely(pmd_trans_huge(*pmd)))
71480 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71481 index 3adceaf..dccfea3 100644
71482 --- a/mm/hugetlb.c
71483 +++ b/mm/hugetlb.c
71484 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71485 return 1;
71486 }
71487
71488 +#ifdef CONFIG_PAX_SEGMEXEC
71489 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71490 +{
71491 + struct mm_struct *mm = vma->vm_mm;
71492 + struct vm_area_struct *vma_m;
71493 + unsigned long address_m;
71494 + pte_t *ptep_m;
71495 +
71496 + vma_m = pax_find_mirror_vma(vma);
71497 + if (!vma_m)
71498 + return;
71499 +
71500 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71501 + address_m = address + SEGMEXEC_TASK_SIZE;
71502 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71503 + get_page(page_m);
71504 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71505 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71506 +}
71507 +#endif
71508 +
71509 /*
71510 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71511 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71512 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71513 make_huge_pte(vma, new_page, 1));
71514 page_remove_rmap(old_page);
71515 hugepage_add_new_anon_rmap(new_page, vma, address);
71516 +
71517 +#ifdef CONFIG_PAX_SEGMEXEC
71518 + pax_mirror_huge_pte(vma, address, new_page);
71519 +#endif
71520 +
71521 /* Make the old page be freed below */
71522 new_page = old_page;
71523 mmu_notifier_invalidate_range_end(mm,
71524 @@ -2786,6 +2812,10 @@ retry:
71525 && (vma->vm_flags & VM_SHARED)));
71526 set_huge_pte_at(mm, address, ptep, new_pte);
71527
71528 +#ifdef CONFIG_PAX_SEGMEXEC
71529 + pax_mirror_huge_pte(vma, address, page);
71530 +#endif
71531 +
71532 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71533 /* Optimization, do the COW without a second fault */
71534 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71535 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71536 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71537 struct hstate *h = hstate_vma(vma);
71538
71539 +#ifdef CONFIG_PAX_SEGMEXEC
71540 + struct vm_area_struct *vma_m;
71541 +#endif
71542 +
71543 address &= huge_page_mask(h);
71544
71545 ptep = huge_pte_offset(mm, address);
71546 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71547 VM_FAULT_SET_HINDEX(hstate_index(h));
71548 }
71549
71550 +#ifdef CONFIG_PAX_SEGMEXEC
71551 + vma_m = pax_find_mirror_vma(vma);
71552 + if (vma_m) {
71553 + unsigned long address_m;
71554 +
71555 + if (vma->vm_start > vma_m->vm_start) {
71556 + address_m = address;
71557 + address -= SEGMEXEC_TASK_SIZE;
71558 + vma = vma_m;
71559 + h = hstate_vma(vma);
71560 + } else
71561 + address_m = address + SEGMEXEC_TASK_SIZE;
71562 +
71563 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71564 + return VM_FAULT_OOM;
71565 + address_m &= HPAGE_MASK;
71566 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71567 + }
71568 +#endif
71569 +
71570 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71571 if (!ptep)
71572 return VM_FAULT_OOM;
71573 diff --git a/mm/internal.h b/mm/internal.h
71574 index b8c91b3..93e95a3 100644
71575 --- a/mm/internal.h
71576 +++ b/mm/internal.h
71577 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71578 * in mm/page_alloc.c
71579 */
71580 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71581 +extern void free_compound_page(struct page *page);
71582 extern void prep_compound_page(struct page *page, unsigned long order);
71583 #ifdef CONFIG_MEMORY_FAILURE
71584 extern bool is_free_buddy_page(struct page *page);
71585 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71586 index 45eb621..6ccd8ea 100644
71587 --- a/mm/kmemleak.c
71588 +++ b/mm/kmemleak.c
71589 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71590
71591 for (i = 0; i < object->trace_len; i++) {
71592 void *ptr = (void *)object->trace[i];
71593 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71594 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71595 }
71596 }
71597
71598 diff --git a/mm/maccess.c b/mm/maccess.c
71599 index d53adf9..03a24bf 100644
71600 --- a/mm/maccess.c
71601 +++ b/mm/maccess.c
71602 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71603 set_fs(KERNEL_DS);
71604 pagefault_disable();
71605 ret = __copy_from_user_inatomic(dst,
71606 - (__force const void __user *)src, size);
71607 + (const void __force_user *)src, size);
71608 pagefault_enable();
71609 set_fs(old_fs);
71610
71611 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71612
71613 set_fs(KERNEL_DS);
71614 pagefault_disable();
71615 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71616 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71617 pagefault_enable();
71618 set_fs(old_fs);
71619
71620 diff --git a/mm/madvise.c b/mm/madvise.c
71621 index 14d260f..b2a80fd 100644
71622 --- a/mm/madvise.c
71623 +++ b/mm/madvise.c
71624 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71625 pgoff_t pgoff;
71626 unsigned long new_flags = vma->vm_flags;
71627
71628 +#ifdef CONFIG_PAX_SEGMEXEC
71629 + struct vm_area_struct *vma_m;
71630 +#endif
71631 +
71632 switch (behavior) {
71633 case MADV_NORMAL:
71634 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71635 @@ -119,6 +123,13 @@ success:
71636 /*
71637 * vm_flags is protected by the mmap_sem held in write mode.
71638 */
71639 +
71640 +#ifdef CONFIG_PAX_SEGMEXEC
71641 + vma_m = pax_find_mirror_vma(vma);
71642 + if (vma_m)
71643 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71644 +#endif
71645 +
71646 vma->vm_flags = new_flags;
71647
71648 out:
71649 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71650 struct vm_area_struct ** prev,
71651 unsigned long start, unsigned long end)
71652 {
71653 +
71654 +#ifdef CONFIG_PAX_SEGMEXEC
71655 + struct vm_area_struct *vma_m;
71656 +#endif
71657 +
71658 *prev = vma;
71659 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71660 return -EINVAL;
71661 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71662 zap_page_range(vma, start, end - start, &details);
71663 } else
71664 zap_page_range(vma, start, end - start, NULL);
71665 +
71666 +#ifdef CONFIG_PAX_SEGMEXEC
71667 + vma_m = pax_find_mirror_vma(vma);
71668 + if (vma_m) {
71669 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71670 + struct zap_details details = {
71671 + .nonlinear_vma = vma_m,
71672 + .last_index = ULONG_MAX,
71673 + };
71674 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71675 + } else
71676 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71677 + }
71678 +#endif
71679 +
71680 return 0;
71681 }
71682
71683 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71684 if (end < start)
71685 goto out;
71686
71687 +#ifdef CONFIG_PAX_SEGMEXEC
71688 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71689 + if (end > SEGMEXEC_TASK_SIZE)
71690 + goto out;
71691 + } else
71692 +#endif
71693 +
71694 + if (end > TASK_SIZE)
71695 + goto out;
71696 +
71697 error = 0;
71698 if (end == start)
71699 goto out;
71700 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71701 index a6e2141..eaf5aad 100644
71702 --- a/mm/memory-failure.c
71703 +++ b/mm/memory-failure.c
71704 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71705
71706 int sysctl_memory_failure_recovery __read_mostly = 1;
71707
71708 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71709 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71710
71711 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71712
71713 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71714 pfn, t->comm, t->pid);
71715 si.si_signo = SIGBUS;
71716 si.si_errno = 0;
71717 - si.si_addr = (void *)addr;
71718 + si.si_addr = (void __user *)addr;
71719 #ifdef __ARCH_SI_TRAPNO
71720 si.si_trapno = trapno;
71721 #endif
71722 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71723 }
71724
71725 nr_pages = 1 << compound_trans_order(hpage);
71726 - atomic_long_add(nr_pages, &mce_bad_pages);
71727 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71728
71729 /*
71730 * We need/can do nothing about count=0 pages.
71731 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71732 if (!PageHWPoison(hpage)
71733 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71734 || (p != hpage && TestSetPageHWPoison(hpage))) {
71735 - atomic_long_sub(nr_pages, &mce_bad_pages);
71736 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71737 return 0;
71738 }
71739 set_page_hwpoison_huge_page(hpage);
71740 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71741 }
71742 if (hwpoison_filter(p)) {
71743 if (TestClearPageHWPoison(p))
71744 - atomic_long_sub(nr_pages, &mce_bad_pages);
71745 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71746 unlock_page(hpage);
71747 put_page(hpage);
71748 return 0;
71749 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71750 return 0;
71751 }
71752 if (TestClearPageHWPoison(p))
71753 - atomic_long_sub(nr_pages, &mce_bad_pages);
71754 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71755 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71756 return 0;
71757 }
71758 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71759 */
71760 if (TestClearPageHWPoison(page)) {
71761 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71762 - atomic_long_sub(nr_pages, &mce_bad_pages);
71763 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71764 freeit = 1;
71765 if (PageHuge(page))
71766 clear_page_hwpoison_huge_page(page);
71767 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71768 }
71769 done:
71770 if (!PageHWPoison(hpage))
71771 - atomic_long_add(1 << compound_trans_order(hpage),
71772 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71773 &mce_bad_pages);
71774 set_page_hwpoison_huge_page(hpage);
71775 dequeue_hwpoisoned_huge_page(hpage);
71776 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71777 return ret;
71778
71779 done:
71780 - atomic_long_add(1, &mce_bad_pages);
71781 + atomic_long_add_unchecked(1, &mce_bad_pages);
71782 SetPageHWPoison(page);
71783 /* keep elevated page count for bad page */
71784 return ret;
71785 diff --git a/mm/memory.c b/mm/memory.c
71786 index 5736170..8e04800 100644
71787 --- a/mm/memory.c
71788 +++ b/mm/memory.c
71789 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71790 free_pte_range(tlb, pmd, addr);
71791 } while (pmd++, addr = next, addr != end);
71792
71793 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71794 start &= PUD_MASK;
71795 if (start < floor)
71796 return;
71797 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71798 pmd = pmd_offset(pud, start);
71799 pud_clear(pud);
71800 pmd_free_tlb(tlb, pmd, start);
71801 +#endif
71802 +
71803 }
71804
71805 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71806 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71807 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71808 } while (pud++, addr = next, addr != end);
71809
71810 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71811 start &= PGDIR_MASK;
71812 if (start < floor)
71813 return;
71814 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71815 pud = pud_offset(pgd, start);
71816 pgd_clear(pgd);
71817 pud_free_tlb(tlb, pud, start);
71818 +#endif
71819 +
71820 }
71821
71822 /*
71823 @@ -1614,12 +1620,6 @@ no_page_table:
71824 return page;
71825 }
71826
71827 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71828 -{
71829 - return stack_guard_page_start(vma, addr) ||
71830 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71831 -}
71832 -
71833 /**
71834 * __get_user_pages() - pin user pages in memory
71835 * @tsk: task_struct of target task
71836 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71837 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71838 i = 0;
71839
71840 - do {
71841 + while (nr_pages) {
71842 struct vm_area_struct *vma;
71843
71844 - vma = find_extend_vma(mm, start);
71845 + vma = find_vma(mm, start);
71846 if (!vma && in_gate_area(mm, start)) {
71847 unsigned long pg = start & PAGE_MASK;
71848 pgd_t *pgd;
71849 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71850 goto next_page;
71851 }
71852
71853 - if (!vma ||
71854 + if (!vma || start < vma->vm_start ||
71855 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71856 !(vm_flags & vma->vm_flags))
71857 return i ? : -EFAULT;
71858 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71859 int ret;
71860 unsigned int fault_flags = 0;
71861
71862 - /* For mlock, just skip the stack guard page. */
71863 - if (foll_flags & FOLL_MLOCK) {
71864 - if (stack_guard_page(vma, start))
71865 - goto next_page;
71866 - }
71867 if (foll_flags & FOLL_WRITE)
71868 fault_flags |= FAULT_FLAG_WRITE;
71869 if (nonblocking)
71870 @@ -1848,7 +1843,7 @@ next_page:
71871 start += PAGE_SIZE;
71872 nr_pages--;
71873 } while (nr_pages && start < vma->vm_end);
71874 - } while (nr_pages);
71875 + }
71876 return i;
71877 }
71878 EXPORT_SYMBOL(__get_user_pages);
71879 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71880 page_add_file_rmap(page);
71881 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71882
71883 +#ifdef CONFIG_PAX_SEGMEXEC
71884 + pax_mirror_file_pte(vma, addr, page, ptl);
71885 +#endif
71886 +
71887 retval = 0;
71888 pte_unmap_unlock(pte, ptl);
71889 return retval;
71890 @@ -2089,10 +2088,22 @@ out:
71891 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71892 struct page *page)
71893 {
71894 +
71895 +#ifdef CONFIG_PAX_SEGMEXEC
71896 + struct vm_area_struct *vma_m;
71897 +#endif
71898 +
71899 if (addr < vma->vm_start || addr >= vma->vm_end)
71900 return -EFAULT;
71901 if (!page_count(page))
71902 return -EINVAL;
71903 +
71904 +#ifdef CONFIG_PAX_SEGMEXEC
71905 + vma_m = pax_find_mirror_vma(vma);
71906 + if (vma_m)
71907 + vma_m->vm_flags |= VM_INSERTPAGE;
71908 +#endif
71909 +
71910 vma->vm_flags |= VM_INSERTPAGE;
71911 return insert_page(vma, addr, page, vma->vm_page_prot);
71912 }
71913 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71914 unsigned long pfn)
71915 {
71916 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71917 + BUG_ON(vma->vm_mirror);
71918
71919 if (addr < vma->vm_start || addr >= vma->vm_end)
71920 return -EFAULT;
71921 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71922
71923 BUG_ON(pud_huge(*pud));
71924
71925 - pmd = pmd_alloc(mm, pud, addr);
71926 + pmd = (mm == &init_mm) ?
71927 + pmd_alloc_kernel(mm, pud, addr) :
71928 + pmd_alloc(mm, pud, addr);
71929 if (!pmd)
71930 return -ENOMEM;
71931 do {
71932 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71933 unsigned long next;
71934 int err;
71935
71936 - pud = pud_alloc(mm, pgd, addr);
71937 + pud = (mm == &init_mm) ?
71938 + pud_alloc_kernel(mm, pgd, addr) :
71939 + pud_alloc(mm, pgd, addr);
71940 if (!pud)
71941 return -ENOMEM;
71942 do {
71943 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71944 copy_user_highpage(dst, src, va, vma);
71945 }
71946
71947 +#ifdef CONFIG_PAX_SEGMEXEC
71948 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71949 +{
71950 + struct mm_struct *mm = vma->vm_mm;
71951 + spinlock_t *ptl;
71952 + pte_t *pte, entry;
71953 +
71954 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71955 + entry = *pte;
71956 + if (!pte_present(entry)) {
71957 + if (!pte_none(entry)) {
71958 + BUG_ON(pte_file(entry));
71959 + free_swap_and_cache(pte_to_swp_entry(entry));
71960 + pte_clear_not_present_full(mm, address, pte, 0);
71961 + }
71962 + } else {
71963 + struct page *page;
71964 +
71965 + flush_cache_page(vma, address, pte_pfn(entry));
71966 + entry = ptep_clear_flush(vma, address, pte);
71967 + BUG_ON(pte_dirty(entry));
71968 + page = vm_normal_page(vma, address, entry);
71969 + if (page) {
71970 + update_hiwater_rss(mm);
71971 + if (PageAnon(page))
71972 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71973 + else
71974 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71975 + page_remove_rmap(page);
71976 + page_cache_release(page);
71977 + }
71978 + }
71979 + pte_unmap_unlock(pte, ptl);
71980 +}
71981 +
71982 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71983 + *
71984 + * the ptl of the lower mapped page is held on entry and is not released on exit
71985 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71986 + */
71987 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71988 +{
71989 + struct mm_struct *mm = vma->vm_mm;
71990 + unsigned long address_m;
71991 + spinlock_t *ptl_m;
71992 + struct vm_area_struct *vma_m;
71993 + pmd_t *pmd_m;
71994 + pte_t *pte_m, entry_m;
71995 +
71996 + BUG_ON(!page_m || !PageAnon(page_m));
71997 +
71998 + vma_m = pax_find_mirror_vma(vma);
71999 + if (!vma_m)
72000 + return;
72001 +
72002 + BUG_ON(!PageLocked(page_m));
72003 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72004 + address_m = address + SEGMEXEC_TASK_SIZE;
72005 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72006 + pte_m = pte_offset_map(pmd_m, address_m);
72007 + ptl_m = pte_lockptr(mm, pmd_m);
72008 + if (ptl != ptl_m) {
72009 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72010 + if (!pte_none(*pte_m))
72011 + goto out;
72012 + }
72013 +
72014 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72015 + page_cache_get(page_m);
72016 + page_add_anon_rmap(page_m, vma_m, address_m);
72017 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72018 + set_pte_at(mm, address_m, pte_m, entry_m);
72019 + update_mmu_cache(vma_m, address_m, entry_m);
72020 +out:
72021 + if (ptl != ptl_m)
72022 + spin_unlock(ptl_m);
72023 + pte_unmap(pte_m);
72024 + unlock_page(page_m);
72025 +}
72026 +
72027 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72028 +{
72029 + struct mm_struct *mm = vma->vm_mm;
72030 + unsigned long address_m;
72031 + spinlock_t *ptl_m;
72032 + struct vm_area_struct *vma_m;
72033 + pmd_t *pmd_m;
72034 + pte_t *pte_m, entry_m;
72035 +
72036 + BUG_ON(!page_m || PageAnon(page_m));
72037 +
72038 + vma_m = pax_find_mirror_vma(vma);
72039 + if (!vma_m)
72040 + return;
72041 +
72042 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72043 + address_m = address + SEGMEXEC_TASK_SIZE;
72044 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72045 + pte_m = pte_offset_map(pmd_m, address_m);
72046 + ptl_m = pte_lockptr(mm, pmd_m);
72047 + if (ptl != ptl_m) {
72048 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72049 + if (!pte_none(*pte_m))
72050 + goto out;
72051 + }
72052 +
72053 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72054 + page_cache_get(page_m);
72055 + page_add_file_rmap(page_m);
72056 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72057 + set_pte_at(mm, address_m, pte_m, entry_m);
72058 + update_mmu_cache(vma_m, address_m, entry_m);
72059 +out:
72060 + if (ptl != ptl_m)
72061 + spin_unlock(ptl_m);
72062 + pte_unmap(pte_m);
72063 +}
72064 +
72065 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72066 +{
72067 + struct mm_struct *mm = vma->vm_mm;
72068 + unsigned long address_m;
72069 + spinlock_t *ptl_m;
72070 + struct vm_area_struct *vma_m;
72071 + pmd_t *pmd_m;
72072 + pte_t *pte_m, entry_m;
72073 +
72074 + vma_m = pax_find_mirror_vma(vma);
72075 + if (!vma_m)
72076 + return;
72077 +
72078 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72079 + address_m = address + SEGMEXEC_TASK_SIZE;
72080 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72081 + pte_m = pte_offset_map(pmd_m, address_m);
72082 + ptl_m = pte_lockptr(mm, pmd_m);
72083 + if (ptl != ptl_m) {
72084 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72085 + if (!pte_none(*pte_m))
72086 + goto out;
72087 + }
72088 +
72089 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72090 + set_pte_at(mm, address_m, pte_m, entry_m);
72091 +out:
72092 + if (ptl != ptl_m)
72093 + spin_unlock(ptl_m);
72094 + pte_unmap(pte_m);
72095 +}
72096 +
72097 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72098 +{
72099 + struct page *page_m;
72100 + pte_t entry;
72101 +
72102 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72103 + goto out;
72104 +
72105 + entry = *pte;
72106 + page_m = vm_normal_page(vma, address, entry);
72107 + if (!page_m)
72108 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72109 + else if (PageAnon(page_m)) {
72110 + if (pax_find_mirror_vma(vma)) {
72111 + pte_unmap_unlock(pte, ptl);
72112 + lock_page(page_m);
72113 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72114 + if (pte_same(entry, *pte))
72115 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72116 + else
72117 + unlock_page(page_m);
72118 + }
72119 + } else
72120 + pax_mirror_file_pte(vma, address, page_m, ptl);
72121 +
72122 +out:
72123 + pte_unmap_unlock(pte, ptl);
72124 +}
72125 +#endif
72126 +
72127 /*
72128 * This routine handles present pages, when users try to write
72129 * to a shared page. It is done by copying the page to a new address
72130 @@ -2703,6 +2899,12 @@ gotten:
72131 */
72132 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72133 if (likely(pte_same(*page_table, orig_pte))) {
72134 +
72135 +#ifdef CONFIG_PAX_SEGMEXEC
72136 + if (pax_find_mirror_vma(vma))
72137 + BUG_ON(!trylock_page(new_page));
72138 +#endif
72139 +
72140 if (old_page) {
72141 if (!PageAnon(old_page)) {
72142 dec_mm_counter_fast(mm, MM_FILEPAGES);
72143 @@ -2754,6 +2956,10 @@ gotten:
72144 page_remove_rmap(old_page);
72145 }
72146
72147 +#ifdef CONFIG_PAX_SEGMEXEC
72148 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72149 +#endif
72150 +
72151 /* Free the old page.. */
72152 new_page = old_page;
72153 ret |= VM_FAULT_WRITE;
72154 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72155 swap_free(entry);
72156 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72157 try_to_free_swap(page);
72158 +
72159 +#ifdef CONFIG_PAX_SEGMEXEC
72160 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72161 +#endif
72162 +
72163 unlock_page(page);
72164 if (swapcache) {
72165 /*
72166 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72167
72168 /* No need to invalidate - it was non-present before */
72169 update_mmu_cache(vma, address, page_table);
72170 +
72171 +#ifdef CONFIG_PAX_SEGMEXEC
72172 + pax_mirror_anon_pte(vma, address, page, ptl);
72173 +#endif
72174 +
72175 unlock:
72176 pte_unmap_unlock(page_table, ptl);
72177 out:
72178 @@ -3075,40 +3291,6 @@ out_release:
72179 }
72180
72181 /*
72182 - * This is like a special single-page "expand_{down|up}wards()",
72183 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72184 - * doesn't hit another vma.
72185 - */
72186 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72187 -{
72188 - address &= PAGE_MASK;
72189 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72190 - struct vm_area_struct *prev = vma->vm_prev;
72191 -
72192 - /*
72193 - * Is there a mapping abutting this one below?
72194 - *
72195 - * That's only ok if it's the same stack mapping
72196 - * that has gotten split..
72197 - */
72198 - if (prev && prev->vm_end == address)
72199 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72200 -
72201 - expand_downwards(vma, address - PAGE_SIZE);
72202 - }
72203 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72204 - struct vm_area_struct *next = vma->vm_next;
72205 -
72206 - /* As VM_GROWSDOWN but s/below/above/ */
72207 - if (next && next->vm_start == address + PAGE_SIZE)
72208 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72209 -
72210 - expand_upwards(vma, address + PAGE_SIZE);
72211 - }
72212 - return 0;
72213 -}
72214 -
72215 -/*
72216 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72217 * but allow concurrent faults), and pte mapped but not yet locked.
72218 * We return with mmap_sem still held, but pte unmapped and unlocked.
72219 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72220 unsigned long address, pte_t *page_table, pmd_t *pmd,
72221 unsigned int flags)
72222 {
72223 - struct page *page;
72224 + struct page *page = NULL;
72225 spinlock_t *ptl;
72226 pte_t entry;
72227
72228 - pte_unmap(page_table);
72229 -
72230 - /* Check if we need to add a guard page to the stack */
72231 - if (check_stack_guard_page(vma, address) < 0)
72232 - return VM_FAULT_SIGBUS;
72233 -
72234 - /* Use the zero-page for reads */
72235 if (!(flags & FAULT_FLAG_WRITE)) {
72236 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72237 vma->vm_page_prot));
72238 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72239 + ptl = pte_lockptr(mm, pmd);
72240 + spin_lock(ptl);
72241 if (!pte_none(*page_table))
72242 goto unlock;
72243 goto setpte;
72244 }
72245
72246 /* Allocate our own private page. */
72247 + pte_unmap(page_table);
72248 +
72249 if (unlikely(anon_vma_prepare(vma)))
72250 goto oom;
72251 page = alloc_zeroed_user_highpage_movable(vma, address);
72252 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72253 if (!pte_none(*page_table))
72254 goto release;
72255
72256 +#ifdef CONFIG_PAX_SEGMEXEC
72257 + if (pax_find_mirror_vma(vma))
72258 + BUG_ON(!trylock_page(page));
72259 +#endif
72260 +
72261 inc_mm_counter_fast(mm, MM_ANONPAGES);
72262 page_add_new_anon_rmap(page, vma, address);
72263 setpte:
72264 @@ -3163,6 +3346,12 @@ setpte:
72265
72266 /* No need to invalidate - it was non-present before */
72267 update_mmu_cache(vma, address, page_table);
72268 +
72269 +#ifdef CONFIG_PAX_SEGMEXEC
72270 + if (page)
72271 + pax_mirror_anon_pte(vma, address, page, ptl);
72272 +#endif
72273 +
72274 unlock:
72275 pte_unmap_unlock(page_table, ptl);
72276 return 0;
72277 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72278 */
72279 /* Only go through if we didn't race with anybody else... */
72280 if (likely(pte_same(*page_table, orig_pte))) {
72281 +
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + if (anon && pax_find_mirror_vma(vma))
72284 + BUG_ON(!trylock_page(page));
72285 +#endif
72286 +
72287 flush_icache_page(vma, page);
72288 entry = mk_pte(page, vma->vm_page_prot);
72289 if (flags & FAULT_FLAG_WRITE)
72290 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72291
72292 /* no need to invalidate: a not-present page won't be cached */
72293 update_mmu_cache(vma, address, page_table);
72294 +
72295 +#ifdef CONFIG_PAX_SEGMEXEC
72296 + if (anon)
72297 + pax_mirror_anon_pte(vma, address, page, ptl);
72298 + else
72299 + pax_mirror_file_pte(vma, address, page, ptl);
72300 +#endif
72301 +
72302 } else {
72303 if (cow_page)
72304 mem_cgroup_uncharge_page(cow_page);
72305 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72306 if (flags & FAULT_FLAG_WRITE)
72307 flush_tlb_fix_spurious_fault(vma, address);
72308 }
72309 +
72310 +#ifdef CONFIG_PAX_SEGMEXEC
72311 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72312 + return 0;
72313 +#endif
72314 +
72315 unlock:
72316 pte_unmap_unlock(pte, ptl);
72317 return 0;
72318 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72319 pmd_t *pmd;
72320 pte_t *pte;
72321
72322 +#ifdef CONFIG_PAX_SEGMEXEC
72323 + struct vm_area_struct *vma_m;
72324 +#endif
72325 +
72326 __set_current_state(TASK_RUNNING);
72327
72328 count_vm_event(PGFAULT);
72329 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72330 if (unlikely(is_vm_hugetlb_page(vma)))
72331 return hugetlb_fault(mm, vma, address, flags);
72332
72333 +#ifdef CONFIG_PAX_SEGMEXEC
72334 + vma_m = pax_find_mirror_vma(vma);
72335 + if (vma_m) {
72336 + unsigned long address_m;
72337 + pgd_t *pgd_m;
72338 + pud_t *pud_m;
72339 + pmd_t *pmd_m;
72340 +
72341 + if (vma->vm_start > vma_m->vm_start) {
72342 + address_m = address;
72343 + address -= SEGMEXEC_TASK_SIZE;
72344 + vma = vma_m;
72345 + } else
72346 + address_m = address + SEGMEXEC_TASK_SIZE;
72347 +
72348 + pgd_m = pgd_offset(mm, address_m);
72349 + pud_m = pud_alloc(mm, pgd_m, address_m);
72350 + if (!pud_m)
72351 + return VM_FAULT_OOM;
72352 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72353 + if (!pmd_m)
72354 + return VM_FAULT_OOM;
72355 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72356 + return VM_FAULT_OOM;
72357 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72358 + }
72359 +#endif
72360 +
72361 retry:
72362 pgd = pgd_offset(mm, address);
72363 pud = pud_alloc(mm, pgd, address);
72364 @@ -3547,7 +3788,7 @@ retry:
72365 * run pte_offset_map on the pmd, if an huge pmd could
72366 * materialize from under us from a different thread.
72367 */
72368 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72369 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72370 return VM_FAULT_OOM;
72371 /* if an huge pmd materialized from under us just retry later */
72372 if (unlikely(pmd_trans_huge(*pmd)))
72373 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72374 spin_unlock(&mm->page_table_lock);
72375 return 0;
72376 }
72377 +
72378 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72379 +{
72380 + pud_t *new = pud_alloc_one(mm, address);
72381 + if (!new)
72382 + return -ENOMEM;
72383 +
72384 + smp_wmb(); /* See comment in __pte_alloc */
72385 +
72386 + spin_lock(&mm->page_table_lock);
72387 + if (pgd_present(*pgd)) /* Another has populated it */
72388 + pud_free(mm, new);
72389 + else
72390 + pgd_populate_kernel(mm, pgd, new);
72391 + spin_unlock(&mm->page_table_lock);
72392 + return 0;
72393 +}
72394 #endif /* __PAGETABLE_PUD_FOLDED */
72395
72396 #ifndef __PAGETABLE_PMD_FOLDED
72397 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72398 spin_unlock(&mm->page_table_lock);
72399 return 0;
72400 }
72401 +
72402 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72403 +{
72404 + pmd_t *new = pmd_alloc_one(mm, address);
72405 + if (!new)
72406 + return -ENOMEM;
72407 +
72408 + smp_wmb(); /* See comment in __pte_alloc */
72409 +
72410 + spin_lock(&mm->page_table_lock);
72411 +#ifndef __ARCH_HAS_4LEVEL_HACK
72412 + if (pud_present(*pud)) /* Another has populated it */
72413 + pmd_free(mm, new);
72414 + else
72415 + pud_populate_kernel(mm, pud, new);
72416 +#else
72417 + if (pgd_present(*pud)) /* Another has populated it */
72418 + pmd_free(mm, new);
72419 + else
72420 + pgd_populate_kernel(mm, pud, new);
72421 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72422 + spin_unlock(&mm->page_table_lock);
72423 + return 0;
72424 +}
72425 #endif /* __PAGETABLE_PMD_FOLDED */
72426
72427 int make_pages_present(unsigned long addr, unsigned long end)
72428 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72429 gate_vma.vm_start = FIXADDR_USER_START;
72430 gate_vma.vm_end = FIXADDR_USER_END;
72431 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72432 - gate_vma.vm_page_prot = __P101;
72433 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72434
72435 return 0;
72436 }
72437 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72438 index 3d64b36..dbab433 100644
72439 --- a/mm/mempolicy.c
72440 +++ b/mm/mempolicy.c
72441 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72442 unsigned long vmstart;
72443 unsigned long vmend;
72444
72445 +#ifdef CONFIG_PAX_SEGMEXEC
72446 + struct vm_area_struct *vma_m;
72447 +#endif
72448 +
72449 vma = find_vma(mm, start);
72450 if (!vma || vma->vm_start > start)
72451 return -EFAULT;
72452 @@ -691,9 +695,18 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72453 if (err)
72454 goto out;
72455 }
72456 +
72457 err = vma_replace_policy(vma, new_pol);
72458 if (err)
72459 goto out;
72460 +
72461 +#ifdef CONFIG_PAX_SEGMEXEC
72462 + vma_m = pax_find_mirror_vma(vma);
72463 + err = vma_replace_policy(vma_m, new_pol);
72464 + if (err)
72465 + goto out;
72466 +#endif
72467 +
72468 }
72469
72470 out:
72471 @@ -1147,6 +1160,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72472
72473 if (end < start)
72474 return -EINVAL;
72475 +
72476 +#ifdef CONFIG_PAX_SEGMEXEC
72477 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72478 + if (end > SEGMEXEC_TASK_SIZE)
72479 + return -EINVAL;
72480 + } else
72481 +#endif
72482 +
72483 + if (end > TASK_SIZE)
72484 + return -EINVAL;
72485 +
72486 if (end == start)
72487 return 0;
72488
72489 @@ -1370,8 +1394,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72490 */
72491 tcred = __task_cred(task);
72492 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72493 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72494 - !capable(CAP_SYS_NICE)) {
72495 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72496 rcu_read_unlock();
72497 err = -EPERM;
72498 goto out_put;
72499 @@ -1402,6 +1425,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72500 goto out;
72501 }
72502
72503 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72504 + if (mm != current->mm &&
72505 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72506 + mmput(mm);
72507 + err = -EPERM;
72508 + goto out;
72509 + }
72510 +#endif
72511 +
72512 err = do_migrate_pages(mm, old, new,
72513 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72514
72515 diff --git a/mm/migrate.c b/mm/migrate.c
72516 index 77ed2d7..317d528 100644
72517 --- a/mm/migrate.c
72518 +++ b/mm/migrate.c
72519 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72520 */
72521 tcred = __task_cred(task);
72522 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72523 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72524 - !capable(CAP_SYS_NICE)) {
72525 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72526 rcu_read_unlock();
72527 err = -EPERM;
72528 goto out;
72529 diff --git a/mm/mlock.c b/mm/mlock.c
72530 index ef726e8..cd7f1ec 100644
72531 --- a/mm/mlock.c
72532 +++ b/mm/mlock.c
72533 @@ -13,6 +13,7 @@
72534 #include <linux/pagemap.h>
72535 #include <linux/mempolicy.h>
72536 #include <linux/syscalls.h>
72537 +#include <linux/security.h>
72538 #include <linux/sched.h>
72539 #include <linux/export.h>
72540 #include <linux/rmap.h>
72541 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72542 {
72543 unsigned long nstart, end, tmp;
72544 struct vm_area_struct * vma, * prev;
72545 - int error;
72546 + int error = 0;
72547
72548 VM_BUG_ON(start & ~PAGE_MASK);
72549 VM_BUG_ON(len != PAGE_ALIGN(len));
72550 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72551 return -EINVAL;
72552 if (end == start)
72553 return 0;
72554 + if (end > TASK_SIZE)
72555 + return -EINVAL;
72556 +
72557 vma = find_vma(current->mm, start);
72558 if (!vma || vma->vm_start > start)
72559 return -ENOMEM;
72560 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72561 for (nstart = start ; ; ) {
72562 vm_flags_t newflags;
72563
72564 +#ifdef CONFIG_PAX_SEGMEXEC
72565 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72566 + break;
72567 +#endif
72568 +
72569 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72570
72571 newflags = vma->vm_flags | VM_LOCKED;
72572 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72573 lock_limit >>= PAGE_SHIFT;
72574
72575 /* check against resource limits */
72576 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72577 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72578 error = do_mlock(start, len, 1);
72579 up_write(&current->mm->mmap_sem);
72580 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72581 static int do_mlockall(int flags)
72582 {
72583 struct vm_area_struct * vma, * prev = NULL;
72584 - unsigned int def_flags = 0;
72585
72586 if (flags & MCL_FUTURE)
72587 - def_flags = VM_LOCKED;
72588 - current->mm->def_flags = def_flags;
72589 + current->mm->def_flags |= VM_LOCKED;
72590 + else
72591 + current->mm->def_flags &= ~VM_LOCKED;
72592 if (flags == MCL_FUTURE)
72593 goto out;
72594
72595 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72596 vm_flags_t newflags;
72597
72598 +#ifdef CONFIG_PAX_SEGMEXEC
72599 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72600 + break;
72601 +#endif
72602 +
72603 + BUG_ON(vma->vm_end > TASK_SIZE);
72604 newflags = vma->vm_flags | VM_LOCKED;
72605 if (!(flags & MCL_CURRENT))
72606 newflags &= ~VM_LOCKED;
72607 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72608 lock_limit >>= PAGE_SHIFT;
72609
72610 ret = -ENOMEM;
72611 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72612 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72613 capable(CAP_IPC_LOCK))
72614 ret = do_mlockall(flags);
72615 diff --git a/mm/mmap.c b/mm/mmap.c
72616 index ae18a48..86cf99e 100644
72617 --- a/mm/mmap.c
72618 +++ b/mm/mmap.c
72619 @@ -47,6 +47,16 @@
72620 #define arch_rebalance_pgtables(addr, len) (addr)
72621 #endif
72622
72623 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72624 +{
72625 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72626 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72627 + up_read(&mm->mmap_sem);
72628 + BUG();
72629 + }
72630 +#endif
72631 +}
72632 +
72633 static void unmap_region(struct mm_struct *mm,
72634 struct vm_area_struct *vma, struct vm_area_struct *prev,
72635 unsigned long start, unsigned long end);
72636 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72637 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72638 *
72639 */
72640 -pgprot_t protection_map[16] = {
72641 +pgprot_t protection_map[16] __read_only = {
72642 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72643 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72644 };
72645
72646 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72647 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72648 {
72649 - return __pgprot(pgprot_val(protection_map[vm_flags &
72650 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72651 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72652 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72653 +
72654 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72655 + if (!(__supported_pte_mask & _PAGE_NX) &&
72656 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72657 + (vm_flags & (VM_READ | VM_WRITE)))
72658 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72659 +#endif
72660 +
72661 + return prot;
72662 }
72663 EXPORT_SYMBOL(vm_get_page_prot);
72664
72665 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72666 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72667 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72668 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72669 /*
72670 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72671 * other variables. It can be updated by several CPUs frequently.
72672 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72673 struct vm_area_struct *next = vma->vm_next;
72674
72675 might_sleep();
72676 + BUG_ON(vma->vm_mirror);
72677 if (vma->vm_ops && vma->vm_ops->close)
72678 vma->vm_ops->close(vma);
72679 if (vma->vm_file) {
72680 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72681 * not page aligned -Ram Gupta
72682 */
72683 rlim = rlimit(RLIMIT_DATA);
72684 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72685 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72686 (mm->end_data - mm->start_data) > rlim)
72687 goto out;
72688 @@ -708,6 +730,12 @@ static int
72689 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72690 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72691 {
72692 +
72693 +#ifdef CONFIG_PAX_SEGMEXEC
72694 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72695 + return 0;
72696 +#endif
72697 +
72698 if (is_mergeable_vma(vma, file, vm_flags) &&
72699 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72700 if (vma->vm_pgoff == vm_pgoff)
72701 @@ -727,6 +755,12 @@ static int
72702 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72703 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72704 {
72705 +
72706 +#ifdef CONFIG_PAX_SEGMEXEC
72707 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72708 + return 0;
72709 +#endif
72710 +
72711 if (is_mergeable_vma(vma, file, vm_flags) &&
72712 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72713 pgoff_t vm_pglen;
72714 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72715 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72716 struct vm_area_struct *prev, unsigned long addr,
72717 unsigned long end, unsigned long vm_flags,
72718 - struct anon_vma *anon_vma, struct file *file,
72719 + struct anon_vma *anon_vma, struct file *file,
72720 pgoff_t pgoff, struct mempolicy *policy)
72721 {
72722 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72723 struct vm_area_struct *area, *next;
72724 int err;
72725
72726 +#ifdef CONFIG_PAX_SEGMEXEC
72727 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72728 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72729 +
72730 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72731 +#endif
72732 +
72733 /*
72734 * We later require that vma->vm_flags == vm_flags,
72735 * so this tests vma->vm_flags & VM_SPECIAL, too.
72736 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72737 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72738 next = next->vm_next;
72739
72740 +#ifdef CONFIG_PAX_SEGMEXEC
72741 + if (prev)
72742 + prev_m = pax_find_mirror_vma(prev);
72743 + if (area)
72744 + area_m = pax_find_mirror_vma(area);
72745 + if (next)
72746 + next_m = pax_find_mirror_vma(next);
72747 +#endif
72748 +
72749 /*
72750 * Can it merge with the predecessor?
72751 */
72752 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72753 /* cases 1, 6 */
72754 err = vma_adjust(prev, prev->vm_start,
72755 next->vm_end, prev->vm_pgoff, NULL);
72756 - } else /* cases 2, 5, 7 */
72757 +
72758 +#ifdef CONFIG_PAX_SEGMEXEC
72759 + if (!err && prev_m)
72760 + err = vma_adjust(prev_m, prev_m->vm_start,
72761 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72762 +#endif
72763 +
72764 + } else { /* cases 2, 5, 7 */
72765 err = vma_adjust(prev, prev->vm_start,
72766 end, prev->vm_pgoff, NULL);
72767 +
72768 +#ifdef CONFIG_PAX_SEGMEXEC
72769 + if (!err && prev_m)
72770 + err = vma_adjust(prev_m, prev_m->vm_start,
72771 + end_m, prev_m->vm_pgoff, NULL);
72772 +#endif
72773 +
72774 + }
72775 if (err)
72776 return NULL;
72777 khugepaged_enter_vma_merge(prev);
72778 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72779 mpol_equal(policy, vma_policy(next)) &&
72780 can_vma_merge_before(next, vm_flags,
72781 anon_vma, file, pgoff+pglen)) {
72782 - if (prev && addr < prev->vm_end) /* case 4 */
72783 + if (prev && addr < prev->vm_end) { /* case 4 */
72784 err = vma_adjust(prev, prev->vm_start,
72785 addr, prev->vm_pgoff, NULL);
72786 - else /* cases 3, 8 */
72787 +
72788 +#ifdef CONFIG_PAX_SEGMEXEC
72789 + if (!err && prev_m)
72790 + err = vma_adjust(prev_m, prev_m->vm_start,
72791 + addr_m, prev_m->vm_pgoff, NULL);
72792 +#endif
72793 +
72794 + } else { /* cases 3, 8 */
72795 err = vma_adjust(area, addr, next->vm_end,
72796 next->vm_pgoff - pglen, NULL);
72797 +
72798 +#ifdef CONFIG_PAX_SEGMEXEC
72799 + if (!err && area_m)
72800 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72801 + next_m->vm_pgoff - pglen, NULL);
72802 +#endif
72803 +
72804 + }
72805 if (err)
72806 return NULL;
72807 khugepaged_enter_vma_merge(area);
72808 @@ -940,16 +1020,13 @@ none:
72809 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72810 struct file *file, long pages)
72811 {
72812 - const unsigned long stack_flags
72813 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72814 -
72815 mm->total_vm += pages;
72816
72817 if (file) {
72818 mm->shared_vm += pages;
72819 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72820 mm->exec_vm += pages;
72821 - } else if (flags & stack_flags)
72822 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72823 mm->stack_vm += pages;
72824 if (flags & (VM_RESERVED|VM_IO))
72825 mm->reserved_vm += pages;
72826 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72827 * (the exception is when the underlying filesystem is noexec
72828 * mounted, in which case we dont add PROT_EXEC.)
72829 */
72830 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72831 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72832 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72833 prot |= PROT_EXEC;
72834
72835 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72836 /* Obtain the address to map to. we verify (or select) it and ensure
72837 * that it represents a valid section of the address space.
72838 */
72839 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72840 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72841 if (addr & ~PAGE_MASK)
72842 return addr;
72843
72844 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72845 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72846 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72847
72848 +#ifdef CONFIG_PAX_MPROTECT
72849 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72850 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72851 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72852 + gr_log_rwxmmap(file);
72853 +
72854 +#ifdef CONFIG_PAX_EMUPLT
72855 + vm_flags &= ~VM_EXEC;
72856 +#else
72857 + return -EPERM;
72858 +#endif
72859 +
72860 + }
72861 +
72862 + if (!(vm_flags & VM_EXEC))
72863 + vm_flags &= ~VM_MAYEXEC;
72864 +#else
72865 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72866 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72867 +#endif
72868 + else
72869 + vm_flags &= ~VM_MAYWRITE;
72870 + }
72871 +#endif
72872 +
72873 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72874 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72875 + vm_flags &= ~VM_PAGEEXEC;
72876 +#endif
72877 +
72878 if (flags & MAP_LOCKED)
72879 if (!can_do_mlock())
72880 return -EPERM;
72881 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72882 locked += mm->locked_vm;
72883 lock_limit = rlimit(RLIMIT_MEMLOCK);
72884 lock_limit >>= PAGE_SHIFT;
72885 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72886 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72887 return -EAGAIN;
72888 }
72889 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72890 }
72891 }
72892
72893 + if (!gr_acl_handle_mmap(file, prot))
72894 + return -EACCES;
72895 +
72896 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72897 }
72898
72899 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72900 vm_flags_t vm_flags = vma->vm_flags;
72901
72902 /* If it was private or non-writable, the write bit is already clear */
72903 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72904 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72905 return 0;
72906
72907 /* The backer wishes to know when pages are first written to? */
72908 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72909 unsigned long charged = 0;
72910 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72911
72912 +#ifdef CONFIG_PAX_SEGMEXEC
72913 + struct vm_area_struct *vma_m = NULL;
72914 +#endif
72915 +
72916 + /*
72917 + * mm->mmap_sem is required to protect against another thread
72918 + * changing the mappings in case we sleep.
72919 + */
72920 + verify_mm_writelocked(mm);
72921 +
72922 /* Clear old maps */
72923 error = -ENOMEM;
72924 -munmap_back:
72925 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72926 if (vma && vma->vm_start < addr + len) {
72927 if (do_munmap(mm, addr, len))
72928 return -ENOMEM;
72929 - goto munmap_back;
72930 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72931 + BUG_ON(vma && vma->vm_start < addr + len);
72932 }
72933
72934 /* Check against address space limit. */
72935 @@ -1282,6 +1403,16 @@ munmap_back:
72936 goto unacct_error;
72937 }
72938
72939 +#ifdef CONFIG_PAX_SEGMEXEC
72940 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72941 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72942 + if (!vma_m) {
72943 + error = -ENOMEM;
72944 + goto free_vma;
72945 + }
72946 + }
72947 +#endif
72948 +
72949 vma->vm_mm = mm;
72950 vma->vm_start = addr;
72951 vma->vm_end = addr + len;
72952 @@ -1306,6 +1437,19 @@ munmap_back:
72953 error = file->f_op->mmap(file, vma);
72954 if (error)
72955 goto unmap_and_free_vma;
72956 +
72957 +#ifdef CONFIG_PAX_SEGMEXEC
72958 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72959 + added_exe_file_vma(mm);
72960 +#endif
72961 +
72962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72963 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72964 + vma->vm_flags |= VM_PAGEEXEC;
72965 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72966 + }
72967 +#endif
72968 +
72969 if (vm_flags & VM_EXECUTABLE)
72970 added_exe_file_vma(mm);
72971
72972 @@ -1343,6 +1487,11 @@ munmap_back:
72973 vma_link(mm, vma, prev, rb_link, rb_parent);
72974 file = vma->vm_file;
72975
72976 +#ifdef CONFIG_PAX_SEGMEXEC
72977 + if (vma_m)
72978 + BUG_ON(pax_mirror_vma(vma_m, vma));
72979 +#endif
72980 +
72981 /* Once vma denies write, undo our temporary denial count */
72982 if (correct_wcount)
72983 atomic_inc(&inode->i_writecount);
72984 @@ -1350,6 +1499,7 @@ out:
72985 perf_event_mmap(vma);
72986
72987 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72988 + track_exec_limit(mm, addr, addr + len, vm_flags);
72989 if (vm_flags & VM_LOCKED) {
72990 if (!mlock_vma_pages_range(vma, addr, addr + len))
72991 mm->locked_vm += (len >> PAGE_SHIFT);
72992 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72993 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72994 charged = 0;
72995 free_vma:
72996 +
72997 +#ifdef CONFIG_PAX_SEGMEXEC
72998 + if (vma_m)
72999 + kmem_cache_free(vm_area_cachep, vma_m);
73000 +#endif
73001 +
73002 kmem_cache_free(vm_area_cachep, vma);
73003 unacct_error:
73004 if (charged)
73005 @@ -1378,6 +1534,44 @@ unacct_error:
73006 return error;
73007 }
73008
73009 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73010 +{
73011 + if (!vma) {
73012 +#ifdef CONFIG_STACK_GROWSUP
73013 + if (addr > sysctl_heap_stack_gap)
73014 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73015 + else
73016 + vma = find_vma(current->mm, 0);
73017 + if (vma && (vma->vm_flags & VM_GROWSUP))
73018 + return false;
73019 +#endif
73020 + return true;
73021 + }
73022 +
73023 + if (addr + len > vma->vm_start)
73024 + return false;
73025 +
73026 + if (vma->vm_flags & VM_GROWSDOWN)
73027 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73028 +#ifdef CONFIG_STACK_GROWSUP
73029 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73030 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73031 +#endif
73032 +
73033 + return true;
73034 +}
73035 +
73036 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73037 +{
73038 + if (vma->vm_start < len)
73039 + return -ENOMEM;
73040 + if (!(vma->vm_flags & VM_GROWSDOWN))
73041 + return vma->vm_start - len;
73042 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73043 + return vma->vm_start - len - sysctl_heap_stack_gap;
73044 + return -ENOMEM;
73045 +}
73046 +
73047 /* Get an address range which is currently unmapped.
73048 * For shmat() with addr=0.
73049 *
73050 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73051 if (flags & MAP_FIXED)
73052 return addr;
73053
73054 +#ifdef CONFIG_PAX_RANDMMAP
73055 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73056 +#endif
73057 +
73058 if (addr) {
73059 addr = PAGE_ALIGN(addr);
73060 - vma = find_vma(mm, addr);
73061 - if (TASK_SIZE - len >= addr &&
73062 - (!vma || addr + len <= vma->vm_start))
73063 - return addr;
73064 + if (TASK_SIZE - len >= addr) {
73065 + vma = find_vma(mm, addr);
73066 + if (check_heap_stack_gap(vma, addr, len))
73067 + return addr;
73068 + }
73069 }
73070 if (len > mm->cached_hole_size) {
73071 - start_addr = addr = mm->free_area_cache;
73072 + start_addr = addr = mm->free_area_cache;
73073 } else {
73074 - start_addr = addr = TASK_UNMAPPED_BASE;
73075 - mm->cached_hole_size = 0;
73076 + start_addr = addr = mm->mmap_base;
73077 + mm->cached_hole_size = 0;
73078 }
73079
73080 full_search:
73081 @@ -1426,34 +1625,40 @@ full_search:
73082 * Start a new search - just in case we missed
73083 * some holes.
73084 */
73085 - if (start_addr != TASK_UNMAPPED_BASE) {
73086 - addr = TASK_UNMAPPED_BASE;
73087 - start_addr = addr;
73088 + if (start_addr != mm->mmap_base) {
73089 + start_addr = addr = mm->mmap_base;
73090 mm->cached_hole_size = 0;
73091 goto full_search;
73092 }
73093 return -ENOMEM;
73094 }
73095 - if (!vma || addr + len <= vma->vm_start) {
73096 - /*
73097 - * Remember the place where we stopped the search:
73098 - */
73099 - mm->free_area_cache = addr + len;
73100 - return addr;
73101 - }
73102 + if (check_heap_stack_gap(vma, addr, len))
73103 + break;
73104 if (addr + mm->cached_hole_size < vma->vm_start)
73105 mm->cached_hole_size = vma->vm_start - addr;
73106 addr = vma->vm_end;
73107 }
73108 +
73109 + /*
73110 + * Remember the place where we stopped the search:
73111 + */
73112 + mm->free_area_cache = addr + len;
73113 + return addr;
73114 }
73115 #endif
73116
73117 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73118 {
73119 +
73120 +#ifdef CONFIG_PAX_SEGMEXEC
73121 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73122 + return;
73123 +#endif
73124 +
73125 /*
73126 * Is this a new hole at the lowest possible address?
73127 */
73128 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73129 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73130 mm->free_area_cache = addr;
73131 }
73132
73133 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73134 {
73135 struct vm_area_struct *vma;
73136 struct mm_struct *mm = current->mm;
73137 - unsigned long addr = addr0, start_addr;
73138 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73139
73140 /* requested length too big for entire address space */
73141 if (len > TASK_SIZE)
73142 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73143 if (flags & MAP_FIXED)
73144 return addr;
73145
73146 +#ifdef CONFIG_PAX_RANDMMAP
73147 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73148 +#endif
73149 +
73150 /* requesting a specific address */
73151 if (addr) {
73152 addr = PAGE_ALIGN(addr);
73153 - vma = find_vma(mm, addr);
73154 - if (TASK_SIZE - len >= addr &&
73155 - (!vma || addr + len <= vma->vm_start))
73156 - return addr;
73157 + if (TASK_SIZE - len >= addr) {
73158 + vma = find_vma(mm, addr);
73159 + if (check_heap_stack_gap(vma, addr, len))
73160 + return addr;
73161 + }
73162 }
73163
73164 /* check if free_area_cache is useful for us */
73165 @@ -1508,7 +1718,7 @@ try_again:
73166 * return with success:
73167 */
73168 vma = find_vma(mm, addr);
73169 - if (!vma || addr+len <= vma->vm_start)
73170 + if (check_heap_stack_gap(vma, addr, len))
73171 /* remember the address as a hint for next time */
73172 return (mm->free_area_cache = addr);
73173
73174 @@ -1517,8 +1727,8 @@ try_again:
73175 mm->cached_hole_size = vma->vm_start - addr;
73176
73177 /* try just below the current vma->vm_start */
73178 - addr = vma->vm_start-len;
73179 - } while (len < vma->vm_start);
73180 + addr = skip_heap_stack_gap(vma, len);
73181 + } while (!IS_ERR_VALUE(addr));
73182
73183 fail:
73184 /*
73185 @@ -1541,13 +1751,21 @@ fail:
73186 * can happen with large stack limits and large mmap()
73187 * allocations.
73188 */
73189 + mm->mmap_base = TASK_UNMAPPED_BASE;
73190 +
73191 +#ifdef CONFIG_PAX_RANDMMAP
73192 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73193 + mm->mmap_base += mm->delta_mmap;
73194 +#endif
73195 +
73196 + mm->free_area_cache = mm->mmap_base;
73197 mm->cached_hole_size = ~0UL;
73198 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73199 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73200 /*
73201 * Restore the topdown base:
73202 */
73203 - mm->free_area_cache = mm->mmap_base;
73204 + mm->mmap_base = base;
73205 + mm->free_area_cache = base;
73206 mm->cached_hole_size = ~0UL;
73207
73208 return addr;
73209 @@ -1556,6 +1774,12 @@ fail:
73210
73211 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73212 {
73213 +
73214 +#ifdef CONFIG_PAX_SEGMEXEC
73215 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73216 + return;
73217 +#endif
73218 +
73219 /*
73220 * Is this a new hole at the highest possible address?
73221 */
73222 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73223 mm->free_area_cache = addr;
73224
73225 /* dont allow allocations above current base */
73226 - if (mm->free_area_cache > mm->mmap_base)
73227 + if (mm->free_area_cache > mm->mmap_base) {
73228 mm->free_area_cache = mm->mmap_base;
73229 + mm->cached_hole_size = ~0UL;
73230 + }
73231 }
73232
73233 unsigned long
73234 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73235 return vma;
73236 }
73237
73238 +#ifdef CONFIG_PAX_SEGMEXEC
73239 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73240 +{
73241 + struct vm_area_struct *vma_m;
73242 +
73243 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73244 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73245 + BUG_ON(vma->vm_mirror);
73246 + return NULL;
73247 + }
73248 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73249 + vma_m = vma->vm_mirror;
73250 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73251 + BUG_ON(vma->vm_file != vma_m->vm_file);
73252 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73253 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73254 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73255 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73256 + return vma_m;
73257 +}
73258 +#endif
73259 +
73260 /*
73261 * Verify that the stack growth is acceptable and
73262 * update accounting. This is shared with both the
73263 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73264 return -ENOMEM;
73265
73266 /* Stack limit test */
73267 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73268 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73269 return -ENOMEM;
73270
73271 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73272 locked = mm->locked_vm + grow;
73273 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73274 limit >>= PAGE_SHIFT;
73275 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73276 if (locked > limit && !capable(CAP_IPC_LOCK))
73277 return -ENOMEM;
73278 }
73279 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73280 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73281 * vma is the last one with address > vma->vm_end. Have to extend vma.
73282 */
73283 +#ifndef CONFIG_IA64
73284 +static
73285 +#endif
73286 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73287 {
73288 int error;
73289 + bool locknext;
73290
73291 if (!(vma->vm_flags & VM_GROWSUP))
73292 return -EFAULT;
73293
73294 + /* Also guard against wrapping around to address 0. */
73295 + if (address < PAGE_ALIGN(address+1))
73296 + address = PAGE_ALIGN(address+1);
73297 + else
73298 + return -ENOMEM;
73299 +
73300 /*
73301 * We must make sure the anon_vma is allocated
73302 * so that the anon_vma locking is not a noop.
73303 */
73304 if (unlikely(anon_vma_prepare(vma)))
73305 return -ENOMEM;
73306 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73307 + if (locknext && anon_vma_prepare(vma->vm_next))
73308 + return -ENOMEM;
73309 vma_lock_anon_vma(vma);
73310 + if (locknext)
73311 + vma_lock_anon_vma(vma->vm_next);
73312
73313 /*
73314 * vma->vm_start/vm_end cannot change under us because the caller
73315 * is required to hold the mmap_sem in read mode. We need the
73316 - * anon_vma lock to serialize against concurrent expand_stacks.
73317 - * Also guard against wrapping around to address 0.
73318 + * anon_vma locks to serialize against concurrent expand_stacks
73319 + * and expand_upwards.
73320 */
73321 - if (address < PAGE_ALIGN(address+4))
73322 - address = PAGE_ALIGN(address+4);
73323 - else {
73324 - vma_unlock_anon_vma(vma);
73325 - return -ENOMEM;
73326 - }
73327 error = 0;
73328
73329 /* Somebody else might have raced and expanded it already */
73330 - if (address > vma->vm_end) {
73331 + 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)
73332 + error = -ENOMEM;
73333 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73334 unsigned long size, grow;
73335
73336 size = address - vma->vm_start;
73337 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73338 }
73339 }
73340 }
73341 + if (locknext)
73342 + vma_unlock_anon_vma(vma->vm_next);
73343 vma_unlock_anon_vma(vma);
73344 khugepaged_enter_vma_merge(vma);
73345 return error;
73346 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73347 unsigned long address)
73348 {
73349 int error;
73350 + bool lockprev = false;
73351 + struct vm_area_struct *prev;
73352
73353 /*
73354 * We must make sure the anon_vma is allocated
73355 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73356 if (error)
73357 return error;
73358
73359 + prev = vma->vm_prev;
73360 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73361 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73362 +#endif
73363 + if (lockprev && anon_vma_prepare(prev))
73364 + return -ENOMEM;
73365 + if (lockprev)
73366 + vma_lock_anon_vma(prev);
73367 +
73368 vma_lock_anon_vma(vma);
73369
73370 /*
73371 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73372 */
73373
73374 /* Somebody else might have raced and expanded it already */
73375 - if (address < vma->vm_start) {
73376 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73377 + error = -ENOMEM;
73378 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73379 unsigned long size, grow;
73380
73381 +#ifdef CONFIG_PAX_SEGMEXEC
73382 + struct vm_area_struct *vma_m;
73383 +
73384 + vma_m = pax_find_mirror_vma(vma);
73385 +#endif
73386 +
73387 size = vma->vm_end - address;
73388 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73389
73390 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73391 if (!error) {
73392 vma->vm_start = address;
73393 vma->vm_pgoff -= grow;
73394 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73395 +
73396 +#ifdef CONFIG_PAX_SEGMEXEC
73397 + if (vma_m) {
73398 + vma_m->vm_start -= grow << PAGE_SHIFT;
73399 + vma_m->vm_pgoff -= grow;
73400 + }
73401 +#endif
73402 +
73403 perf_event_mmap(vma);
73404 }
73405 }
73406 }
73407 vma_unlock_anon_vma(vma);
73408 + if (lockprev)
73409 + vma_unlock_anon_vma(prev);
73410 khugepaged_enter_vma_merge(vma);
73411 return error;
73412 }
73413 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73414 do {
73415 long nrpages = vma_pages(vma);
73416
73417 +#ifdef CONFIG_PAX_SEGMEXEC
73418 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73419 + vma = remove_vma(vma);
73420 + continue;
73421 + }
73422 +#endif
73423 +
73424 if (vma->vm_flags & VM_ACCOUNT)
73425 nr_accounted += nrpages;
73426 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73427 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73428 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73429 vma->vm_prev = NULL;
73430 do {
73431 +
73432 +#ifdef CONFIG_PAX_SEGMEXEC
73433 + if (vma->vm_mirror) {
73434 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73435 + vma->vm_mirror->vm_mirror = NULL;
73436 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73437 + vma->vm_mirror = NULL;
73438 + }
73439 +#endif
73440 +
73441 rb_erase(&vma->vm_rb, &mm->mm_rb);
73442 mm->map_count--;
73443 tail_vma = vma;
73444 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73445 struct vm_area_struct *new;
73446 int err = -ENOMEM;
73447
73448 +#ifdef CONFIG_PAX_SEGMEXEC
73449 + struct vm_area_struct *vma_m, *new_m = NULL;
73450 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73451 +#endif
73452 +
73453 if (is_vm_hugetlb_page(vma) && (addr &
73454 ~(huge_page_mask(hstate_vma(vma)))))
73455 return -EINVAL;
73456
73457 +#ifdef CONFIG_PAX_SEGMEXEC
73458 + vma_m = pax_find_mirror_vma(vma);
73459 +#endif
73460 +
73461 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73462 if (!new)
73463 goto out_err;
73464
73465 +#ifdef CONFIG_PAX_SEGMEXEC
73466 + if (vma_m) {
73467 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73468 + if (!new_m) {
73469 + kmem_cache_free(vm_area_cachep, new);
73470 + goto out_err;
73471 + }
73472 + }
73473 +#endif
73474 +
73475 /* most fields are the same, copy all, and then fixup */
73476 *new = *vma;
73477
73478 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73479 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73480 }
73481
73482 +#ifdef CONFIG_PAX_SEGMEXEC
73483 + if (vma_m) {
73484 + *new_m = *vma_m;
73485 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73486 + new_m->vm_mirror = new;
73487 + new->vm_mirror = new_m;
73488 +
73489 + if (new_below)
73490 + new_m->vm_end = addr_m;
73491 + else {
73492 + new_m->vm_start = addr_m;
73493 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73494 + }
73495 + }
73496 +#endif
73497 +
73498 pol = mpol_dup(vma_policy(vma));
73499 if (IS_ERR(pol)) {
73500 err = PTR_ERR(pol);
73501 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73502 else
73503 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73504
73505 +#ifdef CONFIG_PAX_SEGMEXEC
73506 + if (!err && vma_m) {
73507 + if (anon_vma_clone(new_m, vma_m))
73508 + goto out_free_mpol;
73509 +
73510 + mpol_get(pol);
73511 + vma_set_policy(new_m, pol);
73512 +
73513 + if (new_m->vm_file) {
73514 + get_file(new_m->vm_file);
73515 + if (vma_m->vm_flags & VM_EXECUTABLE)
73516 + added_exe_file_vma(mm);
73517 + }
73518 +
73519 + if (new_m->vm_ops && new_m->vm_ops->open)
73520 + new_m->vm_ops->open(new_m);
73521 +
73522 + if (new_below)
73523 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73524 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73525 + else
73526 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73527 +
73528 + if (err) {
73529 + if (new_m->vm_ops && new_m->vm_ops->close)
73530 + new_m->vm_ops->close(new_m);
73531 + if (new_m->vm_file) {
73532 + if (vma_m->vm_flags & VM_EXECUTABLE)
73533 + removed_exe_file_vma(mm);
73534 + fput(new_m->vm_file);
73535 + }
73536 + mpol_put(pol);
73537 + }
73538 + }
73539 +#endif
73540 +
73541 /* Success. */
73542 if (!err)
73543 return 0;
73544 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73545 removed_exe_file_vma(mm);
73546 fput(new->vm_file);
73547 }
73548 - unlink_anon_vmas(new);
73549 out_free_mpol:
73550 mpol_put(pol);
73551 out_free_vma:
73552 +
73553 +#ifdef CONFIG_PAX_SEGMEXEC
73554 + if (new_m) {
73555 + unlink_anon_vmas(new_m);
73556 + kmem_cache_free(vm_area_cachep, new_m);
73557 + }
73558 +#endif
73559 +
73560 + unlink_anon_vmas(new);
73561 kmem_cache_free(vm_area_cachep, new);
73562 out_err:
73563 return err;
73564 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73565 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73566 unsigned long addr, int new_below)
73567 {
73568 +
73569 +#ifdef CONFIG_PAX_SEGMEXEC
73570 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73571 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73572 + if (mm->map_count >= sysctl_max_map_count-1)
73573 + return -ENOMEM;
73574 + } else
73575 +#endif
73576 +
73577 if (mm->map_count >= sysctl_max_map_count)
73578 return -ENOMEM;
73579
73580 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73581 * work. This now handles partial unmappings.
73582 * Jeremy Fitzhardinge <jeremy@goop.org>
73583 */
73584 +#ifdef CONFIG_PAX_SEGMEXEC
73585 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73586 {
73587 + int ret = __do_munmap(mm, start, len);
73588 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73589 + return ret;
73590 +
73591 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73592 +}
73593 +
73594 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73595 +#else
73596 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73597 +#endif
73598 +{
73599 unsigned long end;
73600 struct vm_area_struct *vma, *prev, *last;
73601
73602 + /*
73603 + * mm->mmap_sem is required to protect against another thread
73604 + * changing the mappings in case we sleep.
73605 + */
73606 + verify_mm_writelocked(mm);
73607 +
73608 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73609 return -EINVAL;
73610
73611 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73612 /* Fix up all other VM information */
73613 remove_vma_list(mm, vma);
73614
73615 + track_exec_limit(mm, start, end, 0UL);
73616 +
73617 return 0;
73618 }
73619
73620 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73621 int ret;
73622 struct mm_struct *mm = current->mm;
73623
73624 +
73625 +#ifdef CONFIG_PAX_SEGMEXEC
73626 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73627 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73628 + return -EINVAL;
73629 +#endif
73630 +
73631 down_write(&mm->mmap_sem);
73632 ret = do_munmap(mm, start, len);
73633 up_write(&mm->mmap_sem);
73634 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73635 return vm_munmap(addr, len);
73636 }
73637
73638 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73639 -{
73640 -#ifdef CONFIG_DEBUG_VM
73641 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73642 - WARN_ON(1);
73643 - up_read(&mm->mmap_sem);
73644 - }
73645 -#endif
73646 -}
73647 -
73648 /*
73649 * this is really a simplified "do_mmap". it only handles
73650 * anonymous maps. eventually we may be able to do some
73651 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73652 struct rb_node ** rb_link, * rb_parent;
73653 pgoff_t pgoff = addr >> PAGE_SHIFT;
73654 int error;
73655 + unsigned long charged;
73656
73657 len = PAGE_ALIGN(len);
73658 if (!len)
73659 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73660
73661 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73662
73663 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73664 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73665 + flags &= ~VM_EXEC;
73666 +
73667 +#ifdef CONFIG_PAX_MPROTECT
73668 + if (mm->pax_flags & MF_PAX_MPROTECT)
73669 + flags &= ~VM_MAYEXEC;
73670 +#endif
73671 +
73672 + }
73673 +#endif
73674 +
73675 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73676 if (error & ~PAGE_MASK)
73677 return error;
73678
73679 + charged = len >> PAGE_SHIFT;
73680 +
73681 /*
73682 * mlock MCL_FUTURE?
73683 */
73684 if (mm->def_flags & VM_LOCKED) {
73685 unsigned long locked, lock_limit;
73686 - locked = len >> PAGE_SHIFT;
73687 + locked = charged;
73688 locked += mm->locked_vm;
73689 lock_limit = rlimit(RLIMIT_MEMLOCK);
73690 lock_limit >>= PAGE_SHIFT;
73691 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73692 /*
73693 * Clear old maps. this also does some error checking for us
73694 */
73695 - munmap_back:
73696 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73697 if (vma && vma->vm_start < addr + len) {
73698 if (do_munmap(mm, addr, len))
73699 return -ENOMEM;
73700 - goto munmap_back;
73701 - }
73702 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73703 + BUG_ON(vma && vma->vm_start < addr + len);
73704 + }
73705
73706 /* Check against address space limits *after* clearing old maps... */
73707 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73708 + if (!may_expand_vm(mm, charged))
73709 return -ENOMEM;
73710
73711 if (mm->map_count > sysctl_max_map_count)
73712 return -ENOMEM;
73713
73714 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73715 + if (security_vm_enough_memory_mm(mm, charged))
73716 return -ENOMEM;
73717
73718 /* Can we just expand an old private anonymous mapping? */
73719 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73720 */
73721 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73722 if (!vma) {
73723 - vm_unacct_memory(len >> PAGE_SHIFT);
73724 + vm_unacct_memory(charged);
73725 return -ENOMEM;
73726 }
73727
73728 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73729 vma_link(mm, vma, prev, rb_link, rb_parent);
73730 out:
73731 perf_event_mmap(vma);
73732 - mm->total_vm += len >> PAGE_SHIFT;
73733 + mm->total_vm += charged;
73734 if (flags & VM_LOCKED) {
73735 if (!mlock_vma_pages_range(vma, addr, addr + len))
73736 - mm->locked_vm += (len >> PAGE_SHIFT);
73737 + mm->locked_vm += charged;
73738 }
73739 + track_exec_limit(mm, addr, addr + len, flags);
73740 return addr;
73741 }
73742
73743 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73744 while (vma) {
73745 if (vma->vm_flags & VM_ACCOUNT)
73746 nr_accounted += vma_pages(vma);
73747 + vma->vm_mirror = NULL;
73748 vma = remove_vma(vma);
73749 }
73750 vm_unacct_memory(nr_accounted);
73751 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73752 struct vm_area_struct * __vma, * prev;
73753 struct rb_node ** rb_link, * rb_parent;
73754
73755 +#ifdef CONFIG_PAX_SEGMEXEC
73756 + struct vm_area_struct *vma_m = NULL;
73757 +#endif
73758 +
73759 + if (security_mmap_addr(vma->vm_start))
73760 + return -EPERM;
73761 +
73762 /*
73763 * The vm_pgoff of a purely anonymous vma should be irrelevant
73764 * until its first write fault, when page's anon_vma and index
73765 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73766 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73767 return -ENOMEM;
73768
73769 +#ifdef CONFIG_PAX_SEGMEXEC
73770 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73771 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73772 + if (!vma_m)
73773 + return -ENOMEM;
73774 + }
73775 +#endif
73776 +
73777 vma_link(mm, vma, prev, rb_link, rb_parent);
73778 +
73779 +#ifdef CONFIG_PAX_SEGMEXEC
73780 + if (vma_m)
73781 + BUG_ON(pax_mirror_vma(vma_m, vma));
73782 +#endif
73783 +
73784 return 0;
73785 }
73786
73787 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73788 struct mempolicy *pol;
73789 bool faulted_in_anon_vma = true;
73790
73791 + BUG_ON(vma->vm_mirror);
73792 +
73793 /*
73794 * If anonymous vma has not yet been faulted, update new pgoff
73795 * to match new location, to increase its chance of merging.
73796 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73797 return NULL;
73798 }
73799
73800 +#ifdef CONFIG_PAX_SEGMEXEC
73801 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73802 +{
73803 + struct vm_area_struct *prev_m;
73804 + struct rb_node **rb_link_m, *rb_parent_m;
73805 + struct mempolicy *pol_m;
73806 +
73807 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73808 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73809 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73810 + *vma_m = *vma;
73811 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73812 + if (anon_vma_clone(vma_m, vma))
73813 + return -ENOMEM;
73814 + pol_m = vma_policy(vma_m);
73815 + mpol_get(pol_m);
73816 + vma_set_policy(vma_m, pol_m);
73817 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73818 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73819 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73820 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73821 + if (vma_m->vm_file)
73822 + get_file(vma_m->vm_file);
73823 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73824 + vma_m->vm_ops->open(vma_m);
73825 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73826 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73827 + vma_m->vm_mirror = vma;
73828 + vma->vm_mirror = vma_m;
73829 + return 0;
73830 +}
73831 +#endif
73832 +
73833 /*
73834 * Return true if the calling process may expand its vm space by the passed
73835 * number of pages
73836 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73837
73838 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73839
73840 +#ifdef CONFIG_PAX_RANDMMAP
73841 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73842 + cur -= mm->brk_gap;
73843 +#endif
73844 +
73845 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73846 if (cur + npages > lim)
73847 return 0;
73848 return 1;
73849 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73850 vma->vm_start = addr;
73851 vma->vm_end = addr + len;
73852
73853 +#ifdef CONFIG_PAX_MPROTECT
73854 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73855 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73856 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73857 + return -EPERM;
73858 + if (!(vm_flags & VM_EXEC))
73859 + vm_flags &= ~VM_MAYEXEC;
73860 +#else
73861 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73862 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73863 +#endif
73864 + else
73865 + vm_flags &= ~VM_MAYWRITE;
73866 + }
73867 +#endif
73868 +
73869 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73870 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73871
73872 diff --git a/mm/mprotect.c b/mm/mprotect.c
73873 index a409926..8b32e6d 100644
73874 --- a/mm/mprotect.c
73875 +++ b/mm/mprotect.c
73876 @@ -23,10 +23,17 @@
73877 #include <linux/mmu_notifier.h>
73878 #include <linux/migrate.h>
73879 #include <linux/perf_event.h>
73880 +
73881 +#ifdef CONFIG_PAX_MPROTECT
73882 +#include <linux/elf.h>
73883 +#include <linux/binfmts.h>
73884 +#endif
73885 +
73886 #include <asm/uaccess.h>
73887 #include <asm/pgtable.h>
73888 #include <asm/cacheflush.h>
73889 #include <asm/tlbflush.h>
73890 +#include <asm/mmu_context.h>
73891
73892 #ifndef pgprot_modify
73893 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73894 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73895 flush_tlb_range(vma, start, end);
73896 }
73897
73898 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73899 +/* called while holding the mmap semaphor for writing except stack expansion */
73900 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73901 +{
73902 + unsigned long oldlimit, newlimit = 0UL;
73903 +
73904 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73905 + return;
73906 +
73907 + spin_lock(&mm->page_table_lock);
73908 + oldlimit = mm->context.user_cs_limit;
73909 + if ((prot & VM_EXEC) && oldlimit < end)
73910 + /* USER_CS limit moved up */
73911 + newlimit = end;
73912 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73913 + /* USER_CS limit moved down */
73914 + newlimit = start;
73915 +
73916 + if (newlimit) {
73917 + mm->context.user_cs_limit = newlimit;
73918 +
73919 +#ifdef CONFIG_SMP
73920 + wmb();
73921 + cpus_clear(mm->context.cpu_user_cs_mask);
73922 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73923 +#endif
73924 +
73925 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73926 + }
73927 + spin_unlock(&mm->page_table_lock);
73928 + if (newlimit == end) {
73929 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73930 +
73931 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73932 + if (is_vm_hugetlb_page(vma))
73933 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73934 + else
73935 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73936 + }
73937 +}
73938 +#endif
73939 +
73940 int
73941 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73942 unsigned long start, unsigned long end, unsigned long newflags)
73943 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73944 int error;
73945 int dirty_accountable = 0;
73946
73947 +#ifdef CONFIG_PAX_SEGMEXEC
73948 + struct vm_area_struct *vma_m = NULL;
73949 + unsigned long start_m, end_m;
73950 +
73951 + start_m = start + SEGMEXEC_TASK_SIZE;
73952 + end_m = end + SEGMEXEC_TASK_SIZE;
73953 +#endif
73954 +
73955 if (newflags == oldflags) {
73956 *pprev = vma;
73957 return 0;
73958 }
73959
73960 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73961 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73962 +
73963 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73964 + return -ENOMEM;
73965 +
73966 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73967 + return -ENOMEM;
73968 + }
73969 +
73970 /*
73971 * If we make a private mapping writable we increase our commit;
73972 * but (without finer accounting) cannot reduce our commit if we
73973 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73974 }
73975 }
73976
73977 +#ifdef CONFIG_PAX_SEGMEXEC
73978 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73979 + if (start != vma->vm_start) {
73980 + error = split_vma(mm, vma, start, 1);
73981 + if (error)
73982 + goto fail;
73983 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73984 + *pprev = (*pprev)->vm_next;
73985 + }
73986 +
73987 + if (end != vma->vm_end) {
73988 + error = split_vma(mm, vma, end, 0);
73989 + if (error)
73990 + goto fail;
73991 + }
73992 +
73993 + if (pax_find_mirror_vma(vma)) {
73994 + error = __do_munmap(mm, start_m, end_m - start_m);
73995 + if (error)
73996 + goto fail;
73997 + } else {
73998 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73999 + if (!vma_m) {
74000 + error = -ENOMEM;
74001 + goto fail;
74002 + }
74003 + vma->vm_flags = newflags;
74004 + error = pax_mirror_vma(vma_m, vma);
74005 + if (error) {
74006 + vma->vm_flags = oldflags;
74007 + goto fail;
74008 + }
74009 + }
74010 + }
74011 +#endif
74012 +
74013 /*
74014 * First try to merge with previous and/or next vma.
74015 */
74016 @@ -204,9 +307,21 @@ success:
74017 * vm_flags and vm_page_prot are protected by the mmap_sem
74018 * held in write mode.
74019 */
74020 +
74021 +#ifdef CONFIG_PAX_SEGMEXEC
74022 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74023 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74024 +#endif
74025 +
74026 vma->vm_flags = newflags;
74027 +
74028 +#ifdef CONFIG_PAX_MPROTECT
74029 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74030 + mm->binfmt->handle_mprotect(vma, newflags);
74031 +#endif
74032 +
74033 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74034 - vm_get_page_prot(newflags));
74035 + vm_get_page_prot(vma->vm_flags));
74036
74037 if (vma_wants_writenotify(vma)) {
74038 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74039 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74040 end = start + len;
74041 if (end <= start)
74042 return -ENOMEM;
74043 +
74044 +#ifdef CONFIG_PAX_SEGMEXEC
74045 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74046 + if (end > SEGMEXEC_TASK_SIZE)
74047 + return -EINVAL;
74048 + } else
74049 +#endif
74050 +
74051 + if (end > TASK_SIZE)
74052 + return -EINVAL;
74053 +
74054 if (!arch_validate_prot(prot))
74055 return -EINVAL;
74056
74057 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74058 /*
74059 * Does the application expect PROT_READ to imply PROT_EXEC:
74060 */
74061 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74062 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74063 prot |= PROT_EXEC;
74064
74065 vm_flags = calc_vm_prot_bits(prot);
74066 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74067 if (start > vma->vm_start)
74068 prev = vma;
74069
74070 +#ifdef CONFIG_PAX_MPROTECT
74071 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74072 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74073 +#endif
74074 +
74075 for (nstart = start ; ; ) {
74076 unsigned long newflags;
74077
74078 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74079
74080 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74081 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74082 + if (prot & (PROT_WRITE | PROT_EXEC))
74083 + gr_log_rwxmprotect(vma->vm_file);
74084 +
74085 + error = -EACCES;
74086 + goto out;
74087 + }
74088 +
74089 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74090 error = -EACCES;
74091 goto out;
74092 }
74093 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74094 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74095 if (error)
74096 goto out;
74097 +
74098 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74099 +
74100 nstart = tmp;
74101
74102 if (nstart < prev->vm_end)
74103 diff --git a/mm/mremap.c b/mm/mremap.c
74104 index cc06d0e..40b5d18 100644
74105 --- a/mm/mremap.c
74106 +++ b/mm/mremap.c
74107 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74108 continue;
74109 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74110 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74111 +
74112 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74113 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74114 + pte = pte_exprotect(pte);
74115 +#endif
74116 +
74117 set_pte_at(mm, new_addr, new_pte, pte);
74118 }
74119
74120 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74121 if (is_vm_hugetlb_page(vma))
74122 goto Einval;
74123
74124 +#ifdef CONFIG_PAX_SEGMEXEC
74125 + if (pax_find_mirror_vma(vma))
74126 + goto Einval;
74127 +#endif
74128 +
74129 /* We can't remap across vm area boundaries */
74130 if (old_len > vma->vm_end - addr)
74131 goto Efault;
74132 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74133 unsigned long ret = -EINVAL;
74134 unsigned long charged = 0;
74135 unsigned long map_flags;
74136 + unsigned long pax_task_size = TASK_SIZE;
74137
74138 if (new_addr & ~PAGE_MASK)
74139 goto out;
74140
74141 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74142 +#ifdef CONFIG_PAX_SEGMEXEC
74143 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74144 + pax_task_size = SEGMEXEC_TASK_SIZE;
74145 +#endif
74146 +
74147 + pax_task_size -= PAGE_SIZE;
74148 +
74149 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74150 goto out;
74151
74152 /* Check if the location we're moving into overlaps the
74153 * old location at all, and fail if it does.
74154 */
74155 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74156 - goto out;
74157 -
74158 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74159 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74160 goto out;
74161
74162 ret = do_munmap(mm, new_addr, new_len);
74163 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74164 struct vm_area_struct *vma;
74165 unsigned long ret = -EINVAL;
74166 unsigned long charged = 0;
74167 + unsigned long pax_task_size = TASK_SIZE;
74168
74169 down_write(&current->mm->mmap_sem);
74170
74171 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74172 if (!new_len)
74173 goto out;
74174
74175 +#ifdef CONFIG_PAX_SEGMEXEC
74176 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74177 + pax_task_size = SEGMEXEC_TASK_SIZE;
74178 +#endif
74179 +
74180 + pax_task_size -= PAGE_SIZE;
74181 +
74182 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74183 + old_len > pax_task_size || addr > pax_task_size-old_len)
74184 + goto out;
74185 +
74186 if (flags & MREMAP_FIXED) {
74187 if (flags & MREMAP_MAYMOVE)
74188 ret = mremap_to(addr, old_len, new_addr, new_len);
74189 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74190 addr + new_len);
74191 }
74192 ret = addr;
74193 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74194 goto out;
74195 }
74196 }
74197 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74198 goto out;
74199 }
74200
74201 + map_flags = vma->vm_flags;
74202 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74203 + if (!(ret & ~PAGE_MASK)) {
74204 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74205 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74206 + }
74207 }
74208 out:
74209 if (ret & ~PAGE_MASK)
74210 diff --git a/mm/nommu.c b/mm/nommu.c
74211 index d4b0c10..ed421b5 100644
74212 --- a/mm/nommu.c
74213 +++ b/mm/nommu.c
74214 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74215 int sysctl_overcommit_ratio = 50; /* default is 50% */
74216 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74217 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74218 -int heap_stack_gap = 0;
74219
74220 atomic_long_t mmap_pages_allocated;
74221
74222 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74223 EXPORT_SYMBOL(find_vma);
74224
74225 /*
74226 - * find a VMA
74227 - * - we don't extend stack VMAs under NOMMU conditions
74228 - */
74229 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74230 -{
74231 - return find_vma(mm, addr);
74232 -}
74233 -
74234 -/*
74235 * expand a stack to a given address
74236 * - not supported under NOMMU conditions
74237 */
74238 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74239
74240 /* most fields are the same, copy all, and then fixup */
74241 *new = *vma;
74242 + INIT_LIST_HEAD(&new->anon_vma_chain);
74243 *region = *vma->vm_region;
74244 new->vm_region = region;
74245
74246 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74247 index c13ea75..081ab2c 100644
74248 --- a/mm/page_alloc.c
74249 +++ b/mm/page_alloc.c
74250 @@ -340,7 +340,7 @@ out:
74251 * This usage means that zero-order pages may not be compound.
74252 */
74253
74254 -static void free_compound_page(struct page *page)
74255 +void free_compound_page(struct page *page)
74256 {
74257 __free_pages_ok(page, compound_order(page));
74258 }
74259 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74260 int i;
74261 int bad = 0;
74262
74263 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74264 + unsigned long index = 1UL << order;
74265 +#endif
74266 +
74267 trace_mm_page_free(page, order);
74268 kmemcheck_free_shadow(page, order);
74269
74270 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74271 debug_check_no_obj_freed(page_address(page),
74272 PAGE_SIZE << order);
74273 }
74274 +
74275 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74276 + for (; index; --index)
74277 + sanitize_highpage(page + index - 1);
74278 +#endif
74279 +
74280 arch_free_page(page, order);
74281 kernel_map_pages(page, 1 << order, 0);
74282
74283 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74284 arch_alloc_page(page, order);
74285 kernel_map_pages(page, 1 << order, 1);
74286
74287 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74288 if (gfp_flags & __GFP_ZERO)
74289 prep_zero_page(page, order, gfp_flags);
74290 +#endif
74291
74292 if (order && (gfp_flags & __GFP_COMP))
74293 prep_compound_page(page, order);
74294 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74295 unsigned long pfn;
74296
74297 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74298 +#ifdef CONFIG_X86_32
74299 + /* boot failures in VMware 8 on 32bit vanilla since
74300 + this change */
74301 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74302 +#else
74303 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74304 +#endif
74305 return 1;
74306 }
74307 return 0;
74308 diff --git a/mm/percpu.c b/mm/percpu.c
74309 index bb4be74..a43ea85 100644
74310 --- a/mm/percpu.c
74311 +++ b/mm/percpu.c
74312 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74313 static unsigned int pcpu_high_unit_cpu __read_mostly;
74314
74315 /* the address of the first chunk which starts with the kernel static area */
74316 -void *pcpu_base_addr __read_mostly;
74317 +void *pcpu_base_addr __read_only;
74318 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74319
74320 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74321 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74322 index 926b466..b23df53 100644
74323 --- a/mm/process_vm_access.c
74324 +++ b/mm/process_vm_access.c
74325 @@ -13,6 +13,7 @@
74326 #include <linux/uio.h>
74327 #include <linux/sched.h>
74328 #include <linux/highmem.h>
74329 +#include <linux/security.h>
74330 #include <linux/ptrace.h>
74331 #include <linux/slab.h>
74332 #include <linux/syscalls.h>
74333 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74334 size_t iov_l_curr_offset = 0;
74335 ssize_t iov_len;
74336
74337 + return -ENOSYS; // PaX: until properly audited
74338 +
74339 /*
74340 * Work out how many pages of struct pages we're going to need
74341 * when eventually calling get_user_pages
74342 */
74343 for (i = 0; i < riovcnt; i++) {
74344 iov_len = rvec[i].iov_len;
74345 - if (iov_len > 0) {
74346 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74347 - + iov_len)
74348 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74349 - / PAGE_SIZE + 1;
74350 - nr_pages = max(nr_pages, nr_pages_iov);
74351 - }
74352 + if (iov_len <= 0)
74353 + continue;
74354 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74355 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74356 + nr_pages = max(nr_pages, nr_pages_iov);
74357 }
74358
74359 if (nr_pages == 0)
74360 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74361 goto free_proc_pages;
74362 }
74363
74364 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74365 + rc = -EPERM;
74366 + goto put_task_struct;
74367 + }
74368 +
74369 mm = mm_access(task, PTRACE_MODE_ATTACH);
74370 if (!mm || IS_ERR(mm)) {
74371 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74372 diff --git a/mm/rmap.c b/mm/rmap.c
74373 index 0f3b7cd..c5652b6 100644
74374 --- a/mm/rmap.c
74375 +++ b/mm/rmap.c
74376 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74377 struct anon_vma *anon_vma = vma->anon_vma;
74378 struct anon_vma_chain *avc;
74379
74380 +#ifdef CONFIG_PAX_SEGMEXEC
74381 + struct anon_vma_chain *avc_m = NULL;
74382 +#endif
74383 +
74384 might_sleep();
74385 if (unlikely(!anon_vma)) {
74386 struct mm_struct *mm = vma->vm_mm;
74387 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74388 if (!avc)
74389 goto out_enomem;
74390
74391 +#ifdef CONFIG_PAX_SEGMEXEC
74392 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74393 + if (!avc_m)
74394 + goto out_enomem_free_avc;
74395 +#endif
74396 +
74397 anon_vma = find_mergeable_anon_vma(vma);
74398 allocated = NULL;
74399 if (!anon_vma) {
74400 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74401 /* page_table_lock to protect against threads */
74402 spin_lock(&mm->page_table_lock);
74403 if (likely(!vma->anon_vma)) {
74404 +
74405 +#ifdef CONFIG_PAX_SEGMEXEC
74406 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74407 +
74408 + if (vma_m) {
74409 + BUG_ON(vma_m->anon_vma);
74410 + vma_m->anon_vma = anon_vma;
74411 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74412 + avc_m = NULL;
74413 + }
74414 +#endif
74415 +
74416 vma->anon_vma = anon_vma;
74417 anon_vma_chain_link(vma, avc, anon_vma);
74418 allocated = NULL;
74419 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74420
74421 if (unlikely(allocated))
74422 put_anon_vma(allocated);
74423 +
74424 +#ifdef CONFIG_PAX_SEGMEXEC
74425 + if (unlikely(avc_m))
74426 + anon_vma_chain_free(avc_m);
74427 +#endif
74428 +
74429 if (unlikely(avc))
74430 anon_vma_chain_free(avc);
74431 }
74432 return 0;
74433
74434 out_enomem_free_avc:
74435 +
74436 +#ifdef CONFIG_PAX_SEGMEXEC
74437 + if (avc_m)
74438 + anon_vma_chain_free(avc_m);
74439 +#endif
74440 +
74441 anon_vma_chain_free(avc);
74442 out_enomem:
74443 return -ENOMEM;
74444 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74445 * Attach the anon_vmas from src to dst.
74446 * Returns 0 on success, -ENOMEM on failure.
74447 */
74448 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74449 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74450 {
74451 struct anon_vma_chain *avc, *pavc;
74452 struct anon_vma *root = NULL;
74453 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74454 * the corresponding VMA in the parent process is attached to.
74455 * Returns 0 on success, non-zero on failure.
74456 */
74457 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74458 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74459 {
74460 struct anon_vma_chain *avc;
74461 struct anon_vma *anon_vma;
74462 diff --git a/mm/shmem.c b/mm/shmem.c
74463 index d2eeca1..3f160be 100644
74464 --- a/mm/shmem.c
74465 +++ b/mm/shmem.c
74466 @@ -31,7 +31,7 @@
74467 #include <linux/export.h>
74468 #include <linux/swap.h>
74469
74470 -static struct vfsmount *shm_mnt;
74471 +struct vfsmount *shm_mnt;
74472
74473 #ifdef CONFIG_SHMEM
74474 /*
74475 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74476 #define BOGO_DIRENT_SIZE 20
74477
74478 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74479 -#define SHORT_SYMLINK_LEN 128
74480 +#define SHORT_SYMLINK_LEN 64
74481
74482 struct shmem_xattr {
74483 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74484 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74485 int err = -ENOMEM;
74486
74487 /* Round up to L1_CACHE_BYTES to resist false sharing */
74488 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74489 - L1_CACHE_BYTES), GFP_KERNEL);
74490 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74491 if (!sbinfo)
74492 return -ENOMEM;
74493
74494 diff --git a/mm/slab.c b/mm/slab.c
74495 index d066037..5bb78d9 100644
74496 --- a/mm/slab.c
74497 +++ b/mm/slab.c
74498 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74499
74500 /* Legal flag mask for kmem_cache_create(). */
74501 #if DEBUG
74502 -# define CREATE_MASK (SLAB_RED_ZONE | \
74503 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74504 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74505 SLAB_CACHE_DMA | \
74506 SLAB_STORE_USER | \
74507 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74508 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74509 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74510 #else
74511 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74512 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74513 SLAB_CACHE_DMA | \
74514 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74515 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74516 @@ -322,7 +322,7 @@ struct kmem_list3 {
74517 * Need this for bootstrapping a per node allocator.
74518 */
74519 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74520 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74521 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74522 #define CACHE_CACHE 0
74523 #define SIZE_AC MAX_NUMNODES
74524 #define SIZE_L3 (2 * MAX_NUMNODES)
74525 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74526 if ((x)->max_freeable < i) \
74527 (x)->max_freeable = i; \
74528 } while (0)
74529 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74530 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74531 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74532 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74533 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74534 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74535 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74536 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74537 #else
74538 #define STATS_INC_ACTIVE(x) do { } while (0)
74539 #define STATS_DEC_ACTIVE(x) do { } while (0)
74540 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74541 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74542 */
74543 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74544 - const struct slab *slab, void *obj)
74545 + const struct slab *slab, const void *obj)
74546 {
74547 u32 offset = (obj - slab->s_mem);
74548 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74549 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74550 struct cache_names {
74551 char *name;
74552 char *name_dma;
74553 + char *name_usercopy;
74554 };
74555
74556 static struct cache_names __initdata cache_names[] = {
74557 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74558 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74559 #include <linux/kmalloc_sizes.h>
74560 - {NULL,}
74561 + {NULL}
74562 #undef CACHE
74563 };
74564
74565 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74566 if (unlikely(gfpflags & GFP_DMA))
74567 return csizep->cs_dmacachep;
74568 #endif
74569 +
74570 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74571 + if (unlikely(gfpflags & GFP_USERCOPY))
74572 + return csizep->cs_usercopycachep;
74573 +#endif
74574 +
74575 return csizep->cs_cachep;
74576 }
74577
74578 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74579 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74580 sizes[INDEX_AC].cs_size,
74581 ARCH_KMALLOC_MINALIGN,
74582 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74583 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74584 NULL);
74585
74586 if (INDEX_AC != INDEX_L3) {
74587 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74588 __kmem_cache_create(names[INDEX_L3].name,
74589 sizes[INDEX_L3].cs_size,
74590 ARCH_KMALLOC_MINALIGN,
74591 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74592 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74593 NULL);
74594 }
74595
74596 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74597 sizes->cs_cachep = __kmem_cache_create(names->name,
74598 sizes->cs_size,
74599 ARCH_KMALLOC_MINALIGN,
74600 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74601 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74602 NULL);
74603 }
74604 #ifdef CONFIG_ZONE_DMA
74605 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74606 SLAB_PANIC,
74607 NULL);
74608 #endif
74609 +
74610 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74611 + sizes->cs_usercopycachep = kmem_cache_create(
74612 + names->name_usercopy,
74613 + sizes->cs_size,
74614 + ARCH_KMALLOC_MINALIGN,
74615 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74616 + NULL);
74617 +#endif
74618 +
74619 sizes++;
74620 names++;
74621 }
74622 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74623 }
74624 /* cpu stats */
74625 {
74626 - unsigned long allochit = atomic_read(&cachep->allochit);
74627 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74628 - unsigned long freehit = atomic_read(&cachep->freehit);
74629 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74630 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74631 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74632 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74633 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74634
74635 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74636 allochit, allocmiss, freehit, freemiss);
74637 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74638 {
74639 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74640 #ifdef CONFIG_DEBUG_SLAB_LEAK
74641 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74642 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74643 #endif
74644 return 0;
74645 }
74646 module_init(slab_proc_init);
74647 #endif
74648
74649 +bool is_usercopy_object(const void *ptr)
74650 +{
74651 + struct page *page;
74652 + struct kmem_cache *cachep;
74653 +
74654 + if (ZERO_OR_NULL_PTR(ptr))
74655 + return false;
74656 +
74657 + if (!slab_is_available())
74658 + return false;
74659 +
74660 + if (!virt_addr_valid(ptr))
74661 + return false;
74662 +
74663 + page = virt_to_head_page(ptr);
74664 +
74665 + if (!PageSlab(page))
74666 + return false;
74667 +
74668 + cachep = page_get_cache(page);
74669 + return cachep->flags & SLAB_USERCOPY;
74670 +}
74671 +
74672 +#ifdef CONFIG_PAX_USERCOPY
74673 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74674 +{
74675 + struct page *page;
74676 + struct kmem_cache *cachep;
74677 + struct slab *slabp;
74678 + unsigned int objnr;
74679 + unsigned long offset;
74680 +
74681 + if (ZERO_OR_NULL_PTR(ptr))
74682 + return "<null>";
74683 +
74684 + if (!virt_addr_valid(ptr))
74685 + return NULL;
74686 +
74687 + page = virt_to_head_page(ptr);
74688 +
74689 + if (!PageSlab(page))
74690 + return NULL;
74691 +
74692 + cachep = page_get_cache(page);
74693 + if (!(cachep->flags & SLAB_USERCOPY))
74694 + return cachep->name;
74695 +
74696 + slabp = page->slab_page;
74697 + objnr = obj_to_index(cachep, slabp, ptr);
74698 + BUG_ON(objnr >= cachep->num);
74699 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74700 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74701 + return NULL;
74702 +
74703 + return cachep->name;
74704 +}
74705 +#endif
74706 +
74707 /**
74708 * ksize - get the actual amount of memory allocated for a given object
74709 * @objp: Pointer to the object
74710 diff --git a/mm/slob.c b/mm/slob.c
74711 index 45d4ca7..88943c1 100644
74712 --- a/mm/slob.c
74713 +++ b/mm/slob.c
74714 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74715 /*
74716 * Return the size of a slob block.
74717 */
74718 -static slobidx_t slob_units(slob_t *s)
74719 +static slobidx_t slob_units(const slob_t *s)
74720 {
74721 if (s->units > 0)
74722 return s->units;
74723 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74724 /*
74725 * Return the next free slob block pointer after this one.
74726 */
74727 -static slob_t *slob_next(slob_t *s)
74728 +static slob_t *slob_next(const slob_t *s)
74729 {
74730 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74731 slobidx_t next;
74732 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74733 /*
74734 * Returns true if s is the last free block in its page.
74735 */
74736 -static int slob_last(slob_t *s)
74737 +static int slob_last(const slob_t *s)
74738 {
74739 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74740 }
74741
74742 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74743 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74744 {
74745 - void *page;
74746 + struct page *page;
74747
74748 #ifdef CONFIG_NUMA
74749 if (node != -1)
74750 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74751 if (!page)
74752 return NULL;
74753
74754 - return page_address(page);
74755 + __SetPageSlab(page);
74756 + return page;
74757 }
74758
74759 -static void slob_free_pages(void *b, int order)
74760 +static void slob_free_pages(struct page *sp, int order)
74761 {
74762 if (current->reclaim_state)
74763 current->reclaim_state->reclaimed_slab += 1 << order;
74764 - free_pages((unsigned long)b, order);
74765 + __ClearPageSlab(sp);
74766 + reset_page_mapcount(sp);
74767 + sp->private = 0;
74768 + __free_pages(sp, order);
74769 }
74770
74771 /*
74772 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74773
74774 /* Not enough space: must allocate a new page */
74775 if (!b) {
74776 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74777 - if (!b)
74778 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74779 + if (!sp)
74780 return NULL;
74781 - sp = virt_to_page(b);
74782 - __SetPageSlab(sp);
74783 + b = page_address(sp);
74784
74785 spin_lock_irqsave(&slob_lock, flags);
74786 sp->units = SLOB_UNITS(PAGE_SIZE);
74787 sp->freelist = b;
74788 + sp->private = 0;
74789 INIT_LIST_HEAD(&sp->list);
74790 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74791 set_slob_page_free(sp, slob_list);
74792 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74793 if (slob_page_free(sp))
74794 clear_slob_page_free(sp);
74795 spin_unlock_irqrestore(&slob_lock, flags);
74796 - __ClearPageSlab(sp);
74797 - reset_page_mapcount(sp);
74798 - slob_free_pages(b, 0);
74799 + slob_free_pages(sp, 0);
74800 return;
74801 }
74802
74803 @@ -425,11 +427,10 @@ out:
74804 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74805 */
74806
74807 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74808 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74809 {
74810 - unsigned int *m;
74811 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74812 - void *ret;
74813 + slob_t *m;
74814 + void *ret = NULL;
74815
74816 gfp &= gfp_allowed_mask;
74817
74818 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74819
74820 if (!m)
74821 return NULL;
74822 - *m = size;
74823 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74824 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74825 + m[0].units = size;
74826 + m[1].units = align;
74827 ret = (void *)m + align;
74828
74829 trace_kmalloc_node(_RET_IP_, ret,
74830 size, size + align, gfp, node);
74831 } else {
74832 unsigned int order = get_order(size);
74833 + struct page *page;
74834
74835 if (likely(order))
74836 gfp |= __GFP_COMP;
74837 - ret = slob_new_pages(gfp, order, node);
74838 - if (ret) {
74839 - struct page *page;
74840 - page = virt_to_page(ret);
74841 + page = slob_new_pages(gfp, order, node);
74842 + if (page) {
74843 + ret = page_address(page);
74844 page->private = size;
74845 }
74846
74847 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74848 size, PAGE_SIZE << order, gfp, node);
74849 }
74850
74851 - kmemleak_alloc(ret, size, 1, gfp);
74852 + return ret;
74853 +}
74854 +
74855 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74856 +{
74857 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74858 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74859 +
74860 + if (!ZERO_OR_NULL_PTR(ret))
74861 + kmemleak_alloc(ret, size, 1, gfp);
74862 return ret;
74863 }
74864 EXPORT_SYMBOL(__kmalloc_node);
74865 @@ -480,15 +493,91 @@ void kfree(const void *block)
74866 kmemleak_free(block);
74867
74868 sp = virt_to_page(block);
74869 - if (PageSlab(sp)) {
74870 + VM_BUG_ON(!PageSlab(sp));
74871 + if (!sp->private) {
74872 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74873 - unsigned int *m = (unsigned int *)(block - align);
74874 - slob_free(m, *m + align);
74875 - } else
74876 + slob_t *m = (slob_t *)(block - align);
74877 + slob_free(m, m[0].units + align);
74878 + } else {
74879 + __ClearPageSlab(sp);
74880 + reset_page_mapcount(sp);
74881 + sp->private = 0;
74882 put_page(sp);
74883 + }
74884 }
74885 EXPORT_SYMBOL(kfree);
74886
74887 +bool is_usercopy_object(const void *ptr)
74888 +{
74889 + if (!slab_is_available())
74890 + return false;
74891 +
74892 + // PAX: TODO
74893 +
74894 + return false;
74895 +}
74896 +
74897 +#ifdef CONFIG_PAX_USERCOPY
74898 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74899 +{
74900 + struct page *page;
74901 + const slob_t *free;
74902 + const void *base;
74903 + unsigned long flags;
74904 +
74905 + if (ZERO_OR_NULL_PTR(ptr))
74906 + return "<null>";
74907 +
74908 + if (!virt_addr_valid(ptr))
74909 + return NULL;
74910 +
74911 + page = virt_to_head_page(ptr);
74912 + if (!PageSlab(page))
74913 + return NULL;
74914 +
74915 + if (page->private) {
74916 + base = page;
74917 + if (base <= ptr && n <= page->private - (ptr - base))
74918 + return NULL;
74919 + return "<slob>";
74920 + }
74921 +
74922 + /* some tricky double walking to find the chunk */
74923 + spin_lock_irqsave(&slob_lock, flags);
74924 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74925 + free = page->freelist;
74926 +
74927 + while (!slob_last(free) && (void *)free <= ptr) {
74928 + base = free + slob_units(free);
74929 + free = slob_next(free);
74930 + }
74931 +
74932 + while (base < (void *)free) {
74933 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74934 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74935 + int offset;
74936 +
74937 + if (ptr < base + align)
74938 + break;
74939 +
74940 + offset = ptr - base - align;
74941 + if (offset >= m) {
74942 + base += size;
74943 + continue;
74944 + }
74945 +
74946 + if (n > m - offset)
74947 + break;
74948 +
74949 + spin_unlock_irqrestore(&slob_lock, flags);
74950 + return NULL;
74951 + }
74952 +
74953 + spin_unlock_irqrestore(&slob_lock, flags);
74954 + return "<slob>";
74955 +}
74956 +#endif
74957 +
74958 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74959 size_t ksize(const void *block)
74960 {
74961 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
74962 return 0;
74963
74964 sp = virt_to_page(block);
74965 - if (PageSlab(sp)) {
74966 + VM_BUG_ON(!PageSlab(sp));
74967 + if (!sp->private) {
74968 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74969 - unsigned int *m = (unsigned int *)(block - align);
74970 - return SLOB_UNITS(*m) * SLOB_UNIT;
74971 + slob_t *m = (slob_t *)(block - align);
74972 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74973 } else
74974 return sp->private;
74975 }
74976 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74977 {
74978 struct kmem_cache *c;
74979
74980 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74981 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74982 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74983 +#else
74984 c = slob_alloc(sizeof(struct kmem_cache),
74985 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74986 +#endif
74987
74988 if (c) {
74989 c->name = name;
74990 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74991
74992 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74993 {
74994 - void *b;
74995 + void *b = NULL;
74996
74997 flags &= gfp_allowed_mask;
74998
74999 lockdep_trace_alloc(flags);
75000
75001 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75002 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75003 +#else
75004 if (c->size < PAGE_SIZE) {
75005 b = slob_alloc(c->size, flags, c->align, node);
75006 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75007 SLOB_UNITS(c->size) * SLOB_UNIT,
75008 flags, node);
75009 } else {
75010 - b = slob_new_pages(flags, get_order(c->size), node);
75011 + struct page *sp;
75012 +
75013 + sp = slob_new_pages(flags, get_order(c->size), node);
75014 + if (sp) {
75015 + b = page_address(sp);
75016 + sp->private = c->size;
75017 + }
75018 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75019 PAGE_SIZE << get_order(c->size),
75020 flags, node);
75021 }
75022 +#endif
75023
75024 if (c->ctor)
75025 c->ctor(b);
75026 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75027
75028 static void __kmem_cache_free(void *b, int size)
75029 {
75030 - if (size < PAGE_SIZE)
75031 + struct page *sp;
75032 +
75033 + sp = virt_to_page(b);
75034 + BUG_ON(!PageSlab(sp));
75035 + if (!sp->private)
75036 slob_free(b, size);
75037 else
75038 - slob_free_pages(b, get_order(size));
75039 + slob_free_pages(sp, get_order(size));
75040 }
75041
75042 static void kmem_rcu_free(struct rcu_head *head)
75043 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75044
75045 void kmem_cache_free(struct kmem_cache *c, void *b)
75046 {
75047 + int size = c->size;
75048 +
75049 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75050 + if (size + c->align < PAGE_SIZE) {
75051 + size += c->align;
75052 + b -= c->align;
75053 + }
75054 +#endif
75055 +
75056 kmemleak_free_recursive(b, c->flags);
75057 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75058 struct slob_rcu *slob_rcu;
75059 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75060 - slob_rcu->size = c->size;
75061 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75062 + slob_rcu->size = size;
75063 call_rcu(&slob_rcu->head, kmem_rcu_free);
75064 } else {
75065 - __kmem_cache_free(b, c->size);
75066 + __kmem_cache_free(b, size);
75067 }
75068
75069 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75070 + trace_kfree(_RET_IP_, b);
75071 +#else
75072 trace_kmem_cache_free(_RET_IP_, b);
75073 +#endif
75074 +
75075 }
75076 EXPORT_SYMBOL(kmem_cache_free);
75077
75078 diff --git a/mm/slub.c b/mm/slub.c
75079 index 2fdd96f..1e2f893 100644
75080 --- a/mm/slub.c
75081 +++ b/mm/slub.c
75082 @@ -201,7 +201,7 @@ struct track {
75083
75084 enum track_item { TRACK_ALLOC, TRACK_FREE };
75085
75086 -#ifdef CONFIG_SYSFS
75087 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75088 static int sysfs_slab_add(struct kmem_cache *);
75089 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75090 static void sysfs_slab_remove(struct kmem_cache *);
75091 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75092 if (!t->addr)
75093 return;
75094
75095 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75096 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75097 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75098 #ifdef CONFIG_STACKTRACE
75099 {
75100 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75101
75102 page = virt_to_head_page(x);
75103
75104 + BUG_ON(!PageSlab(page));
75105 +
75106 slab_free(s, page, x, _RET_IP_);
75107
75108 trace_kmem_cache_free(_RET_IP_, x);
75109 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75110 * Merge control. If this is set then no merging of slab caches will occur.
75111 * (Could be removed. This was introduced to pacify the merge skeptics.)
75112 */
75113 -static int slub_nomerge;
75114 +static int slub_nomerge = 1;
75115
75116 /*
75117 * Calculate the order of allocation given an slab object size.
75118 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75119 else
75120 s->cpu_partial = 30;
75121
75122 - s->refcount = 1;
75123 + atomic_set(&s->refcount, 1);
75124 #ifdef CONFIG_NUMA
75125 s->remote_node_defrag_ratio = 1000;
75126 #endif
75127 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75128 void kmem_cache_destroy(struct kmem_cache *s)
75129 {
75130 mutex_lock(&slab_mutex);
75131 - s->refcount--;
75132 - if (!s->refcount) {
75133 + if (atomic_dec_and_test(&s->refcount)) {
75134 list_del(&s->list);
75135 mutex_unlock(&slab_mutex);
75136 if (kmem_cache_close(s)) {
75137 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75138 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75139 #endif
75140
75141 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75142 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75143 +#endif
75144 +
75145 static int __init setup_slub_min_order(char *str)
75146 {
75147 get_option(&str, &slub_min_order);
75148 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75149 return kmalloc_dma_caches[index];
75150
75151 #endif
75152 +
75153 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75154 + if (flags & SLAB_USERCOPY)
75155 + return kmalloc_usercopy_caches[index];
75156 +
75157 +#endif
75158 +
75159 return kmalloc_caches[index];
75160 }
75161
75162 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75163 EXPORT_SYMBOL(__kmalloc_node);
75164 #endif
75165
75166 +bool is_usercopy_object(const void *ptr)
75167 +{
75168 + struct page *page;
75169 + struct kmem_cache *s;
75170 +
75171 + if (ZERO_OR_NULL_PTR(ptr))
75172 + return false;
75173 +
75174 + if (!slab_is_available())
75175 + return false;
75176 +
75177 + if (!virt_addr_valid(ptr))
75178 + return false;
75179 +
75180 + page = virt_to_head_page(ptr);
75181 +
75182 + if (!PageSlab(page))
75183 + return false;
75184 +
75185 + s = page->slab;
75186 + return s->flags & SLAB_USERCOPY;
75187 +}
75188 +
75189 +#ifdef CONFIG_PAX_USERCOPY
75190 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75191 +{
75192 + struct page *page;
75193 + struct kmem_cache *s;
75194 + unsigned long offset;
75195 +
75196 + if (ZERO_OR_NULL_PTR(ptr))
75197 + return "<null>";
75198 +
75199 + if (!virt_addr_valid(ptr))
75200 + return NULL;
75201 +
75202 + page = virt_to_head_page(ptr);
75203 +
75204 + if (!PageSlab(page))
75205 + return NULL;
75206 +
75207 + s = page->slab;
75208 + if (!(s->flags & SLAB_USERCOPY))
75209 + return s->name;
75210 +
75211 + offset = (ptr - page_address(page)) % s->size;
75212 + if (offset <= s->object_size && n <= s->object_size - offset)
75213 + return NULL;
75214 +
75215 + return s->name;
75216 +}
75217 +#endif
75218 +
75219 size_t ksize(const void *object)
75220 {
75221 struct page *page;
75222 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75223 int node;
75224
75225 list_add(&s->list, &slab_caches);
75226 - s->refcount = -1;
75227 + atomic_set(&s->refcount, -1);
75228
75229 for_each_node_state(node, N_NORMAL_MEMORY) {
75230 struct kmem_cache_node *n = get_node(s, node);
75231 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75232
75233 /* Caches that are not of the two-to-the-power-of size */
75234 if (KMALLOC_MIN_SIZE <= 32) {
75235 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75236 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75237 caches++;
75238 }
75239
75240 if (KMALLOC_MIN_SIZE <= 64) {
75241 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75242 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75243 caches++;
75244 }
75245
75246 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75247 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75248 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75249 caches++;
75250 }
75251
75252 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75253 }
75254 }
75255 #endif
75256 +
75257 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75258 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75259 + struct kmem_cache *s = kmalloc_caches[i];
75260 +
75261 + if (s && s->size) {
75262 + char *name = kasprintf(GFP_NOWAIT,
75263 + "usercopy-kmalloc-%d", s->object_size);
75264 +
75265 + BUG_ON(!name);
75266 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75267 + s->object_size, SLAB_USERCOPY);
75268 + }
75269 + }
75270 +#endif
75271 +
75272 printk(KERN_INFO
75273 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75274 " CPUs=%d, Nodes=%d\n",
75275 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75276 /*
75277 * We may have set a slab to be unmergeable during bootstrap.
75278 */
75279 - if (s->refcount < 0)
75280 + if (atomic_read(&s->refcount) < 0)
75281 return 1;
75282
75283 return 0;
75284 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75285
75286 s = find_mergeable(size, align, flags, name, ctor);
75287 if (s) {
75288 - s->refcount++;
75289 + atomic_inc(&s->refcount);
75290 /*
75291 * Adjust the object sizes so that we clear
75292 * the complete object on kzalloc.
75293 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75294 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75295
75296 if (sysfs_slab_alias(s, name)) {
75297 - s->refcount--;
75298 + atomic_dec(&s->refcount);
75299 return NULL;
75300 }
75301 return s;
75302 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75303 }
75304 #endif
75305
75306 -#ifdef CONFIG_SYSFS
75307 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75308 static int count_inuse(struct page *page)
75309 {
75310 return page->inuse;
75311 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75312 validate_slab_cache(kmalloc_caches[9]);
75313 }
75314 #else
75315 -#ifdef CONFIG_SYSFS
75316 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75317 static void resiliency_test(void) {};
75318 #endif
75319 #endif
75320
75321 -#ifdef CONFIG_SYSFS
75322 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75323 enum slab_stat_type {
75324 SL_ALL, /* All slabs */
75325 SL_PARTIAL, /* Only partially allocated slabs */
75326 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75327
75328 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75329 {
75330 - return sprintf(buf, "%d\n", s->refcount - 1);
75331 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75332 }
75333 SLAB_ATTR_RO(aliases);
75334
75335 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75336 return name;
75337 }
75338
75339 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75340 static int sysfs_slab_add(struct kmem_cache *s)
75341 {
75342 int err;
75343 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75344 kobject_del(&s->kobj);
75345 kobject_put(&s->kobj);
75346 }
75347 +#endif
75348
75349 /*
75350 * Need to buffer aliases during bootup until sysfs becomes
75351 @@ -5354,6 +5437,7 @@ struct saved_alias {
75352
75353 static struct saved_alias *alias_list;
75354
75355 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75356 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75357 {
75358 struct saved_alias *al;
75359 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75360 alias_list = al;
75361 return 0;
75362 }
75363 +#endif
75364
75365 static int __init slab_sysfs_init(void)
75366 {
75367 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75368 index 1b7e22a..3fcd4f3 100644
75369 --- a/mm/sparse-vmemmap.c
75370 +++ b/mm/sparse-vmemmap.c
75371 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75372 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75373 if (!p)
75374 return NULL;
75375 - pud_populate(&init_mm, pud, p);
75376 + pud_populate_kernel(&init_mm, pud, p);
75377 }
75378 return pud;
75379 }
75380 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75381 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75382 if (!p)
75383 return NULL;
75384 - pgd_populate(&init_mm, pgd, p);
75385 + pgd_populate_kernel(&init_mm, pgd, p);
75386 }
75387 return pgd;
75388 }
75389 diff --git a/mm/swap.c b/mm/swap.c
75390 index 7782588..228c784 100644
75391 --- a/mm/swap.c
75392 +++ b/mm/swap.c
75393 @@ -30,6 +30,7 @@
75394 #include <linux/backing-dev.h>
75395 #include <linux/memcontrol.h>
75396 #include <linux/gfp.h>
75397 +#include <linux/hugetlb.h>
75398
75399 #include "internal.h"
75400
75401 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75402
75403 __page_cache_release(page);
75404 dtor = get_compound_page_dtor(page);
75405 + if (!PageHuge(page))
75406 + BUG_ON(dtor != free_compound_page);
75407 (*dtor)(page);
75408 }
75409
75410 diff --git a/mm/swapfile.c b/mm/swapfile.c
75411 index 14e254c..a6af32c 100644
75412 --- a/mm/swapfile.c
75413 +++ b/mm/swapfile.c
75414 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75415
75416 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75417 /* Activity counter to indicate that a swapon or swapoff has occurred */
75418 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75419 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75420
75421 static inline unsigned char swap_count(unsigned char ent)
75422 {
75423 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75424 }
75425 filp_close(swap_file, NULL);
75426 err = 0;
75427 - atomic_inc(&proc_poll_event);
75428 + atomic_inc_unchecked(&proc_poll_event);
75429 wake_up_interruptible(&proc_poll_wait);
75430
75431 out_dput:
75432 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75433
75434 poll_wait(file, &proc_poll_wait, wait);
75435
75436 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75437 - seq->poll_event = atomic_read(&proc_poll_event);
75438 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75439 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75440 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75441 }
75442
75443 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75444 return ret;
75445
75446 seq = file->private_data;
75447 - seq->poll_event = atomic_read(&proc_poll_event);
75448 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75449 return 0;
75450 }
75451
75452 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75453 (frontswap_map) ? "FS" : "");
75454
75455 mutex_unlock(&swapon_mutex);
75456 - atomic_inc(&proc_poll_event);
75457 + atomic_inc_unchecked(&proc_poll_event);
75458 wake_up_interruptible(&proc_poll_wait);
75459
75460 if (S_ISREG(inode->i_mode))
75461 diff --git a/mm/util.c b/mm/util.c
75462 index 8c7265a..c96d884 100644
75463 --- a/mm/util.c
75464 +++ b/mm/util.c
75465 @@ -285,6 +285,12 @@ done:
75466 void arch_pick_mmap_layout(struct mm_struct *mm)
75467 {
75468 mm->mmap_base = TASK_UNMAPPED_BASE;
75469 +
75470 +#ifdef CONFIG_PAX_RANDMMAP
75471 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75472 + mm->mmap_base += mm->delta_mmap;
75473 +#endif
75474 +
75475 mm->get_unmapped_area = arch_get_unmapped_area;
75476 mm->unmap_area = arch_unmap_area;
75477 }
75478 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75479 index 2bb90b1..ed47e53 100644
75480 --- a/mm/vmalloc.c
75481 +++ b/mm/vmalloc.c
75482 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75483
75484 pte = pte_offset_kernel(pmd, addr);
75485 do {
75486 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75487 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75488 +
75489 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75490 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75491 + BUG_ON(!pte_exec(*pte));
75492 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75493 + continue;
75494 + }
75495 +#endif
75496 +
75497 + {
75498 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75499 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75500 + }
75501 } while (pte++, addr += PAGE_SIZE, addr != end);
75502 }
75503
75504 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75505 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75506 {
75507 pte_t *pte;
75508 + int ret = -ENOMEM;
75509
75510 /*
75511 * nr is a running index into the array which helps higher level
75512 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75513 pte = pte_alloc_kernel(pmd, addr);
75514 if (!pte)
75515 return -ENOMEM;
75516 +
75517 + pax_open_kernel();
75518 do {
75519 struct page *page = pages[*nr];
75520
75521 - if (WARN_ON(!pte_none(*pte)))
75522 - return -EBUSY;
75523 - if (WARN_ON(!page))
75524 - return -ENOMEM;
75525 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75526 + if (pgprot_val(prot) & _PAGE_NX)
75527 +#endif
75528 +
75529 + if (WARN_ON(!pte_none(*pte))) {
75530 + ret = -EBUSY;
75531 + goto out;
75532 + }
75533 + if (WARN_ON(!page)) {
75534 + ret = -ENOMEM;
75535 + goto out;
75536 + }
75537 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75538 (*nr)++;
75539 } while (pte++, addr += PAGE_SIZE, addr != end);
75540 - return 0;
75541 + ret = 0;
75542 +out:
75543 + pax_close_kernel();
75544 + return ret;
75545 }
75546
75547 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75548 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75549 pmd_t *pmd;
75550 unsigned long next;
75551
75552 - pmd = pmd_alloc(&init_mm, pud, addr);
75553 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75554 if (!pmd)
75555 return -ENOMEM;
75556 do {
75557 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75558 pud_t *pud;
75559 unsigned long next;
75560
75561 - pud = pud_alloc(&init_mm, pgd, addr);
75562 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75563 if (!pud)
75564 return -ENOMEM;
75565 do {
75566 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75567 * and fall back on vmalloc() if that fails. Others
75568 * just put it in the vmalloc space.
75569 */
75570 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75571 +#ifdef CONFIG_MODULES
75572 +#ifdef MODULES_VADDR
75573 unsigned long addr = (unsigned long)x;
75574 if (addr >= MODULES_VADDR && addr < MODULES_END)
75575 return 1;
75576 #endif
75577 +
75578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75579 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75580 + return 1;
75581 +#endif
75582 +
75583 +#endif
75584 +
75585 return is_vmalloc_addr(x);
75586 }
75587
75588 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75589
75590 if (!pgd_none(*pgd)) {
75591 pud_t *pud = pud_offset(pgd, addr);
75592 +#ifdef CONFIG_X86
75593 + if (!pud_large(*pud))
75594 +#endif
75595 if (!pud_none(*pud)) {
75596 pmd_t *pmd = pmd_offset(pud, addr);
75597 +#ifdef CONFIG_X86
75598 + if (!pmd_large(*pmd))
75599 +#endif
75600 if (!pmd_none(*pmd)) {
75601 pte_t *ptep, pte;
75602
75603 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75604 * Allocate a region of KVA of the specified size and alignment, within the
75605 * vstart and vend.
75606 */
75607 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75608 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75609 unsigned long align,
75610 unsigned long vstart, unsigned long vend,
75611 int node, gfp_t gfp_mask)
75612 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75613 struct vm_struct *area;
75614
75615 BUG_ON(in_interrupt());
75616 +
75617 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75618 + if (flags & VM_KERNEXEC) {
75619 + if (start != VMALLOC_START || end != VMALLOC_END)
75620 + return NULL;
75621 + start = (unsigned long)MODULES_EXEC_VADDR;
75622 + end = (unsigned long)MODULES_EXEC_END;
75623 + }
75624 +#endif
75625 +
75626 if (flags & VM_IOREMAP) {
75627 int bit = fls(size);
75628
75629 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75630 if (count > totalram_pages)
75631 return NULL;
75632
75633 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75634 + if (!(pgprot_val(prot) & _PAGE_NX))
75635 + flags |= VM_KERNEXEC;
75636 +#endif
75637 +
75638 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75639 __builtin_return_address(0));
75640 if (!area)
75641 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75642 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75643 goto fail;
75644
75645 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75646 + if (!(pgprot_val(prot) & _PAGE_NX))
75647 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75648 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75649 + else
75650 +#endif
75651 +
75652 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75653 start, end, node, gfp_mask, caller);
75654 if (!area)
75655 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75656 * For tight control over page level allocator and protection flags
75657 * use __vmalloc() instead.
75658 */
75659 -
75660 void *vmalloc_exec(unsigned long size)
75661 {
75662 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75663 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75664 -1, __builtin_return_address(0));
75665 }
75666
75667 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75668 unsigned long uaddr = vma->vm_start;
75669 unsigned long usize = vma->vm_end - vma->vm_start;
75670
75671 + BUG_ON(vma->vm_mirror);
75672 +
75673 if ((PAGE_SIZE-1) & (unsigned long)addr)
75674 return -EINVAL;
75675
75676 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75677 {
75678 struct vm_struct *v = p;
75679
75680 - seq_printf(m, "0x%p-0x%p %7ld",
75681 + seq_printf(m, "0x%pK-0x%pK %7ld",
75682 v->addr, v->addr + v->size, v->size);
75683
75684 if (v->caller)
75685 diff --git a/mm/vmstat.c b/mm/vmstat.c
75686 index df7a674..8b4a4f3 100644
75687 --- a/mm/vmstat.c
75688 +++ b/mm/vmstat.c
75689 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75690 *
75691 * vm_stat contains the global counters
75692 */
75693 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75694 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75695 EXPORT_SYMBOL(vm_stat);
75696
75697 #ifdef CONFIG_SMP
75698 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75699 v = p->vm_stat_diff[i];
75700 p->vm_stat_diff[i] = 0;
75701 local_irq_restore(flags);
75702 - atomic_long_add(v, &zone->vm_stat[i]);
75703 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75704 global_diff[i] += v;
75705 #ifdef CONFIG_NUMA
75706 /* 3 seconds idle till flush */
75707 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75708
75709 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75710 if (global_diff[i])
75711 - atomic_long_add(global_diff[i], &vm_stat[i]);
75712 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75713 }
75714
75715 #endif
75716 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75717 start_cpu_timer(cpu);
75718 #endif
75719 #ifdef CONFIG_PROC_FS
75720 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75721 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75722 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75723 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75724 + {
75725 + mode_t gr_mode = S_IRUGO;
75726 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75727 + gr_mode = S_IRUSR;
75728 +#endif
75729 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75730 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75731 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75732 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75733 +#else
75734 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75735 +#endif
75736 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75737 + }
75738 #endif
75739 return 0;
75740 }
75741 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75742 index 9096bcb..43ed7bb 100644
75743 --- a/net/8021q/vlan.c
75744 +++ b/net/8021q/vlan.c
75745 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75746 err = -EPERM;
75747 if (!capable(CAP_NET_ADMIN))
75748 break;
75749 - if ((args.u.name_type >= 0) &&
75750 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75751 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75752 struct vlan_net *vn;
75753
75754 vn = net_generic(net, vlan_net_id);
75755 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75756 index 6449bae..8c1f454 100644
75757 --- a/net/9p/trans_fd.c
75758 +++ b/net/9p/trans_fd.c
75759 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75760 oldfs = get_fs();
75761 set_fs(get_ds());
75762 /* The cast to a user pointer is valid due to the set_fs() */
75763 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75764 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75765 set_fs(oldfs);
75766
75767 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75768 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75769 index 876fbe8..8bbea9f 100644
75770 --- a/net/atm/atm_misc.c
75771 +++ b/net/atm/atm_misc.c
75772 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75773 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75774 return 1;
75775 atm_return(vcc, truesize);
75776 - atomic_inc(&vcc->stats->rx_drop);
75777 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75778 return 0;
75779 }
75780 EXPORT_SYMBOL(atm_charge);
75781 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75782 }
75783 }
75784 atm_return(vcc, guess);
75785 - atomic_inc(&vcc->stats->rx_drop);
75786 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75787 return NULL;
75788 }
75789 EXPORT_SYMBOL(atm_alloc_charge);
75790 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75791
75792 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75793 {
75794 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75795 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75796 __SONET_ITEMS
75797 #undef __HANDLE_ITEM
75798 }
75799 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75800
75801 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75802 {
75803 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75804 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75805 __SONET_ITEMS
75806 #undef __HANDLE_ITEM
75807 }
75808 diff --git a/net/atm/lec.h b/net/atm/lec.h
75809 index a86aff9..3a0d6f6 100644
75810 --- a/net/atm/lec.h
75811 +++ b/net/atm/lec.h
75812 @@ -48,7 +48,7 @@ struct lane2_ops {
75813 const u8 *tlvs, u32 sizeoftlvs);
75814 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75815 const u8 *tlvs, u32 sizeoftlvs);
75816 -};
75817 +} __no_const;
75818
75819 /*
75820 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75821 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75822 index 0919a88..a23d54e 100644
75823 --- a/net/atm/mpc.h
75824 +++ b/net/atm/mpc.h
75825 @@ -33,7 +33,7 @@ struct mpoa_client {
75826 struct mpc_parameters parameters; /* parameters for this client */
75827
75828 const struct net_device_ops *old_ops;
75829 - struct net_device_ops new_ops;
75830 + net_device_ops_no_const new_ops;
75831 };
75832
75833
75834 diff --git a/net/atm/proc.c b/net/atm/proc.c
75835 index 0d020de..011c7bb 100644
75836 --- a/net/atm/proc.c
75837 +++ b/net/atm/proc.c
75838 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75839 const struct k_atm_aal_stats *stats)
75840 {
75841 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75842 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75843 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75844 - atomic_read(&stats->rx_drop));
75845 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75846 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75847 + atomic_read_unchecked(&stats->rx_drop));
75848 }
75849
75850 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75851 diff --git a/net/atm/resources.c b/net/atm/resources.c
75852 index 23f45ce..c748f1a 100644
75853 --- a/net/atm/resources.c
75854 +++ b/net/atm/resources.c
75855 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75856 static void copy_aal_stats(struct k_atm_aal_stats *from,
75857 struct atm_aal_stats *to)
75858 {
75859 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75860 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75861 __AAL_STAT_ITEMS
75862 #undef __HANDLE_ITEM
75863 }
75864 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75865 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75866 struct atm_aal_stats *to)
75867 {
75868 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75869 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75870 __AAL_STAT_ITEMS
75871 #undef __HANDLE_ITEM
75872 }
75873 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75874 index 469daab..9fc7f8d 100644
75875 --- a/net/batman-adv/bat_iv_ogm.c
75876 +++ b/net/batman-adv/bat_iv_ogm.c
75877 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75878
75879 /* randomize initial seqno to avoid collision */
75880 get_random_bytes(&random_seqno, sizeof(random_seqno));
75881 - atomic_set(&hard_iface->seqno, random_seqno);
75882 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75883
75884 hard_iface->packet_len = BATADV_OGM_HLEN;
75885 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75886 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75887 "Sending own" :
75888 "Forwarding"));
75889 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75890 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75891 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75892 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75893 batadv_ogm_packet->orig,
75894 ntohl(batadv_ogm_packet->seqno),
75895 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75896
75897 /* change sequence number to network order */
75898 batadv_ogm_packet->seqno =
75899 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75900 - atomic_inc(&hard_iface->seqno);
75901 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75902 + atomic_inc_unchecked(&hard_iface->seqno);
75903
75904 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75905 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75906 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75907 return;
75908
75909 /* could be changed by schedule_own_packet() */
75910 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75911 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75912
75913 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75914 has_directlink_flag = 1;
75915 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75916 index 282bf6e..4b2603d 100644
75917 --- a/net/batman-adv/hard-interface.c
75918 +++ b/net/batman-adv/hard-interface.c
75919 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75920 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75921 dev_add_pack(&hard_iface->batman_adv_ptype);
75922
75923 - atomic_set(&hard_iface->frag_seqno, 1);
75924 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75925 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75926 hard_iface->net_dev->name);
75927
75928 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75929 /* This can't be called via a bat_priv callback because
75930 * we have no bat_priv yet.
75931 */
75932 - atomic_set(&hard_iface->seqno, 1);
75933 + atomic_set_unchecked(&hard_iface->seqno, 1);
75934 hard_iface->packet_buff = NULL;
75935
75936 return hard_iface;
75937 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75938 index 21c5357..768be1a 100644
75939 --- a/net/batman-adv/soft-interface.c
75940 +++ b/net/batman-adv/soft-interface.c
75941 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75942
75943 /* set broadcast sequence number */
75944 bcast_packet->seqno =
75945 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75946 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75947
75948 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75949
75950 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75951 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75952
75953 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75954 - atomic_set(&bat_priv->bcast_seqno, 1);
75955 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75956 atomic_set(&bat_priv->ttvn, 0);
75957 atomic_set(&bat_priv->tt_local_changes, 0);
75958 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75959 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75960 index 12635fd..d99d837 100644
75961 --- a/net/batman-adv/types.h
75962 +++ b/net/batman-adv/types.h
75963 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
75964 int16_t if_num;
75965 char if_status;
75966 struct net_device *net_dev;
75967 - atomic_t seqno;
75968 - atomic_t frag_seqno;
75969 + atomic_unchecked_t seqno;
75970 + atomic_unchecked_t frag_seqno;
75971 unsigned char *packet_buff;
75972 int packet_len;
75973 struct kobject *hardif_obj;
75974 @@ -176,7 +176,7 @@ struct batadv_priv {
75975 atomic_t orig_interval; /* uint */
75976 atomic_t hop_penalty; /* uint */
75977 atomic_t log_level; /* uint */
75978 - atomic_t bcast_seqno;
75979 + atomic_unchecked_t bcast_seqno;
75980 atomic_t bcast_queue_left;
75981 atomic_t batman_queue_left;
75982 atomic_t ttvn; /* translation table version number */
75983 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75984 index 0016464..0ef3e53 100644
75985 --- a/net/batman-adv/unicast.c
75986 +++ b/net/batman-adv/unicast.c
75987 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75988 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75989 frag2->flags = large_tail;
75990
75991 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75992 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75993 frag1->seqno = htons(seqno - 1);
75994 frag2->seqno = htons(seqno);
75995
75996 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75997 index d5ace1e..231c4bf 100644
75998 --- a/net/bluetooth/hci_sock.c
75999 +++ b/net/bluetooth/hci_sock.c
76000 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76001 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76002 }
76003
76004 - len = min_t(unsigned int, len, sizeof(uf));
76005 + len = min((size_t)len, sizeof(uf));
76006 if (copy_from_user(&uf, optval, len)) {
76007 err = -EFAULT;
76008 break;
76009 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76010 index 38c00f1..e9d566e 100644
76011 --- a/net/bluetooth/l2cap_core.c
76012 +++ b/net/bluetooth/l2cap_core.c
76013 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76014 break;
76015
76016 case L2CAP_CONF_RFC:
76017 - if (olen == sizeof(rfc))
76018 - memcpy(&rfc, (void *)val, olen);
76019 + if (olen != sizeof(rfc))
76020 + break;
76021 +
76022 + memcpy(&rfc, (void *)val, olen);
76023
76024 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76025 rfc.mode != chan->mode)
76026 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76027 index 34bbe1c..451c19b 100644
76028 --- a/net/bluetooth/l2cap_sock.c
76029 +++ b/net/bluetooth/l2cap_sock.c
76030 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76031 struct sock *sk = sock->sk;
76032 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76033 struct l2cap_options opts;
76034 - int len, err = 0;
76035 + int err = 0;
76036 + size_t len = optlen;
76037 u32 opt;
76038
76039 BT_DBG("sk %p", sk);
76040 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76041 opts.max_tx = chan->max_tx;
76042 opts.txwin_size = chan->tx_win;
76043
76044 - len = min_t(unsigned int, sizeof(opts), optlen);
76045 + len = min(sizeof(opts), len);
76046 if (copy_from_user((char *) &opts, optval, len)) {
76047 err = -EFAULT;
76048 break;
76049 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76050 struct bt_security sec;
76051 struct bt_power pwr;
76052 struct l2cap_conn *conn;
76053 - int len, err = 0;
76054 + int err = 0;
76055 + size_t len = optlen;
76056 u32 opt;
76057
76058 BT_DBG("sk %p", sk);
76059 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76060
76061 sec.level = BT_SECURITY_LOW;
76062
76063 - len = min_t(unsigned int, sizeof(sec), optlen);
76064 + len = min(sizeof(sec), len);
76065 if (copy_from_user((char *) &sec, optval, len)) {
76066 err = -EFAULT;
76067 break;
76068 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76069
76070 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76071
76072 - len = min_t(unsigned int, sizeof(pwr), optlen);
76073 + len = min(sizeof(pwr), len);
76074 if (copy_from_user((char *) &pwr, optval, len)) {
76075 err = -EFAULT;
76076 break;
76077 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76078 index 1a17850..65a3129 100644
76079 --- a/net/bluetooth/rfcomm/sock.c
76080 +++ b/net/bluetooth/rfcomm/sock.c
76081 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76082 struct sock *sk = sock->sk;
76083 struct bt_security sec;
76084 int err = 0;
76085 - size_t len;
76086 + size_t len = optlen;
76087 u32 opt;
76088
76089 BT_DBG("sk %p", sk);
76090 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76091
76092 sec.level = BT_SECURITY_LOW;
76093
76094 - len = min_t(unsigned int, sizeof(sec), optlen);
76095 + len = min(sizeof(sec), len);
76096 if (copy_from_user((char *) &sec, optval, len)) {
76097 err = -EFAULT;
76098 break;
76099 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76100 index 56f1823..da44330 100644
76101 --- a/net/bluetooth/rfcomm/tty.c
76102 +++ b/net/bluetooth/rfcomm/tty.c
76103 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76104 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76105
76106 spin_lock_irqsave(&dev->port.lock, flags);
76107 - if (dev->port.count > 0) {
76108 + if (atomic_read(&dev->port.count) > 0) {
76109 spin_unlock_irqrestore(&dev->port.lock, flags);
76110 return;
76111 }
76112 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76113 return -ENODEV;
76114
76115 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76116 - dev->channel, dev->port.count);
76117 + dev->channel, atomic_read(&dev->port.count));
76118
76119 spin_lock_irqsave(&dev->port.lock, flags);
76120 - if (++dev->port.count > 1) {
76121 + if (atomic_inc_return(&dev->port.count) > 1) {
76122 spin_unlock_irqrestore(&dev->port.lock, flags);
76123 return 0;
76124 }
76125 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76126 return;
76127
76128 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76129 - dev->port.count);
76130 + atomic_read(&dev->port.count));
76131
76132 spin_lock_irqsave(&dev->port.lock, flags);
76133 - if (!--dev->port.count) {
76134 + if (!atomic_dec_return(&dev->port.count)) {
76135 spin_unlock_irqrestore(&dev->port.lock, flags);
76136 if (dev->tty_dev->parent)
76137 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76138 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76139 index 5fe2ff3..121d696 100644
76140 --- a/net/bridge/netfilter/ebtables.c
76141 +++ b/net/bridge/netfilter/ebtables.c
76142 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76143 tmp.valid_hooks = t->table->valid_hooks;
76144 }
76145 mutex_unlock(&ebt_mutex);
76146 - if (copy_to_user(user, &tmp, *len) != 0){
76147 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76148 BUGPRINT("c2u Didn't work\n");
76149 ret = -EFAULT;
76150 break;
76151 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76152 goto out;
76153 tmp.valid_hooks = t->valid_hooks;
76154
76155 - if (copy_to_user(user, &tmp, *len) != 0) {
76156 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76157 ret = -EFAULT;
76158 break;
76159 }
76160 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76161 tmp.entries_size = t->table->entries_size;
76162 tmp.valid_hooks = t->table->valid_hooks;
76163
76164 - if (copy_to_user(user, &tmp, *len) != 0) {
76165 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76166 ret = -EFAULT;
76167 break;
76168 }
76169 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76170 index 44f270f..1f5602d 100644
76171 --- a/net/caif/cfctrl.c
76172 +++ b/net/caif/cfctrl.c
76173 @@ -10,6 +10,7 @@
76174 #include <linux/spinlock.h>
76175 #include <linux/slab.h>
76176 #include <linux/pkt_sched.h>
76177 +#include <linux/sched.h>
76178 #include <net/caif/caif_layer.h>
76179 #include <net/caif/cfpkt.h>
76180 #include <net/caif/cfctrl.h>
76181 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76182 memset(&dev_info, 0, sizeof(dev_info));
76183 dev_info.id = 0xff;
76184 cfsrvl_init(&this->serv, 0, &dev_info, false);
76185 - atomic_set(&this->req_seq_no, 1);
76186 - atomic_set(&this->rsp_seq_no, 1);
76187 + atomic_set_unchecked(&this->req_seq_no, 1);
76188 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76189 this->serv.layer.receive = cfctrl_recv;
76190 sprintf(this->serv.layer.name, "ctrl");
76191 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76192 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76193 struct cfctrl_request_info *req)
76194 {
76195 spin_lock_bh(&ctrl->info_list_lock);
76196 - atomic_inc(&ctrl->req_seq_no);
76197 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76198 + atomic_inc_unchecked(&ctrl->req_seq_no);
76199 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76200 list_add_tail(&req->list, &ctrl->list);
76201 spin_unlock_bh(&ctrl->info_list_lock);
76202 }
76203 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76204 if (p != first)
76205 pr_warn("Requests are not received in order\n");
76206
76207 - atomic_set(&ctrl->rsp_seq_no,
76208 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76209 p->sequence_no);
76210 list_del(&p->list);
76211 goto out;
76212 diff --git a/net/can/gw.c b/net/can/gw.c
76213 index b54d5e6..91c3b25 100644
76214 --- a/net/can/gw.c
76215 +++ b/net/can/gw.c
76216 @@ -96,7 +96,7 @@ struct cf_mod {
76217 struct {
76218 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76219 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76220 - } csumfunc;
76221 + } __no_const csumfunc;
76222 };
76223
76224
76225 diff --git a/net/compat.c b/net/compat.c
76226 index 74ed1d7..3695bd9 100644
76227 --- a/net/compat.c
76228 +++ b/net/compat.c
76229 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76230 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76231 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76232 return -EFAULT;
76233 - kmsg->msg_name = compat_ptr(tmp1);
76234 - kmsg->msg_iov = compat_ptr(tmp2);
76235 - kmsg->msg_control = compat_ptr(tmp3);
76236 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76237 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76238 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76239 return 0;
76240 }
76241
76242 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76243
76244 if (kern_msg->msg_namelen) {
76245 if (mode == VERIFY_READ) {
76246 - int err = move_addr_to_kernel(kern_msg->msg_name,
76247 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76248 kern_msg->msg_namelen,
76249 kern_address);
76250 if (err < 0)
76251 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76252 kern_msg->msg_name = NULL;
76253
76254 tot_len = iov_from_user_compat_to_kern(kern_iov,
76255 - (struct compat_iovec __user *)kern_msg->msg_iov,
76256 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76257 kern_msg->msg_iovlen);
76258 if (tot_len >= 0)
76259 kern_msg->msg_iov = kern_iov;
76260 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76261
76262 #define CMSG_COMPAT_FIRSTHDR(msg) \
76263 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76264 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76265 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76266 (struct compat_cmsghdr __user *)NULL)
76267
76268 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76269 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76270 (ucmlen) <= (unsigned long) \
76271 ((mhdr)->msg_controllen - \
76272 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76273 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76274
76275 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76276 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76277 {
76278 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76279 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76280 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76281 msg->msg_controllen)
76282 return NULL;
76283 return (struct compat_cmsghdr __user *)ptr;
76284 @@ -219,7 +219,7 @@ Efault:
76285
76286 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76287 {
76288 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76289 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76290 struct compat_cmsghdr cmhdr;
76291 struct compat_timeval ctv;
76292 struct compat_timespec cts[3];
76293 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76294
76295 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76296 {
76297 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76298 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76299 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76300 int fdnum = scm->fp->count;
76301 struct file **fp = scm->fp->fp;
76302 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76303 return -EFAULT;
76304 old_fs = get_fs();
76305 set_fs(KERNEL_DS);
76306 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76307 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76308 set_fs(old_fs);
76309
76310 return err;
76311 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76312 len = sizeof(ktime);
76313 old_fs = get_fs();
76314 set_fs(KERNEL_DS);
76315 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76316 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76317 set_fs(old_fs);
76318
76319 if (!err) {
76320 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76321 case MCAST_JOIN_GROUP:
76322 case MCAST_LEAVE_GROUP:
76323 {
76324 - struct compat_group_req __user *gr32 = (void *)optval;
76325 + struct compat_group_req __user *gr32 = (void __user *)optval;
76326 struct group_req __user *kgr =
76327 compat_alloc_user_space(sizeof(struct group_req));
76328 u32 interface;
76329 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76330 case MCAST_BLOCK_SOURCE:
76331 case MCAST_UNBLOCK_SOURCE:
76332 {
76333 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76334 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76335 struct group_source_req __user *kgsr = compat_alloc_user_space(
76336 sizeof(struct group_source_req));
76337 u32 interface;
76338 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76339 }
76340 case MCAST_MSFILTER:
76341 {
76342 - struct compat_group_filter __user *gf32 = (void *)optval;
76343 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76344 struct group_filter __user *kgf;
76345 u32 interface, fmode, numsrc;
76346
76347 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76348 char __user *optval, int __user *optlen,
76349 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76350 {
76351 - struct compat_group_filter __user *gf32 = (void *)optval;
76352 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76353 struct group_filter __user *kgf;
76354 int __user *koptlen;
76355 u32 interface, fmode, numsrc;
76356 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76357
76358 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76359 return -EINVAL;
76360 - if (copy_from_user(a, args, nas[call]))
76361 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76362 return -EFAULT;
76363 a0 = a[0];
76364 a1 = a[1];
76365 diff --git a/net/core/datagram.c b/net/core/datagram.c
76366 index 0337e2b..47914a0 100644
76367 --- a/net/core/datagram.c
76368 +++ b/net/core/datagram.c
76369 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76370 }
76371
76372 kfree_skb(skb);
76373 - atomic_inc(&sk->sk_drops);
76374 + atomic_inc_unchecked(&sk->sk_drops);
76375 sk_mem_reclaim_partial(sk);
76376
76377 return err;
76378 diff --git a/net/core/dev.c b/net/core/dev.c
76379 index 89e33a5..16d9d25 100644
76380 --- a/net/core/dev.c
76381 +++ b/net/core/dev.c
76382 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76383 if (no_module && capable(CAP_NET_ADMIN))
76384 no_module = request_module("netdev-%s", name);
76385 if (no_module && capable(CAP_SYS_MODULE)) {
76386 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76387 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76388 +#else
76389 if (!request_module("%s", name))
76390 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76391 name);
76392 +#endif
76393 }
76394 }
76395 EXPORT_SYMBOL(dev_load);
76396 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76397 {
76398 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76399 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76400 - atomic_long_inc(&dev->rx_dropped);
76401 + atomic_long_inc_unchecked(&dev->rx_dropped);
76402 kfree_skb(skb);
76403 return NET_RX_DROP;
76404 }
76405 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76406 nf_reset(skb);
76407
76408 if (unlikely(!is_skb_forwardable(dev, skb))) {
76409 - atomic_long_inc(&dev->rx_dropped);
76410 + atomic_long_inc_unchecked(&dev->rx_dropped);
76411 kfree_skb(skb);
76412 return NET_RX_DROP;
76413 }
76414 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76415
76416 struct dev_gso_cb {
76417 void (*destructor)(struct sk_buff *skb);
76418 -};
76419 +} __no_const;
76420
76421 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76422
76423 @@ -2928,7 +2932,7 @@ enqueue:
76424
76425 local_irq_restore(flags);
76426
76427 - atomic_long_inc(&skb->dev->rx_dropped);
76428 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76429 kfree_skb(skb);
76430 return NET_RX_DROP;
76431 }
76432 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76433 }
76434 EXPORT_SYMBOL(netif_rx_ni);
76435
76436 -static void net_tx_action(struct softirq_action *h)
76437 +static void net_tx_action(void)
76438 {
76439 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76440
76441 @@ -3328,7 +3332,7 @@ ncls:
76442 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76443 } else {
76444 drop:
76445 - atomic_long_inc(&skb->dev->rx_dropped);
76446 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76447 kfree_skb(skb);
76448 /* Jamal, now you will not able to escape explaining
76449 * me how you were going to use this. :-)
76450 @@ -3895,7 +3899,7 @@ void netif_napi_del(struct napi_struct *napi)
76451 }
76452 EXPORT_SYMBOL(netif_napi_del);
76453
76454 -static void net_rx_action(struct softirq_action *h)
76455 +static void net_rx_action(void)
76456 {
76457 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76458 unsigned long time_limit = jiffies + 2;
76459 @@ -4365,8 +4369,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76460 else
76461 seq_printf(seq, "%04x", ntohs(pt->type));
76462
76463 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76464 + seq_printf(seq, " %-8s %p\n",
76465 + pt->dev ? pt->dev->name : "", NULL);
76466 +#else
76467 seq_printf(seq, " %-8s %pF\n",
76468 pt->dev ? pt->dev->name : "", pt->func);
76469 +#endif
76470 }
76471
76472 return 0;
76473 @@ -5919,7 +5928,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76474 } else {
76475 netdev_stats_to_stats64(storage, &dev->stats);
76476 }
76477 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76478 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76479 return storage;
76480 }
76481 EXPORT_SYMBOL(dev_get_stats);
76482 diff --git a/net/core/flow.c b/net/core/flow.c
76483 index e318c7e..168b1d0 100644
76484 --- a/net/core/flow.c
76485 +++ b/net/core/flow.c
76486 @@ -61,7 +61,7 @@ struct flow_cache {
76487 struct timer_list rnd_timer;
76488 };
76489
76490 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76491 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76492 EXPORT_SYMBOL(flow_cache_genid);
76493 static struct flow_cache flow_cache_global;
76494 static struct kmem_cache *flow_cachep __read_mostly;
76495 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76496
76497 static int flow_entry_valid(struct flow_cache_entry *fle)
76498 {
76499 - if (atomic_read(&flow_cache_genid) != fle->genid)
76500 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76501 return 0;
76502 if (fle->object && !fle->object->ops->check(fle->object))
76503 return 0;
76504 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76505 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76506 fcp->hash_count++;
76507 }
76508 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76509 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76510 flo = fle->object;
76511 if (!flo)
76512 goto ret_object;
76513 @@ -280,7 +280,7 @@ nocache:
76514 }
76515 flo = resolver(net, key, family, dir, flo, ctx);
76516 if (fle) {
76517 - fle->genid = atomic_read(&flow_cache_genid);
76518 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76519 if (!IS_ERR(flo))
76520 fle->object = flo;
76521 else
76522 diff --git a/net/core/iovec.c b/net/core/iovec.c
76523 index 7e7aeb0..2a998cb 100644
76524 --- a/net/core/iovec.c
76525 +++ b/net/core/iovec.c
76526 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76527 if (m->msg_namelen) {
76528 if (mode == VERIFY_READ) {
76529 void __user *namep;
76530 - namep = (void __user __force *) m->msg_name;
76531 + namep = (void __force_user *) m->msg_name;
76532 err = move_addr_to_kernel(namep, m->msg_namelen,
76533 address);
76534 if (err < 0)
76535 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76536 }
76537
76538 size = m->msg_iovlen * sizeof(struct iovec);
76539 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76540 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76541 return -EFAULT;
76542
76543 m->msg_iov = iov;
76544 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76545 index 2c5a0a0..a45f90c 100644
76546 --- a/net/core/rtnetlink.c
76547 +++ b/net/core/rtnetlink.c
76548 @@ -58,7 +58,7 @@ struct rtnl_link {
76549 rtnl_doit_func doit;
76550 rtnl_dumpit_func dumpit;
76551 rtnl_calcit_func calcit;
76552 -};
76553 +} __no_const;
76554
76555 static DEFINE_MUTEX(rtnl_mutex);
76556
76557 diff --git a/net/core/scm.c b/net/core/scm.c
76558 index 040cebe..5b1e312 100644
76559 --- a/net/core/scm.c
76560 +++ b/net/core/scm.c
76561 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76562 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76563 {
76564 struct cmsghdr __user *cm
76565 - = (__force struct cmsghdr __user *)msg->msg_control;
76566 + = (struct cmsghdr __force_user *)msg->msg_control;
76567 struct cmsghdr cmhdr;
76568 int cmlen = CMSG_LEN(len);
76569 int err;
76570 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76571 err = -EFAULT;
76572 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76573 goto out;
76574 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76575 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76576 goto out;
76577 cmlen = CMSG_SPACE(len);
76578 if (msg->msg_controllen < cmlen)
76579 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76580 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76581 {
76582 struct cmsghdr __user *cm
76583 - = (__force struct cmsghdr __user*)msg->msg_control;
76584 + = (struct cmsghdr __force_user *)msg->msg_control;
76585
76586 int fdmax = 0;
76587 int fdnum = scm->fp->count;
76588 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76589 if (fdnum < fdmax)
76590 fdmax = fdnum;
76591
76592 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76593 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76594 i++, cmfptr++)
76595 {
76596 struct socket *sock;
76597 diff --git a/net/core/sock.c b/net/core/sock.c
76598 index a6000fb..d4aee72 100644
76599 --- a/net/core/sock.c
76600 +++ b/net/core/sock.c
76601 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76602 struct sk_buff_head *list = &sk->sk_receive_queue;
76603
76604 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76605 - atomic_inc(&sk->sk_drops);
76606 + atomic_inc_unchecked(&sk->sk_drops);
76607 trace_sock_rcvqueue_full(sk, skb);
76608 return -ENOMEM;
76609 }
76610 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76611 return err;
76612
76613 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76614 - atomic_inc(&sk->sk_drops);
76615 + atomic_inc_unchecked(&sk->sk_drops);
76616 return -ENOBUFS;
76617 }
76618
76619 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76620 skb_dst_force(skb);
76621
76622 spin_lock_irqsave(&list->lock, flags);
76623 - skb->dropcount = atomic_read(&sk->sk_drops);
76624 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76625 __skb_queue_tail(list, skb);
76626 spin_unlock_irqrestore(&list->lock, flags);
76627
76628 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76629 skb->dev = NULL;
76630
76631 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76632 - atomic_inc(&sk->sk_drops);
76633 + atomic_inc_unchecked(&sk->sk_drops);
76634 goto discard_and_relse;
76635 }
76636 if (nested)
76637 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76638 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76639 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76640 bh_unlock_sock(sk);
76641 - atomic_inc(&sk->sk_drops);
76642 + atomic_inc_unchecked(&sk->sk_drops);
76643 goto discard_and_relse;
76644 }
76645
76646 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76647 struct timeval tm;
76648 } v;
76649
76650 - int lv = sizeof(int);
76651 - int len;
76652 + unsigned int lv = sizeof(int);
76653 + unsigned int len;
76654
76655 if (get_user(len, optlen))
76656 return -EFAULT;
76657 - if (len < 0)
76658 + if (len > INT_MAX)
76659 return -EINVAL;
76660
76661 memset(&v, 0, sizeof(v));
76662 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76663
76664 case SO_PEERNAME:
76665 {
76666 - char address[128];
76667 + char address[_K_SS_MAXSIZE];
76668
76669 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76670 return -ENOTCONN;
76671 - if (lv < len)
76672 + if (lv < len || sizeof address < len)
76673 return -EINVAL;
76674 if (copy_to_user(optval, address, len))
76675 return -EFAULT;
76676 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76677
76678 if (len > lv)
76679 len = lv;
76680 - if (copy_to_user(optval, &v, len))
76681 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76682 return -EFAULT;
76683 lenout:
76684 if (put_user(len, optlen))
76685 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76686 */
76687 smp_wmb();
76688 atomic_set(&sk->sk_refcnt, 1);
76689 - atomic_set(&sk->sk_drops, 0);
76690 + atomic_set_unchecked(&sk->sk_drops, 0);
76691 }
76692 EXPORT_SYMBOL(sock_init_data);
76693
76694 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76695 index 9d8755e..26de8bc 100644
76696 --- a/net/core/sock_diag.c
76697 +++ b/net/core/sock_diag.c
76698 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76699
76700 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76701 {
76702 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76703 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76704 cookie[1] != INET_DIAG_NOCOOKIE) &&
76705 ((u32)(unsigned long)sk != cookie[0] ||
76706 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76707 return -ESTALE;
76708 else
76709 +#endif
76710 return 0;
76711 }
76712 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76713
76714 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76715 {
76716 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76717 + cookie[0] = 0;
76718 + cookie[1] = 0;
76719 +#else
76720 cookie[0] = (u32)(unsigned long)sk;
76721 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76722 +#endif
76723 }
76724 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76725
76726 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76727 index a55eecc..dd8428c 100644
76728 --- a/net/decnet/sysctl_net_decnet.c
76729 +++ b/net/decnet/sysctl_net_decnet.c
76730 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76731
76732 if (len > *lenp) len = *lenp;
76733
76734 - if (copy_to_user(buffer, addr, len))
76735 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76736 return -EFAULT;
76737
76738 *lenp = len;
76739 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76740
76741 if (len > *lenp) len = *lenp;
76742
76743 - if (copy_to_user(buffer, devname, len))
76744 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76745 return -EFAULT;
76746
76747 *lenp = len;
76748 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76749 index 8e2b475..7263d89 100644
76750 --- a/net/ipv4/fib_frontend.c
76751 +++ b/net/ipv4/fib_frontend.c
76752 @@ -1019,12 +1019,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76753 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76754 fib_sync_up(dev);
76755 #endif
76756 - atomic_inc(&net->ipv4.dev_addr_genid);
76757 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76758 rt_cache_flush(dev_net(dev));
76759 break;
76760 case NETDEV_DOWN:
76761 fib_del_ifaddr(ifa, NULL);
76762 - atomic_inc(&net->ipv4.dev_addr_genid);
76763 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76764 if (ifa->ifa_dev->ifa_list == NULL) {
76765 /* Last address was deleted from this interface.
76766 * Disable IP.
76767 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76768 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76769 fib_sync_up(dev);
76770 #endif
76771 - atomic_inc(&net->ipv4.dev_addr_genid);
76772 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76773 rt_cache_flush(dev_net(dev));
76774 break;
76775 case NETDEV_DOWN:
76776 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76777 index a747100..c5c8de1 100644
76778 --- a/net/ipv4/fib_semantics.c
76779 +++ b/net/ipv4/fib_semantics.c
76780 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76781 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76782 nh->nh_gw,
76783 nh->nh_parent->fib_scope);
76784 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76785 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76786
76787 return nh->nh_saddr;
76788 }
76789 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76790 index 7880af9..70f92a3 100644
76791 --- a/net/ipv4/inet_hashtables.c
76792 +++ b/net/ipv4/inet_hashtables.c
76793 @@ -18,12 +18,15 @@
76794 #include <linux/sched.h>
76795 #include <linux/slab.h>
76796 #include <linux/wait.h>
76797 +#include <linux/security.h>
76798
76799 #include <net/inet_connection_sock.h>
76800 #include <net/inet_hashtables.h>
76801 #include <net/secure_seq.h>
76802 #include <net/ip.h>
76803
76804 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76805 +
76806 /*
76807 * Allocate and initialize a new local port bind bucket.
76808 * The bindhash mutex for snum's hash chain must be held here.
76809 @@ -530,6 +533,8 @@ ok:
76810 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76811 spin_unlock(&head->lock);
76812
76813 + gr_update_task_in_ip_table(current, inet_sk(sk));
76814 +
76815 if (tw) {
76816 inet_twsk_deschedule(tw, death_row);
76817 while (twrefcnt) {
76818 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76819 index c7527f6..d8bba61 100644
76820 --- a/net/ipv4/inetpeer.c
76821 +++ b/net/ipv4/inetpeer.c
76822 @@ -503,8 +503,8 @@ relookup:
76823 if (p) {
76824 p->daddr = *daddr;
76825 atomic_set(&p->refcnt, 1);
76826 - atomic_set(&p->rid, 0);
76827 - atomic_set(&p->ip_id_count,
76828 + atomic_set_unchecked(&p->rid, 0);
76829 + atomic_set_unchecked(&p->ip_id_count,
76830 (daddr->family == AF_INET) ?
76831 secure_ip_id(daddr->addr.a4) :
76832 secure_ipv6_id(daddr->addr.a6));
76833 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76834 index 8d07c97..d0812ef 100644
76835 --- a/net/ipv4/ip_fragment.c
76836 +++ b/net/ipv4/ip_fragment.c
76837 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76838 return 0;
76839
76840 start = qp->rid;
76841 - end = atomic_inc_return(&peer->rid);
76842 + end = atomic_inc_return_unchecked(&peer->rid);
76843 qp->rid = end;
76844
76845 rc = qp->q.fragments && (end - start) > max;
76846 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76847 index 5eea4a8..49819c2 100644
76848 --- a/net/ipv4/ip_sockglue.c
76849 +++ b/net/ipv4/ip_sockglue.c
76850 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76851 len = min_t(unsigned int, len, opt->optlen);
76852 if (put_user(len, optlen))
76853 return -EFAULT;
76854 - if (copy_to_user(optval, opt->__data, len))
76855 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76856 + copy_to_user(optval, opt->__data, len))
76857 return -EFAULT;
76858 return 0;
76859 }
76860 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76861 if (sk->sk_type != SOCK_STREAM)
76862 return -ENOPROTOOPT;
76863
76864 - msg.msg_control = optval;
76865 + msg.msg_control = (void __force_kernel *)optval;
76866 msg.msg_controllen = len;
76867 msg.msg_flags = flags;
76868
76869 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76870 index 67e8a6b..386764d 100644
76871 --- a/net/ipv4/ipconfig.c
76872 +++ b/net/ipv4/ipconfig.c
76873 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76874
76875 mm_segment_t oldfs = get_fs();
76876 set_fs(get_ds());
76877 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76878 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76879 set_fs(oldfs);
76880 return res;
76881 }
76882 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76883
76884 mm_segment_t oldfs = get_fs();
76885 set_fs(get_ds());
76886 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76887 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76888 set_fs(oldfs);
76889 return res;
76890 }
76891 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76892
76893 mm_segment_t oldfs = get_fs();
76894 set_fs(get_ds());
76895 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76896 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76897 set_fs(oldfs);
76898 return res;
76899 }
76900 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76901 index 97e61ea..cac1bbb 100644
76902 --- a/net/ipv4/netfilter/arp_tables.c
76903 +++ b/net/ipv4/netfilter/arp_tables.c
76904 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76905 #endif
76906
76907 static int get_info(struct net *net, void __user *user,
76908 - const int *len, int compat)
76909 + int len, int compat)
76910 {
76911 char name[XT_TABLE_MAXNAMELEN];
76912 struct xt_table *t;
76913 int ret;
76914
76915 - if (*len != sizeof(struct arpt_getinfo)) {
76916 - duprintf("length %u != %Zu\n", *len,
76917 + if (len != sizeof(struct arpt_getinfo)) {
76918 + duprintf("length %u != %Zu\n", len,
76919 sizeof(struct arpt_getinfo));
76920 return -EINVAL;
76921 }
76922 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76923 info.size = private->size;
76924 strcpy(info.name, name);
76925
76926 - if (copy_to_user(user, &info, *len) != 0)
76927 + if (copy_to_user(user, &info, len) != 0)
76928 ret = -EFAULT;
76929 else
76930 ret = 0;
76931 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76932
76933 switch (cmd) {
76934 case ARPT_SO_GET_INFO:
76935 - ret = get_info(sock_net(sk), user, len, 1);
76936 + ret = get_info(sock_net(sk), user, *len, 1);
76937 break;
76938 case ARPT_SO_GET_ENTRIES:
76939 ret = compat_get_entries(sock_net(sk), user, len);
76940 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76941
76942 switch (cmd) {
76943 case ARPT_SO_GET_INFO:
76944 - ret = get_info(sock_net(sk), user, len, 0);
76945 + ret = get_info(sock_net(sk), user, *len, 0);
76946 break;
76947
76948 case ARPT_SO_GET_ENTRIES:
76949 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76950 index 170b1fd..6105b91 100644
76951 --- a/net/ipv4/netfilter/ip_tables.c
76952 +++ b/net/ipv4/netfilter/ip_tables.c
76953 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76954 #endif
76955
76956 static int get_info(struct net *net, void __user *user,
76957 - const int *len, int compat)
76958 + int len, int compat)
76959 {
76960 char name[XT_TABLE_MAXNAMELEN];
76961 struct xt_table *t;
76962 int ret;
76963
76964 - if (*len != sizeof(struct ipt_getinfo)) {
76965 - duprintf("length %u != %zu\n", *len,
76966 + if (len != sizeof(struct ipt_getinfo)) {
76967 + duprintf("length %u != %zu\n", len,
76968 sizeof(struct ipt_getinfo));
76969 return -EINVAL;
76970 }
76971 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76972 info.size = private->size;
76973 strcpy(info.name, name);
76974
76975 - if (copy_to_user(user, &info, *len) != 0)
76976 + if (copy_to_user(user, &info, len) != 0)
76977 ret = -EFAULT;
76978 else
76979 ret = 0;
76980 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76981
76982 switch (cmd) {
76983 case IPT_SO_GET_INFO:
76984 - ret = get_info(sock_net(sk), user, len, 1);
76985 + ret = get_info(sock_net(sk), user, *len, 1);
76986 break;
76987 case IPT_SO_GET_ENTRIES:
76988 ret = compat_get_entries(sock_net(sk), user, len);
76989 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76990
76991 switch (cmd) {
76992 case IPT_SO_GET_INFO:
76993 - ret = get_info(sock_net(sk), user, len, 0);
76994 + ret = get_info(sock_net(sk), user, *len, 0);
76995 break;
76996
76997 case IPT_SO_GET_ENTRIES:
76998 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76999 index 6232d47..6b88607 100644
77000 --- a/net/ipv4/ping.c
77001 +++ b/net/ipv4/ping.c
77002 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77003 sk_rmem_alloc_get(sp),
77004 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77005 atomic_read(&sp->sk_refcnt), sp,
77006 - atomic_read(&sp->sk_drops), len);
77007 + atomic_read_unchecked(&sp->sk_drops), len);
77008 }
77009
77010 static int ping_seq_show(struct seq_file *seq, void *v)
77011 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77012 index d23c657..cb69cc2 100644
77013 --- a/net/ipv4/raw.c
77014 +++ b/net/ipv4/raw.c
77015 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77016 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77017 {
77018 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77019 - atomic_inc(&sk->sk_drops);
77020 + atomic_inc_unchecked(&sk->sk_drops);
77021 kfree_skb(skb);
77022 return NET_RX_DROP;
77023 }
77024 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77025
77026 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77027 {
77028 + struct icmp_filter filter;
77029 +
77030 if (optlen > sizeof(struct icmp_filter))
77031 optlen = sizeof(struct icmp_filter);
77032 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77033 + if (copy_from_user(&filter, optval, optlen))
77034 return -EFAULT;
77035 + raw_sk(sk)->filter = filter;
77036 return 0;
77037 }
77038
77039 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77040 {
77041 int len, ret = -EFAULT;
77042 + struct icmp_filter filter;
77043
77044 if (get_user(len, optlen))
77045 goto out;
77046 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77047 if (len > sizeof(struct icmp_filter))
77048 len = sizeof(struct icmp_filter);
77049 ret = -EFAULT;
77050 - if (put_user(len, optlen) ||
77051 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77052 + filter = raw_sk(sk)->filter;
77053 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77054 goto out;
77055 ret = 0;
77056 out: return ret;
77057 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77058 sk_wmem_alloc_get(sp),
77059 sk_rmem_alloc_get(sp),
77060 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77061 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77062 + atomic_read(&sp->sk_refcnt),
77063 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77064 + NULL,
77065 +#else
77066 + sp,
77067 +#endif
77068 + atomic_read_unchecked(&sp->sk_drops));
77069 }
77070
77071 static int raw_seq_show(struct seq_file *seq, void *v)
77072 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77073 index fd9af60..dca4e54 100644
77074 --- a/net/ipv4/route.c
77075 +++ b/net/ipv4/route.c
77076 @@ -2501,7 +2501,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77077
77078 static __net_init int rt_genid_init(struct net *net)
77079 {
77080 - atomic_set(&net->rt_genid, 0);
77081 + atomic_set_unchecked(&net->rt_genid, 0);
77082 get_random_bytes(&net->ipv4.dev_addr_genid,
77083 sizeof(net->ipv4.dev_addr_genid));
77084 return 0;
77085 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77086 index d377f48..c2211ed 100644
77087 --- a/net/ipv4/tcp_input.c
77088 +++ b/net/ipv4/tcp_input.c
77089 @@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77090 * simplifies code)
77091 */
77092 static void
77093 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77094 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77095 struct sk_buff *head, struct sk_buff *tail,
77096 u32 start, u32 end)
77097 {
77098 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77099 index 00a748d..e6d546b 100644
77100 --- a/net/ipv4/tcp_ipv4.c
77101 +++ b/net/ipv4/tcp_ipv4.c
77102 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77103 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77104
77105
77106 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77107 +extern int grsec_enable_blackhole;
77108 +#endif
77109 +
77110 #ifdef CONFIG_TCP_MD5SIG
77111 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77112 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77113 @@ -1663,6 +1667,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77114 return 0;
77115
77116 reset:
77117 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77118 + if (!grsec_enable_blackhole)
77119 +#endif
77120 tcp_v4_send_reset(rsk, skb);
77121 discard:
77122 kfree_skb(skb);
77123 @@ -1763,12 +1770,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77124 TCP_SKB_CB(skb)->sacked = 0;
77125
77126 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77127 - if (!sk)
77128 + if (!sk) {
77129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77130 + ret = 1;
77131 +#endif
77132 goto no_tcp_socket;
77133 -
77134 + }
77135 process:
77136 - if (sk->sk_state == TCP_TIME_WAIT)
77137 + if (sk->sk_state == TCP_TIME_WAIT) {
77138 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77139 + ret = 2;
77140 +#endif
77141 goto do_time_wait;
77142 + }
77143
77144 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77145 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77146 @@ -1819,6 +1833,10 @@ no_tcp_socket:
77147 bad_packet:
77148 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77149 } else {
77150 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77151 + if (!grsec_enable_blackhole || (ret == 1 &&
77152 + (skb->dev->flags & IFF_LOOPBACK)))
77153 +#endif
77154 tcp_v4_send_reset(NULL, skb);
77155 }
77156
77157 @@ -2414,7 +2432,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77158 0, /* non standard timer */
77159 0, /* open_requests have no inode */
77160 atomic_read(&sk->sk_refcnt),
77161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77162 + NULL,
77163 +#else
77164 req,
77165 +#endif
77166 len);
77167 }
77168
77169 @@ -2464,7 +2486,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77170 sock_i_uid(sk),
77171 icsk->icsk_probes_out,
77172 sock_i_ino(sk),
77173 - atomic_read(&sk->sk_refcnt), sk,
77174 + atomic_read(&sk->sk_refcnt),
77175 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77176 + NULL,
77177 +#else
77178 + sk,
77179 +#endif
77180 jiffies_to_clock_t(icsk->icsk_rto),
77181 jiffies_to_clock_t(icsk->icsk_ack.ato),
77182 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77183 @@ -2492,7 +2519,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77184 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77185 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77186 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77187 - atomic_read(&tw->tw_refcnt), tw, len);
77188 + atomic_read(&tw->tw_refcnt),
77189 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77190 + NULL,
77191 +#else
77192 + tw,
77193 +#endif
77194 + len);
77195 }
77196
77197 #define TMPSZ 150
77198 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77199 index 6ff7f10..38de56e 100644
77200 --- a/net/ipv4/tcp_minisocks.c
77201 +++ b/net/ipv4/tcp_minisocks.c
77202 @@ -27,6 +27,10 @@
77203 #include <net/inet_common.h>
77204 #include <net/xfrm.h>
77205
77206 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77207 +extern int grsec_enable_blackhole;
77208 +#endif
77209 +
77210 int sysctl_tcp_syncookies __read_mostly = 1;
77211 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77212
77213 @@ -707,6 +711,10 @@ listen_overflow:
77214
77215 embryonic_reset:
77216 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77217 +
77218 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77219 + if (!grsec_enable_blackhole)
77220 +#endif
77221 if (!(flg & TCP_FLAG_RST))
77222 req->rsk_ops->send_reset(sk, skb);
77223
77224 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77225 index 4526fe6..1a34e43 100644
77226 --- a/net/ipv4/tcp_probe.c
77227 +++ b/net/ipv4/tcp_probe.c
77228 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77229 if (cnt + width >= len)
77230 break;
77231
77232 - if (copy_to_user(buf + cnt, tbuf, width))
77233 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77234 return -EFAULT;
77235 cnt += width;
77236 }
77237 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77238 index b774a03..3873efe 100644
77239 --- a/net/ipv4/tcp_timer.c
77240 +++ b/net/ipv4/tcp_timer.c
77241 @@ -22,6 +22,10 @@
77242 #include <linux/gfp.h>
77243 #include <net/tcp.h>
77244
77245 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77246 +extern int grsec_lastack_retries;
77247 +#endif
77248 +
77249 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77250 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77251 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77252 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77253 }
77254 }
77255
77256 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77257 + if ((sk->sk_state == TCP_LAST_ACK) &&
77258 + (grsec_lastack_retries > 0) &&
77259 + (grsec_lastack_retries < retry_until))
77260 + retry_until = grsec_lastack_retries;
77261 +#endif
77262 +
77263 if (retransmits_timed_out(sk, retry_until,
77264 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77265 /* Has it gone just too far? */
77266 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77267 index 2814f66..fa2b223 100644
77268 --- a/net/ipv4/udp.c
77269 +++ b/net/ipv4/udp.c
77270 @@ -87,6 +87,7 @@
77271 #include <linux/types.h>
77272 #include <linux/fcntl.h>
77273 #include <linux/module.h>
77274 +#include <linux/security.h>
77275 #include <linux/socket.h>
77276 #include <linux/sockios.h>
77277 #include <linux/igmp.h>
77278 @@ -111,6 +112,10 @@
77279 #include <trace/events/skb.h>
77280 #include "udp_impl.h"
77281
77282 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77283 +extern int grsec_enable_blackhole;
77284 +#endif
77285 +
77286 struct udp_table udp_table __read_mostly;
77287 EXPORT_SYMBOL(udp_table);
77288
77289 @@ -569,6 +574,9 @@ found:
77290 return s;
77291 }
77292
77293 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77294 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77295 +
77296 /*
77297 * This routine is called by the ICMP module when it gets some
77298 * sort of error condition. If err < 0 then the socket should
77299 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77300 dport = usin->sin_port;
77301 if (dport == 0)
77302 return -EINVAL;
77303 +
77304 + err = gr_search_udp_sendmsg(sk, usin);
77305 + if (err)
77306 + return err;
77307 } else {
77308 if (sk->sk_state != TCP_ESTABLISHED)
77309 return -EDESTADDRREQ;
77310 +
77311 + err = gr_search_udp_sendmsg(sk, NULL);
77312 + if (err)
77313 + return err;
77314 +
77315 daddr = inet->inet_daddr;
77316 dport = inet->inet_dport;
77317 /* Open fast path for connected socket.
77318 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77319 udp_lib_checksum_complete(skb)) {
77320 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77321 IS_UDPLITE(sk));
77322 - atomic_inc(&sk->sk_drops);
77323 + atomic_inc_unchecked(&sk->sk_drops);
77324 __skb_unlink(skb, rcvq);
77325 __skb_queue_tail(&list_kill, skb);
77326 }
77327 @@ -1194,6 +1211,10 @@ try_again:
77328 if (!skb)
77329 goto out;
77330
77331 + err = gr_search_udp_recvmsg(sk, skb);
77332 + if (err)
77333 + goto out_free;
77334 +
77335 ulen = skb->len - sizeof(struct udphdr);
77336 copied = len;
77337 if (copied > ulen)
77338 @@ -1227,7 +1248,7 @@ try_again:
77339 if (unlikely(err)) {
77340 trace_kfree_skb(skb, udp_recvmsg);
77341 if (!peeked) {
77342 - atomic_inc(&sk->sk_drops);
77343 + atomic_inc_unchecked(&sk->sk_drops);
77344 UDP_INC_STATS_USER(sock_net(sk),
77345 UDP_MIB_INERRORS, is_udplite);
77346 }
77347 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77348
77349 drop:
77350 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77351 - atomic_inc(&sk->sk_drops);
77352 + atomic_inc_unchecked(&sk->sk_drops);
77353 kfree_skb(skb);
77354 return -1;
77355 }
77356 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77357 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77358
77359 if (!skb1) {
77360 - atomic_inc(&sk->sk_drops);
77361 + atomic_inc_unchecked(&sk->sk_drops);
77362 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77363 IS_UDPLITE(sk));
77364 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77365 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77366 goto csum_error;
77367
77368 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77369 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77370 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77371 +#endif
77372 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77373
77374 /*
77375 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77376 sk_wmem_alloc_get(sp),
77377 sk_rmem_alloc_get(sp),
77378 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77379 - atomic_read(&sp->sk_refcnt), sp,
77380 - atomic_read(&sp->sk_drops), len);
77381 + atomic_read(&sp->sk_refcnt),
77382 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77383 + NULL,
77384 +#else
77385 + sp,
77386 +#endif
77387 + atomic_read_unchecked(&sp->sk_drops), len);
77388 }
77389
77390 int udp4_seq_show(struct seq_file *seq, void *v)
77391 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77392 index ea3e9af..b60262e 100644
77393 --- a/net/ipv6/addrconf.c
77394 +++ b/net/ipv6/addrconf.c
77395 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77396 p.iph.ihl = 5;
77397 p.iph.protocol = IPPROTO_IPV6;
77398 p.iph.ttl = 64;
77399 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77400 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77401
77402 if (ops->ndo_do_ioctl) {
77403 mm_segment_t oldfs = get_fs();
77404 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77405 index ba6d13d..6899122 100644
77406 --- a/net/ipv6/ipv6_sockglue.c
77407 +++ b/net/ipv6/ipv6_sockglue.c
77408 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77409 if (sk->sk_type != SOCK_STREAM)
77410 return -ENOPROTOOPT;
77411
77412 - msg.msg_control = optval;
77413 + msg.msg_control = (void __force_kernel *)optval;
77414 msg.msg_controllen = len;
77415 msg.msg_flags = flags;
77416
77417 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77418 index d7cb045..8c0ded6 100644
77419 --- a/net/ipv6/netfilter/ip6_tables.c
77420 +++ b/net/ipv6/netfilter/ip6_tables.c
77421 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77422 #endif
77423
77424 static int get_info(struct net *net, void __user *user,
77425 - const int *len, int compat)
77426 + int len, int compat)
77427 {
77428 char name[XT_TABLE_MAXNAMELEN];
77429 struct xt_table *t;
77430 int ret;
77431
77432 - if (*len != sizeof(struct ip6t_getinfo)) {
77433 - duprintf("length %u != %zu\n", *len,
77434 + if (len != sizeof(struct ip6t_getinfo)) {
77435 + duprintf("length %u != %zu\n", len,
77436 sizeof(struct ip6t_getinfo));
77437 return -EINVAL;
77438 }
77439 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77440 info.size = private->size;
77441 strcpy(info.name, name);
77442
77443 - if (copy_to_user(user, &info, *len) != 0)
77444 + if (copy_to_user(user, &info, len) != 0)
77445 ret = -EFAULT;
77446 else
77447 ret = 0;
77448 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77449
77450 switch (cmd) {
77451 case IP6T_SO_GET_INFO:
77452 - ret = get_info(sock_net(sk), user, len, 1);
77453 + ret = get_info(sock_net(sk), user, *len, 1);
77454 break;
77455 case IP6T_SO_GET_ENTRIES:
77456 ret = compat_get_entries(sock_net(sk), user, len);
77457 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77458
77459 switch (cmd) {
77460 case IP6T_SO_GET_INFO:
77461 - ret = get_info(sock_net(sk), user, len, 0);
77462 + ret = get_info(sock_net(sk), user, *len, 0);
77463 break;
77464
77465 case IP6T_SO_GET_ENTRIES:
77466 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77467 index 4a5f78b..3f22ebe 100644
77468 --- a/net/ipv6/raw.c
77469 +++ b/net/ipv6/raw.c
77470 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77471 {
77472 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77473 skb_checksum_complete(skb)) {
77474 - atomic_inc(&sk->sk_drops);
77475 + atomic_inc_unchecked(&sk->sk_drops);
77476 kfree_skb(skb);
77477 return NET_RX_DROP;
77478 }
77479 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77480 struct raw6_sock *rp = raw6_sk(sk);
77481
77482 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77483 - atomic_inc(&sk->sk_drops);
77484 + atomic_inc_unchecked(&sk->sk_drops);
77485 kfree_skb(skb);
77486 return NET_RX_DROP;
77487 }
77488 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77489
77490 if (inet->hdrincl) {
77491 if (skb_checksum_complete(skb)) {
77492 - atomic_inc(&sk->sk_drops);
77493 + atomic_inc_unchecked(&sk->sk_drops);
77494 kfree_skb(skb);
77495 return NET_RX_DROP;
77496 }
77497 @@ -604,7 +604,7 @@ out:
77498 return err;
77499 }
77500
77501 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77502 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77503 struct flowi6 *fl6, struct dst_entry **dstp,
77504 unsigned int flags)
77505 {
77506 @@ -916,12 +916,15 @@ do_confirm:
77507 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77508 char __user *optval, int optlen)
77509 {
77510 + struct icmp6_filter filter;
77511 +
77512 switch (optname) {
77513 case ICMPV6_FILTER:
77514 if (optlen > sizeof(struct icmp6_filter))
77515 optlen = sizeof(struct icmp6_filter);
77516 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77517 + if (copy_from_user(&filter, optval, optlen))
77518 return -EFAULT;
77519 + raw6_sk(sk)->filter = filter;
77520 return 0;
77521 default:
77522 return -ENOPROTOOPT;
77523 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77524 char __user *optval, int __user *optlen)
77525 {
77526 int len;
77527 + struct icmp6_filter filter;
77528
77529 switch (optname) {
77530 case ICMPV6_FILTER:
77531 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77532 len = sizeof(struct icmp6_filter);
77533 if (put_user(len, optlen))
77534 return -EFAULT;
77535 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77536 + filter = raw6_sk(sk)->filter;
77537 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77538 return -EFAULT;
77539 return 0;
77540 default:
77541 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77542 0, 0L, 0,
77543 sock_i_uid(sp), 0,
77544 sock_i_ino(sp),
77545 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77546 + atomic_read(&sp->sk_refcnt),
77547 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77548 + NULL,
77549 +#else
77550 + sp,
77551 +#endif
77552 + atomic_read_unchecked(&sp->sk_drops));
77553 }
77554
77555 static int raw6_seq_show(struct seq_file *seq, void *v)
77556 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77557 index acd32e3..f73f8f7 100644
77558 --- a/net/ipv6/tcp_ipv6.c
77559 +++ b/net/ipv6/tcp_ipv6.c
77560 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77561 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77562 }
77563
77564 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77565 +extern int grsec_enable_blackhole;
77566 +#endif
77567 +
77568 static void tcp_v6_hash(struct sock *sk)
77569 {
77570 if (sk->sk_state != TCP_CLOSE) {
77571 @@ -1510,6 +1514,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77572 return 0;
77573
77574 reset:
77575 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77576 + if (!grsec_enable_blackhole)
77577 +#endif
77578 tcp_v6_send_reset(sk, skb);
77579 discard:
77580 if (opt_skb)
77581 @@ -1591,12 +1598,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77582 TCP_SKB_CB(skb)->sacked = 0;
77583
77584 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77585 - if (!sk)
77586 + if (!sk) {
77587 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77588 + ret = 1;
77589 +#endif
77590 goto no_tcp_socket;
77591 + }
77592
77593 process:
77594 - if (sk->sk_state == TCP_TIME_WAIT)
77595 + if (sk->sk_state == TCP_TIME_WAIT) {
77596 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77597 + ret = 2;
77598 +#endif
77599 goto do_time_wait;
77600 + }
77601
77602 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77603 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77604 @@ -1645,6 +1660,10 @@ no_tcp_socket:
77605 bad_packet:
77606 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77607 } else {
77608 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77609 + if (!grsec_enable_blackhole || (ret == 1 &&
77610 + (skb->dev->flags & IFF_LOOPBACK)))
77611 +#endif
77612 tcp_v6_send_reset(NULL, skb);
77613 }
77614
77615 @@ -1856,7 +1875,13 @@ static void get_openreq6(struct seq_file *seq,
77616 uid,
77617 0, /* non standard timer */
77618 0, /* open_requests have no inode */
77619 - 0, req);
77620 + 0,
77621 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77622 + NULL
77623 +#else
77624 + req
77625 +#endif
77626 + );
77627 }
77628
77629 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77630 @@ -1906,7 +1931,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77631 sock_i_uid(sp),
77632 icsk->icsk_probes_out,
77633 sock_i_ino(sp),
77634 - atomic_read(&sp->sk_refcnt), sp,
77635 + atomic_read(&sp->sk_refcnt),
77636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77637 + NULL,
77638 +#else
77639 + sp,
77640 +#endif
77641 jiffies_to_clock_t(icsk->icsk_rto),
77642 jiffies_to_clock_t(icsk->icsk_ack.ato),
77643 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77644 @@ -1941,7 +1971,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77645 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77646 tw->tw_substate, 0, 0,
77647 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77648 - atomic_read(&tw->tw_refcnt), tw);
77649 + atomic_read(&tw->tw_refcnt),
77650 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77651 + NULL
77652 +#else
77653 + tw
77654 +#endif
77655 + );
77656 }
77657
77658 static int tcp6_seq_show(struct seq_file *seq, void *v)
77659 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77660 index 07e2bfe..328dae8 100644
77661 --- a/net/ipv6/udp.c
77662 +++ b/net/ipv6/udp.c
77663 @@ -51,6 +51,10 @@
77664 #include <trace/events/skb.h>
77665 #include "udp_impl.h"
77666
77667 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77668 +extern int grsec_enable_blackhole;
77669 +#endif
77670 +
77671 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77672 {
77673 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77674 @@ -395,7 +399,7 @@ try_again:
77675 if (unlikely(err)) {
77676 trace_kfree_skb(skb, udpv6_recvmsg);
77677 if (!peeked) {
77678 - atomic_inc(&sk->sk_drops);
77679 + atomic_inc_unchecked(&sk->sk_drops);
77680 if (is_udp4)
77681 UDP_INC_STATS_USER(sock_net(sk),
77682 UDP_MIB_INERRORS,
77683 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77684 return rc;
77685 drop:
77686 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77687 - atomic_inc(&sk->sk_drops);
77688 + atomic_inc_unchecked(&sk->sk_drops);
77689 kfree_skb(skb);
77690 return -1;
77691 }
77692 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77693 if (likely(skb1 == NULL))
77694 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77695 if (!skb1) {
77696 - atomic_inc(&sk->sk_drops);
77697 + atomic_inc_unchecked(&sk->sk_drops);
77698 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77699 IS_UDPLITE(sk));
77700 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77701 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77702 goto discard;
77703
77704 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77705 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77706 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77707 +#endif
77708 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77709
77710 kfree_skb(skb);
77711 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77712 0, 0L, 0,
77713 sock_i_uid(sp), 0,
77714 sock_i_ino(sp),
77715 - atomic_read(&sp->sk_refcnt), sp,
77716 - atomic_read(&sp->sk_drops));
77717 + atomic_read(&sp->sk_refcnt),
77718 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77719 + NULL,
77720 +#else
77721 + sp,
77722 +#endif
77723 + atomic_read_unchecked(&sp->sk_drops));
77724 }
77725
77726 int udp6_seq_show(struct seq_file *seq, void *v)
77727 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77728 index 6b9d5a0..4dffaf1 100644
77729 --- a/net/irda/ircomm/ircomm_tty.c
77730 +++ b/net/irda/ircomm/ircomm_tty.c
77731 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77732 add_wait_queue(&self->open_wait, &wait);
77733
77734 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77735 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77736 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77737
77738 /* As far as I can see, we protect open_count - Jean II */
77739 spin_lock_irqsave(&self->spinlock, flags);
77740 if (!tty_hung_up_p(filp)) {
77741 extra_count = 1;
77742 - self->open_count--;
77743 + local_dec(&self->open_count);
77744 }
77745 spin_unlock_irqrestore(&self->spinlock, flags);
77746 - self->blocked_open++;
77747 + local_inc(&self->blocked_open);
77748
77749 while (1) {
77750 if (tty->termios->c_cflag & CBAUD) {
77751 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77752 }
77753
77754 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77755 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77756 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77757
77758 schedule();
77759 }
77760 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77761 if (extra_count) {
77762 /* ++ is not atomic, so this should be protected - Jean II */
77763 spin_lock_irqsave(&self->spinlock, flags);
77764 - self->open_count++;
77765 + local_inc(&self->open_count);
77766 spin_unlock_irqrestore(&self->spinlock, flags);
77767 }
77768 - self->blocked_open--;
77769 + local_dec(&self->blocked_open);
77770
77771 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77772 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77773 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77774
77775 if (!retval)
77776 self->flags |= ASYNC_NORMAL_ACTIVE;
77777 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77778 }
77779 /* ++ is not atomic, so this should be protected - Jean II */
77780 spin_lock_irqsave(&self->spinlock, flags);
77781 - self->open_count++;
77782 + local_inc(&self->open_count);
77783
77784 tty->driver_data = self;
77785 self->tty = tty;
77786 spin_unlock_irqrestore(&self->spinlock, flags);
77787
77788 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77789 - self->line, self->open_count);
77790 + self->line, local_read(&self->open_count));
77791
77792 /* Not really used by us, but lets do it anyway */
77793 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77794 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77795 return;
77796 }
77797
77798 - if ((tty->count == 1) && (self->open_count != 1)) {
77799 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77800 /*
77801 * Uh, oh. tty->count is 1, which means that the tty
77802 * structure will be freed. state->count should always
77803 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77804 */
77805 IRDA_DEBUG(0, "%s(), bad serial port count; "
77806 "tty->count is 1, state->count is %d\n", __func__ ,
77807 - self->open_count);
77808 - self->open_count = 1;
77809 + local_read(&self->open_count));
77810 + local_set(&self->open_count, 1);
77811 }
77812
77813 - if (--self->open_count < 0) {
77814 + if (local_dec_return(&self->open_count) < 0) {
77815 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77816 - __func__, self->line, self->open_count);
77817 - self->open_count = 0;
77818 + __func__, self->line, local_read(&self->open_count));
77819 + local_set(&self->open_count, 0);
77820 }
77821 - if (self->open_count) {
77822 + if (local_read(&self->open_count)) {
77823 spin_unlock_irqrestore(&self->spinlock, flags);
77824
77825 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77826 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77827 tty->closing = 0;
77828 self->tty = NULL;
77829
77830 - if (self->blocked_open) {
77831 + if (local_read(&self->blocked_open)) {
77832 if (self->close_delay)
77833 schedule_timeout_interruptible(self->close_delay);
77834 wake_up_interruptible(&self->open_wait);
77835 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77836 spin_lock_irqsave(&self->spinlock, flags);
77837 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77838 self->tty = NULL;
77839 - self->open_count = 0;
77840 + local_set(&self->open_count, 0);
77841 spin_unlock_irqrestore(&self->spinlock, flags);
77842
77843 wake_up_interruptible(&self->open_wait);
77844 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77845 seq_putc(m, '\n');
77846
77847 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77848 - seq_printf(m, "Open count: %d\n", self->open_count);
77849 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77850 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77851 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77852
77853 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77854 index cd6f7a9..e63fe89 100644
77855 --- a/net/iucv/af_iucv.c
77856 +++ b/net/iucv/af_iucv.c
77857 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77858
77859 write_lock_bh(&iucv_sk_list.lock);
77860
77861 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77862 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77863 while (__iucv_get_sock_by_name(name)) {
77864 sprintf(name, "%08x",
77865 - atomic_inc_return(&iucv_sk_list.autobind_name));
77866 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77867 }
77868
77869 write_unlock_bh(&iucv_sk_list.lock);
77870 diff --git a/net/key/af_key.c b/net/key/af_key.c
77871 index 34e4185..8823368 100644
77872 --- a/net/key/af_key.c
77873 +++ b/net/key/af_key.c
77874 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77875 static u32 get_acqseq(void)
77876 {
77877 u32 res;
77878 - static atomic_t acqseq;
77879 + static atomic_unchecked_t acqseq;
77880
77881 do {
77882 - res = atomic_inc_return(&acqseq);
77883 + res = atomic_inc_return_unchecked(&acqseq);
77884 } while (!res);
77885 return res;
77886 }
77887 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77888 index bb61f77..3788d63 100644
77889 --- a/net/mac80211/ieee80211_i.h
77890 +++ b/net/mac80211/ieee80211_i.h
77891 @@ -28,6 +28,7 @@
77892 #include <net/ieee80211_radiotap.h>
77893 #include <net/cfg80211.h>
77894 #include <net/mac80211.h>
77895 +#include <asm/local.h>
77896 #include "key.h"
77897 #include "sta_info.h"
77898 #include "debug.h"
77899 @@ -840,7 +841,7 @@ struct ieee80211_local {
77900 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77901 spinlock_t queue_stop_reason_lock;
77902
77903 - int open_count;
77904 + local_t open_count;
77905 int monitors, cooked_mntrs;
77906 /* number of interfaces with corresponding FIF_ flags */
77907 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77908 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77909 index bfb57dc..77c4b81 100644
77910 --- a/net/mac80211/iface.c
77911 +++ b/net/mac80211/iface.c
77912 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77913 break;
77914 }
77915
77916 - if (local->open_count == 0) {
77917 + if (local_read(&local->open_count) == 0) {
77918 res = drv_start(local);
77919 if (res)
77920 goto err_del_bss;
77921 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77922 break;
77923 }
77924
77925 - if (local->monitors == 0 && local->open_count == 0) {
77926 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77927 res = ieee80211_add_virtual_monitor(local);
77928 if (res)
77929 goto err_stop;
77930 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77931 mutex_unlock(&local->mtx);
77932
77933 if (coming_up)
77934 - local->open_count++;
77935 + local_inc(&local->open_count);
77936
77937 if (hw_reconf_flags)
77938 ieee80211_hw_config(local, hw_reconf_flags);
77939 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77940 err_del_interface:
77941 drv_remove_interface(local, sdata);
77942 err_stop:
77943 - if (!local->open_count)
77944 + if (!local_read(&local->open_count))
77945 drv_stop(local);
77946 err_del_bss:
77947 sdata->bss = NULL;
77948 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77949 }
77950
77951 if (going_down)
77952 - local->open_count--;
77953 + local_dec(&local->open_count);
77954
77955 switch (sdata->vif.type) {
77956 case NL80211_IFTYPE_AP_VLAN:
77957 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77958
77959 ieee80211_recalc_ps(local, -1);
77960
77961 - if (local->open_count == 0) {
77962 + if (local_read(&local->open_count) == 0) {
77963 if (local->ops->napi_poll)
77964 napi_disable(&local->napi);
77965 ieee80211_clear_tx_pending(local);
77966 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77967 }
77968 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77969
77970 - if (local->monitors == local->open_count && local->monitors > 0)
77971 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77972 ieee80211_add_virtual_monitor(local);
77973 }
77974
77975 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77976 index c26e231..8916637 100644
77977 --- a/net/mac80211/main.c
77978 +++ b/net/mac80211/main.c
77979 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77980 local->hw.conf.power_level = power;
77981 }
77982
77983 - if (changed && local->open_count) {
77984 + if (changed && local_read(&local->open_count)) {
77985 ret = drv_config(local, changed);
77986 /*
77987 * Goal:
77988 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77989 index 5c572e7..ecf75ce 100644
77990 --- a/net/mac80211/pm.c
77991 +++ b/net/mac80211/pm.c
77992 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77993 struct ieee80211_sub_if_data *sdata;
77994 struct sta_info *sta;
77995
77996 - if (!local->open_count)
77997 + if (!local_read(&local->open_count))
77998 goto suspend;
77999
78000 ieee80211_scan_cancel(local);
78001 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78002 cancel_work_sync(&local->dynamic_ps_enable_work);
78003 del_timer_sync(&local->dynamic_ps_timer);
78004
78005 - local->wowlan = wowlan && local->open_count;
78006 + local->wowlan = wowlan && local_read(&local->open_count);
78007 if (local->wowlan) {
78008 int err = drv_suspend(local, wowlan);
78009 if (err < 0) {
78010 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78011 drv_remove_interface(local, sdata);
78012
78013 /* stop hardware - this must stop RX */
78014 - if (local->open_count)
78015 + if (local_read(&local->open_count))
78016 ieee80211_stop_device(local);
78017
78018 suspend:
78019 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78020 index 3313c11..bec9f17 100644
78021 --- a/net/mac80211/rate.c
78022 +++ b/net/mac80211/rate.c
78023 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78024
78025 ASSERT_RTNL();
78026
78027 - if (local->open_count)
78028 + if (local_read(&local->open_count))
78029 return -EBUSY;
78030
78031 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78032 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78033 index c97a065..ff61928 100644
78034 --- a/net/mac80211/rc80211_pid_debugfs.c
78035 +++ b/net/mac80211/rc80211_pid_debugfs.c
78036 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78037
78038 spin_unlock_irqrestore(&events->lock, status);
78039
78040 - if (copy_to_user(buf, pb, p))
78041 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78042 return -EFAULT;
78043
78044 return p;
78045 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78046 index 39b82fe..5469ef4 100644
78047 --- a/net/mac80211/util.c
78048 +++ b/net/mac80211/util.c
78049 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78050 }
78051 #endif
78052 /* everything else happens only if HW was up & running */
78053 - if (!local->open_count)
78054 + if (!local_read(&local->open_count))
78055 goto wake_up;
78056
78057 /*
78058 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78059 index c19b214..471fad1 100644
78060 --- a/net/netfilter/Kconfig
78061 +++ b/net/netfilter/Kconfig
78062 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78063
78064 To compile it as a module, choose M here. If unsure, say N.
78065
78066 +config NETFILTER_XT_MATCH_GRADM
78067 + tristate '"gradm" match support'
78068 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78069 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78070 + ---help---
78071 + The gradm match allows to match on grsecurity RBAC being enabled.
78072 + It is useful when iptables rules are applied early on bootup to
78073 + prevent connections to the machine (except from a trusted host)
78074 + while the RBAC system is disabled.
78075 +
78076 config NETFILTER_XT_MATCH_HASHLIMIT
78077 tristate '"hashlimit" match support'
78078 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78079 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78080 index 1c5160f..145ae21 100644
78081 --- a/net/netfilter/Makefile
78082 +++ b/net/netfilter/Makefile
78083 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78084 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78085 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78086 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78087 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78088 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78089 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78090 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78091 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78092 index 1548df9..98ad9b4 100644
78093 --- a/net/netfilter/ipvs/ip_vs_conn.c
78094 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78095 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78096 /* Increase the refcnt counter of the dest */
78097 atomic_inc(&dest->refcnt);
78098
78099 - conn_flags = atomic_read(&dest->conn_flags);
78100 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78101 if (cp->protocol != IPPROTO_UDP)
78102 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78103 flags = cp->flags;
78104 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78105 atomic_set(&cp->refcnt, 1);
78106
78107 atomic_set(&cp->n_control, 0);
78108 - atomic_set(&cp->in_pkts, 0);
78109 + atomic_set_unchecked(&cp->in_pkts, 0);
78110
78111 atomic_inc(&ipvs->conn_count);
78112 if (flags & IP_VS_CONN_F_NO_CPORT)
78113 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78114
78115 /* Don't drop the entry if its number of incoming packets is not
78116 located in [0, 8] */
78117 - i = atomic_read(&cp->in_pkts);
78118 + i = atomic_read_unchecked(&cp->in_pkts);
78119 if (i > 8 || i < 0) return 0;
78120
78121 if (!todrop_rate[i]) return 0;
78122 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78123 index b54ecce..fc5f6cf 100644
78124 --- a/net/netfilter/ipvs/ip_vs_core.c
78125 +++ b/net/netfilter/ipvs/ip_vs_core.c
78126 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78127 ret = cp->packet_xmit(skb, cp, pd->pp);
78128 /* do not touch skb anymore */
78129
78130 - atomic_inc(&cp->in_pkts);
78131 + atomic_inc_unchecked(&cp->in_pkts);
78132 ip_vs_conn_put(cp);
78133 return ret;
78134 }
78135 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78136 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78137 pkts = sysctl_sync_threshold(ipvs);
78138 else
78139 - pkts = atomic_add_return(1, &cp->in_pkts);
78140 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78141
78142 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78143 ip_vs_sync_conn(net, cp, pkts);
78144 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78145 index f51013c..c99ee52 100644
78146 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78147 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78148 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78149 ip_vs_rs_hash(ipvs, dest);
78150 write_unlock_bh(&ipvs->rs_lock);
78151 }
78152 - atomic_set(&dest->conn_flags, conn_flags);
78153 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78154
78155 /* bind the service */
78156 if (!dest->svc) {
78157 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78158 " %-7s %-6d %-10d %-10d\n",
78159 &dest->addr.in6,
78160 ntohs(dest->port),
78161 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78162 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78163 atomic_read(&dest->weight),
78164 atomic_read(&dest->activeconns),
78165 atomic_read(&dest->inactconns));
78166 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78167 "%-7s %-6d %-10d %-10d\n",
78168 ntohl(dest->addr.ip),
78169 ntohs(dest->port),
78170 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78171 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78172 atomic_read(&dest->weight),
78173 atomic_read(&dest->activeconns),
78174 atomic_read(&dest->inactconns));
78175 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78176
78177 entry.addr = dest->addr.ip;
78178 entry.port = dest->port;
78179 - entry.conn_flags = atomic_read(&dest->conn_flags);
78180 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78181 entry.weight = atomic_read(&dest->weight);
78182 entry.u_threshold = dest->u_threshold;
78183 entry.l_threshold = dest->l_threshold;
78184 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78185 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78186 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78187 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78188 - (atomic_read(&dest->conn_flags) &
78189 + (atomic_read_unchecked(&dest->conn_flags) &
78190 IP_VS_CONN_F_FWD_MASK)) ||
78191 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78192 atomic_read(&dest->weight)) ||
78193 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78194 index effa10c..9058928 100644
78195 --- a/net/netfilter/ipvs/ip_vs_sync.c
78196 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78197 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78198 cp = cp->control;
78199 if (cp) {
78200 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78201 - pkts = atomic_add_return(1, &cp->in_pkts);
78202 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78203 else
78204 pkts = sysctl_sync_threshold(ipvs);
78205 ip_vs_sync_conn(net, cp->control, pkts);
78206 @@ -758,7 +758,7 @@ control:
78207 if (!cp)
78208 return;
78209 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78210 - pkts = atomic_add_return(1, &cp->in_pkts);
78211 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78212 else
78213 pkts = sysctl_sync_threshold(ipvs);
78214 goto sloop;
78215 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78216
78217 if (opt)
78218 memcpy(&cp->in_seq, opt, sizeof(*opt));
78219 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78220 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78221 cp->state = state;
78222 cp->old_state = cp->state;
78223 /*
78224 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78225 index 65b616a..760a66b 100644
78226 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78227 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78228 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78229 else
78230 rc = NF_ACCEPT;
78231 /* do not touch skb anymore */
78232 - atomic_inc(&cp->in_pkts);
78233 + atomic_inc_unchecked(&cp->in_pkts);
78234 goto out;
78235 }
78236
78237 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78238 else
78239 rc = NF_ACCEPT;
78240 /* do not touch skb anymore */
78241 - atomic_inc(&cp->in_pkts);
78242 + atomic_inc_unchecked(&cp->in_pkts);
78243 goto out;
78244 }
78245
78246 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78247 index 2ceec64..a5b8a61 100644
78248 --- a/net/netfilter/nf_conntrack_core.c
78249 +++ b/net/netfilter/nf_conntrack_core.c
78250 @@ -1529,6 +1529,10 @@ err_extend:
78251 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78252 #define DYING_NULLS_VAL ((1<<30)+1)
78253
78254 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78255 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78256 +#endif
78257 +
78258 static int nf_conntrack_init_net(struct net *net)
78259 {
78260 int ret;
78261 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78262 goto err_stat;
78263 }
78264
78265 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78266 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78267 +#else
78268 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78269 +#endif
78270 if (!net->ct.slabname) {
78271 ret = -ENOMEM;
78272 goto err_slabname;
78273 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78274 index 5cfb5be..217c6d8 100644
78275 --- a/net/netfilter/nfnetlink_log.c
78276 +++ b/net/netfilter/nfnetlink_log.c
78277 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78278 };
78279
78280 static DEFINE_SPINLOCK(instances_lock);
78281 -static atomic_t global_seq;
78282 +static atomic_unchecked_t global_seq;
78283
78284 #define INSTANCE_BUCKETS 16
78285 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78286 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78287 /* global sequence number */
78288 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78289 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78290 - htonl(atomic_inc_return(&global_seq))))
78291 + htonl(atomic_inc_return_unchecked(&global_seq))))
78292 goto nla_put_failure;
78293
78294 if (data_len) {
78295 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78296 new file mode 100644
78297 index 0000000..6905327
78298 --- /dev/null
78299 +++ b/net/netfilter/xt_gradm.c
78300 @@ -0,0 +1,51 @@
78301 +/*
78302 + * gradm match for netfilter
78303 + * Copyright © Zbigniew Krzystolik, 2010
78304 + *
78305 + * This program is free software; you can redistribute it and/or modify
78306 + * it under the terms of the GNU General Public License; either version
78307 + * 2 or 3 as published by the Free Software Foundation.
78308 + */
78309 +#include <linux/module.h>
78310 +#include <linux/moduleparam.h>
78311 +#include <linux/skbuff.h>
78312 +#include <linux/netfilter/x_tables.h>
78313 +#include <linux/grsecurity.h>
78314 +#include <linux/netfilter/xt_gradm.h>
78315 +
78316 +static bool
78317 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78318 +{
78319 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78320 + bool retval = false;
78321 + if (gr_acl_is_enabled())
78322 + retval = true;
78323 + return retval ^ info->invflags;
78324 +}
78325 +
78326 +static struct xt_match gradm_mt_reg __read_mostly = {
78327 + .name = "gradm",
78328 + .revision = 0,
78329 + .family = NFPROTO_UNSPEC,
78330 + .match = gradm_mt,
78331 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78332 + .me = THIS_MODULE,
78333 +};
78334 +
78335 +static int __init gradm_mt_init(void)
78336 +{
78337 + return xt_register_match(&gradm_mt_reg);
78338 +}
78339 +
78340 +static void __exit gradm_mt_exit(void)
78341 +{
78342 + xt_unregister_match(&gradm_mt_reg);
78343 +}
78344 +
78345 +module_init(gradm_mt_init);
78346 +module_exit(gradm_mt_exit);
78347 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78348 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78349 +MODULE_LICENSE("GPL");
78350 +MODULE_ALIAS("ipt_gradm");
78351 +MODULE_ALIAS("ip6t_gradm");
78352 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78353 index 4fe4fb4..87a89e5 100644
78354 --- a/net/netfilter/xt_statistic.c
78355 +++ b/net/netfilter/xt_statistic.c
78356 @@ -19,7 +19,7 @@
78357 #include <linux/module.h>
78358
78359 struct xt_statistic_priv {
78360 - atomic_t count;
78361 + atomic_unchecked_t count;
78362 } ____cacheline_aligned_in_smp;
78363
78364 MODULE_LICENSE("GPL");
78365 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78366 break;
78367 case XT_STATISTIC_MODE_NTH:
78368 do {
78369 - oval = atomic_read(&info->master->count);
78370 + oval = atomic_read_unchecked(&info->master->count);
78371 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78372 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78373 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78374 if (nval == 0)
78375 ret = !ret;
78376 break;
78377 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78378 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78379 if (info->master == NULL)
78380 return -ENOMEM;
78381 - atomic_set(&info->master->count, info->u.nth.count);
78382 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78383
78384 return 0;
78385 }
78386 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78387 index 5270238..5d37fbc 100644
78388 --- a/net/netlink/af_netlink.c
78389 +++ b/net/netlink/af_netlink.c
78390 @@ -767,7 +767,7 @@ static void netlink_overrun(struct sock *sk)
78391 sk->sk_error_report(sk);
78392 }
78393 }
78394 - atomic_inc(&sk->sk_drops);
78395 + atomic_inc_unchecked(&sk->sk_drops);
78396 }
78397
78398 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78399 @@ -2046,7 +2046,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78400 sk_wmem_alloc_get(s),
78401 nlk->cb,
78402 atomic_read(&s->sk_refcnt),
78403 - atomic_read(&s->sk_drops),
78404 + atomic_read_unchecked(&s->sk_drops),
78405 sock_i_ino(s)
78406 );
78407
78408 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78409 index 7261eb8..44e8ac6 100644
78410 --- a/net/netrom/af_netrom.c
78411 +++ b/net/netrom/af_netrom.c
78412 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78413 struct sock *sk = sock->sk;
78414 struct nr_sock *nr = nr_sk(sk);
78415
78416 + memset(sax, 0, sizeof(*sax));
78417 lock_sock(sk);
78418 if (peer != 0) {
78419 if (sk->sk_state != TCP_ESTABLISHED) {
78420 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78421 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78422 } else {
78423 sax->fsa_ax25.sax25_family = AF_NETROM;
78424 - sax->fsa_ax25.sax25_ndigis = 0;
78425 sax->fsa_ax25.sax25_call = nr->source_addr;
78426 *uaddr_len = sizeof(struct sockaddr_ax25);
78427 }
78428 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78429 index c5c9e2a..4814ab1 100644
78430 --- a/net/packet/af_packet.c
78431 +++ b/net/packet/af_packet.c
78432 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78433
78434 spin_lock(&sk->sk_receive_queue.lock);
78435 po->stats.tp_packets++;
78436 - skb->dropcount = atomic_read(&sk->sk_drops);
78437 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78438 __skb_queue_tail(&sk->sk_receive_queue, skb);
78439 spin_unlock(&sk->sk_receive_queue.lock);
78440 sk->sk_data_ready(sk, skb->len);
78441 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78442 drop_n_acct:
78443 spin_lock(&sk->sk_receive_queue.lock);
78444 po->stats.tp_drops++;
78445 - atomic_inc(&sk->sk_drops);
78446 + atomic_inc_unchecked(&sk->sk_drops);
78447 spin_unlock(&sk->sk_receive_queue.lock);
78448
78449 drop_n_restore:
78450 @@ -2642,6 +2642,7 @@ out:
78451
78452 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78453 {
78454 + struct sock_extended_err ee;
78455 struct sock_exterr_skb *serr;
78456 struct sk_buff *skb, *skb2;
78457 int copied, err;
78458 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78459 sock_recv_timestamp(msg, sk, skb);
78460
78461 serr = SKB_EXT_ERR(skb);
78462 + ee = serr->ee;
78463 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78464 - sizeof(serr->ee), &serr->ee);
78465 + sizeof ee, &ee);
78466
78467 msg->msg_flags |= MSG_ERRQUEUE;
78468 err = copied;
78469 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78470 case PACKET_HDRLEN:
78471 if (len > sizeof(int))
78472 len = sizeof(int);
78473 - if (copy_from_user(&val, optval, len))
78474 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78475 return -EFAULT;
78476 switch (val) {
78477 case TPACKET_V1:
78478 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78479 len = lv;
78480 if (put_user(len, optlen))
78481 return -EFAULT;
78482 - if (copy_to_user(optval, data, len))
78483 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78484 return -EFAULT;
78485 return 0;
78486 }
78487 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78488 index 5a940db..f0b9c12 100644
78489 --- a/net/phonet/af_phonet.c
78490 +++ b/net/phonet/af_phonet.c
78491 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78492 {
78493 struct phonet_protocol *pp;
78494
78495 - if (protocol >= PHONET_NPROTO)
78496 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78497 return NULL;
78498
78499 rcu_read_lock();
78500 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78501 {
78502 int err = 0;
78503
78504 - if (protocol >= PHONET_NPROTO)
78505 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78506 return -EINVAL;
78507
78508 err = proto_register(pp->prot, 1);
78509 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78510 index 576f22c..bc7a71b 100644
78511 --- a/net/phonet/pep.c
78512 +++ b/net/phonet/pep.c
78513 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78514
78515 case PNS_PEP_CTRL_REQ:
78516 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78517 - atomic_inc(&sk->sk_drops);
78518 + atomic_inc_unchecked(&sk->sk_drops);
78519 break;
78520 }
78521 __skb_pull(skb, 4);
78522 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78523 }
78524
78525 if (pn->rx_credits == 0) {
78526 - atomic_inc(&sk->sk_drops);
78527 + atomic_inc_unchecked(&sk->sk_drops);
78528 err = -ENOBUFS;
78529 break;
78530 }
78531 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78532 }
78533
78534 if (pn->rx_credits == 0) {
78535 - atomic_inc(&sk->sk_drops);
78536 + atomic_inc_unchecked(&sk->sk_drops);
78537 err = NET_RX_DROP;
78538 break;
78539 }
78540 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78541 index 0acc943..c727611 100644
78542 --- a/net/phonet/socket.c
78543 +++ b/net/phonet/socket.c
78544 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78545 pn->resource, sk->sk_state,
78546 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78547 sock_i_uid(sk), sock_i_ino(sk),
78548 - atomic_read(&sk->sk_refcnt), sk,
78549 - atomic_read(&sk->sk_drops), &len);
78550 + atomic_read(&sk->sk_refcnt),
78551 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78552 + NULL,
78553 +#else
78554 + sk,
78555 +#endif
78556 + atomic_read_unchecked(&sk->sk_drops), &len);
78557 }
78558 seq_printf(seq, "%*s\n", 127 - len, "");
78559 return 0;
78560 diff --git a/net/rds/cong.c b/net/rds/cong.c
78561 index e5b65ac..f3b6fb7 100644
78562 --- a/net/rds/cong.c
78563 +++ b/net/rds/cong.c
78564 @@ -78,7 +78,7 @@
78565 * finds that the saved generation number is smaller than the global generation
78566 * number, it wakes up the process.
78567 */
78568 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78569 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78570
78571 /*
78572 * Congestion monitoring
78573 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78574 rdsdebug("waking map %p for %pI4\n",
78575 map, &map->m_addr);
78576 rds_stats_inc(s_cong_update_received);
78577 - atomic_inc(&rds_cong_generation);
78578 + atomic_inc_unchecked(&rds_cong_generation);
78579 if (waitqueue_active(&map->m_waitq))
78580 wake_up(&map->m_waitq);
78581 if (waitqueue_active(&rds_poll_waitq))
78582 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78583
78584 int rds_cong_updated_since(unsigned long *recent)
78585 {
78586 - unsigned long gen = atomic_read(&rds_cong_generation);
78587 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78588
78589 if (likely(*recent == gen))
78590 return 0;
78591 diff --git a/net/rds/ib.h b/net/rds/ib.h
78592 index 8d2b3d5..227ec5b 100644
78593 --- a/net/rds/ib.h
78594 +++ b/net/rds/ib.h
78595 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78596 /* sending acks */
78597 unsigned long i_ack_flags;
78598 #ifdef KERNEL_HAS_ATOMIC64
78599 - atomic64_t i_ack_next; /* next ACK to send */
78600 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78601 #else
78602 spinlock_t i_ack_lock; /* protect i_ack_next */
78603 u64 i_ack_next; /* next ACK to send */
78604 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78605 index a1e1162..265e129 100644
78606 --- a/net/rds/ib_cm.c
78607 +++ b/net/rds/ib_cm.c
78608 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78609 /* Clear the ACK state */
78610 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78611 #ifdef KERNEL_HAS_ATOMIC64
78612 - atomic64_set(&ic->i_ack_next, 0);
78613 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78614 #else
78615 ic->i_ack_next = 0;
78616 #endif
78617 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78618 index 8d19491..05a3e65 100644
78619 --- a/net/rds/ib_recv.c
78620 +++ b/net/rds/ib_recv.c
78621 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78622 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78623 int ack_required)
78624 {
78625 - atomic64_set(&ic->i_ack_next, seq);
78626 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78627 if (ack_required) {
78628 smp_mb__before_clear_bit();
78629 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78630 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78631 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78632 smp_mb__after_clear_bit();
78633
78634 - return atomic64_read(&ic->i_ack_next);
78635 + return atomic64_read_unchecked(&ic->i_ack_next);
78636 }
78637 #endif
78638
78639 diff --git a/net/rds/iw.h b/net/rds/iw.h
78640 index 04ce3b1..48119a6 100644
78641 --- a/net/rds/iw.h
78642 +++ b/net/rds/iw.h
78643 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78644 /* sending acks */
78645 unsigned long i_ack_flags;
78646 #ifdef KERNEL_HAS_ATOMIC64
78647 - atomic64_t i_ack_next; /* next ACK to send */
78648 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78649 #else
78650 spinlock_t i_ack_lock; /* protect i_ack_next */
78651 u64 i_ack_next; /* next ACK to send */
78652 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78653 index a91e1db..cf3053f 100644
78654 --- a/net/rds/iw_cm.c
78655 +++ b/net/rds/iw_cm.c
78656 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78657 /* Clear the ACK state */
78658 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78659 #ifdef KERNEL_HAS_ATOMIC64
78660 - atomic64_set(&ic->i_ack_next, 0);
78661 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78662 #else
78663 ic->i_ack_next = 0;
78664 #endif
78665 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78666 index 4503335..db566b4 100644
78667 --- a/net/rds/iw_recv.c
78668 +++ b/net/rds/iw_recv.c
78669 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78670 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78671 int ack_required)
78672 {
78673 - atomic64_set(&ic->i_ack_next, seq);
78674 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78675 if (ack_required) {
78676 smp_mb__before_clear_bit();
78677 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78678 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78679 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78680 smp_mb__after_clear_bit();
78681
78682 - return atomic64_read(&ic->i_ack_next);
78683 + return atomic64_read_unchecked(&ic->i_ack_next);
78684 }
78685 #endif
78686
78687 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78688 index edac9ef..16bcb98 100644
78689 --- a/net/rds/tcp.c
78690 +++ b/net/rds/tcp.c
78691 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78692 int val = 1;
78693
78694 set_fs(KERNEL_DS);
78695 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78696 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78697 sizeof(val));
78698 set_fs(oldfs);
78699 }
78700 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78701 index 1b4fd68..2234175 100644
78702 --- a/net/rds/tcp_send.c
78703 +++ b/net/rds/tcp_send.c
78704 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78705
78706 oldfs = get_fs();
78707 set_fs(KERNEL_DS);
78708 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78709 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78710 sizeof(val));
78711 set_fs(oldfs);
78712 }
78713 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78714 index 05996d0..5a1dfe0 100644
78715 --- a/net/rxrpc/af_rxrpc.c
78716 +++ b/net/rxrpc/af_rxrpc.c
78717 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78718 __be32 rxrpc_epoch;
78719
78720 /* current debugging ID */
78721 -atomic_t rxrpc_debug_id;
78722 +atomic_unchecked_t rxrpc_debug_id;
78723
78724 /* count of skbs currently in use */
78725 atomic_t rxrpc_n_skbs;
78726 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78727 index e4d9cbc..b229649 100644
78728 --- a/net/rxrpc/ar-ack.c
78729 +++ b/net/rxrpc/ar-ack.c
78730 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78731
78732 _enter("{%d,%d,%d,%d},",
78733 call->acks_hard, call->acks_unacked,
78734 - atomic_read(&call->sequence),
78735 + atomic_read_unchecked(&call->sequence),
78736 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78737
78738 stop = 0;
78739 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78740
78741 /* each Tx packet has a new serial number */
78742 sp->hdr.serial =
78743 - htonl(atomic_inc_return(&call->conn->serial));
78744 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78745
78746 hdr = (struct rxrpc_header *) txb->head;
78747 hdr->serial = sp->hdr.serial;
78748 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78749 */
78750 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78751 {
78752 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78753 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78754 }
78755
78756 /*
78757 @@ -629,7 +629,7 @@ process_further:
78758
78759 latest = ntohl(sp->hdr.serial);
78760 hard = ntohl(ack.firstPacket);
78761 - tx = atomic_read(&call->sequence);
78762 + tx = atomic_read_unchecked(&call->sequence);
78763
78764 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78765 latest,
78766 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78767 goto maybe_reschedule;
78768
78769 send_ACK_with_skew:
78770 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78771 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78772 ntohl(ack.serial));
78773 send_ACK:
78774 mtu = call->conn->trans->peer->if_mtu;
78775 @@ -1173,7 +1173,7 @@ send_ACK:
78776 ackinfo.rxMTU = htonl(5692);
78777 ackinfo.jumbo_max = htonl(4);
78778
78779 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78780 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78781 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78782 ntohl(hdr.serial),
78783 ntohs(ack.maxSkew),
78784 @@ -1191,7 +1191,7 @@ send_ACK:
78785 send_message:
78786 _debug("send message");
78787
78788 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78789 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78790 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78791 send_message_2:
78792
78793 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78794 index a3bbb36..3341fb9 100644
78795 --- a/net/rxrpc/ar-call.c
78796 +++ b/net/rxrpc/ar-call.c
78797 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78798 spin_lock_init(&call->lock);
78799 rwlock_init(&call->state_lock);
78800 atomic_set(&call->usage, 1);
78801 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78802 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78803 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78804
78805 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78806 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78807 index 4106ca9..a338d7a 100644
78808 --- a/net/rxrpc/ar-connection.c
78809 +++ b/net/rxrpc/ar-connection.c
78810 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78811 rwlock_init(&conn->lock);
78812 spin_lock_init(&conn->state_lock);
78813 atomic_set(&conn->usage, 1);
78814 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78815 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78816 conn->avail_calls = RXRPC_MAXCALLS;
78817 conn->size_align = 4;
78818 conn->header_size = sizeof(struct rxrpc_header);
78819 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78820 index e7ed43a..6afa140 100644
78821 --- a/net/rxrpc/ar-connevent.c
78822 +++ b/net/rxrpc/ar-connevent.c
78823 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78824
78825 len = iov[0].iov_len + iov[1].iov_len;
78826
78827 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78828 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78829 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78830
78831 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78832 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78833 index 529572f..c758ca7 100644
78834 --- a/net/rxrpc/ar-input.c
78835 +++ b/net/rxrpc/ar-input.c
78836 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78837 /* track the latest serial number on this connection for ACK packet
78838 * information */
78839 serial = ntohl(sp->hdr.serial);
78840 - hi_serial = atomic_read(&call->conn->hi_serial);
78841 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78842 while (serial > hi_serial)
78843 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78844 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78845 serial);
78846
78847 /* request ACK generation for any ACK or DATA packet that requests
78848 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78849 index a693aca..81e7293 100644
78850 --- a/net/rxrpc/ar-internal.h
78851 +++ b/net/rxrpc/ar-internal.h
78852 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78853 int error; /* error code for local abort */
78854 int debug_id; /* debug ID for printks */
78855 unsigned int call_counter; /* call ID counter */
78856 - atomic_t serial; /* packet serial number counter */
78857 - atomic_t hi_serial; /* highest serial number received */
78858 + atomic_unchecked_t serial; /* packet serial number counter */
78859 + atomic_unchecked_t hi_serial; /* highest serial number received */
78860 u8 avail_calls; /* number of calls available */
78861 u8 size_align; /* data size alignment (for security) */
78862 u8 header_size; /* rxrpc + security header size */
78863 @@ -346,7 +346,7 @@ struct rxrpc_call {
78864 spinlock_t lock;
78865 rwlock_t state_lock; /* lock for state transition */
78866 atomic_t usage;
78867 - atomic_t sequence; /* Tx data packet sequence counter */
78868 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78869 u32 abort_code; /* local/remote abort code */
78870 enum { /* current state of call */
78871 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78872 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78873 */
78874 extern atomic_t rxrpc_n_skbs;
78875 extern __be32 rxrpc_epoch;
78876 -extern atomic_t rxrpc_debug_id;
78877 +extern atomic_unchecked_t rxrpc_debug_id;
78878 extern struct workqueue_struct *rxrpc_workqueue;
78879
78880 /*
78881 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78882 index 87f7135..74d3703 100644
78883 --- a/net/rxrpc/ar-local.c
78884 +++ b/net/rxrpc/ar-local.c
78885 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78886 spin_lock_init(&local->lock);
78887 rwlock_init(&local->services_lock);
78888 atomic_set(&local->usage, 1);
78889 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78890 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78891 memcpy(&local->srx, srx, sizeof(*srx));
78892 }
78893
78894 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78895 index e1ac183..b43e10e 100644
78896 --- a/net/rxrpc/ar-output.c
78897 +++ b/net/rxrpc/ar-output.c
78898 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78899 sp->hdr.cid = call->cid;
78900 sp->hdr.callNumber = call->call_id;
78901 sp->hdr.seq =
78902 - htonl(atomic_inc_return(&call->sequence));
78903 + htonl(atomic_inc_return_unchecked(&call->sequence));
78904 sp->hdr.serial =
78905 - htonl(atomic_inc_return(&conn->serial));
78906 + htonl(atomic_inc_return_unchecked(&conn->serial));
78907 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78908 sp->hdr.userStatus = 0;
78909 sp->hdr.securityIndex = conn->security_ix;
78910 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78911 index bebaa43..2644591 100644
78912 --- a/net/rxrpc/ar-peer.c
78913 +++ b/net/rxrpc/ar-peer.c
78914 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78915 INIT_LIST_HEAD(&peer->error_targets);
78916 spin_lock_init(&peer->lock);
78917 atomic_set(&peer->usage, 1);
78918 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78919 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78920 memcpy(&peer->srx, srx, sizeof(*srx));
78921
78922 rxrpc_assess_MTU_size(peer);
78923 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78924 index 38047f7..9f48511 100644
78925 --- a/net/rxrpc/ar-proc.c
78926 +++ b/net/rxrpc/ar-proc.c
78927 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78928 atomic_read(&conn->usage),
78929 rxrpc_conn_states[conn->state],
78930 key_serial(conn->key),
78931 - atomic_read(&conn->serial),
78932 - atomic_read(&conn->hi_serial));
78933 + atomic_read_unchecked(&conn->serial),
78934 + atomic_read_unchecked(&conn->hi_serial));
78935
78936 return 0;
78937 }
78938 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78939 index 92df566..87ec1bf 100644
78940 --- a/net/rxrpc/ar-transport.c
78941 +++ b/net/rxrpc/ar-transport.c
78942 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78943 spin_lock_init(&trans->client_lock);
78944 rwlock_init(&trans->conn_lock);
78945 atomic_set(&trans->usage, 1);
78946 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78947 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78948
78949 if (peer->srx.transport.family == AF_INET) {
78950 switch (peer->srx.transport_type) {
78951 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78952 index f226709..0e735a8 100644
78953 --- a/net/rxrpc/rxkad.c
78954 +++ b/net/rxrpc/rxkad.c
78955 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78956
78957 len = iov[0].iov_len + iov[1].iov_len;
78958
78959 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78960 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78961 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78962
78963 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78964 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78965
78966 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78967
78968 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78969 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78970 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78971
78972 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78973 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78974 index 1e2eee8..ce3967e 100644
78975 --- a/net/sctp/proc.c
78976 +++ b/net/sctp/proc.c
78977 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78978 seq_printf(seq,
78979 "%8pK %8pK %-3d %-3d %-2d %-4d "
78980 "%4d %8d %8d %7d %5lu %-5d %5d ",
78981 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78982 + assoc, sk,
78983 + sctp_sk(sk)->type, sk->sk_state,
78984 assoc->state, hash,
78985 assoc->assoc_id,
78986 assoc->sndbuf_used,
78987 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78988 index 5e25981..dbda919 100644
78989 --- a/net/sctp/socket.c
78990 +++ b/net/sctp/socket.c
78991 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78992 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78993 if (space_left < addrlen)
78994 return -ENOMEM;
78995 + if (addrlen > sizeof(temp) || addrlen < 0)
78996 + return -EFAULT;
78997 if (copy_to_user(to, &temp, addrlen))
78998 return -EFAULT;
78999 to += addrlen;
79000 diff --git a/net/socket.c b/net/socket.c
79001 index edc3c4a..4b4e4a8 100644
79002 --- a/net/socket.c
79003 +++ b/net/socket.c
79004 @@ -88,6 +88,7 @@
79005 #include <linux/nsproxy.h>
79006 #include <linux/magic.h>
79007 #include <linux/slab.h>
79008 +#include <linux/in.h>
79009
79010 #include <asm/uaccess.h>
79011 #include <asm/unistd.h>
79012 @@ -105,6 +106,8 @@
79013 #include <linux/sockios.h>
79014 #include <linux/atalk.h>
79015
79016 +#include <linux/grsock.h>
79017 +
79018 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79019 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79020 unsigned long nr_segs, loff_t pos);
79021 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79022 &sockfs_dentry_operations, SOCKFS_MAGIC);
79023 }
79024
79025 -static struct vfsmount *sock_mnt __read_mostly;
79026 +struct vfsmount *sock_mnt __read_mostly;
79027
79028 static struct file_system_type sock_fs_type = {
79029 .name = "sockfs",
79030 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79031 return -EAFNOSUPPORT;
79032 if (type < 0 || type >= SOCK_MAX)
79033 return -EINVAL;
79034 + if (protocol < 0)
79035 + return -EINVAL;
79036
79037 /* Compatibility.
79038
79039 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79040 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79041 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79042
79043 + if(!gr_search_socket(family, type, protocol)) {
79044 + retval = -EACCES;
79045 + goto out;
79046 + }
79047 +
79048 + if (gr_handle_sock_all(family, type, protocol)) {
79049 + retval = -EACCES;
79050 + goto out;
79051 + }
79052 +
79053 retval = sock_create(family, type, protocol, &sock);
79054 if (retval < 0)
79055 goto out;
79056 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79057 if (sock) {
79058 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79059 if (err >= 0) {
79060 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79061 + err = -EACCES;
79062 + goto error;
79063 + }
79064 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79065 + if (err)
79066 + goto error;
79067 +
79068 err = security_socket_bind(sock,
79069 (struct sockaddr *)&address,
79070 addrlen);
79071 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79072 (struct sockaddr *)
79073 &address, addrlen);
79074 }
79075 +error:
79076 fput_light(sock->file, fput_needed);
79077 }
79078 return err;
79079 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79080 if ((unsigned int)backlog > somaxconn)
79081 backlog = somaxconn;
79082
79083 + if (gr_handle_sock_server_other(sock->sk)) {
79084 + err = -EPERM;
79085 + goto error;
79086 + }
79087 +
79088 + err = gr_search_listen(sock);
79089 + if (err)
79090 + goto error;
79091 +
79092 err = security_socket_listen(sock, backlog);
79093 if (!err)
79094 err = sock->ops->listen(sock, backlog);
79095
79096 +error:
79097 fput_light(sock->file, fput_needed);
79098 }
79099 return err;
79100 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79101 newsock->type = sock->type;
79102 newsock->ops = sock->ops;
79103
79104 + if (gr_handle_sock_server_other(sock->sk)) {
79105 + err = -EPERM;
79106 + sock_release(newsock);
79107 + goto out_put;
79108 + }
79109 +
79110 + err = gr_search_accept(sock);
79111 + if (err) {
79112 + sock_release(newsock);
79113 + goto out_put;
79114 + }
79115 +
79116 /*
79117 * We don't need try_module_get here, as the listening socket (sock)
79118 * has the protocol module (sock->ops->owner) held.
79119 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79120 fd_install(newfd, newfile);
79121 err = newfd;
79122
79123 + gr_attach_curr_ip(newsock->sk);
79124 +
79125 out_put:
79126 fput_light(sock->file, fput_needed);
79127 out:
79128 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79129 int, addrlen)
79130 {
79131 struct socket *sock;
79132 + struct sockaddr *sck;
79133 struct sockaddr_storage address;
79134 int err, fput_needed;
79135
79136 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79137 if (err < 0)
79138 goto out_put;
79139
79140 + sck = (struct sockaddr *)&address;
79141 +
79142 + if (gr_handle_sock_client(sck)) {
79143 + err = -EACCES;
79144 + goto out_put;
79145 + }
79146 +
79147 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79148 + if (err)
79149 + goto out_put;
79150 +
79151 err =
79152 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79153 if (err)
79154 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79155 * checking falls down on this.
79156 */
79157 if (copy_from_user(ctl_buf,
79158 - (void __user __force *)msg_sys->msg_control,
79159 + (void __force_user *)msg_sys->msg_control,
79160 ctl_len))
79161 goto out_freectl;
79162 msg_sys->msg_control = ctl_buf;
79163 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79164 * kernel msghdr to use the kernel address space)
79165 */
79166
79167 - uaddr = (__force void __user *)msg_sys->msg_name;
79168 + uaddr = (void __force_user *)msg_sys->msg_name;
79169 uaddr_len = COMPAT_NAMELEN(msg);
79170 if (MSG_CMSG_COMPAT & flags) {
79171 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79172 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79173 }
79174
79175 ifr = compat_alloc_user_space(buf_size);
79176 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79177 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79178
79179 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79180 return -EFAULT;
79181 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79182 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79183
79184 if (copy_in_user(rxnfc, compat_rxnfc,
79185 - (void *)(&rxnfc->fs.m_ext + 1) -
79186 - (void *)rxnfc) ||
79187 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79188 + (void __user *)rxnfc) ||
79189 copy_in_user(&rxnfc->fs.ring_cookie,
79190 &compat_rxnfc->fs.ring_cookie,
79191 - (void *)(&rxnfc->fs.location + 1) -
79192 - (void *)&rxnfc->fs.ring_cookie) ||
79193 + (void __user *)(&rxnfc->fs.location + 1) -
79194 + (void __user *)&rxnfc->fs.ring_cookie) ||
79195 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79196 sizeof(rxnfc->rule_cnt)))
79197 return -EFAULT;
79198 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79199
79200 if (convert_out) {
79201 if (copy_in_user(compat_rxnfc, rxnfc,
79202 - (const void *)(&rxnfc->fs.m_ext + 1) -
79203 - (const void *)rxnfc) ||
79204 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79205 + (const void __user *)rxnfc) ||
79206 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79207 &rxnfc->fs.ring_cookie,
79208 - (const void *)(&rxnfc->fs.location + 1) -
79209 - (const void *)&rxnfc->fs.ring_cookie) ||
79210 + (const void __user *)(&rxnfc->fs.location + 1) -
79211 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79212 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79213 sizeof(rxnfc->rule_cnt)))
79214 return -EFAULT;
79215 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79216 old_fs = get_fs();
79217 set_fs(KERNEL_DS);
79218 err = dev_ioctl(net, cmd,
79219 - (struct ifreq __user __force *) &kifr);
79220 + (struct ifreq __force_user *) &kifr);
79221 set_fs(old_fs);
79222
79223 return err;
79224 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79225
79226 old_fs = get_fs();
79227 set_fs(KERNEL_DS);
79228 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79229 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79230 set_fs(old_fs);
79231
79232 if (cmd == SIOCGIFMAP && !err) {
79233 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79234 ret |= __get_user(rtdev, &(ur4->rt_dev));
79235 if (rtdev) {
79236 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79237 - r4.rt_dev = (char __user __force *)devname;
79238 + r4.rt_dev = (char __force_user *)devname;
79239 devname[15] = 0;
79240 } else
79241 r4.rt_dev = NULL;
79242 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79243 int __user *uoptlen;
79244 int err;
79245
79246 - uoptval = (char __user __force *) optval;
79247 - uoptlen = (int __user __force *) optlen;
79248 + uoptval = (char __force_user *) optval;
79249 + uoptlen = (int __force_user *) optlen;
79250
79251 set_fs(KERNEL_DS);
79252 if (level == SOL_SOCKET)
79253 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79254 char __user *uoptval;
79255 int err;
79256
79257 - uoptval = (char __user __force *) optval;
79258 + uoptval = (char __force_user *) optval;
79259
79260 set_fs(KERNEL_DS);
79261 if (level == SOL_SOCKET)
79262 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79263 index 128494e..775d0e0 100644
79264 --- a/net/sunrpc/sched.c
79265 +++ b/net/sunrpc/sched.c
79266 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79267 #ifdef RPC_DEBUG
79268 static void rpc_task_set_debuginfo(struct rpc_task *task)
79269 {
79270 - static atomic_t rpc_pid;
79271 + static atomic_unchecked_t rpc_pid;
79272
79273 - task->tk_pid = atomic_inc_return(&rpc_pid);
79274 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79275 }
79276 #else
79277 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79278 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79279 index 8343737..677025e 100644
79280 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79281 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79282 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79283 static unsigned int min_max_inline = 4096;
79284 static unsigned int max_max_inline = 65536;
79285
79286 -atomic_t rdma_stat_recv;
79287 -atomic_t rdma_stat_read;
79288 -atomic_t rdma_stat_write;
79289 -atomic_t rdma_stat_sq_starve;
79290 -atomic_t rdma_stat_rq_starve;
79291 -atomic_t rdma_stat_rq_poll;
79292 -atomic_t rdma_stat_rq_prod;
79293 -atomic_t rdma_stat_sq_poll;
79294 -atomic_t rdma_stat_sq_prod;
79295 +atomic_unchecked_t rdma_stat_recv;
79296 +atomic_unchecked_t rdma_stat_read;
79297 +atomic_unchecked_t rdma_stat_write;
79298 +atomic_unchecked_t rdma_stat_sq_starve;
79299 +atomic_unchecked_t rdma_stat_rq_starve;
79300 +atomic_unchecked_t rdma_stat_rq_poll;
79301 +atomic_unchecked_t rdma_stat_rq_prod;
79302 +atomic_unchecked_t rdma_stat_sq_poll;
79303 +atomic_unchecked_t rdma_stat_sq_prod;
79304
79305 /* Temporary NFS request map and context caches */
79306 struct kmem_cache *svc_rdma_map_cachep;
79307 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79308 len -= *ppos;
79309 if (len > *lenp)
79310 len = *lenp;
79311 - if (len && copy_to_user(buffer, str_buf, len))
79312 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79313 return -EFAULT;
79314 *lenp = len;
79315 *ppos += len;
79316 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79317 {
79318 .procname = "rdma_stat_read",
79319 .data = &rdma_stat_read,
79320 - .maxlen = sizeof(atomic_t),
79321 + .maxlen = sizeof(atomic_unchecked_t),
79322 .mode = 0644,
79323 .proc_handler = read_reset_stat,
79324 },
79325 {
79326 .procname = "rdma_stat_recv",
79327 .data = &rdma_stat_recv,
79328 - .maxlen = sizeof(atomic_t),
79329 + .maxlen = sizeof(atomic_unchecked_t),
79330 .mode = 0644,
79331 .proc_handler = read_reset_stat,
79332 },
79333 {
79334 .procname = "rdma_stat_write",
79335 .data = &rdma_stat_write,
79336 - .maxlen = sizeof(atomic_t),
79337 + .maxlen = sizeof(atomic_unchecked_t),
79338 .mode = 0644,
79339 .proc_handler = read_reset_stat,
79340 },
79341 {
79342 .procname = "rdma_stat_sq_starve",
79343 .data = &rdma_stat_sq_starve,
79344 - .maxlen = sizeof(atomic_t),
79345 + .maxlen = sizeof(atomic_unchecked_t),
79346 .mode = 0644,
79347 .proc_handler = read_reset_stat,
79348 },
79349 {
79350 .procname = "rdma_stat_rq_starve",
79351 .data = &rdma_stat_rq_starve,
79352 - .maxlen = sizeof(atomic_t),
79353 + .maxlen = sizeof(atomic_unchecked_t),
79354 .mode = 0644,
79355 .proc_handler = read_reset_stat,
79356 },
79357 {
79358 .procname = "rdma_stat_rq_poll",
79359 .data = &rdma_stat_rq_poll,
79360 - .maxlen = sizeof(atomic_t),
79361 + .maxlen = sizeof(atomic_unchecked_t),
79362 .mode = 0644,
79363 .proc_handler = read_reset_stat,
79364 },
79365 {
79366 .procname = "rdma_stat_rq_prod",
79367 .data = &rdma_stat_rq_prod,
79368 - .maxlen = sizeof(atomic_t),
79369 + .maxlen = sizeof(atomic_unchecked_t),
79370 .mode = 0644,
79371 .proc_handler = read_reset_stat,
79372 },
79373 {
79374 .procname = "rdma_stat_sq_poll",
79375 .data = &rdma_stat_sq_poll,
79376 - .maxlen = sizeof(atomic_t),
79377 + .maxlen = sizeof(atomic_unchecked_t),
79378 .mode = 0644,
79379 .proc_handler = read_reset_stat,
79380 },
79381 {
79382 .procname = "rdma_stat_sq_prod",
79383 .data = &rdma_stat_sq_prod,
79384 - .maxlen = sizeof(atomic_t),
79385 + .maxlen = sizeof(atomic_unchecked_t),
79386 .mode = 0644,
79387 .proc_handler = read_reset_stat,
79388 },
79389 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79390 index 41cb63b..c4a1489 100644
79391 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79392 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79393 @@ -501,7 +501,7 @@ next_sge:
79394 svc_rdma_put_context(ctxt, 0);
79395 goto out;
79396 }
79397 - atomic_inc(&rdma_stat_read);
79398 + atomic_inc_unchecked(&rdma_stat_read);
79399
79400 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79401 chl_map->ch[ch_no].count -= read_wr.num_sge;
79402 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79403 dto_q);
79404 list_del_init(&ctxt->dto_q);
79405 } else {
79406 - atomic_inc(&rdma_stat_rq_starve);
79407 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79408 clear_bit(XPT_DATA, &xprt->xpt_flags);
79409 ctxt = NULL;
79410 }
79411 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79412 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79413 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79414 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79415 - atomic_inc(&rdma_stat_recv);
79416 + atomic_inc_unchecked(&rdma_stat_recv);
79417
79418 /* Build up the XDR from the receive buffers. */
79419 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79420 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79421 index 42eb7ba..c887c45 100644
79422 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79423 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79424 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79425 write_wr.wr.rdma.remote_addr = to;
79426
79427 /* Post It */
79428 - atomic_inc(&rdma_stat_write);
79429 + atomic_inc_unchecked(&rdma_stat_write);
79430 if (svc_rdma_send(xprt, &write_wr))
79431 goto err;
79432 return 0;
79433 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79434 index 73b428b..5f3f8f3 100644
79435 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79436 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79437 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79438 return;
79439
79440 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79441 - atomic_inc(&rdma_stat_rq_poll);
79442 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79443
79444 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79445 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79446 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79447 }
79448
79449 if (ctxt)
79450 - atomic_inc(&rdma_stat_rq_prod);
79451 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79452
79453 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79454 /*
79455 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79456 return;
79457
79458 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79459 - atomic_inc(&rdma_stat_sq_poll);
79460 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79461 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79462 if (wc.status != IB_WC_SUCCESS)
79463 /* Close the transport */
79464 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79465 }
79466
79467 if (ctxt)
79468 - atomic_inc(&rdma_stat_sq_prod);
79469 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79470 }
79471
79472 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79473 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79474 spin_lock_bh(&xprt->sc_lock);
79475 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79476 spin_unlock_bh(&xprt->sc_lock);
79477 - atomic_inc(&rdma_stat_sq_starve);
79478 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79479
79480 /* See if we can opportunistically reap SQ WR to make room */
79481 sq_cq_reap(xprt);
79482 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79483 index e3a6e37..be2ea77 100644
79484 --- a/net/sysctl_net.c
79485 +++ b/net/sysctl_net.c
79486 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79487 struct ctl_table *table)
79488 {
79489 /* Allow network administrator to have same access as root. */
79490 - if (capable(CAP_NET_ADMIN)) {
79491 + if (capable_nolog(CAP_NET_ADMIN)) {
79492 int mode = (table->mode >> 6) & 7;
79493 return (mode << 6) | (mode << 3) | mode;
79494 }
79495 diff --git a/net/tipc/link.c b/net/tipc/link.c
79496 index 1c1e615..113e0ae 100644
79497 --- a/net/tipc/link.c
79498 +++ b/net/tipc/link.c
79499 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79500 struct tipc_msg fragm_hdr;
79501 struct sk_buff *buf, *buf_chain, *prev;
79502 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79503 - const unchar *sect_crs;
79504 + const unchar __user *sect_crs;
79505 int curr_sect;
79506 u32 fragm_no;
79507
79508 @@ -1212,7 +1212,7 @@ again:
79509
79510 if (!sect_rest) {
79511 sect_rest = msg_sect[++curr_sect].iov_len;
79512 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79513 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79514 }
79515
79516 if (sect_rest < fragm_rest)
79517 @@ -1231,7 +1231,7 @@ error:
79518 }
79519 } else
79520 skb_copy_to_linear_data_offset(buf, fragm_crs,
79521 - sect_crs, sz);
79522 + (const void __force_kernel *)sect_crs, sz);
79523 sect_crs += sz;
79524 sect_rest -= sz;
79525 fragm_crs += sz;
79526 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79527 index f2db8a8..9245aa4 100644
79528 --- a/net/tipc/msg.c
79529 +++ b/net/tipc/msg.c
79530 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79531 msg_sect[cnt].iov_len);
79532 else
79533 skb_copy_to_linear_data_offset(*buf, pos,
79534 - msg_sect[cnt].iov_base,
79535 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79536 msg_sect[cnt].iov_len);
79537 pos += msg_sect[cnt].iov_len;
79538 }
79539 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79540 index 5ed5965..90abe34 100644
79541 --- a/net/tipc/subscr.c
79542 +++ b/net/tipc/subscr.c
79543 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79544 {
79545 struct iovec msg_sect;
79546
79547 - msg_sect.iov_base = (void *)&sub->evt;
79548 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79549 msg_sect.iov_len = sizeof(struct tipc_event);
79550
79551 sub->evt.event = htohl(event, sub->swap);
79552 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79553 index c5ee4ff..e905948 100644
79554 --- a/net/unix/af_unix.c
79555 +++ b/net/unix/af_unix.c
79556 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79557 err = -ECONNREFUSED;
79558 if (!S_ISSOCK(inode->i_mode))
79559 goto put_fail;
79560 +
79561 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79562 + err = -EACCES;
79563 + goto put_fail;
79564 + }
79565 +
79566 u = unix_find_socket_byinode(inode);
79567 if (!u)
79568 goto put_fail;
79569 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79570 if (u) {
79571 struct dentry *dentry;
79572 dentry = unix_sk(u)->path.dentry;
79573 +
79574 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79575 + err = -EPERM;
79576 + sock_put(u);
79577 + goto fail;
79578 + }
79579 +
79580 if (dentry)
79581 touch_atime(&unix_sk(u)->path);
79582 } else
79583 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79584 */
79585 err = security_path_mknod(&path, dentry, mode, 0);
79586 if (!err) {
79587 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79588 + err = -EACCES;
79589 + goto out;
79590 + }
79591 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79592 if (!err) {
79593 res->mnt = mntget(path.mnt);
79594 res->dentry = dget(dentry);
79595 + gr_handle_create(dentry, path.mnt);
79596 }
79597 }
79598 +out:
79599 done_path_create(&path, dentry);
79600 return err;
79601 }
79602 diff --git a/net/wireless/core.h b/net/wireless/core.h
79603 index bc7430b..35349de 100644
79604 --- a/net/wireless/core.h
79605 +++ b/net/wireless/core.h
79606 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79607 struct mutex mtx;
79608
79609 /* rfkill support */
79610 - struct rfkill_ops rfkill_ops;
79611 + rfkill_ops_no_const rfkill_ops;
79612 struct rfkill *rfkill;
79613 struct work_struct rfkill_sync;
79614
79615 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79616 index b0eb7aa..7d73e82 100644
79617 --- a/net/wireless/wext-core.c
79618 +++ b/net/wireless/wext-core.c
79619 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79620 */
79621
79622 /* Support for very large requests */
79623 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79624 - (user_length > descr->max_tokens)) {
79625 + if (user_length > descr->max_tokens) {
79626 /* Allow userspace to GET more than max so
79627 * we can support any size GET requests.
79628 * There is still a limit : -ENOMEM.
79629 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79630 }
79631 }
79632
79633 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79634 - /*
79635 - * If this is a GET, but not NOMAX, it means that the extra
79636 - * data is not bounded by userspace, but by max_tokens. Thus
79637 - * set the length to max_tokens. This matches the extra data
79638 - * allocation.
79639 - * The driver should fill it with the number of tokens it
79640 - * provided, and it may check iwp->length rather than having
79641 - * knowledge of max_tokens. If the driver doesn't change the
79642 - * iwp->length, this ioctl just copies back max_token tokens
79643 - * filled with zeroes. Hopefully the driver isn't claiming
79644 - * them to be valid data.
79645 - */
79646 - iwp->length = descr->max_tokens;
79647 - }
79648 -
79649 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79650
79651 iwp->length += essid_compat;
79652 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79653 index 387848e..a6667a2 100644
79654 --- a/net/xfrm/xfrm_policy.c
79655 +++ b/net/xfrm/xfrm_policy.c
79656 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79657 {
79658 policy->walk.dead = 1;
79659
79660 - atomic_inc(&policy->genid);
79661 + atomic_inc_unchecked(&policy->genid);
79662
79663 if (del_timer(&policy->timer))
79664 xfrm_pol_put(policy);
79665 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79666 hlist_add_head(&policy->bydst, chain);
79667 xfrm_pol_hold(policy);
79668 net->xfrm.policy_count[dir]++;
79669 - atomic_inc(&flow_cache_genid);
79670 + atomic_inc_unchecked(&flow_cache_genid);
79671 rt_genid_bump(net);
79672 if (delpol)
79673 __xfrm_policy_unlink(delpol, dir);
79674 @@ -1533,7 +1533,7 @@ free_dst:
79675 goto out;
79676 }
79677
79678 -static int inline
79679 +static inline int
79680 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79681 {
79682 if (!*target) {
79683 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79684 return 0;
79685 }
79686
79687 -static int inline
79688 +static inline int
79689 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79690 {
79691 #ifdef CONFIG_XFRM_SUB_POLICY
79692 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79693 #endif
79694 }
79695
79696 -static int inline
79697 +static inline int
79698 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79699 {
79700 #ifdef CONFIG_XFRM_SUB_POLICY
79701 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79702
79703 xdst->num_pols = num_pols;
79704 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79705 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79706 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79707
79708 return xdst;
79709 }
79710 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79711 if (xdst->xfrm_genid != dst->xfrm->genid)
79712 return 0;
79713 if (xdst->num_pols > 0 &&
79714 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79715 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79716 return 0;
79717
79718 mtu = dst_mtu(dst->child);
79719 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79720 sizeof(pol->xfrm_vec[i].saddr));
79721 pol->xfrm_vec[i].encap_family = mp->new_family;
79722 /* flush bundles */
79723 - atomic_inc(&pol->genid);
79724 + atomic_inc_unchecked(&pol->genid);
79725 }
79726 }
79727
79728 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79729 index ff1720d..ed8475e 100644
79730 --- a/scripts/Makefile.build
79731 +++ b/scripts/Makefile.build
79732 @@ -111,7 +111,7 @@ endif
79733 endif
79734
79735 # Do not include host rules unless needed
79736 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79737 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79738 include scripts/Makefile.host
79739 endif
79740
79741 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79742 index 686cb0d..9d653bf 100644
79743 --- a/scripts/Makefile.clean
79744 +++ b/scripts/Makefile.clean
79745 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79746 __clean-files := $(extra-y) $(always) \
79747 $(targets) $(clean-files) \
79748 $(host-progs) \
79749 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79750 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79751 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79752
79753 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79754
79755 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79756 index 1ac414f..38575f7 100644
79757 --- a/scripts/Makefile.host
79758 +++ b/scripts/Makefile.host
79759 @@ -31,6 +31,8 @@
79760 # Note: Shared libraries consisting of C++ files are not supported
79761
79762 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79763 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79764 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79765
79766 # C code
79767 # Executables compiled from a single .c file
79768 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79769 # Shared libaries (only .c supported)
79770 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79771 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79772 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79773 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79774 # Remove .so files from "xxx-objs"
79775 host-cobjs := $(filter-out %.so,$(host-cobjs))
79776 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79777
79778 -#Object (.o) files used by the shared libaries
79779 +# Object (.o) files used by the shared libaries
79780 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79781 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79782
79783 # output directory for programs/.o files
79784 # hostprogs-y := tools/build may have been specified. Retrieve directory
79785 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79786 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79787 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79788 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79789 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79790 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79791 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79792 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79793
79794 obj-dirs += $(host-objdirs)
79795 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79796 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79797 $(call if_changed_dep,host-cshobjs)
79798
79799 +# Compile .c file, create position independent .o file
79800 +# host-cxxshobjs -> .o
79801 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79802 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79803 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79804 + $(call if_changed_dep,host-cxxshobjs)
79805 +
79806 # Link a shared library, based on position independent .o files
79807 # *.o -> .so shared library (host-cshlib)
79808 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79809 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79810 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79811 $(call if_changed,host-cshlib)
79812
79813 +# Link a shared library, based on position independent .o files
79814 +# *.o -> .so shared library (host-cxxshlib)
79815 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79816 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79817 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79818 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79819 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79820 + $(call if_changed,host-cxxshlib)
79821 +
79822 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79823 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79824 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79825
79826 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79827 index cb1f50c..cef2a7c 100644
79828 --- a/scripts/basic/fixdep.c
79829 +++ b/scripts/basic/fixdep.c
79830 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79831 /*
79832 * Lookup a value in the configuration string.
79833 */
79834 -static int is_defined_config(const char *name, int len, unsigned int hash)
79835 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79836 {
79837 struct item *aux;
79838
79839 @@ -211,10 +211,10 @@ static void clear_config(void)
79840 /*
79841 * Record the use of a CONFIG_* word.
79842 */
79843 -static void use_config(const char *m, int slen)
79844 +static void use_config(const char *m, unsigned int slen)
79845 {
79846 unsigned int hash = strhash(m, slen);
79847 - int c, i;
79848 + unsigned int c, i;
79849
79850 if (is_defined_config(m, slen, hash))
79851 return;
79852 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79853
79854 static void parse_config_file(const char *map, size_t len)
79855 {
79856 - const int *end = (const int *) (map + len);
79857 + const unsigned int *end = (const unsigned int *) (map + len);
79858 /* start at +1, so that p can never be < map */
79859 - const int *m = (const int *) map + 1;
79860 + const unsigned int *m = (const unsigned int *) map + 1;
79861 const char *p, *q;
79862
79863 for (; m < end; m++) {
79864 @@ -406,7 +406,7 @@ static void print_deps(void)
79865 static void traps(void)
79866 {
79867 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79868 - int *p = (int *)test;
79869 + unsigned int *p = (unsigned int *)test;
79870
79871 if (*p != INT_CONF) {
79872 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79873 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79874 new file mode 100644
79875 index 0000000..008ac1a
79876 --- /dev/null
79877 +++ b/scripts/gcc-plugin.sh
79878 @@ -0,0 +1,17 @@
79879 +#!/bin/bash
79880 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79881 +#include "gcc-plugin.h"
79882 +#include "tree.h"
79883 +#include "tm.h"
79884 +#include "rtl.h"
79885 +#ifdef ENABLE_BUILD_WITH_CXX
79886 +#warning $2
79887 +#else
79888 +#warning $1
79889 +#endif
79890 +EOF`
79891 +if [ $? -eq 0 ]
79892 +then
79893 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79894 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79895 +fi
79896 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79897 index b3d907e..a4782ab 100644
79898 --- a/scripts/link-vmlinux.sh
79899 +++ b/scripts/link-vmlinux.sh
79900 @@ -152,7 +152,7 @@ else
79901 fi;
79902
79903 # final build of init/
79904 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79905 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79906
79907 kallsymso=""
79908 kallsyms_vmlinux=""
79909 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79910 index 7ed6864..b6e90e6 100644
79911 --- a/scripts/mod/file2alias.c
79912 +++ b/scripts/mod/file2alias.c
79913 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79914 unsigned long size, unsigned long id_size,
79915 void *symval)
79916 {
79917 - int i;
79918 + unsigned int i;
79919
79920 if (size % id_size || size < id_size) {
79921 if (cross_build != 0)
79922 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79923 /* USB is special because the bcdDevice can be matched against a numeric range */
79924 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
79925 static void do_usb_entry(struct usb_device_id *id,
79926 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79927 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79928 unsigned char range_lo, unsigned char range_hi,
79929 unsigned char max, struct module *mod)
79930 {
79931 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79932 {
79933 unsigned int devlo, devhi;
79934 unsigned char chi, clo, max;
79935 - int ndigits;
79936 + unsigned int ndigits;
79937
79938 id->match_flags = TO_NATIVE(id->match_flags);
79939 id->idVendor = TO_NATIVE(id->idVendor);
79940 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79941 for (i = 0; i < count; i++) {
79942 const char *id = (char *)devs[i].id;
79943 char acpi_id[sizeof(devs[0].id)];
79944 - int j;
79945 + unsigned int j;
79946
79947 buf_printf(&mod->dev_table_buf,
79948 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79949 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79950
79951 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79952 const char *id = (char *)card->devs[j].id;
79953 - int i2, j2;
79954 + unsigned int i2, j2;
79955 int dup = 0;
79956
79957 if (!id[0])
79958 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79959 /* add an individual alias for every device entry */
79960 if (!dup) {
79961 char acpi_id[sizeof(card->devs[0].id)];
79962 - int k;
79963 + unsigned int k;
79964
79965 buf_printf(&mod->dev_table_buf,
79966 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79967 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79968 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79969 char *alias)
79970 {
79971 - int i, j;
79972 + unsigned int i, j;
79973
79974 sprintf(alias, "dmi*");
79975
79976 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79977 index 68e9f5e..ac7759b 100644
79978 --- a/scripts/mod/modpost.c
79979 +++ b/scripts/mod/modpost.c
79980 @@ -930,6 +930,7 @@ enum mismatch {
79981 ANY_INIT_TO_ANY_EXIT,
79982 ANY_EXIT_TO_ANY_INIT,
79983 EXPORT_TO_INIT_EXIT,
79984 + DATA_TO_TEXT
79985 };
79986
79987 struct sectioncheck {
79988 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
79989 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79990 .mismatch = EXPORT_TO_INIT_EXIT,
79991 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79992 +},
79993 +/* Do not reference code from writable data */
79994 +{
79995 + .fromsec = { DATA_SECTIONS, NULL },
79996 + .tosec = { TEXT_SECTIONS, NULL },
79997 + .mismatch = DATA_TO_TEXT
79998 }
79999 };
80000
80001 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80002 continue;
80003 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80004 continue;
80005 - if (sym->st_value == addr)
80006 - return sym;
80007 /* Find a symbol nearby - addr are maybe negative */
80008 d = sym->st_value - addr;
80009 + if (d == 0)
80010 + return sym;
80011 if (d < 0)
80012 d = addr - sym->st_value;
80013 if (d < distance) {
80014 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80015 tosym, prl_to, prl_to, tosym);
80016 free(prl_to);
80017 break;
80018 + case DATA_TO_TEXT:
80019 +#if 0
80020 + fprintf(stderr,
80021 + "The %s %s:%s references\n"
80022 + "the %s %s:%s%s\n",
80023 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80024 +#endif
80025 + break;
80026 }
80027 fprintf(stderr, "\n");
80028 }
80029 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80030 static void check_sec_ref(struct module *mod, const char *modname,
80031 struct elf_info *elf)
80032 {
80033 - int i;
80034 + unsigned int i;
80035 Elf_Shdr *sechdrs = elf->sechdrs;
80036
80037 /* Walk through all sections */
80038 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80039 va_end(ap);
80040 }
80041
80042 -void buf_write(struct buffer *buf, const char *s, int len)
80043 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80044 {
80045 if (buf->size - buf->pos < len) {
80046 buf->size += len + SZ;
80047 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80048 if (fstat(fileno(file), &st) < 0)
80049 goto close_write;
80050
80051 - if (st.st_size != b->pos)
80052 + if (st.st_size != (off_t)b->pos)
80053 goto close_write;
80054
80055 tmp = NOFAIL(malloc(b->pos));
80056 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80057 index 51207e4..f7d603d 100644
80058 --- a/scripts/mod/modpost.h
80059 +++ b/scripts/mod/modpost.h
80060 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80061
80062 struct buffer {
80063 char *p;
80064 - int pos;
80065 - int size;
80066 + unsigned int pos;
80067 + unsigned int size;
80068 };
80069
80070 void __attribute__((format(printf, 2, 3)))
80071 buf_printf(struct buffer *buf, const char *fmt, ...);
80072
80073 void
80074 -buf_write(struct buffer *buf, const char *s, int len);
80075 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80076
80077 struct module {
80078 struct module *next;
80079 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80080 index 9dfcd6d..099068e 100644
80081 --- a/scripts/mod/sumversion.c
80082 +++ b/scripts/mod/sumversion.c
80083 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80084 goto out;
80085 }
80086
80087 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80088 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80089 warn("writing sum in %s failed: %s\n",
80090 filename, strerror(errno));
80091 goto out;
80092 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80093 index 5c11312..72742b5 100644
80094 --- a/scripts/pnmtologo.c
80095 +++ b/scripts/pnmtologo.c
80096 @@ -237,14 +237,14 @@ static void write_header(void)
80097 fprintf(out, " * Linux logo %s\n", logoname);
80098 fputs(" */\n\n", out);
80099 fputs("#include <linux/linux_logo.h>\n\n", out);
80100 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80101 + fprintf(out, "static unsigned char %s_data[] = {\n",
80102 logoname);
80103 }
80104
80105 static void write_footer(void)
80106 {
80107 fputs("\n};\n\n", out);
80108 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80109 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80110 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80111 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80112 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80113 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80114 fputs("\n};\n\n", out);
80115
80116 /* write logo clut */
80117 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80118 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80119 logoname);
80120 write_hex_cnt = 0;
80121 for (i = 0; i < logo_clutsize; i++) {
80122 diff --git a/security/Kconfig b/security/Kconfig
80123 index e9c6ac7..e7feb0d 100644
80124 --- a/security/Kconfig
80125 +++ b/security/Kconfig
80126 @@ -4,6 +4,896 @@
80127
80128 menu "Security options"
80129
80130 +menu "Grsecurity"
80131 +
80132 + config ARCH_TRACK_EXEC_LIMIT
80133 + bool
80134 +
80135 + config PAX_KERNEXEC_PLUGIN
80136 + bool
80137 +
80138 + config PAX_PER_CPU_PGD
80139 + bool
80140 +
80141 + config TASK_SIZE_MAX_SHIFT
80142 + int
80143 + depends on X86_64
80144 + default 47 if !PAX_PER_CPU_PGD
80145 + default 42 if PAX_PER_CPU_PGD
80146 +
80147 + config PAX_ENABLE_PAE
80148 + bool
80149 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80150 +
80151 + config PAX_USERCOPY_SLABS
80152 + bool
80153 +
80154 +config GRKERNSEC
80155 + bool "Grsecurity"
80156 + select CRYPTO
80157 + select CRYPTO_SHA256
80158 + select PROC_FS
80159 + select STOP_MACHINE
80160 + help
80161 + If you say Y here, you will be able to configure many features
80162 + that will enhance the security of your system. It is highly
80163 + recommended that you say Y here and read through the help
80164 + for each option so that you fully understand the features and
80165 + can evaluate their usefulness for your machine.
80166 +
80167 +choice
80168 + prompt "Configuration Method"
80169 + depends on GRKERNSEC
80170 + default GRKERNSEC_CONFIG_CUSTOM
80171 + help
80172 +
80173 +config GRKERNSEC_CONFIG_AUTO
80174 + bool "Automatic"
80175 + help
80176 + If you choose this configuration method, you'll be able to answer a small
80177 + number of simple questions about how you plan to use this kernel.
80178 + The settings of grsecurity and PaX will be automatically configured for
80179 + the highest commonly-used settings within the provided constraints.
80180 +
80181 + If you require additional configuration, custom changes can still be made
80182 + from the "custom configuration" menu.
80183 +
80184 +config GRKERNSEC_CONFIG_CUSTOM
80185 + bool "Custom"
80186 + help
80187 + If you choose this configuration method, you'll be able to configure all
80188 + grsecurity and PaX settings manually. Via this method, no options are
80189 + automatically enabled.
80190 +
80191 +endchoice
80192 +
80193 +choice
80194 + prompt "Usage Type"
80195 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80196 + default GRKERNSEC_CONFIG_SERVER
80197 + help
80198 +
80199 +config GRKERNSEC_CONFIG_SERVER
80200 + bool "Server"
80201 + help
80202 + Choose this option if you plan to use this kernel on a server.
80203 +
80204 +config GRKERNSEC_CONFIG_DESKTOP
80205 + bool "Desktop"
80206 + help
80207 + Choose this option if you plan to use this kernel on a desktop.
80208 +
80209 +endchoice
80210 +
80211 +choice
80212 + prompt "Virtualization Type"
80213 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80214 + default GRKERNSEC_CONFIG_VIRT_NONE
80215 + help
80216 +
80217 +config GRKERNSEC_CONFIG_VIRT_NONE
80218 + bool "None"
80219 + help
80220 + Choose this option if this kernel will be run on bare metal.
80221 +
80222 +config GRKERNSEC_CONFIG_VIRT_GUEST
80223 + bool "Guest"
80224 + help
80225 + Choose this option if this kernel will be run as a VM guest.
80226 +
80227 +config GRKERNSEC_CONFIG_VIRT_HOST
80228 + bool "Host"
80229 + help
80230 + Choose this option if this kernel will be run as a VM host.
80231 +
80232 +endchoice
80233 +
80234 +choice
80235 + prompt "Virtualization Hardware"
80236 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80237 + help
80238 +
80239 +config GRKERNSEC_CONFIG_VIRT_EPT
80240 + bool "EPT/RVI Processor Support"
80241 + depends on X86
80242 + help
80243 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80244 + hardware virtualization. This allows for additional kernel hardening protections
80245 + to operate without additional performance impact.
80246 +
80247 + To see if your Intel processor supports EPT, see:
80248 + http://ark.intel.com/Products/VirtualizationTechnology
80249 + (Most Core i3/5/7 support EPT)
80250 +
80251 + To see if your AMD processor supports RVI, see:
80252 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80253 +
80254 +config GRKERNSEC_CONFIG_VIRT_SOFT
80255 + bool "First-gen/No Hardware Virtualization"
80256 + help
80257 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80258 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80259 +
80260 +endchoice
80261 +
80262 +choice
80263 + prompt "Virtualization Software"
80264 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80265 + help
80266 +
80267 +config GRKERNSEC_CONFIG_VIRT_XEN
80268 + bool "Xen"
80269 + help
80270 + Choose this option if this kernel is running as a Xen guest or host.
80271 +
80272 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80273 + bool "VMWare"
80274 + help
80275 + Choose this option if this kernel is running as a VMWare guest or host.
80276 +
80277 +config GRKERNSEC_CONFIG_VIRT_KVM
80278 + bool "KVM"
80279 + help
80280 + Choose this option if this kernel is running as a KVM guest or host.
80281 +
80282 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80283 + bool "VirtualBox"
80284 + help
80285 + Choose this option if this kernel is running as a VirtualBox guest or host.
80286 +
80287 +endchoice
80288 +
80289 +choice
80290 + prompt "Required Priorities"
80291 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80292 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80293 + help
80294 +
80295 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80296 + bool "Performance"
80297 + help
80298 + Choose this option if performance is of highest priority for this deployment
80299 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80300 + and freed memory sanitizing will be disabled.
80301 +
80302 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80303 + bool "Security"
80304 + help
80305 + Choose this option if security is of highest priority for this deployment of
80306 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80307 + be enabled for this kernel. In a worst-case scenario, these features can
80308 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80309 +
80310 +endchoice
80311 +
80312 +menu "Default Special Groups"
80313 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80314 +
80315 +config GRKERNSEC_PROC_GID
80316 + int "GID exempted from /proc restrictions"
80317 + default 1001
80318 + help
80319 + Setting this GID determines which group will be exempted from
80320 + grsecurity's /proc restrictions, allowing users of the specified
80321 + group to view network statistics and the existence of other users'
80322 + processes on the system. This GID may also be chosen at boot time
80323 + via "grsec_proc_gid=" on the kernel commandline.
80324 +
80325 +config GRKERNSEC_TPE_UNTRUSTED_GID
80326 + int "GID for TPE-untrusted users"
80327 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80328 + default 1005
80329 + help
80330 + Setting this GID determines which group untrusted users should
80331 + be added to. These users will be placed under grsecurity's Trusted Path
80332 + Execution mechanism, preventing them from executing their own binaries.
80333 + The users will only be able to execute binaries in directories owned and
80334 + writable only by the root user. If the sysctl option is enabled, a sysctl
80335 + option with name "tpe_gid" is created.
80336 +
80337 +config GRKERNSEC_TPE_TRUSTED_GID
80338 + int "GID for TPE-trusted users"
80339 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80340 + default 1005
80341 + help
80342 + Setting this GID determines what group TPE restrictions will be
80343 + *disabled* for. If the sysctl option is enabled, a sysctl option
80344 + with name "tpe_gid" is created.
80345 +
80346 +config GRKERNSEC_SYMLINKOWN_GID
80347 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80348 + depends on GRKERNSEC_CONFIG_SERVER
80349 + default 1006
80350 + help
80351 + Setting this GID determines what group kernel-enforced
80352 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80353 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80354 +
80355 +
80356 +endmenu
80357 +
80358 +menu "Customize Configuration"
80359 +depends on GRKERNSEC
80360 +
80361 +menu "PaX"
80362 +
80363 +config PAX
80364 + bool "Enable various PaX features"
80365 + default y if GRKERNSEC_CONFIG_AUTO
80366 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80367 + help
80368 + This allows you to enable various PaX features. PaX adds
80369 + intrusion prevention mechanisms to the kernel that reduce
80370 + the risks posed by exploitable memory corruption bugs.
80371 +
80372 +menu "PaX Control"
80373 + depends on PAX
80374 +
80375 +config PAX_SOFTMODE
80376 + bool 'Support soft mode'
80377 + help
80378 + Enabling this option will allow you to run PaX in soft mode, that
80379 + is, PaX features will not be enforced by default, only on executables
80380 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80381 + support as they are the only way to mark executables for soft mode use.
80382 +
80383 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80384 + line option on boot. Furthermore you can control various PaX features
80385 + at runtime via the entries in /proc/sys/kernel/pax.
80386 +
80387 +config PAX_EI_PAX
80388 + bool 'Use legacy ELF header marking'
80389 + default y if GRKERNSEC_CONFIG_AUTO
80390 + help
80391 + Enabling this option will allow you to control PaX features on
80392 + a per executable basis via the 'chpax' utility available at
80393 + http://pax.grsecurity.net/. The control flags will be read from
80394 + an otherwise reserved part of the ELF header. This marking has
80395 + numerous drawbacks (no support for soft-mode, toolchain does not
80396 + know about the non-standard use of the ELF header) therefore it
80397 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80398 + support.
80399 +
80400 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80401 + support as well, they will override the legacy EI_PAX marks.
80402 +
80403 + If you enable none of the marking options then all applications
80404 + will run with PaX enabled on them by default.
80405 +
80406 +config PAX_PT_PAX_FLAGS
80407 + bool 'Use ELF program header marking'
80408 + default y if GRKERNSEC_CONFIG_AUTO
80409 + help
80410 + Enabling this option will allow you to control PaX features on
80411 + a per executable basis via the 'paxctl' utility available at
80412 + http://pax.grsecurity.net/. The control flags will be read from
80413 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80414 + has the benefits of supporting both soft mode and being fully
80415 + integrated into the toolchain (the binutils patch is available
80416 + from http://pax.grsecurity.net).
80417 +
80418 + Note that if you enable the legacy EI_PAX marking support as well,
80419 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80420 +
80421 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80422 + must make sure that the marks are the same if a binary has both marks.
80423 +
80424 + If you enable none of the marking options then all applications
80425 + will run with PaX enabled on them by default.
80426 +
80427 +config PAX_XATTR_PAX_FLAGS
80428 + bool 'Use filesystem extended attributes marking'
80429 + default y if GRKERNSEC_CONFIG_AUTO
80430 + select CIFS_XATTR if CIFS
80431 + select EXT2_FS_XATTR if EXT2_FS
80432 + select EXT3_FS_XATTR if EXT3_FS
80433 + select EXT4_FS_XATTR if EXT4_FS
80434 + select JFFS2_FS_XATTR if JFFS2_FS
80435 + select REISERFS_FS_XATTR if REISERFS_FS
80436 + select SQUASHFS_XATTR if SQUASHFS
80437 + select TMPFS_XATTR if TMPFS
80438 + select UBIFS_FS_XATTR if UBIFS_FS
80439 + help
80440 + Enabling this option will allow you to control PaX features on
80441 + a per executable basis via the 'setfattr' utility. The control
80442 + flags will be read from the user.pax.flags extended attribute of
80443 + the file. This marking has the benefit of supporting binary-only
80444 + applications that self-check themselves (e.g., skype) and would
80445 + not tolerate chpax/paxctl changes. The main drawback is that
80446 + extended attributes are not supported by some filesystems (e.g.,
80447 + isofs, udf, vfat) so copying files through such filesystems will
80448 + lose the extended attributes and these PaX markings.
80449 +
80450 + Note that if you enable the legacy EI_PAX marking support as well,
80451 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80452 +
80453 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80454 + must make sure that the marks are the same if a binary has both marks.
80455 +
80456 + If you enable none of the marking options then all applications
80457 + will run with PaX enabled on them by default.
80458 +
80459 +choice
80460 + prompt 'MAC system integration'
80461 + default PAX_HAVE_ACL_FLAGS
80462 + help
80463 + Mandatory Access Control systems have the option of controlling
80464 + PaX flags on a per executable basis, choose the method supported
80465 + by your particular system.
80466 +
80467 + - "none": if your MAC system does not interact with PaX,
80468 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80469 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80470 +
80471 + NOTE: this option is for developers/integrators only.
80472 +
80473 + config PAX_NO_ACL_FLAGS
80474 + bool 'none'
80475 +
80476 + config PAX_HAVE_ACL_FLAGS
80477 + bool 'direct'
80478 +
80479 + config PAX_HOOK_ACL_FLAGS
80480 + bool 'hook'
80481 +endchoice
80482 +
80483 +endmenu
80484 +
80485 +menu "Non-executable pages"
80486 + depends on PAX
80487 +
80488 +config PAX_NOEXEC
80489 + bool "Enforce non-executable pages"
80490 + default y if GRKERNSEC_CONFIG_AUTO
80491 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80492 + help
80493 + By design some architectures do not allow for protecting memory
80494 + pages against execution or even if they do, Linux does not make
80495 + use of this feature. In practice this means that if a page is
80496 + readable (such as the stack or heap) it is also executable.
80497 +
80498 + There is a well known exploit technique that makes use of this
80499 + fact and a common programming mistake where an attacker can
80500 + introduce code of his choice somewhere in the attacked program's
80501 + memory (typically the stack or the heap) and then execute it.
80502 +
80503 + If the attacked program was running with different (typically
80504 + higher) privileges than that of the attacker, then he can elevate
80505 + his own privilege level (e.g. get a root shell, write to files for
80506 + which he does not have write access to, etc).
80507 +
80508 + Enabling this option will let you choose from various features
80509 + that prevent the injection and execution of 'foreign' code in
80510 + a program.
80511 +
80512 + This will also break programs that rely on the old behaviour and
80513 + expect that dynamically allocated memory via the malloc() family
80514 + of functions is executable (which it is not). Notable examples
80515 + are the XFree86 4.x server, the java runtime and wine.
80516 +
80517 +config PAX_PAGEEXEC
80518 + bool "Paging based non-executable pages"
80519 + default y if GRKERNSEC_CONFIG_AUTO
80520 + 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)
80521 + select S390_SWITCH_AMODE if S390
80522 + select S390_EXEC_PROTECT if S390
80523 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80524 + help
80525 + This implementation is based on the paging feature of the CPU.
80526 + On i386 without hardware non-executable bit support there is a
80527 + variable but usually low performance impact, however on Intel's
80528 + P4 core based CPUs it is very high so you should not enable this
80529 + for kernels meant to be used on such CPUs.
80530 +
80531 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80532 + with hardware non-executable bit support there is no performance
80533 + impact, on ppc the impact is negligible.
80534 +
80535 + Note that several architectures require various emulations due to
80536 + badly designed userland ABIs, this will cause a performance impact
80537 + but will disappear as soon as userland is fixed. For example, ppc
80538 + userland MUST have been built with secure-plt by a recent toolchain.
80539 +
80540 +config PAX_SEGMEXEC
80541 + bool "Segmentation based non-executable pages"
80542 + default y if GRKERNSEC_CONFIG_AUTO
80543 + depends on PAX_NOEXEC && X86_32
80544 + help
80545 + This implementation is based on the segmentation feature of the
80546 + CPU and has a very small performance impact, however applications
80547 + will be limited to a 1.5 GB address space instead of the normal
80548 + 3 GB.
80549 +
80550 +config PAX_EMUTRAMP
80551 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80552 + default y if PARISC
80553 + help
80554 + There are some programs and libraries that for one reason or
80555 + another attempt to execute special small code snippets from
80556 + non-executable memory pages. Most notable examples are the
80557 + signal handler return code generated by the kernel itself and
80558 + the GCC trampolines.
80559 +
80560 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80561 + such programs will no longer work under your kernel.
80562 +
80563 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80564 + utilities to enable trampoline emulation for the affected programs
80565 + yet still have the protection provided by the non-executable pages.
80566 +
80567 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80568 + your system will not even boot.
80569 +
80570 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80571 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80572 + for the affected files.
80573 +
80574 + NOTE: enabling this feature *may* open up a loophole in the
80575 + protection provided by non-executable pages that an attacker
80576 + could abuse. Therefore the best solution is to not have any
80577 + files on your system that would require this option. This can
80578 + be achieved by not using libc5 (which relies on the kernel
80579 + signal handler return code) and not using or rewriting programs
80580 + that make use of the nested function implementation of GCC.
80581 + Skilled users can just fix GCC itself so that it implements
80582 + nested function calls in a way that does not interfere with PaX.
80583 +
80584 +config PAX_EMUSIGRT
80585 + bool "Automatically emulate sigreturn trampolines"
80586 + depends on PAX_EMUTRAMP && PARISC
80587 + default y
80588 + help
80589 + Enabling this option will have the kernel automatically detect
80590 + and emulate signal return trampolines executing on the stack
80591 + that would otherwise lead to task termination.
80592 +
80593 + This solution is intended as a temporary one for users with
80594 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80595 + Modula-3 runtime, etc) or executables linked to such, basically
80596 + everything that does not specify its own SA_RESTORER function in
80597 + normal executable memory like glibc 2.1+ does.
80598 +
80599 + On parisc you MUST enable this option, otherwise your system will
80600 + not even boot.
80601 +
80602 + NOTE: this feature cannot be disabled on a per executable basis
80603 + and since it *does* open up a loophole in the protection provided
80604 + by non-executable pages, the best solution is to not have any
80605 + files on your system that would require this option.
80606 +
80607 +config PAX_MPROTECT
80608 + bool "Restrict mprotect()"
80609 + default y if GRKERNSEC_CONFIG_AUTO
80610 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80611 + help
80612 + Enabling this option will prevent programs from
80613 + - changing the executable status of memory pages that were
80614 + not originally created as executable,
80615 + - making read-only executable pages writable again,
80616 + - creating executable pages from anonymous memory,
80617 + - making read-only-after-relocations (RELRO) data pages writable again.
80618 +
80619 + You should say Y here to complete the protection provided by
80620 + the enforcement of non-executable pages.
80621 +
80622 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80623 + this feature on a per file basis.
80624 +
80625 +config PAX_MPROTECT_COMPAT
80626 + bool "Use legacy/compat protection demoting (read help)"
80627 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80628 + depends on PAX_MPROTECT
80629 + help
80630 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80631 + by sending the proper error code to the application. For some broken
80632 + userland, this can cause problems with Python or other applications. The
80633 + current implementation however allows for applications like clamav to
80634 + detect if JIT compilation/execution is allowed and to fall back gracefully
80635 + to an interpreter-based mode if it does not. While we encourage everyone
80636 + to use the current implementation as-is and push upstream to fix broken
80637 + userland (note that the RWX logging option can assist with this), in some
80638 + environments this may not be possible. Having to disable MPROTECT
80639 + completely on certain binaries reduces the security benefit of PaX,
80640 + so this option is provided for those environments to revert to the old
80641 + behavior.
80642 +
80643 +config PAX_ELFRELOCS
80644 + bool "Allow ELF text relocations (read help)"
80645 + depends on PAX_MPROTECT
80646 + default n
80647 + help
80648 + Non-executable pages and mprotect() restrictions are effective
80649 + in preventing the introduction of new executable code into an
80650 + attacked task's address space. There remain only two venues
80651 + for this kind of attack: if the attacker can execute already
80652 + existing code in the attacked task then he can either have it
80653 + create and mmap() a file containing his code or have it mmap()
80654 + an already existing ELF library that does not have position
80655 + independent code in it and use mprotect() on it to make it
80656 + writable and copy his code there. While protecting against
80657 + the former approach is beyond PaX, the latter can be prevented
80658 + by having only PIC ELF libraries on one's system (which do not
80659 + need to relocate their code). If you are sure this is your case,
80660 + as is the case with all modern Linux distributions, then leave
80661 + this option disabled. You should say 'n' here.
80662 +
80663 +config PAX_ETEXECRELOCS
80664 + bool "Allow ELF ET_EXEC text relocations"
80665 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80666 + select PAX_ELFRELOCS
80667 + default y
80668 + help
80669 + On some architectures there are incorrectly created applications
80670 + that require text relocations and would not work without enabling
80671 + this option. If you are an alpha, ia64 or parisc user, you should
80672 + enable this option and disable it once you have made sure that
80673 + none of your applications need it.
80674 +
80675 +config PAX_EMUPLT
80676 + bool "Automatically emulate ELF PLT"
80677 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80678 + default y
80679 + help
80680 + Enabling this option will have the kernel automatically detect
80681 + and emulate the Procedure Linkage Table entries in ELF files.
80682 + On some architectures such entries are in writable memory, and
80683 + become non-executable leading to task termination. Therefore
80684 + it is mandatory that you enable this option on alpha, parisc,
80685 + sparc and sparc64, otherwise your system would not even boot.
80686 +
80687 + NOTE: this feature *does* open up a loophole in the protection
80688 + provided by the non-executable pages, therefore the proper
80689 + solution is to modify the toolchain to produce a PLT that does
80690 + not need to be writable.
80691 +
80692 +config PAX_DLRESOLVE
80693 + bool 'Emulate old glibc resolver stub'
80694 + depends on PAX_EMUPLT && SPARC
80695 + default n
80696 + help
80697 + This option is needed if userland has an old glibc (before 2.4)
80698 + that puts a 'save' instruction into the runtime generated resolver
80699 + stub that needs special emulation.
80700 +
80701 +config PAX_KERNEXEC
80702 + bool "Enforce non-executable kernel pages"
80703 + 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))
80704 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80705 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80706 + select PAX_KERNEXEC_PLUGIN if X86_64
80707 + help
80708 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80709 + that is, enabling this option will make it harder to inject
80710 + and execute 'foreign' code in kernel memory itself.
80711 +
80712 +choice
80713 + prompt "Return Address Instrumentation Method"
80714 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80715 + depends on PAX_KERNEXEC_PLUGIN
80716 + help
80717 + Select the method used to instrument function pointer dereferences.
80718 + Note that binary modules cannot be instrumented by this approach.
80719 +
80720 + Note that the implementation requires a gcc with plugin support,
80721 + i.e., gcc 4.5 or newer. You may need to install the supporting
80722 + headers explicitly in addition to the normal gcc package.
80723 +
80724 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80725 + bool "bts"
80726 + help
80727 + This method is compatible with binary only modules but has
80728 + a higher runtime overhead.
80729 +
80730 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80731 + bool "or"
80732 + depends on !PARAVIRT
80733 + help
80734 + This method is incompatible with binary only modules but has
80735 + a lower runtime overhead.
80736 +endchoice
80737 +
80738 +config PAX_KERNEXEC_PLUGIN_METHOD
80739 + string
80740 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80741 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80742 + default ""
80743 +
80744 +config PAX_KERNEXEC_MODULE_TEXT
80745 + int "Minimum amount of memory reserved for module code"
80746 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80747 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80748 + depends on PAX_KERNEXEC && X86_32 && MODULES
80749 + help
80750 + Due to implementation details the kernel must reserve a fixed
80751 + amount of memory for module code at compile time that cannot be
80752 + changed at runtime. Here you can specify the minimum amount
80753 + in MB that will be reserved. Due to the same implementation
80754 + details this size will always be rounded up to the next 2/4 MB
80755 + boundary (depends on PAE) so the actually available memory for
80756 + module code will usually be more than this minimum.
80757 +
80758 + The default 4 MB should be enough for most users but if you have
80759 + an excessive number of modules (e.g., most distribution configs
80760 + compile many drivers as modules) or use huge modules such as
80761 + nvidia's kernel driver, you will need to adjust this amount.
80762 + A good rule of thumb is to look at your currently loaded kernel
80763 + modules and add up their sizes.
80764 +
80765 +endmenu
80766 +
80767 +menu "Address Space Layout Randomization"
80768 + depends on PAX
80769 +
80770 +config PAX_ASLR
80771 + bool "Address Space Layout Randomization"
80772 + default y if GRKERNSEC_CONFIG_AUTO
80773 + help
80774 + Many if not most exploit techniques rely on the knowledge of
80775 + certain addresses in the attacked program. The following options
80776 + will allow the kernel to apply a certain amount of randomization
80777 + to specific parts of the program thereby forcing an attacker to
80778 + guess them in most cases. Any failed guess will most likely crash
80779 + the attacked program which allows the kernel to detect such attempts
80780 + and react on them. PaX itself provides no reaction mechanisms,
80781 + instead it is strongly encouraged that you make use of Nergal's
80782 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80783 + (http://www.grsecurity.net/) built-in crash detection features or
80784 + develop one yourself.
80785 +
80786 + By saying Y here you can choose to randomize the following areas:
80787 + - top of the task's kernel stack
80788 + - top of the task's userland stack
80789 + - base address for mmap() requests that do not specify one
80790 + (this includes all libraries)
80791 + - base address of the main executable
80792 +
80793 + It is strongly recommended to say Y here as address space layout
80794 + randomization has negligible impact on performance yet it provides
80795 + a very effective protection.
80796 +
80797 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80798 + this feature on a per file basis.
80799 +
80800 +config PAX_RANDKSTACK
80801 + bool "Randomize kernel stack base"
80802 + default y if GRKERNSEC_CONFIG_AUTO
80803 + depends on X86_TSC && X86
80804 + help
80805 + By saying Y here the kernel will randomize every task's kernel
80806 + stack on every system call. This will not only force an attacker
80807 + to guess it but also prevent him from making use of possible
80808 + leaked information about it.
80809 +
80810 + Since the kernel stack is a rather scarce resource, randomization
80811 + may cause unexpected stack overflows, therefore you should very
80812 + carefully test your system. Note that once enabled in the kernel
80813 + configuration, this feature cannot be disabled on a per file basis.
80814 +
80815 +config PAX_RANDUSTACK
80816 + bool "Randomize user stack base"
80817 + default y if GRKERNSEC_CONFIG_AUTO
80818 + depends on PAX_ASLR
80819 + help
80820 + By saying Y here the kernel will randomize every task's userland
80821 + stack. The randomization is done in two steps where the second
80822 + one may apply a big amount of shift to the top of the stack and
80823 + cause problems for programs that want to use lots of memory (more
80824 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80825 + For this reason the second step can be controlled by 'chpax' or
80826 + 'paxctl' on a per file basis.
80827 +
80828 +config PAX_RANDMMAP
80829 + bool "Randomize mmap() base"
80830 + default y if GRKERNSEC_CONFIG_AUTO
80831 + depends on PAX_ASLR
80832 + help
80833 + By saying Y here the kernel will use a randomized base address for
80834 + mmap() requests that do not specify one themselves. As a result
80835 + all dynamically loaded libraries will appear at random addresses
80836 + and therefore be harder to exploit by a technique where an attacker
80837 + attempts to execute library code for his purposes (e.g. spawn a
80838 + shell from an exploited program that is running at an elevated
80839 + privilege level).
80840 +
80841 + Furthermore, if a program is relinked as a dynamic ELF file, its
80842 + base address will be randomized as well, completing the full
80843 + randomization of the address space layout. Attacking such programs
80844 + becomes a guess game. You can find an example of doing this at
80845 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80846 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80847 +
80848 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80849 + feature on a per file basis.
80850 +
80851 +endmenu
80852 +
80853 +menu "Miscellaneous hardening features"
80854 +
80855 +config PAX_MEMORY_SANITIZE
80856 + bool "Sanitize all freed memory"
80857 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80858 + depends on !HIBERNATION
80859 + help
80860 + By saying Y here the kernel will erase memory pages as soon as they
80861 + are freed. This in turn reduces the lifetime of data stored in the
80862 + pages, making it less likely that sensitive information such as
80863 + passwords, cryptographic secrets, etc stay in memory for too long.
80864 +
80865 + This is especially useful for programs whose runtime is short, long
80866 + lived processes and the kernel itself benefit from this as long as
80867 + they operate on whole memory pages and ensure timely freeing of pages
80868 + that may hold sensitive information.
80869 +
80870 + The tradeoff is performance impact, on a single CPU system kernel
80871 + compilation sees a 3% slowdown, other systems and workloads may vary
80872 + and you are advised to test this feature on your expected workload
80873 + before deploying it.
80874 +
80875 + Note that this feature does not protect data stored in live pages,
80876 + e.g., process memory swapped to disk may stay there for a long time.
80877 +
80878 +config PAX_MEMORY_STACKLEAK
80879 + bool "Sanitize kernel stack"
80880 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80881 + depends on X86
80882 + help
80883 + By saying Y here the kernel will erase the kernel stack before it
80884 + returns from a system call. This in turn reduces the information
80885 + that a kernel stack leak bug can reveal.
80886 +
80887 + Note that such a bug can still leak information that was put on
80888 + the stack by the current system call (the one eventually triggering
80889 + the bug) but traces of earlier system calls on the kernel stack
80890 + cannot leak anymore.
80891 +
80892 + The tradeoff is performance impact: on a single CPU system kernel
80893 + compilation sees a 1% slowdown, other systems and workloads may vary
80894 + and you are advised to test this feature on your expected workload
80895 + before deploying it.
80896 +
80897 + Note that the full feature requires a gcc with plugin support,
80898 + i.e., gcc 4.5 or newer. You may need to install the supporting
80899 + headers explicitly in addition to the normal gcc package. Using
80900 + older gcc versions means that functions with large enough stack
80901 + frames may leave uninitialized memory behind that may be exposed
80902 + to a later syscall leaking the stack.
80903 +
80904 +config PAX_MEMORY_UDEREF
80905 + bool "Prevent invalid userland pointer dereference"
80906 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80907 + depends on X86 && !UML_X86 && !XEN
80908 + select PAX_PER_CPU_PGD if X86_64
80909 + help
80910 + By saying Y here the kernel will be prevented from dereferencing
80911 + userland pointers in contexts where the kernel expects only kernel
80912 + pointers. This is both a useful runtime debugging feature and a
80913 + security measure that prevents exploiting a class of kernel bugs.
80914 +
80915 + The tradeoff is that some virtualization solutions may experience
80916 + a huge slowdown and therefore you should not enable this feature
80917 + for kernels meant to run in such environments. Whether a given VM
80918 + solution is affected or not is best determined by simply trying it
80919 + out, the performance impact will be obvious right on boot as this
80920 + mechanism engages from very early on. A good rule of thumb is that
80921 + VMs running on CPUs without hardware virtualization support (i.e.,
80922 + the majority of IA-32 CPUs) will likely experience the slowdown.
80923 +
80924 +config PAX_REFCOUNT
80925 + bool "Prevent various kernel object reference counter overflows"
80926 + default y if GRKERNSEC_CONFIG_AUTO
80927 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80928 + help
80929 + By saying Y here the kernel will detect and prevent overflowing
80930 + various (but not all) kinds of object reference counters. Such
80931 + overflows can normally occur due to bugs only and are often, if
80932 + not always, exploitable.
80933 +
80934 + The tradeoff is that data structures protected by an overflowed
80935 + refcount will never be freed and therefore will leak memory. Note
80936 + that this leak also happens even without this protection but in
80937 + that case the overflow can eventually trigger the freeing of the
80938 + data structure while it is still being used elsewhere, resulting
80939 + in the exploitable situation that this feature prevents.
80940 +
80941 + Since this has a negligible performance impact, you should enable
80942 + this feature.
80943 +
80944 +config PAX_USERCOPY
80945 + bool "Harden heap object copies between kernel and userland"
80946 + default y if GRKERNSEC_CONFIG_AUTO
80947 + depends on X86 || PPC || SPARC || ARM
80948 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80949 + select PAX_USERCOPY_SLABS
80950 + help
80951 + By saying Y here the kernel will enforce the size of heap objects
80952 + when they are copied in either direction between the kernel and
80953 + userland, even if only a part of the heap object is copied.
80954 +
80955 + Specifically, this checking prevents information leaking from the
80956 + kernel heap during kernel to userland copies (if the kernel heap
80957 + object is otherwise fully initialized) and prevents kernel heap
80958 + overflows during userland to kernel copies.
80959 +
80960 + Note that the current implementation provides the strictest bounds
80961 + checks for the SLUB allocator.
80962 +
80963 + Enabling this option also enables per-slab cache protection against
80964 + data in a given cache being copied into/out of via userland
80965 + accessors. Though the whitelist of regions will be reduced over
80966 + time, it notably protects important data structures like task structs.
80967 +
80968 + If frame pointers are enabled on x86, this option will also restrict
80969 + copies into and out of the kernel stack to local variables within a
80970 + single frame.
80971 +
80972 + Since this has a negligible performance impact, you should enable
80973 + this feature.
80974 +
80975 +config PAX_SIZE_OVERFLOW
80976 + bool "Prevent various integer overflows in function size parameters"
80977 + default y if GRKERNSEC_CONFIG_AUTO
80978 + depends on X86
80979 + help
80980 + By saying Y here the kernel recomputes expressions of function
80981 + arguments marked by a size_overflow attribute with double integer
80982 + precision (DImode/TImode for 32/64 bit integer types).
80983 +
80984 + The recomputed argument is checked against TYPE_MAX and an event
80985 + is logged on overflow and the triggering process is killed.
80986 +
80987 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80988 +
80989 + Note that the implementation requires a gcc with plugin support,
80990 + i.e., gcc 4.5 or newer. You may need to install the supporting
80991 + headers explicitly in addition to the normal gcc package.
80992 +
80993 +config PAX_LATENT_ENTROPY
80994 + bool "Generate some entropy during boot"
80995 + default y if GRKERNSEC_CONFIG_AUTO
80996 + help
80997 + By saying Y here the kernel will instrument early boot code to
80998 + extract some entropy from both original and artificially created
80999 + program state. This will help especially embedded systems where
81000 + there is little 'natural' source of entropy normally. The cost
81001 + is some slowdown of the boot process.
81002 +
81003 + Note that the implementation requires a gcc with plugin support,
81004 + i.e., gcc 4.5 or newer. You may need to install the supporting
81005 + headers explicitly in addition to the normal gcc package.
81006 +
81007 + Note that entropy extracted this way is not cryptographically
81008 + secure!
81009 +
81010 +endmenu
81011 +
81012 +endmenu
81013 +
81014 +source grsecurity/Kconfig
81015 +
81016 +endmenu
81017 +
81018 +endmenu
81019 +
81020 source security/keys/Kconfig
81021
81022 config SECURITY_DMESG_RESTRICT
81023 @@ -103,7 +993,7 @@ config INTEL_TXT
81024 config LSM_MMAP_MIN_ADDR
81025 int "Low address space for LSM to protect from user allocation"
81026 depends on SECURITY && SECURITY_SELINUX
81027 - default 32768 if ARM
81028 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81029 default 65536
81030 help
81031 This is the portion of low virtual memory which should be protected
81032 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81033 index 8ea39aa..8569ac5 100644
81034 --- a/security/apparmor/lsm.c
81035 +++ b/security/apparmor/lsm.c
81036 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81037 return error;
81038 }
81039
81040 -static struct security_operations apparmor_ops = {
81041 +static struct security_operations apparmor_ops __read_only = {
81042 .name = "apparmor",
81043
81044 .ptrace_access_check = apparmor_ptrace_access_check,
81045 diff --git a/security/commoncap.c b/security/commoncap.c
81046 index 6dbae46..d5611fd 100644
81047 --- a/security/commoncap.c
81048 +++ b/security/commoncap.c
81049 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81050 return 0;
81051 }
81052
81053 +/* returns:
81054 + 1 for suid privilege
81055 + 2 for sgid privilege
81056 + 3 for fscap privilege
81057 +*/
81058 +int is_privileged_binary(const struct dentry *dentry)
81059 +{
81060 + struct cpu_vfs_cap_data capdata;
81061 + struct inode *inode = dentry->d_inode;
81062 +
81063 + if (!inode || S_ISDIR(inode->i_mode))
81064 + return 0;
81065 +
81066 + if (inode->i_mode & S_ISUID)
81067 + return 1;
81068 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81069 + return 2;
81070 +
81071 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81072 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81073 + return 3;
81074 + }
81075 +
81076 + return 0;
81077 +}
81078 +
81079 /*
81080 * Attempt to get the on-exec apply capability sets for an executable file from
81081 * its xattrs and, if present, apply them to the proposed credentials being
81082 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81083 const struct cred *cred = current_cred();
81084 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81085
81086 + if (gr_acl_enable_at_secure())
81087 + return 1;
81088 +
81089 if (!uid_eq(cred->uid, root_uid)) {
81090 if (bprm->cap_effective)
81091 return 1;
81092 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81093 index e7c99fd..5b2fa24 100644
81094 --- a/security/integrity/ima/ima.h
81095 +++ b/security/integrity/ima/ima.h
81096 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81097 extern spinlock_t ima_queue_lock;
81098
81099 struct ima_h_table {
81100 - atomic_long_t len; /* number of stored measurements in the list */
81101 - atomic_long_t violations;
81102 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81103 + atomic_long_unchecked_t violations;
81104 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81105 };
81106 extern struct ima_h_table ima_htable;
81107 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81108 index 032ff03..c428a74 100644
81109 --- a/security/integrity/ima/ima_api.c
81110 +++ b/security/integrity/ima/ima_api.c
81111 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81112 int result;
81113
81114 /* can overflow, only indicator */
81115 - atomic_long_inc(&ima_htable.violations);
81116 + atomic_long_inc_unchecked(&ima_htable.violations);
81117
81118 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81119 if (!entry) {
81120 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81121 index 38477c9..87a60c7 100644
81122 --- a/security/integrity/ima/ima_fs.c
81123 +++ b/security/integrity/ima/ima_fs.c
81124 @@ -28,12 +28,12 @@
81125 static int valid_policy = 1;
81126 #define TMPBUFLEN 12
81127 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81128 - loff_t *ppos, atomic_long_t *val)
81129 + loff_t *ppos, atomic_long_unchecked_t *val)
81130 {
81131 char tmpbuf[TMPBUFLEN];
81132 ssize_t len;
81133
81134 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81135 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81136 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81137 }
81138
81139 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81140 index 55a6271..ad829c3 100644
81141 --- a/security/integrity/ima/ima_queue.c
81142 +++ b/security/integrity/ima/ima_queue.c
81143 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81144 INIT_LIST_HEAD(&qe->later);
81145 list_add_tail_rcu(&qe->later, &ima_measurements);
81146
81147 - atomic_long_inc(&ima_htable.len);
81148 + atomic_long_inc_unchecked(&ima_htable.len);
81149 key = ima_hash_key(entry->digest);
81150 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81151 return 0;
81152 diff --git a/security/keys/compat.c b/security/keys/compat.c
81153 index 1c26176..64a1ba2 100644
81154 --- a/security/keys/compat.c
81155 +++ b/security/keys/compat.c
81156 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81157 if (ret == 0)
81158 goto no_payload_free;
81159
81160 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81161 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81162
81163 if (iov != iovstack)
81164 kfree(iov);
81165 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81166 index 3364fbf..1f10f31 100644
81167 --- a/security/keys/keyctl.c
81168 +++ b/security/keys/keyctl.c
81169 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81170 /*
81171 * Copy the iovec data from userspace
81172 */
81173 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81174 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81175 unsigned ioc)
81176 {
81177 for (; ioc > 0; ioc--) {
81178 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81179 * If successful, 0 will be returned.
81180 */
81181 long keyctl_instantiate_key_common(key_serial_t id,
81182 - const struct iovec *payload_iov,
81183 + const struct iovec __user *payload_iov,
81184 unsigned ioc,
81185 size_t plen,
81186 key_serial_t ringid)
81187 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81188 [0].iov_len = plen
81189 };
81190
81191 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81192 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81193 }
81194
81195 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81196 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81197 if (ret == 0)
81198 goto no_payload_free;
81199
81200 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81201 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81202
81203 if (iov != iovstack)
81204 kfree(iov);
81205 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81206 index 81e7852..2b2ecc3 100644
81207 --- a/security/keys/keyring.c
81208 +++ b/security/keys/keyring.c
81209 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81210 ret = -EFAULT;
81211
81212 for (loop = 0; loop < klist->nkeys; loop++) {
81213 + key_serial_t serial;
81214 key = rcu_deref_link_locked(klist, loop,
81215 keyring);
81216 + serial = key->serial;
81217
81218 tmp = sizeof(key_serial_t);
81219 if (tmp > buflen)
81220 tmp = buflen;
81221
81222 - if (copy_to_user(buffer,
81223 - &key->serial,
81224 - tmp) != 0)
81225 + if (copy_to_user(buffer, &serial, tmp))
81226 goto error;
81227
81228 buflen -= tmp;
81229 diff --git a/security/min_addr.c b/security/min_addr.c
81230 index f728728..6457a0c 100644
81231 --- a/security/min_addr.c
81232 +++ b/security/min_addr.c
81233 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81234 */
81235 static void update_mmap_min_addr(void)
81236 {
81237 +#ifndef SPARC
81238 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81239 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81240 mmap_min_addr = dac_mmap_min_addr;
81241 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81242 #else
81243 mmap_min_addr = dac_mmap_min_addr;
81244 #endif
81245 +#endif
81246 }
81247
81248 /*
81249 diff --git a/security/security.c b/security/security.c
81250 index 860aeb3..45765c0 100644
81251 --- a/security/security.c
81252 +++ b/security/security.c
81253 @@ -20,6 +20,7 @@
81254 #include <linux/ima.h>
81255 #include <linux/evm.h>
81256 #include <linux/fsnotify.h>
81257 +#include <linux/mm.h>
81258 #include <linux/mman.h>
81259 #include <linux/mount.h>
81260 #include <linux/personality.h>
81261 @@ -32,8 +33,8 @@
81262 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81263 CONFIG_DEFAULT_SECURITY;
81264
81265 -static struct security_operations *security_ops;
81266 -static struct security_operations default_security_ops = {
81267 +static struct security_operations *security_ops __read_only;
81268 +static struct security_operations default_security_ops __read_only = {
81269 .name = "default",
81270 };
81271
81272 @@ -74,7 +75,9 @@ int __init security_init(void)
81273
81274 void reset_security_ops(void)
81275 {
81276 + pax_open_kernel();
81277 security_ops = &default_security_ops;
81278 + pax_close_kernel();
81279 }
81280
81281 /* Save user chosen LSM */
81282 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81283 index 6c77f63..7496c76 100644
81284 --- a/security/selinux/hooks.c
81285 +++ b/security/selinux/hooks.c
81286 @@ -95,8 +95,6 @@
81287
81288 #define NUM_SEL_MNT_OPTS 5
81289
81290 -extern struct security_operations *security_ops;
81291 -
81292 /* SECMARK reference count */
81293 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81294
81295 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81296
81297 #endif
81298
81299 -static struct security_operations selinux_ops = {
81300 +static struct security_operations selinux_ops __read_only = {
81301 .name = "selinux",
81302
81303 .ptrace_access_check = selinux_ptrace_access_check,
81304 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81305 index 65f67cb..3f141ef 100644
81306 --- a/security/selinux/include/xfrm.h
81307 +++ b/security/selinux/include/xfrm.h
81308 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81309
81310 static inline void selinux_xfrm_notify_policyload(void)
81311 {
81312 - atomic_inc(&flow_cache_genid);
81313 + atomic_inc_unchecked(&flow_cache_genid);
81314 rt_genid_bump(&init_net);
81315 }
81316 #else
81317 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81318 index 8221514..5c4775f 100644
81319 --- a/security/smack/smack_lsm.c
81320 +++ b/security/smack/smack_lsm.c
81321 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81322 return 0;
81323 }
81324
81325 -struct security_operations smack_ops = {
81326 +struct security_operations smack_ops __read_only = {
81327 .name = "smack",
81328
81329 .ptrace_access_check = smack_ptrace_access_check,
81330 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81331 index c2d04a5..e6a1aeb 100644
81332 --- a/security/tomoyo/tomoyo.c
81333 +++ b/security/tomoyo/tomoyo.c
81334 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81335 * tomoyo_security_ops is a "struct security_operations" which is used for
81336 * registering TOMOYO.
81337 */
81338 -static struct security_operations tomoyo_security_ops = {
81339 +static struct security_operations tomoyo_security_ops __read_only = {
81340 .name = "tomoyo",
81341 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81342 .cred_prepare = tomoyo_cred_prepare,
81343 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81344 index 51d6709..1f3dbe2 100644
81345 --- a/security/yama/Kconfig
81346 +++ b/security/yama/Kconfig
81347 @@ -1,6 +1,6 @@
81348 config SECURITY_YAMA
81349 bool "Yama support"
81350 - depends on SECURITY
81351 + depends on SECURITY && !GRKERNSEC
81352 select SECURITYFS
81353 select SECURITY_PATH
81354 default n
81355 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81356 index 4cedc69..e59d8a3 100644
81357 --- a/sound/aoa/codecs/onyx.c
81358 +++ b/sound/aoa/codecs/onyx.c
81359 @@ -54,7 +54,7 @@ struct onyx {
81360 spdif_locked:1,
81361 analog_locked:1,
81362 original_mute:2;
81363 - int open_count;
81364 + local_t open_count;
81365 struct codec_info *codec_info;
81366
81367 /* mutex serializes concurrent access to the device
81368 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81369 struct onyx *onyx = cii->codec_data;
81370
81371 mutex_lock(&onyx->mutex);
81372 - onyx->open_count++;
81373 + local_inc(&onyx->open_count);
81374 mutex_unlock(&onyx->mutex);
81375
81376 return 0;
81377 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81378 struct onyx *onyx = cii->codec_data;
81379
81380 mutex_lock(&onyx->mutex);
81381 - onyx->open_count--;
81382 - if (!onyx->open_count)
81383 + if (local_dec_and_test(&onyx->open_count))
81384 onyx->spdif_locked = onyx->analog_locked = 0;
81385 mutex_unlock(&onyx->mutex);
81386
81387 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81388 index ffd2025..df062c9 100644
81389 --- a/sound/aoa/codecs/onyx.h
81390 +++ b/sound/aoa/codecs/onyx.h
81391 @@ -11,6 +11,7 @@
81392 #include <linux/i2c.h>
81393 #include <asm/pmac_low_i2c.h>
81394 #include <asm/prom.h>
81395 +#include <asm/local.h>
81396
81397 /* PCM3052 register definitions */
81398
81399 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81400 index 08fde00..0bf641a 100644
81401 --- a/sound/core/oss/pcm_oss.c
81402 +++ b/sound/core/oss/pcm_oss.c
81403 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81404 if (in_kernel) {
81405 mm_segment_t fs;
81406 fs = snd_enter_user();
81407 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81408 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81409 snd_leave_user(fs);
81410 } else {
81411 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81412 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81413 }
81414 if (ret != -EPIPE && ret != -ESTRPIPE)
81415 break;
81416 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81417 if (in_kernel) {
81418 mm_segment_t fs;
81419 fs = snd_enter_user();
81420 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81421 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81422 snd_leave_user(fs);
81423 } else {
81424 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81425 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81426 }
81427 if (ret == -EPIPE) {
81428 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81429 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81430 struct snd_pcm_plugin_channel *channels;
81431 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81432 if (!in_kernel) {
81433 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81434 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81435 return -EFAULT;
81436 buf = runtime->oss.buffer;
81437 }
81438 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81439 }
81440 } else {
81441 tmp = snd_pcm_oss_write2(substream,
81442 - (const char __force *)buf,
81443 + (const char __force_kernel *)buf,
81444 runtime->oss.period_bytes, 0);
81445 if (tmp <= 0)
81446 goto err;
81447 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81448 struct snd_pcm_runtime *runtime = substream->runtime;
81449 snd_pcm_sframes_t frames, frames1;
81450 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81451 - char __user *final_dst = (char __force __user *)buf;
81452 + char __user *final_dst = (char __force_user *)buf;
81453 if (runtime->oss.plugin_first) {
81454 struct snd_pcm_plugin_channel *channels;
81455 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81456 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81457 xfer += tmp;
81458 runtime->oss.buffer_used -= tmp;
81459 } else {
81460 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81461 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81462 runtime->oss.period_bytes, 0);
81463 if (tmp <= 0)
81464 goto err;
81465 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81466 size1);
81467 size1 /= runtime->channels; /* frames */
81468 fs = snd_enter_user();
81469 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81470 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81471 snd_leave_user(fs);
81472 }
81473 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81474 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81475 index 91cdf94..4085161 100644
81476 --- a/sound/core/pcm_compat.c
81477 +++ b/sound/core/pcm_compat.c
81478 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81479 int err;
81480
81481 fs = snd_enter_user();
81482 - err = snd_pcm_delay(substream, &delay);
81483 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81484 snd_leave_user(fs);
81485 if (err < 0)
81486 return err;
81487 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81488 index 53b5ada..2db94c8 100644
81489 --- a/sound/core/pcm_native.c
81490 +++ b/sound/core/pcm_native.c
81491 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81492 switch (substream->stream) {
81493 case SNDRV_PCM_STREAM_PLAYBACK:
81494 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81495 - (void __user *)arg);
81496 + (void __force_user *)arg);
81497 break;
81498 case SNDRV_PCM_STREAM_CAPTURE:
81499 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81500 - (void __user *)arg);
81501 + (void __force_user *)arg);
81502 break;
81503 default:
81504 result = -EINVAL;
81505 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81506 index 5cf8d65..912a79c 100644
81507 --- a/sound/core/seq/seq_device.c
81508 +++ b/sound/core/seq/seq_device.c
81509 @@ -64,7 +64,7 @@ struct ops_list {
81510 int argsize; /* argument size */
81511
81512 /* operators */
81513 - struct snd_seq_dev_ops ops;
81514 + struct snd_seq_dev_ops *ops;
81515
81516 /* registred devices */
81517 struct list_head dev_list; /* list of devices */
81518 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81519
81520 mutex_lock(&ops->reg_mutex);
81521 /* copy driver operators */
81522 - ops->ops = *entry;
81523 + ops->ops = entry;
81524 ops->driver |= DRIVER_LOADED;
81525 ops->argsize = argsize;
81526
81527 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81528 dev->name, ops->id, ops->argsize, dev->argsize);
81529 return -EINVAL;
81530 }
81531 - if (ops->ops.init_device(dev) >= 0) {
81532 + if (ops->ops->init_device(dev) >= 0) {
81533 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81534 ops->num_init_devices++;
81535 } else {
81536 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81537 dev->name, ops->id, ops->argsize, dev->argsize);
81538 return -EINVAL;
81539 }
81540 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81541 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81542 dev->status = SNDRV_SEQ_DEVICE_FREE;
81543 dev->driver_data = NULL;
81544 ops->num_init_devices--;
81545 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81546 index 2d5514b..3afae9c 100644
81547 --- a/sound/drivers/mts64.c
81548 +++ b/sound/drivers/mts64.c
81549 @@ -29,6 +29,7 @@
81550 #include <sound/initval.h>
81551 #include <sound/rawmidi.h>
81552 #include <sound/control.h>
81553 +#include <asm/local.h>
81554
81555 #define CARD_NAME "Miditerminal 4140"
81556 #define DRIVER_NAME "MTS64"
81557 @@ -67,7 +68,7 @@ struct mts64 {
81558 struct pardevice *pardev;
81559 int pardev_claimed;
81560
81561 - int open_count;
81562 + local_t open_count;
81563 int current_midi_output_port;
81564 int current_midi_input_port;
81565 u8 mode[MTS64_NUM_INPUT_PORTS];
81566 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81567 {
81568 struct mts64 *mts = substream->rmidi->private_data;
81569
81570 - if (mts->open_count == 0) {
81571 + if (local_read(&mts->open_count) == 0) {
81572 /* We don't need a spinlock here, because this is just called
81573 if the device has not been opened before.
81574 So there aren't any IRQs from the device */
81575 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81576
81577 msleep(50);
81578 }
81579 - ++(mts->open_count);
81580 + local_inc(&mts->open_count);
81581
81582 return 0;
81583 }
81584 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81585 struct mts64 *mts = substream->rmidi->private_data;
81586 unsigned long flags;
81587
81588 - --(mts->open_count);
81589 - if (mts->open_count == 0) {
81590 + if (local_dec_return(&mts->open_count) == 0) {
81591 /* We need the spinlock_irqsave here because we can still
81592 have IRQs at this point */
81593 spin_lock_irqsave(&mts->lock, flags);
81594 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81595
81596 msleep(500);
81597
81598 - } else if (mts->open_count < 0)
81599 - mts->open_count = 0;
81600 + } else if (local_read(&mts->open_count) < 0)
81601 + local_set(&mts->open_count, 0);
81602
81603 return 0;
81604 }
81605 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81606 index b953fb4..1999c01 100644
81607 --- a/sound/drivers/opl4/opl4_lib.c
81608 +++ b/sound/drivers/opl4/opl4_lib.c
81609 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81610 MODULE_DESCRIPTION("OPL4 driver");
81611 MODULE_LICENSE("GPL");
81612
81613 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81614 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81615 {
81616 int timeout = 10;
81617 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81618 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81619 index 8364855..59f2e2b 100644
81620 --- a/sound/drivers/portman2x4.c
81621 +++ b/sound/drivers/portman2x4.c
81622 @@ -48,6 +48,7 @@
81623 #include <sound/initval.h>
81624 #include <sound/rawmidi.h>
81625 #include <sound/control.h>
81626 +#include <asm/local.h>
81627
81628 #define CARD_NAME "Portman 2x4"
81629 #define DRIVER_NAME "portman"
81630 @@ -85,7 +86,7 @@ struct portman {
81631 struct pardevice *pardev;
81632 int pardev_claimed;
81633
81634 - int open_count;
81635 + local_t open_count;
81636 int mode[PORTMAN_NUM_INPUT_PORTS];
81637 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81638 };
81639 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81640 index ea995af..f1bfa37 100644
81641 --- a/sound/firewire/amdtp.c
81642 +++ b/sound/firewire/amdtp.c
81643 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81644 ptr = s->pcm_buffer_pointer + data_blocks;
81645 if (ptr >= pcm->runtime->buffer_size)
81646 ptr -= pcm->runtime->buffer_size;
81647 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81648 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81649
81650 s->pcm_period_pointer += data_blocks;
81651 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81652 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81653 */
81654 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81655 {
81656 - ACCESS_ONCE(s->source_node_id_field) =
81657 + ACCESS_ONCE_RW(s->source_node_id_field) =
81658 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81659 }
81660 EXPORT_SYMBOL(amdtp_out_stream_update);
81661 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81662 index b680c5e..061b7a0 100644
81663 --- a/sound/firewire/amdtp.h
81664 +++ b/sound/firewire/amdtp.h
81665 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81666 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81667 struct snd_pcm_substream *pcm)
81668 {
81669 - ACCESS_ONCE(s->pcm) = pcm;
81670 + ACCESS_ONCE_RW(s->pcm) = pcm;
81671 }
81672
81673 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81674 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81675 index d428ffe..751ef78 100644
81676 --- a/sound/firewire/isight.c
81677 +++ b/sound/firewire/isight.c
81678 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81679 ptr += count;
81680 if (ptr >= runtime->buffer_size)
81681 ptr -= runtime->buffer_size;
81682 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81683 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81684
81685 isight->period_counter += count;
81686 if (isight->period_counter >= runtime->period_size) {
81687 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81688 if (err < 0)
81689 return err;
81690
81691 - ACCESS_ONCE(isight->pcm_active) = true;
81692 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81693
81694 return 0;
81695 }
81696 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81697 {
81698 struct isight *isight = substream->private_data;
81699
81700 - ACCESS_ONCE(isight->pcm_active) = false;
81701 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81702
81703 mutex_lock(&isight->mutex);
81704 isight_stop_streaming(isight);
81705 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81706
81707 switch (cmd) {
81708 case SNDRV_PCM_TRIGGER_START:
81709 - ACCESS_ONCE(isight->pcm_running) = true;
81710 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81711 break;
81712 case SNDRV_PCM_TRIGGER_STOP:
81713 - ACCESS_ONCE(isight->pcm_running) = false;
81714 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81715 break;
81716 default:
81717 return -EINVAL;
81718 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81719 index 7bd5e33..1fcab12 100644
81720 --- a/sound/isa/cmi8330.c
81721 +++ b/sound/isa/cmi8330.c
81722 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81723
81724 struct snd_pcm *pcm;
81725 struct snd_cmi8330_stream {
81726 - struct snd_pcm_ops ops;
81727 + snd_pcm_ops_no_const ops;
81728 snd_pcm_open_callback_t open;
81729 void *private_data; /* sb or wss */
81730 } streams[2];
81731 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81732 index b2b3c01..e1c1e1f 100644
81733 --- a/sound/oss/sb_audio.c
81734 +++ b/sound/oss/sb_audio.c
81735 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
81736 buf16 = (signed short *)(localbuf + localoffs);
81737 while (c)
81738 {
81739 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81740 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81741 if (copy_from_user(lbuf8,
81742 userbuf+useroffs + p,
81743 locallen))
81744 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81745 index 7d8803a..559f8d0 100644
81746 --- a/sound/oss/swarm_cs4297a.c
81747 +++ b/sound/oss/swarm_cs4297a.c
81748 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
81749 {
81750 struct cs4297a_state *s;
81751 u32 pwr, id;
81752 - mm_segment_t fs;
81753 int rval;
81754 #ifndef CONFIG_BCM_CS4297A_CSWARM
81755 u64 cfg;
81756 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
81757 if (!rval) {
81758 char *sb1250_duart_present;
81759
81760 +#if 0
81761 + mm_segment_t fs;
81762 fs = get_fs();
81763 set_fs(KERNEL_DS);
81764 -#if 0
81765 val = SOUND_MASK_LINE;
81766 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81767 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81768 val = initvol[i].vol;
81769 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81770 }
81771 + set_fs(fs);
81772 // cs4297a_write_ac97(s, 0x18, 0x0808);
81773 #else
81774 // cs4297a_write_ac97(s, 0x5e, 0x180);
81775 cs4297a_write_ac97(s, 0x02, 0x0808);
81776 cs4297a_write_ac97(s, 0x18, 0x0808);
81777 #endif
81778 - set_fs(fs);
81779
81780 list_add(&s->list, &cs4297a_devs);
81781
81782 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81783 index e5a7e19..4049063 100644
81784 --- a/sound/pci/hda/hda_codec.h
81785 +++ b/sound/pci/hda/hda_codec.h
81786 @@ -614,7 +614,7 @@ struct hda_bus_ops {
81787 /* notify power-up/down from codec to controller */
81788 void (*pm_notify)(struct hda_bus *bus);
81789 #endif
81790 -};
81791 +} __no_const;
81792
81793 /* template to pass to the bus constructor */
81794 struct hda_bus_template {
81795 @@ -714,6 +714,7 @@ struct hda_codec_ops {
81796 #endif
81797 void (*reboot_notify)(struct hda_codec *codec);
81798 };
81799 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81800
81801 /* record for amp information cache */
81802 struct hda_cache_head {
81803 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
81804 struct snd_pcm_substream *substream);
81805 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81806 struct snd_pcm_substream *substream);
81807 -};
81808 +} __no_const;
81809
81810 /* PCM information for each substream */
81811 struct hda_pcm_stream {
81812 @@ -802,7 +803,7 @@ struct hda_codec {
81813 const char *modelname; /* model name for preset */
81814
81815 /* set by patch */
81816 - struct hda_codec_ops patch_ops;
81817 + hda_codec_ops_no_const patch_ops;
81818
81819 /* PCM to create, set by patch_ops.build_pcms callback */
81820 unsigned int num_pcms;
81821 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81822 index 0da778a..bc38b84 100644
81823 --- a/sound/pci/ice1712/ice1712.h
81824 +++ b/sound/pci/ice1712/ice1712.h
81825 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81826 unsigned int mask_flags; /* total mask bits */
81827 struct snd_akm4xxx_ops {
81828 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81829 - } ops;
81830 + } __no_const ops;
81831 };
81832
81833 struct snd_ice1712_spdif {
81834 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81835 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81836 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81837 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81838 - } ops;
81839 + } __no_const ops;
81840 };
81841
81842
81843 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
81844 index bddc405..2c0733c 100644
81845 --- a/sound/pci/ymfpci/ymfpci.h
81846 +++ b/sound/pci/ymfpci/ymfpci.h
81847 @@ -358,7 +358,7 @@ struct snd_ymfpci {
81848 spinlock_t reg_lock;
81849 spinlock_t voice_lock;
81850 wait_queue_head_t interrupt_sleep;
81851 - atomic_t interrupt_sleep_count;
81852 + atomic_unchecked_t interrupt_sleep_count;
81853 struct snd_info_entry *proc_entry;
81854 const struct firmware *dsp_microcode;
81855 const struct firmware *controller_microcode;
81856 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81857 index 62b2363..ee77972 100644
81858 --- a/sound/pci/ymfpci/ymfpci_main.c
81859 +++ b/sound/pci/ymfpci/ymfpci_main.c
81860 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81861 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81862 break;
81863 }
81864 - if (atomic_read(&chip->interrupt_sleep_count)) {
81865 - atomic_set(&chip->interrupt_sleep_count, 0);
81866 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81867 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81868 wake_up(&chip->interrupt_sleep);
81869 }
81870 __end:
81871 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81872 continue;
81873 init_waitqueue_entry(&wait, current);
81874 add_wait_queue(&chip->interrupt_sleep, &wait);
81875 - atomic_inc(&chip->interrupt_sleep_count);
81876 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81877 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81878 remove_wait_queue(&chip->interrupt_sleep, &wait);
81879 }
81880 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81881 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81882 spin_unlock(&chip->reg_lock);
81883
81884 - if (atomic_read(&chip->interrupt_sleep_count)) {
81885 - atomic_set(&chip->interrupt_sleep_count, 0);
81886 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81887 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81888 wake_up(&chip->interrupt_sleep);
81889 }
81890 }
81891 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81892 spin_lock_init(&chip->reg_lock);
81893 spin_lock_init(&chip->voice_lock);
81894 init_waitqueue_head(&chip->interrupt_sleep);
81895 - atomic_set(&chip->interrupt_sleep_count, 0);
81896 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81897 chip->card = card;
81898 chip->pci = pci;
81899 chip->irq = -1;
81900 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81901 new file mode 100644
81902 index 0000000..50f2f2f
81903 --- /dev/null
81904 +++ b/tools/gcc/.gitignore
81905 @@ -0,0 +1 @@
81906 +size_overflow_hash.h
81907 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81908 new file mode 100644
81909 index 0000000..1d09b7e
81910 --- /dev/null
81911 +++ b/tools/gcc/Makefile
81912 @@ -0,0 +1,43 @@
81913 +#CC := gcc
81914 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81915 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81916 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81917 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81918 +
81919 +ifeq ($(PLUGINCC),$(HOSTCC))
81920 +HOSTLIBS := hostlibs
81921 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81922 +else
81923 +HOSTLIBS := hostcxxlibs
81924 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81925 +endif
81926 +
81927 +$(HOSTLIBS)-y := constify_plugin.so
81928 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81929 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81930 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81931 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81932 +$(HOSTLIBS)-y += colorize_plugin.so
81933 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81934 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81935 +
81936 +always := $($(HOSTLIBS)-y)
81937 +
81938 +constify_plugin-objs := constify_plugin.o
81939 +stackleak_plugin-objs := stackleak_plugin.o
81940 +kallocstat_plugin-objs := kallocstat_plugin.o
81941 +kernexec_plugin-objs := kernexec_plugin.o
81942 +checker_plugin-objs := checker_plugin.o
81943 +colorize_plugin-objs := colorize_plugin.o
81944 +size_overflow_plugin-objs := size_overflow_plugin.o
81945 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81946 +
81947 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81948 +
81949 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81950 + cmd_build_size_overflow_hash = \
81951 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81952 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81953 + $(call if_changed,build_size_overflow_hash)
81954 +
81955 +targets += size_overflow_hash.h
81956 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81957 new file mode 100644
81958 index 0000000..d41b5af
81959 --- /dev/null
81960 +++ b/tools/gcc/checker_plugin.c
81961 @@ -0,0 +1,171 @@
81962 +/*
81963 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81964 + * Licensed under the GPL v2
81965 + *
81966 + * Note: the choice of the license means that the compilation process is
81967 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81968 + * but for the kernel it doesn't matter since it doesn't link against
81969 + * any of the gcc libraries
81970 + *
81971 + * gcc plugin to implement various sparse (source code checker) features
81972 + *
81973 + * TODO:
81974 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81975 + *
81976 + * BUGS:
81977 + * - none known
81978 + */
81979 +#include "gcc-plugin.h"
81980 +#include "config.h"
81981 +#include "system.h"
81982 +#include "coretypes.h"
81983 +#include "tree.h"
81984 +#include "tree-pass.h"
81985 +#include "flags.h"
81986 +#include "intl.h"
81987 +#include "toplev.h"
81988 +#include "plugin.h"
81989 +//#include "expr.h" where are you...
81990 +#include "diagnostic.h"
81991 +#include "plugin-version.h"
81992 +#include "tm.h"
81993 +#include "function.h"
81994 +#include "basic-block.h"
81995 +#include "gimple.h"
81996 +#include "rtl.h"
81997 +#include "emit-rtl.h"
81998 +#include "tree-flow.h"
81999 +#include "target.h"
82000 +
82001 +extern void c_register_addr_space (const char *str, addr_space_t as);
82002 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82003 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82004 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82005 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82006 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82007 +
82008 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82009 +extern rtx emit_move_insn(rtx x, rtx y);
82010 +
82011 +int plugin_is_GPL_compatible;
82012 +
82013 +static struct plugin_info checker_plugin_info = {
82014 + .version = "201111150100",
82015 +};
82016 +
82017 +#define ADDR_SPACE_KERNEL 0
82018 +#define ADDR_SPACE_FORCE_KERNEL 1
82019 +#define ADDR_SPACE_USER 2
82020 +#define ADDR_SPACE_FORCE_USER 3
82021 +#define ADDR_SPACE_IOMEM 0
82022 +#define ADDR_SPACE_FORCE_IOMEM 0
82023 +#define ADDR_SPACE_PERCPU 0
82024 +#define ADDR_SPACE_FORCE_PERCPU 0
82025 +#define ADDR_SPACE_RCU 0
82026 +#define ADDR_SPACE_FORCE_RCU 0
82027 +
82028 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82029 +{
82030 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82031 +}
82032 +
82033 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82034 +{
82035 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82036 +}
82037 +
82038 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82039 +{
82040 + return default_addr_space_valid_pointer_mode(mode, as);
82041 +}
82042 +
82043 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82044 +{
82045 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82046 +}
82047 +
82048 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82049 +{
82050 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82051 +}
82052 +
82053 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82054 +{
82055 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82056 + return true;
82057 +
82058 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82059 + return true;
82060 +
82061 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82062 + return true;
82063 +
82064 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82065 + return true;
82066 +
82067 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82068 + return true;
82069 +
82070 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82071 + return true;
82072 +
82073 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82074 + return true;
82075 +
82076 + return subset == superset;
82077 +}
82078 +
82079 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82080 +{
82081 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82082 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82083 +
82084 + return op;
82085 +}
82086 +
82087 +static void register_checker_address_spaces(void *event_data, void *data)
82088 +{
82089 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82090 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82091 + c_register_addr_space("__user", ADDR_SPACE_USER);
82092 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82093 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82094 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82095 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82096 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82097 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82098 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82099 +
82100 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82101 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82102 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82103 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82104 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82105 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82106 + targetm.addr_space.convert = checker_addr_space_convert;
82107 +}
82108 +
82109 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82110 +{
82111 + const char * const plugin_name = plugin_info->base_name;
82112 + const int argc = plugin_info->argc;
82113 + const struct plugin_argument * const argv = plugin_info->argv;
82114 + int i;
82115 +
82116 + if (!plugin_default_version_check(version, &gcc_version)) {
82117 + error(G_("incompatible gcc/plugin versions"));
82118 + return 1;
82119 + }
82120 +
82121 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82122 +
82123 + for (i = 0; i < argc; ++i)
82124 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82125 +
82126 + if (TARGET_64BIT == 0)
82127 + return 0;
82128 +
82129 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82130 +
82131 + return 0;
82132 +}
82133 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82134 new file mode 100644
82135 index 0000000..846aeb0
82136 --- /dev/null
82137 +++ b/tools/gcc/colorize_plugin.c
82138 @@ -0,0 +1,148 @@
82139 +/*
82140 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82141 + * Licensed under the GPL v2
82142 + *
82143 + * Note: the choice of the license means that the compilation process is
82144 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82145 + * but for the kernel it doesn't matter since it doesn't link against
82146 + * any of the gcc libraries
82147 + *
82148 + * gcc plugin to colorize diagnostic output
82149 + *
82150 + */
82151 +
82152 +#include "gcc-plugin.h"
82153 +#include "config.h"
82154 +#include "system.h"
82155 +#include "coretypes.h"
82156 +#include "tree.h"
82157 +#include "tree-pass.h"
82158 +#include "flags.h"
82159 +#include "intl.h"
82160 +#include "toplev.h"
82161 +#include "plugin.h"
82162 +#include "diagnostic.h"
82163 +#include "plugin-version.h"
82164 +#include "tm.h"
82165 +
82166 +int plugin_is_GPL_compatible;
82167 +
82168 +static struct plugin_info colorize_plugin_info = {
82169 + .version = "201203092200",
82170 + .help = NULL,
82171 +};
82172 +
82173 +#define GREEN "\033[32m\033[2m"
82174 +#define LIGHTGREEN "\033[32m\033[1m"
82175 +#define YELLOW "\033[33m\033[2m"
82176 +#define LIGHTYELLOW "\033[33m\033[1m"
82177 +#define RED "\033[31m\033[2m"
82178 +#define LIGHTRED "\033[31m\033[1m"
82179 +#define BLUE "\033[34m\033[2m"
82180 +#define LIGHTBLUE "\033[34m\033[1m"
82181 +#define BRIGHT "\033[m\033[1m"
82182 +#define NORMAL "\033[m"
82183 +
82184 +static diagnostic_starter_fn old_starter;
82185 +static diagnostic_finalizer_fn old_finalizer;
82186 +
82187 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82188 +{
82189 + const char *color;
82190 + char *newprefix;
82191 +
82192 + switch (diagnostic->kind) {
82193 + case DK_NOTE:
82194 + color = LIGHTBLUE;
82195 + break;
82196 +
82197 + case DK_PEDWARN:
82198 + case DK_WARNING:
82199 + color = LIGHTYELLOW;
82200 + break;
82201 +
82202 + case DK_ERROR:
82203 + case DK_FATAL:
82204 + case DK_ICE:
82205 + case DK_PERMERROR:
82206 + case DK_SORRY:
82207 + color = LIGHTRED;
82208 + break;
82209 +
82210 + default:
82211 + color = NORMAL;
82212 + }
82213 +
82214 + old_starter(context, diagnostic);
82215 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82216 + return;
82217 + pp_destroy_prefix(context->printer);
82218 + pp_set_prefix(context->printer, newprefix);
82219 +}
82220 +
82221 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82222 +{
82223 + old_finalizer(context, diagnostic);
82224 +}
82225 +
82226 +static void colorize_arm(void)
82227 +{
82228 + old_starter = diagnostic_starter(global_dc);
82229 + old_finalizer = diagnostic_finalizer(global_dc);
82230 +
82231 + diagnostic_starter(global_dc) = start_colorize;
82232 + diagnostic_finalizer(global_dc) = finalize_colorize;
82233 +}
82234 +
82235 +static unsigned int execute_colorize_rearm(void)
82236 +{
82237 + if (diagnostic_starter(global_dc) == start_colorize)
82238 + return 0;
82239 +
82240 + colorize_arm();
82241 + return 0;
82242 +}
82243 +
82244 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82245 + .pass = {
82246 + .type = SIMPLE_IPA_PASS,
82247 + .name = "colorize_rearm",
82248 + .gate = NULL,
82249 + .execute = execute_colorize_rearm,
82250 + .sub = NULL,
82251 + .next = NULL,
82252 + .static_pass_number = 0,
82253 + .tv_id = TV_NONE,
82254 + .properties_required = 0,
82255 + .properties_provided = 0,
82256 + .properties_destroyed = 0,
82257 + .todo_flags_start = 0,
82258 + .todo_flags_finish = 0
82259 + }
82260 +};
82261 +
82262 +static void colorize_start_unit(void *gcc_data, void *user_data)
82263 +{
82264 + colorize_arm();
82265 +}
82266 +
82267 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82268 +{
82269 + const char * const plugin_name = plugin_info->base_name;
82270 + struct register_pass_info colorize_rearm_pass_info = {
82271 + .pass = &pass_ipa_colorize_rearm.pass,
82272 + .reference_pass_name = "*free_lang_data",
82273 + .ref_pass_instance_number = 1,
82274 + .pos_op = PASS_POS_INSERT_AFTER
82275 + };
82276 +
82277 + if (!plugin_default_version_check(version, &gcc_version)) {
82278 + error(G_("incompatible gcc/plugin versions"));
82279 + return 1;
82280 + }
82281 +
82282 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82283 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82284 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82285 + return 0;
82286 +}
82287 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82288 new file mode 100644
82289 index 0000000..92ed719
82290 --- /dev/null
82291 +++ b/tools/gcc/constify_plugin.c
82292 @@ -0,0 +1,331 @@
82293 +/*
82294 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82295 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82296 + * Licensed under the GPL v2, or (at your option) v3
82297 + *
82298 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82299 + *
82300 + * Homepage:
82301 + * http://www.grsecurity.net/~ephox/const_plugin/
82302 + *
82303 + * Usage:
82304 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82305 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82306 + */
82307 +
82308 +#include "gcc-plugin.h"
82309 +#include "config.h"
82310 +#include "system.h"
82311 +#include "coretypes.h"
82312 +#include "tree.h"
82313 +#include "tree-pass.h"
82314 +#include "flags.h"
82315 +#include "intl.h"
82316 +#include "toplev.h"
82317 +#include "plugin.h"
82318 +#include "diagnostic.h"
82319 +#include "plugin-version.h"
82320 +#include "tm.h"
82321 +#include "function.h"
82322 +#include "basic-block.h"
82323 +#include "gimple.h"
82324 +#include "rtl.h"
82325 +#include "emit-rtl.h"
82326 +#include "tree-flow.h"
82327 +
82328 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82329 +
82330 +int plugin_is_GPL_compatible;
82331 +
82332 +static struct plugin_info const_plugin_info = {
82333 + .version = "201205300030",
82334 + .help = "no-constify\tturn off constification\n",
82335 +};
82336 +
82337 +static void deconstify_tree(tree node);
82338 +
82339 +static void deconstify_type(tree type)
82340 +{
82341 + tree field;
82342 +
82343 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82344 + tree type = TREE_TYPE(field);
82345 +
82346 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82347 + continue;
82348 + if (!TYPE_READONLY(type))
82349 + continue;
82350 +
82351 + deconstify_tree(field);
82352 + }
82353 + TYPE_READONLY(type) = 0;
82354 + C_TYPE_FIELDS_READONLY(type) = 0;
82355 +}
82356 +
82357 +static void deconstify_tree(tree node)
82358 +{
82359 + tree old_type, new_type, field;
82360 +
82361 + old_type = TREE_TYPE(node);
82362 +
82363 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82364 +
82365 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82366 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82367 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82368 + DECL_FIELD_CONTEXT(field) = new_type;
82369 +
82370 + deconstify_type(new_type);
82371 +
82372 + TREE_READONLY(node) = 0;
82373 + TREE_TYPE(node) = new_type;
82374 +}
82375 +
82376 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82377 +{
82378 + tree type;
82379 +
82380 + *no_add_attrs = true;
82381 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82382 + error("%qE attribute does not apply to functions", name);
82383 + return NULL_TREE;
82384 + }
82385 +
82386 + if (TREE_CODE(*node) == VAR_DECL) {
82387 + error("%qE attribute does not apply to variables", name);
82388 + return NULL_TREE;
82389 + }
82390 +
82391 + if (TYPE_P(*node)) {
82392 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82393 + *no_add_attrs = false;
82394 + else
82395 + error("%qE attribute applies to struct and union types only", name);
82396 + return NULL_TREE;
82397 + }
82398 +
82399 + type = TREE_TYPE(*node);
82400 +
82401 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82402 + error("%qE attribute applies to struct and union types only", name);
82403 + return NULL_TREE;
82404 + }
82405 +
82406 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82407 + error("%qE attribute is already applied to the type", name);
82408 + return NULL_TREE;
82409 + }
82410 +
82411 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82412 + error("%qE attribute used on type that is not constified", name);
82413 + return NULL_TREE;
82414 + }
82415 +
82416 + if (TREE_CODE(*node) == TYPE_DECL) {
82417 + deconstify_tree(*node);
82418 + return NULL_TREE;
82419 + }
82420 +
82421 + return NULL_TREE;
82422 +}
82423 +
82424 +static void constify_type(tree type)
82425 +{
82426 + TYPE_READONLY(type) = 1;
82427 + C_TYPE_FIELDS_READONLY(type) = 1;
82428 +}
82429 +
82430 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82431 +{
82432 + *no_add_attrs = true;
82433 + if (!TYPE_P(*node)) {
82434 + error("%qE attribute applies to types only", name);
82435 + return NULL_TREE;
82436 + }
82437 +
82438 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82439 + error("%qE attribute applies to struct and union types only", name);
82440 + return NULL_TREE;
82441 + }
82442 +
82443 + *no_add_attrs = false;
82444 + constify_type(*node);
82445 + return NULL_TREE;
82446 +}
82447 +
82448 +static struct attribute_spec no_const_attr = {
82449 + .name = "no_const",
82450 + .min_length = 0,
82451 + .max_length = 0,
82452 + .decl_required = false,
82453 + .type_required = false,
82454 + .function_type_required = false,
82455 + .handler = handle_no_const_attribute,
82456 +#if BUILDING_GCC_VERSION >= 4007
82457 + .affects_type_identity = true
82458 +#endif
82459 +};
82460 +
82461 +static struct attribute_spec do_const_attr = {
82462 + .name = "do_const",
82463 + .min_length = 0,
82464 + .max_length = 0,
82465 + .decl_required = false,
82466 + .type_required = false,
82467 + .function_type_required = false,
82468 + .handler = handle_do_const_attribute,
82469 +#if BUILDING_GCC_VERSION >= 4007
82470 + .affects_type_identity = true
82471 +#endif
82472 +};
82473 +
82474 +static void register_attributes(void *event_data, void *data)
82475 +{
82476 + register_attribute(&no_const_attr);
82477 + register_attribute(&do_const_attr);
82478 +}
82479 +
82480 +static bool is_fptr(tree field)
82481 +{
82482 + tree ptr = TREE_TYPE(field);
82483 +
82484 + if (TREE_CODE(ptr) != POINTER_TYPE)
82485 + return false;
82486 +
82487 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82488 +}
82489 +
82490 +static bool walk_struct(tree node)
82491 +{
82492 + tree field;
82493 +
82494 + if (TYPE_FIELDS(node) == NULL_TREE)
82495 + return false;
82496 +
82497 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82498 + gcc_assert(!TYPE_READONLY(node));
82499 + deconstify_type(node);
82500 + return false;
82501 + }
82502 +
82503 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82504 + tree type = TREE_TYPE(field);
82505 + enum tree_code code = TREE_CODE(type);
82506 +
82507 + if (node == type)
82508 + return false;
82509 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82510 + if (!(walk_struct(type)))
82511 + return false;
82512 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82513 + return false;
82514 + }
82515 + return true;
82516 +}
82517 +
82518 +static void finish_type(void *event_data, void *data)
82519 +{
82520 + tree type = (tree)event_data;
82521 +
82522 + if (type == NULL_TREE || type == error_mark_node)
82523 + return;
82524 +
82525 + if (TYPE_READONLY(type))
82526 + return;
82527 +
82528 + if (walk_struct(type))
82529 + constify_type(type);
82530 +}
82531 +
82532 +static unsigned int check_local_variables(void);
82533 +
82534 +struct gimple_opt_pass pass_local_variable = {
82535 + {
82536 + .type = GIMPLE_PASS,
82537 + .name = "check_local_variables",
82538 + .gate = NULL,
82539 + .execute = check_local_variables,
82540 + .sub = NULL,
82541 + .next = NULL,
82542 + .static_pass_number = 0,
82543 + .tv_id = TV_NONE,
82544 + .properties_required = 0,
82545 + .properties_provided = 0,
82546 + .properties_destroyed = 0,
82547 + .todo_flags_start = 0,
82548 + .todo_flags_finish = 0
82549 + }
82550 +};
82551 +
82552 +static unsigned int check_local_variables(void)
82553 +{
82554 + tree var;
82555 + referenced_var_iterator rvi;
82556 +
82557 +#if BUILDING_GCC_VERSION == 4005
82558 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82559 +#else
82560 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82561 +#endif
82562 + tree type = TREE_TYPE(var);
82563 +
82564 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82565 + continue;
82566 +
82567 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82568 + continue;
82569 +
82570 + if (!TYPE_READONLY(type))
82571 + continue;
82572 +
82573 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82574 +// continue;
82575 +
82576 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82577 +// continue;
82578 +
82579 + if (walk_struct(type)) {
82580 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82581 + return 1;
82582 + }
82583 + }
82584 + return 0;
82585 +}
82586 +
82587 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82588 +{
82589 + const char * const plugin_name = plugin_info->base_name;
82590 + const int argc = plugin_info->argc;
82591 + const struct plugin_argument * const argv = plugin_info->argv;
82592 + int i;
82593 + bool constify = true;
82594 +
82595 + struct register_pass_info local_variable_pass_info = {
82596 + .pass = &pass_local_variable.pass,
82597 + .reference_pass_name = "*referenced_vars",
82598 + .ref_pass_instance_number = 1,
82599 + .pos_op = PASS_POS_INSERT_AFTER
82600 + };
82601 +
82602 + if (!plugin_default_version_check(version, &gcc_version)) {
82603 + error(G_("incompatible gcc/plugin versions"));
82604 + return 1;
82605 + }
82606 +
82607 + for (i = 0; i < argc; ++i) {
82608 + if (!(strcmp(argv[i].key, "no-constify"))) {
82609 + constify = false;
82610 + continue;
82611 + }
82612 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82613 + }
82614 +
82615 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82616 + if (constify) {
82617 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82618 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82619 + }
82620 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82621 +
82622 + return 0;
82623 +}
82624 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82625 new file mode 100644
82626 index 0000000..02c6bec
82627 --- /dev/null
82628 +++ b/tools/gcc/generate_size_overflow_hash.sh
82629 @@ -0,0 +1,94 @@
82630 +#!/bin/bash
82631 +
82632 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82633 +
82634 +header1="size_overflow_hash.h"
82635 +database="size_overflow_hash.data"
82636 +n=65536
82637 +
82638 +usage() {
82639 +cat <<EOF
82640 +usage: $0 options
82641 +OPTIONS:
82642 + -h|--help help
82643 + -o header file
82644 + -d database file
82645 + -n hash array size
82646 +EOF
82647 + return 0
82648 +}
82649 +
82650 +while true
82651 +do
82652 + case "$1" in
82653 + -h|--help) usage && exit 0;;
82654 + -n) n=$2; shift 2;;
82655 + -o) header1="$2"; shift 2;;
82656 + -d) database="$2"; shift 2;;
82657 + --) shift 1; break ;;
82658 + *) break ;;
82659 + esac
82660 +done
82661 +
82662 +create_defines() {
82663 + for i in `seq 1 32`
82664 + do
82665 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82666 + done
82667 + echo >> "$header1"
82668 +}
82669 +
82670 +create_structs () {
82671 + rm -f "$header1"
82672 +
82673 + create_defines
82674 +
82675 + cat "$database" | while read data
82676 + do
82677 + data_array=($data)
82678 + struct_hash_name="${data_array[0]}"
82679 + funcn="${data_array[1]}"
82680 + params="${data_array[2]}"
82681 + next="${data_array[5]}"
82682 +
82683 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82684 +
82685 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82686 + echo -en "\t.param\t= " >> "$header1"
82687 + line=
82688 + for param_num in ${params//-/ };
82689 + do
82690 + line="${line}PARAM"$param_num"|"
82691 + done
82692 +
82693 + echo -e "${line%?},\n};\n" >> "$header1"
82694 + done
82695 +}
82696 +
82697 +create_headers () {
82698 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82699 +}
82700 +
82701 +create_array_elements () {
82702 + index=0
82703 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82704 + do
82705 + data_array=($data)
82706 + i="${data_array[3]}"
82707 + hash="${data_array[4]}"
82708 + while [[ $index -lt $i ]]
82709 + do
82710 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82711 + index=$(($index + 1))
82712 + done
82713 + index=$(($index + 1))
82714 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82715 + done
82716 + echo '};' >> $header1
82717 +}
82718 +
82719 +create_structs
82720 +create_headers
82721 +create_array_elements
82722 +
82723 +exit 0
82724 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82725 new file mode 100644
82726 index 0000000..a86e422
82727 --- /dev/null
82728 +++ b/tools/gcc/kallocstat_plugin.c
82729 @@ -0,0 +1,167 @@
82730 +/*
82731 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82732 + * Licensed under the GPL v2
82733 + *
82734 + * Note: the choice of the license means that the compilation process is
82735 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82736 + * but for the kernel it doesn't matter since it doesn't link against
82737 + * any of the gcc libraries
82738 + *
82739 + * gcc plugin to find the distribution of k*alloc sizes
82740 + *
82741 + * TODO:
82742 + *
82743 + * BUGS:
82744 + * - none known
82745 + */
82746 +#include "gcc-plugin.h"
82747 +#include "config.h"
82748 +#include "system.h"
82749 +#include "coretypes.h"
82750 +#include "tree.h"
82751 +#include "tree-pass.h"
82752 +#include "flags.h"
82753 +#include "intl.h"
82754 +#include "toplev.h"
82755 +#include "plugin.h"
82756 +//#include "expr.h" where are you...
82757 +#include "diagnostic.h"
82758 +#include "plugin-version.h"
82759 +#include "tm.h"
82760 +#include "function.h"
82761 +#include "basic-block.h"
82762 +#include "gimple.h"
82763 +#include "rtl.h"
82764 +#include "emit-rtl.h"
82765 +
82766 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82767 +
82768 +int plugin_is_GPL_compatible;
82769 +
82770 +static const char * const kalloc_functions[] = {
82771 + "__kmalloc",
82772 + "kmalloc",
82773 + "kmalloc_large",
82774 + "kmalloc_node",
82775 + "kmalloc_order",
82776 + "kmalloc_order_trace",
82777 + "kmalloc_slab",
82778 + "kzalloc",
82779 + "kzalloc_node",
82780 +};
82781 +
82782 +static struct plugin_info kallocstat_plugin_info = {
82783 + .version = "201111150100",
82784 +};
82785 +
82786 +static unsigned int execute_kallocstat(void);
82787 +
82788 +static struct gimple_opt_pass kallocstat_pass = {
82789 + .pass = {
82790 + .type = GIMPLE_PASS,
82791 + .name = "kallocstat",
82792 + .gate = NULL,
82793 + .execute = execute_kallocstat,
82794 + .sub = NULL,
82795 + .next = NULL,
82796 + .static_pass_number = 0,
82797 + .tv_id = TV_NONE,
82798 + .properties_required = 0,
82799 + .properties_provided = 0,
82800 + .properties_destroyed = 0,
82801 + .todo_flags_start = 0,
82802 + .todo_flags_finish = 0
82803 + }
82804 +};
82805 +
82806 +static bool is_kalloc(const char *fnname)
82807 +{
82808 + size_t i;
82809 +
82810 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82811 + if (!strcmp(fnname, kalloc_functions[i]))
82812 + return true;
82813 + return false;
82814 +}
82815 +
82816 +static unsigned int execute_kallocstat(void)
82817 +{
82818 + basic_block bb;
82819 +
82820 + // 1. loop through BBs and GIMPLE statements
82821 + FOR_EACH_BB(bb) {
82822 + gimple_stmt_iterator gsi;
82823 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82824 + // gimple match:
82825 + tree fndecl, size;
82826 + gimple call_stmt;
82827 + const char *fnname;
82828 +
82829 + // is it a call
82830 + call_stmt = gsi_stmt(gsi);
82831 + if (!is_gimple_call(call_stmt))
82832 + continue;
82833 + fndecl = gimple_call_fndecl(call_stmt);
82834 + if (fndecl == NULL_TREE)
82835 + continue;
82836 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82837 + continue;
82838 +
82839 + // is it a call to k*alloc
82840 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82841 + if (!is_kalloc(fnname))
82842 + continue;
82843 +
82844 + // is the size arg the result of a simple const assignment
82845 + size = gimple_call_arg(call_stmt, 0);
82846 + while (true) {
82847 + gimple def_stmt;
82848 + expanded_location xloc;
82849 + size_t size_val;
82850 +
82851 + if (TREE_CODE(size) != SSA_NAME)
82852 + break;
82853 + def_stmt = SSA_NAME_DEF_STMT(size);
82854 + if (!def_stmt || !is_gimple_assign(def_stmt))
82855 + break;
82856 + if (gimple_num_ops(def_stmt) != 2)
82857 + break;
82858 + size = gimple_assign_rhs1(def_stmt);
82859 + if (!TREE_CONSTANT(size))
82860 + continue;
82861 + xloc = expand_location(gimple_location(def_stmt));
82862 + if (!xloc.file)
82863 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82864 + size_val = TREE_INT_CST_LOW(size);
82865 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82866 + break;
82867 + }
82868 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82869 +//debug_tree(gimple_call_fn(call_stmt));
82870 +//print_node(stderr, "pax", fndecl, 4);
82871 + }
82872 + }
82873 +
82874 + return 0;
82875 +}
82876 +
82877 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82878 +{
82879 + const char * const plugin_name = plugin_info->base_name;
82880 + struct register_pass_info kallocstat_pass_info = {
82881 + .pass = &kallocstat_pass.pass,
82882 + .reference_pass_name = "ssa",
82883 + .ref_pass_instance_number = 1,
82884 + .pos_op = PASS_POS_INSERT_AFTER
82885 + };
82886 +
82887 + if (!plugin_default_version_check(version, &gcc_version)) {
82888 + error(G_("incompatible gcc/plugin versions"));
82889 + return 1;
82890 + }
82891 +
82892 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82893 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82894 +
82895 + return 0;
82896 +}
82897 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82898 new file mode 100644
82899 index 0000000..98011fa
82900 --- /dev/null
82901 +++ b/tools/gcc/kernexec_plugin.c
82902 @@ -0,0 +1,427 @@
82903 +/*
82904 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82905 + * Licensed under the GPL v2
82906 + *
82907 + * Note: the choice of the license means that the compilation process is
82908 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82909 + * but for the kernel it doesn't matter since it doesn't link against
82910 + * any of the gcc libraries
82911 + *
82912 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82913 + *
82914 + * TODO:
82915 + *
82916 + * BUGS:
82917 + * - none known
82918 + */
82919 +#include "gcc-plugin.h"
82920 +#include "config.h"
82921 +#include "system.h"
82922 +#include "coretypes.h"
82923 +#include "tree.h"
82924 +#include "tree-pass.h"
82925 +#include "flags.h"
82926 +#include "intl.h"
82927 +#include "toplev.h"
82928 +#include "plugin.h"
82929 +//#include "expr.h" where are you...
82930 +#include "diagnostic.h"
82931 +#include "plugin-version.h"
82932 +#include "tm.h"
82933 +#include "function.h"
82934 +#include "basic-block.h"
82935 +#include "gimple.h"
82936 +#include "rtl.h"
82937 +#include "emit-rtl.h"
82938 +#include "tree-flow.h"
82939 +
82940 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82941 +extern rtx emit_move_insn(rtx x, rtx y);
82942 +
82943 +int plugin_is_GPL_compatible;
82944 +
82945 +static struct plugin_info kernexec_plugin_info = {
82946 + .version = "201111291120",
82947 + .help = "method=[bts|or]\tinstrumentation method\n"
82948 +};
82949 +
82950 +static unsigned int execute_kernexec_reload(void);
82951 +static unsigned int execute_kernexec_fptr(void);
82952 +static unsigned int execute_kernexec_retaddr(void);
82953 +static bool kernexec_cmodel_check(void);
82954 +
82955 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82956 +static void (*kernexec_instrument_retaddr)(rtx);
82957 +
82958 +static struct gimple_opt_pass kernexec_reload_pass = {
82959 + .pass = {
82960 + .type = GIMPLE_PASS,
82961 + .name = "kernexec_reload",
82962 + .gate = kernexec_cmodel_check,
82963 + .execute = execute_kernexec_reload,
82964 + .sub = NULL,
82965 + .next = NULL,
82966 + .static_pass_number = 0,
82967 + .tv_id = TV_NONE,
82968 + .properties_required = 0,
82969 + .properties_provided = 0,
82970 + .properties_destroyed = 0,
82971 + .todo_flags_start = 0,
82972 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82973 + }
82974 +};
82975 +
82976 +static struct gimple_opt_pass kernexec_fptr_pass = {
82977 + .pass = {
82978 + .type = GIMPLE_PASS,
82979 + .name = "kernexec_fptr",
82980 + .gate = kernexec_cmodel_check,
82981 + .execute = execute_kernexec_fptr,
82982 + .sub = NULL,
82983 + .next = NULL,
82984 + .static_pass_number = 0,
82985 + .tv_id = TV_NONE,
82986 + .properties_required = 0,
82987 + .properties_provided = 0,
82988 + .properties_destroyed = 0,
82989 + .todo_flags_start = 0,
82990 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82991 + }
82992 +};
82993 +
82994 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82995 + .pass = {
82996 + .type = RTL_PASS,
82997 + .name = "kernexec_retaddr",
82998 + .gate = kernexec_cmodel_check,
82999 + .execute = execute_kernexec_retaddr,
83000 + .sub = NULL,
83001 + .next = NULL,
83002 + .static_pass_number = 0,
83003 + .tv_id = TV_NONE,
83004 + .properties_required = 0,
83005 + .properties_provided = 0,
83006 + .properties_destroyed = 0,
83007 + .todo_flags_start = 0,
83008 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83009 + }
83010 +};
83011 +
83012 +static bool kernexec_cmodel_check(void)
83013 +{
83014 + tree section;
83015 +
83016 + if (ix86_cmodel != CM_KERNEL)
83017 + return false;
83018 +
83019 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83020 + if (!section || !TREE_VALUE(section))
83021 + return true;
83022 +
83023 + section = TREE_VALUE(TREE_VALUE(section));
83024 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83025 + return true;
83026 +
83027 + return false;
83028 +}
83029 +
83030 +/*
83031 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83032 + */
83033 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83034 +{
83035 + gimple asm_movabs_stmt;
83036 +
83037 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83038 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83039 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83040 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83041 + update_stmt(asm_movabs_stmt);
83042 +}
83043 +
83044 +/*
83045 + * find all asm() stmts that clobber r10 and add a reload of r10
83046 + */
83047 +static unsigned int execute_kernexec_reload(void)
83048 +{
83049 + basic_block bb;
83050 +
83051 + // 1. loop through BBs and GIMPLE statements
83052 + FOR_EACH_BB(bb) {
83053 + gimple_stmt_iterator gsi;
83054 +
83055 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83056 + // gimple match: __asm__ ("" : : : "r10");
83057 + gimple asm_stmt;
83058 + size_t nclobbers;
83059 +
83060 + // is it an asm ...
83061 + asm_stmt = gsi_stmt(gsi);
83062 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83063 + continue;
83064 +
83065 + // ... clobbering r10
83066 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83067 + while (nclobbers--) {
83068 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83069 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83070 + continue;
83071 + kernexec_reload_fptr_mask(&gsi);
83072 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83073 + break;
83074 + }
83075 + }
83076 + }
83077 +
83078 + return 0;
83079 +}
83080 +
83081 +/*
83082 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83083 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83084 + */
83085 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83086 +{
83087 + gimple assign_intptr, assign_new_fptr, call_stmt;
83088 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83089 +
83090 + call_stmt = gsi_stmt(*gsi);
83091 + old_fptr = gimple_call_fn(call_stmt);
83092 +
83093 + // create temporary unsigned long variable used for bitops and cast fptr to it
83094 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83095 + add_referenced_var(intptr);
83096 + mark_sym_for_renaming(intptr);
83097 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83098 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83099 + update_stmt(assign_intptr);
83100 +
83101 + // apply logical or to temporary unsigned long and bitmask
83102 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83103 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83104 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83105 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83106 + update_stmt(assign_intptr);
83107 +
83108 + // cast temporary unsigned long back to a temporary fptr variable
83109 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83110 + add_referenced_var(new_fptr);
83111 + mark_sym_for_renaming(new_fptr);
83112 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83113 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83114 + update_stmt(assign_new_fptr);
83115 +
83116 + // replace call stmt fn with the new fptr
83117 + gimple_call_set_fn(call_stmt, new_fptr);
83118 + update_stmt(call_stmt);
83119 +}
83120 +
83121 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83122 +{
83123 + gimple asm_or_stmt, call_stmt;
83124 + tree old_fptr, new_fptr, input, output;
83125 + VEC(tree, gc) *inputs = NULL;
83126 + VEC(tree, gc) *outputs = NULL;
83127 +
83128 + call_stmt = gsi_stmt(*gsi);
83129 + old_fptr = gimple_call_fn(call_stmt);
83130 +
83131 + // create temporary fptr variable
83132 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83133 + add_referenced_var(new_fptr);
83134 + mark_sym_for_renaming(new_fptr);
83135 +
83136 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83137 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83138 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83139 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83140 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83141 + VEC_safe_push(tree, gc, inputs, input);
83142 + VEC_safe_push(tree, gc, outputs, output);
83143 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83144 + gimple_asm_set_volatile(asm_or_stmt, true);
83145 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83146 + update_stmt(asm_or_stmt);
83147 +
83148 + // replace call stmt fn with the new fptr
83149 + gimple_call_set_fn(call_stmt, new_fptr);
83150 + update_stmt(call_stmt);
83151 +}
83152 +
83153 +/*
83154 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83155 + */
83156 +static unsigned int execute_kernexec_fptr(void)
83157 +{
83158 + basic_block bb;
83159 +
83160 + // 1. loop through BBs and GIMPLE statements
83161 + FOR_EACH_BB(bb) {
83162 + gimple_stmt_iterator gsi;
83163 +
83164 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83165 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83166 + tree fn;
83167 + gimple call_stmt;
83168 +
83169 + // is it a call ...
83170 + call_stmt = gsi_stmt(gsi);
83171 + if (!is_gimple_call(call_stmt))
83172 + continue;
83173 + fn = gimple_call_fn(call_stmt);
83174 + if (TREE_CODE(fn) == ADDR_EXPR)
83175 + continue;
83176 + if (TREE_CODE(fn) != SSA_NAME)
83177 + gcc_unreachable();
83178 +
83179 + // ... through a function pointer
83180 + fn = SSA_NAME_VAR(fn);
83181 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83182 + continue;
83183 + fn = TREE_TYPE(fn);
83184 + if (TREE_CODE(fn) != POINTER_TYPE)
83185 + continue;
83186 + fn = TREE_TYPE(fn);
83187 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83188 + continue;
83189 +
83190 + kernexec_instrument_fptr(&gsi);
83191 +
83192 +//debug_tree(gimple_call_fn(call_stmt));
83193 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83194 + }
83195 + }
83196 +
83197 + return 0;
83198 +}
83199 +
83200 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83201 +static void kernexec_instrument_retaddr_bts(rtx insn)
83202 +{
83203 + rtx btsq;
83204 + rtvec argvec, constraintvec, labelvec;
83205 + int line;
83206 +
83207 + // create asm volatile("btsq $63,(%%rsp)":::)
83208 + argvec = rtvec_alloc(0);
83209 + constraintvec = rtvec_alloc(0);
83210 + labelvec = rtvec_alloc(0);
83211 + line = expand_location(RTL_LOCATION(insn)).line;
83212 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83213 + MEM_VOLATILE_P(btsq) = 1;
83214 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83215 + emit_insn_before(btsq, insn);
83216 +}
83217 +
83218 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83219 +static void kernexec_instrument_retaddr_or(rtx insn)
83220 +{
83221 + rtx orq;
83222 + rtvec argvec, constraintvec, labelvec;
83223 + int line;
83224 +
83225 + // create asm volatile("orq %%r10,(%%rsp)":::)
83226 + argvec = rtvec_alloc(0);
83227 + constraintvec = rtvec_alloc(0);
83228 + labelvec = rtvec_alloc(0);
83229 + line = expand_location(RTL_LOCATION(insn)).line;
83230 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83231 + MEM_VOLATILE_P(orq) = 1;
83232 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83233 + emit_insn_before(orq, insn);
83234 +}
83235 +
83236 +/*
83237 + * find all asm level function returns and forcibly set the highest bit of the return address
83238 + */
83239 +static unsigned int execute_kernexec_retaddr(void)
83240 +{
83241 + rtx insn;
83242 +
83243 + // 1. find function returns
83244 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83245 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83246 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83247 + rtx body;
83248 +
83249 + // is it a retn
83250 + if (!JUMP_P(insn))
83251 + continue;
83252 + body = PATTERN(insn);
83253 + if (GET_CODE(body) == PARALLEL)
83254 + body = XVECEXP(body, 0, 0);
83255 + if (GET_CODE(body) != RETURN)
83256 + continue;
83257 + kernexec_instrument_retaddr(insn);
83258 + }
83259 +
83260 +// print_simple_rtl(stderr, get_insns());
83261 +// print_rtl(stderr, get_insns());
83262 +
83263 + return 0;
83264 +}
83265 +
83266 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83267 +{
83268 + const char * const plugin_name = plugin_info->base_name;
83269 + const int argc = plugin_info->argc;
83270 + const struct plugin_argument * const argv = plugin_info->argv;
83271 + int i;
83272 + struct register_pass_info kernexec_reload_pass_info = {
83273 + .pass = &kernexec_reload_pass.pass,
83274 + .reference_pass_name = "ssa",
83275 + .ref_pass_instance_number = 1,
83276 + .pos_op = PASS_POS_INSERT_AFTER
83277 + };
83278 + struct register_pass_info kernexec_fptr_pass_info = {
83279 + .pass = &kernexec_fptr_pass.pass,
83280 + .reference_pass_name = "ssa",
83281 + .ref_pass_instance_number = 1,
83282 + .pos_op = PASS_POS_INSERT_AFTER
83283 + };
83284 + struct register_pass_info kernexec_retaddr_pass_info = {
83285 + .pass = &kernexec_retaddr_pass.pass,
83286 + .reference_pass_name = "pro_and_epilogue",
83287 + .ref_pass_instance_number = 1,
83288 + .pos_op = PASS_POS_INSERT_AFTER
83289 + };
83290 +
83291 + if (!plugin_default_version_check(version, &gcc_version)) {
83292 + error(G_("incompatible gcc/plugin versions"));
83293 + return 1;
83294 + }
83295 +
83296 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83297 +
83298 + if (TARGET_64BIT == 0)
83299 + return 0;
83300 +
83301 + for (i = 0; i < argc; ++i) {
83302 + if (!strcmp(argv[i].key, "method")) {
83303 + if (!argv[i].value) {
83304 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83305 + continue;
83306 + }
83307 + if (!strcmp(argv[i].value, "bts")) {
83308 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83309 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83310 + } else if (!strcmp(argv[i].value, "or")) {
83311 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83312 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83313 + fix_register("r10", 1, 1);
83314 + } else
83315 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83316 + continue;
83317 + }
83318 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83319 + }
83320 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83321 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83322 +
83323 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83324 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83325 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83326 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83327 +
83328 + return 0;
83329 +}
83330 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83331 new file mode 100644
83332 index 0000000..b8008f7
83333 --- /dev/null
83334 +++ b/tools/gcc/latent_entropy_plugin.c
83335 @@ -0,0 +1,295 @@
83336 +/*
83337 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83338 + * Licensed under the GPL v2
83339 + *
83340 + * Note: the choice of the license means that the compilation process is
83341 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83342 + * but for the kernel it doesn't matter since it doesn't link against
83343 + * any of the gcc libraries
83344 + *
83345 + * gcc plugin to help generate a little bit of entropy from program state,
83346 + * used during boot in the kernel
83347 + *
83348 + * TODO:
83349 + * - add ipa pass to identify not explicitly marked candidate functions
83350 + * - mix in more program state (function arguments/return values, loop variables, etc)
83351 + * - more instrumentation control via attribute parameters
83352 + *
83353 + * BUGS:
83354 + * - LTO needs -flto-partition=none for now
83355 + */
83356 +#include "gcc-plugin.h"
83357 +#include "config.h"
83358 +#include "system.h"
83359 +#include "coretypes.h"
83360 +#include "tree.h"
83361 +#include "tree-pass.h"
83362 +#include "flags.h"
83363 +#include "intl.h"
83364 +#include "toplev.h"
83365 +#include "plugin.h"
83366 +//#include "expr.h" where are you...
83367 +#include "diagnostic.h"
83368 +#include "plugin-version.h"
83369 +#include "tm.h"
83370 +#include "function.h"
83371 +#include "basic-block.h"
83372 +#include "gimple.h"
83373 +#include "rtl.h"
83374 +#include "emit-rtl.h"
83375 +#include "tree-flow.h"
83376 +
83377 +int plugin_is_GPL_compatible;
83378 +
83379 +static tree latent_entropy_decl;
83380 +
83381 +static struct plugin_info latent_entropy_plugin_info = {
83382 + .version = "201207271820",
83383 + .help = NULL
83384 +};
83385 +
83386 +static unsigned int execute_latent_entropy(void);
83387 +static bool gate_latent_entropy(void);
83388 +
83389 +static struct gimple_opt_pass latent_entropy_pass = {
83390 + .pass = {
83391 + .type = GIMPLE_PASS,
83392 + .name = "latent_entropy",
83393 + .gate = gate_latent_entropy,
83394 + .execute = execute_latent_entropy,
83395 + .sub = NULL,
83396 + .next = NULL,
83397 + .static_pass_number = 0,
83398 + .tv_id = TV_NONE,
83399 + .properties_required = PROP_gimple_leh | PROP_cfg,
83400 + .properties_provided = 0,
83401 + .properties_destroyed = 0,
83402 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83403 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83404 + }
83405 +};
83406 +
83407 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83408 +{
83409 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83410 + *no_add_attrs = true;
83411 + error("%qE attribute only applies to functions", name);
83412 + }
83413 + return NULL_TREE;
83414 +}
83415 +
83416 +static struct attribute_spec latent_entropy_attr = {
83417 + .name = "latent_entropy",
83418 + .min_length = 0,
83419 + .max_length = 0,
83420 + .decl_required = true,
83421 + .type_required = false,
83422 + .function_type_required = false,
83423 + .handler = handle_latent_entropy_attribute,
83424 +#if BUILDING_GCC_VERSION >= 4007
83425 + .affects_type_identity = false
83426 +#endif
83427 +};
83428 +
83429 +static void register_attributes(void *event_data, void *data)
83430 +{
83431 + register_attribute(&latent_entropy_attr);
83432 +}
83433 +
83434 +static bool gate_latent_entropy(void)
83435 +{
83436 + tree latent_entropy_attr;
83437 +
83438 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83439 + return latent_entropy_attr != NULL_TREE;
83440 +}
83441 +
83442 +static unsigned HOST_WIDE_INT seed;
83443 +static unsigned HOST_WIDE_INT get_random_const(void)
83444 +{
83445 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83446 + return seed;
83447 +}
83448 +
83449 +static enum tree_code get_op(tree *rhs)
83450 +{
83451 + static enum tree_code op;
83452 + unsigned HOST_WIDE_INT random_const;
83453 +
83454 + random_const = get_random_const();
83455 +
83456 + switch (op) {
83457 + case BIT_XOR_EXPR:
83458 + op = PLUS_EXPR;
83459 + break;
83460 +
83461 + case PLUS_EXPR:
83462 + if (rhs) {
83463 + op = LROTATE_EXPR;
83464 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83465 + break;
83466 + }
83467 +
83468 + case LROTATE_EXPR:
83469 + default:
83470 + op = BIT_XOR_EXPR;
83471 + break;
83472 + }
83473 + if (rhs)
83474 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83475 + return op;
83476 +}
83477 +
83478 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83479 +{
83480 + gimple_stmt_iterator gsi;
83481 + gimple assign;
83482 + tree addxorrol, rhs;
83483 + enum tree_code op;
83484 +
83485 + op = get_op(&rhs);
83486 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83487 + assign = gimple_build_assign(local_entropy, addxorrol);
83488 + find_referenced_vars_in(assign);
83489 +//debug_bb(bb);
83490 + gsi = gsi_after_labels(bb);
83491 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83492 + update_stmt(assign);
83493 +}
83494 +
83495 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83496 +{
83497 + gimple_stmt_iterator gsi;
83498 + gimple assign;
83499 + tree addxorrol, temp;
83500 +
83501 + // 1. create temporary copy of latent_entropy
83502 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83503 + add_referenced_var(temp);
83504 + mark_sym_for_renaming(temp);
83505 +
83506 + // 2. read...
83507 + assign = gimple_build_assign(temp, latent_entropy_decl);
83508 + find_referenced_vars_in(assign);
83509 + gsi = gsi_after_labels(bb);
83510 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83511 + update_stmt(assign);
83512 +
83513 + // 3. ...modify...
83514 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83515 + assign = gimple_build_assign(temp, addxorrol);
83516 + find_referenced_vars_in(assign);
83517 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83518 + update_stmt(assign);
83519 +
83520 + // 4. ...write latent_entropy
83521 + assign = gimple_build_assign(latent_entropy_decl, temp);
83522 + find_referenced_vars_in(assign);
83523 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83524 + update_stmt(assign);
83525 +}
83526 +
83527 +static unsigned int execute_latent_entropy(void)
83528 +{
83529 + basic_block bb;
83530 + gimple assign;
83531 + gimple_stmt_iterator gsi;
83532 + tree local_entropy;
83533 +
83534 + if (!latent_entropy_decl) {
83535 + struct varpool_node *node;
83536 +
83537 + for (node = varpool_nodes; node; node = node->next) {
83538 + tree var = node->decl;
83539 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83540 + continue;
83541 + latent_entropy_decl = var;
83542 +// debug_tree(var);
83543 + break;
83544 + }
83545 + if (!latent_entropy_decl) {
83546 +// debug_tree(current_function_decl);
83547 + return 0;
83548 + }
83549 + }
83550 +
83551 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83552 +
83553 + // 1. create local entropy variable
83554 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83555 + add_referenced_var(local_entropy);
83556 + mark_sym_for_renaming(local_entropy);
83557 +
83558 + // 2. initialize local entropy variable
83559 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83560 + if (dom_info_available_p(CDI_DOMINATORS))
83561 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83562 + gsi = gsi_start_bb(bb);
83563 +
83564 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83565 +// gimple_set_location(assign, loc);
83566 + find_referenced_vars_in(assign);
83567 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83568 + update_stmt(assign);
83569 + bb = bb->next_bb;
83570 +
83571 + // 3. instrument each BB with an operation on the local entropy variable
83572 + while (bb != EXIT_BLOCK_PTR) {
83573 + perturb_local_entropy(bb, local_entropy);
83574 + bb = bb->next_bb;
83575 + };
83576 +
83577 + // 4. mix local entropy into the global entropy variable
83578 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83579 + return 0;
83580 +}
83581 +
83582 +static void start_unit_callback(void *gcc_data, void *user_data)
83583 +{
83584 +#if BUILDING_GCC_VERSION >= 4007
83585 + seed = get_random_seed(false);
83586 +#else
83587 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83588 + seed *= seed;
83589 +#endif
83590 +
83591 + if (in_lto_p)
83592 + return;
83593 +
83594 + // extern u64 latent_entropy
83595 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83596 +
83597 + TREE_STATIC(latent_entropy_decl) = 1;
83598 + TREE_PUBLIC(latent_entropy_decl) = 1;
83599 + TREE_USED(latent_entropy_decl) = 1;
83600 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83601 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83602 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83603 + DECL_INITIAL(latent_entropy_decl) = NULL;
83604 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83605 +// varpool_finalize_decl(latent_entropy_decl);
83606 +// varpool_mark_needed_node(latent_entropy_decl);
83607 +}
83608 +
83609 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83610 +{
83611 + const char * const plugin_name = plugin_info->base_name;
83612 + struct register_pass_info latent_entropy_pass_info = {
83613 + .pass = &latent_entropy_pass.pass,
83614 + .reference_pass_name = "optimized",
83615 + .ref_pass_instance_number = 1,
83616 + .pos_op = PASS_POS_INSERT_BEFORE
83617 + };
83618 +
83619 + if (!plugin_default_version_check(version, &gcc_version)) {
83620 + error(G_("incompatible gcc/plugin versions"));
83621 + return 1;
83622 + }
83623 +
83624 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83625 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83626 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83627 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83628 +
83629 + return 0;
83630 +}
83631 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83632 new file mode 100644
83633 index 0000000..9332f17
83634 --- /dev/null
83635 +++ b/tools/gcc/size_overflow_hash.data
83636 @@ -0,0 +1,3597 @@
83637 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83638 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83639 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83640 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83641 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83642 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83643 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83644 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83645 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
83646 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83647 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
83648 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
83649 +_000014_hash kmemdup 2 64015 _000014_hash NULL
83650 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
83651 +_000016_hash memdup_user 2 59590 _000016_hash NULL
83652 +_000017_hash module_alloc 1 63630 _000017_hash NULL
83653 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
83654 +_000019_hash read_kcore 3 63488 _000019_hash NULL
83655 +_000020_hash read_ldt 2 47570 _000020_hash NULL
83656 +_000021_hash read_zero 3 19366 _000021_hash NULL
83657 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
83658 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
83659 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
83660 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
83661 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
83662 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
83663 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
83664 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
83665 +_000031_hash adu_write 3 30487 _000031_hash NULL
83666 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
83667 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
83668 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
83669 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
83670 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
83671 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
83672 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
83673 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
83674 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
83675 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
83676 +_000044_hash alloc_context 1 3194 _000044_hash NULL
83677 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
83678 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
83679 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
83680 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
83681 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
83682 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
83683 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
83684 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
83685 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
83686 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
83687 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
83688 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
83689 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
83690 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
83691 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
83692 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
83693 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
83694 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
83695 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
83696 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
83697 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
83698 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
83699 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
83700 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
83701 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
83702 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
83703 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
83704 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
83705 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
83706 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
83707 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
83708 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
83709 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
83710 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
83711 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
83712 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
83713 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
83714 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
83715 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
83716 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
83717 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
83718 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
83719 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
83720 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
83721 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
83722 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
83723 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
83724 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
83725 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
83726 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
83727 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
83728 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
83729 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
83730 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
83731 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
83732 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
83733 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
83734 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
83735 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
83736 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
83737 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
83738 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
83739 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
83740 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
83741 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
83742 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
83743 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
83744 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
83745 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
83746 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
83747 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
83748 +_000122_hash change_xattr 5 61390 _000122_hash NULL
83749 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
83750 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
83751 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
83752 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
83753 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
83754 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
83755 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
83756 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
83757 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
83758 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
83759 +_000133_hash cmm_write 3 2896 _000133_hash NULL
83760 +_000134_hash cm_write 3 36858 _000134_hash NULL
83761 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
83762 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
83763 +_000137_hash command_file_write 3 31318 _000137_hash NULL
83764 +_000138_hash command_write 3 58841 _000138_hash NULL
83765 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
83766 +_000140_hash concat_writev 3 21451 _000140_hash NULL
83767 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
83768 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
83769 +_000143_hash copy_items 6 50140 _000143_hash NULL
83770 +_000144_hash copy_macs 4 45534 _000144_hash NULL
83771 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
83772 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
83773 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
83774 +_000148_hash cosa_write 3 1774 _000148_hash NULL
83775 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
83776 +_000150_hash create_entry 2 33479 _000150_hash NULL
83777 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
83778 +_000153_hash create_xattr 5 54106 _000153_hash NULL
83779 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
83780 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
83781 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
83782 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
83783 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
83784 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
83785 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
83786 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
83787 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
83788 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
83789 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
83790 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
83791 +_000168_hash dev_config 3 8506 _000168_hash NULL
83792 +_000169_hash device_write 3 45156 _000169_hash NULL
83793 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
83794 +_000171_hash devres_alloc 2 551 _000171_hash NULL
83795 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
83796 +_000173_hash direct_entry 3 38836 _000173_hash NULL
83797 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
83798 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
83799 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
83800 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
83801 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
83802 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
83803 +_000180_hash dm_read 3 15674 _000180_hash NULL
83804 +_000181_hash dm_write 3 2513 _000181_hash NULL
83805 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
83806 +_000183_hash dns_query 3 9676 _000183_hash NULL
83807 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
83808 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
83809 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
83810 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
83811 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
83812 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
83813 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
83814 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
83815 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
83816 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
83817 +_000194_hash dsp_write 2 46218 _000194_hash NULL
83818 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
83819 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
83820 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
83821 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
83822 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
83823 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
83824 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
83825 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
83826 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
83827 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
83828 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
83829 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
83830 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
83831 +_000208_hash ep_read 3 58813 _000208_hash NULL
83832 +_000209_hash ep_write 3 59008 _000209_hash NULL
83833 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
83834 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
83835 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
83836 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
83837 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
83838 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
83839 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
83840 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
83841 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
83842 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
83843 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
83844 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
83845 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
83846 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
83847 +_000225_hash fl_create 5 56435 _000225_hash NULL
83848 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
83849 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
83850 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
83851 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
83852 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
83853 +_000231_hash get_arg 3 5694 _000231_hash NULL
83854 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
83855 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
83856 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
83857 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
83858 +_000236_hash get_registers 3 26187 _000236_hash NULL
83859 +_000237_hash get_scq 2 10897 _000237_hash NULL
83860 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
83861 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
83862 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
83863 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
83864 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
83865 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
83866 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
83867 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
83868 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
83869 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
83870 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
83871 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
83872 +_000250_hash handle_request 9 10024 _000250_hash NULL
83873 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
83874 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
83875 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
83876 +_000254_hash heap_init 2 49617 _000254_hash NULL
83877 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
83878 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
83879 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
83880 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
83881 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
83882 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
83883 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
83884 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
83885 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
83886 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
83887 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
83888 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
83889 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
83890 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
83891 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
83892 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
83893 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
83894 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
83895 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
83896 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
83897 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
83898 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
83899 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
83900 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
83901 +_000279_hash if_write 3 51756 _000279_hash NULL
83902 +_000280_hash ilo_write 3 64378 _000280_hash NULL
83903 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
83904 +_000282_hash init_data_container 1 60709 _000282_hash NULL
83905 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
83906 +_000284_hash insert_dent 7 65034 _000284_hash NULL
83907 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
83908 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
83909 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
83910 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
83911 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
83912 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
83913 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
83914 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
83915 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
83916 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
83917 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
83918 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
83919 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
83920 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
83921 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
83922 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
83923 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
83924 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
83925 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
83926 +_000304_hash isdn_read 3 50021 _000304_hash NULL
83927 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
83928 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
83929 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
83930 +_000308_hash iso_callback 3 43208 _000308_hash NULL
83931 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
83932 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
83933 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
83934 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
83935 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
83936 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
83937 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
83938 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
83939 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
83940 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
83941 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
83942 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
83943 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
83944 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
83945 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
83946 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
83947 +_000328_hash kone_receive 4 4690 _000328_hash NULL
83948 +_000329_hash kone_send 4 63435 _000329_hash NULL
83949 +_000330_hash krealloc 2 14908 _000330_hash NULL
83950 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
83951 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
83952 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
83953 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
83954 +_000335_hash kzalloc 1 54740 _000335_hash NULL
83955 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
83956 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
83957 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
83958 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
83959 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
83960 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
83961 +_000342_hash __lgread 4 31668 _000342_hash NULL
83962 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
83963 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
83964 +_000345_hash listxattr 3 12769 _000345_hash NULL
83965 +_000346_hash load_msg 2 95 _000346_hash NULL
83966 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
83967 +_000348_hash lp_write 3 9511 _000348_hash NULL
83968 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
83969 +_000350_hash mce_write 3 26201 _000350_hash NULL
83970 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
83971 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
83972 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
83973 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
83974 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
83975 +_000357_hash mem_rw 3 22085 _000357_hash NULL
83976 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
83977 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
83978 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
83979 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
83980 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
83981 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
83982 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
83983 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
83984 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
83985 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
83986 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
83987 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
83988 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
83989 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
83990 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
83991 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
83992 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
83993 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
83994 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
83995 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
83996 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
83997 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
83998 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
83999 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84000 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84001 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84002 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84003 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84004 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84005 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84006 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84007 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84008 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84009 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84010 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84011 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84012 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84013 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84014 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84015 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84016 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84017 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84018 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84019 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84020 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84021 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84022 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84023 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84024 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84025 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84026 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84027 +_000415_hash parse_command 2 37079 _000415_hash NULL
84028 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84029 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84030 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84031 +_000419_hash pg_write 3 40766 _000419_hash NULL
84032 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84033 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84034 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84035 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84036 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84037 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84038 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84039 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84040 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84041 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84042 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84043 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84044 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84045 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84046 +_000434_hash pp_read 3 33210 _000434_hash NULL
84047 +_000435_hash pp_write 3 39554 _000435_hash NULL
84048 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84049 +_000437_hash printer_write 3 60276 _000437_hash NULL
84050 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84051 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84052 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84053 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84054 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84055 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84056 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84057 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84058 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84059 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84060 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84061 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84062 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84063 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84064 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84065 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84066 +_000456_hash pt_write 3 40159 _000456_hash NULL
84067 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84068 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84069 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84070 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84071 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84072 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84073 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84074 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84075 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84076 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84077 +_000467_hash read 3 9397 _000467_hash NULL
84078 +_000468_hash read_buf 2 20469 _000468_hash NULL
84079 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84080 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84081 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84082 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84083 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84084 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84085 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84086 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84087 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84088 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84089 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84090 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84091 +_000481_hash revalidate 2 19043 _000481_hash NULL
84092 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84093 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84094 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84095 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84096 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84097 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84098 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84099 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84100 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84101 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84102 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84103 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84104 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84105 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84106 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84107 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84108 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84109 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84110 +_000500_hash savemem 3 58129 _000500_hash NULL
84111 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84112 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84113 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84114 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84115 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84116 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84117 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84118 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84119 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84120 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84121 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84122 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84123 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84124 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84125 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84126 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84127 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84128 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84129 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84130 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84131 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84132 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84133 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84134 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84135 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84136 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84137 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84138 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84139 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84140 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84141 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84142 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84143 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84144 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84145 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84146 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84147 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84148 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84149 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84150 +_000542_hash set_registers 3 53582 _000542_hash NULL
84151 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84152 +_000544_hash setup_req 3 5848 _000544_hash NULL
84153 +_000545_hash setxattr 4 37006 _000545_hash NULL
84154 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84155 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84156 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84157 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84158 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84159 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84160 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84161 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84162 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84163 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84164 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84165 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84166 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84167 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84168 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84169 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84170 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84171 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84172 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84173 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84174 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84175 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84176 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84177 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84178 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84179 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84180 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84181 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84182 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84183 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84184 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84185 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84186 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84187 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84188 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84189 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84190 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84191 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84192 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84193 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84194 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84195 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84196 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84197 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84198 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84199 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84200 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84201 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84202 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84203 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84204 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84205 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84206 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84207 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84208 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84209 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84210 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84211 +_000606_hash tower_write 3 8580 _000606_hash NULL
84212 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84213 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84214 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84215 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84216 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84217 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84218 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84219 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84220 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84221 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84222 +_000617_hash uea_request 4 47613 _000617_hash NULL
84223 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84224 +_000619_hash uio_write 3 43202 _000619_hash NULL
84225 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84226 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84227 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84228 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84229 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84230 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84231 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84232 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84233 +_000629_hash user_update 3 41332 _000629_hash NULL
84234 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84235 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84236 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84237 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84238 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84239 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84240 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84241 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84242 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84243 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84244 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84245 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84246 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84247 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84248 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84249 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84250 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84251 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84252 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84253 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84254 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84255 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84256 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84257 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84258 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84259 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84260 +_000659_hash write 3 62671 _000659_hash NULL
84261 +_000660_hash write_flush 3 50803 _000660_hash NULL
84262 +_000661_hash write_rio 3 54837 _000661_hash NULL
84263 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84264 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84265 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84266 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84267 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84268 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84269 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84270 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84271 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84272 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84273 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84274 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84275 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84276 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84277 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84278 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84279 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84280 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84281 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84282 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84283 +_000684_hash addtgt 3 54703 _000684_hash NULL
84284 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84285 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84286 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84287 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84288 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84289 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84290 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84291 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84292 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84293 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84294 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84295 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84296 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84297 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84298 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84299 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84300 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84301 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84302 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84303 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84304 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84305 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84306 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84307 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84308 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84309 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84310 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84311 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84312 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84313 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84314 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84315 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84316 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84317 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84318 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84319 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84320 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84321 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84322 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84323 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84324 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84325 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84326 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84327 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84328 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84329 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84330 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84331 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84332 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84333 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84334 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84335 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84336 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84337 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84338 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84339 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84340 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84341 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84342 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84343 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84344 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84345 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84346 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84347 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84348 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84349 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84350 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84351 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84352 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84353 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84354 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84355 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84356 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84357 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84358 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84359 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84360 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84361 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84362 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84363 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84364 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84365 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84366 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84367 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84368 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84369 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84370 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84371 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84372 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84373 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84374 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84375 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84376 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84377 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84378 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84379 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84380 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84381 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84382 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84383 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84384 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84385 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84386 +_000799_hash construct_key 3 11329 _000799_hash NULL
84387 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84388 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84389 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84390 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84391 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84392 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84393 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84394 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84395 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84396 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84397 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84398 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84399 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84400 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84401 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84402 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84403 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84404 +_000819_hash depth_write 3 3021 _000819_hash NULL
84405 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84406 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84407 +_000822_hash dev_write 3 7708 _000822_hash NULL
84408 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84409 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84410 +_000825_hash disconnect 4 32521 _000825_hash NULL
84411 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84412 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84413 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84414 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84415 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84416 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84417 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84418 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84419 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84420 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84421 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84422 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84423 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84424 +_000840_hash do_sync 1 9604 _000840_hash NULL
84425 +_000841_hash dup_array 3 33551 _000841_hash NULL
84426 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84427 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84428 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84429 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84430 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84431 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84432 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84433 +_000849_hash enable_write 3 30456 _000849_hash NULL
84434 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84435 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84436 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84437 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84438 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84439 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84440 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84441 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84442 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84443 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84444 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84445 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84446 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84447 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84448 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84449 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84450 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84451 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84452 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84453 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84454 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84455 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84456 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84457 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84458 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84459 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84460 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84461 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84462 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84463 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84464 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84465 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84466 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84467 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84468 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84469 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84470 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84471 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84472 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84473 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84474 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84475 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84476 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84477 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84478 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84479 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84480 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84481 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84482 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84483 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84484 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84485 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84486 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84487 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84488 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84489 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84490 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84491 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84492 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84493 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84494 +_000915_hash init_q 4 132 _000915_hash NULL
84495 +_000916_hash init_state 2 60165 _000916_hash NULL
84496 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84497 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84498 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84499 +_000920_hash interfaces 2 38859 _000920_hash NULL
84500 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84501 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84502 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84503 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84504 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84505 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84506 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84507 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84508 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84509 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84510 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84511 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84512 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84513 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84514 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84515 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84516 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84517 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84518 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84519 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84520 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84521 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84522 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84523 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84524 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84525 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84526 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84527 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84528 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84529 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84530 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84531 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84532 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84533 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84534 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84535 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84536 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84537 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84538 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84539 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84540 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84541 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84542 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84543 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84544 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84545 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84546 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84547 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84548 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84549 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84550 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84551 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84552 +_000977_hash lc_create 3 48662 _000977_hash NULL
84553 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84554 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84555 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84556 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84557 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84558 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84559 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84560 +_000985_hash mem_read 3 57631 _000985_hash NULL
84561 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84562 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84563 +_000988_hash mem_write 3 22232 _000988_hash NULL
84564 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84565 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84566 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84567 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84568 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84569 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84570 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84571 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84572 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84573 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84574 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84575 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84576 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84577 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84578 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84579 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84580 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84581 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84582 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84583 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84584 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84585 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84586 +_001014_hash new_dir 3 31919 _001014_hash NULL
84587 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84588 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84589 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84590 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84591 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84592 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84593 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84594 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84595 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84596 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84597 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84598 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84599 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84600 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84601 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84602 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84603 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84604 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84605 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84606 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
84607 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
84608 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
84609 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
84610 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
84611 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
84612 +_001046_hash osst_write 3 31581 _001046_hash NULL
84613 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
84614 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
84615 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
84616 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
84617 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
84618 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
84619 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
84620 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
84621 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
84622 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
84623 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
84624 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
84625 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
84626 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
84627 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
84628 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
84629 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
84630 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
84631 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
84632 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
84633 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
84634 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
84635 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
84636 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
84637 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
84638 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
84639 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
84640 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
84641 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
84642 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
84643 +_001083_hash proc_write 3 51003 _001083_hash NULL
84644 +_001084_hash profile_load 3 58267 _001084_hash NULL
84645 +_001085_hash profile_remove 3 8556 _001085_hash NULL
84646 +_001086_hash profile_replace 3 14652 _001086_hash NULL
84647 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
84648 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
84649 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
84650 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
84651 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
84652 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
84653 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
84654 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
84655 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
84656 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
84657 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
84658 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
84659 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
84660 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
84661 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
84662 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
84663 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
84664 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
84665 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
84666 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
84667 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
84668 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
84669 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
84670 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
84671 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
84672 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
84673 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
84674 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
84675 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
84676 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
84677 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
84678 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
84679 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
84680 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
84681 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
84682 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
84683 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
84684 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
84685 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
84686 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
84687 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
84688 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
84689 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
84690 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
84691 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
84692 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
84693 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
84694 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
84695 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
84696 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
84697 +_001139_hash self_check_write 5 50856 _001139_hash NULL
84698 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
84699 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
84700 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
84701 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
84702 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
84703 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
84704 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
84705 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
84706 +_001148_hash set_connectable 4 56458 _001148_hash NULL
84707 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
84708 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
84709 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
84710 +_001152_hash setkey 3 14987 _001152_hash NULL
84711 +_001153_hash set_le 4 30581 _001153_hash NULL
84712 +_001154_hash set_link_security 4 4502 _001154_hash NULL
84713 +_001155_hash set_local_name 4 55757 _001155_hash NULL
84714 +_001156_hash set_powered 4 12129 _001156_hash NULL
84715 +_001157_hash set_ssp 4 62411 _001157_hash NULL
84716 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
84717 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
84718 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
84719 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
84720 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
84721 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
84722 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
84723 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
84724 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
84725 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
84726 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
84727 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
84728 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
84729 +_001174_hash skb_pad 2 17302 _001174_hash NULL
84730 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
84731 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
84732 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
84733 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
84734 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
84735 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
84736 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
84737 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
84738 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
84739 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
84740 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
84741 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
84742 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
84743 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
84744 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
84745 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
84746 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
84747 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
84748 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
84749 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
84750 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
84751 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
84752 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
84753 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
84754 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
84755 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
84756 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
84757 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
84758 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
84759 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
84760 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
84761 +_001208_hash sound_write 3 5102 _001208_hash NULL
84762 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
84763 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
84764 +_001213_hash spidev_message 3 5518 _001213_hash NULL
84765 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
84766 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
84767 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
84768 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
84769 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
84770 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
84771 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
84772 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
84773 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
84774 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
84775 +_001227_hash st_write 3 16874 _001227_hash NULL
84776 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
84777 +_001229_hash symtab_init 2 61050 _001229_hash NULL
84778 +_001230_hash sys_bind 3 10799 _001230_hash NULL
84779 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
84780 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
84781 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
84782 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
84783 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
84784 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
84785 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
84786 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
84787 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
84788 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
84789 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
84790 +_001242_hash sys_select 1 38827 _001242_hash NULL
84791 +_001243_hash sys_semop 3 39457 _001243_hash NULL
84792 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
84793 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
84794 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
84795 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
84796 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
84797 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
84798 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
84799 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
84800 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
84801 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
84802 +_001254_hash timeout_write 3 50991 _001254_hash NULL
84803 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
84804 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
84805 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
84806 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
84807 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
84808 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
84809 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
84810 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
84811 +_001264_hash tty_write 3 5494 _001264_hash NULL
84812 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
84813 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
84814 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
84815 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
84816 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
84817 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
84818 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
84819 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
84820 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
84821 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
84822 +_001277_hash vhci_write 3 2224 _001277_hash NULL
84823 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
84824 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
84825 +_001281_hash vmalloc 1 15464 _001281_hash NULL
84826 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
84827 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
84828 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
84829 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
84830 +_001286_hash vzalloc 1 47421 _001286_hash NULL
84831 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
84832 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
84833 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
84834 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
84835 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
84836 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
84837 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
84838 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
84839 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
84840 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
84841 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
84842 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
84843 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
84844 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
84845 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
84846 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
84847 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
84848 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
84849 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
84850 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
84851 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
84852 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
84853 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
84854 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
84855 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
84856 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
84857 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
84858 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
84859 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
84860 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
84861 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
84862 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
84863 +_001319_hash add_child 4 45201 _001319_hash NULL
84864 +_001320_hash add_port 2 54941 _001320_hash NULL
84865 +_001321_hash adu_read 3 24177 _001321_hash NULL
84866 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
84867 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
84868 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
84869 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
84870 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
84871 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
84872 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
84873 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
84874 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
84875 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
84876 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
84877 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
84878 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
84879 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
84880 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
84881 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
84882 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
84883 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
84884 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
84885 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
84886 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
84887 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
84888 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
84889 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
84890 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
84891 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
84892 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
84893 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
84894 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
84895 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
84896 +_001356_hash async_setkey 3 35521 _001356_hash NULL
84897 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
84898 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
84899 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
84900 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
84901 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
84902 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
84903 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
84904 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
84905 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
84906 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
84907 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
84908 +_001370_hash ax25_output 2 22736 _001370_hash NULL
84909 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
84910 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
84911 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
84912 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
84913 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
84914 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
84915 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
84916 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
84917 +_001380_hash bm_init 2 13529 _001380_hash NULL
84918 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
84919 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
84920 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
84921 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
84922 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
84923 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
84924 +_001387_hash cache_read 3 24790 _001387_hash NULL
84925 +_001388_hash cache_write 3 13589 _001388_hash NULL
84926 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
84927 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
84928 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
84929 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
84930 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
84931 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
84932 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
84933 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
84934 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
84935 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
84936 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
84937 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
84938 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
84939 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
84940 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
84941 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
84942 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
84943 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
84944 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
84945 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
84946 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
84947 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
84948 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
84949 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
84950 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
84951 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
84952 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
84953 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
84954 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
84955 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
84956 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
84957 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
84958 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
84959 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
84960 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
84961 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
84962 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
84963 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
84964 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
84965 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
84966 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
84967 +_001435_hash do_readlink 2 43518 _001435_hash NULL
84968 +_001436_hash __do_replace 5 37227 _001436_hash NULL
84969 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
84970 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
84971 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
84972 +_001440_hash dump_midi 3 51040 _001440_hash NULL
84973 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
84974 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
84975 +_001443_hash ep0_read 3 38095 _001443_hash NULL
84976 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
84977 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
84978 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
84979 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
84980 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
84981 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
84982 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
84983 +_001451_hash filldir 3 55137 _001451_hash NULL
84984 +_001452_hash filldir64 3 46469 _001452_hash NULL
84985 +_001453_hash find_skb 2 20431 _001453_hash NULL
84986 +_001454_hash from_buffer 3 18625 _001454_hash NULL
84987 +_001455_hash fsm_init 2 16134 _001455_hash NULL
84988 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
84989 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
84990 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
84991 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
84992 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
84993 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
84994 +_001462_hash get_packet 3 41914 _001462_hash NULL
84995 +_001463_hash get_packet 3 5747 _001463_hash NULL
84996 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
84997 +_001465_hash get_skb 2 63008 _001465_hash NULL
84998 +_001466_hash get_subdir 3 62581 _001466_hash NULL
84999 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85000 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85001 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85002 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85003 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85004 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85005 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85006 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85007 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85008 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85009 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85010 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85011 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85012 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85013 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85014 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85015 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85016 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85017 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85018 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85019 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85020 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85021 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85022 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85023 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85024 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85025 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85026 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85027 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85028 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85029 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85030 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85031 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85032 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85033 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85034 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85035 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85036 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85037 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85038 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85039 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85040 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85041 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85042 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85043 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85044 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85045 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85046 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85047 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85048 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85049 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85050 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85051 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85052 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85053 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85054 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85055 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85056 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85057 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85058 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85059 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85060 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85061 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85062 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85063 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85064 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85065 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85066 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85067 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85068 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85069 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85070 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85071 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85072 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85073 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85074 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85075 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85076 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85077 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85078 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85079 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85080 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85081 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85082 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85083 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85084 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85085 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85086 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85087 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85088 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85089 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85090 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85091 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85092 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85093 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85094 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85095 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85096 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85097 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85098 +_001575_hash new_skb 1 21148 _001575_hash NULL
85099 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85100 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85101 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85102 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85103 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85104 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85105 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85106 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85107 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85108 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85109 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85110 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85111 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85112 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85113 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85114 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85115 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85116 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85117 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85118 +_001599_hash override_release 2 52032 _001599_hash NULL
85119 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85120 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85121 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85122 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85123 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85124 +_001605_hash pg_read 3 17276 _001605_hash NULL
85125 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85126 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85127 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85128 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85129 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85130 +_001611_hash printer_read 3 54851 _001611_hash NULL
85131 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85132 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85133 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85134 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85135 +_001616_hash pt_read 3 49136 _001616_hash NULL
85136 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85137 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85138 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85139 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85140 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85141 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85142 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85143 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85144 +_001625_hash read_flush 3 43851 _001625_hash NULL
85145 +_001626_hash read_profile 3 27859 _001626_hash NULL
85146 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85147 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85148 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85149 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85150 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85151 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85152 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85153 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85154 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85155 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85156 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85157 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85158 +_001640_hash rx 4 57944 _001640_hash NULL
85159 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85160 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85161 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85162 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85163 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85164 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85165 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85166 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85167 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85168 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85169 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85170 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85171 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85172 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85173 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85174 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85175 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85176 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85177 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85178 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85179 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85180 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85181 +_001663_hash send_command 4 10832 _001663_hash NULL
85182 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85183 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85184 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85185 +_001667_hash set_arg 3 42824 _001667_hash NULL
85186 +_001668_hash sg_read 3 25799 _001668_hash NULL
85187 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85188 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85189 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85190 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85191 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85192 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85193 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85194 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85195 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85196 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85197 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85198 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85199 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85200 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85201 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85202 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85203 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85204 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85205 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85206 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85207 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85208 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85209 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85210 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85211 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85212 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85213 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85214 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85215 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85216 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85217 +_001704_hash store_msg 3 56417 _001704_hash NULL
85218 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85219 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85220 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85221 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85222 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85223 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85224 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85225 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85226 +_001713_hash syslog_print 2 307 _001713_hash NULL
85227 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85228 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85229 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85230 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85231 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85232 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85233 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85234 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85235 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85236 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85237 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85238 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85239 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85240 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85241 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85242 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85243 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85244 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85245 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85246 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85247 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85248 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85249 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85250 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85251 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85252 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85253 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85254 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85255 +_001746_hash uio_read 3 49300 _001746_hash NULL
85256 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85257 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85258 +_001749_hash unlink1 3 63059 _001749_hash NULL
85259 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85260 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85261 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85262 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85263 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85264 +_001756_hash user_read 3 51881 _001756_hash NULL
85265 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85266 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85267 +_001759_hash venus_create 4 20555 _001759_hash NULL
85268 +_001760_hash venus_link 5 32165 _001760_hash NULL
85269 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85270 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85271 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85272 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85273 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85274 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85275 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85276 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85277 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85278 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85279 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85280 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85281 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85282 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85283 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85284 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85285 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85286 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85287 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85288 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85289 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85290 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85291 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85292 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85293 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85294 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85295 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85296 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85297 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85298 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85299 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85300 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85301 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85302 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85303 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85304 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85305 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85306 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85307 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85308 +_001803_hash add_partition 2 55588 _001803_hash NULL
85309 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85310 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85311 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85312 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85313 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85314 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85315 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85316 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85317 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85318 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85319 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85320 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85321 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85322 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85323 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85324 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85325 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85326 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85327 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85328 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85329 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85330 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85331 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85332 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85333 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85334 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85335 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85336 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85337 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85338 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85339 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85340 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85341 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85342 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85343 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85344 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85345 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85346 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85347 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85348 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85349 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85350 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85351 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85352 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85353 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85354 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85355 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85356 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85357 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85358 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85359 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85360 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85361 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85362 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85363 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85364 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85365 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85366 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85367 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85368 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85369 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85370 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85371 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85372 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85373 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85374 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85375 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85376 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85377 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85378 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85379 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85380 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85381 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85382 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85383 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85384 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85385 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85386 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85387 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85388 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85389 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85390 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85391 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85392 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85393 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85394 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85395 +_001892_hash check_header 2 56930 _001892_hash NULL
85396 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85397 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85398 +_001895_hash console_store 4 36007 _001895_hash NULL
85399 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85400 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85401 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85402 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85403 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85404 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85405 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85406 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85407 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85408 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85409 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85410 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85411 +_001912_hash debug_output 3 18575 _001912_hash NULL
85412 +_001913_hash debug_read 3 19322 _001913_hash NULL
85413 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85414 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85415 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85416 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85417 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85418 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85419 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85420 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85421 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85422 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85423 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85424 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85425 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85426 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85427 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85428 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85429 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85430 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85431 +_001933_hash filter_read 3 61692 _001933_hash NULL
85432 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85433 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85434 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85435 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85436 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85437 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85438 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85439 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85440 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85441 +_001943_hash handle_response 5 55951 _001943_hash NULL
85442 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85443 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85444 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85445 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85446 +_001948_hash help 4 14971 _001948_hash NULL
85447 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85448 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85449 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85450 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85451 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85452 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85453 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85454 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85455 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85456 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85457 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85458 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85459 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85460 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85461 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85462 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85463 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85464 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85465 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85466 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85467 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85468 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85469 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85470 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85471 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85472 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85473 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85474 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85475 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85476 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85477 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85478 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85479 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85480 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85481 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85482 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85483 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85484 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85485 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85486 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85487 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85488 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85489 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85490 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85491 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85492 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85493 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85494 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85495 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85496 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85497 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85498 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85499 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85500 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85501 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85502 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85503 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85504 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85505 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85506 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85507 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85508 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85509 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85510 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85511 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85512 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85513 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85514 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85515 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85516 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85517 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85518 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85519 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85520 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85521 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85522 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85523 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85524 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85525 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85526 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85527 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85528 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85529 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85530 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85531 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85532 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85533 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85534 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85535 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85536 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85537 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85538 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85539 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85540 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85541 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85542 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85543 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85544 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85545 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85546 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85547 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85548 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85549 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85550 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85551 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85552 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85553 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85554 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85555 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85556 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85557 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85558 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85559 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85560 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85561 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85562 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85563 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85564 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85565 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85566 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85567 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85568 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85569 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85570 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85571 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85572 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85573 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85574 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85575 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85576 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85577 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85578 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85579 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85580 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85581 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85582 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85583 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85584 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85585 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85586 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85587 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85588 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85589 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85590 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85591 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85592 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85593 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85594 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85595 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85596 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85597 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85598 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85599 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85600 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85601 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85602 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85603 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85604 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85605 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85606 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
85607 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
85608 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
85609 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
85610 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
85611 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
85612 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
85613 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
85614 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
85615 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
85616 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
85617 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
85618 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
85619 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
85620 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
85621 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
85622 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
85623 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
85624 +_002136_hash osst_read 3 40237 _002136_hash NULL
85625 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
85626 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
85627 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
85628 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
85629 +_002143_hash page_readlink 3 23346 _002143_hash NULL
85630 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
85631 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
85632 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
85633 +_002148_hash pep_reply 5 50582 _002148_hash NULL
85634 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
85635 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
85636 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
85637 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
85638 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
85639 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
85640 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
85641 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
85642 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
85643 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
85644 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
85645 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
85646 +_002161_hash proc_read 3 43614 _002161_hash NULL
85647 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
85648 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
85649 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
85650 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
85651 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
85652 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
85653 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
85654 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
85655 +_002170_hash queues_read 3 24877 _002170_hash NULL
85656 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
85657 +_002172_hash rcname_read 3 25919 _002172_hash NULL
85658 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
85659 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
85660 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
85661 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
85662 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
85663 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
85664 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
85665 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
85666 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
85667 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
85668 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
85669 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
85670 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
85671 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
85672 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
85673 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
85674 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
85675 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
85676 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
85677 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
85678 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
85679 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
85680 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
85681 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
85682 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
85683 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
85684 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
85685 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
85686 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
85687 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
85688 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
85689 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
85690 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
85691 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
85692 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
85693 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
85694 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
85695 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
85696 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
85697 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
85698 +_002213_hash receive_packet 2 12367 _002213_hash NULL
85699 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
85700 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
85701 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
85702 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
85703 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
85704 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
85705 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
85706 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
85707 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
85708 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
85709 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
85710 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
85711 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
85712 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
85713 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
85714 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
85715 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
85716 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
85717 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
85718 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
85719 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
85720 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
85721 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
85722 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
85723 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
85724 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
85725 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
85726 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
85727 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
85728 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
85729 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
85730 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
85731 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
85732 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
85733 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
85734 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
85735 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
85736 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
85737 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
85738 +_002254_hash send_msg 4 37323 _002254_hash NULL
85739 +_002255_hash send_packet 4 52960 _002255_hash NULL
85740 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
85741 +_002257_hash sge_rx 3 50594 _002257_hash NULL
85742 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
85743 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
85744 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
85745 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
85746 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
85747 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
85748 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
85749 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
85750 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
85751 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
85752 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
85753 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
85754 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
85755 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
85756 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
85757 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
85758 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
85759 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
85760 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
85761 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
85762 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
85763 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
85764 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
85765 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
85766 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
85767 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
85768 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
85769 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
85770 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
85771 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
85772 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
85773 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
85774 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
85775 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
85776 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
85777 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
85778 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
85779 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
85780 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
85781 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
85782 +_002306_hash st_read 3 51251 _002306_hash NULL
85783 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
85784 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
85785 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
85786 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
85787 +_002311_hash sys_readv 3 50664 _002311_hash NULL
85788 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
85789 +_002313_hash sys_writev 3 28384 _002313_hash NULL
85790 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
85791 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
85792 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
85793 +_002317_hash teiup_create 3 43201 _002317_hash NULL
85794 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
85795 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
85796 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
85797 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
85798 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
85799 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
85800 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
85801 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
85802 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
85803 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
85804 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
85805 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
85806 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
85807 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
85808 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
85809 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
85810 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
85811 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
85812 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
85813 +_002341_hash um_idi_read 3 850 _002341_hash NULL
85814 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
85815 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
85816 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
85817 +_002345_hash use_pool 2 64607 _002345_hash NULL
85818 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
85819 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
85820 +_002348_hash vhci_read 3 47878 _002348_hash NULL
85821 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
85822 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
85823 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
85824 +_002353_hash waiters_read 3 40902 _002353_hash NULL
85825 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
85826 +_002355_hash write_pbl 4 59583 _002355_hash NULL
85827 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
85828 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
85829 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
85830 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
85831 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
85832 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
85833 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
85834 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
85835 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
85836 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
85837 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
85838 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
85839 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
85840 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
85841 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
85842 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
85843 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
85844 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
85845 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
85846 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
85847 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
85848 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
85849 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
85850 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
85851 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
85852 +_002382_hash bioset_create 1 5580 _002382_hash NULL
85853 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
85854 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
85855 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
85856 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
85857 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
85858 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
85859 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
85860 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
85861 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
85862 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
85863 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
85864 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
85865 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
85866 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
85867 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
85868 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
85869 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
85870 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
85871 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
85872 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
85873 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
85874 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
85875 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
85876 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
85877 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
85878 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
85879 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
85880 +_002411_hash depth_read 3 31112 _002411_hash NULL
85881 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
85882 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
85883 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
85884 +_002415_hash divas_write 3 63901 _002415_hash NULL
85885 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
85886 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
85887 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
85888 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
85889 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
85890 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
85891 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
85892 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
85893 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
85894 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
85895 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
85896 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
85897 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
85898 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
85899 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
85900 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
85901 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
85902 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
85903 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
85904 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
85905 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
85906 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
85907 +_002439_hash got_frame 2 16028 _002439_hash NULL
85908 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
85909 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
85910 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
85911 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
85912 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
85913 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
85914 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
85915 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
85916 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
85917 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
85918 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
85919 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
85920 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
85921 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
85922 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
85923 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
85924 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
85925 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
85926 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
85927 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
85928 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
85929 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
85930 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
85931 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
85932 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
85933 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
85934 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
85935 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
85936 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
85937 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
85938 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
85939 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
85940 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
85941 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
85942 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
85943 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
85944 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
85945 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
85946 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
85947 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
85948 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
85949 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
85950 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
85951 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
85952 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
85953 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
85954 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
85955 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
85956 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
85957 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
85958 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
85959 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
85960 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
85961 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
85962 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
85963 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
85964 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
85965 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
85966 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
85967 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
85968 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
85969 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
85970 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
85971 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
85972 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
85973 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
85974 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
85975 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
85976 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
85977 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
85978 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
85979 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
85980 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
85981 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
85982 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
85983 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
85984 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
85985 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
85986 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
85987 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
85988 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
85989 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
85990 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
85991 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
85992 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
85993 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
85994 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
85995 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
85996 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
85997 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
85998 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
85999 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86000 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86001 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86002 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86003 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86004 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86005 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86006 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86007 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86008 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86009 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86010 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86011 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86012 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86013 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86014 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86015 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86016 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86017 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86018 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86019 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86020 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86021 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86022 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86023 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86024 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86025 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86026 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86027 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86028 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86029 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86030 +_002570_hash map_addr 6 4666 _002570_hash NULL
86031 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86032 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86033 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86034 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86035 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86036 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86037 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86038 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86039 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86040 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86041 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86042 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86043 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86044 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86045 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86046 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86047 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86048 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86049 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86050 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86051 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86052 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86053 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86054 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86055 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86056 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86057 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86058 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86059 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86060 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86061 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86062 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86063 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86064 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86065 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86066 +_002612_hash power_read 3 15939 _002612_hash NULL
86067 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86068 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86069 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86070 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86071 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86072 +_002618_hash prison_create 1 43623 _002618_hash NULL
86073 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86074 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86075 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86076 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86077 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86078 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86079 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86080 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86081 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86082 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86083 +_002629_hash read_dma 3 55086 _002629_hash NULL
86084 +_002630_hash read_fifo 3 826 _002630_hash NULL
86085 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86086 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86087 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86088 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86089 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86090 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86091 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86092 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86093 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86094 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86095 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86096 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86097 +_002644_hash rx_data 4 60442 _002644_hash NULL
86098 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86099 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86100 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86101 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86102 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86103 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86104 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86105 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86106 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86107 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86108 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86109 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86110 +_002658_hash send_stream 4 3397 _002658_hash NULL
86111 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86112 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86113 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86114 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86115 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86116 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86117 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86118 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86119 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86120 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86121 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86122 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86123 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86124 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86125 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86126 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86127 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86128 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86129 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86130 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86131 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86132 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86133 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86134 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86135 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86136 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86137 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86138 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86139 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86140 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86141 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86142 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86143 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86144 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86145 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86146 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86147 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86148 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86149 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86150 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86151 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86152 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86153 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86154 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86155 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86156 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86157 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86158 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86159 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86160 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86161 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86162 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86163 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86164 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86165 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86166 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86167 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86168 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86169 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86170 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86171 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86172 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86173 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86174 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86175 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86176 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86177 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86178 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86179 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86180 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86181 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86182 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86183 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86184 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86185 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86186 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86187 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86188 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86189 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86190 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86191 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86192 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86193 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86194 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86195 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86196 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86197 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86198 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86199 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86200 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86201 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86202 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86203 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86204 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86205 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86206 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86207 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86208 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86209 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86210 +_002770_hash push_rx 3 28939 _002770_hash NULL
86211 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86212 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86213 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86214 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86215 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86216 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86217 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86218 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86219 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86220 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86221 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86222 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86223 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86224 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86225 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86226 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86227 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86228 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86229 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86230 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86231 +_002794_hash write_leb 5 36957 _002794_hash NULL
86232 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86233 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86234 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86235 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86236 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86237 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86238 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86239 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86240 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86241 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86242 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86243 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86244 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86245 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86246 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86247 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86248 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86249 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86250 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86251 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86252 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86253 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86254 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86255 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86256 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86257 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86258 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86259 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86260 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86261 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86262 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86263 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86264 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86265 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86266 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86267 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86268 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86269 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86270 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86271 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86272 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86273 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86274 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86275 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86276 +_002846_hash recover_head 3 17904 _002846_hash NULL
86277 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86278 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86279 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86280 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86281 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86282 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86283 +_002853_hash write_head 4 30481 _002853_hash NULL
86284 +_002854_hash write_node 4 33121 _002854_hash NULL
86285 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86286 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86287 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86288 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86289 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86290 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86291 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86292 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86293 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86294 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86295 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86296 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86297 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86298 +_002869_hash create_log 2 8225 _002869_hash NULL
86299 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86300 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86301 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86302 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86303 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86304 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86305 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86306 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86307 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86308 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86309 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86310 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86311 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86312 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86313 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86314 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86315 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86316 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86317 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86318 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86319 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86320 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86321 +_002893_hash _malloc 1 54077 _002893_hash NULL
86322 +_002894_hash mei_read 3 6507 _002894_hash NULL
86323 +_002895_hash mei_write 3 4005 _002895_hash NULL
86324 +_002896_hash msg_set 3 51725 _002896_hash NULL
86325 +_002897_hash newpart 6 47485 _002897_hash NULL
86326 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86327 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86328 +_002900_hash packet_came 3 18072 _002900_hash NULL
86329 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86330 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86331 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86332 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86333 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86334 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86335 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86336 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86337 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86338 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86339 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86340 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86341 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86342 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86343 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86344 +_002923_hash sep_read 3 17161 _002923_hash NULL
86345 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86346 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86347 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86348 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86349 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86350 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86351 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86352 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86353 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86354 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86355 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86356 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86357 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86358 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86359 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86360 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86361 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86362 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86363 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86364 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86365 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86366 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86367 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86368 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86369 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86370 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86371 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86372 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86373 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86374 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86375 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86376 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86377 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86378 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86379 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86380 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86381 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86382 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86383 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86384 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86385 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86386 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86387 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86388 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86389 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86390 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86391 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86392 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86393 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86394 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86395 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86396 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86397 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86398 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86399 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86400 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86401 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86402 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86403 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86404 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86405 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86406 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86407 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86408 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86409 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86410 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86411 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86412 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86413 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86414 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86415 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86416 +_003003_hash flash_read 3 57843 _003003_hash NULL
86417 +_003004_hash flash_write 3 62354 _003004_hash NULL
86418 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86419 +_003006_hash gather_array 3 56641 _003006_hash NULL
86420 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86421 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86422 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86423 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86424 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86425 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86426 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86427 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86428 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86429 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86430 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86431 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86432 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86433 +_003021_hash options_write 3 47243 _003021_hash NULL
86434 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86435 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86436 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86437 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86438 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86439 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86440 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86441 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86442 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86443 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86444 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86445 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86446 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86447 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86448 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86449 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86450 +_003038_hash split 2 11691 _003038_hash NULL
86451 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86452 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86453 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86454 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86455 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86456 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86457 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86458 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86459 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86460 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86461 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86462 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86463 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86464 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86465 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86466 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86467 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86468 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86469 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86470 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86471 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86472 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86473 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86474 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86475 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86476 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86477 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86478 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86479 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86480 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86481 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86482 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86483 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86484 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86485 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86486 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86487 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86488 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86489 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86490 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86491 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86492 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86493 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86494 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86495 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86496 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86497 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86498 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86499 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86500 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86501 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86502 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86503 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86504 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86505 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86506 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86507 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86508 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86509 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86510 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86511 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86512 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86513 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86514 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86515 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86516 +_003108_hash conf_read 3 55786 _003108_hash NULL
86517 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86518 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86519 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86520 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86521 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86522 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86523 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86524 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86525 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86526 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86527 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86528 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86529 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86530 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86531 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86532 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86533 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86534 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86535 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86536 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86537 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86538 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86539 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86540 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86541 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86542 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86543 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86544 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86545 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86546 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86547 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86548 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86549 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86550 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86551 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86552 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86553 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86554 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86555 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86556 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86557 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86558 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86559 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86560 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86561 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86562 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86563 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86564 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86565 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86566 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86567 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86568 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86569 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86570 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86571 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86572 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86573 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86574 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86575 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86576 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86577 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86578 +_003175_hash get_info 3 55681 _003175_hash NULL
86579 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86580 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86581 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86582 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86583 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86584 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86585 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86586 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86587 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86588 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86589 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86590 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86591 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86592 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86593 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86594 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86595 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86596 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86597 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86598 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86599 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86600 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86601 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86602 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86603 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86604 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86605 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86606 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
86607 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
86608 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
86609 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
86610 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
86611 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
86612 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
86613 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
86614 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
86615 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
86616 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
86617 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
86618 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
86619 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
86620 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
86621 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
86622 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
86623 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
86624 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
86625 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
86626 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
86627 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
86628 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
86629 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
86630 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
86631 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
86632 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
86633 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
86634 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
86635 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
86636 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
86637 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
86638 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
86639 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
86640 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
86641 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
86642 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
86643 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
86644 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
86645 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
86646 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
86647 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
86648 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
86649 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
86650 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
86651 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
86652 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
86653 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
86654 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
86655 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
86656 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
86657 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
86658 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
86659 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
86660 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
86661 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
86662 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
86663 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
86664 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
86665 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
86666 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
86667 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
86668 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
86669 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
86670 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
86671 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
86672 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
86673 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
86674 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
86675 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
86676 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
86677 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
86678 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
86679 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
86680 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
86681 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
86682 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
86683 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
86684 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
86685 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
86686 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
86687 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
86688 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
86689 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
86690 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
86691 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
86692 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
86693 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
86694 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
86695 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
86696 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
86697 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
86698 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
86699 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
86700 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
86701 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
86702 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
86703 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
86704 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
86705 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
86706 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
86707 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
86708 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
86709 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
86710 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
86711 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
86712 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
86713 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
86714 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
86715 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
86716 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
86717 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
86718 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
86719 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
86720 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
86721 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
86722 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
86723 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
86724 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
86725 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
86726 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
86727 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
86728 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
86729 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
86730 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
86731 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
86732 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
86733 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
86734 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
86735 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
86736 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
86737 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
86738 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
86739 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
86740 +_003340_hash alloc_private 2 22399 _003340_hash NULL
86741 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
86742 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
86743 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
86744 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
86745 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
86746 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
86747 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
86748 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
86749 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
86750 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
86751 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
86752 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
86753 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
86754 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
86755 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
86756 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
86757 +_003359_hash comedi_read 3 13199 _003359_hash NULL
86758 +_003360_hash comedi_write 3 47926 _003360_hash NULL
86759 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
86760 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
86761 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
86762 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
86763 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
86764 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
86765 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
86766 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
86767 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
86768 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
86769 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
86770 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
86771 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
86772 +_003377_hash dev_read 3 56369 _003377_hash NULL
86773 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
86774 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
86775 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
86776 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
86777 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
86778 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
86779 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
86780 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
86781 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
86782 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
86783 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
86784 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
86785 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
86786 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
86787 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
86788 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
86789 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
86790 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
86791 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
86792 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
86793 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
86794 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
86795 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
86796 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
86797 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
86798 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
86799 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
86800 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
86801 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
86802 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
86803 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
86804 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
86805 +_003412_hash fb_read 3 33506 _003412_hash NULL
86806 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
86807 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
86808 +_003415_hash fb_write 3 46924 _003415_hash NULL
86809 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
86810 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
86811 +_003418_hash fops_read 3 40672 _003418_hash NULL
86812 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
86813 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
86814 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
86815 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
86816 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
86817 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
86818 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
86819 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
86820 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
86821 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
86822 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
86823 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
86824 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
86825 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
86826 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
86827 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
86828 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
86829 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
86830 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
86831 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
86832 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
86833 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
86834 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
86835 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
86836 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
86837 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
86838 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
86839 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
86840 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
86841 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
86842 +_003451_hash lirc_write 3 20604 _003451_hash NULL
86843 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
86844 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
86845 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
86846 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
86847 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
86848 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
86849 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
86850 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
86851 +_003461_hash mmio_read 4 40348 _003461_hash NULL
86852 +_003462_hash netlink_send 5 38434 _003462_hash NULL
86853 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
86854 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
86855 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
86856 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
86857 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
86858 +_003468_hash odev_update 2 50169 _003468_hash NULL
86859 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
86860 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
86861 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
86862 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
86863 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
86864 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
86865 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
86866 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
86867 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
86868 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
86869 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
86870 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
86871 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
86872 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
86873 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
86874 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
86875 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
86876 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
86877 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
86878 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
86879 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
86880 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
86881 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
86882 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
86883 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
86884 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
86885 +_003497_hash play_iframe 3 8219 _003497_hash NULL
86886 +_003498_hash probes_write 3 29711 _003498_hash NULL
86887 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
86888 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
86889 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
86890 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
86891 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
86892 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
86893 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
86894 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
86895 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
86896 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
86897 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
86898 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
86899 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
86900 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
86901 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
86902 +_003514_hash qc_capture 3 19298 _003514_hash NULL
86903 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
86904 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
86905 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
86906 +_003518_hash Realloc 2 34961 _003518_hash NULL
86907 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
86908 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
86909 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
86910 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
86911 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
86912 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
86913 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
86914 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
86915 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
86916 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
86917 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
86918 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
86919 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
86920 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
86921 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
86922 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
86923 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
86924 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
86925 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
86926 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
86927 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
86928 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
86929 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
86930 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
86931 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
86932 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
86933 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
86934 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
86935 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
86936 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
86937 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
86938 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
86939 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
86940 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
86941 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
86942 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
86943 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
86944 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
86945 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
86946 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
86947 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
86948 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
86949 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
86950 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
86951 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
86952 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
86953 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
86954 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
86955 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
86956 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
86957 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
86958 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
86959 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
86960 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
86961 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
86962 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
86963 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
86964 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
86965 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
86966 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
86967 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
86968 +_003584_hash ts_read 3 44687 _003584_hash NULL
86969 +_003585_hash ts_write 3 64336 _003585_hash NULL
86970 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
86971 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
86972 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
86973 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
86974 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
86975 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
86976 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
86977 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
86978 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
86979 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
86980 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
86981 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
86982 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
86983 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
86984 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
86985 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
86986 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
86987 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
86988 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
86989 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
86990 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
86991 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
86992 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
86993 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
86994 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
86995 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
86996 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
86997 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
86998 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
86999 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87000 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87001 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87002 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87003 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87004 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87005 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87006 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87007 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87008 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87009 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87010 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87011 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87012 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87013 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87014 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87015 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87016 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87017 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87018 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87019 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87020 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87021 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87022 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87023 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87024 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87025 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87026 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87027 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87028 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87029 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87030 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87031 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87032 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87033 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87034 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87035 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87036 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87037 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87038 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87039 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87040 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87041 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87042 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87043 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87044 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87045 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87046 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87047 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87048 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87049 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87050 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87051 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87052 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87053 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87054 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87055 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87056 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87057 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87058 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87059 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87060 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87061 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87062 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87063 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87064 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87065 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87066 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87067 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87068 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87069 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87070 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87071 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87072 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87073 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87074 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87075 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87076 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87077 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87078 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87079 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87080 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87081 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87082 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87083 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87084 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87085 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87086 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87087 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87088 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87089 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87090 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87091 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87092 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87093 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87094 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87095 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87096 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87097 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87098 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87099 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87100 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87101 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87102 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87103 +_003729_hash vmap 2 15025 _003729_hash NULL
87104 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87105 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87106 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87107 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87108 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87109 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87110 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87111 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87112 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87113 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87114 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87115 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87116 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87117 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87118 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87119 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87120 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87121 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87122 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87123 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87124 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87125 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87126 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87127 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87128 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87129 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87130 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87131 +_003766_hash video_read 3 28148 _003766_hash NULL
87132 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87133 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87134 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87135 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87136 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87137 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87138 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87139 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87140 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87141 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87142 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87143 +_003783_hash do_test 1 15766 _003783_hash NULL
87144 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87145 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87146 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87147 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87148 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87149 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87150 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87151 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87152 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87153 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87154 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87155 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87156 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87157 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87158 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87159 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87160 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87161 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87162 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87163 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87164 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87165 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87166 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87167 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87168 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87169 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87170 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87171 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87172 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87173 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87174 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87175 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87176 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87177 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87178 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87179 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87180 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87181 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87182 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87183 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87184 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87185 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87186 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87187 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87188 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87189 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87190 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87191 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87192 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87193 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87194 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87195 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87196 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87197 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87198 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87199 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87200 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87201 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87202 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87203 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87204 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87205 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87206 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87207 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87208 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87209 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87210 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87211 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87212 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87213 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87214 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87215 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87216 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87217 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87218 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87219 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87220 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87221 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87222 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87223 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87224 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87225 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87226 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87227 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87228 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87229 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87230 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87231 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87232 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87233 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87234 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87235 new file mode 100644
87236 index 0000000..244559e
87237 --- /dev/null
87238 +++ b/tools/gcc/size_overflow_plugin.c
87239 @@ -0,0 +1,1879 @@
87240 +/*
87241 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87242 + * Licensed under the GPL v2, or (at your option) v3
87243 + *
87244 + * Homepage:
87245 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87246 + *
87247 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87248 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87249 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87250 + *
87251 + * Usage:
87252 + * $ 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
87253 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87254 + */
87255 +
87256 +#include "gcc-plugin.h"
87257 +#include "config.h"
87258 +#include "system.h"
87259 +#include "coretypes.h"
87260 +#include "tree.h"
87261 +#include "tree-pass.h"
87262 +#include "intl.h"
87263 +#include "plugin-version.h"
87264 +#include "tm.h"
87265 +#include "toplev.h"
87266 +#include "function.h"
87267 +#include "tree-flow.h"
87268 +#include "plugin.h"
87269 +#include "gimple.h"
87270 +#include "c-common.h"
87271 +#include "diagnostic.h"
87272 +#include "cfgloop.h"
87273 +
87274 +#if BUILDING_GCC_VERSION >= 4007
87275 +#include "c-tree.h"
87276 +#else
87277 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87278 +#endif
87279 +
87280 +struct size_overflow_hash {
87281 + const struct size_overflow_hash * const next;
87282 + const char * const name;
87283 + const unsigned int param;
87284 +};
87285 +
87286 +#include "size_overflow_hash.h"
87287 +
87288 +enum marked {
87289 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87290 +};
87291 +
87292 +#define __unused __attribute__((__unused__))
87293 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87294 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87295 +#define BEFORE_STMT true
87296 +#define AFTER_STMT false
87297 +#define CREATE_NEW_VAR NULL_TREE
87298 +#define CODES_LIMIT 32
87299 +#define MAX_PARAM 32
87300 +#define MY_STMT GF_PLF_1
87301 +#define NO_CAST_CHECK GF_PLF_2
87302 +
87303 +#if BUILDING_GCC_VERSION == 4005
87304 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87305 +#endif
87306 +
87307 +int plugin_is_GPL_compatible;
87308 +void debug_gimple_stmt(gimple gs);
87309 +
87310 +static tree expand(struct pointer_set_t *visited, tree lhs);
87311 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87312 +static tree report_size_overflow_decl;
87313 +static const_tree const_char_ptr_type_node;
87314 +static unsigned int handle_function(void);
87315 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87316 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87317 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87318 +
87319 +static struct plugin_info size_overflow_plugin_info = {
87320 + .version = "20120930beta",
87321 + .help = "no-size-overflow\tturn off size overflow checking\n",
87322 +};
87323 +
87324 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87325 +{
87326 + unsigned int arg_count;
87327 + enum tree_code code = TREE_CODE(*node);
87328 +
87329 + switch (code) {
87330 + case FUNCTION_DECL:
87331 + arg_count = type_num_arguments(TREE_TYPE(*node));
87332 + break;
87333 + case FUNCTION_TYPE:
87334 + case METHOD_TYPE:
87335 + arg_count = type_num_arguments(*node);
87336 + break;
87337 + default:
87338 + *no_add_attrs = true;
87339 + error("%s: %qE attribute only applies to functions", __func__, name);
87340 + return NULL_TREE;
87341 + }
87342 +
87343 + for (; args; args = TREE_CHAIN(args)) {
87344 + tree position = TREE_VALUE(args);
87345 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87346 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87347 + *no_add_attrs = true;
87348 + }
87349 + }
87350 + return NULL_TREE;
87351 +}
87352 +
87353 +static const char* get_asm_name(tree node)
87354 +{
87355 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87356 +}
87357 +
87358 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87359 +{
87360 + unsigned int arg_count, arg_num;
87361 + enum tree_code code = TREE_CODE(*node);
87362 +
87363 + switch (code) {
87364 + case FUNCTION_DECL:
87365 + arg_count = type_num_arguments(TREE_TYPE(*node));
87366 + break;
87367 + case FUNCTION_TYPE:
87368 + case METHOD_TYPE:
87369 + arg_count = type_num_arguments(*node);
87370 + break;
87371 + case FIELD_DECL:
87372 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87373 + if (arg_num != 0) {
87374 + *no_add_attrs = true;
87375 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87376 + }
87377 + return NULL_TREE;
87378 + default:
87379 + *no_add_attrs = true;
87380 + error("%qE attribute only applies to functions", name);
87381 + return NULL_TREE;
87382 + }
87383 +
87384 + for (; args; args = TREE_CHAIN(args)) {
87385 + tree position = TREE_VALUE(args);
87386 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87387 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87388 + *no_add_attrs = true;
87389 + }
87390 + }
87391 + return NULL_TREE;
87392 +}
87393 +
87394 +static struct attribute_spec size_overflow_attr = {
87395 + .name = "size_overflow",
87396 + .min_length = 1,
87397 + .max_length = -1,
87398 + .decl_required = true,
87399 + .type_required = false,
87400 + .function_type_required = false,
87401 + .handler = handle_size_overflow_attribute,
87402 +#if BUILDING_GCC_VERSION >= 4007
87403 + .affects_type_identity = false
87404 +#endif
87405 +};
87406 +
87407 +static struct attribute_spec intentional_overflow_attr = {
87408 + .name = "intentional_overflow",
87409 + .min_length = 1,
87410 + .max_length = -1,
87411 + .decl_required = true,
87412 + .type_required = false,
87413 + .function_type_required = false,
87414 + .handler = handle_intentional_overflow_attribute,
87415 +#if BUILDING_GCC_VERSION >= 4007
87416 + .affects_type_identity = false
87417 +#endif
87418 +};
87419 +
87420 +static void register_attributes(void __unused *event_data, void __unused *data)
87421 +{
87422 + register_attribute(&size_overflow_attr);
87423 + register_attribute(&intentional_overflow_attr);
87424 +}
87425 +
87426 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87427 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87428 +{
87429 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87430 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87431 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87432 +
87433 + unsigned int m = 0x57559429;
87434 + unsigned int n = 0x5052acdb;
87435 + const unsigned int *key4 = (const unsigned int *)key;
87436 + unsigned int h = len;
87437 + unsigned int k = len + seed + n;
87438 + unsigned long long p;
87439 +
87440 + while (len >= 8) {
87441 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87442 + len -= 8;
87443 + }
87444 + if (len >= 4) {
87445 + cwmixb(key4[0]) key4 += 1;
87446 + len -= 4;
87447 + }
87448 + if (len)
87449 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87450 + cwmixb(h ^ (k + n));
87451 + return k ^ h;
87452 +
87453 +#undef cwfold
87454 +#undef cwmixa
87455 +#undef cwmixb
87456 +}
87457 +
87458 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87459 +{
87460 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87461 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87462 + return fn ^ codes;
87463 +}
87464 +
87465 +static inline tree get_original_function_decl(tree fndecl)
87466 +{
87467 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87468 + return DECL_ABSTRACT_ORIGIN(fndecl);
87469 + return fndecl;
87470 +}
87471 +
87472 +static inline gimple get_def_stmt(const_tree node)
87473 +{
87474 + gcc_assert(node != NULL_TREE);
87475 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87476 + return SSA_NAME_DEF_STMT(node);
87477 +}
87478 +
87479 +static unsigned char get_tree_code(const_tree type)
87480 +{
87481 + switch (TREE_CODE(type)) {
87482 + case ARRAY_TYPE:
87483 + return 0;
87484 + case BOOLEAN_TYPE:
87485 + return 1;
87486 + case ENUMERAL_TYPE:
87487 + return 2;
87488 + case FUNCTION_TYPE:
87489 + return 3;
87490 + case INTEGER_TYPE:
87491 + return 4;
87492 + case POINTER_TYPE:
87493 + return 5;
87494 + case RECORD_TYPE:
87495 + return 6;
87496 + case UNION_TYPE:
87497 + return 7;
87498 + case VOID_TYPE:
87499 + return 8;
87500 + case REAL_TYPE:
87501 + return 9;
87502 + case VECTOR_TYPE:
87503 + return 10;
87504 + case REFERENCE_TYPE:
87505 + return 11;
87506 + case OFFSET_TYPE:
87507 + return 12;
87508 + case COMPLEX_TYPE:
87509 + return 13;
87510 + default:
87511 + debug_tree((tree)type);
87512 + gcc_unreachable();
87513 + }
87514 +}
87515 +
87516 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87517 +{
87518 + gcc_assert(type != NULL_TREE);
87519 +
87520 + while (type && len < CODES_LIMIT) {
87521 + tree_codes[len] = get_tree_code(type);
87522 + len++;
87523 + type = TREE_TYPE(type);
87524 + }
87525 + return len;
87526 +}
87527 +
87528 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87529 +{
87530 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87531 + enum tree_code code = TREE_CODE(type);
87532 + size_t len = 0;
87533 +
87534 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87535 +
87536 + arg = TYPE_ARG_TYPES(type);
87537 + // skip builtins __builtin_constant_p
87538 + if (!arg && DECL_BUILT_IN(fndecl))
87539 + return 0;
87540 +
87541 + if (TREE_CODE_CLASS(code) == tcc_type)
87542 + result = type;
87543 + else
87544 + result = DECL_RESULT(fndecl);
87545 +
87546 + gcc_assert(result != NULL_TREE);
87547 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87548 +
87549 + if (arg == NULL_TREE) {
87550 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87551 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87552 + if (arg_field == NULL_TREE)
87553 + return 0;
87554 + arg = TREE_TYPE(arg_field);
87555 + len = add_type_codes(arg, tree_codes, len);
87556 + gcc_assert(len != 0);
87557 + return len;
87558 + }
87559 +
87560 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87561 + while (arg && len < CODES_LIMIT) {
87562 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87563 + arg = TREE_CHAIN(arg);
87564 + }
87565 +
87566 + gcc_assert(len != 0);
87567 + return len;
87568 +}
87569 +
87570 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87571 +{
87572 + unsigned int hash;
87573 + const struct size_overflow_hash *entry;
87574 + unsigned char tree_codes[CODES_LIMIT];
87575 + size_t len;
87576 + const char *func_name = get_asm_name(fndecl);
87577 +
87578 + len = get_function_decl(fndecl, tree_codes);
87579 + if (len == 0)
87580 + return NULL;
87581 +
87582 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87583 +
87584 + entry = size_overflow_hash[hash];
87585 + while (entry) {
87586 + if (!strcmp(entry->name, func_name))
87587 + return entry;
87588 + entry = entry->next;
87589 + }
87590 +
87591 + return NULL;
87592 +}
87593 +
87594 +static void check_arg_type(const_tree arg)
87595 +{
87596 + const_tree type = TREE_TYPE(arg);
87597 + enum tree_code code = TREE_CODE(type);
87598 +
87599 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87600 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87601 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87602 +}
87603 +
87604 +static int find_arg_number(const_tree arg, tree func)
87605 +{
87606 + tree var;
87607 + unsigned int argnum = 1;
87608 +
87609 + if (TREE_CODE(arg) == SSA_NAME)
87610 + arg = SSA_NAME_VAR(arg);
87611 +
87612 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
87613 + if (strcmp(NAME(arg), NAME(var))) {
87614 + argnum++;
87615 + continue;
87616 + }
87617 + check_arg_type(var);
87618 + return argnum;
87619 + }
87620 + gcc_unreachable();
87621 +}
87622 +
87623 +static tree create_new_var(tree type)
87624 +{
87625 + tree new_var = create_tmp_var(type, "cicus");
87626 +
87627 + add_referenced_var(new_var);
87628 + mark_sym_for_renaming(new_var);
87629 + return new_var;
87630 +}
87631 +
87632 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
87633 +{
87634 + gimple assign;
87635 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87636 + tree type = TREE_TYPE(rhs1);
87637 + tree lhs = create_new_var(type);
87638 +
87639 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
87640 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87641 +
87642 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87643 + update_stmt(assign);
87644 + gimple_set_plf(assign, MY_STMT, true);
87645 + return assign;
87646 +}
87647 +
87648 +static bool is_bool(const_tree node)
87649 +{
87650 + const_tree type;
87651 +
87652 + if (node == NULL_TREE)
87653 + return false;
87654 +
87655 + type = TREE_TYPE(node);
87656 + if (!INTEGRAL_TYPE_P(type))
87657 + return false;
87658 + if (TREE_CODE(type) == BOOLEAN_TYPE)
87659 + return true;
87660 + if (TYPE_PRECISION(type) == 1)
87661 + return true;
87662 + return false;
87663 +}
87664 +
87665 +static tree cast_a_tree(tree type, tree var)
87666 +{
87667 + gcc_assert(type != NULL_TREE);
87668 + gcc_assert(var != NULL_TREE);
87669 + gcc_assert(fold_convertible_p(type, var));
87670 +
87671 + return fold_convert(type, var);
87672 +}
87673 +
87674 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
87675 +{
87676 + gimple assign;
87677 +
87678 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
87679 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
87680 + gcc_unreachable();
87681 +
87682 + if (lhs == CREATE_NEW_VAR)
87683 + lhs = create_new_var(dst_type);
87684 +
87685 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
87686 +
87687 + if (!gsi_end_p(*gsi)) {
87688 + location_t loc = gimple_location(gsi_stmt(*gsi));
87689 + gimple_set_location(assign, loc);
87690 + }
87691 +
87692 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87693 +
87694 + if (before)
87695 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
87696 + else
87697 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
87698 + update_stmt(assign);
87699 + gimple_set_plf(assign, MY_STMT, true);
87700 +
87701 + return assign;
87702 +}
87703 +
87704 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
87705 +{
87706 + const_gimple assign;
87707 + gimple_stmt_iterator gsi;
87708 +
87709 + if (new_rhs1 == NULL_TREE)
87710 + return NULL_TREE;
87711 +
87712 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
87713 + gsi = gsi_for_stmt(stmt);
87714 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
87715 + return gimple_get_lhs(assign);
87716 + }
87717 + return new_rhs1;
87718 +}
87719 +
87720 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, gimple stmt, const_tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
87721 +{
87722 + tree size_overflow_type = get_size_overflow_type(stmt, node);
87723 +
87724 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87725 +
87726 + if (new_rhs2 != NULL_TREE)
87727 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
87728 +
87729 + if (new_rhs3 != NULL_TREE)
87730 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
87731 +
87732 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
87733 +}
87734 +
87735 +
87736 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
87737 +{
87738 + tree size_overflow_type, lhs;
87739 + gimple stmt;
87740 + gimple_stmt_iterator gsi;
87741 +
87742 + if (rhs1 == NULL_TREE) {
87743 + debug_gimple_stmt(oldstmt);
87744 + error("%s: rhs1 is NULL_TREE", __func__);
87745 + gcc_unreachable();
87746 + }
87747 +
87748 + if (gimple_code(oldstmt) == GIMPLE_ASM)
87749 + lhs = rhs1;
87750 + else
87751 + lhs = gimple_get_lhs(oldstmt);
87752 +
87753 + gsi = gsi_for_stmt(oldstmt);
87754 + pointer_set_insert(visited, oldstmt);
87755 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
87756 + basic_block next_bb, cur_bb;
87757 + const_edge e;
87758 +
87759 + gcc_assert(before == false);
87760 + gcc_assert(stmt_can_throw_internal(oldstmt));
87761 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
87762 + gcc_assert(!gsi_end_p(gsi));
87763 +
87764 + cur_bb = gimple_bb(oldstmt);
87765 + next_bb = cur_bb->next_bb;
87766 + e = find_edge(cur_bb, next_bb);
87767 + gcc_assert(e != NULL);
87768 + gcc_assert(e->flags & EDGE_FALLTHRU);
87769 +
87770 + gsi = gsi_after_labels(next_bb);
87771 + gcc_assert(!gsi_end_p(gsi));
87772 +
87773 + before = true;
87774 + oldstmt = gsi_stmt(gsi);
87775 + }
87776 +
87777 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
87778 +
87779 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
87780 + gimple_set_plf(stmt, MY_STMT, true);
87781 + return gimple_get_lhs(stmt);
87782 +}
87783 +
87784 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
87785 +{
87786 + gimple stmt;
87787 + gimple_stmt_iterator gsi;
87788 + tree new_var, lhs = gimple_get_lhs(oldstmt);
87789 +
87790 + if (gimple_plf(oldstmt, MY_STMT))
87791 + return lhs;
87792 +
87793 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
87794 + rhs1 = gimple_assign_rhs1(oldstmt);
87795 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
87796 + }
87797 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
87798 + rhs2 = gimple_assign_rhs2(oldstmt);
87799 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
87800 + }
87801 +
87802 + stmt = gimple_copy(oldstmt);
87803 + gimple_set_location(stmt, gimple_location(oldstmt));
87804 + gimple_set_plf(stmt, MY_STMT, true);
87805 +
87806 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
87807 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
87808 +
87809 + if (is_bool(lhs))
87810 + new_var = SSA_NAME_VAR(lhs);
87811 + else
87812 + new_var = create_new_var(size_overflow_type);
87813 + new_var = make_ssa_name(new_var, stmt);
87814 + gimple_set_lhs(stmt, new_var);
87815 +
87816 + if (rhs1 != NULL_TREE) {
87817 + if (!gimple_assign_cast_p(oldstmt))
87818 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
87819 + gimple_assign_set_rhs1(stmt, rhs1);
87820 + }
87821 +
87822 + if (rhs2 != NULL_TREE)
87823 + gimple_assign_set_rhs2(stmt, rhs2);
87824 +#if BUILDING_GCC_VERSION >= 4007
87825 + if (rhs3 != NULL_TREE)
87826 + gimple_assign_set_rhs3(stmt, rhs3);
87827 +#endif
87828 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
87829 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
87830 +
87831 + gsi = gsi_for_stmt(oldstmt);
87832 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
87833 + update_stmt(stmt);
87834 + pointer_set_insert(visited, oldstmt);
87835 + return gimple_get_lhs(stmt);
87836 +}
87837 +
87838 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
87839 +{
87840 + basic_block bb;
87841 + gimple phi;
87842 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
87843 +
87844 + bb = gsi_bb(gsi);
87845 +
87846 + phi = create_phi_node(result, bb);
87847 + gsi = gsi_last(phi_nodes(bb));
87848 + gsi_remove(&gsi, false);
87849 +
87850 + gsi = gsi_for_stmt(oldstmt);
87851 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
87852 + gimple_set_bb(phi, bb);
87853 + gimple_set_plf(phi, MY_STMT, true);
87854 + return phi;
87855 +}
87856 +
87857 +static basic_block create_a_first_bb(void)
87858 +{
87859 + basic_block first_bb;
87860 +
87861 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87862 + if (dom_info_available_p(CDI_DOMINATORS))
87863 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
87864 + return first_bb;
87865 +}
87866 +
87867 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
87868 +{
87869 + basic_block bb;
87870 + const_gimple newstmt;
87871 + gimple_stmt_iterator gsi;
87872 + bool before = BEFORE_STMT;
87873 +
87874 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
87875 + gsi = gsi_for_stmt(get_def_stmt(arg));
87876 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
87877 + return gimple_get_lhs(newstmt);
87878 + }
87879 +
87880 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
87881 + gsi = gsi_after_labels(bb);
87882 + if (bb->index == 0) {
87883 + bb = create_a_first_bb();
87884 + gsi = gsi_start_bb(bb);
87885 + }
87886 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
87887 + return gimple_get_lhs(newstmt);
87888 +}
87889 +
87890 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
87891 +{
87892 + gimple newstmt;
87893 + gimple_stmt_iterator gsi;
87894 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
87895 + gimple def_newstmt = get_def_stmt(new_rhs);
87896 +
87897 + gsi_insert = gsi_insert_after;
87898 + gsi = gsi_for_stmt(def_newstmt);
87899 +
87900 + switch (gimple_code(get_def_stmt(arg))) {
87901 + case GIMPLE_PHI:
87902 + newstmt = gimple_build_assign(new_var, new_rhs);
87903 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
87904 + gsi_insert = gsi_insert_before;
87905 + break;
87906 + case GIMPLE_ASM:
87907 + case GIMPLE_CALL:
87908 + newstmt = gimple_build_assign(new_var, new_rhs);
87909 + break;
87910 + case GIMPLE_ASSIGN:
87911 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
87912 + break;
87913 + default:
87914 + /* unknown gimple_code (handle_build_new_phi_arg) */
87915 + gcc_unreachable();
87916 + }
87917 +
87918 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
87919 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
87920 + gimple_set_plf(newstmt, MY_STMT, true);
87921 + update_stmt(newstmt);
87922 + return newstmt;
87923 +}
87924 +
87925 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
87926 +{
87927 + const_gimple newstmt;
87928 + gimple def_stmt;
87929 + tree new_rhs;
87930 +
87931 + new_rhs = expand(visited, arg);
87932 + if (new_rhs == NULL_TREE)
87933 + return NULL_TREE;
87934 +
87935 + def_stmt = get_def_stmt(new_rhs);
87936 + if (gimple_code(def_stmt) == GIMPLE_NOP)
87937 + return NULL_TREE;
87938 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
87939 +
87940 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87941 + return gimple_get_lhs(newstmt);
87942 +}
87943 +
87944 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
87945 +{
87946 + gimple phi, oldstmt = get_def_stmt(orig_result);
87947 + tree new_result, size_overflow_type;
87948 + unsigned int i;
87949 + unsigned int n = gimple_phi_num_args(oldstmt);
87950 +
87951 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87952 +
87953 + new_result = create_new_var(size_overflow_type);
87954 +
87955 + pointer_set_insert(visited, oldstmt);
87956 + phi = overflow_create_phi_node(oldstmt, new_result);
87957 + for (i = 0; i < n; i++) {
87958 + tree arg, lhs;
87959 +
87960 + arg = gimple_phi_arg_def(oldstmt, i);
87961 + if (is_gimple_constant(arg))
87962 + arg = cast_a_tree(size_overflow_type, arg);
87963 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
87964 + if (lhs == NULL_TREE)
87965 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87966 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87967 + }
87968 +
87969 + update_stmt(phi);
87970 + return gimple_phi_result(phi);
87971 +}
87972 +
87973 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87974 +{
87975 + const_gimple assign;
87976 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87977 + tree origtype = TREE_TYPE(orig_rhs);
87978 +
87979 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87980 +
87981 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87982 + return gimple_get_lhs(assign);
87983 +}
87984 +
87985 +static void change_rhs1(gimple stmt, tree new_rhs1)
87986 +{
87987 + tree assign_rhs;
87988 + const_tree rhs = gimple_assign_rhs1(stmt);
87989 +
87990 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87991 + gimple_assign_set_rhs1(stmt, assign_rhs);
87992 + update_stmt(stmt);
87993 +}
87994 +
87995 +static bool check_mode_type(const_gimple stmt)
87996 +{
87997 + const_tree lhs = gimple_get_lhs(stmt);
87998 + const_tree lhs_type = TREE_TYPE(lhs);
87999 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88000 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88001 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88002 +
88003 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88004 + return false;
88005 +
88006 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88007 + return false;
88008 +
88009 + return true;
88010 +}
88011 +
88012 +static bool check_undefined_integer_operation(const_gimple stmt)
88013 +{
88014 + const_gimple def_stmt;
88015 + const_tree lhs = gimple_get_lhs(stmt);
88016 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88017 + const_tree rhs1_type = TREE_TYPE(rhs1);
88018 + const_tree lhs_type = TREE_TYPE(lhs);
88019 +
88020 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88021 + return false;
88022 +
88023 + def_stmt = get_def_stmt(rhs1);
88024 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88025 + return false;
88026 +
88027 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88028 + return false;
88029 + return true;
88030 +}
88031 +
88032 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88033 +{
88034 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88035 + enum machine_mode lhs_mode, rhs_mode;
88036 + gimple def_stmt = get_def_stmt(no_const_rhs);
88037 +
88038 + if (!gimple_assign_cast_p(def_stmt))
88039 + return false;
88040 +
88041 + rhs1 = gimple_assign_rhs1(def_stmt);
88042 + lhs = gimple_get_lhs(def_stmt);
88043 + rhs1_type = TREE_TYPE(rhs1);
88044 + lhs_type = TREE_TYPE(lhs);
88045 + rhs_mode = TYPE_MODE(rhs1_type);
88046 + lhs_mode = TYPE_MODE(lhs_type);
88047 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88048 + return false;
88049 +
88050 + return true;
88051 +}
88052 +
88053 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88054 +{
88055 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88056 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88057 + const_tree rhs1_type = TREE_TYPE(rhs1);
88058 + const_tree lhs_type = TREE_TYPE(lhs);
88059 +
88060 + new_rhs1 = expand(visited, rhs1);
88061 +
88062 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88063 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88064 +
88065 + if (gimple_plf(stmt, MY_STMT))
88066 + return lhs;
88067 +
88068 + if (gimple_plf(stmt, NO_CAST_CHECK))
88069 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88070 +
88071 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88072 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88073 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88074 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88075 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88076 + }
88077 +
88078 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88079 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88080 +
88081 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88082 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88083 +
88084 + change_rhs1(stmt, new_rhs1);
88085 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88086 +
88087 + rhs1 = gimple_assign_rhs1(stmt);
88088 + rhs1_type = TREE_TYPE(rhs1);
88089 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88090 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88091 +
88092 + if (!check_mode_type(stmt))
88093 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88094 +
88095 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88096 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88097 +
88098 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88099 +
88100 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88101 +}
88102 +
88103 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88104 +{
88105 + gimple def_stmt = get_def_stmt(lhs);
88106 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88107 +
88108 + if (is_gimple_constant(rhs1))
88109 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88110 +
88111 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88112 + switch (TREE_CODE(rhs1)) {
88113 + case SSA_NAME:
88114 + return handle_unary_rhs(visited, def_stmt);
88115 + case ARRAY_REF:
88116 + case BIT_FIELD_REF:
88117 + case ADDR_EXPR:
88118 + case COMPONENT_REF:
88119 + case INDIRECT_REF:
88120 +#if BUILDING_GCC_VERSION >= 4006
88121 + case MEM_REF:
88122 +#endif
88123 + case PARM_DECL:
88124 + case TARGET_MEM_REF:
88125 + case VAR_DECL:
88126 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88127 +
88128 + default:
88129 + debug_gimple_stmt(def_stmt);
88130 + debug_tree(rhs1);
88131 + gcc_unreachable();
88132 + }
88133 +}
88134 +
88135 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88136 +{
88137 + gimple cond_stmt;
88138 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88139 +
88140 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88141 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88142 + update_stmt(cond_stmt);
88143 +}
88144 +
88145 +static tree create_string_param(tree string)
88146 +{
88147 + tree i_type, a_type;
88148 + const int length = TREE_STRING_LENGTH(string);
88149 +
88150 + gcc_assert(length > 0);
88151 +
88152 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88153 + a_type = build_array_type(char_type_node, i_type);
88154 +
88155 + TREE_TYPE(string) = a_type;
88156 + TREE_CONSTANT(string) = 1;
88157 + TREE_READONLY(string) = 1;
88158 +
88159 + return build1(ADDR_EXPR, ptr_type_node, string);
88160 +}
88161 +
88162 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88163 +{
88164 + gimple func_stmt;
88165 + const_gimple def_stmt;
88166 + const_tree loc_line;
88167 + tree loc_file, ssa_name, current_func;
88168 + expanded_location xloc;
88169 + char ssa_name_buf[256];
88170 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88171 +
88172 + def_stmt = get_def_stmt(arg);
88173 + xloc = expand_location(gimple_location(def_stmt));
88174 +
88175 + if (!gimple_has_location(def_stmt)) {
88176 + xloc = expand_location(gimple_location(stmt));
88177 + if (!gimple_has_location(stmt))
88178 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88179 + }
88180 +
88181 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88182 +
88183 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88184 + loc_file = create_string_param(loc_file);
88185 +
88186 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88187 + current_func = create_string_param(current_func);
88188 +
88189 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88190 + ssa_name = build_string(256, ssa_name_buf);
88191 + ssa_name = create_string_param(ssa_name);
88192 +
88193 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88194 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88195 +
88196 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88197 +}
88198 +
88199 +static void __unused print_the_code_insertions(const_gimple stmt)
88200 +{
88201 + location_t loc = gimple_location(stmt);
88202 +
88203 + inform(loc, "Integer size_overflow check applied here.");
88204 +}
88205 +
88206 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88207 +{
88208 + basic_block cond_bb, join_bb, bb_true;
88209 + edge e;
88210 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88211 +
88212 + cond_bb = gimple_bb(stmt);
88213 + if (before)
88214 + gsi_prev(&gsi);
88215 + if (gsi_end_p(gsi))
88216 + e = split_block_after_labels(cond_bb);
88217 + else
88218 + e = split_block(cond_bb, gsi_stmt(gsi));
88219 + cond_bb = e->src;
88220 + join_bb = e->dest;
88221 + e->flags = EDGE_FALSE_VALUE;
88222 + e->probability = REG_BR_PROB_BASE;
88223 +
88224 + bb_true = create_empty_bb(cond_bb);
88225 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88226 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88227 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88228 +
88229 + if (dom_info_available_p(CDI_DOMINATORS)) {
88230 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88231 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88232 + }
88233 +
88234 + if (current_loops != NULL) {
88235 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88236 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88237 + }
88238 +
88239 + insert_cond(cond_bb, arg, cond_code, type_value);
88240 + insert_cond_result(bb_true, stmt, arg, min);
88241 +
88242 +// print_the_code_insertions(stmt);
88243 +}
88244 +
88245 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88246 +{
88247 + const_tree rhs_type = TREE_TYPE(rhs);
88248 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88249 +
88250 + gcc_assert(rhs_type != NULL_TREE);
88251 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88252 + return;
88253 +
88254 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88255 +
88256 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88257 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88258 +
88259 + gcc_assert(!TREE_OVERFLOW(type_max));
88260 +
88261 + cast_rhs_type = TREE_TYPE(cast_rhs);
88262 + type_max_type = TREE_TYPE(type_max);
88263 + type_min_type = TREE_TYPE(type_min);
88264 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88265 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88266 +
88267 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88268 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88269 +}
88270 +
88271 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88272 +{
88273 + gimple change_rhs_def_stmt;
88274 + tree lhs = gimple_get_lhs(def_stmt);
88275 + tree lhs_type = TREE_TYPE(lhs);
88276 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88277 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88278 +
88279 + if (change_rhs == NULL_TREE)
88280 + return get_size_overflow_type(def_stmt, lhs);
88281 +
88282 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88283 +
88284 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88285 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88286 +
88287 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88288 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88289 +
88290 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88291 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88292 +
88293 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88294 + debug_gimple_stmt(def_stmt);
88295 + gcc_unreachable();
88296 + }
88297 +
88298 + return get_size_overflow_type(def_stmt, lhs);
88299 +}
88300 +
88301 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88302 +{
88303 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88304 + return false;
88305 + if (!is_gimple_constant(rhs))
88306 + return false;
88307 + return true;
88308 +}
88309 +
88310 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88311 +{
88312 + gimple def_stmt;
88313 +
88314 + def_stmt = get_def_stmt(new_rhs);
88315 + // get_size_overflow_type
88316 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88317 + gcc_assert(gimple_assign_cast_p(def_stmt));
88318 + return gimple_assign_rhs1(def_stmt);
88319 +}
88320 +
88321 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88322 +{
88323 + gimple_stmt_iterator gsi;
88324 + const_gimple cast_stmt;
88325 + gimple def_stmt;
88326 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88327 +
88328 + if (mode != TImode && mode != DImode) {
88329 + def_stmt = get_def_stmt(new_rhs);
88330 + gcc_assert(gimple_assign_cast_p(def_stmt));
88331 + new_rhs = gimple_assign_rhs1(def_stmt);
88332 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88333 + }
88334 +
88335 + gcc_assert(mode == TImode || mode == DImode);
88336 +
88337 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88338 + return new_rhs;
88339 +
88340 + gsi = gsi_for_stmt(stmt);
88341 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88342 + new_rhs = gimple_get_lhs(cast_stmt);
88343 +
88344 + if (mode == DImode)
88345 + return new_rhs;
88346 +
88347 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88348 +
88349 + return new_rhs;
88350 +}
88351 +
88352 +static bool is_an_integer_trunction(const_gimple stmt)
88353 +{
88354 + gimple rhs1_def_stmt, rhs2_def_stmt;
88355 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88356 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88357 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88358 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88359 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88360 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88361 +
88362 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88363 + return false;
88364 +
88365 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88366 +
88367 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88368 + return false;
88369 +
88370 + rhs1_def_stmt = get_def_stmt(rhs1);
88371 + rhs2_def_stmt = get_def_stmt(rhs2);
88372 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88373 + return false;
88374 +
88375 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88376 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88377 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88378 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88379 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88380 + return false;
88381 +
88382 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88383 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88384 + return true;
88385 +}
88386 +
88387 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88388 +{
88389 + tree new_rhs1, new_rhs2;
88390 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88391 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88392 + gimple assign, stmt = get_def_stmt(lhs);
88393 + tree rhs1 = gimple_assign_rhs1(stmt);
88394 + tree rhs2 = gimple_assign_rhs2(stmt);
88395 +
88396 + if (!is_an_integer_trunction(stmt))
88397 + return NULL_TREE;
88398 +
88399 + new_rhs1 = expand(visited, rhs1);
88400 + new_rhs2 = expand(visited, rhs2);
88401 +
88402 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88403 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88404 +
88405 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88406 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88407 +
88408 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88409 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88410 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88411 + }
88412 +
88413 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88414 + new_lhs = gimple_get_lhs(assign);
88415 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88416 +
88417 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88418 +}
88419 +
88420 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88421 +{
88422 + const_gimple def_stmt;
88423 +
88424 + if (TREE_CODE(rhs) != SSA_NAME)
88425 + return false;
88426 +
88427 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88428 + return false;
88429 +
88430 + def_stmt = get_def_stmt(rhs);
88431 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88432 + return false;
88433 +
88434 + return true;
88435 +}
88436 +
88437 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88438 +{
88439 + tree new_rhs, size_overflow_type, orig_rhs;
88440 + void (*gimple_assign_set_rhs)(gimple, tree);
88441 + tree rhs1 = gimple_assign_rhs1(stmt);
88442 + tree rhs2 = gimple_assign_rhs2(stmt);
88443 + tree lhs = gimple_get_lhs(stmt);
88444 +
88445 + if (change_rhs == NULL_TREE)
88446 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88447 +
88448 + if (new_rhs2 == NULL_TREE) {
88449 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88450 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88451 + orig_rhs = rhs1;
88452 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88453 + } else {
88454 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88455 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88456 + orig_rhs = rhs2;
88457 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88458 + }
88459 +
88460 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88461 +
88462 + if (check_overflow)
88463 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88464 +
88465 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88466 + gimple_assign_set_rhs(stmt, new_rhs);
88467 + update_stmt(stmt);
88468 +
88469 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88470 +}
88471 +
88472 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88473 +{
88474 + tree rhs1, rhs2, new_lhs;
88475 + gimple def_stmt = get_def_stmt(lhs);
88476 + tree new_rhs1 = NULL_TREE;
88477 + tree new_rhs2 = NULL_TREE;
88478 +
88479 + rhs1 = gimple_assign_rhs1(def_stmt);
88480 + rhs2 = gimple_assign_rhs2(def_stmt);
88481 +
88482 + /* no DImode/TImode division in the 32/64 bit kernel */
88483 + switch (gimple_assign_rhs_code(def_stmt)) {
88484 + case RDIV_EXPR:
88485 + case TRUNC_DIV_EXPR:
88486 + case CEIL_DIV_EXPR:
88487 + case FLOOR_DIV_EXPR:
88488 + case ROUND_DIV_EXPR:
88489 + case TRUNC_MOD_EXPR:
88490 + case CEIL_MOD_EXPR:
88491 + case FLOOR_MOD_EXPR:
88492 + case ROUND_MOD_EXPR:
88493 + case EXACT_DIV_EXPR:
88494 + case POINTER_PLUS_EXPR:
88495 + case BIT_AND_EXPR:
88496 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88497 + default:
88498 + break;
88499 + }
88500 +
88501 + new_lhs = handle_integer_truncation(visited, lhs);
88502 + if (new_lhs != NULL_TREE)
88503 + return new_lhs;
88504 +
88505 + if (TREE_CODE(rhs1) == SSA_NAME)
88506 + new_rhs1 = expand(visited, rhs1);
88507 + if (TREE_CODE(rhs2) == SSA_NAME)
88508 + new_rhs2 = expand(visited, rhs2);
88509 +
88510 + if (is_a_neg_overflow(def_stmt, rhs2))
88511 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88512 + if (is_a_neg_overflow(def_stmt, rhs1))
88513 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88514 +
88515 + if (is_a_constant_overflow(def_stmt, rhs2))
88516 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88517 + if (is_a_constant_overflow(def_stmt, rhs1))
88518 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88519 +
88520 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88521 +}
88522 +
88523 +#if BUILDING_GCC_VERSION >= 4007
88524 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88525 +{
88526 + if (is_gimple_constant(rhs))
88527 + return cast_a_tree(size_overflow_type, rhs);
88528 + if (TREE_CODE(rhs) != SSA_NAME)
88529 + return NULL_TREE;
88530 + return expand(visited, rhs);
88531 +}
88532 +
88533 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88534 +{
88535 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88536 + gimple def_stmt = get_def_stmt(lhs);
88537 +
88538 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88539 +
88540 + rhs1 = gimple_assign_rhs1(def_stmt);
88541 + rhs2 = gimple_assign_rhs2(def_stmt);
88542 + rhs3 = gimple_assign_rhs3(def_stmt);
88543 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88544 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88545 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88546 +
88547 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88548 +}
88549 +#endif
88550 +
88551 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88552 +{
88553 + const_tree type;
88554 +
88555 + gcc_assert(node != NULL_TREE);
88556 +
88557 + type = TREE_TYPE(node);
88558 +
88559 + if (gimple_plf(stmt, MY_STMT))
88560 + return TREE_TYPE(node);
88561 +
88562 + switch (TYPE_MODE(type)) {
88563 + case QImode:
88564 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88565 + case HImode:
88566 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88567 + case SImode:
88568 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88569 + case DImode:
88570 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88571 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88572 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88573 + default:
88574 + debug_tree((tree)node);
88575 + error("%s: unsupported gcc configuration.", __func__);
88576 + gcc_unreachable();
88577 + }
88578 +}
88579 +
88580 +static tree expand_visited(gimple def_stmt)
88581 +{
88582 + const_gimple next_stmt;
88583 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88584 +
88585 + gsi_next(&gsi);
88586 + next_stmt = gsi_stmt(gsi);
88587 +
88588 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88589 +
88590 + switch (gimple_code(next_stmt)) {
88591 + case GIMPLE_ASSIGN:
88592 + return gimple_get_lhs(next_stmt);
88593 + case GIMPLE_PHI:
88594 + return gimple_phi_result(next_stmt);
88595 + case GIMPLE_CALL:
88596 + return gimple_call_lhs(next_stmt);
88597 + default:
88598 + return NULL_TREE;
88599 + }
88600 +}
88601 +
88602 +static tree expand(struct pointer_set_t *visited, tree lhs)
88603 +{
88604 + gimple def_stmt;
88605 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88606 +
88607 + if (is_gimple_constant(lhs))
88608 + return NULL_TREE;
88609 +
88610 + if (TREE_CODE(lhs) == ADDR_EXPR)
88611 + return NULL_TREE;
88612 +
88613 + if (code == REAL_TYPE)
88614 + return NULL_TREE;
88615 +
88616 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
88617 +
88618 +
88619 + def_stmt = get_def_stmt(lhs);
88620 +
88621 + if (!def_stmt)
88622 + return NULL_TREE;
88623 +
88624 + if (gimple_plf(def_stmt, MY_STMT))
88625 + return lhs;
88626 +
88627 + if (pointer_set_contains(visited, def_stmt))
88628 + return expand_visited(def_stmt);
88629 +
88630 + switch (gimple_code(def_stmt)) {
88631 + case GIMPLE_NOP:
88632 + return NULL_TREE;
88633 + case GIMPLE_PHI:
88634 + return build_new_phi(visited, lhs);
88635 + case GIMPLE_CALL:
88636 + case GIMPLE_ASM:
88637 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88638 + case GIMPLE_ASSIGN:
88639 + switch (gimple_num_ops(def_stmt)) {
88640 + case 2:
88641 + return handle_unary_ops(visited, lhs);
88642 + case 3:
88643 + return handle_binary_ops(visited, lhs);
88644 +#if BUILDING_GCC_VERSION >= 4007
88645 + case 4:
88646 + return handle_ternary_ops(visited, lhs);
88647 +#endif
88648 + }
88649 + default:
88650 + debug_gimple_stmt(def_stmt);
88651 + error("%s: unknown gimple code", __func__);
88652 + gcc_unreachable();
88653 + }
88654 +}
88655 +
88656 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
88657 +{
88658 + const_gimple assign;
88659 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88660 + tree origtype = TREE_TYPE(origarg);
88661 +
88662 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
88663 +
88664 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88665 +
88666 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
88667 + update_stmt(stmt);
88668 +}
88669 +
88670 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
88671 +{
88672 + const char *origid;
88673 + tree arg;
88674 + const_tree origarg;
88675 +
88676 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
88677 + return true;
88678 +
88679 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
88680 + while (origarg && *argnum) {
88681 + (*argnum)--;
88682 + origarg = TREE_CHAIN(origarg);
88683 + }
88684 +
88685 + gcc_assert(*argnum == 0);
88686 +
88687 + gcc_assert(origarg != NULL_TREE);
88688 + origid = NAME(origarg);
88689 + *argnum = 0;
88690 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
88691 + if (!strcmp(origid, NAME(arg)))
88692 + return true;
88693 + (*argnum)++;
88694 + }
88695 + return false;
88696 +}
88697 +
88698 +static bool skip_types(const_tree var)
88699 +{
88700 + switch (TREE_CODE(var)) {
88701 + case ADDR_EXPR:
88702 +#if BUILDING_GCC_VERSION >= 4006
88703 + case MEM_REF:
88704 +#endif
88705 + case ARRAY_REF:
88706 + case BIT_FIELD_REF:
88707 + case INDIRECT_REF:
88708 + case TARGET_MEM_REF:
88709 + case VAR_DECL:
88710 + return true;
88711 + default:
88712 + break;
88713 + }
88714 + return false;
88715 +}
88716 +
88717 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
88718 +{
88719 + gimple phi = get_def_stmt(result);
88720 + unsigned int i, n = gimple_phi_num_args(phi);
88721 +
88722 + if (!phi)
88723 + return false;
88724 +
88725 + pointer_set_insert(visited, phi);
88726 + for (i = 0; i < n; i++) {
88727 + const_tree arg = gimple_phi_arg_def(phi, i);
88728 + if (pre_expand(visited, arg))
88729 + return true;
88730 + }
88731 + return false;
88732 +}
88733 +
88734 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
88735 +{
88736 + gimple def_stmt = get_def_stmt(lhs);
88737 + const_tree rhs;
88738 +
88739 + if (!def_stmt)
88740 + return false;
88741 +
88742 + rhs = gimple_assign_rhs1(def_stmt);
88743 + if (pre_expand(visited, rhs))
88744 + return true;
88745 + return false;
88746 +}
88747 +
88748 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
88749 +{
88750 + bool rhs1_found, rhs2_found;
88751 + gimple def_stmt = get_def_stmt(lhs);
88752 + const_tree rhs1, rhs2;
88753 +
88754 + if (!def_stmt)
88755 + return false;
88756 +
88757 + rhs1 = gimple_assign_rhs1(def_stmt);
88758 + rhs2 = gimple_assign_rhs2(def_stmt);
88759 + rhs1_found = pre_expand(visited, rhs1);
88760 + rhs2_found = pre_expand(visited, rhs2);
88761 +
88762 + return rhs1_found || rhs2_found;
88763 +}
88764 +
88765 +static const_tree search_field_decl(const_tree comp_ref)
88766 +{
88767 + const_tree field = NULL_TREE;
88768 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
88769 +
88770 + for (i = 0; i < len; i++) {
88771 + field = TREE_OPERAND(comp_ref, i);
88772 + if (TREE_CODE(field) == FIELD_DECL)
88773 + break;
88774 + }
88775 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
88776 + return field;
88777 +}
88778 +
88779 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
88780 +{
88781 + const_tree attr, p;
88782 +
88783 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
88784 + if (!attr || !TREE_VALUE(attr))
88785 + return MARKED_NO;
88786 +
88787 + p = TREE_VALUE(attr);
88788 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
88789 + return MARKED_NOT_INTENTIONAL;
88790 +
88791 + do {
88792 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
88793 + return MARKED_YES;
88794 + p = TREE_CHAIN(p);
88795 + } while (p);
88796 +
88797 + return MARKED_NO;
88798 +}
88799 +
88800 +static void print_missing_msg(tree func, unsigned int argnum)
88801 +{
88802 + unsigned int new_hash;
88803 + size_t len;
88804 + unsigned char tree_codes[CODES_LIMIT];
88805 + location_t loc = DECL_SOURCE_LOCATION(func);
88806 + const char *curfunc = get_asm_name(func);
88807 +
88808 + len = get_function_decl(func, tree_codes);
88809 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
88810 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
88811 +}
88812 +
88813 +static unsigned int search_missing_attribute(const_tree arg)
88814 +{
88815 + const_tree type = TREE_TYPE(arg);
88816 + tree func = get_original_function_decl(current_function_decl);
88817 + unsigned int argnum;
88818 + const struct size_overflow_hash *hash;
88819 +
88820 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
88821 +
88822 + if (TREE_CODE(type) == POINTER_TYPE)
88823 + return 0;
88824 +
88825 + argnum = find_arg_number(arg, func);
88826 + if (argnum == 0)
88827 + return 0;
88828 +
88829 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
88830 + return argnum;
88831 +
88832 + hash = get_function_hash(func);
88833 + if (!hash || !(hash->param & (1U << argnum))) {
88834 + print_missing_msg(func, argnum);
88835 + return 0;
88836 + }
88837 + return argnum;
88838 +}
88839 +
88840 +static bool is_already_marked(const_tree lhs)
88841 +{
88842 + unsigned int argnum;
88843 + const_tree fndecl;
88844 +
88845 + argnum = search_missing_attribute(lhs);
88846 + fndecl = get_original_function_decl(current_function_decl);
88847 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
88848 + return true;
88849 + return false;
88850 +}
88851 +
88852 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
88853 +{
88854 + const_gimple def_stmt;
88855 +
88856 + if (is_gimple_constant(lhs))
88857 + return false;
88858 +
88859 + if (skip_types(lhs))
88860 + return false;
88861 +
88862 + if (TREE_CODE(lhs) == PARM_DECL)
88863 + return is_already_marked(lhs);
88864 +
88865 + if (TREE_CODE(lhs) == COMPONENT_REF) {
88866 + const_tree field, attr;
88867 +
88868 + field = search_field_decl(lhs);
88869 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
88870 + if (!attr || !TREE_VALUE(attr))
88871 + return false;
88872 + return true;
88873 + }
88874 +
88875 + def_stmt = get_def_stmt(lhs);
88876 +
88877 + if (!def_stmt)
88878 + return false;
88879 +
88880 + if (pointer_set_contains(visited, def_stmt))
88881 + return false;
88882 +
88883 + switch (gimple_code(def_stmt)) {
88884 + case GIMPLE_NOP:
88885 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
88886 + return is_already_marked(lhs);
88887 + return false;
88888 + case GIMPLE_PHI:
88889 + return walk_phi(visited, lhs);
88890 + case GIMPLE_CALL:
88891 + case GIMPLE_ASM:
88892 + return false;
88893 + case GIMPLE_ASSIGN:
88894 + switch (gimple_num_ops(def_stmt)) {
88895 + case 2:
88896 + return walk_unary_ops(visited, lhs);
88897 + case 3:
88898 + return walk_binary_ops(visited, lhs);
88899 + }
88900 + default:
88901 + debug_gimple_stmt((gimple)def_stmt);
88902 + error("%s: unknown gimple code", __func__);
88903 + gcc_unreachable();
88904 + }
88905 +}
88906 +
88907 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
88908 +{
88909 + struct pointer_set_t *visited;
88910 + bool is_found;
88911 + enum marked is_marked;
88912 + location_t loc;
88913 +
88914 + visited = pointer_set_create();
88915 + is_found = pre_expand(visited, arg);
88916 + pointer_set_destroy(visited);
88917 +
88918 + is_marked = mark_status(fndecl, argnum + 1);
88919 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
88920 + return true;
88921 +
88922 + if (is_found) {
88923 + loc = DECL_SOURCE_LOCATION(fndecl);
88924 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
88925 + return true;
88926 + }
88927 + return false;
88928 +}
88929 +
88930 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
88931 +{
88932 + struct pointer_set_t *visited;
88933 + tree arg, newarg;
88934 + bool match;
88935 +
88936 + match = get_function_arg(&argnum, fndecl);
88937 + if (!match)
88938 + return;
88939 + gcc_assert(gimple_call_num_args(stmt) > argnum);
88940 + arg = gimple_call_arg(stmt, argnum);
88941 + if (arg == NULL_TREE)
88942 + return;
88943 +
88944 + if (is_gimple_constant(arg))
88945 + return;
88946 +
88947 + if (search_attributes(fndecl, arg, argnum))
88948 + return;
88949 +
88950 + if (TREE_CODE(arg) != SSA_NAME)
88951 + return;
88952 +
88953 + check_arg_type(arg);
88954 +
88955 + visited = pointer_set_create();
88956 + newarg = expand(visited, arg);
88957 + pointer_set_destroy(visited);
88958 +
88959 + if (newarg == NULL_TREE)
88960 + return;
88961 +
88962 + change_function_arg(stmt, arg, argnum, newarg);
88963 +
88964 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
88965 +}
88966 +
88967 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
88968 +{
88969 + tree p = TREE_VALUE(attr);
88970 + do {
88971 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
88972 + p = TREE_CHAIN(p);
88973 + } while (p);
88974 +}
88975 +
88976 +static void handle_function_by_hash(gimple stmt, tree fndecl)
88977 +{
88978 + tree orig_fndecl;
88979 + unsigned int num;
88980 + const struct size_overflow_hash *hash;
88981 +
88982 + orig_fndecl = get_original_function_decl(fndecl);
88983 + if (C_DECL_IMPLICIT(orig_fndecl))
88984 + return;
88985 + hash = get_function_hash(orig_fndecl);
88986 + if (!hash)
88987 + return;
88988 +
88989 + for (num = 1; num <= MAX_PARAM; num++)
88990 + if (hash->param & (1U << num))
88991 + handle_function_arg(stmt, fndecl, num - 1);
88992 +}
88993 +
88994 +static void set_plf_false(void)
88995 +{
88996 + basic_block bb;
88997 +
88998 + FOR_ALL_BB(bb) {
88999 + gimple_stmt_iterator si;
89000 +
89001 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89002 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89003 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89004 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89005 + }
89006 +}
89007 +
89008 +static unsigned int handle_function(void)
89009 +{
89010 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89011 +
89012 + set_plf_false();
89013 +
89014 + do {
89015 + gimple_stmt_iterator gsi;
89016 + next = bb->next_bb;
89017 +
89018 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89019 + tree fndecl, attr;
89020 + gimple stmt = gsi_stmt(gsi);
89021 +
89022 + if (!(is_gimple_call(stmt)))
89023 + continue;
89024 + fndecl = gimple_call_fndecl(stmt);
89025 + if (fndecl == NULL_TREE)
89026 + continue;
89027 + if (gimple_call_num_args(stmt) == 0)
89028 + continue;
89029 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89030 + if (!attr || !TREE_VALUE(attr))
89031 + handle_function_by_hash(stmt, fndecl);
89032 + else
89033 + handle_function_by_attribute(stmt, attr, fndecl);
89034 + gsi = gsi_for_stmt(stmt);
89035 + next = gimple_bb(stmt)->next_bb;
89036 + }
89037 + bb = next;
89038 + } while (bb);
89039 + return 0;
89040 +}
89041 +
89042 +static struct gimple_opt_pass size_overflow_pass = {
89043 + .pass = {
89044 + .type = GIMPLE_PASS,
89045 + .name = "size_overflow",
89046 + .gate = NULL,
89047 + .execute = handle_function,
89048 + .sub = NULL,
89049 + .next = NULL,
89050 + .static_pass_number = 0,
89051 + .tv_id = TV_NONE,
89052 + .properties_required = PROP_cfg | PROP_referenced_vars,
89053 + .properties_provided = 0,
89054 + .properties_destroyed = 0,
89055 + .todo_flags_start = 0,
89056 + .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
89057 + }
89058 +};
89059 +
89060 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89061 +{
89062 + tree fntype;
89063 +
89064 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89065 +
89066 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89067 + fntype = build_function_type_list(void_type_node,
89068 + const_char_ptr_type_node,
89069 + unsigned_type_node,
89070 + const_char_ptr_type_node,
89071 + const_char_ptr_type_node,
89072 + NULL_TREE);
89073 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89074 +
89075 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89076 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89077 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89078 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89079 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89080 +}
89081 +
89082 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89083 +{
89084 + int i;
89085 + const char * const plugin_name = plugin_info->base_name;
89086 + const int argc = plugin_info->argc;
89087 + const struct plugin_argument * const argv = plugin_info->argv;
89088 + bool enable = true;
89089 +
89090 + struct register_pass_info size_overflow_pass_info = {
89091 + .pass = &size_overflow_pass.pass,
89092 + .reference_pass_name = "ssa",
89093 + .ref_pass_instance_number = 1,
89094 + .pos_op = PASS_POS_INSERT_AFTER
89095 + };
89096 +
89097 + if (!plugin_default_version_check(version, &gcc_version)) {
89098 + error(G_("incompatible gcc/plugin versions"));
89099 + return 1;
89100 + }
89101 +
89102 + for (i = 0; i < argc; ++i) {
89103 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89104 + enable = false;
89105 + continue;
89106 + }
89107 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89108 + }
89109 +
89110 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89111 + if (enable) {
89112 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89113 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89114 + }
89115 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89116 +
89117 + return 0;
89118 +}
89119 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89120 new file mode 100644
89121 index 0000000..38d2014
89122 --- /dev/null
89123 +++ b/tools/gcc/stackleak_plugin.c
89124 @@ -0,0 +1,313 @@
89125 +/*
89126 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89127 + * Licensed under the GPL v2
89128 + *
89129 + * Note: the choice of the license means that the compilation process is
89130 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89131 + * but for the kernel it doesn't matter since it doesn't link against
89132 + * any of the gcc libraries
89133 + *
89134 + * gcc plugin to help implement various PaX features
89135 + *
89136 + * - track lowest stack pointer
89137 + *
89138 + * TODO:
89139 + * - initialize all local variables
89140 + *
89141 + * BUGS:
89142 + * - none known
89143 + */
89144 +#include "gcc-plugin.h"
89145 +#include "config.h"
89146 +#include "system.h"
89147 +#include "coretypes.h"
89148 +#include "tree.h"
89149 +#include "tree-pass.h"
89150 +#include "flags.h"
89151 +#include "intl.h"
89152 +#include "toplev.h"
89153 +#include "plugin.h"
89154 +//#include "expr.h" where are you...
89155 +#include "diagnostic.h"
89156 +#include "plugin-version.h"
89157 +#include "tm.h"
89158 +#include "function.h"
89159 +#include "basic-block.h"
89160 +#include "gimple.h"
89161 +#include "rtl.h"
89162 +#include "emit-rtl.h"
89163 +
89164 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89165 +
89166 +int plugin_is_GPL_compatible;
89167 +
89168 +static int track_frame_size = -1;
89169 +static const char track_function[] = "pax_track_stack";
89170 +static const char check_function[] = "pax_check_alloca";
89171 +static bool init_locals;
89172 +
89173 +static struct plugin_info stackleak_plugin_info = {
89174 + .version = "201203140940",
89175 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89176 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89177 +};
89178 +
89179 +static bool gate_stackleak_track_stack(void);
89180 +static unsigned int execute_stackleak_tree_instrument(void);
89181 +static unsigned int execute_stackleak_final(void);
89182 +
89183 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89184 + .pass = {
89185 + .type = GIMPLE_PASS,
89186 + .name = "stackleak_tree_instrument",
89187 + .gate = gate_stackleak_track_stack,
89188 + .execute = execute_stackleak_tree_instrument,
89189 + .sub = NULL,
89190 + .next = NULL,
89191 + .static_pass_number = 0,
89192 + .tv_id = TV_NONE,
89193 + .properties_required = PROP_gimple_leh | PROP_cfg,
89194 + .properties_provided = 0,
89195 + .properties_destroyed = 0,
89196 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89197 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89198 + }
89199 +};
89200 +
89201 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89202 + .pass = {
89203 + .type = RTL_PASS,
89204 + .name = "stackleak_final",
89205 + .gate = gate_stackleak_track_stack,
89206 + .execute = execute_stackleak_final,
89207 + .sub = NULL,
89208 + .next = NULL,
89209 + .static_pass_number = 0,
89210 + .tv_id = TV_NONE,
89211 + .properties_required = 0,
89212 + .properties_provided = 0,
89213 + .properties_destroyed = 0,
89214 + .todo_flags_start = 0,
89215 + .todo_flags_finish = TODO_dump_func
89216 + }
89217 +};
89218 +
89219 +static bool gate_stackleak_track_stack(void)
89220 +{
89221 + return track_frame_size >= 0;
89222 +}
89223 +
89224 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89225 +{
89226 + gimple check_alloca;
89227 + tree fntype, fndecl, alloca_size;
89228 +
89229 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89230 + fndecl = build_fn_decl(check_function, fntype);
89231 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89232 +
89233 + // insert call to void pax_check_alloca(unsigned long size)
89234 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89235 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89236 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89237 +}
89238 +
89239 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89240 +{
89241 + gimple track_stack;
89242 + tree fntype, fndecl;
89243 +
89244 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89245 + fndecl = build_fn_decl(track_function, fntype);
89246 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89247 +
89248 + // insert call to void pax_track_stack(void)
89249 + track_stack = gimple_build_call(fndecl, 0);
89250 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89251 +}
89252 +
89253 +#if BUILDING_GCC_VERSION == 4005
89254 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89255 +{
89256 + tree fndecl;
89257 +
89258 + if (!is_gimple_call(stmt))
89259 + return false;
89260 + fndecl = gimple_call_fndecl(stmt);
89261 + if (!fndecl)
89262 + return false;
89263 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89264 + return false;
89265 +// print_node(stderr, "pax", fndecl, 4);
89266 + return DECL_FUNCTION_CODE(fndecl) == code;
89267 +}
89268 +#endif
89269 +
89270 +static bool is_alloca(gimple stmt)
89271 +{
89272 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89273 + return true;
89274 +
89275 +#if BUILDING_GCC_VERSION >= 4007
89276 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89277 + return true;
89278 +#endif
89279 +
89280 + return false;
89281 +}
89282 +
89283 +static unsigned int execute_stackleak_tree_instrument(void)
89284 +{
89285 + basic_block bb, entry_bb;
89286 + bool prologue_instrumented = false, is_leaf = true;
89287 +
89288 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89289 +
89290 + // 1. loop through BBs and GIMPLE statements
89291 + FOR_EACH_BB(bb) {
89292 + gimple_stmt_iterator gsi;
89293 +
89294 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89295 + gimple stmt;
89296 +
89297 + stmt = gsi_stmt(gsi);
89298 +
89299 + if (is_gimple_call(stmt))
89300 + is_leaf = false;
89301 +
89302 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89303 + if (!is_alloca(stmt))
89304 + continue;
89305 +
89306 + // 2. insert stack overflow check before each __builtin_alloca call
89307 + stackleak_check_alloca(&gsi);
89308 +
89309 + // 3. insert track call after each __builtin_alloca call
89310 + stackleak_add_instrumentation(&gsi);
89311 + if (bb == entry_bb)
89312 + prologue_instrumented = true;
89313 + }
89314 + }
89315 +
89316 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89317 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89318 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89319 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89320 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89321 + return 0;
89322 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89323 + return 0;
89324 +
89325 + // 4. insert track call at the beginning
89326 + if (!prologue_instrumented) {
89327 + gimple_stmt_iterator gsi;
89328 +
89329 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89330 + if (dom_info_available_p(CDI_DOMINATORS))
89331 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89332 + gsi = gsi_start_bb(bb);
89333 + stackleak_add_instrumentation(&gsi);
89334 + }
89335 +
89336 + return 0;
89337 +}
89338 +
89339 +static unsigned int execute_stackleak_final(void)
89340 +{
89341 + rtx insn;
89342 +
89343 + if (cfun->calls_alloca)
89344 + return 0;
89345 +
89346 + // keep calls only if function frame is big enough
89347 + if (get_frame_size() >= track_frame_size)
89348 + return 0;
89349 +
89350 + // 1. find pax_track_stack calls
89351 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89352 + // 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))
89353 + rtx body;
89354 +
89355 + if (!CALL_P(insn))
89356 + continue;
89357 + body = PATTERN(insn);
89358 + if (GET_CODE(body) != CALL)
89359 + continue;
89360 + body = XEXP(body, 0);
89361 + if (GET_CODE(body) != MEM)
89362 + continue;
89363 + body = XEXP(body, 0);
89364 + if (GET_CODE(body) != SYMBOL_REF)
89365 + continue;
89366 + if (strcmp(XSTR(body, 0), track_function))
89367 + continue;
89368 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89369 + // 2. delete call
89370 + insn = delete_insn_and_edges(insn);
89371 +#if BUILDING_GCC_VERSION >= 4007
89372 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89373 + insn = delete_insn_and_edges(insn);
89374 +#endif
89375 + }
89376 +
89377 +// print_simple_rtl(stderr, get_insns());
89378 +// print_rtl(stderr, get_insns());
89379 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89380 +
89381 + return 0;
89382 +}
89383 +
89384 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89385 +{
89386 + const char * const plugin_name = plugin_info->base_name;
89387 + const int argc = plugin_info->argc;
89388 + const struct plugin_argument * const argv = plugin_info->argv;
89389 + int i;
89390 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89391 + .pass = &stackleak_tree_instrument_pass.pass,
89392 +// .reference_pass_name = "tree_profile",
89393 + .reference_pass_name = "optimized",
89394 + .ref_pass_instance_number = 1,
89395 + .pos_op = PASS_POS_INSERT_BEFORE
89396 + };
89397 + struct register_pass_info stackleak_final_pass_info = {
89398 + .pass = &stackleak_final_rtl_opt_pass.pass,
89399 + .reference_pass_name = "final",
89400 + .ref_pass_instance_number = 1,
89401 + .pos_op = PASS_POS_INSERT_BEFORE
89402 + };
89403 +
89404 + if (!plugin_default_version_check(version, &gcc_version)) {
89405 + error(G_("incompatible gcc/plugin versions"));
89406 + return 1;
89407 + }
89408 +
89409 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89410 +
89411 + for (i = 0; i < argc; ++i) {
89412 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89413 + if (!argv[i].value) {
89414 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89415 + continue;
89416 + }
89417 + track_frame_size = atoi(argv[i].value);
89418 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89419 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89420 + continue;
89421 + }
89422 + if (!strcmp(argv[i].key, "initialize-locals")) {
89423 + if (argv[i].value) {
89424 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89425 + continue;
89426 + }
89427 + init_locals = true;
89428 + continue;
89429 + }
89430 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89431 + }
89432 +
89433 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89434 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89435 +
89436 + return 0;
89437 +}
89438 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89439 index 6789d78..4afd019e 100644
89440 --- a/tools/perf/util/include/asm/alternative-asm.h
89441 +++ b/tools/perf/util/include/asm/alternative-asm.h
89442 @@ -5,4 +5,7 @@
89443
89444 #define altinstruction_entry #
89445
89446 + .macro pax_force_retaddr rip=0, reload=0
89447 + .endm
89448 +
89449 #endif
89450 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
89451 index af0f22f..9a7d479 100644
89452 --- a/usr/gen_init_cpio.c
89453 +++ b/usr/gen_init_cpio.c
89454 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
89455 int retval;
89456 int rc = -1;
89457 int namesize;
89458 - int i;
89459 + unsigned int i;
89460
89461 mode |= S_IFREG;
89462
89463 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
89464 *env_var = *expanded = '\0';
89465 strncat(env_var, start + 2, end - start - 2);
89466 strncat(expanded, new_location, start - new_location);
89467 - strncat(expanded, getenv(env_var), PATH_MAX);
89468 - strncat(expanded, end + 1, PATH_MAX);
89469 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
89470 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
89471 strncpy(new_location, expanded, PATH_MAX);
89472 + new_location[PATH_MAX] = 0;
89473 } else
89474 break;
89475 }
89476 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89477 index d617f69..6b445d2 100644
89478 --- a/virt/kvm/kvm_main.c
89479 +++ b/virt/kvm/kvm_main.c
89480 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89481
89482 static cpumask_var_t cpus_hardware_enabled;
89483 static int kvm_usage_count = 0;
89484 -static atomic_t hardware_enable_failed;
89485 +static atomic_unchecked_t hardware_enable_failed;
89486
89487 struct kmem_cache *kvm_vcpu_cache;
89488 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89489 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89490 /* We can read the guest memory with __xxx_user() later on. */
89491 if (user_alloc &&
89492 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89493 - !access_ok(VERIFY_WRITE,
89494 + !__access_ok(VERIFY_WRITE,
89495 (void __user *)(unsigned long)mem->userspace_addr,
89496 mem->memory_size)))
89497 goto out;
89498 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89499
89500 if (r) {
89501 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89502 - atomic_inc(&hardware_enable_failed);
89503 + atomic_inc_unchecked(&hardware_enable_failed);
89504 printk(KERN_INFO "kvm: enabling virtualization on "
89505 "CPU%d failed\n", cpu);
89506 }
89507 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89508
89509 kvm_usage_count++;
89510 if (kvm_usage_count == 1) {
89511 - atomic_set(&hardware_enable_failed, 0);
89512 + atomic_set_unchecked(&hardware_enable_failed, 0);
89513 on_each_cpu(hardware_enable_nolock, NULL, 1);
89514
89515 - if (atomic_read(&hardware_enable_failed)) {
89516 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89517 hardware_disable_all_nolock();
89518 r = -EBUSY;
89519 }
89520 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89521 kvm_arch_vcpu_put(vcpu);
89522 }
89523
89524 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89525 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89526 struct module *module)
89527 {
89528 int r;
89529 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89530 if (!vcpu_align)
89531 vcpu_align = __alignof__(struct kvm_vcpu);
89532 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89533 - 0, NULL);
89534 + SLAB_USERCOPY, NULL);
89535 if (!kvm_vcpu_cache) {
89536 r = -ENOMEM;
89537 goto out_free_3;
89538 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89539 if (r)
89540 goto out_free;
89541
89542 - kvm_chardev_ops.owner = module;
89543 - kvm_vm_fops.owner = module;
89544 - kvm_vcpu_fops.owner = module;
89545 + pax_open_kernel();
89546 + *(void **)&kvm_chardev_ops.owner = module;
89547 + *(void **)&kvm_vm_fops.owner = module;
89548 + *(void **)&kvm_vcpu_fops.owner = module;
89549 + pax_close_kernel();
89550
89551 r = misc_register(&kvm_dev);
89552 if (r) {