]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.7-201211181105.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.7-201211181105.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 39462cf..611a556 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125 -linux
126 +lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130 @@ -163,14 +181,15 @@ machtypes.h
131 map
132 map_hugetlb
133 maui_boot.h
134 -media
135 mconf
136 +mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143 +mkpiggy
144 mkprep
145 mkregtable
146 mktables
147 @@ -187,6 +206,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151 +parse-events*
152 +pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156 @@ -196,6 +217,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -205,7 +227,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168 +realmode.lds
169 +realmode.relocs
170 recordmcount
171 +regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175 @@ -215,8 +240,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +size_overflow_hash.h
180 sImage
181 +slabinfo
182 sm_tbl*
183 +sortextable
184 split-include
185 syscalltab.h
186 tables.c
187 @@ -226,6 +254,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191 +user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195 @@ -237,13 +266,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199 +vdsox32.lds
200 +vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207 +vmlinux.bin.bz2
208 vmlinux.lds
209 +vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213 @@ -251,9 +284,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217 +utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223 +zconf.lex.c
224 zoffset.h
225 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226 index ad7e2e5..199f49e 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239 @@ -2050,6 +2053,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244 + virtualization environments that don't cope well with the
245 + expand down segment used by UDEREF on X86-32 or the frequent
246 + page table updates on X86-64.
247 +
248 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249 +
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253 diff --git a/Makefile b/Makefile
254 index 07f2308..7271d99 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index ecf9019..b71d9a1 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 77bd79f..ad4cd27 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 693b744..e684262 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1853 index 37afbd1..c22ad7c 100644
1854 --- a/arch/arm/mach-omap2/omap_hwmod.c
1855 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1856 @@ -187,10 +187,10 @@ struct omap_hwmod_soc_ops {
1857 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1858 struct omap_hwmod_rst_info *ohri);
1859 int (*init_clkdm)(struct omap_hwmod *oh);
1860 -};
1861 +} __no_const;
1862
1863 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1864 -static struct omap_hwmod_soc_ops soc_ops;
1865 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1866
1867 /* omap_hwmod_list contains all registered struct omap_hwmods */
1868 static LIST_HEAD(omap_hwmod_list);
1869 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1870 index c3bd834..e81ef02 100644
1871 --- a/arch/arm/mm/fault.c
1872 +++ b/arch/arm/mm/fault.c
1873 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1874 }
1875 #endif
1876
1877 +#ifdef CONFIG_PAX_PAGEEXEC
1878 + if (fsr & FSR_LNX_PF) {
1879 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1880 + do_group_exit(SIGKILL);
1881 + }
1882 +#endif
1883 +
1884 tsk->thread.address = addr;
1885 tsk->thread.error_code = fsr;
1886 tsk->thread.trap_no = 14;
1887 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1888 }
1889 #endif /* CONFIG_MMU */
1890
1891 +#ifdef CONFIG_PAX_PAGEEXEC
1892 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1893 +{
1894 + long i;
1895 +
1896 + printk(KERN_ERR "PAX: bytes at PC: ");
1897 + for (i = 0; i < 20; i++) {
1898 + unsigned char c;
1899 + if (get_user(c, (__force unsigned char __user *)pc+i))
1900 + printk(KERN_CONT "?? ");
1901 + else
1902 + printk(KERN_CONT "%02x ", c);
1903 + }
1904 + printk("\n");
1905 +
1906 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1907 + for (i = -1; i < 20; i++) {
1908 + unsigned long c;
1909 + if (get_user(c, (__force unsigned long __user *)sp+i))
1910 + printk(KERN_CONT "???????? ");
1911 + else
1912 + printk(KERN_CONT "%08lx ", c);
1913 + }
1914 + printk("\n");
1915 +}
1916 +#endif
1917 +
1918 /*
1919 * First Level Translation Fault Handler
1920 *
1921 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1923 struct siginfo info;
1924
1925 +#ifdef CONFIG_PAX_REFCOUNT
1926 + if (fsr_fs(ifsr) == 2) {
1927 + unsigned int bkpt;
1928 +
1929 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1930 + current->thread.error_code = ifsr;
1931 + current->thread.trap_no = 0;
1932 + pax_report_refcount_overflow(regs);
1933 + fixup_exception(regs);
1934 + return;
1935 + }
1936 + }
1937 +#endif
1938 +
1939 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1940 return;
1941
1942 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1943 index ce8cb19..3ec539d 100644
1944 --- a/arch/arm/mm/mmap.c
1945 +++ b/arch/arm/mm/mmap.c
1946 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1947 if (len > TASK_SIZE)
1948 return -ENOMEM;
1949
1950 +#ifdef CONFIG_PAX_RANDMMAP
1951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1952 +#endif
1953 +
1954 if (addr) {
1955 if (do_align)
1956 addr = COLOUR_ALIGN(addr, pgoff);
1957 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1958 addr = PAGE_ALIGN(addr);
1959
1960 vma = find_vma(mm, addr);
1961 - if (TASK_SIZE - len >= addr &&
1962 - (!vma || addr + len <= vma->vm_start))
1963 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1964 return addr;
1965 }
1966 if (len > mm->cached_hole_size) {
1967 - start_addr = addr = mm->free_area_cache;
1968 + start_addr = addr = mm->free_area_cache;
1969 } else {
1970 - start_addr = addr = mm->mmap_base;
1971 - mm->cached_hole_size = 0;
1972 + start_addr = addr = mm->mmap_base;
1973 + mm->cached_hole_size = 0;
1974 }
1975
1976 full_search:
1977 @@ -124,14 +127,14 @@ full_search:
1978 * Start a new search - just in case we missed
1979 * some holes.
1980 */
1981 - if (start_addr != TASK_UNMAPPED_BASE) {
1982 - start_addr = addr = TASK_UNMAPPED_BASE;
1983 + if (start_addr != mm->mmap_base) {
1984 + start_addr = addr = mm->mmap_base;
1985 mm->cached_hole_size = 0;
1986 goto full_search;
1987 }
1988 return -ENOMEM;
1989 }
1990 - if (!vma || addr + len <= vma->vm_start) {
1991 + if (check_heap_stack_gap(vma, addr, len)) {
1992 /*
1993 * Remember the place where we stopped the search:
1994 */
1995 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1996
1997 if (mmap_is_legacy()) {
1998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1999 +
2000 +#ifdef CONFIG_PAX_RANDMMAP
2001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2002 + mm->mmap_base += mm->delta_mmap;
2003 +#endif
2004 +
2005 mm->get_unmapped_area = arch_get_unmapped_area;
2006 mm->unmap_area = arch_unmap_area;
2007 } else {
2008 mm->mmap_base = mmap_base(random_factor);
2009 +
2010 +#ifdef CONFIG_PAX_RANDMMAP
2011 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2012 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2013 +#endif
2014 +
2015 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2016 mm->unmap_area = arch_unmap_area_topdown;
2017 }
2018 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2019 index fd556f7..af2e7d2 100644
2020 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2021 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2022 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2023 value in bridge_virt_base */
2024 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2025 const int win);
2026 -};
2027 +} __no_const;
2028
2029 /*
2030 * Information needed to setup one address mapping.
2031 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2032 index f5144cd..71f6d1f 100644
2033 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2035 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2036 int (*started)(unsigned ch);
2037 int (*flush)(unsigned ch);
2038 int (*stop)(unsigned ch);
2039 -};
2040 +} __no_const;
2041
2042 extern void *samsung_dmadev_get_ops(void);
2043 extern void *s3c_dma_get_ops(void);
2044 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2045 index 5f28cae..3d23723 100644
2046 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2047 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2048 @@ -14,7 +14,7 @@
2049 struct s5p_ehci_platdata {
2050 int (*phy_init)(struct platform_device *pdev, int type);
2051 int (*phy_exit)(struct platform_device *pdev, int type);
2052 -};
2053 +} __no_const;
2054
2055 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2056
2057 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2058 index c3a58a1..78fbf54 100644
2059 --- a/arch/avr32/include/asm/cache.h
2060 +++ b/arch/avr32/include/asm/cache.h
2061 @@ -1,8 +1,10 @@
2062 #ifndef __ASM_AVR32_CACHE_H
2063 #define __ASM_AVR32_CACHE_H
2064
2065 +#include <linux/const.h>
2066 +
2067 #define L1_CACHE_SHIFT 5
2068 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2069 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2070
2071 /*
2072 * Memory returned by kmalloc() may be used for DMA, so we must make
2073 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2074 index 3b3159b..425ea94 100644
2075 --- a/arch/avr32/include/asm/elf.h
2076 +++ b/arch/avr32/include/asm/elf.h
2077 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2078 the loader. We need to make sure that it is out of the way of the program
2079 that it will "exec", and that there is sufficient room for the brk. */
2080
2081 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2082 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2083
2084 +#ifdef CONFIG_PAX_ASLR
2085 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2086 +
2087 +#define PAX_DELTA_MMAP_LEN 15
2088 +#define PAX_DELTA_STACK_LEN 15
2089 +#endif
2090
2091 /* This yields a mask that user programs can use to figure out what
2092 instruction set this CPU supports. This could be done in user space,
2093 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2094 index 479330b..53717a8 100644
2095 --- a/arch/avr32/include/asm/kmap_types.h
2096 +++ b/arch/avr32/include/asm/kmap_types.h
2097 @@ -2,9 +2,9 @@
2098 #define __ASM_AVR32_KMAP_TYPES_H
2099
2100 #ifdef CONFIG_DEBUG_HIGHMEM
2101 -# define KM_TYPE_NR 29
2102 +# define KM_TYPE_NR 30
2103 #else
2104 -# define KM_TYPE_NR 14
2105 +# define KM_TYPE_NR 15
2106 #endif
2107
2108 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2109 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2110 index b92e609..b69c101 100644
2111 --- a/arch/avr32/mm/fault.c
2112 +++ b/arch/avr32/mm/fault.c
2113 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2114
2115 int exception_trace = 1;
2116
2117 +#ifdef CONFIG_PAX_PAGEEXEC
2118 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2119 +{
2120 + unsigned long i;
2121 +
2122 + printk(KERN_ERR "PAX: bytes at PC: ");
2123 + for (i = 0; i < 20; i++) {
2124 + unsigned char c;
2125 + if (get_user(c, (unsigned char *)pc+i))
2126 + printk(KERN_CONT "???????? ");
2127 + else
2128 + printk(KERN_CONT "%02x ", c);
2129 + }
2130 + printk("\n");
2131 +}
2132 +#endif
2133 +
2134 /*
2135 * This routine handles page faults. It determines the address and the
2136 * problem, and then passes it off to one of the appropriate routines.
2137 @@ -173,6 +190,16 @@ bad_area:
2138 up_read(&mm->mmap_sem);
2139
2140 if (user_mode(regs)) {
2141 +
2142 +#ifdef CONFIG_PAX_PAGEEXEC
2143 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2144 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2145 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2146 + do_group_exit(SIGKILL);
2147 + }
2148 + }
2149 +#endif
2150 +
2151 if (exception_trace && printk_ratelimit())
2152 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2153 "sp %08lx ecr %lu\n",
2154 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2155 index 568885a..f8008df 100644
2156 --- a/arch/blackfin/include/asm/cache.h
2157 +++ b/arch/blackfin/include/asm/cache.h
2158 @@ -7,6 +7,7 @@
2159 #ifndef __ARCH_BLACKFIN_CACHE_H
2160 #define __ARCH_BLACKFIN_CACHE_H
2161
2162 +#include <linux/const.h>
2163 #include <linux/linkage.h> /* for asmlinkage */
2164
2165 /*
2166 @@ -14,7 +15,7 @@
2167 * Blackfin loads 32 bytes for cache
2168 */
2169 #define L1_CACHE_SHIFT 5
2170 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2171 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2173
2174 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2175 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2176 index aea2718..3639a60 100644
2177 --- a/arch/cris/include/arch-v10/arch/cache.h
2178 +++ b/arch/cris/include/arch-v10/arch/cache.h
2179 @@ -1,8 +1,9 @@
2180 #ifndef _ASM_ARCH_CACHE_H
2181 #define _ASM_ARCH_CACHE_H
2182
2183 +#include <linux/const.h>
2184 /* Etrax 100LX have 32-byte cache-lines. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #endif /* _ASM_ARCH_CACHE_H */
2190 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2191 index 7caf25d..ee65ac5 100644
2192 --- a/arch/cris/include/arch-v32/arch/cache.h
2193 +++ b/arch/cris/include/arch-v32/arch/cache.h
2194 @@ -1,11 +1,12 @@
2195 #ifndef _ASM_CRIS_ARCH_CACHE_H
2196 #define _ASM_CRIS_ARCH_CACHE_H
2197
2198 +#include <linux/const.h>
2199 #include <arch/hwregs/dma.h>
2200
2201 /* A cache-line is 32 bytes. */
2202 -#define L1_CACHE_BYTES 32
2203 #define L1_CACHE_SHIFT 5
2204 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2205
2206 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2207
2208 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2209 index b86329d..6709906 100644
2210 --- a/arch/frv/include/asm/atomic.h
2211 +++ b/arch/frv/include/asm/atomic.h
2212 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2213 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2214 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2215
2216 +#define atomic64_read_unchecked(v) atomic64_read(v)
2217 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2218 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2219 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2220 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2221 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2222 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2223 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2224 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2225 +
2226 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2227 {
2228 int c, old;
2229 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2230 index 2797163..c2a401d 100644
2231 --- a/arch/frv/include/asm/cache.h
2232 +++ b/arch/frv/include/asm/cache.h
2233 @@ -12,10 +12,11 @@
2234 #ifndef __ASM_CACHE_H
2235 #define __ASM_CACHE_H
2236
2237 +#include <linux/const.h>
2238
2239 /* bytes per L1 cache line */
2240 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2241 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2242 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2243
2244 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2245 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2246 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2247 index 43901f2..0d8b865 100644
2248 --- a/arch/frv/include/asm/kmap_types.h
2249 +++ b/arch/frv/include/asm/kmap_types.h
2250 @@ -2,6 +2,6 @@
2251 #ifndef _ASM_KMAP_TYPES_H
2252 #define _ASM_KMAP_TYPES_H
2253
2254 -#define KM_TYPE_NR 17
2255 +#define KM_TYPE_NR 18
2256
2257 #endif
2258 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2259 index 385fd30..6c3d97e 100644
2260 --- a/arch/frv/mm/elf-fdpic.c
2261 +++ b/arch/frv/mm/elf-fdpic.c
2262 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 if (addr) {
2264 addr = PAGE_ALIGN(addr);
2265 vma = find_vma(current->mm, addr);
2266 - if (TASK_SIZE - len >= addr &&
2267 - (!vma || addr + len <= vma->vm_start))
2268 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2269 goto success;
2270 }
2271
2272 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2273 for (; vma; vma = vma->vm_next) {
2274 if (addr > limit)
2275 break;
2276 - if (addr + len <= vma->vm_start)
2277 + if (check_heap_stack_gap(vma, addr, len))
2278 goto success;
2279 addr = vma->vm_end;
2280 }
2281 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2282 for (; vma; vma = vma->vm_next) {
2283 if (addr > limit)
2284 break;
2285 - if (addr + len <= vma->vm_start)
2286 + if (check_heap_stack_gap(vma, addr, len))
2287 goto success;
2288 addr = vma->vm_end;
2289 }
2290 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2291 index c635028..6d9445a 100644
2292 --- a/arch/h8300/include/asm/cache.h
2293 +++ b/arch/h8300/include/asm/cache.h
2294 @@ -1,8 +1,10 @@
2295 #ifndef __ARCH_H8300_CACHE_H
2296 #define __ARCH_H8300_CACHE_H
2297
2298 +#include <linux/const.h>
2299 +
2300 /* bytes per L1 cache line */
2301 -#define L1_CACHE_BYTES 4
2302 +#define L1_CACHE_BYTES _AC(4,UL)
2303
2304 /* m68k-elf-gcc 2.95.2 doesn't like these */
2305
2306 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2307 index 0f01de2..d37d309 100644
2308 --- a/arch/hexagon/include/asm/cache.h
2309 +++ b/arch/hexagon/include/asm/cache.h
2310 @@ -21,9 +21,11 @@
2311 #ifndef __ASM_CACHE_H
2312 #define __ASM_CACHE_H
2313
2314 +#include <linux/const.h>
2315 +
2316 /* Bytes per L1 cache line */
2317 -#define L1_CACHE_SHIFT (5)
2318 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2319 +#define L1_CACHE_SHIFT 5
2320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2321
2322 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2323 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2324 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2325 index 6e6fe18..a6ae668 100644
2326 --- a/arch/ia64/include/asm/atomic.h
2327 +++ b/arch/ia64/include/asm/atomic.h
2328 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2329 #define atomic64_inc(v) atomic64_add(1, (v))
2330 #define atomic64_dec(v) atomic64_sub(1, (v))
2331
2332 +#define atomic64_read_unchecked(v) atomic64_read(v)
2333 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2334 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2335 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2336 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2337 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2338 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2339 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2340 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2341 +
2342 /* Atomic operations are already serializing */
2343 #define smp_mb__before_atomic_dec() barrier()
2344 #define smp_mb__after_atomic_dec() barrier()
2345 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2346 index 988254a..e1ee885 100644
2347 --- a/arch/ia64/include/asm/cache.h
2348 +++ b/arch/ia64/include/asm/cache.h
2349 @@ -1,6 +1,7 @@
2350 #ifndef _ASM_IA64_CACHE_H
2351 #define _ASM_IA64_CACHE_H
2352
2353 +#include <linux/const.h>
2354
2355 /*
2356 * Copyright (C) 1998-2000 Hewlett-Packard Co
2357 @@ -9,7 +10,7 @@
2358
2359 /* Bytes per L1 (data) cache line. */
2360 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2361 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2362 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2363
2364 #ifdef CONFIG_SMP
2365 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2366 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2367 index b5298eb..67c6e62 100644
2368 --- a/arch/ia64/include/asm/elf.h
2369 +++ b/arch/ia64/include/asm/elf.h
2370 @@ -42,6 +42,13 @@
2371 */
2372 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2373
2374 +#ifdef CONFIG_PAX_ASLR
2375 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2376 +
2377 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2378 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2379 +#endif
2380 +
2381 #define PT_IA_64_UNWIND 0x70000001
2382
2383 /* IA-64 relocations: */
2384 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2385 index 96a8d92..617a1cf 100644
2386 --- a/arch/ia64/include/asm/pgalloc.h
2387 +++ b/arch/ia64/include/asm/pgalloc.h
2388 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2389 pgd_val(*pgd_entry) = __pa(pud);
2390 }
2391
2392 +static inline void
2393 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2394 +{
2395 + pgd_populate(mm, pgd_entry, pud);
2396 +}
2397 +
2398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2399 {
2400 return quicklist_alloc(0, GFP_KERNEL, NULL);
2401 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2402 pud_val(*pud_entry) = __pa(pmd);
2403 }
2404
2405 +static inline void
2406 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2407 +{
2408 + pud_populate(mm, pud_entry, pmd);
2409 +}
2410 +
2411 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2412 {
2413 return quicklist_alloc(0, GFP_KERNEL, NULL);
2414 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2415 index 815810c..d60bd4c 100644
2416 --- a/arch/ia64/include/asm/pgtable.h
2417 +++ b/arch/ia64/include/asm/pgtable.h
2418 @@ -12,7 +12,7 @@
2419 * David Mosberger-Tang <davidm@hpl.hp.com>
2420 */
2421
2422 -
2423 +#include <linux/const.h>
2424 #include <asm/mman.h>
2425 #include <asm/page.h>
2426 #include <asm/processor.h>
2427 @@ -142,6 +142,17 @@
2428 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2429 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2430 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2431 +
2432 +#ifdef CONFIG_PAX_PAGEEXEC
2433 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2434 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2435 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2436 +#else
2437 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2438 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2439 +# define PAGE_COPY_NOEXEC PAGE_COPY
2440 +#endif
2441 +
2442 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2443 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2444 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2445 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2446 index 54ff557..70c88b7 100644
2447 --- a/arch/ia64/include/asm/spinlock.h
2448 +++ b/arch/ia64/include/asm/spinlock.h
2449 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2450 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2451
2452 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2453 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2454 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2455 }
2456
2457 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2458 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2459 index 449c8c0..432a3d2 100644
2460 --- a/arch/ia64/include/asm/uaccess.h
2461 +++ b/arch/ia64/include/asm/uaccess.h
2462 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2463 const void *__cu_from = (from); \
2464 long __cu_len = (n); \
2465 \
2466 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2467 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2468 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2469 __cu_len; \
2470 })
2471 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2472 long __cu_len = (n); \
2473 \
2474 __chk_user_ptr(__cu_from); \
2475 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2476 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2477 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2478 __cu_len; \
2479 })
2480 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2481 index 24603be..948052d 100644
2482 --- a/arch/ia64/kernel/module.c
2483 +++ b/arch/ia64/kernel/module.c
2484 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2485 void
2486 module_free (struct module *mod, void *module_region)
2487 {
2488 - if (mod && mod->arch.init_unw_table &&
2489 - module_region == mod->module_init) {
2490 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2491 unw_remove_unwind_table(mod->arch.init_unw_table);
2492 mod->arch.init_unw_table = NULL;
2493 }
2494 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2495 }
2496
2497 static inline int
2498 +in_init_rx (const struct module *mod, uint64_t addr)
2499 +{
2500 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2501 +}
2502 +
2503 +static inline int
2504 +in_init_rw (const struct module *mod, uint64_t addr)
2505 +{
2506 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2507 +}
2508 +
2509 +static inline int
2510 in_init (const struct module *mod, uint64_t addr)
2511 {
2512 - return addr - (uint64_t) mod->module_init < mod->init_size;
2513 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2514 +}
2515 +
2516 +static inline int
2517 +in_core_rx (const struct module *mod, uint64_t addr)
2518 +{
2519 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2520 +}
2521 +
2522 +static inline int
2523 +in_core_rw (const struct module *mod, uint64_t addr)
2524 +{
2525 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2526 }
2527
2528 static inline int
2529 in_core (const struct module *mod, uint64_t addr)
2530 {
2531 - return addr - (uint64_t) mod->module_core < mod->core_size;
2532 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2533 }
2534
2535 static inline int
2536 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2537 break;
2538
2539 case RV_BDREL:
2540 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2541 + if (in_init_rx(mod, val))
2542 + val -= (uint64_t) mod->module_init_rx;
2543 + else if (in_init_rw(mod, val))
2544 + val -= (uint64_t) mod->module_init_rw;
2545 + else if (in_core_rx(mod, val))
2546 + val -= (uint64_t) mod->module_core_rx;
2547 + else if (in_core_rw(mod, val))
2548 + val -= (uint64_t) mod->module_core_rw;
2549 break;
2550
2551 case RV_LTV:
2552 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2553 * addresses have been selected...
2554 */
2555 uint64_t gp;
2556 - if (mod->core_size > MAX_LTOFF)
2557 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2558 /*
2559 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2560 * at the end of the module.
2561 */
2562 - gp = mod->core_size - MAX_LTOFF / 2;
2563 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2564 else
2565 - gp = mod->core_size / 2;
2566 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2567 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2568 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2569 mod->arch.gp = gp;
2570 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2571 }
2572 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2573 index d9439ef..b9a4303 100644
2574 --- a/arch/ia64/kernel/sys_ia64.c
2575 +++ b/arch/ia64/kernel/sys_ia64.c
2576 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2577 if (REGION_NUMBER(addr) == RGN_HPAGE)
2578 addr = 0;
2579 #endif
2580 +
2581 +#ifdef CONFIG_PAX_RANDMMAP
2582 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2583 + addr = mm->free_area_cache;
2584 + else
2585 +#endif
2586 +
2587 if (!addr)
2588 addr = mm->free_area_cache;
2589
2590 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2592 /* At this point: (!vma || addr < vma->vm_end). */
2593 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2594 - if (start_addr != TASK_UNMAPPED_BASE) {
2595 + if (start_addr != mm->mmap_base) {
2596 /* Start a new search --- just in case we missed some holes. */
2597 - addr = TASK_UNMAPPED_BASE;
2598 + addr = mm->mmap_base;
2599 goto full_search;
2600 }
2601 return -ENOMEM;
2602 }
2603 - if (!vma || addr + len <= vma->vm_start) {
2604 + if (check_heap_stack_gap(vma, addr, len)) {
2605 /* Remember the address where we stopped this search: */
2606 mm->free_area_cache = addr + len;
2607 return addr;
2608 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2609 index 0ccb28f..8992469 100644
2610 --- a/arch/ia64/kernel/vmlinux.lds.S
2611 +++ b/arch/ia64/kernel/vmlinux.lds.S
2612 @@ -198,7 +198,7 @@ SECTIONS {
2613 /* Per-cpu data: */
2614 . = ALIGN(PERCPU_PAGE_SIZE);
2615 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2616 - __phys_per_cpu_start = __per_cpu_load;
2617 + __phys_per_cpu_start = per_cpu_load;
2618 /*
2619 * ensure percpu data fits
2620 * into percpu page size
2621 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2622 index 8443daf..0a01e30 100644
2623 --- a/arch/ia64/mm/fault.c
2624 +++ b/arch/ia64/mm/fault.c
2625 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2626 return pte_present(pte);
2627 }
2628
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2631 +{
2632 + unsigned long i;
2633 +
2634 + printk(KERN_ERR "PAX: bytes at PC: ");
2635 + for (i = 0; i < 8; i++) {
2636 + unsigned int c;
2637 + if (get_user(c, (unsigned int *)pc+i))
2638 + printk(KERN_CONT "???????? ");
2639 + else
2640 + printk(KERN_CONT "%08x ", c);
2641 + }
2642 + printk("\n");
2643 +}
2644 +#endif
2645 +
2646 # define VM_READ_BIT 0
2647 # define VM_WRITE_BIT 1
2648 # define VM_EXEC_BIT 2
2649 @@ -149,8 +166,21 @@ retry:
2650 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2651 goto bad_area;
2652
2653 - if ((vma->vm_flags & mask) != mask)
2654 + if ((vma->vm_flags & mask) != mask) {
2655 +
2656 +#ifdef CONFIG_PAX_PAGEEXEC
2657 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2658 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2659 + goto bad_area;
2660 +
2661 + up_read(&mm->mmap_sem);
2662 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2663 + do_group_exit(SIGKILL);
2664 + }
2665 +#endif
2666 +
2667 goto bad_area;
2668 + }
2669
2670 /*
2671 * If for any reason at all we couldn't handle the fault, make
2672 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2673 index 5ca674b..e0e1b70 100644
2674 --- a/arch/ia64/mm/hugetlbpage.c
2675 +++ b/arch/ia64/mm/hugetlbpage.c
2676 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2677 /* At this point: (!vmm || addr < vmm->vm_end). */
2678 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2679 return -ENOMEM;
2680 - if (!vmm || (addr + len) <= vmm->vm_start)
2681 + if (check_heap_stack_gap(vmm, addr, len))
2682 return addr;
2683 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2684 }
2685 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2686 index 0eab454..bd794f2 100644
2687 --- a/arch/ia64/mm/init.c
2688 +++ b/arch/ia64/mm/init.c
2689 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2690 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2691 vma->vm_end = vma->vm_start + PAGE_SIZE;
2692 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2693 +
2694 +#ifdef CONFIG_PAX_PAGEEXEC
2695 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2696 + vma->vm_flags &= ~VM_EXEC;
2697 +
2698 +#ifdef CONFIG_PAX_MPROTECT
2699 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2700 + vma->vm_flags &= ~VM_MAYEXEC;
2701 +#endif
2702 +
2703 + }
2704 +#endif
2705 +
2706 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2707 down_write(&current->mm->mmap_sem);
2708 if (insert_vm_struct(current->mm, vma)) {
2709 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2710 index 40b3ee9..8c2c112 100644
2711 --- a/arch/m32r/include/asm/cache.h
2712 +++ b/arch/m32r/include/asm/cache.h
2713 @@ -1,8 +1,10 @@
2714 #ifndef _ASM_M32R_CACHE_H
2715 #define _ASM_M32R_CACHE_H
2716
2717 +#include <linux/const.h>
2718 +
2719 /* L1 cache line size */
2720 #define L1_CACHE_SHIFT 4
2721 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2723
2724 #endif /* _ASM_M32R_CACHE_H */
2725 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2726 index 82abd15..d95ae5d 100644
2727 --- a/arch/m32r/lib/usercopy.c
2728 +++ b/arch/m32r/lib/usercopy.c
2729 @@ -14,6 +14,9 @@
2730 unsigned long
2731 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 {
2733 + if ((long)n < 0)
2734 + return n;
2735 +
2736 prefetch(from);
2737 if (access_ok(VERIFY_WRITE, to, n))
2738 __copy_user(to,from,n);
2739 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2740 unsigned long
2741 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2742 {
2743 + if ((long)n < 0)
2744 + return n;
2745 +
2746 prefetchw(to);
2747 if (access_ok(VERIFY_READ, from, n))
2748 __copy_user_zeroing(to,from,n);
2749 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2750 index 0395c51..5f26031 100644
2751 --- a/arch/m68k/include/asm/cache.h
2752 +++ b/arch/m68k/include/asm/cache.h
2753 @@ -4,9 +4,11 @@
2754 #ifndef __ARCH_M68K_CACHE_H
2755 #define __ARCH_M68K_CACHE_H
2756
2757 +#include <linux/const.h>
2758 +
2759 /* bytes per L1 cache line */
2760 #define L1_CACHE_SHIFT 4
2761 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2762 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2763
2764 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2765
2766 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2767 index 4efe96a..60e8699 100644
2768 --- a/arch/microblaze/include/asm/cache.h
2769 +++ b/arch/microblaze/include/asm/cache.h
2770 @@ -13,11 +13,12 @@
2771 #ifndef _ASM_MICROBLAZE_CACHE_H
2772 #define _ASM_MICROBLAZE_CACHE_H
2773
2774 +#include <linux/const.h>
2775 #include <asm/registers.h>
2776
2777 #define L1_CACHE_SHIFT 5
2778 /* word-granular cache in microblaze */
2779 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2780 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2781
2782 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2783
2784 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2785 index 3f4c5cb..3439c6e 100644
2786 --- a/arch/mips/include/asm/atomic.h
2787 +++ b/arch/mips/include/asm/atomic.h
2788 @@ -21,6 +21,10 @@
2789 #include <asm/cmpxchg.h>
2790 #include <asm/war.h>
2791
2792 +#ifdef CONFIG_GENERIC_ATOMIC64
2793 +#include <asm-generic/atomic64.h>
2794 +#endif
2795 +
2796 #define ATOMIC_INIT(i) { (i) }
2797
2798 /*
2799 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2800 */
2801 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2802
2803 +#define atomic64_read_unchecked(v) atomic64_read(v)
2804 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2805 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2806 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2807 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2808 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2809 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2810 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2811 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2812 +
2813 #endif /* CONFIG_64BIT */
2814
2815 /*
2816 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2817 index b4db69f..8f3b093 100644
2818 --- a/arch/mips/include/asm/cache.h
2819 +++ b/arch/mips/include/asm/cache.h
2820 @@ -9,10 +9,11 @@
2821 #ifndef _ASM_CACHE_H
2822 #define _ASM_CACHE_H
2823
2824 +#include <linux/const.h>
2825 #include <kmalloc.h>
2826
2827 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2828 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2829 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2830
2831 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2833 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2834 index 455c0ac..ad65fbe 100644
2835 --- a/arch/mips/include/asm/elf.h
2836 +++ b/arch/mips/include/asm/elf.h
2837 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2838 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2839 #endif
2840
2841 +#ifdef CONFIG_PAX_ASLR
2842 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2843 +
2844 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2846 +#endif
2847 +
2848 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2849 struct linux_binprm;
2850 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2851 int uses_interp);
2852
2853 -struct mm_struct;
2854 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2855 -#define arch_randomize_brk arch_randomize_brk
2856 -
2857 #endif /* _ASM_ELF_H */
2858 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2859 index c1f6afa..38cc6e9 100644
2860 --- a/arch/mips/include/asm/exec.h
2861 +++ b/arch/mips/include/asm/exec.h
2862 @@ -12,6 +12,6 @@
2863 #ifndef _ASM_EXEC_H
2864 #define _ASM_EXEC_H
2865
2866 -extern unsigned long arch_align_stack(unsigned long sp);
2867 +#define arch_align_stack(x) ((x) & ~0xfUL)
2868
2869 #endif /* _ASM_EXEC_H */
2870 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2871 index da9bd7d..91aa7ab 100644
2872 --- a/arch/mips/include/asm/page.h
2873 +++ b/arch/mips/include/asm/page.h
2874 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2875 #ifdef CONFIG_CPU_MIPS32
2876 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2877 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2878 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2879 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2880 #else
2881 typedef struct { unsigned long long pte; } pte_t;
2882 #define pte_val(x) ((x).pte)
2883 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2884 index 881d18b..cea38bc 100644
2885 --- a/arch/mips/include/asm/pgalloc.h
2886 +++ b/arch/mips/include/asm/pgalloc.h
2887 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2888 {
2889 set_pud(pud, __pud((unsigned long)pmd));
2890 }
2891 +
2892 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893 +{
2894 + pud_populate(mm, pud, pmd);
2895 +}
2896 #endif
2897
2898 /*
2899 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2900 index ca97e0e..cd08920 100644
2901 --- a/arch/mips/include/asm/thread_info.h
2902 +++ b/arch/mips/include/asm/thread_info.h
2903 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2904 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2905 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2906 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2907 +/* li takes a 32bit immediate */
2908 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2909 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2910
2911 #ifdef CONFIG_MIPS32_O32
2912 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2913 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2914 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2915 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2916 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2917 +
2918 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2919
2920 /* work to do in syscall_trace_leave() */
2921 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2922 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2923
2924 /* work to do on interrupt/exception return */
2925 #define _TIF_WORK_MASK (0x0000ffef & \
2926 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2927 /* work to do on any return to u-space */
2928 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2929 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2930
2931 #endif /* __KERNEL__ */
2932
2933 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2934 index 9fdd8bc..4bd7f1a 100644
2935 --- a/arch/mips/kernel/binfmt_elfn32.c
2936 +++ b/arch/mips/kernel/binfmt_elfn32.c
2937 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2938 #undef ELF_ET_DYN_BASE
2939 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2940
2941 +#ifdef CONFIG_PAX_ASLR
2942 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2943 +
2944 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#endif
2947 +
2948 #include <asm/processor.h>
2949 #include <linux/module.h>
2950 #include <linux/elfcore.h>
2951 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2952 index ff44823..97f8906 100644
2953 --- a/arch/mips/kernel/binfmt_elfo32.c
2954 +++ b/arch/mips/kernel/binfmt_elfo32.c
2955 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2956 #undef ELF_ET_DYN_BASE
2957 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2958
2959 +#ifdef CONFIG_PAX_ASLR
2960 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2961 +
2962 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2964 +#endif
2965 +
2966 #include <asm/processor.h>
2967
2968 /*
2969 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2970 index e9a5fd7..378809a 100644
2971 --- a/arch/mips/kernel/process.c
2972 +++ b/arch/mips/kernel/process.c
2973 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2974 out:
2975 return pc;
2976 }
2977 -
2978 -/*
2979 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2980 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2981 - */
2982 -unsigned long arch_align_stack(unsigned long sp)
2983 -{
2984 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2985 - sp -= get_random_int() & ~PAGE_MASK;
2986 -
2987 - return sp & ALMASK;
2988 -}
2989 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2990 index 4812c6d..2069554 100644
2991 --- a/arch/mips/kernel/ptrace.c
2992 +++ b/arch/mips/kernel/ptrace.c
2993 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2994 return arch;
2995 }
2996
2997 +#ifdef CONFIG_GRKERNSEC_SETXID
2998 +extern void gr_delayed_cred_worker(void);
2999 +#endif
3000 +
3001 /*
3002 * Notification of system call entry/exit
3003 * - triggered by current->work.syscall_trace
3004 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3005 /* do the secure computing check first */
3006 secure_computing_strict(regs->regs[2]);
3007
3008 +#ifdef CONFIG_GRKERNSEC_SETXID
3009 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3010 + gr_delayed_cred_worker();
3011 +#endif
3012 +
3013 if (!(current->ptrace & PT_PTRACED))
3014 goto out;
3015
3016 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3017 index a632bc1..0b77c7c 100644
3018 --- a/arch/mips/kernel/scall32-o32.S
3019 +++ b/arch/mips/kernel/scall32-o32.S
3020 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3021
3022 stack_done:
3023 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3024 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3025 + li t1, _TIF_SYSCALL_WORK
3026 and t0, t1
3027 bnez t0, syscall_trace_entry # -> yes
3028
3029 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3030 index 3b5a5e9..e1ee86d 100644
3031 --- a/arch/mips/kernel/scall64-64.S
3032 +++ b/arch/mips/kernel/scall64-64.S
3033 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3034
3035 sd a3, PT_R26(sp) # save a3 for syscall restarting
3036
3037 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3038 + li t1, _TIF_SYSCALL_WORK
3039 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3040 and t0, t1, t0
3041 bnez t0, syscall_trace_entry
3042 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3043 index 6be6f70..1859577 100644
3044 --- a/arch/mips/kernel/scall64-n32.S
3045 +++ b/arch/mips/kernel/scall64-n32.S
3046 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3047
3048 sd a3, PT_R26(sp) # save a3 for syscall restarting
3049
3050 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3051 + li t1, _TIF_SYSCALL_WORK
3052 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3053 and t0, t1, t0
3054 bnez t0, n32_syscall_trace_entry
3055 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3056 index 5422855..74e63a3 100644
3057 --- a/arch/mips/kernel/scall64-o32.S
3058 +++ b/arch/mips/kernel/scall64-o32.S
3059 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3060 PTR 4b, bad_stack
3061 .previous
3062
3063 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3064 + li t1, _TIF_SYSCALL_WORK
3065 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3066 and t0, t1, t0
3067 bnez t0, trace_a_syscall
3068 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3069 index c14f6df..537e729 100644
3070 --- a/arch/mips/mm/fault.c
3071 +++ b/arch/mips/mm/fault.c
3072 @@ -27,6 +27,23 @@
3073 #include <asm/highmem.h> /* For VMALLOC_END */
3074 #include <linux/kdebug.h>
3075
3076 +#ifdef CONFIG_PAX_PAGEEXEC
3077 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3078 +{
3079 + unsigned long i;
3080 +
3081 + printk(KERN_ERR "PAX: bytes at PC: ");
3082 + for (i = 0; i < 5; i++) {
3083 + unsigned int c;
3084 + if (get_user(c, (unsigned int *)pc+i))
3085 + printk(KERN_CONT "???????? ");
3086 + else
3087 + printk(KERN_CONT "%08x ", c);
3088 + }
3089 + printk("\n");
3090 +}
3091 +#endif
3092 +
3093 /*
3094 * This routine handles page faults. It determines the address,
3095 * and the problem, and then passes it off to one of the appropriate
3096 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3097 index 302d779..7d35bf8 100644
3098 --- a/arch/mips/mm/mmap.c
3099 +++ b/arch/mips/mm/mmap.c
3100 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3101 do_color_align = 1;
3102
3103 /* requesting a specific address */
3104 +
3105 +#ifdef CONFIG_PAX_RANDMMAP
3106 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3107 +#endif
3108 +
3109 if (addr) {
3110 if (do_color_align)
3111 addr = COLOUR_ALIGN(addr, pgoff);
3112 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 addr = PAGE_ALIGN(addr);
3114
3115 vma = find_vma(mm, addr);
3116 - if (TASK_SIZE - len >= addr &&
3117 - (!vma || addr + len <= vma->vm_start))
3118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3119 return addr;
3120 }
3121
3122 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126 - if (!vma || addr + len <= vma->vm_start)
3127 + if (check_heap_stack_gap(vmm, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 if (do_color_align)
3131 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3132 /* make sure it can fit in the remaining address space */
3133 if (likely(addr > len)) {
3134 vma = find_vma(mm, addr - len);
3135 - if (!vma || addr <= vma->vm_start) {
3136 + if (check_heap_stack_gap(vmm, addr - len, len))
3137 /* cache the address as a hint for next time */
3138 return mm->free_area_cache = addr - len;
3139 }
3140 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 * return with success:
3142 */
3143 vma = find_vma(mm, addr);
3144 - if (likely(!vma || addr + len <= vma->vm_start)) {
3145 + if (check_heap_stack_gap(vmm, addr, len)) {
3146 /* cache the address as a hint for next time */
3147 return mm->free_area_cache = addr;
3148 }
3149 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3150 mm->unmap_area = arch_unmap_area_topdown;
3151 }
3152 }
3153 -
3154 -static inline unsigned long brk_rnd(void)
3155 -{
3156 - unsigned long rnd = get_random_int();
3157 -
3158 - rnd = rnd << PAGE_SHIFT;
3159 - /* 8MB for 32bit, 256MB for 64bit */
3160 - if (TASK_IS_32BIT_ADDR)
3161 - rnd = rnd & 0x7ffffful;
3162 - else
3163 - rnd = rnd & 0xffffffful;
3164 -
3165 - return rnd;
3166 -}
3167 -
3168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3169 -{
3170 - unsigned long base = mm->brk;
3171 - unsigned long ret;
3172 -
3173 - ret = PAGE_ALIGN(base + brk_rnd());
3174 -
3175 - if (ret < mm->brk)
3176 - return mm->brk;
3177 -
3178 - return ret;
3179 -}
3180 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3181 index 967d144..db12197 100644
3182 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3184 @@ -11,12 +11,14 @@
3185 #ifndef _ASM_PROC_CACHE_H
3186 #define _ASM_PROC_CACHE_H
3187
3188 +#include <linux/const.h>
3189 +
3190 /* L1 cache */
3191
3192 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3193 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3194 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3195 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3196 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3197 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3198
3199 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3200 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3201 index bcb5df2..84fabd2 100644
3202 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3204 @@ -16,13 +16,15 @@
3205 #ifndef _ASM_PROC_CACHE_H
3206 #define _ASM_PROC_CACHE_H
3207
3208 +#include <linux/const.h>
3209 +
3210 /*
3211 * L1 cache
3212 */
3213 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3214 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3215 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3216 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3217 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3218 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3219
3220 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3221 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3222 index 4ce7a01..449202a 100644
3223 --- a/arch/openrisc/include/asm/cache.h
3224 +++ b/arch/openrisc/include/asm/cache.h
3225 @@ -19,11 +19,13 @@
3226 #ifndef __ASM_OPENRISC_CACHE_H
3227 #define __ASM_OPENRISC_CACHE_H
3228
3229 +#include <linux/const.h>
3230 +
3231 /* FIXME: How can we replace these with values from the CPU...
3232 * they shouldn't be hard-coded!
3233 */
3234
3235 -#define L1_CACHE_BYTES 16
3236 #define L1_CACHE_SHIFT 4
3237 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3238
3239 #endif /* __ASM_OPENRISC_CACHE_H */
3240 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3241 index af9cf30..2aae9b2 100644
3242 --- a/arch/parisc/include/asm/atomic.h
3243 +++ b/arch/parisc/include/asm/atomic.h
3244 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3245
3246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3247
3248 +#define atomic64_read_unchecked(v) atomic64_read(v)
3249 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3250 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3251 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3252 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3253 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3254 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3255 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3256 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3257 +
3258 #endif /* !CONFIG_64BIT */
3259
3260
3261 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3262 index 47f11c7..3420df2 100644
3263 --- a/arch/parisc/include/asm/cache.h
3264 +++ b/arch/parisc/include/asm/cache.h
3265 @@ -5,6 +5,7 @@
3266 #ifndef __ARCH_PARISC_CACHE_H
3267 #define __ARCH_PARISC_CACHE_H
3268
3269 +#include <linux/const.h>
3270
3271 /*
3272 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3273 @@ -15,13 +16,13 @@
3274 * just ruin performance.
3275 */
3276 #ifdef CONFIG_PA20
3277 -#define L1_CACHE_BYTES 64
3278 #define L1_CACHE_SHIFT 6
3279 #else
3280 -#define L1_CACHE_BYTES 32
3281 #define L1_CACHE_SHIFT 5
3282 #endif
3283
3284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3285 +
3286 #ifndef __ASSEMBLY__
3287
3288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3289 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3290 index 19f6cb1..6c78cf2 100644
3291 --- a/arch/parisc/include/asm/elf.h
3292 +++ b/arch/parisc/include/asm/elf.h
3293 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3294
3295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3296
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3299 +
3300 +#define PAX_DELTA_MMAP_LEN 16
3301 +#define PAX_DELTA_STACK_LEN 16
3302 +#endif
3303 +
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. This could be done in user space,
3306 but it's not easy, and we've already done it here. */
3307 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3308 index fc987a1..6e068ef 100644
3309 --- a/arch/parisc/include/asm/pgalloc.h
3310 +++ b/arch/parisc/include/asm/pgalloc.h
3311 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3312 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3313 }
3314
3315 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3316 +{
3317 + pgd_populate(mm, pgd, pmd);
3318 +}
3319 +
3320 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3321 {
3322 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3323 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3324 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3325 #define pmd_free(mm, x) do { } while (0)
3326 #define pgd_populate(mm, pmd, pte) BUG()
3327 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3328
3329 #endif
3330
3331 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3332 index ee99f23..802b0a1 100644
3333 --- a/arch/parisc/include/asm/pgtable.h
3334 +++ b/arch/parisc/include/asm/pgtable.h
3335 @@ -212,6 +212,17 @@ struct vm_area_struct;
3336 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3337 #define PAGE_COPY PAGE_EXECREAD
3338 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3339 +
3340 +#ifdef CONFIG_PAX_PAGEEXEC
3341 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3342 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3344 +#else
3345 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3346 +# define PAGE_COPY_NOEXEC PAGE_COPY
3347 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3348 +#endif
3349 +
3350 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3351 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3352 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3353 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3354 index 4ba2c93..f5e3974 100644
3355 --- a/arch/parisc/include/asm/uaccess.h
3356 +++ b/arch/parisc/include/asm/uaccess.h
3357 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3358 const void __user *from,
3359 unsigned long n)
3360 {
3361 - int sz = __compiletime_object_size(to);
3362 + size_t sz = __compiletime_object_size(to);
3363 int ret = -EFAULT;
3364
3365 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3366 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3367 ret = __copy_from_user(to, from, n);
3368 else
3369 copy_from_user_overflow();
3370 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3371 index 5e34ccf..672bc9c 100644
3372 --- a/arch/parisc/kernel/module.c
3373 +++ b/arch/parisc/kernel/module.c
3374 @@ -98,16 +98,38 @@
3375
3376 /* three functions to determine where in the module core
3377 * or init pieces the location is */
3378 +static inline int in_init_rx(struct module *me, void *loc)
3379 +{
3380 + return (loc >= me->module_init_rx &&
3381 + loc < (me->module_init_rx + me->init_size_rx));
3382 +}
3383 +
3384 +static inline int in_init_rw(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rw &&
3387 + loc < (me->module_init_rw + me->init_size_rw));
3388 +}
3389 +
3390 static inline int in_init(struct module *me, void *loc)
3391 {
3392 - return (loc >= me->module_init &&
3393 - loc <= (me->module_init + me->init_size));
3394 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3395 +}
3396 +
3397 +static inline int in_core_rx(struct module *me, void *loc)
3398 +{
3399 + return (loc >= me->module_core_rx &&
3400 + loc < (me->module_core_rx + me->core_size_rx));
3401 +}
3402 +
3403 +static inline int in_core_rw(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rw &&
3406 + loc < (me->module_core_rw + me->core_size_rw));
3407 }
3408
3409 static inline int in_core(struct module *me, void *loc)
3410 {
3411 - return (loc >= me->module_core &&
3412 - loc <= (me->module_core + me->core_size));
3413 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3414 }
3415
3416 static inline int in_local(struct module *me, void *loc)
3417 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3418 }
3419
3420 /* align things a bit */
3421 - me->core_size = ALIGN(me->core_size, 16);
3422 - me->arch.got_offset = me->core_size;
3423 - me->core_size += gots * sizeof(struct got_entry);
3424 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3425 + me->arch.got_offset = me->core_size_rw;
3426 + me->core_size_rw += gots * sizeof(struct got_entry);
3427
3428 - me->core_size = ALIGN(me->core_size, 16);
3429 - me->arch.fdesc_offset = me->core_size;
3430 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3431 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3432 + me->arch.fdesc_offset = me->core_size_rw;
3433 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3434
3435 me->arch.got_max = gots;
3436 me->arch.fdesc_max = fdescs;
3437 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3438
3439 BUG_ON(value == 0);
3440
3441 - got = me->module_core + me->arch.got_offset;
3442 + got = me->module_core_rw + me->arch.got_offset;
3443 for (i = 0; got[i].addr; i++)
3444 if (got[i].addr == value)
3445 goto out;
3446 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3447 #ifdef CONFIG_64BIT
3448 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3449 {
3450 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3451 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3452
3453 if (!value) {
3454 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3455 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3456
3457 /* Create new one */
3458 fdesc->addr = value;
3459 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3460 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3461 return (Elf_Addr)fdesc;
3462 }
3463 #endif /* CONFIG_64BIT */
3464 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3465
3466 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3467 end = table + sechdrs[me->arch.unwind_section].sh_size;
3468 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3469 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3470
3471 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3472 me->arch.unwind_section, table, end, gp);
3473 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3474 index 7426e40..30c8dbe 100644
3475 --- a/arch/parisc/kernel/sys_parisc.c
3476 +++ b/arch/parisc/kernel/sys_parisc.c
3477 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3478 /* At this point: (!vma || addr < vma->vm_end). */
3479 if (TASK_SIZE - len < addr)
3480 return -ENOMEM;
3481 - if (!vma || addr + len <= vma->vm_start)
3482 + if (check_heap_stack_gap(vma, addr, len))
3483 return addr;
3484 addr = vma->vm_end;
3485 }
3486 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3487 /* At this point: (!vma || addr < vma->vm_end). */
3488 if (TASK_SIZE - len < addr)
3489 return -ENOMEM;
3490 - if (!vma || addr + len <= vma->vm_start)
3491 + if (check_heap_stack_gap(vma, addr, len))
3492 return addr;
3493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3494 if (addr < vma->vm_end) /* handle wraparound */
3495 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3496 if (flags & MAP_FIXED)
3497 return addr;
3498 if (!addr)
3499 - addr = TASK_UNMAPPED_BASE;
3500 + addr = current->mm->mmap_base;
3501
3502 if (filp) {
3503 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3504 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3505 index 45ba99f..8e22c33 100644
3506 --- a/arch/parisc/kernel/traps.c
3507 +++ b/arch/parisc/kernel/traps.c
3508 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3509
3510 down_read(&current->mm->mmap_sem);
3511 vma = find_vma(current->mm,regs->iaoq[0]);
3512 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3513 - && (vma->vm_flags & VM_EXEC)) {
3514 -
3515 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3516 fault_address = regs->iaoq[0];
3517 fault_space = regs->iasq[0];
3518
3519 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3520 index 18162ce..94de376 100644
3521 --- a/arch/parisc/mm/fault.c
3522 +++ b/arch/parisc/mm/fault.c
3523 @@ -15,6 +15,7 @@
3524 #include <linux/sched.h>
3525 #include <linux/interrupt.h>
3526 #include <linux/module.h>
3527 +#include <linux/unistd.h>
3528
3529 #include <asm/uaccess.h>
3530 #include <asm/traps.h>
3531 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3532 static unsigned long
3533 parisc_acctyp(unsigned long code, unsigned int inst)
3534 {
3535 - if (code == 6 || code == 16)
3536 + if (code == 6 || code == 7 || code == 16)
3537 return VM_EXEC;
3538
3539 switch (inst & 0xf0000000) {
3540 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3541 }
3542 #endif
3543
3544 +#ifdef CONFIG_PAX_PAGEEXEC
3545 +/*
3546 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3547 + *
3548 + * returns 1 when task should be killed
3549 + * 2 when rt_sigreturn trampoline was detected
3550 + * 3 when unpatched PLT trampoline was detected
3551 + */
3552 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3553 +{
3554 +
3555 +#ifdef CONFIG_PAX_EMUPLT
3556 + int err;
3557 +
3558 + do { /* PaX: unpatched PLT emulation */
3559 + unsigned int bl, depwi;
3560 +
3561 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3562 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3563 +
3564 + if (err)
3565 + break;
3566 +
3567 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3568 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3569 +
3570 + err = get_user(ldw, (unsigned int *)addr);
3571 + err |= get_user(bv, (unsigned int *)(addr+4));
3572 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3573 +
3574 + if (err)
3575 + break;
3576 +
3577 + if (ldw == 0x0E801096U &&
3578 + bv == 0xEAC0C000U &&
3579 + ldw2 == 0x0E881095U)
3580 + {
3581 + unsigned int resolver, map;
3582 +
3583 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3584 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3585 + if (err)
3586 + break;
3587 +
3588 + regs->gr[20] = instruction_pointer(regs)+8;
3589 + regs->gr[21] = map;
3590 + regs->gr[22] = resolver;
3591 + regs->iaoq[0] = resolver | 3UL;
3592 + regs->iaoq[1] = regs->iaoq[0] + 4;
3593 + return 3;
3594 + }
3595 + }
3596 + } while (0);
3597 +#endif
3598 +
3599 +#ifdef CONFIG_PAX_EMUTRAMP
3600 +
3601 +#ifndef CONFIG_PAX_EMUSIGRT
3602 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3603 + return 1;
3604 +#endif
3605 +
3606 + do { /* PaX: rt_sigreturn emulation */
3607 + unsigned int ldi1, ldi2, bel, nop;
3608 +
3609 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3610 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3611 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3612 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3613 +
3614 + if (err)
3615 + break;
3616 +
3617 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3618 + ldi2 == 0x3414015AU &&
3619 + bel == 0xE4008200U &&
3620 + nop == 0x08000240U)
3621 + {
3622 + regs->gr[25] = (ldi1 & 2) >> 1;
3623 + regs->gr[20] = __NR_rt_sigreturn;
3624 + regs->gr[31] = regs->iaoq[1] + 16;
3625 + regs->sr[0] = regs->iasq[1];
3626 + regs->iaoq[0] = 0x100UL;
3627 + regs->iaoq[1] = regs->iaoq[0] + 4;
3628 + regs->iasq[0] = regs->sr[2];
3629 + regs->iasq[1] = regs->sr[2];
3630 + return 2;
3631 + }
3632 + } while (0);
3633 +#endif
3634 +
3635 + return 1;
3636 +}
3637 +
3638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3639 +{
3640 + unsigned long i;
3641 +
3642 + printk(KERN_ERR "PAX: bytes at PC: ");
3643 + for (i = 0; i < 5; i++) {
3644 + unsigned int c;
3645 + if (get_user(c, (unsigned int *)pc+i))
3646 + printk(KERN_CONT "???????? ");
3647 + else
3648 + printk(KERN_CONT "%08x ", c);
3649 + }
3650 + printk("\n");
3651 +}
3652 +#endif
3653 +
3654 int fixup_exception(struct pt_regs *regs)
3655 {
3656 const struct exception_table_entry *fix;
3657 @@ -192,8 +303,33 @@ good_area:
3658
3659 acc_type = parisc_acctyp(code,regs->iir);
3660
3661 - if ((vma->vm_flags & acc_type) != acc_type)
3662 + if ((vma->vm_flags & acc_type) != acc_type) {
3663 +
3664 +#ifdef CONFIG_PAX_PAGEEXEC
3665 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3666 + (address & ~3UL) == instruction_pointer(regs))
3667 + {
3668 + up_read(&mm->mmap_sem);
3669 + switch (pax_handle_fetch_fault(regs)) {
3670 +
3671 +#ifdef CONFIG_PAX_EMUPLT
3672 + case 3:
3673 + return;
3674 +#endif
3675 +
3676 +#ifdef CONFIG_PAX_EMUTRAMP
3677 + case 2:
3678 + return;
3679 +#endif
3680 +
3681 + }
3682 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3683 + do_group_exit(SIGKILL);
3684 + }
3685 +#endif
3686 +
3687 goto bad_area;
3688 + }
3689
3690 /*
3691 * If for any reason at all we couldn't handle the fault, make
3692 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3693 index da29032..f76c24c 100644
3694 --- a/arch/powerpc/include/asm/atomic.h
3695 +++ b/arch/powerpc/include/asm/atomic.h
3696 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3697 return t1;
3698 }
3699
3700 +#define atomic64_read_unchecked(v) atomic64_read(v)
3701 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3702 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3703 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3704 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3705 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3706 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3707 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3708 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3709 +
3710 #endif /* __powerpc64__ */
3711
3712 #endif /* __KERNEL__ */
3713 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3714 index 9e495c9..b6878e5 100644
3715 --- a/arch/powerpc/include/asm/cache.h
3716 +++ b/arch/powerpc/include/asm/cache.h
3717 @@ -3,6 +3,7 @@
3718
3719 #ifdef __KERNEL__
3720
3721 +#include <linux/const.h>
3722
3723 /* bytes per L1 cache line */
3724 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3725 @@ -22,7 +23,7 @@
3726 #define L1_CACHE_SHIFT 7
3727 #endif
3728
3729 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3730 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3731
3732 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3733
3734 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3735 index 3bf9cca..e7457d0 100644
3736 --- a/arch/powerpc/include/asm/elf.h
3737 +++ b/arch/powerpc/include/asm/elf.h
3738 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3739 the loader. We need to make sure that it is out of the way of the program
3740 that it will "exec", and that there is sufficient room for the brk. */
3741
3742 -extern unsigned long randomize_et_dyn(unsigned long base);
3743 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3744 +#define ELF_ET_DYN_BASE (0x20000000)
3745 +
3746 +#ifdef CONFIG_PAX_ASLR
3747 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3748 +
3749 +#ifdef __powerpc64__
3750 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3751 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3752 +#else
3753 +#define PAX_DELTA_MMAP_LEN 15
3754 +#define PAX_DELTA_STACK_LEN 15
3755 +#endif
3756 +#endif
3757
3758 /*
3759 * Our registers are always unsigned longs, whether we're a 32 bit
3760 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3761 (0x7ff >> (PAGE_SHIFT - 12)) : \
3762 (0x3ffff >> (PAGE_SHIFT - 12)))
3763
3764 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3765 -#define arch_randomize_brk arch_randomize_brk
3766 -
3767 #endif /* __KERNEL__ */
3768
3769 /*
3770 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3771 index 8196e9c..d83a9f3 100644
3772 --- a/arch/powerpc/include/asm/exec.h
3773 +++ b/arch/powerpc/include/asm/exec.h
3774 @@ -4,6 +4,6 @@
3775 #ifndef _ASM_POWERPC_EXEC_H
3776 #define _ASM_POWERPC_EXEC_H
3777
3778 -extern unsigned long arch_align_stack(unsigned long sp);
3779 +#define arch_align_stack(x) ((x) & ~0xfUL)
3780
3781 #endif /* _ASM_POWERPC_EXEC_H */
3782 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3783 index 5acabbd..7ea14fa 100644
3784 --- a/arch/powerpc/include/asm/kmap_types.h
3785 +++ b/arch/powerpc/include/asm/kmap_types.h
3786 @@ -10,7 +10,7 @@
3787 * 2 of the License, or (at your option) any later version.
3788 */
3789
3790 -#define KM_TYPE_NR 16
3791 +#define KM_TYPE_NR 17
3792
3793 #endif /* __KERNEL__ */
3794 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3795 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3796 index d4a7f64..451de1c 100644
3797 --- a/arch/powerpc/include/asm/mman.h
3798 +++ b/arch/powerpc/include/asm/mman.h
3799 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3800 }
3801 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3802
3803 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3804 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3805 {
3806 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3807 }
3808 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3809 index f072e97..b436dee 100644
3810 --- a/arch/powerpc/include/asm/page.h
3811 +++ b/arch/powerpc/include/asm/page.h
3812 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3813 * and needs to be executable. This means the whole heap ends
3814 * up being executable.
3815 */
3816 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_DATA_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3825 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3826 #endif
3827
3828 +#define ktla_ktva(addr) (addr)
3829 +#define ktva_ktla(addr) (addr)
3830 +
3831 /*
3832 * Use the top bit of the higher-level page table entries to indicate whether
3833 * the entries we point to contain hugepages. This works because we know that
3834 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3835 index fed85e6..da5c71b 100644
3836 --- a/arch/powerpc/include/asm/page_64.h
3837 +++ b/arch/powerpc/include/asm/page_64.h
3838 @@ -146,15 +146,18 @@ do { \
3839 * stack by default, so in the absence of a PT_GNU_STACK program header
3840 * we turn execute permission off.
3841 */
3842 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3843 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3844 +#define VM_STACK_DEFAULT_FLAGS32 \
3845 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3846 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3847
3848 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3849 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3850
3851 +#ifndef CONFIG_PAX_PAGEEXEC
3852 #define VM_STACK_DEFAULT_FLAGS \
3853 (is_32bit_task() ? \
3854 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3855 +#endif
3856
3857 #include <asm-generic/getorder.h>
3858
3859 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3860 index 292725c..f87ae14 100644
3861 --- a/arch/powerpc/include/asm/pgalloc-64.h
3862 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3863 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3864 #ifndef CONFIG_PPC_64K_PAGES
3865
3866 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3867 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3868
3869 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3870 {
3871 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3872 pud_set(pud, (unsigned long)pmd);
3873 }
3874
3875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876 +{
3877 + pud_populate(mm, pud, pmd);
3878 +}
3879 +
3880 #define pmd_populate(mm, pmd, pte_page) \
3881 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3882 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3883 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3884 #else /* CONFIG_PPC_64K_PAGES */
3885
3886 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3887 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3888
3889 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3890 pte_t *pte)
3891 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3892 index 2e0e411..7899c68 100644
3893 --- a/arch/powerpc/include/asm/pgtable.h
3894 +++ b/arch/powerpc/include/asm/pgtable.h
3895 @@ -2,6 +2,7 @@
3896 #define _ASM_POWERPC_PGTABLE_H
3897 #ifdef __KERNEL__
3898
3899 +#include <linux/const.h>
3900 #ifndef __ASSEMBLY__
3901 #include <asm/processor.h> /* For TASK_SIZE */
3902 #include <asm/mmu.h>
3903 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3904 index 4aad413..85d86bf 100644
3905 --- a/arch/powerpc/include/asm/pte-hash32.h
3906 +++ b/arch/powerpc/include/asm/pte-hash32.h
3907 @@ -21,6 +21,7 @@
3908 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3909 #define _PAGE_USER 0x004 /* usermode access allowed */
3910 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3911 +#define _PAGE_EXEC _PAGE_GUARDED
3912 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3913 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3914 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3915 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3916 index 6386086..6982225 100644
3917 --- a/arch/powerpc/include/asm/reg.h
3918 +++ b/arch/powerpc/include/asm/reg.h
3919 @@ -212,6 +212,7 @@
3920 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3921 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3922 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3923 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3924 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3925 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3926 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3927 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3928 index faf9352..ab2ccec 100644
3929 --- a/arch/powerpc/include/asm/thread_info.h
3930 +++ b/arch/powerpc/include/asm/thread_info.h
3931 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3932 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3933 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3934 #define TIF_SINGLESTEP 8 /* singlestepping active */
3935 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3936 #define TIF_SECCOMP 10 /* secure computing */
3937 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3938 #define TIF_NOERROR 12 /* Force successful syscall return */
3939 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3940 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3941 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3942 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3943 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3944
3945 /* as above, but as bit values */
3946 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3947 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3948 #define _TIF_NOERROR (1<<TIF_NOERROR)
3949 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3950 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3951 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3952 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3953 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3954 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3955 + _TIF_GRSEC_SETXID)
3956
3957 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3958 _TIF_NOTIFY_RESUME)
3959 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3960 index 17bb40c..353c98b 100644
3961 --- a/arch/powerpc/include/asm/uaccess.h
3962 +++ b/arch/powerpc/include/asm/uaccess.h
3963 @@ -13,6 +13,8 @@
3964 #define VERIFY_READ 0
3965 #define VERIFY_WRITE 1
3966
3967 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3968 +
3969 /*
3970 * The fs value determines whether argument validity checking should be
3971 * performed or not. If get_fs() == USER_DS, checking is performed, with
3972 @@ -329,52 +331,6 @@ do { \
3973 extern unsigned long __copy_tofrom_user(void __user *to,
3974 const void __user *from, unsigned long size);
3975
3976 -#ifndef __powerpc64__
3977 -
3978 -static inline unsigned long copy_from_user(void *to,
3979 - const void __user *from, unsigned long n)
3980 -{
3981 - unsigned long over;
3982 -
3983 - if (access_ok(VERIFY_READ, from, n))
3984 - return __copy_tofrom_user((__force void __user *)to, from, n);
3985 - if ((unsigned long)from < TASK_SIZE) {
3986 - over = (unsigned long)from + n - TASK_SIZE;
3987 - return __copy_tofrom_user((__force void __user *)to, from,
3988 - n - over) + over;
3989 - }
3990 - return n;
3991 -}
3992 -
3993 -static inline unsigned long copy_to_user(void __user *to,
3994 - const void *from, unsigned long n)
3995 -{
3996 - unsigned long over;
3997 -
3998 - if (access_ok(VERIFY_WRITE, to, n))
3999 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4000 - if ((unsigned long)to < TASK_SIZE) {
4001 - over = (unsigned long)to + n - TASK_SIZE;
4002 - return __copy_tofrom_user(to, (__force void __user *)from,
4003 - n - over) + over;
4004 - }
4005 - return n;
4006 -}
4007 -
4008 -#else /* __powerpc64__ */
4009 -
4010 -#define __copy_in_user(to, from, size) \
4011 - __copy_tofrom_user((to), (from), (size))
4012 -
4013 -extern unsigned long copy_from_user(void *to, const void __user *from,
4014 - unsigned long n);
4015 -extern unsigned long copy_to_user(void __user *to, const void *from,
4016 - unsigned long n);
4017 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4018 - unsigned long n);
4019 -
4020 -#endif /* __powerpc64__ */
4021 -
4022 static inline unsigned long __copy_from_user_inatomic(void *to,
4023 const void __user *from, unsigned long n)
4024 {
4025 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4026 if (ret == 0)
4027 return 0;
4028 }
4029 +
4030 + if (!__builtin_constant_p(n))
4031 + check_object_size(to, n, false);
4032 +
4033 return __copy_tofrom_user((__force void __user *)to, from, n);
4034 }
4035
4036 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4037 if (ret == 0)
4038 return 0;
4039 }
4040 +
4041 + if (!__builtin_constant_p(n))
4042 + check_object_size(from, n, true);
4043 +
4044 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4045 }
4046
4047 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4048 return __copy_to_user_inatomic(to, from, size);
4049 }
4050
4051 +#ifndef __powerpc64__
4052 +
4053 +static inline unsigned long __must_check copy_from_user(void *to,
4054 + const void __user *from, unsigned long n)
4055 +{
4056 + unsigned long over;
4057 +
4058 + if ((long)n < 0)
4059 + return n;
4060 +
4061 + if (access_ok(VERIFY_READ, from, n)) {
4062 + if (!__builtin_constant_p(n))
4063 + check_object_size(to, n, false);
4064 + return __copy_tofrom_user((__force void __user *)to, from, n);
4065 + }
4066 + if ((unsigned long)from < TASK_SIZE) {
4067 + over = (unsigned long)from + n - TASK_SIZE;
4068 + if (!__builtin_constant_p(n - over))
4069 + check_object_size(to, n - over, false);
4070 + return __copy_tofrom_user((__force void __user *)to, from,
4071 + n - over) + over;
4072 + }
4073 + return n;
4074 +}
4075 +
4076 +static inline unsigned long __must_check copy_to_user(void __user *to,
4077 + const void *from, unsigned long n)
4078 +{
4079 + unsigned long over;
4080 +
4081 + if ((long)n < 0)
4082 + return n;
4083 +
4084 + if (access_ok(VERIFY_WRITE, to, n)) {
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(from, n, true);
4087 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4088 + }
4089 + if ((unsigned long)to < TASK_SIZE) {
4090 + over = (unsigned long)to + n - TASK_SIZE;
4091 + if (!__builtin_constant_p(n))
4092 + check_object_size(from, n - over, true);
4093 + return __copy_tofrom_user(to, (__force void __user *)from,
4094 + n - over) + over;
4095 + }
4096 + return n;
4097 +}
4098 +
4099 +#else /* __powerpc64__ */
4100 +
4101 +#define __copy_in_user(to, from, size) \
4102 + __copy_tofrom_user((to), (from), (size))
4103 +
4104 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4105 +{
4106 + if ((long)n < 0 || n > INT_MAX)
4107 + return n;
4108 +
4109 + if (!__builtin_constant_p(n))
4110 + check_object_size(to, n, false);
4111 +
4112 + if (likely(access_ok(VERIFY_READ, from, n)))
4113 + n = __copy_from_user(to, from, n);
4114 + else
4115 + memset(to, 0, n);
4116 + return n;
4117 +}
4118 +
4119 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4120 +{
4121 + if ((long)n < 0 || n > INT_MAX)
4122 + return n;
4123 +
4124 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4125 + if (!__builtin_constant_p(n))
4126 + check_object_size(from, n, true);
4127 + n = __copy_to_user(to, from, n);
4128 + }
4129 + return n;
4130 +}
4131 +
4132 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4133 + unsigned long n);
4134 +
4135 +#endif /* __powerpc64__ */
4136 +
4137 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4138
4139 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4140 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4141 index 98be7f0..8ef62de 100644
4142 --- a/arch/powerpc/kernel/exceptions-64e.S
4143 +++ b/arch/powerpc/kernel/exceptions-64e.S
4144 @@ -661,6 +661,7 @@ storage_fault_common:
4145 std r14,_DAR(r1)
4146 std r15,_DSISR(r1)
4147 addi r3,r1,STACK_FRAME_OVERHEAD
4148 + bl .save_nvgprs
4149 mr r4,r14
4150 mr r5,r15
4151 ld r14,PACA_EXGEN+EX_R14(r13)
4152 @@ -669,8 +670,7 @@ storage_fault_common:
4153 cmpdi r3,0
4154 bne- 1f
4155 b .ret_from_except_lite
4156 -1: bl .save_nvgprs
4157 - mr r5,r3
4158 +1: mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 ld r4,_DAR(r1)
4161 bl .bad_page_fault
4162 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4163 index 39aa97d..dc916ee 100644
4164 --- a/arch/powerpc/kernel/exceptions-64s.S
4165 +++ b/arch/powerpc/kernel/exceptions-64s.S
4166 @@ -890,10 +890,10 @@ handle_page_fault:
4167 11: ld r4,_DAR(r1)
4168 ld r5,_DSISR(r1)
4169 addi r3,r1,STACK_FRAME_OVERHEAD
4170 + bl .save_nvgprs
4171 bl .do_page_fault
4172 cmpdi r3,0
4173 beq+ 12f
4174 - bl .save_nvgprs
4175 mr r5,r3
4176 addi r3,r1,STACK_FRAME_OVERHEAD
4177 lwz r4,_DAR(r1)
4178 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4179 index 2e3200c..72095ce 100644
4180 --- a/arch/powerpc/kernel/module_32.c
4181 +++ b/arch/powerpc/kernel/module_32.c
4182 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4183 me->arch.core_plt_section = i;
4184 }
4185 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4186 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4187 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4188 return -ENOEXEC;
4189 }
4190
4191 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4192
4193 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4194 /* Init, or core PLT? */
4195 - if (location >= mod->module_core
4196 - && location < mod->module_core + mod->core_size)
4197 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4198 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4199 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4200 - else
4201 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4202 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4203 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4204 + else {
4205 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4206 + return ~0UL;
4207 + }
4208
4209 /* Find this entry, or if that fails, the next avail. entry */
4210 while (entry->jump[0]) {
4211 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4212 index 1a1f2dd..f4d1bb4 100644
4213 --- a/arch/powerpc/kernel/process.c
4214 +++ b/arch/powerpc/kernel/process.c
4215 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4216 * Lookup NIP late so we have the best change of getting the
4217 * above info out without failing
4218 */
4219 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4220 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4221 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4222 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4223 #endif
4224 show_stack(current, (unsigned long *) regs->gpr[1]);
4225 if (!user_mode(regs))
4226 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4227 newsp = stack[0];
4228 ip = stack[STACK_FRAME_LR_SAVE];
4229 if (!firstframe || ip != lr) {
4230 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4231 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4233 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4234 - printk(" (%pS)",
4235 + printk(" (%pA)",
4236 (void *)current->ret_stack[curr_frame].ret);
4237 curr_frame--;
4238 }
4239 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4240 struct pt_regs *regs = (struct pt_regs *)
4241 (sp + STACK_FRAME_OVERHEAD);
4242 lr = regs->link;
4243 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4244 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4245 regs->trap, (void *)regs->nip, (void *)lr);
4246 firstframe = 1;
4247 }
4248 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4249 mtspr(SPRN_CTRLT, ctrl);
4250 }
4251 #endif /* CONFIG_PPC64 */
4252 -
4253 -unsigned long arch_align_stack(unsigned long sp)
4254 -{
4255 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4256 - sp -= get_random_int() & ~PAGE_MASK;
4257 - return sp & ~0xf;
4258 -}
4259 -
4260 -static inline unsigned long brk_rnd(void)
4261 -{
4262 - unsigned long rnd = 0;
4263 -
4264 - /* 8MB for 32bit, 1GB for 64bit */
4265 - if (is_32bit_task())
4266 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4267 - else
4268 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4269 -
4270 - return rnd << PAGE_SHIFT;
4271 -}
4272 -
4273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4274 -{
4275 - unsigned long base = mm->brk;
4276 - unsigned long ret;
4277 -
4278 -#ifdef CONFIG_PPC_STD_MMU_64
4279 - /*
4280 - * If we are using 1TB segments and we are allowed to randomise
4281 - * the heap, we can put it above 1TB so it is backed by a 1TB
4282 - * segment. Otherwise the heap will be in the bottom 1TB
4283 - * which always uses 256MB segments and this may result in a
4284 - * performance penalty.
4285 - */
4286 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4287 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4288 -#endif
4289 -
4290 - ret = PAGE_ALIGN(base + brk_rnd());
4291 -
4292 - if (ret < mm->brk)
4293 - return mm->brk;
4294 -
4295 - return ret;
4296 -}
4297 -
4298 -unsigned long randomize_et_dyn(unsigned long base)
4299 -{
4300 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4301 -
4302 - if (ret < base)
4303 - return base;
4304 -
4305 - return ret;
4306 -}
4307 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4308 index c10fc28..c4ef063 100644
4309 --- a/arch/powerpc/kernel/ptrace.c
4310 +++ b/arch/powerpc/kernel/ptrace.c
4311 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4312 return ret;
4313 }
4314
4315 +#ifdef CONFIG_GRKERNSEC_SETXID
4316 +extern void gr_delayed_cred_worker(void);
4317 +#endif
4318 +
4319 /*
4320 * We must return the syscall number to actually look up in the table.
4321 * This can be -1L to skip running any syscall at all.
4322 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4323
4324 secure_computing_strict(regs->gpr[0]);
4325
4326 +#ifdef CONFIG_GRKERNSEC_SETXID
4327 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4328 + gr_delayed_cred_worker();
4329 +#endif
4330 +
4331 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4332 tracehook_report_syscall_entry(regs))
4333 /*
4334 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4335 {
4336 int step;
4337
4338 +#ifdef CONFIG_GRKERNSEC_SETXID
4339 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4340 + gr_delayed_cred_worker();
4341 +#endif
4342 +
4343 audit_syscall_exit(regs);
4344
4345 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4346 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4347 index 8b4c049..dcd6ef3 100644
4348 --- a/arch/powerpc/kernel/signal_32.c
4349 +++ b/arch/powerpc/kernel/signal_32.c
4350 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4351 /* Save user registers on the stack */
4352 frame = &rt_sf->uc.uc_mcontext;
4353 addr = frame;
4354 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4355 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4356 if (save_user_regs(regs, frame, 0, 1))
4357 goto badframe;
4358 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4359 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4360 index d183f87..1867f1a 100644
4361 --- a/arch/powerpc/kernel/signal_64.c
4362 +++ b/arch/powerpc/kernel/signal_64.c
4363 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4364 current->thread.fpscr.val = 0;
4365
4366 /* Set up to return from userspace. */
4367 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4368 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4369 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4370 } else {
4371 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4372 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4373 index ae0843f..f16372c 100644
4374 --- a/arch/powerpc/kernel/traps.c
4375 +++ b/arch/powerpc/kernel/traps.c
4376 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4377 return flags;
4378 }
4379
4380 +extern void gr_handle_kernel_exploit(void);
4381 +
4382 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4383 int signr)
4384 {
4385 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4386 panic("Fatal exception in interrupt");
4387 if (panic_on_oops)
4388 panic("Fatal exception");
4389 +
4390 + gr_handle_kernel_exploit();
4391 +
4392 do_exit(signr);
4393 }
4394
4395 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4396 index b67db22..38825d2 100644
4397 --- a/arch/powerpc/kernel/vdso.c
4398 +++ b/arch/powerpc/kernel/vdso.c
4399 @@ -34,6 +34,7 @@
4400 #include <asm/firmware.h>
4401 #include <asm/vdso.h>
4402 #include <asm/vdso_datapage.h>
4403 +#include <asm/mman.h>
4404
4405 #include "setup.h"
4406
4407 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = VDSO32_MBASE;
4409 #endif
4410
4411 - current->mm->context.vdso_base = 0;
4412 + current->mm->context.vdso_base = ~0UL;
4413
4414 /* vDSO has a problem and was disabled, just don't "enable" it for the
4415 * process
4416 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4417 vdso_base = get_unmapped_area(NULL, vdso_base,
4418 (vdso_pages << PAGE_SHIFT) +
4419 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4420 - 0, 0);
4421 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4422 if (IS_ERR_VALUE(vdso_base)) {
4423 rc = vdso_base;
4424 goto fail_mmapsem;
4425 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4426 index 5eea6f3..5d10396 100644
4427 --- a/arch/powerpc/lib/usercopy_64.c
4428 +++ b/arch/powerpc/lib/usercopy_64.c
4429 @@ -9,22 +9,6 @@
4430 #include <linux/module.h>
4431 #include <asm/uaccess.h>
4432
4433 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4434 -{
4435 - if (likely(access_ok(VERIFY_READ, from, n)))
4436 - n = __copy_from_user(to, from, n);
4437 - else
4438 - memset(to, 0, n);
4439 - return n;
4440 -}
4441 -
4442 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4443 -{
4444 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4445 - n = __copy_to_user(to, from, n);
4446 - return n;
4447 -}
4448 -
4449 unsigned long copy_in_user(void __user *to, const void __user *from,
4450 unsigned long n)
4451 {
4452 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4453 return n;
4454 }
4455
4456 -EXPORT_SYMBOL(copy_from_user);
4457 -EXPORT_SYMBOL(copy_to_user);
4458 EXPORT_SYMBOL(copy_in_user);
4459
4460 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4461 index 08ffcf5..a0ab912 100644
4462 --- a/arch/powerpc/mm/fault.c
4463 +++ b/arch/powerpc/mm/fault.c
4464 @@ -32,6 +32,10 @@
4465 #include <linux/perf_event.h>
4466 #include <linux/magic.h>
4467 #include <linux/ratelimit.h>
4468 +#include <linux/slab.h>
4469 +#include <linux/pagemap.h>
4470 +#include <linux/compiler.h>
4471 +#include <linux/unistd.h>
4472
4473 #include <asm/firmware.h>
4474 #include <asm/page.h>
4475 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4476 }
4477 #endif
4478
4479 +#ifdef CONFIG_PAX_PAGEEXEC
4480 +/*
4481 + * PaX: decide what to do with offenders (regs->nip = fault address)
4482 + *
4483 + * returns 1 when task should be killed
4484 + */
4485 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4486 +{
4487 + return 1;
4488 +}
4489 +
4490 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4491 +{
4492 + unsigned long i;
4493 +
4494 + printk(KERN_ERR "PAX: bytes at PC: ");
4495 + for (i = 0; i < 5; i++) {
4496 + unsigned int c;
4497 + if (get_user(c, (unsigned int __user *)pc+i))
4498 + printk(KERN_CONT "???????? ");
4499 + else
4500 + printk(KERN_CONT "%08x ", c);
4501 + }
4502 + printk("\n");
4503 +}
4504 +#endif
4505 +
4506 /*
4507 * Check whether the instruction at regs->nip is a store using
4508 * an update addressing form which will update r1.
4509 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4510 * indicate errors in DSISR but can validly be set in SRR1.
4511 */
4512 if (trap == 0x400)
4513 - error_code &= 0x48200000;
4514 + error_code &= 0x58200000;
4515 else
4516 is_write = error_code & DSISR_ISSTORE;
4517 #else
4518 @@ -366,7 +397,7 @@ good_area:
4519 * "undefined". Of those that can be set, this is the only
4520 * one which seems bad.
4521 */
4522 - if (error_code & 0x10000000)
4523 + if (error_code & DSISR_GUARDED)
4524 /* Guarded storage error. */
4525 goto bad_area;
4526 #endif /* CONFIG_8xx */
4527 @@ -381,7 +412,7 @@ good_area:
4528 * processors use the same I/D cache coherency mechanism
4529 * as embedded.
4530 */
4531 - if (error_code & DSISR_PROTFAULT)
4532 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4533 goto bad_area;
4534 #endif /* CONFIG_PPC_STD_MMU */
4535
4536 @@ -463,6 +494,23 @@ bad_area:
4537 bad_area_nosemaphore:
4538 /* User mode accesses cause a SIGSEGV */
4539 if (user_mode(regs)) {
4540 +
4541 +#ifdef CONFIG_PAX_PAGEEXEC
4542 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4543 +#ifdef CONFIG_PPC_STD_MMU
4544 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4545 +#else
4546 + if (is_exec && regs->nip == address) {
4547 +#endif
4548 + switch (pax_handle_fetch_fault(regs)) {
4549 + }
4550 +
4551 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4552 + do_group_exit(SIGKILL);
4553 + }
4554 + }
4555 +#endif
4556 +
4557 _exception(SIGSEGV, regs, code, address);
4558 return 0;
4559 }
4560 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4561 index 67a42ed..1c7210c 100644
4562 --- a/arch/powerpc/mm/mmap_64.c
4563 +++ b/arch/powerpc/mm/mmap_64.c
4564 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4565 */
4566 if (mmap_is_legacy()) {
4567 mm->mmap_base = TASK_UNMAPPED_BASE;
4568 +
4569 +#ifdef CONFIG_PAX_RANDMMAP
4570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4571 + mm->mmap_base += mm->delta_mmap;
4572 +#endif
4573 +
4574 mm->get_unmapped_area = arch_get_unmapped_area;
4575 mm->unmap_area = arch_unmap_area;
4576 } else {
4577 mm->mmap_base = mmap_base();
4578 +
4579 +#ifdef CONFIG_PAX_RANDMMAP
4580 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4581 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4582 +#endif
4583 +
4584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4585 mm->unmap_area = arch_unmap_area_topdown;
4586 }
4587 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4588 index 73709f7..6b90313 100644
4589 --- a/arch/powerpc/mm/slice.c
4590 +++ b/arch/powerpc/mm/slice.c
4591 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4592 if ((mm->task_size - len) < addr)
4593 return 0;
4594 vma = find_vma(mm, addr);
4595 - return (!vma || (addr + len) <= vma->vm_start);
4596 + return check_heap_stack_gap(vma, addr, len);
4597 }
4598
4599 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4600 @@ -256,7 +256,7 @@ full_search:
4601 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4602 continue;
4603 }
4604 - if (!vma || addr + len <= vma->vm_start) {
4605 + if (check_heap_stack_gap(vma, addr, len)) {
4606 /*
4607 * Remember the place where we stopped the search:
4608 */
4609 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4610 }
4611 }
4612
4613 - addr = mm->mmap_base;
4614 - while (addr > len) {
4615 + if (mm->mmap_base < len)
4616 + addr = -ENOMEM;
4617 + else
4618 + addr = mm->mmap_base - len;
4619 +
4620 + while (!IS_ERR_VALUE(addr)) {
4621 /* Go down by chunk size */
4622 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4623 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4624
4625 /* Check for hit with different page size */
4626 mask = slice_range_to_mask(addr, len);
4627 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 * return with success:
4629 */
4630 vma = find_vma(mm, addr);
4631 - if (!vma || (addr + len) <= vma->vm_start) {
4632 + if (check_heap_stack_gap(vma, addr, len)) {
4633 /* remember the address as a hint for next time */
4634 if (use_cache)
4635 mm->free_area_cache = addr;
4636 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4637 mm->cached_hole_size = vma->vm_start - addr;
4638
4639 /* try just below the current vma->vm_start */
4640 - addr = vma->vm_start;
4641 + addr = skip_heap_stack_gap(vma, len);
4642 }
4643
4644 /*
4645 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4646 if (fixed && addr > (mm->task_size - len))
4647 return -EINVAL;
4648
4649 +#ifdef CONFIG_PAX_RANDMMAP
4650 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4651 + addr = 0;
4652 +#endif
4653 +
4654 /* If hint, make sure it matches our alignment restrictions */
4655 if (!fixed && addr) {
4656 addr = _ALIGN_UP(addr, 1ul << pshift);
4657 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4658 index c797832..ce575c8 100644
4659 --- a/arch/s390/include/asm/atomic.h
4660 +++ b/arch/s390/include/asm/atomic.h
4661 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4662 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4664
4665 +#define atomic64_read_unchecked(v) atomic64_read(v)
4666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674 +
4675 #define smp_mb__before_atomic_dec() smp_mb()
4676 #define smp_mb__after_atomic_dec() smp_mb()
4677 #define smp_mb__before_atomic_inc() smp_mb()
4678 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4679 index 4d7ccac..d03d0ad 100644
4680 --- a/arch/s390/include/asm/cache.h
4681 +++ b/arch/s390/include/asm/cache.h
4682 @@ -9,8 +9,10 @@
4683 #ifndef __ARCH_S390_CACHE_H
4684 #define __ARCH_S390_CACHE_H
4685
4686 -#define L1_CACHE_BYTES 256
4687 +#include <linux/const.h>
4688 +
4689 #define L1_CACHE_SHIFT 8
4690 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define NET_SKB_PAD 32
4692
4693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4694 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4695 index 9b94a16..63d4034 100644
4696 --- a/arch/s390/include/asm/elf.h
4697 +++ b/arch/s390/include/asm/elf.h
4698 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4699 the loader. We need to make sure that it is out of the way of the program
4700 that it will "exec", and that there is sufficient room for the brk. */
4701
4702 -extern unsigned long randomize_et_dyn(unsigned long base);
4703 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4704 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4705 +
4706 +#ifdef CONFIG_PAX_ASLR
4707 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4708 +
4709 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4711 +#endif
4712
4713 /* This yields a mask that user programs can use to figure out what
4714 instruction set this CPU supports. */
4715 @@ -209,7 +215,4 @@ struct linux_binprm;
4716 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4717 int arch_setup_additional_pages(struct linux_binprm *, int);
4718
4719 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4720 -#define arch_randomize_brk arch_randomize_brk
4721 -
4722 #endif
4723 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4724 index c4a93d6..4d2a9b4 100644
4725 --- a/arch/s390/include/asm/exec.h
4726 +++ b/arch/s390/include/asm/exec.h
4727 @@ -7,6 +7,6 @@
4728 #ifndef __ASM_EXEC_H
4729 #define __ASM_EXEC_H
4730
4731 -extern unsigned long arch_align_stack(unsigned long sp);
4732 +#define arch_align_stack(x) ((x) & ~0xfUL)
4733
4734 #endif /* __ASM_EXEC_H */
4735 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4736 index a8ab18b..75ddbf0 100644
4737 --- a/arch/s390/include/asm/uaccess.h
4738 +++ b/arch/s390/include/asm/uaccess.h
4739 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4740 copy_to_user(void __user *to, const void *from, unsigned long n)
4741 {
4742 might_fault();
4743 +
4744 + if ((long)n < 0)
4745 + return n;
4746 +
4747 if (access_ok(VERIFY_WRITE, to, n))
4748 n = __copy_to_user(to, from, n);
4749 return n;
4750 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4751 static inline unsigned long __must_check
4752 __copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754 + if ((long)n < 0)
4755 + return n;
4756 +
4757 if (__builtin_constant_p(n) && (n <= 256))
4758 return uaccess.copy_from_user_small(n, from, to);
4759 else
4760 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4761 static inline unsigned long __must_check
4762 copy_from_user(void *to, const void __user *from, unsigned long n)
4763 {
4764 - unsigned int sz = __compiletime_object_size(to);
4765 + size_t sz = __compiletime_object_size(to);
4766
4767 might_fault();
4768 - if (unlikely(sz != -1 && sz < n)) {
4769 +
4770 + if ((long)n < 0)
4771 + return n;
4772 +
4773 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4774 copy_from_user_overflow();
4775 return n;
4776 }
4777 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4778 index 46412b1..e32874f 100644
4779 --- a/arch/s390/kernel/module.c
4780 +++ b/arch/s390/kernel/module.c
4781 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4782
4783 /* Increase core size by size of got & plt and set start
4784 offsets for got and plt. */
4785 - me->core_size = ALIGN(me->core_size, 4);
4786 - me->arch.got_offset = me->core_size;
4787 - me->core_size += me->arch.got_size;
4788 - me->arch.plt_offset = me->core_size;
4789 - me->core_size += me->arch.plt_size;
4790 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4791 + me->arch.got_offset = me->core_size_rw;
4792 + me->core_size_rw += me->arch.got_size;
4793 + me->arch.plt_offset = me->core_size_rx;
4794 + me->core_size_rx += me->arch.plt_size;
4795 return 0;
4796 }
4797
4798 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 if (info->got_initialized == 0) {
4800 Elf_Addr *gotent;
4801
4802 - gotent = me->module_core + me->arch.got_offset +
4803 + gotent = me->module_core_rw + me->arch.got_offset +
4804 info->got_offset;
4805 *gotent = val;
4806 info->got_initialized = 1;
4807 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 else if (r_type == R_390_GOTENT ||
4809 r_type == R_390_GOTPLTENT)
4810 *(unsigned int *) loc =
4811 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4812 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4813 else if (r_type == R_390_GOT64 ||
4814 r_type == R_390_GOTPLT64)
4815 *(unsigned long *) loc = val;
4816 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4818 if (info->plt_initialized == 0) {
4819 unsigned int *ip;
4820 - ip = me->module_core + me->arch.plt_offset +
4821 + ip = me->module_core_rx + me->arch.plt_offset +
4822 info->plt_offset;
4823 #ifndef CONFIG_64BIT
4824 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4825 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 val - loc + 0xffffUL < 0x1ffffeUL) ||
4827 (r_type == R_390_PLT32DBL &&
4828 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4829 - val = (Elf_Addr) me->module_core +
4830 + val = (Elf_Addr) me->module_core_rx +
4831 me->arch.plt_offset +
4832 info->plt_offset;
4833 val += rela->r_addend - loc;
4834 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4836 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4837 val = val + rela->r_addend -
4838 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4839 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4840 if (r_type == R_390_GOTOFF16)
4841 *(unsigned short *) loc = val;
4842 else if (r_type == R_390_GOTOFF32)
4843 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 break;
4845 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4846 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4847 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4848 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4849 rela->r_addend - loc;
4850 if (r_type == R_390_GOTPC)
4851 *(unsigned int *) loc = val;
4852 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4853 index 7331753..dd71de4 100644
4854 --- a/arch/s390/kernel/process.c
4855 +++ b/arch/s390/kernel/process.c
4856 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4857 }
4858 return 0;
4859 }
4860 -
4861 -unsigned long arch_align_stack(unsigned long sp)
4862 -{
4863 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4864 - sp -= get_random_int() & ~PAGE_MASK;
4865 - return sp & ~0xf;
4866 -}
4867 -
4868 -static inline unsigned long brk_rnd(void)
4869 -{
4870 - /* 8MB for 32bit, 1GB for 64bit */
4871 - if (is_32bit_task())
4872 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4873 - else
4874 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4875 -}
4876 -
4877 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4878 -{
4879 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4880 -
4881 - if (ret < mm->brk)
4882 - return mm->brk;
4883 - return ret;
4884 -}
4885 -
4886 -unsigned long randomize_et_dyn(unsigned long base)
4887 -{
4888 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4889 -
4890 - if (!(current->flags & PF_RANDOMIZE))
4891 - return base;
4892 - if (ret < base)
4893 - return base;
4894 - return ret;
4895 -}
4896 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4897 index c59a5ef..3fae59c 100644
4898 --- a/arch/s390/mm/mmap.c
4899 +++ b/arch/s390/mm/mmap.c
4900 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4901 */
4902 if (mmap_is_legacy()) {
4903 mm->mmap_base = TASK_UNMAPPED_BASE;
4904 +
4905 +#ifdef CONFIG_PAX_RANDMMAP
4906 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4907 + mm->mmap_base += mm->delta_mmap;
4908 +#endif
4909 +
4910 mm->get_unmapped_area = arch_get_unmapped_area;
4911 mm->unmap_area = arch_unmap_area;
4912 } else {
4913 mm->mmap_base = mmap_base();
4914 +
4915 +#ifdef CONFIG_PAX_RANDMMAP
4916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4917 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4918 +#endif
4919 +
4920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4921 mm->unmap_area = arch_unmap_area_topdown;
4922 }
4923 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4924 */
4925 if (mmap_is_legacy()) {
4926 mm->mmap_base = TASK_UNMAPPED_BASE;
4927 +
4928 +#ifdef CONFIG_PAX_RANDMMAP
4929 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4930 + mm->mmap_base += mm->delta_mmap;
4931 +#endif
4932 +
4933 mm->get_unmapped_area = s390_get_unmapped_area;
4934 mm->unmap_area = arch_unmap_area;
4935 } else {
4936 mm->mmap_base = mmap_base();
4937 +
4938 +#ifdef CONFIG_PAX_RANDMMAP
4939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4940 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4941 +#endif
4942 +
4943 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4944 mm->unmap_area = arch_unmap_area_topdown;
4945 }
4946 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4947 index ae3d59f..f65f075 100644
4948 --- a/arch/score/include/asm/cache.h
4949 +++ b/arch/score/include/asm/cache.h
4950 @@ -1,7 +1,9 @@
4951 #ifndef _ASM_SCORE_CACHE_H
4952 #define _ASM_SCORE_CACHE_H
4953
4954 +#include <linux/const.h>
4955 +
4956 #define L1_CACHE_SHIFT 4
4957 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4959
4960 #endif /* _ASM_SCORE_CACHE_H */
4961 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4962 index f9f3cd5..58ff438 100644
4963 --- a/arch/score/include/asm/exec.h
4964 +++ b/arch/score/include/asm/exec.h
4965 @@ -1,6 +1,6 @@
4966 #ifndef _ASM_SCORE_EXEC_H
4967 #define _ASM_SCORE_EXEC_H
4968
4969 -extern unsigned long arch_align_stack(unsigned long sp);
4970 +#define arch_align_stack(x) (x)
4971
4972 #endif /* _ASM_SCORE_EXEC_H */
4973 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4974 index 637970c..0b6556b 100644
4975 --- a/arch/score/kernel/process.c
4976 +++ b/arch/score/kernel/process.c
4977 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4978
4979 return task_pt_regs(task)->cp0_epc;
4980 }
4981 -
4982 -unsigned long arch_align_stack(unsigned long sp)
4983 -{
4984 - return sp;
4985 -}
4986 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4987 index ef9e555..331bd29 100644
4988 --- a/arch/sh/include/asm/cache.h
4989 +++ b/arch/sh/include/asm/cache.h
4990 @@ -9,10 +9,11 @@
4991 #define __ASM_SH_CACHE_H
4992 #ifdef __KERNEL__
4993
4994 +#include <linux/const.h>
4995 #include <linux/init.h>
4996 #include <cpu/cache.h>
4997
4998 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5000
5001 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5002
5003 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5004 index afeb710..d1d1289 100644
5005 --- a/arch/sh/mm/mmap.c
5006 +++ b/arch/sh/mm/mmap.c
5007 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5008 addr = PAGE_ALIGN(addr);
5009
5010 vma = find_vma(mm, addr);
5011 - if (TASK_SIZE - len >= addr &&
5012 - (!vma || addr + len <= vma->vm_start))
5013 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5014 return addr;
5015 }
5016
5017 @@ -106,7 +105,7 @@ full_search:
5018 }
5019 return -ENOMEM;
5020 }
5021 - if (likely(!vma || addr + len <= vma->vm_start)) {
5022 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5023 /*
5024 * Remember the place where we stopped the search:
5025 */
5026 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 addr = PAGE_ALIGN(addr);
5028
5029 vma = find_vma(mm, addr);
5030 - if (TASK_SIZE - len >= addr &&
5031 - (!vma || addr + len <= vma->vm_start))
5032 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5033 return addr;
5034 }
5035
5036 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 /* make sure it can fit in the remaining address space */
5038 if (likely(addr > len)) {
5039 vma = find_vma(mm, addr-len);
5040 - if (!vma || addr <= vma->vm_start) {
5041 + if (check_heap_stack_gap(vma, addr - len, len)) {
5042 /* remember the address as a hint for next time */
5043 return (mm->free_area_cache = addr-len);
5044 }
5045 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5046 if (unlikely(mm->mmap_base < len))
5047 goto bottomup;
5048
5049 - addr = mm->mmap_base-len;
5050 - if (do_colour_align)
5051 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5052 + addr = mm->mmap_base - len;
5053
5054 do {
5055 + if (do_colour_align)
5056 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 /*
5058 * Lookup failure means no vma is above this address,
5059 * else if new region fits below vma->vm_start,
5060 * return with success:
5061 */
5062 vma = find_vma(mm, addr);
5063 - if (likely(!vma || addr+len <= vma->vm_start)) {
5064 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5065 /* remember the address as a hint for next time */
5066 return (mm->free_area_cache = addr);
5067 }
5068 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5069 mm->cached_hole_size = vma->vm_start - addr;
5070
5071 /* try just below the current vma->vm_start */
5072 - addr = vma->vm_start-len;
5073 - if (do_colour_align)
5074 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5075 - } while (likely(len < vma->vm_start));
5076 + addr = skip_heap_stack_gap(vma, len);
5077 + } while (!IS_ERR_VALUE(addr));
5078
5079 bottomup:
5080 /*
5081 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5082 index ce35a1c..2e7b8f9 100644
5083 --- a/arch/sparc/include/asm/atomic_64.h
5084 +++ b/arch/sparc/include/asm/atomic_64.h
5085 @@ -14,18 +14,40 @@
5086 #define ATOMIC64_INIT(i) { (i) }
5087
5088 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5089 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5090 +{
5091 + return v->counter;
5092 +}
5093 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5094 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5095 +{
5096 + return v->counter;
5097 +}
5098
5099 #define atomic_set(v, i) (((v)->counter) = i)
5100 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5101 +{
5102 + v->counter = i;
5103 +}
5104 #define atomic64_set(v, i) (((v)->counter) = i)
5105 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5106 +{
5107 + v->counter = i;
5108 +}
5109
5110 extern void atomic_add(int, atomic_t *);
5111 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5112 extern void atomic64_add(long, atomic64_t *);
5113 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5114 extern void atomic_sub(int, atomic_t *);
5115 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_sub(long, atomic64_t *);
5117 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5118
5119 extern int atomic_add_ret(int, atomic_t *);
5120 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5121 extern long atomic64_add_ret(long, atomic64_t *);
5122 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5123 extern int atomic_sub_ret(int, atomic_t *);
5124 extern long atomic64_sub_ret(long, atomic64_t *);
5125
5126 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5127 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5128
5129 #define atomic_inc_return(v) atomic_add_ret(1, v)
5130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5131 +{
5132 + return atomic_add_ret_unchecked(1, v);
5133 +}
5134 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5135 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5136 +{
5137 + return atomic64_add_ret_unchecked(1, v);
5138 +}
5139
5140 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5141 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5142
5143 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5144 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5145 +{
5146 + return atomic_add_ret_unchecked(i, v);
5147 +}
5148 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5149 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5150 +{
5151 + return atomic64_add_ret_unchecked(i, v);
5152 +}
5153
5154 /*
5155 * atomic_inc_and_test - increment and test
5156 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5157 * other cases.
5158 */
5159 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5160 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5161 +{
5162 + return atomic_inc_return_unchecked(v) == 0;
5163 +}
5164 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5165
5166 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5167 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5168 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5169
5170 #define atomic_inc(v) atomic_add(1, v)
5171 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5172 +{
5173 + atomic_add_unchecked(1, v);
5174 +}
5175 #define atomic64_inc(v) atomic64_add(1, v)
5176 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5177 +{
5178 + atomic64_add_unchecked(1, v);
5179 +}
5180
5181 #define atomic_dec(v) atomic_sub(1, v)
5182 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5183 +{
5184 + atomic_sub_unchecked(1, v);
5185 +}
5186 #define atomic64_dec(v) atomic64_sub(1, v)
5187 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5188 +{
5189 + atomic64_sub_unchecked(1, v);
5190 +}
5191
5192 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5193 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5194
5195 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5196 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5197 +{
5198 + return cmpxchg(&v->counter, old, new);
5199 +}
5200 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5201 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5202 +{
5203 + return xchg(&v->counter, new);
5204 +}
5205
5206 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5207 {
5208 - int c, old;
5209 + int c, old, new;
5210 c = atomic_read(v);
5211 for (;;) {
5212 - if (unlikely(c == (u)))
5213 + if (unlikely(c == u))
5214 break;
5215 - old = atomic_cmpxchg((v), c, c + (a));
5216 +
5217 + asm volatile("addcc %2, %0, %0\n"
5218 +
5219 +#ifdef CONFIG_PAX_REFCOUNT
5220 + "tvs %%icc, 6\n"
5221 +#endif
5222 +
5223 + : "=r" (new)
5224 + : "0" (c), "ir" (a)
5225 + : "cc");
5226 +
5227 + old = atomic_cmpxchg(v, c, new);
5228 if (likely(old == c))
5229 break;
5230 c = old;
5231 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 #define atomic64_cmpxchg(v, o, n) \
5233 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5234 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5235 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5236 +{
5237 + return xchg(&v->counter, new);
5238 +}
5239
5240 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5241 {
5242 - long c, old;
5243 + long c, old, new;
5244 c = atomic64_read(v);
5245 for (;;) {
5246 - if (unlikely(c == (u)))
5247 + if (unlikely(c == u))
5248 break;
5249 - old = atomic64_cmpxchg((v), c, c + (a));
5250 +
5251 + asm volatile("addcc %2, %0, %0\n"
5252 +
5253 +#ifdef CONFIG_PAX_REFCOUNT
5254 + "tvs %%xcc, 6\n"
5255 +#endif
5256 +
5257 + : "=r" (new)
5258 + : "0" (c), "ir" (a)
5259 + : "cc");
5260 +
5261 + old = atomic64_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 }
5266 - return c != (u);
5267 + return c != u;
5268 }
5269
5270 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5271 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5272 index 5bb6991..5c2132e 100644
5273 --- a/arch/sparc/include/asm/cache.h
5274 +++ b/arch/sparc/include/asm/cache.h
5275 @@ -7,10 +7,12 @@
5276 #ifndef _SPARC_CACHE_H
5277 #define _SPARC_CACHE_H
5278
5279 +#include <linux/const.h>
5280 +
5281 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5282
5283 #define L1_CACHE_SHIFT 5
5284 -#define L1_CACHE_BYTES 32
5285 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5286
5287 #ifdef CONFIG_SPARC32
5288 #define SMP_CACHE_BYTES_SHIFT 5
5289 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5290 index 2d4d755..81b6662 100644
5291 --- a/arch/sparc/include/asm/elf_32.h
5292 +++ b/arch/sparc/include/asm/elf_32.h
5293 @@ -114,6 +114,13 @@ typedef struct {
5294
5295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5296
5297 +#ifdef CONFIG_PAX_ASLR
5298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5299 +
5300 +#define PAX_DELTA_MMAP_LEN 16
5301 +#define PAX_DELTA_STACK_LEN 16
5302 +#endif
5303 +
5304 /* This yields a mask that user programs can use to figure out what
5305 instruction set this cpu supports. This can NOT be done in userspace
5306 on Sparc. */
5307 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5308 index 7df8b7f..4946269 100644
5309 --- a/arch/sparc/include/asm/elf_64.h
5310 +++ b/arch/sparc/include/asm/elf_64.h
5311 @@ -180,6 +180,13 @@ typedef struct {
5312 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5313 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5314
5315 +#ifdef CONFIG_PAX_ASLR
5316 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5317 +
5318 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5319 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5320 +#endif
5321 +
5322 extern unsigned long sparc64_elf_hwcap;
5323 #define ELF_HWCAP sparc64_elf_hwcap
5324
5325 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5326 index 9b1c36d..209298b 100644
5327 --- a/arch/sparc/include/asm/pgalloc_32.h
5328 +++ b/arch/sparc/include/asm/pgalloc_32.h
5329 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5330 }
5331
5332 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5333 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5334
5335 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5336 unsigned long address)
5337 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5338 index 40b2d7a..22a665b 100644
5339 --- a/arch/sparc/include/asm/pgalloc_64.h
5340 +++ b/arch/sparc/include/asm/pgalloc_64.h
5341 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5342 }
5343
5344 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5345 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5346
5347 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5348 {
5349 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5350 index 6fc1348..390c50a 100644
5351 --- a/arch/sparc/include/asm/pgtable_32.h
5352 +++ b/arch/sparc/include/asm/pgtable_32.h
5353 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5354 #define PAGE_SHARED SRMMU_PAGE_SHARED
5355 #define PAGE_COPY SRMMU_PAGE_COPY
5356 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5357 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5358 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5359 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5360 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5361
5362 /* Top-level page directory - dummy used by init-mm.
5363 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5364
5365 /* xwr */
5366 #define __P000 PAGE_NONE
5367 -#define __P001 PAGE_READONLY
5368 -#define __P010 PAGE_COPY
5369 -#define __P011 PAGE_COPY
5370 +#define __P001 PAGE_READONLY_NOEXEC
5371 +#define __P010 PAGE_COPY_NOEXEC
5372 +#define __P011 PAGE_COPY_NOEXEC
5373 #define __P100 PAGE_READONLY
5374 #define __P101 PAGE_READONLY
5375 #define __P110 PAGE_COPY
5376 #define __P111 PAGE_COPY
5377
5378 #define __S000 PAGE_NONE
5379 -#define __S001 PAGE_READONLY
5380 -#define __S010 PAGE_SHARED
5381 -#define __S011 PAGE_SHARED
5382 +#define __S001 PAGE_READONLY_NOEXEC
5383 +#define __S010 PAGE_SHARED_NOEXEC
5384 +#define __S011 PAGE_SHARED_NOEXEC
5385 #define __S100 PAGE_READONLY
5386 #define __S101 PAGE_READONLY
5387 #define __S110 PAGE_SHARED
5388 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5389 index 79da178..c2eede8 100644
5390 --- a/arch/sparc/include/asm/pgtsrmmu.h
5391 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5392 @@ -115,6 +115,11 @@
5393 SRMMU_EXEC | SRMMU_REF)
5394 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5395 SRMMU_EXEC | SRMMU_REF)
5396 +
5397 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400 +
5401 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5402 SRMMU_DIRTY | SRMMU_REF)
5403
5404 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5405 index 9689176..63c18ea 100644
5406 --- a/arch/sparc/include/asm/spinlock_64.h
5407 +++ b/arch/sparc/include/asm/spinlock_64.h
5408 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5409
5410 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5411
5412 -static void inline arch_read_lock(arch_rwlock_t *lock)
5413 +static inline void arch_read_lock(arch_rwlock_t *lock)
5414 {
5415 unsigned long tmp1, tmp2;
5416
5417 __asm__ __volatile__ (
5418 "1: ldsw [%2], %0\n"
5419 " brlz,pn %0, 2f\n"
5420 -"4: add %0, 1, %1\n"
5421 +"4: addcc %0, 1, %1\n"
5422 +
5423 +#ifdef CONFIG_PAX_REFCOUNT
5424 +" tvs %%icc, 6\n"
5425 +#endif
5426 +
5427 " cas [%2], %0, %1\n"
5428 " cmp %0, %1\n"
5429 " bne,pn %%icc, 1b\n"
5430 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5431 " .previous"
5432 : "=&r" (tmp1), "=&r" (tmp2)
5433 : "r" (lock)
5434 - : "memory");
5435 + : "memory", "cc");
5436 }
5437
5438 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5439 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5440 {
5441 int tmp1, tmp2;
5442
5443 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 "1: ldsw [%2], %0\n"
5445 " brlz,a,pn %0, 2f\n"
5446 " mov 0, %0\n"
5447 -" add %0, 1, %1\n"
5448 +" addcc %0, 1, %1\n"
5449 +
5450 +#ifdef CONFIG_PAX_REFCOUNT
5451 +" tvs %%icc, 6\n"
5452 +#endif
5453 +
5454 " cas [%2], %0, %1\n"
5455 " cmp %0, %1\n"
5456 " bne,pn %%icc, 1b\n"
5457 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5458 return tmp1;
5459 }
5460
5461 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5463 {
5464 unsigned long tmp1, tmp2;
5465
5466 __asm__ __volatile__(
5467 "1: lduw [%2], %0\n"
5468 -" sub %0, 1, %1\n"
5469 +" subcc %0, 1, %1\n"
5470 +
5471 +#ifdef CONFIG_PAX_REFCOUNT
5472 +" tvs %%icc, 6\n"
5473 +#endif
5474 +
5475 " cas [%2], %0, %1\n"
5476 " cmp %0, %1\n"
5477 " bne,pn %%xcc, 1b\n"
5478 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482 -static void inline arch_write_lock(arch_rwlock_t *lock)
5483 +static inline void arch_write_lock(arch_rwlock_t *lock)
5484 {
5485 unsigned long mask, tmp1, tmp2;
5486
5487 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5492 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5493 {
5494 __asm__ __volatile__(
5495 " stw %%g0, [%0]"
5496 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 : "memory");
5498 }
5499
5500 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5501 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5502 {
5503 unsigned long mask, tmp1, tmp2, result;
5504
5505 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5506 index e6cd224..3a71793 100644
5507 --- a/arch/sparc/include/asm/thread_info_32.h
5508 +++ b/arch/sparc/include/asm/thread_info_32.h
5509 @@ -49,6 +49,8 @@ struct thread_info {
5510 unsigned long w_saved;
5511
5512 struct restart_block restart_block;
5513 +
5514 + unsigned long lowest_stack;
5515 };
5516
5517 /*
5518 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5519 index cfa8c38..13f30d3 100644
5520 --- a/arch/sparc/include/asm/thread_info_64.h
5521 +++ b/arch/sparc/include/asm/thread_info_64.h
5522 @@ -63,6 +63,8 @@ struct thread_info {
5523 struct pt_regs *kern_una_regs;
5524 unsigned int kern_una_insn;
5525
5526 + unsigned long lowest_stack;
5527 +
5528 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5529 };
5530
5531 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5532 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5533 /* flag bit 6 is available */
5534 #define TIF_32BIT 7 /* 32-bit binary */
5535 -/* flag bit 8 is available */
5536 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5537 #define TIF_SECCOMP 9 /* secure computing */
5538 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5539 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5540 +
5541 /* NOTE: Thread flags >= 12 should be ones we have no interest
5542 * in using in assembly, else we can't use the mask as
5543 * an immediate value in instructions such as andcc.
5544 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5545 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5546 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5547 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5548 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5549
5550 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5551 _TIF_DO_NOTIFY_RESUME_MASK | \
5552 _TIF_NEED_RESCHED)
5553 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5554
5555 +#define _TIF_WORK_SYSCALL \
5556 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5558 +
5559 +
5560 /*
5561 * Thread-synchronous status.
5562 *
5563 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5564 index 0167d26..9acd8ed 100644
5565 --- a/arch/sparc/include/asm/uaccess.h
5566 +++ b/arch/sparc/include/asm/uaccess.h
5567 @@ -1,5 +1,13 @@
5568 #ifndef ___ASM_SPARC_UACCESS_H
5569 #define ___ASM_SPARC_UACCESS_H
5570 +
5571 +#ifdef __KERNEL__
5572 +#ifndef __ASSEMBLY__
5573 +#include <linux/types.h>
5574 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5575 +#endif
5576 +#endif
5577 +
5578 #if defined(__sparc__) && defined(__arch64__)
5579 #include <asm/uaccess_64.h>
5580 #else
5581 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5582 index 53a28dd..50c38c3 100644
5583 --- a/arch/sparc/include/asm/uaccess_32.h
5584 +++ b/arch/sparc/include/asm/uaccess_32.h
5585 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5586
5587 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5588 {
5589 - if (n && __access_ok((unsigned long) to, n))
5590 + if ((long)n < 0)
5591 + return n;
5592 +
5593 + if (n && __access_ok((unsigned long) to, n)) {
5594 + if (!__builtin_constant_p(n))
5595 + check_object_size(from, n, true);
5596 return __copy_user(to, (__force void __user *) from, n);
5597 - else
5598 + } else
5599 return n;
5600 }
5601
5602 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5603 {
5604 + if ((long)n < 0)
5605 + return n;
5606 +
5607 + if (!__builtin_constant_p(n))
5608 + check_object_size(from, n, true);
5609 +
5610 return __copy_user(to, (__force void __user *) from, n);
5611 }
5612
5613 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5614 {
5615 - if (n && __access_ok((unsigned long) from, n))
5616 + if ((long)n < 0)
5617 + return n;
5618 +
5619 + if (n && __access_ok((unsigned long) from, n)) {
5620 + if (!__builtin_constant_p(n))
5621 + check_object_size(to, n, false);
5622 return __copy_user((__force void __user *) to, from, n);
5623 - else
5624 + } else
5625 return n;
5626 }
5627
5628 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5629 {
5630 + if ((long)n < 0)
5631 + return n;
5632 +
5633 return __copy_user((__force void __user *) to, from, n);
5634 }
5635
5636 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5637 index 7c831d8..d440ca7 100644
5638 --- a/arch/sparc/include/asm/uaccess_64.h
5639 +++ b/arch/sparc/include/asm/uaccess_64.h
5640 @@ -10,6 +10,7 @@
5641 #include <linux/compiler.h>
5642 #include <linux/string.h>
5643 #include <linux/thread_info.h>
5644 +#include <linux/kernel.h>
5645 #include <asm/asi.h>
5646 #include <asm/spitfire.h>
5647 #include <asm-generic/uaccess-unaligned.h>
5648 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5649 static inline unsigned long __must_check
5650 copy_from_user(void *to, const void __user *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_from_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(to, size, false);
5660 +
5661 + ret = ___copy_from_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_from_user_fixup(to, from, size);
5664
5665 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5666 static inline unsigned long __must_check
5667 copy_to_user(void __user *to, const void *from, unsigned long size)
5668 {
5669 - unsigned long ret = ___copy_to_user(to, from, size);
5670 + unsigned long ret;
5671
5672 + if ((long)size < 0 || size > INT_MAX)
5673 + return size;
5674 +
5675 + if (!__builtin_constant_p(size))
5676 + check_object_size(from, size, true);
5677 +
5678 + ret = ___copy_to_user(to, from, size);
5679 if (unlikely(ret))
5680 ret = copy_to_user_fixup(to, from, size);
5681 return ret;
5682 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5683 index 6cf591b..b49e65a 100644
5684 --- a/arch/sparc/kernel/Makefile
5685 +++ b/arch/sparc/kernel/Makefile
5686 @@ -3,7 +3,7 @@
5687 #
5688
5689 asflags-y := -ansi
5690 -ccflags-y := -Werror
5691 +#ccflags-y := -Werror
5692
5693 extra-y := head_$(BITS).o
5694
5695 diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5696 index f8b6eee..87f60ee 100644
5697 --- a/arch/sparc/kernel/leon_kernel.c
5698 +++ b/arch/sparc/kernel/leon_kernel.c
5699 @@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5700 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5701 {
5702 unsigned int eirq;
5703 + struct irq_bucket *p;
5704 int cpu = sparc_leon3_cpuid();
5705
5706 eirq = leon_eirq_get(cpu);
5707 - if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5708 - generic_handle_irq(irq_map[eirq]->irq);
5709 + p = irq_map[eirq];
5710 + if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5711 + generic_handle_irq(p->irq);
5712 }
5713
5714 /* The extended IRQ controller has been found, this function registers it */
5715 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5716 index 14006d8..8146238 100644
5717 --- a/arch/sparc/kernel/process_32.c
5718 +++ b/arch/sparc/kernel/process_32.c
5719 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5720
5721 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5722 r->psr, r->pc, r->npc, r->y, print_tainted());
5723 - printk("PC: <%pS>\n", (void *) r->pc);
5724 + printk("PC: <%pA>\n", (void *) r->pc);
5725 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5726 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5727 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5728 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5729 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5730 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5731 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5732 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5733
5734 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5735 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5736 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5737 rw = (struct reg_window32 *) fp;
5738 pc = rw->ins[7];
5739 printk("[%08lx : ", pc);
5740 - printk("%pS ] ", (void *) pc);
5741 + printk("%pA ] ", (void *) pc);
5742 fp = rw->ins[6];
5743 } while (++count < 16);
5744 printk("\n");
5745 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5746 index aff0c72..9067b39 100644
5747 --- a/arch/sparc/kernel/process_64.c
5748 +++ b/arch/sparc/kernel/process_64.c
5749 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5750 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5751 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5752 if (regs->tstate & TSTATE_PRIV)
5753 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5754 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5755 }
5756
5757 void show_regs(struct pt_regs *regs)
5758 {
5759 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5760 regs->tpc, regs->tnpc, regs->y, print_tainted());
5761 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5762 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5763 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5764 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5765 regs->u_regs[3]);
5766 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5767 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5768 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5769 regs->u_regs[15]);
5770 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5771 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5772 show_regwindow(regs);
5773 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5774 }
5775 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5776 ((tp && tp->task) ? tp->task->pid : -1));
5777
5778 if (gp->tstate & TSTATE_PRIV) {
5779 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5780 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5781 (void *) gp->tpc,
5782 (void *) gp->o7,
5783 (void *) gp->i7,
5784 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5785 index 484daba..0674139 100644
5786 --- a/arch/sparc/kernel/ptrace_64.c
5787 +++ b/arch/sparc/kernel/ptrace_64.c
5788 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5789 return ret;
5790 }
5791
5792 +#ifdef CONFIG_GRKERNSEC_SETXID
5793 +extern void gr_delayed_cred_worker(void);
5794 +#endif
5795 +
5796 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797 {
5798 int ret = 0;
5799 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5800 /* do the secure computing check first */
5801 secure_computing_strict(regs->u_regs[UREG_G1]);
5802
5803 +#ifdef CONFIG_GRKERNSEC_SETXID
5804 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5805 + gr_delayed_cred_worker();
5806 +#endif
5807 +
5808 if (test_thread_flag(TIF_SYSCALL_TRACE))
5809 ret = tracehook_report_syscall_entry(regs);
5810
5811 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812
5813 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5814 {
5815 +#ifdef CONFIG_GRKERNSEC_SETXID
5816 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5817 + gr_delayed_cred_worker();
5818 +#endif
5819 +
5820 audit_syscall_exit(regs);
5821
5822 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5823 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5824 index 0c9b31b..7cb7aee 100644
5825 --- a/arch/sparc/kernel/sys_sparc_32.c
5826 +++ b/arch/sparc/kernel/sys_sparc_32.c
5827 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5828 if (len > TASK_SIZE - PAGE_SIZE)
5829 return -ENOMEM;
5830 if (!addr)
5831 - addr = TASK_UNMAPPED_BASE;
5832 + addr = current->mm->mmap_base;
5833
5834 if (flags & MAP_SHARED)
5835 addr = COLOUR_ALIGN(addr);
5836 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5837 /* At this point: (!vmm || addr < vmm->vm_end). */
5838 if (TASK_SIZE - PAGE_SIZE - len < addr)
5839 return -ENOMEM;
5840 - if (!vmm || addr + len <= vmm->vm_start)
5841 + if (check_heap_stack_gap(vmm, addr, len))
5842 return addr;
5843 addr = vmm->vm_end;
5844 if (flags & MAP_SHARED)
5845 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5846 index 11c6c96..3ec33e8 100644
5847 --- a/arch/sparc/kernel/sys_sparc_64.c
5848 +++ b/arch/sparc/kernel/sys_sparc_64.c
5849 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5850 /* We do not accept a shared mapping if it would violate
5851 * cache aliasing constraints.
5852 */
5853 - if ((flags & MAP_SHARED) &&
5854 + if ((filp || (flags & MAP_SHARED)) &&
5855 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5856 return -EINVAL;
5857 return addr;
5858 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5859 if (filp || (flags & MAP_SHARED))
5860 do_color_align = 1;
5861
5862 +#ifdef CONFIG_PAX_RANDMMAP
5863 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5864 +#endif
5865 +
5866 if (addr) {
5867 if (do_color_align)
5868 addr = COLOUR_ALIGN(addr, pgoff);
5869 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5870 addr = PAGE_ALIGN(addr);
5871
5872 vma = find_vma(mm, addr);
5873 - if (task_size - len >= addr &&
5874 - (!vma || addr + len <= vma->vm_start))
5875 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5876 return addr;
5877 }
5878
5879 if (len > mm->cached_hole_size) {
5880 - start_addr = addr = mm->free_area_cache;
5881 + start_addr = addr = mm->free_area_cache;
5882 } else {
5883 - start_addr = addr = TASK_UNMAPPED_BASE;
5884 + start_addr = addr = mm->mmap_base;
5885 mm->cached_hole_size = 0;
5886 }
5887
5888 @@ -157,14 +160,14 @@ full_search:
5889 vma = find_vma(mm, VA_EXCLUDE_END);
5890 }
5891 if (unlikely(task_size < addr)) {
5892 - if (start_addr != TASK_UNMAPPED_BASE) {
5893 - start_addr = addr = TASK_UNMAPPED_BASE;
5894 + if (start_addr != mm->mmap_base) {
5895 + start_addr = addr = mm->mmap_base;
5896 mm->cached_hole_size = 0;
5897 goto full_search;
5898 }
5899 return -ENOMEM;
5900 }
5901 - if (likely(!vma || addr + len <= vma->vm_start)) {
5902 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5903 /*
5904 * Remember the place where we stopped the search:
5905 */
5906 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5907 /* We do not accept a shared mapping if it would violate
5908 * cache aliasing constraints.
5909 */
5910 - if ((flags & MAP_SHARED) &&
5911 + if ((filp || (flags & MAP_SHARED)) &&
5912 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5913 return -EINVAL;
5914 return addr;
5915 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 addr = PAGE_ALIGN(addr);
5917
5918 vma = find_vma(mm, addr);
5919 - if (task_size - len >= addr &&
5920 - (!vma || addr + len <= vma->vm_start))
5921 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5922 return addr;
5923 }
5924
5925 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5926 /* make sure it can fit in the remaining address space */
5927 if (likely(addr > len)) {
5928 vma = find_vma(mm, addr-len);
5929 - if (!vma || addr <= vma->vm_start) {
5930 + if (check_heap_stack_gap(vma, addr - len, len)) {
5931 /* remember the address as a hint for next time */
5932 return (mm->free_area_cache = addr-len);
5933 }
5934 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5935 if (unlikely(mm->mmap_base < len))
5936 goto bottomup;
5937
5938 - addr = mm->mmap_base-len;
5939 - if (do_color_align)
5940 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5941 + addr = mm->mmap_base - len;
5942
5943 do {
5944 + if (do_color_align)
5945 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5946 /*
5947 * Lookup failure means no vma is above this address,
5948 * else if new region fits below vma->vm_start,
5949 * return with success:
5950 */
5951 vma = find_vma(mm, addr);
5952 - if (likely(!vma || addr+len <= vma->vm_start)) {
5953 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5954 /* remember the address as a hint for next time */
5955 return (mm->free_area_cache = addr);
5956 }
5957 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5958 mm->cached_hole_size = vma->vm_start - addr;
5959
5960 /* try just below the current vma->vm_start */
5961 - addr = vma->vm_start-len;
5962 - if (do_color_align)
5963 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5964 - } while (likely(len < vma->vm_start));
5965 + addr = skip_heap_stack_gap(vma, len);
5966 + } while (!IS_ERR_VALUE(addr));
5967
5968 bottomup:
5969 /*
5970 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5971 gap == RLIM_INFINITY ||
5972 sysctl_legacy_va_layout) {
5973 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5974 +
5975 +#ifdef CONFIG_PAX_RANDMMAP
5976 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5977 + mm->mmap_base += mm->delta_mmap;
5978 +#endif
5979 +
5980 mm->get_unmapped_area = arch_get_unmapped_area;
5981 mm->unmap_area = arch_unmap_area;
5982 } else {
5983 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5984 gap = (task_size / 6 * 5);
5985
5986 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5987 +
5988 +#ifdef CONFIG_PAX_RANDMMAP
5989 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5990 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5991 +#endif
5992 +
5993 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5994 mm->unmap_area = arch_unmap_area_topdown;
5995 }
5996 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5997 index 7f5f65d..3308382 100644
5998 --- a/arch/sparc/kernel/syscalls.S
5999 +++ b/arch/sparc/kernel/syscalls.S
6000 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6001 #endif
6002 .align 32
6003 1: ldx [%g6 + TI_FLAGS], %l5
6004 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6005 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6006 be,pt %icc, rtrap
6007 nop
6008 call syscall_trace_leave
6009 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6010
6011 srl %i5, 0, %o5 ! IEU1
6012 srl %i2, 0, %o2 ! IEU0 Group
6013 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6014 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6015 bne,pn %icc, linux_syscall_trace32 ! CTI
6016 mov %i0, %l5 ! IEU1
6017 call %l7 ! CTI Group brk forced
6018 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6019
6020 mov %i3, %o3 ! IEU1
6021 mov %i4, %o4 ! IEU0 Group
6022 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6023 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6024 bne,pn %icc, linux_syscall_trace ! CTI Group
6025 mov %i0, %l5 ! IEU0
6026 2: call %l7 ! CTI Group brk forced
6027 @@ -218,7 +218,7 @@ ret_sys_call:
6028
6029 cmp %o0, -ERESTART_RESTARTBLOCK
6030 bgeu,pn %xcc, 1f
6031 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6032 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6033 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6034
6035 2:
6036 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6037 index a5785ea..405c5f7 100644
6038 --- a/arch/sparc/kernel/traps_32.c
6039 +++ b/arch/sparc/kernel/traps_32.c
6040 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6041 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6042 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6043
6044 +extern void gr_handle_kernel_exploit(void);
6045 +
6046 void die_if_kernel(char *str, struct pt_regs *regs)
6047 {
6048 static int die_counter;
6049 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6050 count++ < 30 &&
6051 (((unsigned long) rw) >= PAGE_OFFSET) &&
6052 !(((unsigned long) rw) & 0x7)) {
6053 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6054 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6055 (void *) rw->ins[7]);
6056 rw = (struct reg_window32 *)rw->ins[6];
6057 }
6058 }
6059 printk("Instruction DUMP:");
6060 instruction_dump ((unsigned long *) regs->pc);
6061 - if(regs->psr & PSR_PS)
6062 + if(regs->psr & PSR_PS) {
6063 + gr_handle_kernel_exploit();
6064 do_exit(SIGKILL);
6065 + }
6066 do_exit(SIGSEGV);
6067 }
6068
6069 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6070 index 3b05e66..6ea2917 100644
6071 --- a/arch/sparc/kernel/traps_64.c
6072 +++ b/arch/sparc/kernel/traps_64.c
6073 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6074 i + 1,
6075 p->trapstack[i].tstate, p->trapstack[i].tpc,
6076 p->trapstack[i].tnpc, p->trapstack[i].tt);
6077 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6078 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6079 }
6080 }
6081
6082 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6083
6084 lvl -= 0x100;
6085 if (regs->tstate & TSTATE_PRIV) {
6086 +
6087 +#ifdef CONFIG_PAX_REFCOUNT
6088 + if (lvl == 6)
6089 + pax_report_refcount_overflow(regs);
6090 +#endif
6091 +
6092 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6093 die_if_kernel(buffer, regs);
6094 }
6095 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6096 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6097 {
6098 char buffer[32];
6099 -
6100 +
6101 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6102 0, lvl, SIGTRAP) == NOTIFY_STOP)
6103 return;
6104
6105 +#ifdef CONFIG_PAX_REFCOUNT
6106 + if (lvl == 6)
6107 + pax_report_refcount_overflow(regs);
6108 +#endif
6109 +
6110 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6111
6112 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6113 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6114 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6115 printk("%s" "ERROR(%d): ",
6116 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6117 - printk("TPC<%pS>\n", (void *) regs->tpc);
6118 + printk("TPC<%pA>\n", (void *) regs->tpc);
6119 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6120 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6121 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6122 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6123 smp_processor_id(),
6124 (type & 0x1) ? 'I' : 'D',
6125 regs->tpc);
6126 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6127 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6128 panic("Irrecoverable Cheetah+ parity error.");
6129 }
6130
6131 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6132 smp_processor_id(),
6133 (type & 0x1) ? 'I' : 'D',
6134 regs->tpc);
6135 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6136 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6137 }
6138
6139 struct sun4v_error_entry {
6140 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6141
6142 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6143 regs->tpc, tl);
6144 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6145 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6146 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6147 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6148 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6149 (void *) regs->u_regs[UREG_I7]);
6150 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6151 "pte[%lx] error[%lx]\n",
6152 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6153
6154 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6155 regs->tpc, tl);
6156 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6157 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6158 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6159 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6160 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6161 (void *) regs->u_regs[UREG_I7]);
6162 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6163 "pte[%lx] error[%lx]\n",
6164 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6165 fp = (unsigned long)sf->fp + STACK_BIAS;
6166 }
6167
6168 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6169 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6170 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6171 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6172 int index = tsk->curr_ret_stack;
6173 if (tsk->ret_stack && index >= graph) {
6174 pc = tsk->ret_stack[index - graph].ret;
6175 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6176 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6177 graph++;
6178 }
6179 }
6180 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6181 return (struct reg_window *) (fp + STACK_BIAS);
6182 }
6183
6184 +extern void gr_handle_kernel_exploit(void);
6185 +
6186 void die_if_kernel(char *str, struct pt_regs *regs)
6187 {
6188 static int die_counter;
6189 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6190 while (rw &&
6191 count++ < 30 &&
6192 kstack_valid(tp, (unsigned long) rw)) {
6193 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6194 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6195 (void *) rw->ins[7]);
6196
6197 rw = kernel_stack_up(rw);
6198 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6199 }
6200 user_instruction_dump ((unsigned int __user *) regs->tpc);
6201 }
6202 - if (regs->tstate & TSTATE_PRIV)
6203 + if (regs->tstate & TSTATE_PRIV) {
6204 + gr_handle_kernel_exploit();
6205 do_exit(SIGKILL);
6206 + }
6207 do_exit(SIGSEGV);
6208 }
6209 EXPORT_SYMBOL(die_if_kernel);
6210 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6211 index f81d038..e7a4680 100644
6212 --- a/arch/sparc/kernel/unaligned_64.c
6213 +++ b/arch/sparc/kernel/unaligned_64.c
6214 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6215 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6216
6217 if (__ratelimit(&ratelimit)) {
6218 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6219 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6220 regs->tpc, (void *) regs->tpc);
6221 }
6222 }
6223 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6224 index dff4096..bd9a388 100644
6225 --- a/arch/sparc/lib/Makefile
6226 +++ b/arch/sparc/lib/Makefile
6227 @@ -2,7 +2,7 @@
6228 #
6229
6230 asflags-y := -ansi -DST_DIV0=0x02
6231 -ccflags-y := -Werror
6232 +#ccflags-y := -Werror
6233
6234 lib-$(CONFIG_SPARC32) += ashrdi3.o
6235 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6236 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6237 index 4d502da..527c48d 100644
6238 --- a/arch/sparc/lib/atomic_64.S
6239 +++ b/arch/sparc/lib/atomic_64.S
6240 @@ -17,7 +17,12 @@
6241 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6242 BACKOFF_SETUP(%o2)
6243 1: lduw [%o1], %g1
6244 - add %g1, %o0, %g7
6245 + addcc %g1, %o0, %g7
6246 +
6247 +#ifdef CONFIG_PAX_REFCOUNT
6248 + tvs %icc, 6
6249 +#endif
6250 +
6251 cas [%o1], %g1, %g7
6252 cmp %g1, %g7
6253 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6254 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6255 2: BACKOFF_SPIN(%o2, %o3, 1b)
6256 ENDPROC(atomic_add)
6257
6258 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6259 + BACKOFF_SETUP(%o2)
6260 +1: lduw [%o1], %g1
6261 + add %g1, %o0, %g7
6262 + cas [%o1], %g1, %g7
6263 + cmp %g1, %g7
6264 + bne,pn %icc, 2f
6265 + nop
6266 + retl
6267 + nop
6268 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6269 +ENDPROC(atomic_add_unchecked)
6270 +
6271 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6272 BACKOFF_SETUP(%o2)
6273 1: lduw [%o1], %g1
6274 - sub %g1, %o0, %g7
6275 + subcc %g1, %o0, %g7
6276 +
6277 +#ifdef CONFIG_PAX_REFCOUNT
6278 + tvs %icc, 6
6279 +#endif
6280 +
6281 cas [%o1], %g1, %g7
6282 cmp %g1, %g7
6283 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6284 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6285 2: BACKOFF_SPIN(%o2, %o3, 1b)
6286 ENDPROC(atomic_sub)
6287
6288 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6289 + BACKOFF_SETUP(%o2)
6290 +1: lduw [%o1], %g1
6291 + sub %g1, %o0, %g7
6292 + cas [%o1], %g1, %g7
6293 + cmp %g1, %g7
6294 + bne,pn %icc, 2f
6295 + nop
6296 + retl
6297 + nop
6298 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 +ENDPROC(atomic_sub_unchecked)
6300 +
6301 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6302 BACKOFF_SETUP(%o2)
6303 1: lduw [%o1], %g1
6304 - add %g1, %o0, %g7
6305 + addcc %g1, %o0, %g7
6306 +
6307 +#ifdef CONFIG_PAX_REFCOUNT
6308 + tvs %icc, 6
6309 +#endif
6310 +
6311 cas [%o1], %g1, %g7
6312 cmp %g1, %g7
6313 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6314 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6315 2: BACKOFF_SPIN(%o2, %o3, 1b)
6316 ENDPROC(atomic_add_ret)
6317
6318 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6319 + BACKOFF_SETUP(%o2)
6320 +1: lduw [%o1], %g1
6321 + addcc %g1, %o0, %g7
6322 + cas [%o1], %g1, %g7
6323 + cmp %g1, %g7
6324 + bne,pn %icc, 2f
6325 + add %g7, %o0, %g7
6326 + sra %g7, 0, %o0
6327 + retl
6328 + nop
6329 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6330 +ENDPROC(atomic_add_ret_unchecked)
6331 +
6332 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: lduw [%o1], %g1
6335 - sub %g1, %o0, %g7
6336 + subcc %g1, %o0, %g7
6337 +
6338 +#ifdef CONFIG_PAX_REFCOUNT
6339 + tvs %icc, 6
6340 +#endif
6341 +
6342 cas [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6345 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6346 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: ldx [%o1], %g1
6349 - add %g1, %o0, %g7
6350 + addcc %g1, %o0, %g7
6351 +
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + tvs %xcc, 6
6354 +#endif
6355 +
6356 casx [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6359 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6360 2: BACKOFF_SPIN(%o2, %o3, 1b)
6361 ENDPROC(atomic64_add)
6362
6363 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6364 + BACKOFF_SETUP(%o2)
6365 +1: ldx [%o1], %g1
6366 + addcc %g1, %o0, %g7
6367 + casx [%o1], %g1, %g7
6368 + cmp %g1, %g7
6369 + bne,pn %xcc, 2f
6370 + nop
6371 + retl
6372 + nop
6373 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6374 +ENDPROC(atomic64_add_unchecked)
6375 +
6376 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6377 BACKOFF_SETUP(%o2)
6378 1: ldx [%o1], %g1
6379 - sub %g1, %o0, %g7
6380 + subcc %g1, %o0, %g7
6381 +
6382 +#ifdef CONFIG_PAX_REFCOUNT
6383 + tvs %xcc, 6
6384 +#endif
6385 +
6386 casx [%o1], %g1, %g7
6387 cmp %g1, %g7
6388 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6389 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6390 2: BACKOFF_SPIN(%o2, %o3, 1b)
6391 ENDPROC(atomic64_sub)
6392
6393 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6394 + BACKOFF_SETUP(%o2)
6395 +1: ldx [%o1], %g1
6396 + subcc %g1, %o0, %g7
6397 + casx [%o1], %g1, %g7
6398 + cmp %g1, %g7
6399 + bne,pn %xcc, 2f
6400 + nop
6401 + retl
6402 + nop
6403 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6404 +ENDPROC(atomic64_sub_unchecked)
6405 +
6406 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6407 BACKOFF_SETUP(%o2)
6408 1: ldx [%o1], %g1
6409 - add %g1, %o0, %g7
6410 + addcc %g1, %o0, %g7
6411 +
6412 +#ifdef CONFIG_PAX_REFCOUNT
6413 + tvs %xcc, 6
6414 +#endif
6415 +
6416 casx [%o1], %g1, %g7
6417 cmp %g1, %g7
6418 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6419 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6420 2: BACKOFF_SPIN(%o2, %o3, 1b)
6421 ENDPROC(atomic64_add_ret)
6422
6423 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6424 + BACKOFF_SETUP(%o2)
6425 +1: ldx [%o1], %g1
6426 + addcc %g1, %o0, %g7
6427 + casx [%o1], %g1, %g7
6428 + cmp %g1, %g7
6429 + bne,pn %xcc, 2f
6430 + add %g7, %o0, %g7
6431 + mov %g7, %o0
6432 + retl
6433 + nop
6434 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6435 +ENDPROC(atomic64_add_ret_unchecked)
6436 +
6437 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6438 BACKOFF_SETUP(%o2)
6439 1: ldx [%o1], %g1
6440 - sub %g1, %o0, %g7
6441 + subcc %g1, %o0, %g7
6442 +
6443 +#ifdef CONFIG_PAX_REFCOUNT
6444 + tvs %xcc, 6
6445 +#endif
6446 +
6447 casx [%o1], %g1, %g7
6448 cmp %g1, %g7
6449 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6450 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6451 index 3b31218..345c609 100644
6452 --- a/arch/sparc/lib/ksyms.c
6453 +++ b/arch/sparc/lib/ksyms.c
6454 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6455
6456 /* Atomic counter implementation. */
6457 EXPORT_SYMBOL(atomic_add);
6458 +EXPORT_SYMBOL(atomic_add_unchecked);
6459 EXPORT_SYMBOL(atomic_add_ret);
6460 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6461 EXPORT_SYMBOL(atomic_sub);
6462 +EXPORT_SYMBOL(atomic_sub_unchecked);
6463 EXPORT_SYMBOL(atomic_sub_ret);
6464 EXPORT_SYMBOL(atomic64_add);
6465 +EXPORT_SYMBOL(atomic64_add_unchecked);
6466 EXPORT_SYMBOL(atomic64_add_ret);
6467 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6468 EXPORT_SYMBOL(atomic64_sub);
6469 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6470 EXPORT_SYMBOL(atomic64_sub_ret);
6471
6472 /* Atomic bit operations. */
6473 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6474 index 30c3ecc..736f015 100644
6475 --- a/arch/sparc/mm/Makefile
6476 +++ b/arch/sparc/mm/Makefile
6477 @@ -2,7 +2,7 @@
6478 #
6479
6480 asflags-y := -ansi
6481 -ccflags-y := -Werror
6482 +#ccflags-y := -Werror
6483
6484 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6485 obj-y += fault_$(BITS).o
6486 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6487 index 77ac917..baf45db 100644
6488 --- a/arch/sparc/mm/fault_32.c
6489 +++ b/arch/sparc/mm/fault_32.c
6490 @@ -21,6 +21,9 @@
6491 #include <linux/perf_event.h>
6492 #include <linux/interrupt.h>
6493 #include <linux/kdebug.h>
6494 +#include <linux/slab.h>
6495 +#include <linux/pagemap.h>
6496 +#include <linux/compiler.h>
6497
6498 #include <asm/page.h>
6499 #include <asm/pgtable.h>
6500 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6501 return safe_compute_effective_address(regs, insn);
6502 }
6503
6504 +#ifdef CONFIG_PAX_PAGEEXEC
6505 +#ifdef CONFIG_PAX_DLRESOLVE
6506 +static void pax_emuplt_close(struct vm_area_struct *vma)
6507 +{
6508 + vma->vm_mm->call_dl_resolve = 0UL;
6509 +}
6510 +
6511 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6512 +{
6513 + unsigned int *kaddr;
6514 +
6515 + vmf->page = alloc_page(GFP_HIGHUSER);
6516 + if (!vmf->page)
6517 + return VM_FAULT_OOM;
6518 +
6519 + kaddr = kmap(vmf->page);
6520 + memset(kaddr, 0, PAGE_SIZE);
6521 + kaddr[0] = 0x9DE3BFA8U; /* save */
6522 + flush_dcache_page(vmf->page);
6523 + kunmap(vmf->page);
6524 + return VM_FAULT_MAJOR;
6525 +}
6526 +
6527 +static const struct vm_operations_struct pax_vm_ops = {
6528 + .close = pax_emuplt_close,
6529 + .fault = pax_emuplt_fault
6530 +};
6531 +
6532 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6533 +{
6534 + int ret;
6535 +
6536 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6537 + vma->vm_mm = current->mm;
6538 + vma->vm_start = addr;
6539 + vma->vm_end = addr + PAGE_SIZE;
6540 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6541 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6542 + vma->vm_ops = &pax_vm_ops;
6543 +
6544 + ret = insert_vm_struct(current->mm, vma);
6545 + if (ret)
6546 + return ret;
6547 +
6548 + ++current->mm->total_vm;
6549 + return 0;
6550 +}
6551 +#endif
6552 +
6553 +/*
6554 + * PaX: decide what to do with offenders (regs->pc = fault address)
6555 + *
6556 + * returns 1 when task should be killed
6557 + * 2 when patched PLT trampoline was detected
6558 + * 3 when unpatched PLT trampoline was detected
6559 + */
6560 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6561 +{
6562 +
6563 +#ifdef CONFIG_PAX_EMUPLT
6564 + int err;
6565 +
6566 + do { /* PaX: patched PLT emulation #1 */
6567 + unsigned int sethi1, sethi2, jmpl;
6568 +
6569 + err = get_user(sethi1, (unsigned int *)regs->pc);
6570 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6571 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6572 +
6573 + if (err)
6574 + break;
6575 +
6576 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6577 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6578 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6579 + {
6580 + unsigned int addr;
6581 +
6582 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6583 + addr = regs->u_regs[UREG_G1];
6584 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6585 + regs->pc = addr;
6586 + regs->npc = addr+4;
6587 + return 2;
6588 + }
6589 + } while (0);
6590 +
6591 + do { /* PaX: patched PLT emulation #2 */
6592 + unsigned int ba;
6593 +
6594 + err = get_user(ba, (unsigned int *)regs->pc);
6595 +
6596 + if (err)
6597 + break;
6598 +
6599 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6600 + unsigned int addr;
6601 +
6602 + if ((ba & 0xFFC00000U) == 0x30800000U)
6603 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6604 + else
6605 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: patched PLT emulation #3 */
6613 + unsigned int sethi, bajmpl, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr;
6627 +
6628 + addr = (sethi & 0x003FFFFFU) << 10;
6629 + regs->u_regs[UREG_G1] = addr;
6630 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6631 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6632 + else
6633 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6634 + regs->pc = addr;
6635 + regs->npc = addr+4;
6636 + return 2;
6637 + }
6638 + } while (0);
6639 +
6640 + do { /* PaX: unpatched PLT emulation step 1 */
6641 + unsigned int sethi, ba, nop;
6642 +
6643 + err = get_user(sethi, (unsigned int *)regs->pc);
6644 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6645 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6646 +
6647 + if (err)
6648 + break;
6649 +
6650 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6651 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6652 + nop == 0x01000000U)
6653 + {
6654 + unsigned int addr, save, call;
6655 +
6656 + if ((ba & 0xFFC00000U) == 0x30800000U)
6657 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6658 + else
6659 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6660 +
6661 + err = get_user(save, (unsigned int *)addr);
6662 + err |= get_user(call, (unsigned int *)(addr+4));
6663 + err |= get_user(nop, (unsigned int *)(addr+8));
6664 + if (err)
6665 + break;
6666 +
6667 +#ifdef CONFIG_PAX_DLRESOLVE
6668 + if (save == 0x9DE3BFA8U &&
6669 + (call & 0xC0000000U) == 0x40000000U &&
6670 + nop == 0x01000000U)
6671 + {
6672 + struct vm_area_struct *vma;
6673 + unsigned long call_dl_resolve;
6674 +
6675 + down_read(&current->mm->mmap_sem);
6676 + call_dl_resolve = current->mm->call_dl_resolve;
6677 + up_read(&current->mm->mmap_sem);
6678 + if (likely(call_dl_resolve))
6679 + goto emulate;
6680 +
6681 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6682 +
6683 + down_write(&current->mm->mmap_sem);
6684 + if (current->mm->call_dl_resolve) {
6685 + call_dl_resolve = current->mm->call_dl_resolve;
6686 + up_write(&current->mm->mmap_sem);
6687 + if (vma)
6688 + kmem_cache_free(vm_area_cachep, vma);
6689 + goto emulate;
6690 + }
6691 +
6692 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6693 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6694 + up_write(&current->mm->mmap_sem);
6695 + if (vma)
6696 + kmem_cache_free(vm_area_cachep, vma);
6697 + return 1;
6698 + }
6699 +
6700 + if (pax_insert_vma(vma, call_dl_resolve)) {
6701 + up_write(&current->mm->mmap_sem);
6702 + kmem_cache_free(vm_area_cachep, vma);
6703 + return 1;
6704 + }
6705 +
6706 + current->mm->call_dl_resolve = call_dl_resolve;
6707 + up_write(&current->mm->mmap_sem);
6708 +
6709 +emulate:
6710 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6711 + regs->pc = call_dl_resolve;
6712 + regs->npc = addr+4;
6713 + return 3;
6714 + }
6715 +#endif
6716 +
6717 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6718 + if ((save & 0xFFC00000U) == 0x05000000U &&
6719 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6720 + nop == 0x01000000U)
6721 + {
6722 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6723 + regs->u_regs[UREG_G2] = addr + 4;
6724 + addr = (save & 0x003FFFFFU) << 10;
6725 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6726 + regs->pc = addr;
6727 + regs->npc = addr+4;
6728 + return 3;
6729 + }
6730 + }
6731 + } while (0);
6732 +
6733 + do { /* PaX: unpatched PLT emulation step 2 */
6734 + unsigned int save, call, nop;
6735 +
6736 + err = get_user(save, (unsigned int *)(regs->pc-4));
6737 + err |= get_user(call, (unsigned int *)regs->pc);
6738 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6739 + if (err)
6740 + break;
6741 +
6742 + if (save == 0x9DE3BFA8U &&
6743 + (call & 0xC0000000U) == 0x40000000U &&
6744 + nop == 0x01000000U)
6745 + {
6746 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6747 +
6748 + regs->u_regs[UREG_RETPC] = regs->pc;
6749 + regs->pc = dl_resolve;
6750 + regs->npc = dl_resolve+4;
6751 + return 3;
6752 + }
6753 + } while (0);
6754 +#endif
6755 +
6756 + return 1;
6757 +}
6758 +
6759 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6760 +{
6761 + unsigned long i;
6762 +
6763 + printk(KERN_ERR "PAX: bytes at PC: ");
6764 + for (i = 0; i < 8; i++) {
6765 + unsigned int c;
6766 + if (get_user(c, (unsigned int *)pc+i))
6767 + printk(KERN_CONT "???????? ");
6768 + else
6769 + printk(KERN_CONT "%08x ", c);
6770 + }
6771 + printk("\n");
6772 +}
6773 +#endif
6774 +
6775 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6776 int text_fault)
6777 {
6778 @@ -230,6 +504,24 @@ good_area:
6779 if (!(vma->vm_flags & VM_WRITE))
6780 goto bad_area;
6781 } else {
6782 +
6783 +#ifdef CONFIG_PAX_PAGEEXEC
6784 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6785 + up_read(&mm->mmap_sem);
6786 + switch (pax_handle_fetch_fault(regs)) {
6787 +
6788 +#ifdef CONFIG_PAX_EMUPLT
6789 + case 2:
6790 + case 3:
6791 + return;
6792 +#endif
6793 +
6794 + }
6795 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6796 + do_group_exit(SIGKILL);
6797 + }
6798 +#endif
6799 +
6800 /* Allow reads even for write-only mappings */
6801 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6802 goto bad_area;
6803 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6804 index 1fe0429..8dd5dd5 100644
6805 --- a/arch/sparc/mm/fault_64.c
6806 +++ b/arch/sparc/mm/fault_64.c
6807 @@ -21,6 +21,9 @@
6808 #include <linux/kprobes.h>
6809 #include <linux/kdebug.h>
6810 #include <linux/percpu.h>
6811 +#include <linux/slab.h>
6812 +#include <linux/pagemap.h>
6813 +#include <linux/compiler.h>
6814
6815 #include <asm/page.h>
6816 #include <asm/pgtable.h>
6817 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6818 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6819 regs->tpc);
6820 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6821 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6822 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6823 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6824 dump_stack();
6825 unhandled_fault(regs->tpc, current, regs);
6826 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6827 show_regs(regs);
6828 }
6829
6830 +#ifdef CONFIG_PAX_PAGEEXEC
6831 +#ifdef CONFIG_PAX_DLRESOLVE
6832 +static void pax_emuplt_close(struct vm_area_struct *vma)
6833 +{
6834 + vma->vm_mm->call_dl_resolve = 0UL;
6835 +}
6836 +
6837 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6838 +{
6839 + unsigned int *kaddr;
6840 +
6841 + vmf->page = alloc_page(GFP_HIGHUSER);
6842 + if (!vmf->page)
6843 + return VM_FAULT_OOM;
6844 +
6845 + kaddr = kmap(vmf->page);
6846 + memset(kaddr, 0, PAGE_SIZE);
6847 + kaddr[0] = 0x9DE3BFA8U; /* save */
6848 + flush_dcache_page(vmf->page);
6849 + kunmap(vmf->page);
6850 + return VM_FAULT_MAJOR;
6851 +}
6852 +
6853 +static const struct vm_operations_struct pax_vm_ops = {
6854 + .close = pax_emuplt_close,
6855 + .fault = pax_emuplt_fault
6856 +};
6857 +
6858 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6859 +{
6860 + int ret;
6861 +
6862 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6863 + vma->vm_mm = current->mm;
6864 + vma->vm_start = addr;
6865 + vma->vm_end = addr + PAGE_SIZE;
6866 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6867 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6868 + vma->vm_ops = &pax_vm_ops;
6869 +
6870 + ret = insert_vm_struct(current->mm, vma);
6871 + if (ret)
6872 + return ret;
6873 +
6874 + ++current->mm->total_vm;
6875 + return 0;
6876 +}
6877 +#endif
6878 +
6879 +/*
6880 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6881 + *
6882 + * returns 1 when task should be killed
6883 + * 2 when patched PLT trampoline was detected
6884 + * 3 when unpatched PLT trampoline was detected
6885 + */
6886 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6887 +{
6888 +
6889 +#ifdef CONFIG_PAX_EMUPLT
6890 + int err;
6891 +
6892 + do { /* PaX: patched PLT emulation #1 */
6893 + unsigned int sethi1, sethi2, jmpl;
6894 +
6895 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6896 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6897 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6898 +
6899 + if (err)
6900 + break;
6901 +
6902 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6903 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6904 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6905 + {
6906 + unsigned long addr;
6907 +
6908 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6909 + addr = regs->u_regs[UREG_G1];
6910 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6911 +
6912 + if (test_thread_flag(TIF_32BIT))
6913 + addr &= 0xFFFFFFFFUL;
6914 +
6915 + regs->tpc = addr;
6916 + regs->tnpc = addr+4;
6917 + return 2;
6918 + }
6919 + } while (0);
6920 +
6921 + do { /* PaX: patched PLT emulation #2 */
6922 + unsigned int ba;
6923 +
6924 + err = get_user(ba, (unsigned int *)regs->tpc);
6925 +
6926 + if (err)
6927 + break;
6928 +
6929 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6930 + unsigned long addr;
6931 +
6932 + if ((ba & 0xFFC00000U) == 0x30800000U)
6933 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6934 + else
6935 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6936 +
6937 + if (test_thread_flag(TIF_32BIT))
6938 + addr &= 0xFFFFFFFFUL;
6939 +
6940 + regs->tpc = addr;
6941 + regs->tnpc = addr+4;
6942 + return 2;
6943 + }
6944 + } while (0);
6945 +
6946 + do { /* PaX: patched PLT emulation #3 */
6947 + unsigned int sethi, bajmpl, nop;
6948 +
6949 + err = get_user(sethi, (unsigned int *)regs->tpc);
6950 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6951 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6952 +
6953 + if (err)
6954 + break;
6955 +
6956 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6957 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6958 + nop == 0x01000000U)
6959 + {
6960 + unsigned long addr;
6961 +
6962 + addr = (sethi & 0x003FFFFFU) << 10;
6963 + regs->u_regs[UREG_G1] = addr;
6964 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6965 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6966 + else
6967 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6968 +
6969 + if (test_thread_flag(TIF_32BIT))
6970 + addr &= 0xFFFFFFFFUL;
6971 +
6972 + regs->tpc = addr;
6973 + regs->tnpc = addr+4;
6974 + return 2;
6975 + }
6976 + } while (0);
6977 +
6978 + do { /* PaX: patched PLT emulation #4 */
6979 + unsigned int sethi, mov1, call, mov2;
6980 +
6981 + err = get_user(sethi, (unsigned int *)regs->tpc);
6982 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6983 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6984 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6985 +
6986 + if (err)
6987 + break;
6988 +
6989 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6990 + mov1 == 0x8210000FU &&
6991 + (call & 0xC0000000U) == 0x40000000U &&
6992 + mov2 == 0x9E100001U)
6993 + {
6994 + unsigned long addr;
6995 +
6996 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6997 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6998 +
6999 + if (test_thread_flag(TIF_32BIT))
7000 + addr &= 0xFFFFFFFFUL;
7001 +
7002 + regs->tpc = addr;
7003 + regs->tnpc = addr+4;
7004 + return 2;
7005 + }
7006 + } while (0);
7007 +
7008 + do { /* PaX: patched PLT emulation #5 */
7009 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7010 +
7011 + err = get_user(sethi, (unsigned int *)regs->tpc);
7012 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7013 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7014 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7015 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7016 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7017 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7018 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7019 +
7020 + if (err)
7021 + break;
7022 +
7023 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7025 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7026 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7027 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7028 + sllx == 0x83287020U &&
7029 + jmpl == 0x81C04005U &&
7030 + nop == 0x01000000U)
7031 + {
7032 + unsigned long addr;
7033 +
7034 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7035 + regs->u_regs[UREG_G1] <<= 32;
7036 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7037 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7038 + regs->tpc = addr;
7039 + regs->tnpc = addr+4;
7040 + return 2;
7041 + }
7042 + } while (0);
7043 +
7044 + do { /* PaX: patched PLT emulation #6 */
7045 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7046 +
7047 + err = get_user(sethi, (unsigned int *)regs->tpc);
7048 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7049 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7050 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7051 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7052 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7053 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7054 +
7055 + if (err)
7056 + break;
7057 +
7058 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7059 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7060 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7061 + sllx == 0x83287020U &&
7062 + (or & 0xFFFFE000U) == 0x8A116000U &&
7063 + jmpl == 0x81C04005U &&
7064 + nop == 0x01000000U)
7065 + {
7066 + unsigned long addr;
7067 +
7068 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7069 + regs->u_regs[UREG_G1] <<= 32;
7070 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7071 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072 + regs->tpc = addr;
7073 + regs->tnpc = addr+4;
7074 + return 2;
7075 + }
7076 + } while (0);
7077 +
7078 + do { /* PaX: unpatched PLT emulation step 1 */
7079 + unsigned int sethi, ba, nop;
7080 +
7081 + err = get_user(sethi, (unsigned int *)regs->tpc);
7082 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7083 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7084 +
7085 + if (err)
7086 + break;
7087 +
7088 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7089 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7090 + nop == 0x01000000U)
7091 + {
7092 + unsigned long addr;
7093 + unsigned int save, call;
7094 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7095 +
7096 + if ((ba & 0xFFC00000U) == 0x30800000U)
7097 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7098 + else
7099 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7100 +
7101 + if (test_thread_flag(TIF_32BIT))
7102 + addr &= 0xFFFFFFFFUL;
7103 +
7104 + err = get_user(save, (unsigned int *)addr);
7105 + err |= get_user(call, (unsigned int *)(addr+4));
7106 + err |= get_user(nop, (unsigned int *)(addr+8));
7107 + if (err)
7108 + break;
7109 +
7110 +#ifdef CONFIG_PAX_DLRESOLVE
7111 + if (save == 0x9DE3BFA8U &&
7112 + (call & 0xC0000000U) == 0x40000000U &&
7113 + nop == 0x01000000U)
7114 + {
7115 + struct vm_area_struct *vma;
7116 + unsigned long call_dl_resolve;
7117 +
7118 + down_read(&current->mm->mmap_sem);
7119 + call_dl_resolve = current->mm->call_dl_resolve;
7120 + up_read(&current->mm->mmap_sem);
7121 + if (likely(call_dl_resolve))
7122 + goto emulate;
7123 +
7124 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7125 +
7126 + down_write(&current->mm->mmap_sem);
7127 + if (current->mm->call_dl_resolve) {
7128 + call_dl_resolve = current->mm->call_dl_resolve;
7129 + up_write(&current->mm->mmap_sem);
7130 + if (vma)
7131 + kmem_cache_free(vm_area_cachep, vma);
7132 + goto emulate;
7133 + }
7134 +
7135 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7136 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7137 + up_write(&current->mm->mmap_sem);
7138 + if (vma)
7139 + kmem_cache_free(vm_area_cachep, vma);
7140 + return 1;
7141 + }
7142 +
7143 + if (pax_insert_vma(vma, call_dl_resolve)) {
7144 + up_write(&current->mm->mmap_sem);
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + return 1;
7147 + }
7148 +
7149 + current->mm->call_dl_resolve = call_dl_resolve;
7150 + up_write(&current->mm->mmap_sem);
7151 +
7152 +emulate:
7153 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7154 + regs->tpc = call_dl_resolve;
7155 + regs->tnpc = addr+4;
7156 + return 3;
7157 + }
7158 +#endif
7159 +
7160 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7161 + if ((save & 0xFFC00000U) == 0x05000000U &&
7162 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7163 + nop == 0x01000000U)
7164 + {
7165 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7166 + regs->u_regs[UREG_G2] = addr + 4;
7167 + addr = (save & 0x003FFFFFU) << 10;
7168 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7169 +
7170 + if (test_thread_flag(TIF_32BIT))
7171 + addr &= 0xFFFFFFFFUL;
7172 +
7173 + regs->tpc = addr;
7174 + regs->tnpc = addr+4;
7175 + return 3;
7176 + }
7177 +
7178 + /* PaX: 64-bit PLT stub */
7179 + err = get_user(sethi1, (unsigned int *)addr);
7180 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7181 + err |= get_user(or1, (unsigned int *)(addr+8));
7182 + err |= get_user(or2, (unsigned int *)(addr+12));
7183 + err |= get_user(sllx, (unsigned int *)(addr+16));
7184 + err |= get_user(add, (unsigned int *)(addr+20));
7185 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7186 + err |= get_user(nop, (unsigned int *)(addr+28));
7187 + if (err)
7188 + break;
7189 +
7190 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7191 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7192 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7193 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7194 + sllx == 0x89293020U &&
7195 + add == 0x8A010005U &&
7196 + jmpl == 0x89C14000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7201 + regs->u_regs[UREG_G4] <<= 32;
7202 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7203 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7204 + regs->u_regs[UREG_G4] = addr + 24;
7205 + addr = regs->u_regs[UREG_G5];
7206 + regs->tpc = addr;
7207 + regs->tnpc = addr+4;
7208 + return 3;
7209 + }
7210 + }
7211 + } while (0);
7212 +
7213 +#ifdef CONFIG_PAX_DLRESOLVE
7214 + do { /* PaX: unpatched PLT emulation step 2 */
7215 + unsigned int save, call, nop;
7216 +
7217 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7218 + err |= get_user(call, (unsigned int *)regs->tpc);
7219 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7220 + if (err)
7221 + break;
7222 +
7223 + if (save == 0x9DE3BFA8U &&
7224 + (call & 0xC0000000U) == 0x40000000U &&
7225 + nop == 0x01000000U)
7226 + {
7227 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7228 +
7229 + if (test_thread_flag(TIF_32BIT))
7230 + dl_resolve &= 0xFFFFFFFFUL;
7231 +
7232 + regs->u_regs[UREG_RETPC] = regs->tpc;
7233 + regs->tpc = dl_resolve;
7234 + regs->tnpc = dl_resolve+4;
7235 + return 3;
7236 + }
7237 + } while (0);
7238 +#endif
7239 +
7240 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7241 + unsigned int sethi, ba, nop;
7242 +
7243 + err = get_user(sethi, (unsigned int *)regs->tpc);
7244 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7245 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7246 +
7247 + if (err)
7248 + break;
7249 +
7250 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7251 + (ba & 0xFFF00000U) == 0x30600000U &&
7252 + nop == 0x01000000U)
7253 + {
7254 + unsigned long addr;
7255 +
7256 + addr = (sethi & 0x003FFFFFU) << 10;
7257 + regs->u_regs[UREG_G1] = addr;
7258 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7259 +
7260 + if (test_thread_flag(TIF_32BIT))
7261 + addr &= 0xFFFFFFFFUL;
7262 +
7263 + regs->tpc = addr;
7264 + regs->tnpc = addr+4;
7265 + return 2;
7266 + }
7267 + } while (0);
7268 +
7269 +#endif
7270 +
7271 + return 1;
7272 +}
7273 +
7274 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7275 +{
7276 + unsigned long i;
7277 +
7278 + printk(KERN_ERR "PAX: bytes at PC: ");
7279 + for (i = 0; i < 8; i++) {
7280 + unsigned int c;
7281 + if (get_user(c, (unsigned int *)pc+i))
7282 + printk(KERN_CONT "???????? ");
7283 + else
7284 + printk(KERN_CONT "%08x ", c);
7285 + }
7286 + printk("\n");
7287 +}
7288 +#endif
7289 +
7290 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7291 {
7292 struct mm_struct *mm = current->mm;
7293 @@ -343,6 +806,29 @@ retry:
7294 if (!vma)
7295 goto bad_area;
7296
7297 +#ifdef CONFIG_PAX_PAGEEXEC
7298 + /* PaX: detect ITLB misses on non-exec pages */
7299 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7300 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7301 + {
7302 + if (address != regs->tpc)
7303 + goto good_area;
7304 +
7305 + up_read(&mm->mmap_sem);
7306 + switch (pax_handle_fetch_fault(regs)) {
7307 +
7308 +#ifdef CONFIG_PAX_EMUPLT
7309 + case 2:
7310 + case 3:
7311 + return;
7312 +#endif
7313 +
7314 + }
7315 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7316 + do_group_exit(SIGKILL);
7317 + }
7318 +#endif
7319 +
7320 /* Pure DTLB misses do not tell us whether the fault causing
7321 * load/store/atomic was a write or not, it only says that there
7322 * was no match. So in such a case we (carefully) read the
7323 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7324 index 07e1453..0a7d9e9 100644
7325 --- a/arch/sparc/mm/hugetlbpage.c
7326 +++ b/arch/sparc/mm/hugetlbpage.c
7327 @@ -67,7 +67,7 @@ full_search:
7328 }
7329 return -ENOMEM;
7330 }
7331 - if (likely(!vma || addr + len <= vma->vm_start)) {
7332 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7333 /*
7334 * Remember the place where we stopped the search:
7335 */
7336 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7337 /* make sure it can fit in the remaining address space */
7338 if (likely(addr > len)) {
7339 vma = find_vma(mm, addr-len);
7340 - if (!vma || addr <= vma->vm_start) {
7341 + if (check_heap_stack_gap(vma, addr - len, len)) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr-len);
7344 }
7345 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 if (unlikely(mm->mmap_base < len))
7347 goto bottomup;
7348
7349 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7350 + addr = mm->mmap_base - len;
7351
7352 do {
7353 + addr &= HPAGE_MASK;
7354 /*
7355 * Lookup failure means no vma is above this address,
7356 * else if new region fits below vma->vm_start,
7357 * return with success:
7358 */
7359 vma = find_vma(mm, addr);
7360 - if (likely(!vma || addr+len <= vma->vm_start)) {
7361 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7362 /* remember the address as a hint for next time */
7363 return (mm->free_area_cache = addr);
7364 }
7365 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7366 mm->cached_hole_size = vma->vm_start - addr;
7367
7368 /* try just below the current vma->vm_start */
7369 - addr = (vma->vm_start-len) & HPAGE_MASK;
7370 - } while (likely(len < vma->vm_start));
7371 + addr = skip_heap_stack_gap(vma, len);
7372 + } while (!IS_ERR_VALUE(addr));
7373
7374 bottomup:
7375 /*
7376 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7377 if (addr) {
7378 addr = ALIGN(addr, HPAGE_SIZE);
7379 vma = find_vma(mm, addr);
7380 - if (task_size - len >= addr &&
7381 - (!vma || addr + len <= vma->vm_start))
7382 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7383 return addr;
7384 }
7385 if (mm->get_unmapped_area == arch_get_unmapped_area)
7386 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7387 index f4500c6..889656c 100644
7388 --- a/arch/tile/include/asm/atomic_64.h
7389 +++ b/arch/tile/include/asm/atomic_64.h
7390 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7391
7392 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7393
7394 +#define atomic64_read_unchecked(v) atomic64_read(v)
7395 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7396 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7397 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7398 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7399 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7400 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7401 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7402 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7403 +
7404 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7405 #define smp_mb__before_atomic_dec() smp_mb()
7406 #define smp_mb__after_atomic_dec() smp_mb()
7407 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7408 index a9a5299..0fce79e 100644
7409 --- a/arch/tile/include/asm/cache.h
7410 +++ b/arch/tile/include/asm/cache.h
7411 @@ -15,11 +15,12 @@
7412 #ifndef _ASM_TILE_CACHE_H
7413 #define _ASM_TILE_CACHE_H
7414
7415 +#include <linux/const.h>
7416 #include <arch/chip.h>
7417
7418 /* bytes per L1 data cache line */
7419 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7420 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7421 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7422
7423 /* bytes per L2 cache line */
7424 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7425 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7426 index 9ab078a..d6635c2 100644
7427 --- a/arch/tile/include/asm/uaccess.h
7428 +++ b/arch/tile/include/asm/uaccess.h
7429 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7430 const void __user *from,
7431 unsigned long n)
7432 {
7433 - int sz = __compiletime_object_size(to);
7434 + size_t sz = __compiletime_object_size(to);
7435
7436 - if (likely(sz == -1 || sz >= n))
7437 + if (likely(sz == (size_t)-1 || sz >= n))
7438 n = _copy_from_user(to, from, n);
7439 else
7440 copy_from_user_overflow();
7441 diff --git a/arch/um/Makefile b/arch/um/Makefile
7442 index 0970910..9f65c40 100644
7443 --- a/arch/um/Makefile
7444 +++ b/arch/um/Makefile
7445 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7446 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7447 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7448
7449 +ifdef CONSTIFY_PLUGIN
7450 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7451 +endif
7452 +
7453 #This will adjust *FLAGS accordingly to the platform.
7454 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7455
7456 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7457 index 19e1bdd..3665b77 100644
7458 --- a/arch/um/include/asm/cache.h
7459 +++ b/arch/um/include/asm/cache.h
7460 @@ -1,6 +1,7 @@
7461 #ifndef __UM_CACHE_H
7462 #define __UM_CACHE_H
7463
7464 +#include <linux/const.h>
7465
7466 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7467 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7468 @@ -12,6 +13,6 @@
7469 # define L1_CACHE_SHIFT 5
7470 #endif
7471
7472 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7473 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7474
7475 #endif
7476 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7477 index 2e0a6b1..a64d0f5 100644
7478 --- a/arch/um/include/asm/kmap_types.h
7479 +++ b/arch/um/include/asm/kmap_types.h
7480 @@ -8,6 +8,6 @@
7481
7482 /* No more #include "asm/arch/kmap_types.h" ! */
7483
7484 -#define KM_TYPE_NR 14
7485 +#define KM_TYPE_NR 15
7486
7487 #endif
7488 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7489 index 7cfc3ce..cbd1a58 100644
7490 --- a/arch/um/include/asm/page.h
7491 +++ b/arch/um/include/asm/page.h
7492 @@ -14,6 +14,9 @@
7493 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7494 #define PAGE_MASK (~(PAGE_SIZE-1))
7495
7496 +#define ktla_ktva(addr) (addr)
7497 +#define ktva_ktla(addr) (addr)
7498 +
7499 #ifndef __ASSEMBLY__
7500
7501 struct page;
7502 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7503 index 0032f92..cd151e0 100644
7504 --- a/arch/um/include/asm/pgtable-3level.h
7505 +++ b/arch/um/include/asm/pgtable-3level.h
7506 @@ -58,6 +58,7 @@
7507 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7508 #define pud_populate(mm, pud, pmd) \
7509 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7510 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7511
7512 #ifdef CONFIG_64BIT
7513 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7514 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7515 index c5f5afa..6abce4b 100644
7516 --- a/arch/um/kernel/process.c
7517 +++ b/arch/um/kernel/process.c
7518 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7519 return 2;
7520 }
7521
7522 -/*
7523 - * Only x86 and x86_64 have an arch_align_stack().
7524 - * All other arches have "#define arch_align_stack(x) (x)"
7525 - * in their asm/system.h
7526 - * As this is included in UML from asm-um/system-generic.h,
7527 - * we can use it to behave as the subarch does.
7528 - */
7529 -#ifndef arch_align_stack
7530 -unsigned long arch_align_stack(unsigned long sp)
7531 -{
7532 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7533 - sp -= get_random_int() % 8192;
7534 - return sp & ~0xf;
7535 -}
7536 -#endif
7537 -
7538 unsigned long get_wchan(struct task_struct *p)
7539 {
7540 unsigned long stack_page, sp, ip;
7541 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7542 index ad8f795..2c7eec6 100644
7543 --- a/arch/unicore32/include/asm/cache.h
7544 +++ b/arch/unicore32/include/asm/cache.h
7545 @@ -12,8 +12,10 @@
7546 #ifndef __UNICORE_CACHE_H__
7547 #define __UNICORE_CACHE_H__
7548
7549 -#define L1_CACHE_SHIFT (5)
7550 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7551 +#include <linux/const.h>
7552 +
7553 +#define L1_CACHE_SHIFT 5
7554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7555
7556 /*
7557 * Memory returned by kmalloc() may be used for DMA, so we must make
7558 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7559 index 50a1d1f..c26369f 100644
7560 --- a/arch/x86/Kconfig
7561 +++ b/arch/x86/Kconfig
7562 @@ -220,7 +220,7 @@ config X86_HT
7563
7564 config X86_32_LAZY_GS
7565 def_bool y
7566 - depends on X86_32 && !CC_STACKPROTECTOR
7567 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7568
7569 config ARCH_HWEIGHT_CFLAGS
7570 string
7571 @@ -1049,7 +1049,7 @@ choice
7572
7573 config NOHIGHMEM
7574 bool "off"
7575 - depends on !X86_NUMAQ
7576 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7577 ---help---
7578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7579 However, the address space of 32-bit x86 processors is only 4
7580 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7581
7582 config HIGHMEM4G
7583 bool "4GB"
7584 - depends on !X86_NUMAQ
7585 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7586 ---help---
7587 Select this if you have a 32-bit processor and between 1 and 4
7588 gigabytes of physical RAM.
7589 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7590 hex
7591 default 0xB0000000 if VMSPLIT_3G_OPT
7592 default 0x80000000 if VMSPLIT_2G
7593 - default 0x78000000 if VMSPLIT_2G_OPT
7594 + default 0x70000000 if VMSPLIT_2G_OPT
7595 default 0x40000000 if VMSPLIT_1G
7596 default 0xC0000000
7597 depends on X86_32
7598 @@ -1528,6 +1528,7 @@ config SECCOMP
7599
7600 config CC_STACKPROTECTOR
7601 bool "Enable -fstack-protector buffer overflow detection"
7602 + depends on X86_64 || !PAX_MEMORY_UDEREF
7603 ---help---
7604 This option turns on the -fstack-protector GCC feature. This
7605 feature puts, at the beginning of functions, a canary value on
7606 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7607 config PHYSICAL_START
7608 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7609 default "0x1000000"
7610 + range 0x400000 0x40000000
7611 ---help---
7612 This gives the physical address where the kernel is loaded.
7613
7614 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7615 config PHYSICAL_ALIGN
7616 hex "Alignment value to which kernel should be aligned" if X86_32
7617 default "0x1000000"
7618 + range 0x400000 0x1000000 if PAX_KERNEXEC
7619 range 0x2000 0x1000000
7620 ---help---
7621 This value puts the alignment restrictions on physical address
7622 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7623 Say N if you want to disable CPU hotplug.
7624
7625 config COMPAT_VDSO
7626 - def_bool y
7627 + def_bool n
7628 prompt "Compat VDSO support"
7629 depends on X86_32 || IA32_EMULATION
7630 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7631 ---help---
7632 Map the 32-bit VDSO to the predictable old-style address too.
7633
7634 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7635 index 706e12e..62e4feb 100644
7636 --- a/arch/x86/Kconfig.cpu
7637 +++ b/arch/x86/Kconfig.cpu
7638 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7639
7640 config X86_F00F_BUG
7641 def_bool y
7642 - depends on M586MMX || M586TSC || M586 || M486 || M386
7643 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7644
7645 config X86_INVD_BUG
7646 def_bool y
7647 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7648
7649 config X86_ALIGNMENT_16
7650 def_bool y
7651 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7652 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7653
7654 config X86_INTEL_USERCOPY
7655 def_bool y
7656 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7657 # generates cmov.
7658 config X86_CMOV
7659 def_bool y
7660 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7661 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7662
7663 config X86_MINIMUM_CPU_FAMILY
7664 int
7665 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7666 index b322f12..652d0d9 100644
7667 --- a/arch/x86/Kconfig.debug
7668 +++ b/arch/x86/Kconfig.debug
7669 @@ -84,7 +84,7 @@ config X86_PTDUMP
7670 config DEBUG_RODATA
7671 bool "Write protect kernel read-only data structures"
7672 default y
7673 - depends on DEBUG_KERNEL
7674 + depends on DEBUG_KERNEL && BROKEN
7675 ---help---
7676 Mark the kernel read-only data as write-protected in the pagetables,
7677 in order to catch accidental (and incorrect) writes to such const
7678 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7679
7680 config DEBUG_SET_MODULE_RONX
7681 bool "Set loadable kernel module data as NX and text as RO"
7682 - depends on MODULES
7683 + depends on MODULES && BROKEN
7684 ---help---
7685 This option helps catch unintended modifications to loadable
7686 kernel module's text and read-only data. It also prevents execution
7687 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7688
7689 config DEBUG_STRICT_USER_COPY_CHECKS
7690 bool "Strict copy size checks"
7691 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7692 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7693 ---help---
7694 Enabling this option turns a certain set of sanity checks for user
7695 copy operations into compile time failures.
7696 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7697 index 05afcca..b6ecb51 100644
7698 --- a/arch/x86/Makefile
7699 +++ b/arch/x86/Makefile
7700 @@ -50,6 +50,7 @@ else
7701 UTS_MACHINE := x86_64
7702 CHECKFLAGS += -D__x86_64__ -m64
7703
7704 + biarch := $(call cc-option,-m64)
7705 KBUILD_AFLAGS += -m64
7706 KBUILD_CFLAGS += -m64
7707
7708 @@ -229,3 +230,12 @@ define archhelp
7709 echo ' FDARGS="..." arguments for the booted kernel'
7710 echo ' FDINITRD=file initrd for the booted kernel'
7711 endef
7712 +
7713 +define OLD_LD
7714 +
7715 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7716 +*** Please upgrade your binutils to 2.18 or newer
7717 +endef
7718 +
7719 +archprepare:
7720 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7721 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7722 index f7535be..37db2d1 100644
7723 --- a/arch/x86/boot/Makefile
7724 +++ b/arch/x86/boot/Makefile
7725 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7726 $(call cc-option, -fno-stack-protector) \
7727 $(call cc-option, -mpreferred-stack-boundary=2)
7728 KBUILD_CFLAGS += $(call cc-option, -m32)
7729 +ifdef CONSTIFY_PLUGIN
7730 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7731 +endif
7732 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7733 GCOV_PROFILE := n
7734
7735 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7736 index 878e4b9..20537ab 100644
7737 --- a/arch/x86/boot/bitops.h
7738 +++ b/arch/x86/boot/bitops.h
7739 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7740 u8 v;
7741 const u32 *p = (const u32 *)addr;
7742
7743 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7744 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7745 return v;
7746 }
7747
7748 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7749
7750 static inline void set_bit(int nr, void *addr)
7751 {
7752 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7753 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7754 }
7755
7756 #endif /* BOOT_BITOPS_H */
7757 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7758 index 18997e5..83d9c67 100644
7759 --- a/arch/x86/boot/boot.h
7760 +++ b/arch/x86/boot/boot.h
7761 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7762 static inline u16 ds(void)
7763 {
7764 u16 seg;
7765 - asm("movw %%ds,%0" : "=rm" (seg));
7766 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7767 return seg;
7768 }
7769
7770 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7771 static inline int memcmp(const void *s1, const void *s2, size_t len)
7772 {
7773 u8 diff;
7774 - asm("repe; cmpsb; setnz %0"
7775 + asm volatile("repe; cmpsb; setnz %0"
7776 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7777 return diff;
7778 }
7779 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7780 index 8a84501..b2d165f 100644
7781 --- a/arch/x86/boot/compressed/Makefile
7782 +++ b/arch/x86/boot/compressed/Makefile
7783 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7784 KBUILD_CFLAGS += $(cflags-y)
7785 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7786 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7787 +ifdef CONSTIFY_PLUGIN
7788 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7789 +endif
7790
7791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7792 GCOV_PROFILE := n
7793 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7794 index b3e0227..f2c02d5 100644
7795 --- a/arch/x86/boot/compressed/eboot.c
7796 +++ b/arch/x86/boot/compressed/eboot.c
7797 @@ -142,7 +142,6 @@ again:
7798 *addr = max_addr;
7799 }
7800
7801 -free_pool:
7802 efi_call_phys1(sys_table->boottime->free_pool, map);
7803
7804 fail:
7805 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7806 if (i == map_size / desc_size)
7807 status = EFI_NOT_FOUND;
7808
7809 -free_pool:
7810 efi_call_phys1(sys_table->boottime->free_pool, map);
7811 fail:
7812 return status;
7813 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7814 index aa4aaf1..6656f2f 100644
7815 --- a/arch/x86/boot/compressed/head_32.S
7816 +++ b/arch/x86/boot/compressed/head_32.S
7817 @@ -116,7 +116,7 @@ preferred_addr:
7818 notl %eax
7819 andl %eax, %ebx
7820 #else
7821 - movl $LOAD_PHYSICAL_ADDR, %ebx
7822 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7823 #endif
7824
7825 /* Target address to relocate to for decompression */
7826 @@ -202,7 +202,7 @@ relocated:
7827 * and where it was actually loaded.
7828 */
7829 movl %ebp, %ebx
7830 - subl $LOAD_PHYSICAL_ADDR, %ebx
7831 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7832 jz 2f /* Nothing to be done if loaded at compiled addr. */
7833 /*
7834 * Process relocations.
7835 @@ -210,8 +210,7 @@ relocated:
7836
7837 1: subl $4, %edi
7838 movl (%edi), %ecx
7839 - testl %ecx, %ecx
7840 - jz 2f
7841 + jecxz 2f
7842 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7843 jmp 1b
7844 2:
7845 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7846 index 2c4b171..e1fa5b1 100644
7847 --- a/arch/x86/boot/compressed/head_64.S
7848 +++ b/arch/x86/boot/compressed/head_64.S
7849 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7850 notl %eax
7851 andl %eax, %ebx
7852 #else
7853 - movl $LOAD_PHYSICAL_ADDR, %ebx
7854 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7855 #endif
7856
7857 /* Target address to relocate to for decompression */
7858 @@ -273,7 +273,7 @@ preferred_addr:
7859 notq %rax
7860 andq %rax, %rbp
7861 #else
7862 - movq $LOAD_PHYSICAL_ADDR, %rbp
7863 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7864 #endif
7865
7866 /* Target address to relocate to for decompression */
7867 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7868 index 88f7ff6..ed695dd 100644
7869 --- a/arch/x86/boot/compressed/misc.c
7870 +++ b/arch/x86/boot/compressed/misc.c
7871 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7872 case PT_LOAD:
7873 #ifdef CONFIG_RELOCATABLE
7874 dest = output;
7875 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7876 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7877 #else
7878 dest = (void *)(phdr->p_paddr);
7879 #endif
7880 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7881 error("Destination address too large");
7882 #endif
7883 #ifndef CONFIG_RELOCATABLE
7884 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7885 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7886 error("Wrong destination address");
7887 #endif
7888
7889 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7890 index 4d3ff03..e4972ff 100644
7891 --- a/arch/x86/boot/cpucheck.c
7892 +++ b/arch/x86/boot/cpucheck.c
7893 @@ -74,7 +74,7 @@ static int has_fpu(void)
7894 u16 fcw = -1, fsw = -1;
7895 u32 cr0;
7896
7897 - asm("movl %%cr0,%0" : "=r" (cr0));
7898 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7899 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7900 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7901 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7902 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7903 {
7904 u32 f0, f1;
7905
7906 - asm("pushfl ; "
7907 + asm volatile("pushfl ; "
7908 "pushfl ; "
7909 "popl %0 ; "
7910 "movl %0,%1 ; "
7911 @@ -115,7 +115,7 @@ static void get_flags(void)
7912 set_bit(X86_FEATURE_FPU, cpu.flags);
7913
7914 if (has_eflag(X86_EFLAGS_ID)) {
7915 - asm("cpuid"
7916 + asm volatile("cpuid"
7917 : "=a" (max_intel_level),
7918 "=b" (cpu_vendor[0]),
7919 "=d" (cpu_vendor[1]),
7920 @@ -124,7 +124,7 @@ static void get_flags(void)
7921
7922 if (max_intel_level >= 0x00000001 &&
7923 max_intel_level <= 0x0000ffff) {
7924 - asm("cpuid"
7925 + asm volatile("cpuid"
7926 : "=a" (tfms),
7927 "=c" (cpu.flags[4]),
7928 "=d" (cpu.flags[0])
7929 @@ -136,7 +136,7 @@ static void get_flags(void)
7930 cpu.model += ((tfms >> 16) & 0xf) << 4;
7931 }
7932
7933 - asm("cpuid"
7934 + asm volatile("cpuid"
7935 : "=a" (max_amd_level)
7936 : "a" (0x80000000)
7937 : "ebx", "ecx", "edx");
7938 @@ -144,7 +144,7 @@ static void get_flags(void)
7939 if (max_amd_level >= 0x80000001 &&
7940 max_amd_level <= 0x8000ffff) {
7941 u32 eax = 0x80000001;
7942 - asm("cpuid"
7943 + asm volatile("cpuid"
7944 : "+a" (eax),
7945 "=c" (cpu.flags[6]),
7946 "=d" (cpu.flags[1])
7947 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7948 u32 ecx = MSR_K7_HWCR;
7949 u32 eax, edx;
7950
7951 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7952 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7953 eax &= ~(1 << 15);
7954 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7955 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956
7957 get_flags(); /* Make sure it really did something */
7958 err = check_flags();
7959 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7960 u32 ecx = MSR_VIA_FCR;
7961 u32 eax, edx;
7962
7963 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7964 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7965 eax |= (1<<1)|(1<<7);
7966 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7967 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7968
7969 set_bit(X86_FEATURE_CX8, cpu.flags);
7970 err = check_flags();
7971 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 eax, edx;
7973 u32 level = 1;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7977 - asm("cpuid"
7978 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7980 + asm volatile("cpuid"
7981 : "+a" (level), "=d" (cpu.flags[0])
7982 : : "ecx", "ebx");
7983 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7984 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7985
7986 err = check_flags();
7987 }
7988 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7989 index b4e15dd..8ac59ce 100644
7990 --- a/arch/x86/boot/header.S
7991 +++ b/arch/x86/boot/header.S
7992 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7993 # single linked list of
7994 # struct setup_data
7995
7996 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7997 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7998
7999 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8001 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8002 +#else
8003 #define VO_INIT_SIZE (VO__end - VO__text)
8004 +#endif
8005 #if ZO_INIT_SIZE > VO_INIT_SIZE
8006 #define INIT_SIZE ZO_INIT_SIZE
8007 #else
8008 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8009 index db75d07..8e6d0af 100644
8010 --- a/arch/x86/boot/memory.c
8011 +++ b/arch/x86/boot/memory.c
8012 @@ -19,7 +19,7 @@
8013
8014 static int detect_memory_e820(void)
8015 {
8016 - int count = 0;
8017 + unsigned int count = 0;
8018 struct biosregs ireg, oreg;
8019 struct e820entry *desc = boot_params.e820_map;
8020 static struct e820entry buf; /* static so it is zeroed */
8021 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8022 index 11e8c6e..fdbb1ed 100644
8023 --- a/arch/x86/boot/video-vesa.c
8024 +++ b/arch/x86/boot/video-vesa.c
8025 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8026
8027 boot_params.screen_info.vesapm_seg = oreg.es;
8028 boot_params.screen_info.vesapm_off = oreg.di;
8029 + boot_params.screen_info.vesapm_size = oreg.cx;
8030 }
8031
8032 /*
8033 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8034 index 43eda28..5ab5fdb 100644
8035 --- a/arch/x86/boot/video.c
8036 +++ b/arch/x86/boot/video.c
8037 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8038 static unsigned int get_entry(void)
8039 {
8040 char entry_buf[4];
8041 - int i, len = 0;
8042 + unsigned int i, len = 0;
8043 int key;
8044 unsigned int v;
8045
8046 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8047 index 5b577d5..3c1fed4 100644
8048 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8049 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8050 @@ -8,6 +8,8 @@
8051 * including this sentence is retained in full.
8052 */
8053
8054 +#include <asm/alternative-asm.h>
8055 +
8056 .extern crypto_ft_tab
8057 .extern crypto_it_tab
8058 .extern crypto_fl_tab
8059 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8060 je B192; \
8061 leaq 32(r9),r9;
8062
8063 +#define ret pax_force_retaddr 0, 1; ret
8064 +
8065 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8066 movq r1,r2; \
8067 movq r3,r4; \
8068 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8069 index 3470624..201259d 100644
8070 --- a/arch/x86/crypto/aesni-intel_asm.S
8071 +++ b/arch/x86/crypto/aesni-intel_asm.S
8072 @@ -31,6 +31,7 @@
8073
8074 #include <linux/linkage.h>
8075 #include <asm/inst.h>
8076 +#include <asm/alternative-asm.h>
8077
8078 #ifdef __x86_64__
8079 .data
8080 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8081 pop %r14
8082 pop %r13
8083 pop %r12
8084 + pax_force_retaddr 0, 1
8085 ret
8086 +ENDPROC(aesni_gcm_dec)
8087
8088
8089 /*****************************************************************************
8090 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8091 pop %r14
8092 pop %r13
8093 pop %r12
8094 + pax_force_retaddr 0, 1
8095 ret
8096 +ENDPROC(aesni_gcm_enc)
8097
8098 #endif
8099
8100 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8101 pxor %xmm1, %xmm0
8102 movaps %xmm0, (TKEYP)
8103 add $0x10, TKEYP
8104 + pax_force_retaddr_bts
8105 ret
8106
8107 .align 4
8108 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8109 shufps $0b01001110, %xmm2, %xmm1
8110 movaps %xmm1, 0x10(TKEYP)
8111 add $0x20, TKEYP
8112 + pax_force_retaddr_bts
8113 ret
8114
8115 .align 4
8116 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8117
8118 movaps %xmm0, (TKEYP)
8119 add $0x10, TKEYP
8120 + pax_force_retaddr_bts
8121 ret
8122
8123 .align 4
8124 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8125 pxor %xmm1, %xmm2
8126 movaps %xmm2, (TKEYP)
8127 add $0x10, TKEYP
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8133 #ifndef __x86_64__
8134 popl KEYP
8135 #endif
8136 + pax_force_retaddr 0, 1
8137 ret
8138 +ENDPROC(aesni_set_key)
8139
8140 /*
8141 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8142 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8143 popl KLEN
8144 popl KEYP
8145 #endif
8146 + pax_force_retaddr 0, 1
8147 ret
8148 +ENDPROC(aesni_enc)
8149
8150 /*
8151 * _aesni_enc1: internal ABI
8152 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8153 AESENC KEY STATE
8154 movaps 0x70(TKEYP), KEY
8155 AESENCLAST KEY STATE
8156 + pax_force_retaddr_bts
8157 ret
8158
8159 /*
8160 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8161 AESENCLAST KEY STATE2
8162 AESENCLAST KEY STATE3
8163 AESENCLAST KEY STATE4
8164 + pax_force_retaddr_bts
8165 ret
8166
8167 /*
8168 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8169 popl KLEN
8170 popl KEYP
8171 #endif
8172 + pax_force_retaddr 0, 1
8173 ret
8174 +ENDPROC(aesni_dec)
8175
8176 /*
8177 * _aesni_dec1: internal ABI
8178 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8179 AESDEC KEY STATE
8180 movaps 0x70(TKEYP), KEY
8181 AESDECLAST KEY STATE
8182 + pax_force_retaddr_bts
8183 ret
8184
8185 /*
8186 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8187 AESDECLAST KEY STATE2
8188 AESDECLAST KEY STATE3
8189 AESDECLAST KEY STATE4
8190 + pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8195 popl KEYP
8196 popl LEN
8197 #endif
8198 + pax_force_retaddr 0, 1
8199 ret
8200 +ENDPROC(aesni_ecb_enc)
8201
8202 /*
8203 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8205 popl KEYP
8206 popl LEN
8207 #endif
8208 + pax_force_retaddr 0, 1
8209 ret
8210 +ENDPROC(aesni_ecb_dec)
8211
8212 /*
8213 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8214 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8215 popl LEN
8216 popl IVP
8217 #endif
8218 + pax_force_retaddr 0, 1
8219 ret
8220 +ENDPROC(aesni_cbc_enc)
8221
8222 /*
8223 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8224 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8225 popl LEN
8226 popl IVP
8227 #endif
8228 + pax_force_retaddr 0, 1
8229 ret
8230 +ENDPROC(aesni_cbc_dec)
8231
8232 #ifdef __x86_64__
8233 .align 16
8234 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8235 mov $1, TCTR_LOW
8236 MOVQ_R64_XMM TCTR_LOW INC
8237 MOVQ_R64_XMM CTR TCTR_LOW
8238 + pax_force_retaddr_bts
8239 ret
8240
8241 /*
8242 @@ -2554,6 +2582,7 @@ _aesni_inc:
8243 .Linc_low:
8244 movaps CTR, IV
8245 PSHUFB_XMM BSWAP_MASK IV
8246 + pax_force_retaddr_bts
8247 ret
8248
8249 /*
8250 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8251 .Lctr_enc_ret:
8252 movups IV, (IVP)
8253 .Lctr_enc_just_ret:
8254 + pax_force_retaddr 0, 1
8255 ret
8256 +ENDPROC(aesni_ctr_enc)
8257 #endif
8258 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8259 index 391d245..67f35c2 100644
8260 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8261 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8262 @@ -20,6 +20,8 @@
8263 *
8264 */
8265
8266 +#include <asm/alternative-asm.h>
8267 +
8268 .file "blowfish-x86_64-asm.S"
8269 .text
8270
8271 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8272 jnz __enc_xor;
8273
8274 write_block();
8275 + pax_force_retaddr 0, 1
8276 ret;
8277 __enc_xor:
8278 xor_block();
8279 + pax_force_retaddr 0, 1
8280 ret;
8281
8282 .align 8
8283 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8284
8285 movq %r11, %rbp;
8286
8287 + pax_force_retaddr 0, 1
8288 ret;
8289
8290 /**********************************************************************
8291 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8292
8293 popq %rbx;
8294 popq %rbp;
8295 + pax_force_retaddr 0, 1
8296 ret;
8297
8298 __enc_xor4:
8299 @@ -349,6 +355,7 @@ __enc_xor4:
8300
8301 popq %rbx;
8302 popq %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8308 popq %rbx;
8309 popq %rbp;
8310
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8315 index 0b33743..7a56206 100644
8316 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8317 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8318 @@ -20,6 +20,8 @@
8319 *
8320 */
8321
8322 +#include <asm/alternative-asm.h>
8323 +
8324 .file "camellia-x86_64-asm_64.S"
8325 .text
8326
8327 @@ -229,12 +231,14 @@ __enc_done:
8328 enc_outunpack(mov, RT1);
8329
8330 movq RRBP, %rbp;
8331 + pax_force_retaddr 0, 1
8332 ret;
8333
8334 __enc_xor:
8335 enc_outunpack(xor, RT1);
8336
8337 movq RRBP, %rbp;
8338 + pax_force_retaddr 0, 1
8339 ret;
8340
8341 .global camellia_dec_blk;
8342 @@ -275,6 +279,7 @@ __dec_rounds16:
8343 dec_outunpack();
8344
8345 movq RRBP, %rbp;
8346 + pax_force_retaddr 0, 1
8347 ret;
8348
8349 /**********************************************************************
8350 @@ -468,6 +473,7 @@ __enc2_done:
8351
8352 movq RRBP, %rbp;
8353 popq %rbx;
8354 + pax_force_retaddr 0, 1
8355 ret;
8356
8357 __enc2_xor:
8358 @@ -475,6 +481,7 @@ __enc2_xor:
8359
8360 movq RRBP, %rbp;
8361 popq %rbx;
8362 + pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk_2way;
8366 @@ -517,4 +524,5 @@ __dec2_rounds16:
8367
8368 movq RRBP, %rbp;
8369 movq RXOR, %rbx;
8370 + pax_force_retaddr 0, 1
8371 ret;
8372 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8373 index 6214a9b..1f4fc9a 100644
8374 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8375 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8376 @@ -1,3 +1,5 @@
8377 +#include <asm/alternative-asm.h>
8378 +
8379 # enter ECRYPT_encrypt_bytes
8380 .text
8381 .p2align 5
8382 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8383 add %r11,%rsp
8384 mov %rdi,%rax
8385 mov %rsi,%rdx
8386 + pax_force_retaddr 0, 1
8387 ret
8388 # bytesatleast65:
8389 ._bytesatleast65:
8390 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8391 add %r11,%rsp
8392 mov %rdi,%rax
8393 mov %rsi,%rdx
8394 + pax_force_retaddr
8395 ret
8396 # enter ECRYPT_ivsetup
8397 .text
8398 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8399 add %r11,%rsp
8400 mov %rdi,%rax
8401 mov %rsi,%rdx
8402 + pax_force_retaddr
8403 ret
8404 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8405 index 504106b..4e50951 100644
8406 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8407 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8408 @@ -24,6 +24,8 @@
8409 *
8410 */
8411
8412 +#include <asm/alternative-asm.h>
8413 +
8414 .file "serpent-avx-x86_64-asm_64.S"
8415 .text
8416
8417 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8418 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8419 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8420
8421 + pax_force_retaddr
8422 ret;
8423
8424 __enc_xor8:
8425 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8426 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8427
8428 + pax_force_retaddr
8429 ret;
8430
8431 .align 8
8432 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8433 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8434 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8435
8436 + pax_force_retaddr
8437 ret;
8438 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439 index 3ee1ff0..cbc568b 100644
8440 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442 @@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446 +#include <asm/alternative-asm.h>
8447 +
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455 + pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462 + pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470 + pax_force_retaddr
8471 ret;
8472 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473 index 49d6987..df66bd4 100644
8474 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8475 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476 @@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480 +#include <asm/alternative-asm.h>
8481 +
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485 @@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489 + pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8494 index 35f4557..16b379f 100644
8495 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8496 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8497 @@ -21,6 +21,8 @@
8498 *
8499 */
8500
8501 +#include <asm/alternative-asm.h>
8502 +
8503 .file "twofish-avx-x86_64-asm_64.S"
8504 .text
8505
8506 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8507 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8508 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8509
8510 + pax_force_retaddr
8511 ret;
8512
8513 __enc_xor8:
8514 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8515 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8516
8517 + pax_force_retaddr
8518 ret;
8519
8520 .align 8
8521 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8522 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8523 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8524
8525 + pax_force_retaddr
8526 ret;
8527 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8528 index 5b012a2..36d5364 100644
8529 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8530 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8531 @@ -20,6 +20,8 @@
8532 *
8533 */
8534
8535 +#include <asm/alternative-asm.h>
8536 +
8537 .file "twofish-x86_64-asm-3way.S"
8538 .text
8539
8540 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8541 popq %r13;
8542 popq %r14;
8543 popq %r15;
8544 + pax_force_retaddr 0, 1
8545 ret;
8546
8547 __enc_xor3:
8548 @@ -271,6 +274,7 @@ __enc_xor3:
8549 popq %r13;
8550 popq %r14;
8551 popq %r15;
8552 + pax_force_retaddr 0, 1
8553 ret;
8554
8555 .global twofish_dec_blk_3way
8556 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8557 popq %r13;
8558 popq %r14;
8559 popq %r15;
8560 + pax_force_retaddr 0, 1
8561 ret;
8562
8563 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8564 index 7bcf3fc..f53832f 100644
8565 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8566 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8567 @@ -21,6 +21,7 @@
8568 .text
8569
8570 #include <asm/asm-offsets.h>
8571 +#include <asm/alternative-asm.h>
8572
8573 #define a_offset 0
8574 #define b_offset 4
8575 @@ -268,6 +269,7 @@ twofish_enc_blk:
8576
8577 popq R1
8578 movq $1,%rax
8579 + pax_force_retaddr 0, 1
8580 ret
8581
8582 twofish_dec_blk:
8583 @@ -319,4 +321,5 @@ twofish_dec_blk:
8584
8585 popq R1
8586 movq $1,%rax
8587 + pax_force_retaddr 0, 1
8588 ret
8589 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8590 index 07b3a68..bd2a388 100644
8591 --- a/arch/x86/ia32/ia32_aout.c
8592 +++ b/arch/x86/ia32/ia32_aout.c
8593 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8594 unsigned long dump_start, dump_size;
8595 struct user32 dump;
8596
8597 + memset(&dump, 0, sizeof(dump));
8598 +
8599 fs = get_fs();
8600 set_fs(KERNEL_DS);
8601 has_dumped = 1;
8602 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8603 index 673ac9b..7a8c5df 100644
8604 --- a/arch/x86/ia32/ia32_signal.c
8605 +++ b/arch/x86/ia32/ia32_signal.c
8606 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8607 }
8608 seg = get_fs();
8609 set_fs(KERNEL_DS);
8610 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8611 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8612 set_fs(seg);
8613 if (ret >= 0 && uoss_ptr) {
8614 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8615 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8616 */
8617 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8618 size_t frame_size,
8619 - void **fpstate)
8620 + void __user **fpstate)
8621 {
8622 unsigned long sp;
8623
8624 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8625
8626 if (used_math()) {
8627 sp = sp - sig_xstate_ia32_size;
8628 - *fpstate = (struct _fpstate_ia32 *) sp;
8629 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8630 if (save_i387_xstate_ia32(*fpstate) < 0)
8631 return (void __user *) -1L;
8632 }
8633 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8634 sp -= frame_size;
8635 /* Align the stack pointer according to the i386 ABI,
8636 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8637 - sp = ((sp + 4) & -16ul) - 4;
8638 + sp = ((sp - 12) & -16ul) - 4;
8639 return (void __user *) sp;
8640 }
8641
8642 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8643 * These are actually not used anymore, but left because some
8644 * gdb versions depend on them as a marker.
8645 */
8646 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8647 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8648 } put_user_catch(err);
8649
8650 if (err)
8651 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8652 0xb8,
8653 __NR_ia32_rt_sigreturn,
8654 0x80cd,
8655 - 0,
8656 + 0
8657 };
8658
8659 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8660 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8661
8662 if (ka->sa.sa_flags & SA_RESTORER)
8663 restorer = ka->sa.sa_restorer;
8664 + else if (current->mm->context.vdso)
8665 + /* Return stub is in 32bit vsyscall page */
8666 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8667 else
8668 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8669 - rt_sigreturn);
8670 + restorer = &frame->retcode;
8671 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8672
8673 /*
8674 * Not actually used anymore, but left because some gdb
8675 * versions need it.
8676 */
8677 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8678 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8679 } put_user_catch(err);
8680
8681 if (err)
8682 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8683 index 20e5f7b..f33c779 100644
8684 --- a/arch/x86/ia32/ia32entry.S
8685 +++ b/arch/x86/ia32/ia32entry.S
8686 @@ -14,8 +14,10 @@
8687 #include <asm/segment.h>
8688 #include <asm/irqflags.h>
8689 #include <asm/asm.h>
8690 +#include <asm/pgtable.h>
8691 #include <linux/linkage.h>
8692 #include <linux/err.h>
8693 +#include <asm/alternative-asm.h>
8694
8695 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8696 #include <linux/elf-em.h>
8697 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8698 ENDPROC(native_irq_enable_sysexit)
8699 #endif
8700
8701 + .macro pax_enter_kernel_user
8702 + pax_set_fptr_mask
8703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8704 + call pax_enter_kernel_user
8705 +#endif
8706 + .endm
8707 +
8708 + .macro pax_exit_kernel_user
8709 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8710 + call pax_exit_kernel_user
8711 +#endif
8712 +#ifdef CONFIG_PAX_RANDKSTACK
8713 + pushq %rax
8714 + pushq %r11
8715 + call pax_randomize_kstack
8716 + popq %r11
8717 + popq %rax
8718 +#endif
8719 + .endm
8720 +
8721 +.macro pax_erase_kstack
8722 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8723 + call pax_erase_kstack
8724 +#endif
8725 +.endm
8726 +
8727 /*
8728 * 32bit SYSENTER instruction entry.
8729 *
8730 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8731 CFI_REGISTER rsp,rbp
8732 SWAPGS_UNSAFE_STACK
8733 movq PER_CPU_VAR(kernel_stack), %rsp
8734 - addq $(KERNEL_STACK_OFFSET),%rsp
8735 - /*
8736 - * No need to follow this irqs on/off section: the syscall
8737 - * disabled irqs, here we enable it straight after entry:
8738 - */
8739 - ENABLE_INTERRUPTS(CLBR_NONE)
8740 movl %ebp,%ebp /* zero extension */
8741 pushq_cfi $__USER32_DS
8742 /*CFI_REL_OFFSET ss,0*/
8743 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8744 CFI_REL_OFFSET rsp,0
8745 pushfq_cfi
8746 /*CFI_REL_OFFSET rflags,0*/
8747 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8748 - CFI_REGISTER rip,r10
8749 + orl $X86_EFLAGS_IF,(%rsp)
8750 + GET_THREAD_INFO(%r11)
8751 + movl TI_sysenter_return(%r11), %r11d
8752 + CFI_REGISTER rip,r11
8753 pushq_cfi $__USER32_CS
8754 /*CFI_REL_OFFSET cs,0*/
8755 movl %eax, %eax
8756 - pushq_cfi %r10
8757 + pushq_cfi %r11
8758 CFI_REL_OFFSET rip,0
8759 pushq_cfi %rax
8760 cld
8761 SAVE_ARGS 0,1,0
8762 + pax_enter_kernel_user
8763 +
8764 +#ifdef CONFIG_PAX_RANDKSTACK
8765 + pax_erase_kstack
8766 +#endif
8767 +
8768 + /*
8769 + * No need to follow this irqs on/off section: the syscall
8770 + * disabled irqs, here we enable it straight after entry:
8771 + */
8772 + ENABLE_INTERRUPTS(CLBR_NONE)
8773 /* no need to do an access_ok check here because rbp has been
8774 32bit zero extended */
8775 +
8776 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8777 + mov $PAX_USER_SHADOW_BASE,%r11
8778 + add %r11,%rbp
8779 +#endif
8780 +
8781 1: movl (%rbp),%ebp
8782 _ASM_EXTABLE(1b,ia32_badarg)
8783 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8784 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8785 + GET_THREAD_INFO(%r11)
8786 + orl $TS_COMPAT,TI_status(%r11)
8787 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8788 CFI_REMEMBER_STATE
8789 jnz sysenter_tracesys
8790 cmpq $(IA32_NR_syscalls-1),%rax
8791 @@ -159,12 +201,15 @@ sysenter_do_call:
8792 sysenter_dispatch:
8793 call *ia32_sys_call_table(,%rax,8)
8794 movq %rax,RAX-ARGOFFSET(%rsp)
8795 + GET_THREAD_INFO(%r11)
8796 DISABLE_INTERRUPTS(CLBR_NONE)
8797 TRACE_IRQS_OFF
8798 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8799 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8800 jnz sysexit_audit
8801 sysexit_from_sys_call:
8802 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803 + pax_exit_kernel_user
8804 + pax_erase_kstack
8805 + andl $~TS_COMPAT,TI_status(%r11)
8806 /* clear IF, that popfq doesn't enable interrupts early */
8807 andl $~0x200,EFLAGS-R11(%rsp)
8808 movl RIP-R11(%rsp),%edx /* User %eip */
8809 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8810 movl %eax,%esi /* 2nd arg: syscall number */
8811 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8812 call __audit_syscall_entry
8813 +
8814 + pax_erase_kstack
8815 +
8816 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8817 cmpq $(IA32_NR_syscalls-1),%rax
8818 ja ia32_badsys
8819 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8820 .endm
8821
8822 .macro auditsys_exit exit
8823 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8824 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8825 jnz ia32_ret_from_sys_call
8826 TRACE_IRQS_ON
8827 sti
8828 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8829 1: setbe %al /* 1 if error, 0 if not */
8830 movzbl %al,%edi /* zero-extend that into %edi */
8831 call __audit_syscall_exit
8832 + GET_THREAD_INFO(%r11)
8833 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8834 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8835 cli
8836 TRACE_IRQS_OFF
8837 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8838 + testl %edi,TI_flags(%r11)
8839 jz \exit
8840 CLEAR_RREGS -ARGOFFSET
8841 jmp int_with_check
8842 @@ -234,7 +283,7 @@ sysexit_audit:
8843
8844 sysenter_tracesys:
8845 #ifdef CONFIG_AUDITSYSCALL
8846 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8848 jz sysenter_auditsys
8849 #endif
8850 SAVE_REST
8851 @@ -246,6 +295,9 @@ sysenter_tracesys:
8852 RESTORE_REST
8853 cmpq $(IA32_NR_syscalls-1),%rax
8854 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8855 +
8856 + pax_erase_kstack
8857 +
8858 jmp sysenter_do_call
8859 CFI_ENDPROC
8860 ENDPROC(ia32_sysenter_target)
8861 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8862 ENTRY(ia32_cstar_target)
8863 CFI_STARTPROC32 simple
8864 CFI_SIGNAL_FRAME
8865 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8866 + CFI_DEF_CFA rsp,0
8867 CFI_REGISTER rip,rcx
8868 /*CFI_REGISTER rflags,r11*/
8869 SWAPGS_UNSAFE_STACK
8870 movl %esp,%r8d
8871 CFI_REGISTER rsp,r8
8872 movq PER_CPU_VAR(kernel_stack),%rsp
8873 + SAVE_ARGS 8*6,0,0
8874 + pax_enter_kernel_user
8875 +
8876 +#ifdef CONFIG_PAX_RANDKSTACK
8877 + pax_erase_kstack
8878 +#endif
8879 +
8880 /*
8881 * No need to follow this irqs on/off section: the syscall
8882 * disabled irqs and here we enable it straight after entry:
8883 */
8884 ENABLE_INTERRUPTS(CLBR_NONE)
8885 - SAVE_ARGS 8,0,0
8886 movl %eax,%eax /* zero extension */
8887 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8888 movq %rcx,RIP-ARGOFFSET(%rsp)
8889 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8890 /* no need to do an access_ok check here because r8 has been
8891 32bit zero extended */
8892 /* hardware stack frame is complete now */
8893 +
8894 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8895 + mov $PAX_USER_SHADOW_BASE,%r11
8896 + add %r11,%r8
8897 +#endif
8898 +
8899 1: movl (%r8),%r9d
8900 _ASM_EXTABLE(1b,ia32_badarg)
8901 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8902 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8903 + GET_THREAD_INFO(%r11)
8904 + orl $TS_COMPAT,TI_status(%r11)
8905 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8906 CFI_REMEMBER_STATE
8907 jnz cstar_tracesys
8908 cmpq $IA32_NR_syscalls-1,%rax
8909 @@ -314,12 +379,15 @@ cstar_do_call:
8910 cstar_dispatch:
8911 call *ia32_sys_call_table(,%rax,8)
8912 movq %rax,RAX-ARGOFFSET(%rsp)
8913 + GET_THREAD_INFO(%r11)
8914 DISABLE_INTERRUPTS(CLBR_NONE)
8915 TRACE_IRQS_OFF
8916 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8917 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8918 jnz sysretl_audit
8919 sysretl_from_sys_call:
8920 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921 + pax_exit_kernel_user
8922 + pax_erase_kstack
8923 + andl $~TS_COMPAT,TI_status(%r11)
8924 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8925 movl RIP-ARGOFFSET(%rsp),%ecx
8926 CFI_REGISTER rip,rcx
8927 @@ -347,7 +415,7 @@ sysretl_audit:
8928
8929 cstar_tracesys:
8930 #ifdef CONFIG_AUDITSYSCALL
8931 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8932 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8933 jz cstar_auditsys
8934 #endif
8935 xchgl %r9d,%ebp
8936 @@ -361,6 +429,9 @@ cstar_tracesys:
8937 xchgl %ebp,%r9d
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8940 +
8941 + pax_erase_kstack
8942 +
8943 jmp cstar_do_call
8944 END(ia32_cstar_target)
8945
8946 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8947 CFI_REL_OFFSET rip,RIP-RIP
8948 PARAVIRT_ADJUST_EXCEPTION_FRAME
8949 SWAPGS
8950 - /*
8951 - * No need to follow this irqs on/off section: the syscall
8952 - * disabled irqs and here we enable it straight after entry:
8953 - */
8954 - ENABLE_INTERRUPTS(CLBR_NONE)
8955 movl %eax,%eax
8956 pushq_cfi %rax
8957 cld
8958 /* note the registers are not zero extended to the sf.
8959 this could be a problem. */
8960 SAVE_ARGS 0,1,0
8961 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8962 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8963 + pax_enter_kernel_user
8964 +
8965 +#ifdef CONFIG_PAX_RANDKSTACK
8966 + pax_erase_kstack
8967 +#endif
8968 +
8969 + /*
8970 + * No need to follow this irqs on/off section: the syscall
8971 + * disabled irqs and here we enable it straight after entry:
8972 + */
8973 + ENABLE_INTERRUPTS(CLBR_NONE)
8974 + GET_THREAD_INFO(%r11)
8975 + orl $TS_COMPAT,TI_status(%r11)
8976 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8977 jnz ia32_tracesys
8978 cmpq $(IA32_NR_syscalls-1),%rax
8979 ja ia32_badsys
8980 @@ -436,6 +514,9 @@ ia32_tracesys:
8981 RESTORE_REST
8982 cmpq $(IA32_NR_syscalls-1),%rax
8983 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8984 +
8985 + pax_erase_kstack
8986 +
8987 jmp ia32_do_call
8988 END(ia32_syscall)
8989
8990 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8991 index 4540bec..714d913 100644
8992 --- a/arch/x86/ia32/sys_ia32.c
8993 +++ b/arch/x86/ia32/sys_ia32.c
8994 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8995 */
8996 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8997 {
8998 - typeof(ubuf->st_uid) uid = 0;
8999 - typeof(ubuf->st_gid) gid = 0;
9000 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9001 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9002 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9003 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9004 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9005 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9006 return ret;
9007 }
9008
9009 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9010 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9011 int options)
9012 {
9013 return compat_sys_wait4(pid, stat_addr, options, NULL);
9014 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9015 mm_segment_t old_fs = get_fs();
9016
9017 set_fs(KERNEL_DS);
9018 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9019 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9020 set_fs(old_fs);
9021 if (put_compat_timespec(&t, interval))
9022 return -EFAULT;
9023 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9024 mm_segment_t old_fs = get_fs();
9025
9026 set_fs(KERNEL_DS);
9027 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9028 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9029 set_fs(old_fs);
9030 if (!ret) {
9031 switch (_NSIG_WORDS) {
9032 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9033 if (copy_siginfo_from_user32(&info, uinfo))
9034 return -EFAULT;
9035 set_fs(KERNEL_DS);
9036 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9037 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9038 set_fs(old_fs);
9039 return ret;
9040 }
9041 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9042 return -EFAULT;
9043
9044 set_fs(KERNEL_DS);
9045 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9046 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9047 count);
9048 set_fs(old_fs);
9049
9050 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9051 index 952bd01..7692c6f 100644
9052 --- a/arch/x86/include/asm/alternative-asm.h
9053 +++ b/arch/x86/include/asm/alternative-asm.h
9054 @@ -15,6 +15,45 @@
9055 .endm
9056 #endif
9057
9058 +#ifdef KERNEXEC_PLUGIN
9059 + .macro pax_force_retaddr_bts rip=0
9060 + btsq $63,\rip(%rsp)
9061 + .endm
9062 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9063 + .macro pax_force_retaddr rip=0, reload=0
9064 + btsq $63,\rip(%rsp)
9065 + .endm
9066 + .macro pax_force_fptr ptr
9067 + btsq $63,\ptr
9068 + .endm
9069 + .macro pax_set_fptr_mask
9070 + .endm
9071 +#endif
9072 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9073 + .macro pax_force_retaddr rip=0, reload=0
9074 + .if \reload
9075 + pax_set_fptr_mask
9076 + .endif
9077 + orq %r10,\rip(%rsp)
9078 + .endm
9079 + .macro pax_force_fptr ptr
9080 + orq %r10,\ptr
9081 + .endm
9082 + .macro pax_set_fptr_mask
9083 + movabs $0x8000000000000000,%r10
9084 + .endm
9085 +#endif
9086 +#else
9087 + .macro pax_force_retaddr rip=0, reload=0
9088 + .endm
9089 + .macro pax_force_fptr ptr
9090 + .endm
9091 + .macro pax_force_retaddr_bts rip=0
9092 + .endm
9093 + .macro pax_set_fptr_mask
9094 + .endm
9095 +#endif
9096 +
9097 .macro altinstruction_entry orig alt feature orig_len alt_len
9098 .long \orig - .
9099 .long \alt - .
9100 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9101 index 7078068..f58bcda 100644
9102 --- a/arch/x86/include/asm/alternative.h
9103 +++ b/arch/x86/include/asm/alternative.h
9104 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9105 ".section .discard,\"aw\",@progbits\n" \
9106 DISCARD_ENTRY(1) \
9107 ".previous\n" \
9108 - ".section .altinstr_replacement, \"ax\"\n" \
9109 + ".section .altinstr_replacement, \"a\"\n" \
9110 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9111 ".previous"
9112
9113 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9114 DISCARD_ENTRY(1) \
9115 DISCARD_ENTRY(2) \
9116 ".previous\n" \
9117 - ".section .altinstr_replacement, \"ax\"\n" \
9118 + ".section .altinstr_replacement, \"a\"\n" \
9119 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9120 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9121 ".previous"
9122 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9123 index f342612..b3fe911 100644
9124 --- a/arch/x86/include/asm/apic.h
9125 +++ b/arch/x86/include/asm/apic.h
9126 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9127
9128 #ifdef CONFIG_X86_LOCAL_APIC
9129
9130 -extern unsigned int apic_verbosity;
9131 +extern int apic_verbosity;
9132 extern int local_apic_timer_c2_ok;
9133
9134 extern int disable_apic;
9135 @@ -391,7 +391,7 @@ struct apic {
9136 */
9137 int (*x86_32_numa_cpu_node)(int cpu);
9138 #endif
9139 -};
9140 +} __do_const;
9141
9142 /*
9143 * Pointer to the local APIC driver in use on this system (there's
9144 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9145 index 20370c6..a2eb9b0 100644
9146 --- a/arch/x86/include/asm/apm.h
9147 +++ b/arch/x86/include/asm/apm.h
9148 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9149 __asm__ __volatile__(APM_DO_ZERO_SEGS
9150 "pushl %%edi\n\t"
9151 "pushl %%ebp\n\t"
9152 - "lcall *%%cs:apm_bios_entry\n\t"
9153 + "lcall *%%ss:apm_bios_entry\n\t"
9154 "setc %%al\n\t"
9155 "popl %%ebp\n\t"
9156 "popl %%edi\n\t"
9157 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9158 __asm__ __volatile__(APM_DO_ZERO_SEGS
9159 "pushl %%edi\n\t"
9160 "pushl %%ebp\n\t"
9161 - "lcall *%%cs:apm_bios_entry\n\t"
9162 + "lcall *%%ss:apm_bios_entry\n\t"
9163 "setc %%bl\n\t"
9164 "popl %%ebp\n\t"
9165 "popl %%edi\n\t"
9166 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9167 index 58cb6d4..a4b806c 100644
9168 --- a/arch/x86/include/asm/atomic.h
9169 +++ b/arch/x86/include/asm/atomic.h
9170 @@ -22,7 +22,18 @@
9171 */
9172 static inline int atomic_read(const atomic_t *v)
9173 {
9174 - return (*(volatile int *)&(v)->counter);
9175 + return (*(volatile const int *)&(v)->counter);
9176 +}
9177 +
9178 +/**
9179 + * atomic_read_unchecked - read atomic variable
9180 + * @v: pointer of type atomic_unchecked_t
9181 + *
9182 + * Atomically reads the value of @v.
9183 + */
9184 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9185 +{
9186 + return (*(volatile const int *)&(v)->counter);
9187 }
9188
9189 /**
9190 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9191 }
9192
9193 /**
9194 + * atomic_set_unchecked - set atomic variable
9195 + * @v: pointer of type atomic_unchecked_t
9196 + * @i: required value
9197 + *
9198 + * Atomically sets the value of @v to @i.
9199 + */
9200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9201 +{
9202 + v->counter = i;
9203 +}
9204 +
9205 +/**
9206 * atomic_add - add integer to atomic variable
9207 * @i: integer value to add
9208 * @v: pointer of type atomic_t
9209 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9210 */
9211 static inline void atomic_add(int i, atomic_t *v)
9212 {
9213 - asm volatile(LOCK_PREFIX "addl %1,%0"
9214 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9215 +
9216 +#ifdef CONFIG_PAX_REFCOUNT
9217 + "jno 0f\n"
9218 + LOCK_PREFIX "subl %1,%0\n"
9219 + "int $4\n0:\n"
9220 + _ASM_EXTABLE(0b, 0b)
9221 +#endif
9222 +
9223 + : "+m" (v->counter)
9224 + : "ir" (i));
9225 +}
9226 +
9227 +/**
9228 + * atomic_add_unchecked - add integer to atomic variable
9229 + * @i: integer value to add
9230 + * @v: pointer of type atomic_unchecked_t
9231 + *
9232 + * Atomically adds @i to @v.
9233 + */
9234 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9235 +{
9236 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9237 : "+m" (v->counter)
9238 : "ir" (i));
9239 }
9240 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9241 */
9242 static inline void atomic_sub(int i, atomic_t *v)
9243 {
9244 - asm volatile(LOCK_PREFIX "subl %1,%0"
9245 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9246 +
9247 +#ifdef CONFIG_PAX_REFCOUNT
9248 + "jno 0f\n"
9249 + LOCK_PREFIX "addl %1,%0\n"
9250 + "int $4\n0:\n"
9251 + _ASM_EXTABLE(0b, 0b)
9252 +#endif
9253 +
9254 + : "+m" (v->counter)
9255 + : "ir" (i));
9256 +}
9257 +
9258 +/**
9259 + * atomic_sub_unchecked - subtract integer from atomic variable
9260 + * @i: integer value to subtract
9261 + * @v: pointer of type atomic_unchecked_t
9262 + *
9263 + * Atomically subtracts @i from @v.
9264 + */
9265 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9266 +{
9267 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9268 : "+m" (v->counter)
9269 : "ir" (i));
9270 }
9271 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9272 {
9273 unsigned char c;
9274
9275 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9276 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9277 +
9278 +#ifdef CONFIG_PAX_REFCOUNT
9279 + "jno 0f\n"
9280 + LOCK_PREFIX "addl %2,%0\n"
9281 + "int $4\n0:\n"
9282 + _ASM_EXTABLE(0b, 0b)
9283 +#endif
9284 +
9285 + "sete %1\n"
9286 : "+m" (v->counter), "=qm" (c)
9287 : "ir" (i) : "memory");
9288 return c;
9289 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9290 */
9291 static inline void atomic_inc(atomic_t *v)
9292 {
9293 - asm volatile(LOCK_PREFIX "incl %0"
9294 + asm volatile(LOCK_PREFIX "incl %0\n"
9295 +
9296 +#ifdef CONFIG_PAX_REFCOUNT
9297 + "jno 0f\n"
9298 + LOCK_PREFIX "decl %0\n"
9299 + "int $4\n0:\n"
9300 + _ASM_EXTABLE(0b, 0b)
9301 +#endif
9302 +
9303 + : "+m" (v->counter));
9304 +}
9305 +
9306 +/**
9307 + * atomic_inc_unchecked - increment atomic variable
9308 + * @v: pointer of type atomic_unchecked_t
9309 + *
9310 + * Atomically increments @v by 1.
9311 + */
9312 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9313 +{
9314 + asm volatile(LOCK_PREFIX "incl %0\n"
9315 : "+m" (v->counter));
9316 }
9317
9318 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9319 */
9320 static inline void atomic_dec(atomic_t *v)
9321 {
9322 - asm volatile(LOCK_PREFIX "decl %0"
9323 + asm volatile(LOCK_PREFIX "decl %0\n"
9324 +
9325 +#ifdef CONFIG_PAX_REFCOUNT
9326 + "jno 0f\n"
9327 + LOCK_PREFIX "incl %0\n"
9328 + "int $4\n0:\n"
9329 + _ASM_EXTABLE(0b, 0b)
9330 +#endif
9331 +
9332 + : "+m" (v->counter));
9333 +}
9334 +
9335 +/**
9336 + * atomic_dec_unchecked - decrement atomic variable
9337 + * @v: pointer of type atomic_unchecked_t
9338 + *
9339 + * Atomically decrements @v by 1.
9340 + */
9341 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9342 +{
9343 + asm volatile(LOCK_PREFIX "decl %0\n"
9344 : "+m" (v->counter));
9345 }
9346
9347 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9348 {
9349 unsigned char c;
9350
9351 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9352 + asm volatile(LOCK_PREFIX "decl %0\n"
9353 +
9354 +#ifdef CONFIG_PAX_REFCOUNT
9355 + "jno 0f\n"
9356 + LOCK_PREFIX "incl %0\n"
9357 + "int $4\n0:\n"
9358 + _ASM_EXTABLE(0b, 0b)
9359 +#endif
9360 +
9361 + "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9370 + asm volatile(LOCK_PREFIX "incl %0\n"
9371 +
9372 +#ifdef CONFIG_PAX_REFCOUNT
9373 + "jno 0f\n"
9374 + LOCK_PREFIX "decl %0\n"
9375 + "int $4\n0:\n"
9376 + _ASM_EXTABLE(0b, 0b)
9377 +#endif
9378 +
9379 + "sete %1\n"
9380 + : "+m" (v->counter), "=qm" (c)
9381 + : : "memory");
9382 + return c != 0;
9383 +}
9384 +
9385 +/**
9386 + * atomic_inc_and_test_unchecked - increment and test
9387 + * @v: pointer of type atomic_unchecked_t
9388 + *
9389 + * Atomically increments @v by 1
9390 + * and returns true if the result is zero, or false for all
9391 + * other cases.
9392 + */
9393 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9394 +{
9395 + unsigned char c;
9396 +
9397 + asm volatile(LOCK_PREFIX "incl %0\n"
9398 + "sete %1\n"
9399 : "+m" (v->counter), "=qm" (c)
9400 : : "memory");
9401 return c != 0;
9402 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9403 {
9404 unsigned char c;
9405
9406 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9407 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9408 +
9409 +#ifdef CONFIG_PAX_REFCOUNT
9410 + "jno 0f\n"
9411 + LOCK_PREFIX "subl %2,%0\n"
9412 + "int $4\n0:\n"
9413 + _ASM_EXTABLE(0b, 0b)
9414 +#endif
9415 +
9416 + "sets %1\n"
9417 : "+m" (v->counter), "=qm" (c)
9418 : "ir" (i) : "memory");
9419 return c;
9420 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9421 goto no_xadd;
9422 #endif
9423 /* Modern 486+ processor */
9424 - return i + xadd(&v->counter, i);
9425 + return i + xadd_check_overflow(&v->counter, i);
9426
9427 #ifdef CONFIG_M386
9428 no_xadd: /* Legacy 386 processor */
9429 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9430 }
9431
9432 /**
9433 + * atomic_add_return_unchecked - add integer and return
9434 + * @i: integer value to add
9435 + * @v: pointer of type atomic_unchecked_t
9436 + *
9437 + * Atomically adds @i to @v and returns @i + @v
9438 + */
9439 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9440 +{
9441 +#ifdef CONFIG_M386
9442 + int __i;
9443 + unsigned long flags;
9444 + if (unlikely(boot_cpu_data.x86 <= 3))
9445 + goto no_xadd;
9446 +#endif
9447 + /* Modern 486+ processor */
9448 + return i + xadd(&v->counter, i);
9449 +
9450 +#ifdef CONFIG_M386
9451 +no_xadd: /* Legacy 386 processor */
9452 + raw_local_irq_save(flags);
9453 + __i = atomic_read_unchecked(v);
9454 + atomic_set_unchecked(v, i + __i);
9455 + raw_local_irq_restore(flags);
9456 + return i + __i;
9457 +#endif
9458 +}
9459 +
9460 +/**
9461 * atomic_sub_return - subtract integer and return
9462 * @v: pointer of type atomic_t
9463 * @i: integer value to subtract
9464 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9465 }
9466
9467 #define atomic_inc_return(v) (atomic_add_return(1, v))
9468 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9469 +{
9470 + return atomic_add_return_unchecked(1, v);
9471 +}
9472 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9473
9474 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9475 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9476 return cmpxchg(&v->counter, old, new);
9477 }
9478
9479 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9480 +{
9481 + return cmpxchg(&v->counter, old, new);
9482 +}
9483 +
9484 static inline int atomic_xchg(atomic_t *v, int new)
9485 {
9486 return xchg(&v->counter, new);
9487 }
9488
9489 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9490 +{
9491 + return xchg(&v->counter, new);
9492 +}
9493 +
9494 /**
9495 * __atomic_add_unless - add unless the number is already a given value
9496 * @v: pointer of type atomic_t
9497 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9498 */
9499 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9500 {
9501 - int c, old;
9502 + int c, old, new;
9503 c = atomic_read(v);
9504 for (;;) {
9505 - if (unlikely(c == (u)))
9506 + if (unlikely(c == u))
9507 break;
9508 - old = atomic_cmpxchg((v), c, c + (a));
9509 +
9510 + asm volatile("addl %2,%0\n"
9511 +
9512 +#ifdef CONFIG_PAX_REFCOUNT
9513 + "jno 0f\n"
9514 + "subl %2,%0\n"
9515 + "int $4\n0:\n"
9516 + _ASM_EXTABLE(0b, 0b)
9517 +#endif
9518 +
9519 + : "=r" (new)
9520 + : "0" (c), "ir" (a));
9521 +
9522 + old = atomic_cmpxchg(v, c, new);
9523 if (likely(old == c))
9524 break;
9525 c = old;
9526 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9527 return c;
9528 }
9529
9530 +/**
9531 + * atomic_inc_not_zero_hint - increment if not null
9532 + * @v: pointer of type atomic_t
9533 + * @hint: probable value of the atomic before the increment
9534 + *
9535 + * This version of atomic_inc_not_zero() gives a hint of probable
9536 + * value of the atomic. This helps processor to not read the memory
9537 + * before doing the atomic read/modify/write cycle, lowering
9538 + * number of bus transactions on some arches.
9539 + *
9540 + * Returns: 0 if increment was not done, 1 otherwise.
9541 + */
9542 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9543 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9544 +{
9545 + int val, c = hint, new;
9546 +
9547 + /* sanity test, should be removed by compiler if hint is a constant */
9548 + if (!hint)
9549 + return __atomic_add_unless(v, 1, 0);
9550 +
9551 + do {
9552 + asm volatile("incl %0\n"
9553 +
9554 +#ifdef CONFIG_PAX_REFCOUNT
9555 + "jno 0f\n"
9556 + "decl %0\n"
9557 + "int $4\n0:\n"
9558 + _ASM_EXTABLE(0b, 0b)
9559 +#endif
9560 +
9561 + : "=r" (new)
9562 + : "0" (c));
9563 +
9564 + val = atomic_cmpxchg(v, c, new);
9565 + if (val == c)
9566 + return 1;
9567 + c = val;
9568 + } while (c);
9569 +
9570 + return 0;
9571 +}
9572
9573 /*
9574 * atomic_dec_if_positive - decrement by 1 if old value positive
9575 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9576 #endif
9577
9578 /* These are x86-specific, used by some header files */
9579 -#define atomic_clear_mask(mask, addr) \
9580 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9581 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9582 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "andl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (~(mask))
9587 + : "memory");
9588 +}
9589
9590 -#define atomic_set_mask(mask, addr) \
9591 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9592 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9593 - : "memory")
9594 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9595 +{
9596 + asm volatile(LOCK_PREFIX "andl %1,%0"
9597 + : "+m" (v->counter)
9598 + : "r" (~(mask))
9599 + : "memory");
9600 +}
9601 +
9602 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9603 +{
9604 + asm volatile(LOCK_PREFIX "orl %1,%0"
9605 + : "+m" (v->counter)
9606 + : "r" (mask)
9607 + : "memory");
9608 +}
9609 +
9610 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9611 +{
9612 + asm volatile(LOCK_PREFIX "orl %1,%0"
9613 + : "+m" (v->counter)
9614 + : "r" (mask)
9615 + : "memory");
9616 +}
9617
9618 /* Atomic operations are already serializing on x86 */
9619 #define smp_mb__before_atomic_dec() barrier()
9620 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9621 index b154de7..aadebd8 100644
9622 --- a/arch/x86/include/asm/atomic64_32.h
9623 +++ b/arch/x86/include/asm/atomic64_32.h
9624 @@ -12,6 +12,14 @@ typedef struct {
9625 u64 __aligned(8) counter;
9626 } atomic64_t;
9627
9628 +#ifdef CONFIG_PAX_REFCOUNT
9629 +typedef struct {
9630 + u64 __aligned(8) counter;
9631 +} atomic64_unchecked_t;
9632 +#else
9633 +typedef atomic64_t atomic64_unchecked_t;
9634 +#endif
9635 +
9636 #define ATOMIC64_INIT(val) { (val) }
9637
9638 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9639 @@ -37,21 +45,31 @@ typedef struct {
9640 ATOMIC64_DECL_ONE(sym##_386)
9641
9642 ATOMIC64_DECL_ONE(add_386);
9643 +ATOMIC64_DECL_ONE(add_unchecked_386);
9644 ATOMIC64_DECL_ONE(sub_386);
9645 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9646 ATOMIC64_DECL_ONE(inc_386);
9647 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9648 ATOMIC64_DECL_ONE(dec_386);
9649 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9650 #endif
9651
9652 #define alternative_atomic64(f, out, in...) \
9653 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9654
9655 ATOMIC64_DECL(read);
9656 +ATOMIC64_DECL(read_unchecked);
9657 ATOMIC64_DECL(set);
9658 +ATOMIC64_DECL(set_unchecked);
9659 ATOMIC64_DECL(xchg);
9660 ATOMIC64_DECL(add_return);
9661 +ATOMIC64_DECL(add_return_unchecked);
9662 ATOMIC64_DECL(sub_return);
9663 +ATOMIC64_DECL(sub_return_unchecked);
9664 ATOMIC64_DECL(inc_return);
9665 +ATOMIC64_DECL(inc_return_unchecked);
9666 ATOMIC64_DECL(dec_return);
9667 +ATOMIC64_DECL(dec_return_unchecked);
9668 ATOMIC64_DECL(dec_if_positive);
9669 ATOMIC64_DECL(inc_not_zero);
9670 ATOMIC64_DECL(add_unless);
9671 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9672 }
9673
9674 /**
9675 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9676 + * @p: pointer to type atomic64_unchecked_t
9677 + * @o: expected value
9678 + * @n: new value
9679 + *
9680 + * Atomically sets @v to @n if it was equal to @o and returns
9681 + * the old value.
9682 + */
9683 +
9684 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9685 +{
9686 + return cmpxchg64(&v->counter, o, n);
9687 +}
9688 +
9689 +/**
9690 * atomic64_xchg - xchg atomic64 variable
9691 * @v: pointer to type atomic64_t
9692 * @n: value to assign
9693 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9694 }
9695
9696 /**
9697 + * atomic64_set_unchecked - set atomic64 variable
9698 + * @v: pointer to type atomic64_unchecked_t
9699 + * @n: value to assign
9700 + *
9701 + * Atomically sets the value of @v to @n.
9702 + */
9703 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9704 +{
9705 + unsigned high = (unsigned)(i >> 32);
9706 + unsigned low = (unsigned)i;
9707 + alternative_atomic64(set, /* no output */,
9708 + "S" (v), "b" (low), "c" (high)
9709 + : "eax", "edx", "memory");
9710 +}
9711 +
9712 +/**
9713 * atomic64_read - read atomic64 variable
9714 * @v: pointer to type atomic64_t
9715 *
9716 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9717 }
9718
9719 /**
9720 + * atomic64_read_unchecked - read atomic64 variable
9721 + * @v: pointer to type atomic64_unchecked_t
9722 + *
9723 + * Atomically reads the value of @v and returns it.
9724 + */
9725 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9726 +{
9727 + long long r;
9728 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9729 + return r;
9730 + }
9731 +
9732 +/**
9733 * atomic64_add_return - add and return
9734 * @i: integer value to add
9735 * @v: pointer to type atomic64_t
9736 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9737 return i;
9738 }
9739
9740 +/**
9741 + * atomic64_add_return_unchecked - add and return
9742 + * @i: integer value to add
9743 + * @v: pointer to type atomic64_unchecked_t
9744 + *
9745 + * Atomically adds @i to @v and returns @i + *@v
9746 + */
9747 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9748 +{
9749 + alternative_atomic64(add_return_unchecked,
9750 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9751 + ASM_NO_INPUT_CLOBBER("memory"));
9752 + return i;
9753 +}
9754 +
9755 /*
9756 * Other variants with different arithmetic operators:
9757 */
9758 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9759 return a;
9760 }
9761
9762 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9763 +{
9764 + long long a;
9765 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9766 + "S" (v) : "memory", "ecx");
9767 + return a;
9768 +}
9769 +
9770 static inline long long atomic64_dec_return(atomic64_t *v)
9771 {
9772 long long a;
9773 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9774 }
9775
9776 /**
9777 + * atomic64_add_unchecked - add integer to atomic64 variable
9778 + * @i: integer value to add
9779 + * @v: pointer to type atomic64_unchecked_t
9780 + *
9781 + * Atomically adds @i to @v.
9782 + */
9783 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9784 +{
9785 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9786 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9787 + ASM_NO_INPUT_CLOBBER("memory"));
9788 + return i;
9789 +}
9790 +
9791 +/**
9792 * atomic64_sub - subtract the atomic64 variable
9793 * @i: integer value to subtract
9794 * @v: pointer to type atomic64_t
9795 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9796 index 0e1cbfc..5623683 100644
9797 --- a/arch/x86/include/asm/atomic64_64.h
9798 +++ b/arch/x86/include/asm/atomic64_64.h
9799 @@ -18,7 +18,19 @@
9800 */
9801 static inline long atomic64_read(const atomic64_t *v)
9802 {
9803 - return (*(volatile long *)&(v)->counter);
9804 + return (*(volatile const long *)&(v)->counter);
9805 +}
9806 +
9807 +/**
9808 + * atomic64_read_unchecked - read atomic64 variable
9809 + * @v: pointer of type atomic64_unchecked_t
9810 + *
9811 + * Atomically reads the value of @v.
9812 + * Doesn't imply a read memory barrier.
9813 + */
9814 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9815 +{
9816 + return (*(volatile const long *)&(v)->counter);
9817 }
9818
9819 /**
9820 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9821 }
9822
9823 /**
9824 + * atomic64_set_unchecked - set atomic64 variable
9825 + * @v: pointer to type atomic64_unchecked_t
9826 + * @i: required value
9827 + *
9828 + * Atomically sets the value of @v to @i.
9829 + */
9830 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9831 +{
9832 + v->counter = i;
9833 +}
9834 +
9835 +/**
9836 * atomic64_add - add integer to atomic64 variable
9837 * @i: integer value to add
9838 * @v: pointer to type atomic64_t
9839 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9840 */
9841 static inline void atomic64_add(long i, atomic64_t *v)
9842 {
9843 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9844 +
9845 +#ifdef CONFIG_PAX_REFCOUNT
9846 + "jno 0f\n"
9847 + LOCK_PREFIX "subq %1,%0\n"
9848 + "int $4\n0:\n"
9849 + _ASM_EXTABLE(0b, 0b)
9850 +#endif
9851 +
9852 + : "=m" (v->counter)
9853 + : "er" (i), "m" (v->counter));
9854 +}
9855 +
9856 +/**
9857 + * atomic64_add_unchecked - add integer to atomic64 variable
9858 + * @i: integer value to add
9859 + * @v: pointer to type atomic64_unchecked_t
9860 + *
9861 + * Atomically adds @i to @v.
9862 + */
9863 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9864 +{
9865 asm volatile(LOCK_PREFIX "addq %1,%0"
9866 : "=m" (v->counter)
9867 : "er" (i), "m" (v->counter));
9868 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9869 */
9870 static inline void atomic64_sub(long i, atomic64_t *v)
9871 {
9872 - asm volatile(LOCK_PREFIX "subq %1,%0"
9873 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9874 +
9875 +#ifdef CONFIG_PAX_REFCOUNT
9876 + "jno 0f\n"
9877 + LOCK_PREFIX "addq %1,%0\n"
9878 + "int $4\n0:\n"
9879 + _ASM_EXTABLE(0b, 0b)
9880 +#endif
9881 +
9882 + : "=m" (v->counter)
9883 + : "er" (i), "m" (v->counter));
9884 +}
9885 +
9886 +/**
9887 + * atomic64_sub_unchecked - subtract the atomic64 variable
9888 + * @i: integer value to subtract
9889 + * @v: pointer to type atomic64_unchecked_t
9890 + *
9891 + * Atomically subtracts @i from @v.
9892 + */
9893 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9894 +{
9895 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9896 : "=m" (v->counter)
9897 : "er" (i), "m" (v->counter));
9898 }
9899 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9900 {
9901 unsigned char c;
9902
9903 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9904 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9905 +
9906 +#ifdef CONFIG_PAX_REFCOUNT
9907 + "jno 0f\n"
9908 + LOCK_PREFIX "addq %2,%0\n"
9909 + "int $4\n0:\n"
9910 + _ASM_EXTABLE(0b, 0b)
9911 +#endif
9912 +
9913 + "sete %1\n"
9914 : "=m" (v->counter), "=qm" (c)
9915 : "er" (i), "m" (v->counter) : "memory");
9916 return c;
9917 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9918 */
9919 static inline void atomic64_inc(atomic64_t *v)
9920 {
9921 + asm volatile(LOCK_PREFIX "incq %0\n"
9922 +
9923 +#ifdef CONFIG_PAX_REFCOUNT
9924 + "jno 0f\n"
9925 + LOCK_PREFIX "decq %0\n"
9926 + "int $4\n0:\n"
9927 + _ASM_EXTABLE(0b, 0b)
9928 +#endif
9929 +
9930 + : "=m" (v->counter)
9931 + : "m" (v->counter));
9932 +}
9933 +
9934 +/**
9935 + * atomic64_inc_unchecked - increment atomic64 variable
9936 + * @v: pointer to type atomic64_unchecked_t
9937 + *
9938 + * Atomically increments @v by 1.
9939 + */
9940 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9941 +{
9942 asm volatile(LOCK_PREFIX "incq %0"
9943 : "=m" (v->counter)
9944 : "m" (v->counter));
9945 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9946 */
9947 static inline void atomic64_dec(atomic64_t *v)
9948 {
9949 - asm volatile(LOCK_PREFIX "decq %0"
9950 + asm volatile(LOCK_PREFIX "decq %0\n"
9951 +
9952 +#ifdef CONFIG_PAX_REFCOUNT
9953 + "jno 0f\n"
9954 + LOCK_PREFIX "incq %0\n"
9955 + "int $4\n0:\n"
9956 + _ASM_EXTABLE(0b, 0b)
9957 +#endif
9958 +
9959 + : "=m" (v->counter)
9960 + : "m" (v->counter));
9961 +}
9962 +
9963 +/**
9964 + * atomic64_dec_unchecked - decrement atomic64 variable
9965 + * @v: pointer to type atomic64_t
9966 + *
9967 + * Atomically decrements @v by 1.
9968 + */
9969 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9970 +{
9971 + asm volatile(LOCK_PREFIX "decq %0\n"
9972 : "=m" (v->counter)
9973 : "m" (v->counter));
9974 }
9975 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9976 {
9977 unsigned char c;
9978
9979 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9980 + asm volatile(LOCK_PREFIX "decq %0\n"
9981 +
9982 +#ifdef CONFIG_PAX_REFCOUNT
9983 + "jno 0f\n"
9984 + LOCK_PREFIX "incq %0\n"
9985 + "int $4\n0:\n"
9986 + _ASM_EXTABLE(0b, 0b)
9987 +#endif
9988 +
9989 + "sete %1\n"
9990 : "=m" (v->counter), "=qm" (c)
9991 : "m" (v->counter) : "memory");
9992 return c != 0;
9993 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9994 {
9995 unsigned char c;
9996
9997 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9998 + asm volatile(LOCK_PREFIX "incq %0\n"
9999 +
10000 +#ifdef CONFIG_PAX_REFCOUNT
10001 + "jno 0f\n"
10002 + LOCK_PREFIX "decq %0\n"
10003 + "int $4\n0:\n"
10004 + _ASM_EXTABLE(0b, 0b)
10005 +#endif
10006 +
10007 + "sete %1\n"
10008 : "=m" (v->counter), "=qm" (c)
10009 : "m" (v->counter) : "memory");
10010 return c != 0;
10011 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10012 {
10013 unsigned char c;
10014
10015 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10016 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10017 +
10018 +#ifdef CONFIG_PAX_REFCOUNT
10019 + "jno 0f\n"
10020 + LOCK_PREFIX "subq %2,%0\n"
10021 + "int $4\n0:\n"
10022 + _ASM_EXTABLE(0b, 0b)
10023 +#endif
10024 +
10025 + "sets %1\n"
10026 : "=m" (v->counter), "=qm" (c)
10027 : "er" (i), "m" (v->counter) : "memory");
10028 return c;
10029 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10030 */
10031 static inline long atomic64_add_return(long i, atomic64_t *v)
10032 {
10033 + return i + xadd_check_overflow(&v->counter, i);
10034 +}
10035 +
10036 +/**
10037 + * atomic64_add_return_unchecked - add and return
10038 + * @i: integer value to add
10039 + * @v: pointer to type atomic64_unchecked_t
10040 + *
10041 + * Atomically adds @i to @v and returns @i + @v
10042 + */
10043 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10044 +{
10045 return i + xadd(&v->counter, i);
10046 }
10047
10048 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10049 }
10050
10051 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10052 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10053 +{
10054 + return atomic64_add_return_unchecked(1, v);
10055 +}
10056 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10057
10058 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10059 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10060 return cmpxchg(&v->counter, old, new);
10061 }
10062
10063 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10064 +{
10065 + return cmpxchg(&v->counter, old, new);
10066 +}
10067 +
10068 static inline long atomic64_xchg(atomic64_t *v, long new)
10069 {
10070 return xchg(&v->counter, new);
10071 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10072 */
10073 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10074 {
10075 - long c, old;
10076 + long c, old, new;
10077 c = atomic64_read(v);
10078 for (;;) {
10079 - if (unlikely(c == (u)))
10080 + if (unlikely(c == u))
10081 break;
10082 - old = atomic64_cmpxchg((v), c, c + (a));
10083 +
10084 + asm volatile("add %2,%0\n"
10085 +
10086 +#ifdef CONFIG_PAX_REFCOUNT
10087 + "jno 0f\n"
10088 + "sub %2,%0\n"
10089 + "int $4\n0:\n"
10090 + _ASM_EXTABLE(0b, 0b)
10091 +#endif
10092 +
10093 + : "=r" (new)
10094 + : "0" (c), "ir" (a));
10095 +
10096 + old = atomic64_cmpxchg(v, c, new);
10097 if (likely(old == c))
10098 break;
10099 c = old;
10100 }
10101 - return c != (u);
10102 + return c != u;
10103 }
10104
10105 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10106 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10107 index 72f5009..2f8b9a9 100644
10108 --- a/arch/x86/include/asm/bitops.h
10109 +++ b/arch/x86/include/asm/bitops.h
10110 @@ -40,7 +40,7 @@
10111 * a mask operation on a byte.
10112 */
10113 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10114 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10115 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10116 #define CONST_MASK(nr) (1 << ((nr) & 7))
10117
10118 /**
10119 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10120 index b13fe63..0dab13a 100644
10121 --- a/arch/x86/include/asm/boot.h
10122 +++ b/arch/x86/include/asm/boot.h
10123 @@ -11,10 +11,15 @@
10124 #include <asm/pgtable_types.h>
10125
10126 /* Physical address where kernel should be loaded. */
10127 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10128 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10129 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10130 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10131
10132 +#ifndef __ASSEMBLY__
10133 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10134 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10135 +#endif
10136 +
10137 /* Minimum kernel alignment, as a power of two */
10138 #ifdef CONFIG_X86_64
10139 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10140 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10141 index 48f99f1..d78ebf9 100644
10142 --- a/arch/x86/include/asm/cache.h
10143 +++ b/arch/x86/include/asm/cache.h
10144 @@ -5,12 +5,13 @@
10145
10146 /* L1 cache line size */
10147 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10148 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10149 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10150
10151 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10152 +#define __read_only __attribute__((__section__(".data..read_only")))
10153
10154 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10155 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10156 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10157
10158 #ifdef CONFIG_X86_VSMP
10159 #ifdef CONFIG_SMP
10160 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10161 index 9863ee3..4a1f8e1 100644
10162 --- a/arch/x86/include/asm/cacheflush.h
10163 +++ b/arch/x86/include/asm/cacheflush.h
10164 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10165 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10166
10167 if (pg_flags == _PGMT_DEFAULT)
10168 - return -1;
10169 + return ~0UL;
10170 else if (pg_flags == _PGMT_WC)
10171 return _PAGE_CACHE_WC;
10172 else if (pg_flags == _PGMT_UC_MINUS)
10173 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10174 index 46fc474..b02b0f9 100644
10175 --- a/arch/x86/include/asm/checksum_32.h
10176 +++ b/arch/x86/include/asm/checksum_32.h
10177 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10178 int len, __wsum sum,
10179 int *src_err_ptr, int *dst_err_ptr);
10180
10181 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10182 + int len, __wsum sum,
10183 + int *src_err_ptr, int *dst_err_ptr);
10184 +
10185 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10186 + int len, __wsum sum,
10187 + int *src_err_ptr, int *dst_err_ptr);
10188 +
10189 /*
10190 * Note: when you get a NULL pointer exception here this means someone
10191 * passed in an incorrect kernel address to one of these functions.
10192 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10193 int *err_ptr)
10194 {
10195 might_sleep();
10196 - return csum_partial_copy_generic((__force void *)src, dst,
10197 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10198 len, sum, err_ptr, NULL);
10199 }
10200
10201 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10202 {
10203 might_sleep();
10204 if (access_ok(VERIFY_WRITE, dst, len))
10205 - return csum_partial_copy_generic(src, (__force void *)dst,
10206 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10207 len, sum, NULL, err_ptr);
10208
10209 if (len)
10210 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10211 index 99480e5..d81165b 100644
10212 --- a/arch/x86/include/asm/cmpxchg.h
10213 +++ b/arch/x86/include/asm/cmpxchg.h
10214 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10215 __compiletime_error("Bad argument size for cmpxchg");
10216 extern void __xadd_wrong_size(void)
10217 __compiletime_error("Bad argument size for xadd");
10218 +extern void __xadd_check_overflow_wrong_size(void)
10219 + __compiletime_error("Bad argument size for xadd_check_overflow");
10220 extern void __add_wrong_size(void)
10221 __compiletime_error("Bad argument size for add");
10222 +extern void __add_check_overflow_wrong_size(void)
10223 + __compiletime_error("Bad argument size for add_check_overflow");
10224
10225 /*
10226 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10227 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10228 __ret; \
10229 })
10230
10231 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10232 + ({ \
10233 + __typeof__ (*(ptr)) __ret = (arg); \
10234 + switch (sizeof(*(ptr))) { \
10235 + case __X86_CASE_L: \
10236 + asm volatile (lock #op "l %0, %1\n" \
10237 + "jno 0f\n" \
10238 + "mov %0,%1\n" \
10239 + "int $4\n0:\n" \
10240 + _ASM_EXTABLE(0b, 0b) \
10241 + : "+r" (__ret), "+m" (*(ptr)) \
10242 + : : "memory", "cc"); \
10243 + break; \
10244 + case __X86_CASE_Q: \
10245 + asm volatile (lock #op "q %q0, %1\n" \
10246 + "jno 0f\n" \
10247 + "mov %0,%1\n" \
10248 + "int $4\n0:\n" \
10249 + _ASM_EXTABLE(0b, 0b) \
10250 + : "+r" (__ret), "+m" (*(ptr)) \
10251 + : : "memory", "cc"); \
10252 + break; \
10253 + default: \
10254 + __ ## op ## _check_overflow_wrong_size(); \
10255 + } \
10256 + __ret; \
10257 + })
10258 +
10259 /*
10260 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10261 * Since this is generally used to protect other memory information, we
10262 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10263 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10264 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10265
10266 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10267 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10268 +
10269 #define __add(ptr, inc, lock) \
10270 ({ \
10271 __typeof__ (*(ptr)) __ret = (inc); \
10272 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10273 index 6b7ee5f..9d664b3 100644
10274 --- a/arch/x86/include/asm/cpufeature.h
10275 +++ b/arch/x86/include/asm/cpufeature.h
10276 @@ -202,13 +202,14 @@
10277 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10278 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10279 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10280 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10281 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10282 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10283 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10284 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10285 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10286 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10287 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10288 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10289
10290 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10291
10292 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10293 ".section .discard,\"aw\",@progbits\n"
10294 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10295 ".previous\n"
10296 - ".section .altinstr_replacement,\"ax\"\n"
10297 + ".section .altinstr_replacement,\"a\"\n"
10298 "3: movb $1,%0\n"
10299 "4:\n"
10300 ".previous\n"
10301 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10302 index 8bf1c06..f723dfd 100644
10303 --- a/arch/x86/include/asm/desc.h
10304 +++ b/arch/x86/include/asm/desc.h
10305 @@ -4,6 +4,7 @@
10306 #include <asm/desc_defs.h>
10307 #include <asm/ldt.h>
10308 #include <asm/mmu.h>
10309 +#include <asm/pgtable.h>
10310
10311 #include <linux/smp.h>
10312 #include <linux/percpu.h>
10313 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10314
10315 desc->type = (info->read_exec_only ^ 1) << 1;
10316 desc->type |= info->contents << 2;
10317 + desc->type |= info->seg_not_present ^ 1;
10318
10319 desc->s = 1;
10320 desc->dpl = 0x3;
10321 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10322 }
10323
10324 extern struct desc_ptr idt_descr;
10325 -extern gate_desc idt_table[];
10326 extern struct desc_ptr nmi_idt_descr;
10327 -extern gate_desc nmi_idt_table[];
10328 -
10329 -struct gdt_page {
10330 - struct desc_struct gdt[GDT_ENTRIES];
10331 -} __attribute__((aligned(PAGE_SIZE)));
10332 -
10333 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10334 +extern gate_desc idt_table[256];
10335 +extern gate_desc nmi_idt_table[256];
10336
10337 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10338 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10339 {
10340 - return per_cpu(gdt_page, cpu).gdt;
10341 + return cpu_gdt_table[cpu];
10342 }
10343
10344 #ifdef CONFIG_X86_64
10345 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10346 unsigned long base, unsigned dpl, unsigned flags,
10347 unsigned short seg)
10348 {
10349 - gate->a = (seg << 16) | (base & 0xffff);
10350 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10351 + gate->gate.offset_low = base;
10352 + gate->gate.seg = seg;
10353 + gate->gate.reserved = 0;
10354 + gate->gate.type = type;
10355 + gate->gate.s = 0;
10356 + gate->gate.dpl = dpl;
10357 + gate->gate.p = 1;
10358 + gate->gate.offset_high = base >> 16;
10359 }
10360
10361 #endif
10362 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10363
10364 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10365 {
10366 + pax_open_kernel();
10367 memcpy(&idt[entry], gate, sizeof(*gate));
10368 + pax_close_kernel();
10369 }
10370
10371 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10372 {
10373 + pax_open_kernel();
10374 memcpy(&ldt[entry], desc, 8);
10375 + pax_close_kernel();
10376 }
10377
10378 static inline void
10379 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10380 default: size = sizeof(*gdt); break;
10381 }
10382
10383 + pax_open_kernel();
10384 memcpy(&gdt[entry], desc, size);
10385 + pax_close_kernel();
10386 }
10387
10388 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10389 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10390
10391 static inline void native_load_tr_desc(void)
10392 {
10393 + pax_open_kernel();
10394 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10395 + pax_close_kernel();
10396 }
10397
10398 static inline void native_load_gdt(const struct desc_ptr *dtr)
10399 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10400 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10401 unsigned int i;
10402
10403 + pax_open_kernel();
10404 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10405 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10406 + pax_close_kernel();
10407 }
10408
10409 #define _LDT_empty(info) \
10410 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10411 }
10412
10413 #ifdef CONFIG_X86_64
10414 -static inline void set_nmi_gate(int gate, void *addr)
10415 +static inline void set_nmi_gate(int gate, const void *addr)
10416 {
10417 gate_desc s;
10418
10419 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10420 }
10421 #endif
10422
10423 -static inline void _set_gate(int gate, unsigned type, void *addr,
10424 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10425 unsigned dpl, unsigned ist, unsigned seg)
10426 {
10427 gate_desc s;
10428 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10429 * Pentium F0 0F bugfix can have resulted in the mapped
10430 * IDT being write-protected.
10431 */
10432 -static inline void set_intr_gate(unsigned int n, void *addr)
10433 +static inline void set_intr_gate(unsigned int n, const void *addr)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10437 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10438 /*
10439 * This routine sets up an interrupt gate at directory privilege level 3.
10440 */
10441 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10442 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10446 }
10447
10448 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10449 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10453 }
10454
10455 -static inline void set_trap_gate(unsigned int n, void *addr)
10456 +static inline void set_trap_gate(unsigned int n, const void *addr)
10457 {
10458 BUG_ON((unsigned)n > 0xFF);
10459 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10460 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10461 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10462 {
10463 BUG_ON((unsigned)n > 0xFF);
10464 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10465 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10466 }
10467
10468 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10469 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10470 {
10471 BUG_ON((unsigned)n > 0xFF);
10472 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10473 }
10474
10475 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10476 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10477 {
10478 BUG_ON((unsigned)n > 0xFF);
10479 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10480 }
10481
10482 +#ifdef CONFIG_X86_32
10483 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10484 +{
10485 + struct desc_struct d;
10486 +
10487 + if (likely(limit))
10488 + limit = (limit - 1UL) >> PAGE_SHIFT;
10489 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10490 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10491 +}
10492 +#endif
10493 +
10494 #endif /* _ASM_X86_DESC_H */
10495 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10496 index 278441f..b95a174 100644
10497 --- a/arch/x86/include/asm/desc_defs.h
10498 +++ b/arch/x86/include/asm/desc_defs.h
10499 @@ -31,6 +31,12 @@ struct desc_struct {
10500 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10501 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10502 };
10503 + struct {
10504 + u16 offset_low;
10505 + u16 seg;
10506 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10507 + unsigned offset_high: 16;
10508 + } gate;
10509 };
10510 } __attribute__((packed));
10511
10512 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10513 index 3778256..c5d4fce 100644
10514 --- a/arch/x86/include/asm/e820.h
10515 +++ b/arch/x86/include/asm/e820.h
10516 @@ -69,7 +69,7 @@ struct e820map {
10517 #define ISA_START_ADDRESS 0xa0000
10518 #define ISA_END_ADDRESS 0x100000
10519
10520 -#define BIOS_BEGIN 0x000a0000
10521 +#define BIOS_BEGIN 0x000c0000
10522 #define BIOS_END 0x00100000
10523
10524 #define BIOS_ROM_BASE 0xffe00000
10525 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10526 index 5939f44..f8845f6 100644
10527 --- a/arch/x86/include/asm/elf.h
10528 +++ b/arch/x86/include/asm/elf.h
10529 @@ -243,7 +243,25 @@ extern int force_personality32;
10530 the loader. We need to make sure that it is out of the way of the program
10531 that it will "exec", and that there is sufficient room for the brk. */
10532
10533 +#ifdef CONFIG_PAX_SEGMEXEC
10534 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10535 +#else
10536 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10537 +#endif
10538 +
10539 +#ifdef CONFIG_PAX_ASLR
10540 +#ifdef CONFIG_X86_32
10541 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10542 +
10543 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10544 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10545 +#else
10546 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10547 +
10548 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10549 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10550 +#endif
10551 +#endif
10552
10553 /* This yields a mask that user programs can use to figure out what
10554 instruction set this CPU supports. This could be done in user space,
10555 @@ -296,16 +314,12 @@ do { \
10556
10557 #define ARCH_DLINFO \
10558 do { \
10559 - if (vdso_enabled) \
10560 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10561 - (unsigned long)current->mm->context.vdso); \
10562 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10563 } while (0)
10564
10565 #define ARCH_DLINFO_X32 \
10566 do { \
10567 - if (vdso_enabled) \
10568 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10569 - (unsigned long)current->mm->context.vdso); \
10570 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10571 } while (0)
10572
10573 #define AT_SYSINFO 32
10574 @@ -320,7 +334,7 @@ else \
10575
10576 #endif /* !CONFIG_X86_32 */
10577
10578 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10579 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10580
10581 #define VDSO_ENTRY \
10582 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10583 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10584 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10585 #define compat_arch_setup_additional_pages syscall32_setup_pages
10586
10587 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10588 -#define arch_randomize_brk arch_randomize_brk
10589 -
10590 /*
10591 * True on X86_32 or when emulating IA32 on X86_64
10592 */
10593 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10594 index 75ce3f4..882e801 100644
10595 --- a/arch/x86/include/asm/emergency-restart.h
10596 +++ b/arch/x86/include/asm/emergency-restart.h
10597 @@ -13,6 +13,6 @@ enum reboot_type {
10598
10599 extern enum reboot_type reboot_type;
10600
10601 -extern void machine_emergency_restart(void);
10602 +extern void machine_emergency_restart(void) __noreturn;
10603
10604 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10605 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10606 index 75f4c6d..ee3eb8f 100644
10607 --- a/arch/x86/include/asm/fpu-internal.h
10608 +++ b/arch/x86/include/asm/fpu-internal.h
10609 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10610 {
10611 int err;
10612
10613 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10614 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10615 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10616 +#endif
10617 +
10618 /* See comment in fxsave() below. */
10619 #ifdef CONFIG_AS_FXSAVEQ
10620 asm volatile("1: fxrstorq %[fx]\n\t"
10621 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10622 {
10623 int err;
10624
10625 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10626 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10627 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10628 +#endif
10629 +
10630 /*
10631 * Clear the bytes not touched by the fxsave and reserved
10632 * for the SW usage.
10633 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10634 "emms\n\t" /* clear stack tags */
10635 "fildl %P[addr]", /* set F?P to defined value */
10636 X86_FEATURE_FXSAVE_LEAK,
10637 - [addr] "m" (tsk->thread.fpu.has_fpu));
10638 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10639
10640 return fpu_restore_checking(&tsk->thread.fpu);
10641 }
10642 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10643 index 71ecbcb..bac10b7 100644
10644 --- a/arch/x86/include/asm/futex.h
10645 +++ b/arch/x86/include/asm/futex.h
10646 @@ -11,16 +11,18 @@
10647 #include <asm/processor.h>
10648
10649 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10650 + typecheck(u32 __user *, uaddr); \
10651 asm volatile("1:\t" insn "\n" \
10652 "2:\t.section .fixup,\"ax\"\n" \
10653 "3:\tmov\t%3, %1\n" \
10654 "\tjmp\t2b\n" \
10655 "\t.previous\n" \
10656 _ASM_EXTABLE(1b, 3b) \
10657 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10658 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10659 : "i" (-EFAULT), "0" (oparg), "1" (0))
10660
10661 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10662 + typecheck(u32 __user *, uaddr); \
10663 asm volatile("1:\tmovl %2, %0\n" \
10664 "\tmovl\t%0, %3\n" \
10665 "\t" insn "\n" \
10666 @@ -33,7 +35,7 @@
10667 _ASM_EXTABLE(1b, 4b) \
10668 _ASM_EXTABLE(2b, 4b) \
10669 : "=&a" (oldval), "=&r" (ret), \
10670 - "+m" (*uaddr), "=&r" (tem) \
10671 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10672 : "r" (oparg), "i" (-EFAULT), "1" (0))
10673
10674 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10675 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10676
10677 switch (op) {
10678 case FUTEX_OP_SET:
10679 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10680 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10681 break;
10682 case FUTEX_OP_ADD:
10683 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10684 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10685 uaddr, oparg);
10686 break;
10687 case FUTEX_OP_OR:
10688 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10689 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10690 return -EFAULT;
10691
10692 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10693 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10694 "2:\t.section .fixup, \"ax\"\n"
10695 "3:\tmov %3, %0\n"
10696 "\tjmp 2b\n"
10697 "\t.previous\n"
10698 _ASM_EXTABLE(1b, 3b)
10699 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10700 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10701 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10702 : "memory"
10703 );
10704 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10705 index eb92a6e..b98b2f4 100644
10706 --- a/arch/x86/include/asm/hw_irq.h
10707 +++ b/arch/x86/include/asm/hw_irq.h
10708 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10709 extern void enable_IO_APIC(void);
10710
10711 /* Statistics */
10712 -extern atomic_t irq_err_count;
10713 -extern atomic_t irq_mis_count;
10714 +extern atomic_unchecked_t irq_err_count;
10715 +extern atomic_unchecked_t irq_mis_count;
10716
10717 /* EISA */
10718 extern void eisa_set_level_irq(unsigned int irq);
10719 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10720 index d8e8eef..99f81ae 100644
10721 --- a/arch/x86/include/asm/io.h
10722 +++ b/arch/x86/include/asm/io.h
10723 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10724
10725 #include <linux/vmalloc.h>
10726
10727 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10728 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10729 +{
10730 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10731 +}
10732 +
10733 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10734 +{
10735 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10736 +}
10737 +
10738 /*
10739 * Convert a virtual cached pointer to an uncached pointer
10740 */
10741 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10742 index bba3cf8..06bc8da 100644
10743 --- a/arch/x86/include/asm/irqflags.h
10744 +++ b/arch/x86/include/asm/irqflags.h
10745 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10746 sti; \
10747 sysexit
10748
10749 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10750 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10751 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10752 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10753 +
10754 #else
10755 #define INTERRUPT_RETURN iret
10756 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10757 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10758 index 5478825..839e88c 100644
10759 --- a/arch/x86/include/asm/kprobes.h
10760 +++ b/arch/x86/include/asm/kprobes.h
10761 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10762 #define RELATIVEJUMP_SIZE 5
10763 #define RELATIVECALL_OPCODE 0xe8
10764 #define RELATIVE_ADDR_SIZE 4
10765 -#define MAX_STACK_SIZE 64
10766 -#define MIN_STACK_SIZE(ADDR) \
10767 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10768 - THREAD_SIZE - (unsigned long)(ADDR))) \
10769 - ? (MAX_STACK_SIZE) \
10770 - : (((unsigned long)current_thread_info()) + \
10771 - THREAD_SIZE - (unsigned long)(ADDR)))
10772 +#define MAX_STACK_SIZE 64UL
10773 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10774
10775 #define flush_insn_slot(p) do { } while (0)
10776
10777 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10778 index 09155d6..d2e6df9 100644
10779 --- a/arch/x86/include/asm/kvm_host.h
10780 +++ b/arch/x86/include/asm/kvm_host.h
10781 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10782 int (*check_intercept)(struct kvm_vcpu *vcpu,
10783 struct x86_instruction_info *info,
10784 enum x86_intercept_stage stage);
10785 -};
10786 +} __do_const;
10787
10788 struct kvm_arch_async_pf {
10789 u32 token;
10790 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10791 index c8bed0d..e5721fa 100644
10792 --- a/arch/x86/include/asm/local.h
10793 +++ b/arch/x86/include/asm/local.h
10794 @@ -17,26 +17,58 @@ typedef struct {
10795
10796 static inline void local_inc(local_t *l)
10797 {
10798 - asm volatile(_ASM_INC "%0"
10799 + asm volatile(_ASM_INC "%0\n"
10800 +
10801 +#ifdef CONFIG_PAX_REFCOUNT
10802 + "jno 0f\n"
10803 + _ASM_DEC "%0\n"
10804 + "int $4\n0:\n"
10805 + _ASM_EXTABLE(0b, 0b)
10806 +#endif
10807 +
10808 : "+m" (l->a.counter));
10809 }
10810
10811 static inline void local_dec(local_t *l)
10812 {
10813 - asm volatile(_ASM_DEC "%0"
10814 + asm volatile(_ASM_DEC "%0\n"
10815 +
10816 +#ifdef CONFIG_PAX_REFCOUNT
10817 + "jno 0f\n"
10818 + _ASM_INC "%0\n"
10819 + "int $4\n0:\n"
10820 + _ASM_EXTABLE(0b, 0b)
10821 +#endif
10822 +
10823 : "+m" (l->a.counter));
10824 }
10825
10826 static inline void local_add(long i, local_t *l)
10827 {
10828 - asm volatile(_ASM_ADD "%1,%0"
10829 + asm volatile(_ASM_ADD "%1,%0\n"
10830 +
10831 +#ifdef CONFIG_PAX_REFCOUNT
10832 + "jno 0f\n"
10833 + _ASM_SUB "%1,%0\n"
10834 + "int $4\n0:\n"
10835 + _ASM_EXTABLE(0b, 0b)
10836 +#endif
10837 +
10838 : "+m" (l->a.counter)
10839 : "ir" (i));
10840 }
10841
10842 static inline void local_sub(long i, local_t *l)
10843 {
10844 - asm volatile(_ASM_SUB "%1,%0"
10845 + asm volatile(_ASM_SUB "%1,%0\n"
10846 +
10847 +#ifdef CONFIG_PAX_REFCOUNT
10848 + "jno 0f\n"
10849 + _ASM_ADD "%1,%0\n"
10850 + "int $4\n0:\n"
10851 + _ASM_EXTABLE(0b, 0b)
10852 +#endif
10853 +
10854 : "+m" (l->a.counter)
10855 : "ir" (i));
10856 }
10857 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10858 {
10859 unsigned char c;
10860
10861 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10862 + asm volatile(_ASM_SUB "%2,%0\n"
10863 +
10864 +#ifdef CONFIG_PAX_REFCOUNT
10865 + "jno 0f\n"
10866 + _ASM_ADD "%2,%0\n"
10867 + "int $4\n0:\n"
10868 + _ASM_EXTABLE(0b, 0b)
10869 +#endif
10870 +
10871 + "sete %1\n"
10872 : "+m" (l->a.counter), "=qm" (c)
10873 : "ir" (i) : "memory");
10874 return c;
10875 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10876 {
10877 unsigned char c;
10878
10879 - asm volatile(_ASM_DEC "%0; sete %1"
10880 + asm volatile(_ASM_DEC "%0\n"
10881 +
10882 +#ifdef CONFIG_PAX_REFCOUNT
10883 + "jno 0f\n"
10884 + _ASM_INC "%0\n"
10885 + "int $4\n0:\n"
10886 + _ASM_EXTABLE(0b, 0b)
10887 +#endif
10888 +
10889 + "sete %1\n"
10890 : "+m" (l->a.counter), "=qm" (c)
10891 : : "memory");
10892 return c != 0;
10893 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10894 {
10895 unsigned char c;
10896
10897 - asm volatile(_ASM_INC "%0; sete %1"
10898 + asm volatile(_ASM_INC "%0\n"
10899 +
10900 +#ifdef CONFIG_PAX_REFCOUNT
10901 + "jno 0f\n"
10902 + _ASM_DEC "%0\n"
10903 + "int $4\n0:\n"
10904 + _ASM_EXTABLE(0b, 0b)
10905 +#endif
10906 +
10907 + "sete %1\n"
10908 : "+m" (l->a.counter), "=qm" (c)
10909 : : "memory");
10910 return c != 0;
10911 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10912 {
10913 unsigned char c;
10914
10915 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10916 + asm volatile(_ASM_ADD "%2,%0\n"
10917 +
10918 +#ifdef CONFIG_PAX_REFCOUNT
10919 + "jno 0f\n"
10920 + _ASM_SUB "%2,%0\n"
10921 + "int $4\n0:\n"
10922 + _ASM_EXTABLE(0b, 0b)
10923 +#endif
10924 +
10925 + "sets %1\n"
10926 : "+m" (l->a.counter), "=qm" (c)
10927 : "ir" (i) : "memory");
10928 return c;
10929 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10930 #endif
10931 /* Modern 486+ processor */
10932 __i = i;
10933 - asm volatile(_ASM_XADD "%0, %1;"
10934 + asm volatile(_ASM_XADD "%0, %1\n"
10935 +
10936 +#ifdef CONFIG_PAX_REFCOUNT
10937 + "jno 0f\n"
10938 + _ASM_MOV "%0,%1\n"
10939 + "int $4\n0:\n"
10940 + _ASM_EXTABLE(0b, 0b)
10941 +#endif
10942 +
10943 : "+r" (i), "+m" (l->a.counter)
10944 : : "memory");
10945 return i + __i;
10946 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10947 index 593e51d..fa69c9a 100644
10948 --- a/arch/x86/include/asm/mman.h
10949 +++ b/arch/x86/include/asm/mman.h
10950 @@ -5,4 +5,14 @@
10951
10952 #include <asm-generic/mman.h>
10953
10954 +#ifdef __KERNEL__
10955 +#ifndef __ASSEMBLY__
10956 +#ifdef CONFIG_X86_32
10957 +#define arch_mmap_check i386_mmap_check
10958 +int i386_mmap_check(unsigned long addr, unsigned long len,
10959 + unsigned long flags);
10960 +#endif
10961 +#endif
10962 +#endif
10963 +
10964 #endif /* _ASM_X86_MMAN_H */
10965 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10966 index 5f55e69..e20bfb1 100644
10967 --- a/arch/x86/include/asm/mmu.h
10968 +++ b/arch/x86/include/asm/mmu.h
10969 @@ -9,7 +9,7 @@
10970 * we put the segment information here.
10971 */
10972 typedef struct {
10973 - void *ldt;
10974 + struct desc_struct *ldt;
10975 int size;
10976
10977 #ifdef CONFIG_X86_64
10978 @@ -18,7 +18,19 @@ typedef struct {
10979 #endif
10980
10981 struct mutex lock;
10982 - void *vdso;
10983 + unsigned long vdso;
10984 +
10985 +#ifdef CONFIG_X86_32
10986 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10987 + unsigned long user_cs_base;
10988 + unsigned long user_cs_limit;
10989 +
10990 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10991 + cpumask_t cpu_user_cs_mask;
10992 +#endif
10993 +
10994 +#endif
10995 +#endif
10996 } mm_context_t;
10997
10998 #ifdef CONFIG_SMP
10999 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11000 index cdbf367..adb37ac 100644
11001 --- a/arch/x86/include/asm/mmu_context.h
11002 +++ b/arch/x86/include/asm/mmu_context.h
11003 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11004
11005 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11006 {
11007 +
11008 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11009 + unsigned int i;
11010 + pgd_t *pgd;
11011 +
11012 + pax_open_kernel();
11013 + pgd = get_cpu_pgd(smp_processor_id());
11014 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11015 + set_pgd_batched(pgd+i, native_make_pgd(0));
11016 + pax_close_kernel();
11017 +#endif
11018 +
11019 #ifdef CONFIG_SMP
11020 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11021 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11022 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11023 struct task_struct *tsk)
11024 {
11025 unsigned cpu = smp_processor_id();
11026 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11027 + int tlbstate = TLBSTATE_OK;
11028 +#endif
11029
11030 if (likely(prev != next)) {
11031 #ifdef CONFIG_SMP
11032 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11033 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11034 +#endif
11035 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11036 this_cpu_write(cpu_tlbstate.active_mm, next);
11037 #endif
11038 cpumask_set_cpu(cpu, mm_cpumask(next));
11039
11040 /* Re-load page tables */
11041 +#ifdef CONFIG_PAX_PER_CPU_PGD
11042 + pax_open_kernel();
11043 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11044 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11045 + pax_close_kernel();
11046 + load_cr3(get_cpu_pgd(cpu));
11047 +#else
11048 load_cr3(next->pgd);
11049 +#endif
11050
11051 /* stop flush ipis for the previous mm */
11052 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11053 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11054 */
11055 if (unlikely(prev->context.ldt != next->context.ldt))
11056 load_LDT_nolock(&next->context);
11057 - }
11058 +
11059 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11060 + if (!(__supported_pte_mask & _PAGE_NX)) {
11061 + smp_mb__before_clear_bit();
11062 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11063 + smp_mb__after_clear_bit();
11064 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11065 + }
11066 +#endif
11067 +
11068 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11069 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11070 + prev->context.user_cs_limit != next->context.user_cs_limit))
11071 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11072 #ifdef CONFIG_SMP
11073 + else if (unlikely(tlbstate != TLBSTATE_OK))
11074 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11075 +#endif
11076 +#endif
11077 +
11078 + }
11079 else {
11080 +
11081 +#ifdef CONFIG_PAX_PER_CPU_PGD
11082 + pax_open_kernel();
11083 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11084 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11085 + pax_close_kernel();
11086 + load_cr3(get_cpu_pgd(cpu));
11087 +#endif
11088 +
11089 +#ifdef CONFIG_SMP
11090 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11091 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11092
11093 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11094 * tlb flush IPI delivery. We must reload CR3
11095 * to make sure to use no freed page tables.
11096 */
11097 +
11098 +#ifndef CONFIG_PAX_PER_CPU_PGD
11099 load_cr3(next->pgd);
11100 +#endif
11101 +
11102 load_LDT_nolock(&next->context);
11103 +
11104 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11105 + if (!(__supported_pte_mask & _PAGE_NX))
11106 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11107 +#endif
11108 +
11109 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11110 +#ifdef CONFIG_PAX_PAGEEXEC
11111 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11112 +#endif
11113 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11114 +#endif
11115 +
11116 }
11117 +#endif
11118 }
11119 -#endif
11120 }
11121
11122 #define activate_mm(prev, next) \
11123 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11124 index 9eae775..c914fea 100644
11125 --- a/arch/x86/include/asm/module.h
11126 +++ b/arch/x86/include/asm/module.h
11127 @@ -5,6 +5,7 @@
11128
11129 #ifdef CONFIG_X86_64
11130 /* X86_64 does not define MODULE_PROC_FAMILY */
11131 +#define MODULE_PROC_FAMILY ""
11132 #elif defined CONFIG_M386
11133 #define MODULE_PROC_FAMILY "386 "
11134 #elif defined CONFIG_M486
11135 @@ -59,8 +60,20 @@
11136 #error unknown processor family
11137 #endif
11138
11139 -#ifdef CONFIG_X86_32
11140 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11141 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11142 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11143 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11144 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11145 +#else
11146 +#define MODULE_PAX_KERNEXEC ""
11147 #endif
11148
11149 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11150 +#define MODULE_PAX_UDEREF "UDEREF "
11151 +#else
11152 +#define MODULE_PAX_UDEREF ""
11153 +#endif
11154 +
11155 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11156 +
11157 #endif /* _ASM_X86_MODULE_H */
11158 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11159 index 320f7bb..e89f8f8 100644
11160 --- a/arch/x86/include/asm/page_64_types.h
11161 +++ b/arch/x86/include/asm/page_64_types.h
11162 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11163
11164 /* duplicated to the one in bootmem.h */
11165 extern unsigned long max_pfn;
11166 -extern unsigned long phys_base;
11167 +extern const unsigned long phys_base;
11168
11169 extern unsigned long __phys_addr(unsigned long);
11170 #define __phys_reloc_hide(x) (x)
11171 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11172 index a0facf3..c017b15 100644
11173 --- a/arch/x86/include/asm/paravirt.h
11174 +++ b/arch/x86/include/asm/paravirt.h
11175 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11176 val);
11177 }
11178
11179 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11180 +{
11181 + pgdval_t val = native_pgd_val(pgd);
11182 +
11183 + if (sizeof(pgdval_t) > sizeof(long))
11184 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11185 + val, (u64)val >> 32);
11186 + else
11187 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11188 + val);
11189 +}
11190 +
11191 static inline void pgd_clear(pgd_t *pgdp)
11192 {
11193 set_pgd(pgdp, __pgd(0));
11194 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11195 pv_mmu_ops.set_fixmap(idx, phys, flags);
11196 }
11197
11198 +#ifdef CONFIG_PAX_KERNEXEC
11199 +static inline unsigned long pax_open_kernel(void)
11200 +{
11201 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11202 +}
11203 +
11204 +static inline unsigned long pax_close_kernel(void)
11205 +{
11206 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11207 +}
11208 +#else
11209 +static inline unsigned long pax_open_kernel(void) { return 0; }
11210 +static inline unsigned long pax_close_kernel(void) { return 0; }
11211 +#endif
11212 +
11213 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11214
11215 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11216 @@ -929,7 +956,7 @@ extern void default_banner(void);
11217
11218 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11219 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11220 -#define PARA_INDIRECT(addr) *%cs:addr
11221 +#define PARA_INDIRECT(addr) *%ss:addr
11222 #endif
11223
11224 #define INTERRUPT_RETURN \
11225 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11226 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11227 CLBR_NONE, \
11228 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11229 +
11230 +#define GET_CR0_INTO_RDI \
11231 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11232 + mov %rax,%rdi
11233 +
11234 +#define SET_RDI_INTO_CR0 \
11235 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11236 +
11237 +#define GET_CR3_INTO_RDI \
11238 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11239 + mov %rax,%rdi
11240 +
11241 +#define SET_RDI_INTO_CR3 \
11242 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11243 +
11244 #endif /* CONFIG_X86_32 */
11245
11246 #endif /* __ASSEMBLY__ */
11247 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11248 index 142236e..6a6b4a6 100644
11249 --- a/arch/x86/include/asm/paravirt_types.h
11250 +++ b/arch/x86/include/asm/paravirt_types.h
11251 @@ -84,20 +84,20 @@ struct pv_init_ops {
11252 */
11253 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11254 unsigned long addr, unsigned len);
11255 -};
11256 +} __no_const;
11257
11258
11259 struct pv_lazy_ops {
11260 /* Set deferred update mode, used for batching operations. */
11261 void (*enter)(void);
11262 void (*leave)(void);
11263 -};
11264 +} __no_const;
11265
11266 struct pv_time_ops {
11267 unsigned long long (*sched_clock)(void);
11268 unsigned long long (*steal_clock)(int cpu);
11269 unsigned long (*get_tsc_khz)(void);
11270 -};
11271 +} __no_const;
11272
11273 struct pv_cpu_ops {
11274 /* hooks for various privileged instructions */
11275 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11276
11277 void (*start_context_switch)(struct task_struct *prev);
11278 void (*end_context_switch)(struct task_struct *next);
11279 -};
11280 +} __no_const;
11281
11282 struct pv_irq_ops {
11283 /*
11284 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11285 unsigned long start_eip,
11286 unsigned long start_esp);
11287 #endif
11288 -};
11289 +} __no_const;
11290
11291 struct pv_mmu_ops {
11292 unsigned long (*read_cr2)(void);
11293 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11294 struct paravirt_callee_save make_pud;
11295
11296 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11297 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11298 #endif /* PAGETABLE_LEVELS == 4 */
11299 #endif /* PAGETABLE_LEVELS >= 3 */
11300
11301 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11302 an mfn. We can tell which is which from the index. */
11303 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11304 phys_addr_t phys, pgprot_t flags);
11305 +
11306 +#ifdef CONFIG_PAX_KERNEXEC
11307 + unsigned long (*pax_open_kernel)(void);
11308 + unsigned long (*pax_close_kernel)(void);
11309 +#endif
11310 +
11311 };
11312
11313 struct arch_spinlock;
11314 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11315 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11316 int (*spin_trylock)(struct arch_spinlock *lock);
11317 void (*spin_unlock)(struct arch_spinlock *lock);
11318 -};
11319 +} __no_const;
11320
11321 /* This contains all the paravirt structures: we get a convenient
11322 * number for each function using the offset which we use to indicate
11323 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11324 index b4389a4..7024269 100644
11325 --- a/arch/x86/include/asm/pgalloc.h
11326 +++ b/arch/x86/include/asm/pgalloc.h
11327 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11328 pmd_t *pmd, pte_t *pte)
11329 {
11330 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11331 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11332 +}
11333 +
11334 +static inline void pmd_populate_user(struct mm_struct *mm,
11335 + pmd_t *pmd, pte_t *pte)
11336 +{
11337 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11338 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11339 }
11340
11341 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11342
11343 #ifdef CONFIG_X86_PAE
11344 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11345 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11346 +{
11347 + pud_populate(mm, pudp, pmd);
11348 +}
11349 #else /* !CONFIG_X86_PAE */
11350 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11351 {
11352 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11353 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11354 }
11355 +
11356 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11357 +{
11358 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11359 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11360 +}
11361 #endif /* CONFIG_X86_PAE */
11362
11363 #if PAGETABLE_LEVELS > 3
11364 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11365 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11366 }
11367
11368 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11369 +{
11370 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11371 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11372 +}
11373 +
11374 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11375 {
11376 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11377 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11378 index f2b489c..4f7e2e5 100644
11379 --- a/arch/x86/include/asm/pgtable-2level.h
11380 +++ b/arch/x86/include/asm/pgtable-2level.h
11381 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11382
11383 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11384 {
11385 + pax_open_kernel();
11386 *pmdp = pmd;
11387 + pax_close_kernel();
11388 }
11389
11390 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11391 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11392 index 4cc9f2b..5fd9226 100644
11393 --- a/arch/x86/include/asm/pgtable-3level.h
11394 +++ b/arch/x86/include/asm/pgtable-3level.h
11395 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11396
11397 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11398 {
11399 + pax_open_kernel();
11400 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11401 + pax_close_kernel();
11402 }
11403
11404 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11405 {
11406 + pax_open_kernel();
11407 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11408 + pax_close_kernel();
11409 }
11410
11411 /*
11412 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11413 index c3520d7..cf742ef 100644
11414 --- a/arch/x86/include/asm/pgtable.h
11415 +++ b/arch/x86/include/asm/pgtable.h
11416 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11417
11418 #ifndef __PAGETABLE_PUD_FOLDED
11419 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11420 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11421 #define pgd_clear(pgd) native_pgd_clear(pgd)
11422 #endif
11423
11424 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11425
11426 #define arch_end_context_switch(prev) do {} while(0)
11427
11428 +#define pax_open_kernel() native_pax_open_kernel()
11429 +#define pax_close_kernel() native_pax_close_kernel()
11430 #endif /* CONFIG_PARAVIRT */
11431
11432 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11433 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11434 +
11435 +#ifdef CONFIG_PAX_KERNEXEC
11436 +static inline unsigned long native_pax_open_kernel(void)
11437 +{
11438 + unsigned long cr0;
11439 +
11440 + preempt_disable();
11441 + barrier();
11442 + cr0 = read_cr0() ^ X86_CR0_WP;
11443 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11444 + write_cr0(cr0);
11445 + return cr0 ^ X86_CR0_WP;
11446 +}
11447 +
11448 +static inline unsigned long native_pax_close_kernel(void)
11449 +{
11450 + unsigned long cr0;
11451 +
11452 + cr0 = read_cr0() ^ X86_CR0_WP;
11453 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11454 + write_cr0(cr0);
11455 + barrier();
11456 + preempt_enable_no_resched();
11457 + return cr0 ^ X86_CR0_WP;
11458 +}
11459 +#else
11460 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11461 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11462 +#endif
11463 +
11464 /*
11465 * The following only work if pte_present() is true.
11466 * Undefined behaviour if not..
11467 */
11468 +static inline int pte_user(pte_t pte)
11469 +{
11470 + return pte_val(pte) & _PAGE_USER;
11471 +}
11472 +
11473 static inline int pte_dirty(pte_t pte)
11474 {
11475 return pte_flags(pte) & _PAGE_DIRTY;
11476 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11477 return pte_clear_flags(pte, _PAGE_RW);
11478 }
11479
11480 +static inline pte_t pte_mkread(pte_t pte)
11481 +{
11482 + return __pte(pte_val(pte) | _PAGE_USER);
11483 +}
11484 +
11485 static inline pte_t pte_mkexec(pte_t pte)
11486 {
11487 - return pte_clear_flags(pte, _PAGE_NX);
11488 +#ifdef CONFIG_X86_PAE
11489 + if (__supported_pte_mask & _PAGE_NX)
11490 + return pte_clear_flags(pte, _PAGE_NX);
11491 + else
11492 +#endif
11493 + return pte_set_flags(pte, _PAGE_USER);
11494 +}
11495 +
11496 +static inline pte_t pte_exprotect(pte_t pte)
11497 +{
11498 +#ifdef CONFIG_X86_PAE
11499 + if (__supported_pte_mask & _PAGE_NX)
11500 + return pte_set_flags(pte, _PAGE_NX);
11501 + else
11502 +#endif
11503 + return pte_clear_flags(pte, _PAGE_USER);
11504 }
11505
11506 static inline pte_t pte_mkdirty(pte_t pte)
11507 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11508 #endif
11509
11510 #ifndef __ASSEMBLY__
11511 +
11512 +#ifdef CONFIG_PAX_PER_CPU_PGD
11513 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11514 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11515 +{
11516 + return cpu_pgd[cpu];
11517 +}
11518 +#endif
11519 +
11520 #include <linux/mm_types.h>
11521
11522 static inline int pte_none(pte_t pte)
11523 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11524
11525 static inline int pgd_bad(pgd_t pgd)
11526 {
11527 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11528 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11529 }
11530
11531 static inline int pgd_none(pgd_t pgd)
11532 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11533 * pgd_offset() returns a (pgd_t *)
11534 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11535 */
11536 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11537 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11538 +
11539 +#ifdef CONFIG_PAX_PER_CPU_PGD
11540 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11541 +#endif
11542 +
11543 /*
11544 * a shortcut which implies the use of the kernel's pgd, instead
11545 * of a process's
11546 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11547 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11548 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11549
11550 +#ifdef CONFIG_X86_32
11551 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11552 +#else
11553 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11554 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11555 +
11556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11557 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11558 +#else
11559 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11560 +#endif
11561 +
11562 +#endif
11563 +
11564 #ifndef __ASSEMBLY__
11565
11566 extern int direct_gbpages;
11567 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11568 * dst and src can be on the same page, but the range must not overlap,
11569 * and must not cross a page boundary.
11570 */
11571 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11572 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11573 {
11574 - memcpy(dst, src, count * sizeof(pgd_t));
11575 + pax_open_kernel();
11576 + while (count--)
11577 + *dst++ = *src++;
11578 + pax_close_kernel();
11579 }
11580
11581 +#ifdef CONFIG_PAX_PER_CPU_PGD
11582 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11583 +#endif
11584 +
11585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11586 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11587 +#else
11588 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11589 +#endif
11590
11591 #include <asm-generic/pgtable.h>
11592 #endif /* __ASSEMBLY__ */
11593 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11594 index 0c92113..34a77c6 100644
11595 --- a/arch/x86/include/asm/pgtable_32.h
11596 +++ b/arch/x86/include/asm/pgtable_32.h
11597 @@ -25,9 +25,6 @@
11598 struct mm_struct;
11599 struct vm_area_struct;
11600
11601 -extern pgd_t swapper_pg_dir[1024];
11602 -extern pgd_t initial_page_table[1024];
11603 -
11604 static inline void pgtable_cache_init(void) { }
11605 static inline void check_pgt_cache(void) { }
11606 void paging_init(void);
11607 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11608 # include <asm/pgtable-2level.h>
11609 #endif
11610
11611 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11612 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11613 +#ifdef CONFIG_X86_PAE
11614 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11615 +#endif
11616 +
11617 #if defined(CONFIG_HIGHPTE)
11618 #define pte_offset_map(dir, address) \
11619 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11620 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11621 /* Clear a kernel PTE and flush it from the TLB */
11622 #define kpte_clear_flush(ptep, vaddr) \
11623 do { \
11624 + pax_open_kernel(); \
11625 pte_clear(&init_mm, (vaddr), (ptep)); \
11626 + pax_close_kernel(); \
11627 __flush_tlb_one((vaddr)); \
11628 } while (0)
11629
11630 @@ -74,6 +79,9 @@ do { \
11631
11632 #endif /* !__ASSEMBLY__ */
11633
11634 +#define HAVE_ARCH_UNMAPPED_AREA
11635 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11636 +
11637 /*
11638 * kern_addr_valid() is (1) for FLATMEM and (0) for
11639 * SPARSEMEM and DISCONTIGMEM
11640 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11641 index ed5903b..c7fe163 100644
11642 --- a/arch/x86/include/asm/pgtable_32_types.h
11643 +++ b/arch/x86/include/asm/pgtable_32_types.h
11644 @@ -8,7 +8,7 @@
11645 */
11646 #ifdef CONFIG_X86_PAE
11647 # include <asm/pgtable-3level_types.h>
11648 -# define PMD_SIZE (1UL << PMD_SHIFT)
11649 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11650 # define PMD_MASK (~(PMD_SIZE - 1))
11651 #else
11652 # include <asm/pgtable-2level_types.h>
11653 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11654 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11655 #endif
11656
11657 +#ifdef CONFIG_PAX_KERNEXEC
11658 +#ifndef __ASSEMBLY__
11659 +extern unsigned char MODULES_EXEC_VADDR[];
11660 +extern unsigned char MODULES_EXEC_END[];
11661 +#endif
11662 +#include <asm/boot.h>
11663 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11664 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11665 +#else
11666 +#define ktla_ktva(addr) (addr)
11667 +#define ktva_ktla(addr) (addr)
11668 +#endif
11669 +
11670 #define MODULES_VADDR VMALLOC_START
11671 #define MODULES_END VMALLOC_END
11672 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11673 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11674 index 8251be0..4ea8b46 100644
11675 --- a/arch/x86/include/asm/pgtable_64.h
11676 +++ b/arch/x86/include/asm/pgtable_64.h
11677 @@ -16,10 +16,14 @@
11678
11679 extern pud_t level3_kernel_pgt[512];
11680 extern pud_t level3_ident_pgt[512];
11681 +extern pud_t level3_vmalloc_start_pgt[512];
11682 +extern pud_t level3_vmalloc_end_pgt[512];
11683 +extern pud_t level3_vmemmap_pgt[512];
11684 +extern pud_t level2_vmemmap_pgt[512];
11685 extern pmd_t level2_kernel_pgt[512];
11686 extern pmd_t level2_fixmap_pgt[512];
11687 -extern pmd_t level2_ident_pgt[512];
11688 -extern pgd_t init_level4_pgt[];
11689 +extern pmd_t level2_ident_pgt[512*2];
11690 +extern pgd_t init_level4_pgt[512];
11691
11692 #define swapper_pg_dir init_level4_pgt
11693
11694 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11695
11696 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11697 {
11698 + pax_open_kernel();
11699 *pmdp = pmd;
11700 + pax_close_kernel();
11701 }
11702
11703 static inline void native_pmd_clear(pmd_t *pmd)
11704 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11705
11706 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11707 {
11708 + pax_open_kernel();
11709 *pudp = pud;
11710 + pax_close_kernel();
11711 }
11712
11713 static inline void native_pud_clear(pud_t *pud)
11714 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11715
11716 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11717 {
11718 + pax_open_kernel();
11719 + *pgdp = pgd;
11720 + pax_close_kernel();
11721 +}
11722 +
11723 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11724 +{
11725 *pgdp = pgd;
11726 }
11727
11728 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11729 index 766ea16..5b96cb3 100644
11730 --- a/arch/x86/include/asm/pgtable_64_types.h
11731 +++ b/arch/x86/include/asm/pgtable_64_types.h
11732 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11733 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11734 #define MODULES_END _AC(0xffffffffff000000, UL)
11735 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11736 +#define MODULES_EXEC_VADDR MODULES_VADDR
11737 +#define MODULES_EXEC_END MODULES_END
11738 +
11739 +#define ktla_ktva(addr) (addr)
11740 +#define ktva_ktla(addr) (addr)
11741
11742 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11743 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11744 index 013286a..8b42f4f 100644
11745 --- a/arch/x86/include/asm/pgtable_types.h
11746 +++ b/arch/x86/include/asm/pgtable_types.h
11747 @@ -16,13 +16,12 @@
11748 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11749 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11750 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11751 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11752 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11753 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11754 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11755 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11756 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11757 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11758 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11759 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11760 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11761 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11762
11763 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11764 @@ -40,7 +39,6 @@
11765 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11766 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11767 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11768 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11769 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11770 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11771 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11772 @@ -57,8 +55,10 @@
11773
11774 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11775 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11776 -#else
11777 +#elif defined(CONFIG_KMEMCHECK)
11778 #define _PAGE_NX (_AT(pteval_t, 0))
11779 +#else
11780 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11781 #endif
11782
11783 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11784 @@ -96,6 +96,9 @@
11785 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11786 _PAGE_ACCESSED)
11787
11788 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11789 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11790 +
11791 #define __PAGE_KERNEL_EXEC \
11792 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11793 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11794 @@ -106,7 +109,7 @@
11795 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11796 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11797 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11798 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11799 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11800 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11801 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11802 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11803 @@ -168,8 +171,8 @@
11804 * bits are combined, this will alow user to access the high address mapped
11805 * VDSO in the presence of CONFIG_COMPAT_VDSO
11806 */
11807 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11808 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11809 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11810 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11811 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11812 #endif
11813
11814 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11815 {
11816 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11817 }
11818 +#endif
11819
11820 +#if PAGETABLE_LEVELS == 3
11821 +#include <asm-generic/pgtable-nopud.h>
11822 +#endif
11823 +
11824 +#if PAGETABLE_LEVELS == 2
11825 +#include <asm-generic/pgtable-nopmd.h>
11826 +#endif
11827 +
11828 +#ifndef __ASSEMBLY__
11829 #if PAGETABLE_LEVELS > 3
11830 typedef struct { pudval_t pud; } pud_t;
11831
11832 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11833 return pud.pud;
11834 }
11835 #else
11836 -#include <asm-generic/pgtable-nopud.h>
11837 -
11838 static inline pudval_t native_pud_val(pud_t pud)
11839 {
11840 return native_pgd_val(pud.pgd);
11841 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11842 return pmd.pmd;
11843 }
11844 #else
11845 -#include <asm-generic/pgtable-nopmd.h>
11846 -
11847 static inline pmdval_t native_pmd_val(pmd_t pmd)
11848 {
11849 return native_pgd_val(pmd.pud.pgd);
11850 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11851
11852 extern pteval_t __supported_pte_mask;
11853 extern void set_nx(void);
11854 -extern int nx_enabled;
11855
11856 #define pgprot_writecombine pgprot_writecombine
11857 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11858 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11859 index aea1d1d..680cf09 100644
11860 --- a/arch/x86/include/asm/processor-flags.h
11861 +++ b/arch/x86/include/asm/processor-flags.h
11862 @@ -65,6 +65,7 @@
11863 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11864 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11865 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11866 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11867
11868 /*
11869 * x86-64 Task Priority Register, CR8
11870 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11871 index d048cad..45e350f 100644
11872 --- a/arch/x86/include/asm/processor.h
11873 +++ b/arch/x86/include/asm/processor.h
11874 @@ -289,7 +289,7 @@ struct tss_struct {
11875
11876 } ____cacheline_aligned;
11877
11878 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11879 +extern struct tss_struct init_tss[NR_CPUS];
11880
11881 /*
11882 * Save the original ist values for checking stack pointers during debugging
11883 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11884 */
11885 #define TASK_SIZE PAGE_OFFSET
11886 #define TASK_SIZE_MAX TASK_SIZE
11887 +
11888 +#ifdef CONFIG_PAX_SEGMEXEC
11889 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11890 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11891 +#else
11892 #define STACK_TOP TASK_SIZE
11893 -#define STACK_TOP_MAX STACK_TOP
11894 +#endif
11895 +
11896 +#define STACK_TOP_MAX TASK_SIZE
11897
11898 #define INIT_THREAD { \
11899 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11900 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11901 .vm86_info = NULL, \
11902 .sysenter_cs = __KERNEL_CS, \
11903 .io_bitmap_ptr = NULL, \
11904 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11905 */
11906 #define INIT_TSS { \
11907 .x86_tss = { \
11908 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11909 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11910 .ss0 = __KERNEL_DS, \
11911 .ss1 = __KERNEL_CS, \
11912 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11913 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11914 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915
11916 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11917 -#define KSTK_TOP(info) \
11918 -({ \
11919 - unsigned long *__ptr = (unsigned long *)(info); \
11920 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11921 -})
11922 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11923
11924 /*
11925 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11926 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11927 #define task_pt_regs(task) \
11928 ({ \
11929 struct pt_regs *__regs__; \
11930 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11931 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11932 __regs__ - 1; \
11933 })
11934
11935 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11936 /*
11937 * User space process size. 47bits minus one guard page.
11938 */
11939 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11940 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11941
11942 /* This decides where the kernel will search for a free chunk of vm
11943 * space during mmap's.
11944 */
11945 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11946 - 0xc0000000 : 0xFFFFe000)
11947 + 0xc0000000 : 0xFFFFf000)
11948
11949 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11950 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11951 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11952 #define STACK_TOP_MAX TASK_SIZE_MAX
11953
11954 #define INIT_THREAD { \
11955 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11956 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11957 }
11958
11959 #define INIT_TSS { \
11960 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11961 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11962 }
11963
11964 /*
11965 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11966 */
11967 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11968
11969 +#ifdef CONFIG_PAX_SEGMEXEC
11970 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11971 +#endif
11972 +
11973 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11974
11975 /* Get/set a process' ability to use the timestamp counter instruction */
11976 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11977 #define cpu_has_amd_erratum(x) (false)
11978 #endif /* CONFIG_CPU_SUP_AMD */
11979
11980 -extern unsigned long arch_align_stack(unsigned long sp);
11981 +#define arch_align_stack(x) ((x) & ~0xfUL)
11982 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11983
11984 void default_idle(void);
11985 bool set_pm_idle_to_default(void);
11986
11987 -void stop_this_cpu(void *dummy);
11988 +void stop_this_cpu(void *dummy) __noreturn;
11989
11990 #endif /* _ASM_X86_PROCESSOR_H */
11991 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11992 index dcfde52..dbfea06 100644
11993 --- a/arch/x86/include/asm/ptrace.h
11994 +++ b/arch/x86/include/asm/ptrace.h
11995 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11996 }
11997
11998 /*
11999 - * user_mode_vm(regs) determines whether a register set came from user mode.
12000 + * user_mode(regs) determines whether a register set came from user mode.
12001 * This is true if V8086 mode was enabled OR if the register set was from
12002 * protected mode with RPL-3 CS value. This tricky test checks that with
12003 * one comparison. Many places in the kernel can bypass this full check
12004 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12005 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12006 + * be used.
12007 */
12008 -static inline int user_mode(struct pt_regs *regs)
12009 +static inline int user_mode_novm(struct pt_regs *regs)
12010 {
12011 #ifdef CONFIG_X86_32
12012 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12013 #else
12014 - return !!(regs->cs & 3);
12015 + return !!(regs->cs & SEGMENT_RPL_MASK);
12016 #endif
12017 }
12018
12019 -static inline int user_mode_vm(struct pt_regs *regs)
12020 +static inline int user_mode(struct pt_regs *regs)
12021 {
12022 #ifdef CONFIG_X86_32
12023 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12024 USER_RPL;
12025 #else
12026 - return user_mode(regs);
12027 + return user_mode_novm(regs);
12028 #endif
12029 }
12030
12031 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12032 #ifdef CONFIG_X86_64
12033 static inline bool user_64bit_mode(struct pt_regs *regs)
12034 {
12035 + unsigned long cs = regs->cs & 0xffff;
12036 #ifndef CONFIG_PARAVIRT
12037 /*
12038 * On non-paravirt systems, this is the only long mode CPL 3
12039 * selector. We do not allow long mode selectors in the LDT.
12040 */
12041 - return regs->cs == __USER_CS;
12042 + return cs == __USER_CS;
12043 #else
12044 /* Headers are too twisted for this to go in paravirt.h. */
12045 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12046 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12047 #endif
12048 }
12049 #endif
12050 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12051 index fe1ec5b..dc5c3fe 100644
12052 --- a/arch/x86/include/asm/realmode.h
12053 +++ b/arch/x86/include/asm/realmode.h
12054 @@ -22,16 +22,14 @@ struct real_mode_header {
12055 #endif
12056 /* APM/BIOS reboot */
12057 u32 machine_real_restart_asm;
12058 -#ifdef CONFIG_X86_64
12059 u32 machine_real_restart_seg;
12060 -#endif
12061 };
12062
12063 /* This must match data at trampoline_32/64.S */
12064 struct trampoline_header {
12065 #ifdef CONFIG_X86_32
12066 u32 start;
12067 - u16 gdt_pad;
12068 + u16 boot_cs;
12069 u16 gdt_limit;
12070 u32 gdt_base;
12071 #else
12072 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12073 index a82c4f1..ac45053 100644
12074 --- a/arch/x86/include/asm/reboot.h
12075 +++ b/arch/x86/include/asm/reboot.h
12076 @@ -6,13 +6,13 @@
12077 struct pt_regs;
12078
12079 struct machine_ops {
12080 - void (*restart)(char *cmd);
12081 - void (*halt)(void);
12082 - void (*power_off)(void);
12083 + void (* __noreturn restart)(char *cmd);
12084 + void (* __noreturn halt)(void);
12085 + void (* __noreturn power_off)(void);
12086 void (*shutdown)(void);
12087 void (*crash_shutdown)(struct pt_regs *);
12088 - void (*emergency_restart)(void);
12089 -};
12090 + void (* __noreturn emergency_restart)(void);
12091 +} __no_const;
12092
12093 extern struct machine_ops machine_ops;
12094
12095 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12096 index 2dbe4a7..ce1db00 100644
12097 --- a/arch/x86/include/asm/rwsem.h
12098 +++ b/arch/x86/include/asm/rwsem.h
12099 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12100 {
12101 asm volatile("# beginning down_read\n\t"
12102 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12103 +
12104 +#ifdef CONFIG_PAX_REFCOUNT
12105 + "jno 0f\n"
12106 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12107 + "int $4\n0:\n"
12108 + _ASM_EXTABLE(0b, 0b)
12109 +#endif
12110 +
12111 /* adds 0x00000001 */
12112 " jns 1f\n"
12113 " call call_rwsem_down_read_failed\n"
12114 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12115 "1:\n\t"
12116 " mov %1,%2\n\t"
12117 " add %3,%2\n\t"
12118 +
12119 +#ifdef CONFIG_PAX_REFCOUNT
12120 + "jno 0f\n"
12121 + "sub %3,%2\n"
12122 + "int $4\n0:\n"
12123 + _ASM_EXTABLE(0b, 0b)
12124 +#endif
12125 +
12126 " jle 2f\n\t"
12127 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12128 " jnz 1b\n\t"
12129 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12130 long tmp;
12131 asm volatile("# beginning down_write\n\t"
12132 LOCK_PREFIX " xadd %1,(%2)\n\t"
12133 +
12134 +#ifdef CONFIG_PAX_REFCOUNT
12135 + "jno 0f\n"
12136 + "mov %1,(%2)\n"
12137 + "int $4\n0:\n"
12138 + _ASM_EXTABLE(0b, 0b)
12139 +#endif
12140 +
12141 /* adds 0xffff0001, returns the old value */
12142 " test %1,%1\n\t"
12143 /* was the count 0 before? */
12144 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12145 long tmp;
12146 asm volatile("# beginning __up_read\n\t"
12147 LOCK_PREFIX " xadd %1,(%2)\n\t"
12148 +
12149 +#ifdef CONFIG_PAX_REFCOUNT
12150 + "jno 0f\n"
12151 + "mov %1,(%2)\n"
12152 + "int $4\n0:\n"
12153 + _ASM_EXTABLE(0b, 0b)
12154 +#endif
12155 +
12156 /* subtracts 1, returns the old value */
12157 " jns 1f\n\t"
12158 " call call_rwsem_wake\n" /* expects old value in %edx */
12159 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12160 long tmp;
12161 asm volatile("# beginning __up_write\n\t"
12162 LOCK_PREFIX " xadd %1,(%2)\n\t"
12163 +
12164 +#ifdef CONFIG_PAX_REFCOUNT
12165 + "jno 0f\n"
12166 + "mov %1,(%2)\n"
12167 + "int $4\n0:\n"
12168 + _ASM_EXTABLE(0b, 0b)
12169 +#endif
12170 +
12171 /* subtracts 0xffff0001, returns the old value */
12172 " jns 1f\n\t"
12173 " call call_rwsem_wake\n" /* expects old value in %edx */
12174 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12175 {
12176 asm volatile("# beginning __downgrade_write\n\t"
12177 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12178 +
12179 +#ifdef CONFIG_PAX_REFCOUNT
12180 + "jno 0f\n"
12181 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12182 + "int $4\n0:\n"
12183 + _ASM_EXTABLE(0b, 0b)
12184 +#endif
12185 +
12186 /*
12187 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12188 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12189 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12190 */
12191 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12192 {
12193 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12194 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12195 +
12196 +#ifdef CONFIG_PAX_REFCOUNT
12197 + "jno 0f\n"
12198 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12199 + "int $4\n0:\n"
12200 + _ASM_EXTABLE(0b, 0b)
12201 +#endif
12202 +
12203 : "+m" (sem->count)
12204 : "er" (delta));
12205 }
12206 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12207 */
12208 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12209 {
12210 - return delta + xadd(&sem->count, delta);
12211 + return delta + xadd_check_overflow(&sem->count, delta);
12212 }
12213
12214 #endif /* __KERNEL__ */
12215 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12216 index c48a950..c6d7468 100644
12217 --- a/arch/x86/include/asm/segment.h
12218 +++ b/arch/x86/include/asm/segment.h
12219 @@ -64,10 +64,15 @@
12220 * 26 - ESPFIX small SS
12221 * 27 - per-cpu [ offset to per-cpu data area ]
12222 * 28 - stack_canary-20 [ for stack protector ]
12223 - * 29 - unused
12224 - * 30 - unused
12225 + * 29 - PCI BIOS CS
12226 + * 30 - PCI BIOS DS
12227 * 31 - TSS for double fault handler
12228 */
12229 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12230 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12231 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12232 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12233 +
12234 #define GDT_ENTRY_TLS_MIN 6
12235 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12236
12237 @@ -79,6 +84,8 @@
12238
12239 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12240
12241 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12242 +
12243 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12244
12245 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12246 @@ -104,6 +111,12 @@
12247 #define __KERNEL_STACK_CANARY 0
12248 #endif
12249
12250 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12251 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12252 +
12253 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12254 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12255 +
12256 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12257
12258 /*
12259 @@ -141,7 +154,7 @@
12260 */
12261
12262 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12263 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12264 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12265
12266
12267 #else
12268 @@ -165,6 +178,8 @@
12269 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12270 #define __USER32_DS __USER_DS
12271
12272 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12273 +
12274 #define GDT_ENTRY_TSS 8 /* needs two entries */
12275 #define GDT_ENTRY_LDT 10 /* needs two entries */
12276 #define GDT_ENTRY_TLS_MIN 12
12277 @@ -185,6 +200,7 @@
12278 #endif
12279
12280 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12281 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12282 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12283 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12284 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12285 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12286 {
12287 unsigned long __limit;
12288 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12289 - return __limit + 1;
12290 + return __limit;
12291 }
12292
12293 #endif /* !__ASSEMBLY__ */
12294 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12295 index 4f19a15..9e14f27 100644
12296 --- a/arch/x86/include/asm/smp.h
12297 +++ b/arch/x86/include/asm/smp.h
12298 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12299 /* cpus sharing the last level cache: */
12300 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12301 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12302 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12303 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12304
12305 static inline struct cpumask *cpu_sibling_mask(int cpu)
12306 {
12307 @@ -79,7 +79,7 @@ struct smp_ops {
12308
12309 void (*send_call_func_ipi)(const struct cpumask *mask);
12310 void (*send_call_func_single_ipi)(int cpu);
12311 -};
12312 +} __no_const;
12313
12314 /* Globals due to paravirt */
12315 extern void set_cpu_sibling_map(int cpu);
12316 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12317 extern int safe_smp_processor_id(void);
12318
12319 #elif defined(CONFIG_X86_64_SMP)
12320 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12321 -
12322 -#define stack_smp_processor_id() \
12323 -({ \
12324 - struct thread_info *ti; \
12325 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12326 - ti->cpu; \
12327 -})
12328 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12329 +#define stack_smp_processor_id() raw_smp_processor_id()
12330 #define safe_smp_processor_id() smp_processor_id()
12331
12332 #endif
12333 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12334 index 33692ea..350a534 100644
12335 --- a/arch/x86/include/asm/spinlock.h
12336 +++ b/arch/x86/include/asm/spinlock.h
12337 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12338 static inline void arch_read_lock(arch_rwlock_t *rw)
12339 {
12340 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12341 +
12342 +#ifdef CONFIG_PAX_REFCOUNT
12343 + "jno 0f\n"
12344 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12345 + "int $4\n0:\n"
12346 + _ASM_EXTABLE(0b, 0b)
12347 +#endif
12348 +
12349 "jns 1f\n"
12350 "call __read_lock_failed\n\t"
12351 "1:\n"
12352 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12353 static inline void arch_write_lock(arch_rwlock_t *rw)
12354 {
12355 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12356 +
12357 +#ifdef CONFIG_PAX_REFCOUNT
12358 + "jno 0f\n"
12359 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12360 + "int $4\n0:\n"
12361 + _ASM_EXTABLE(0b, 0b)
12362 +#endif
12363 +
12364 "jz 1f\n"
12365 "call __write_lock_failed\n\t"
12366 "1:\n"
12367 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12368
12369 static inline void arch_read_unlock(arch_rwlock_t *rw)
12370 {
12371 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12372 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12373 +
12374 +#ifdef CONFIG_PAX_REFCOUNT
12375 + "jno 0f\n"
12376 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12377 + "int $4\n0:\n"
12378 + _ASM_EXTABLE(0b, 0b)
12379 +#endif
12380 +
12381 :"+m" (rw->lock) : : "memory");
12382 }
12383
12384 static inline void arch_write_unlock(arch_rwlock_t *rw)
12385 {
12386 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12387 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12388 +
12389 +#ifdef CONFIG_PAX_REFCOUNT
12390 + "jno 0f\n"
12391 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12392 + "int $4\n0:\n"
12393 + _ASM_EXTABLE(0b, 0b)
12394 +#endif
12395 +
12396 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12397 }
12398
12399 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12400 index 6a99859..03cb807 100644
12401 --- a/arch/x86/include/asm/stackprotector.h
12402 +++ b/arch/x86/include/asm/stackprotector.h
12403 @@ -47,7 +47,7 @@
12404 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12405 */
12406 #define GDT_STACK_CANARY_INIT \
12407 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12408 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12409
12410 /*
12411 * Initialize the stackprotector canary value.
12412 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12413
12414 static inline void load_stack_canary_segment(void)
12415 {
12416 -#ifdef CONFIG_X86_32
12417 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12418 asm volatile ("mov %0, %%gs" : : "r" (0));
12419 #endif
12420 }
12421 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12422 index 70bbe39..4ae2bd4 100644
12423 --- a/arch/x86/include/asm/stacktrace.h
12424 +++ b/arch/x86/include/asm/stacktrace.h
12425 @@ -11,28 +11,20 @@
12426
12427 extern int kstack_depth_to_print;
12428
12429 -struct thread_info;
12430 +struct task_struct;
12431 struct stacktrace_ops;
12432
12433 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12434 - unsigned long *stack,
12435 - unsigned long bp,
12436 - const struct stacktrace_ops *ops,
12437 - void *data,
12438 - unsigned long *end,
12439 - int *graph);
12440 +typedef unsigned long walk_stack_t(struct task_struct *task,
12441 + void *stack_start,
12442 + unsigned long *stack,
12443 + unsigned long bp,
12444 + const struct stacktrace_ops *ops,
12445 + void *data,
12446 + unsigned long *end,
12447 + int *graph);
12448
12449 -extern unsigned long
12450 -print_context_stack(struct thread_info *tinfo,
12451 - unsigned long *stack, unsigned long bp,
12452 - const struct stacktrace_ops *ops, void *data,
12453 - unsigned long *end, int *graph);
12454 -
12455 -extern unsigned long
12456 -print_context_stack_bp(struct thread_info *tinfo,
12457 - unsigned long *stack, unsigned long bp,
12458 - const struct stacktrace_ops *ops, void *data,
12459 - unsigned long *end, int *graph);
12460 +extern walk_stack_t print_context_stack;
12461 +extern walk_stack_t print_context_stack_bp;
12462
12463 /* Generic stack tracer with callbacks */
12464
12465 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12466 void (*address)(void *data, unsigned long address, int reliable);
12467 /* On negative return stop dumping */
12468 int (*stack)(void *data, char *name);
12469 - walk_stack_t walk_stack;
12470 + walk_stack_t *walk_stack;
12471 };
12472
12473 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12474 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12475 index 4ec45b3..a4f0a8a 100644
12476 --- a/arch/x86/include/asm/switch_to.h
12477 +++ b/arch/x86/include/asm/switch_to.h
12478 @@ -108,7 +108,7 @@ do { \
12479 "call __switch_to\n\t" \
12480 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12481 __switch_canary \
12482 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12483 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12484 "movq %%rax,%%rdi\n\t" \
12485 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12486 "jnz ret_from_fork\n\t" \
12487 @@ -119,7 +119,7 @@ do { \
12488 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12489 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12490 [_tif_fork] "i" (_TIF_FORK), \
12491 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12492 + [thread_info] "m" (current_tinfo), \
12493 [current_task] "m" (current_task) \
12494 __switch_canary_iparam \
12495 : "memory", "cc" __EXTRA_CLOBBER)
12496 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12497 index 3fda9db4..4ca1c61 100644
12498 --- a/arch/x86/include/asm/sys_ia32.h
12499 +++ b/arch/x86/include/asm/sys_ia32.h
12500 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12501 struct old_sigaction32 __user *);
12502 asmlinkage long sys32_alarm(unsigned int);
12503
12504 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12505 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12506 asmlinkage long sys32_sysfs(int, u32, u32);
12507
12508 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12509 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12510 index 89f794f..1422765 100644
12511 --- a/arch/x86/include/asm/thread_info.h
12512 +++ b/arch/x86/include/asm/thread_info.h
12513 @@ -10,6 +10,7 @@
12514 #include <linux/compiler.h>
12515 #include <asm/page.h>
12516 #include <asm/types.h>
12517 +#include <asm/percpu.h>
12518
12519 /*
12520 * low level task data that entry.S needs immediate access to
12521 @@ -24,7 +25,6 @@ struct exec_domain;
12522 #include <linux/atomic.h>
12523
12524 struct thread_info {
12525 - struct task_struct *task; /* main task structure */
12526 struct exec_domain *exec_domain; /* execution domain */
12527 __u32 flags; /* low level flags */
12528 __u32 status; /* thread synchronous flags */
12529 @@ -34,19 +34,13 @@ struct thread_info {
12530 mm_segment_t addr_limit;
12531 struct restart_block restart_block;
12532 void __user *sysenter_return;
12533 -#ifdef CONFIG_X86_32
12534 - unsigned long previous_esp; /* ESP of the previous stack in
12535 - case of nested (IRQ) stacks
12536 - */
12537 - __u8 supervisor_stack[0];
12538 -#endif
12539 + unsigned long lowest_stack;
12540 unsigned int sig_on_uaccess_error:1;
12541 unsigned int uaccess_err:1; /* uaccess failed */
12542 };
12543
12544 -#define INIT_THREAD_INFO(tsk) \
12545 +#define INIT_THREAD_INFO \
12546 { \
12547 - .task = &tsk, \
12548 .exec_domain = &default_exec_domain, \
12549 .flags = 0, \
12550 .cpu = 0, \
12551 @@ -57,7 +51,7 @@ struct thread_info {
12552 }, \
12553 }
12554
12555 -#define init_thread_info (init_thread_union.thread_info)
12556 +#define init_thread_info (init_thread_union.stack)
12557 #define init_stack (init_thread_union.stack)
12558
12559 #else /* !__ASSEMBLY__ */
12560 @@ -98,6 +92,7 @@ struct thread_info {
12561 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12562 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12563 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12564 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12565
12566 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12567 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12568 @@ -122,16 +117,18 @@ struct thread_info {
12569 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12570 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12571 #define _TIF_X32 (1 << TIF_X32)
12572 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12573
12574 /* work to do in syscall_trace_enter() */
12575 #define _TIF_WORK_SYSCALL_ENTRY \
12576 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12577 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12578 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12579 + _TIF_GRSEC_SETXID)
12580
12581 /* work to do in syscall_trace_leave() */
12582 #define _TIF_WORK_SYSCALL_EXIT \
12583 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12584 - _TIF_SYSCALL_TRACEPOINT)
12585 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12586
12587 /* work to do on interrupt/exception return */
12588 #define _TIF_WORK_MASK \
12589 @@ -141,7 +138,8 @@ struct thread_info {
12590
12591 /* work to do on any return to user space */
12592 #define _TIF_ALLWORK_MASK \
12593 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12594 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12595 + _TIF_GRSEC_SETXID)
12596
12597 /* Only used for 64 bit */
12598 #define _TIF_DO_NOTIFY_MASK \
12599 @@ -157,45 +155,40 @@ struct thread_info {
12600
12601 #define PREEMPT_ACTIVE 0x10000000
12602
12603 -#ifdef CONFIG_X86_32
12604 -
12605 -#define STACK_WARN (THREAD_SIZE/8)
12606 -/*
12607 - * macros/functions for gaining access to the thread information structure
12608 - *
12609 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12610 - */
12611 -#ifndef __ASSEMBLY__
12612 -
12613 -
12614 -/* how to get the current stack pointer from C */
12615 -register unsigned long current_stack_pointer asm("esp") __used;
12616 -
12617 -/* how to get the thread information struct from C */
12618 -static inline struct thread_info *current_thread_info(void)
12619 -{
12620 - return (struct thread_info *)
12621 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12622 -}
12623 -
12624 -#else /* !__ASSEMBLY__ */
12625 -
12626 +#ifdef __ASSEMBLY__
12627 /* how to get the thread information struct from ASM */
12628 #define GET_THREAD_INFO(reg) \
12629 - movl $-THREAD_SIZE, reg; \
12630 - andl %esp, reg
12631 + mov PER_CPU_VAR(current_tinfo), reg
12632
12633 /* use this one if reg already contains %esp */
12634 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12635 - andl $-THREAD_SIZE, reg
12636 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12637 +#else
12638 +/* how to get the thread information struct from C */
12639 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12640 +
12641 +static __always_inline struct thread_info *current_thread_info(void)
12642 +{
12643 + return this_cpu_read_stable(current_tinfo);
12644 +}
12645 +#endif
12646 +
12647 +#ifdef CONFIG_X86_32
12648 +
12649 +#define STACK_WARN (THREAD_SIZE/8)
12650 +/*
12651 + * macros/functions for gaining access to the thread information structure
12652 + *
12653 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12654 + */
12655 +#ifndef __ASSEMBLY__
12656 +
12657 +/* how to get the current stack pointer from C */
12658 +register unsigned long current_stack_pointer asm("esp") __used;
12659
12660 #endif
12661
12662 #else /* X86_32 */
12663
12664 -#include <asm/percpu.h>
12665 -#define KERNEL_STACK_OFFSET (5*8)
12666 -
12667 /*
12668 * macros/functions for gaining access to the thread information structure
12669 * preempt_count needs to be 1 initially, until the scheduler is functional.
12670 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12671 #ifndef __ASSEMBLY__
12672 DECLARE_PER_CPU(unsigned long, kernel_stack);
12673
12674 -static inline struct thread_info *current_thread_info(void)
12675 -{
12676 - struct thread_info *ti;
12677 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12678 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12679 - return ti;
12680 -}
12681 -
12682 -#else /* !__ASSEMBLY__ */
12683 -
12684 -/* how to get the thread information struct from ASM */
12685 -#define GET_THREAD_INFO(reg) \
12686 - movq PER_CPU_VAR(kernel_stack),reg ; \
12687 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12688 -
12689 -/*
12690 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12691 - * a certain register (to be used in assembler memory operands).
12692 - */
12693 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12694 -
12695 +/* how to get the current stack pointer from C */
12696 +register unsigned long current_stack_pointer asm("rsp") __used;
12697 #endif
12698
12699 #endif /* !X86_32 */
12700 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12701 extern void arch_task_cache_init(void);
12702 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12703 extern void arch_release_task_struct(struct task_struct *tsk);
12704 +
12705 +#define __HAVE_THREAD_FUNCTIONS
12706 +#define task_thread_info(task) (&(task)->tinfo)
12707 +#define task_stack_page(task) ((task)->stack)
12708 +#define setup_thread_stack(p, org) do {} while (0)
12709 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12710 +
12711 #endif
12712 #endif /* _ASM_X86_THREAD_INFO_H */
12713 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12714 index e1f3a17..1ab364d 100644
12715 --- a/arch/x86/include/asm/uaccess.h
12716 +++ b/arch/x86/include/asm/uaccess.h
12717 @@ -7,12 +7,15 @@
12718 #include <linux/compiler.h>
12719 #include <linux/thread_info.h>
12720 #include <linux/string.h>
12721 +#include <linux/sched.h>
12722 #include <asm/asm.h>
12723 #include <asm/page.h>
12724
12725 #define VERIFY_READ 0
12726 #define VERIFY_WRITE 1
12727
12728 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12729 +
12730 /*
12731 * The fs value determines whether argument validity checking should be
12732 * performed or not. If get_fs() == USER_DS, checking is performed, with
12733 @@ -28,7 +31,12 @@
12734
12735 #define get_ds() (KERNEL_DS)
12736 #define get_fs() (current_thread_info()->addr_limit)
12737 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12738 +void __set_fs(mm_segment_t x);
12739 +void set_fs(mm_segment_t x);
12740 +#else
12741 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12742 +#endif
12743
12744 #define segment_eq(a, b) ((a).seg == (b).seg)
12745
12746 @@ -76,8 +84,33 @@
12747 * checks that the pointer is in the user space range - after calling
12748 * this function, memory access functions may still return -EFAULT.
12749 */
12750 -#define access_ok(type, addr, size) \
12751 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12752 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12753 +#define access_ok(type, addr, size) \
12754 +({ \
12755 + long __size = size; \
12756 + unsigned long __addr = (unsigned long)addr; \
12757 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12758 + unsigned long __end_ao = __addr + __size - 1; \
12759 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12760 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12761 + while(__addr_ao <= __end_ao) { \
12762 + char __c_ao; \
12763 + __addr_ao += PAGE_SIZE; \
12764 + if (__size > PAGE_SIZE) \
12765 + cond_resched(); \
12766 + if (__get_user(__c_ao, (char __user *)__addr)) \
12767 + break; \
12768 + if (type != VERIFY_WRITE) { \
12769 + __addr = __addr_ao; \
12770 + continue; \
12771 + } \
12772 + if (__put_user(__c_ao, (char __user *)__addr)) \
12773 + break; \
12774 + __addr = __addr_ao; \
12775 + } \
12776 + } \
12777 + __ret_ao; \
12778 +})
12779
12780 /*
12781 * The exception table consists of pairs of addresses relative to the
12782 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12783 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12784 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12785
12786 -
12787 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12788 +#define __copyuser_seg "gs;"
12789 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12790 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12791 +#else
12792 +#define __copyuser_seg
12793 +#define __COPYUSER_SET_ES
12794 +#define __COPYUSER_RESTORE_ES
12795 +#endif
12796
12797 #ifdef CONFIG_X86_32
12798 #define __put_user_asm_u64(x, addr, err, errret) \
12799 - asm volatile("1: movl %%eax,0(%2)\n" \
12800 - "2: movl %%edx,4(%2)\n" \
12801 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12802 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12803 "3:\n" \
12804 ".section .fixup,\"ax\"\n" \
12805 "4: movl %3,%0\n" \
12806 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12807 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12808
12809 #define __put_user_asm_ex_u64(x, addr) \
12810 - asm volatile("1: movl %%eax,0(%1)\n" \
12811 - "2: movl %%edx,4(%1)\n" \
12812 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12813 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12814 "3:\n" \
12815 _ASM_EXTABLE_EX(1b, 2b) \
12816 _ASM_EXTABLE_EX(2b, 3b) \
12817 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12818 __typeof__(*(ptr)) __pu_val; \
12819 __chk_user_ptr(ptr); \
12820 might_fault(); \
12821 - __pu_val = x; \
12822 + __pu_val = (x); \
12823 switch (sizeof(*(ptr))) { \
12824 case 1: \
12825 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12826 @@ -379,7 +420,7 @@ do { \
12827 } while (0)
12828
12829 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12830 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12831 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12832 "2:\n" \
12833 ".section .fixup,\"ax\"\n" \
12834 "3: mov %3,%0\n" \
12835 @@ -387,7 +428,7 @@ do { \
12836 " jmp 2b\n" \
12837 ".previous\n" \
12838 _ASM_EXTABLE(1b, 3b) \
12839 - : "=r" (err), ltype(x) \
12840 + : "=r" (err), ltype (x) \
12841 : "m" (__m(addr)), "i" (errret), "0" (err))
12842
12843 #define __get_user_size_ex(x, ptr, size) \
12844 @@ -412,7 +453,7 @@ do { \
12845 } while (0)
12846
12847 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12848 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12849 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12850 "2:\n" \
12851 _ASM_EXTABLE_EX(1b, 2b) \
12852 : ltype(x) : "m" (__m(addr)))
12853 @@ -429,13 +470,24 @@ do { \
12854 int __gu_err; \
12855 unsigned long __gu_val; \
12856 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12857 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12858 + (x) = (__typeof__(*(ptr)))__gu_val; \
12859 __gu_err; \
12860 })
12861
12862 /* FIXME: this hack is definitely wrong -AK */
12863 struct __large_struct { unsigned long buf[100]; };
12864 -#define __m(x) (*(struct __large_struct __user *)(x))
12865 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12866 +#define ____m(x) \
12867 +({ \
12868 + unsigned long ____x = (unsigned long)(x); \
12869 + if (____x < PAX_USER_SHADOW_BASE) \
12870 + ____x += PAX_USER_SHADOW_BASE; \
12871 + (void __user *)____x; \
12872 +})
12873 +#else
12874 +#define ____m(x) (x)
12875 +#endif
12876 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12877
12878 /*
12879 * Tell gcc we read from memory instead of writing: this is because
12880 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12881 * aliasing issues.
12882 */
12883 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12884 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12885 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12886 "2:\n" \
12887 ".section .fixup,\"ax\"\n" \
12888 "3: mov %3,%0\n" \
12889 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12890 ".previous\n" \
12891 _ASM_EXTABLE(1b, 3b) \
12892 : "=r"(err) \
12893 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12894 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12895
12896 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12897 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12898 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12899 "2:\n" \
12900 _ASM_EXTABLE_EX(1b, 2b) \
12901 : : ltype(x), "m" (__m(addr)))
12902 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12903 * On error, the variable @x is set to zero.
12904 */
12905
12906 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12907 +#define __get_user(x, ptr) get_user((x), (ptr))
12908 +#else
12909 #define __get_user(x, ptr) \
12910 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12911 +#endif
12912
12913 /**
12914 * __put_user: - Write a simple value into user space, with less checking.
12915 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12916 * Returns zero on success, or -EFAULT on error.
12917 */
12918
12919 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12920 +#define __put_user(x, ptr) put_user((x), (ptr))
12921 +#else
12922 #define __put_user(x, ptr) \
12923 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12924 +#endif
12925
12926 #define __get_user_unaligned __get_user
12927 #define __put_user_unaligned __put_user
12928 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12929 #define get_user_ex(x, ptr) do { \
12930 unsigned long __gue_val; \
12931 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12932 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12933 + (x) = (__typeof__(*(ptr)))__gue_val; \
12934 } while (0)
12935
12936 #ifdef CONFIG_X86_WP_WORKS_OK
12937 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12938 index 576e39b..ccd0a39 100644
12939 --- a/arch/x86/include/asm/uaccess_32.h
12940 +++ b/arch/x86/include/asm/uaccess_32.h
12941 @@ -11,15 +11,15 @@
12942 #include <asm/page.h>
12943
12944 unsigned long __must_check __copy_to_user_ll
12945 - (void __user *to, const void *from, unsigned long n);
12946 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12947 unsigned long __must_check __copy_from_user_ll
12948 - (void *to, const void __user *from, unsigned long n);
12949 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12950 unsigned long __must_check __copy_from_user_ll_nozero
12951 - (void *to, const void __user *from, unsigned long n);
12952 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12953 unsigned long __must_check __copy_from_user_ll_nocache
12954 - (void *to, const void __user *from, unsigned long n);
12955 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12956 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12957 - (void *to, const void __user *from, unsigned long n);
12958 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12959
12960 /**
12961 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12962 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12963 static __always_inline unsigned long __must_check
12964 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12965 {
12966 + if ((long)n < 0)
12967 + return n;
12968 +
12969 if (__builtin_constant_p(n)) {
12970 unsigned long ret;
12971
12972 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12973 return ret;
12974 }
12975 }
12976 + if (!__builtin_constant_p(n))
12977 + check_object_size(from, n, true);
12978 return __copy_to_user_ll(to, from, n);
12979 }
12980
12981 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12982 __copy_to_user(void __user *to, const void *from, unsigned long n)
12983 {
12984 might_fault();
12985 +
12986 return __copy_to_user_inatomic(to, from, n);
12987 }
12988
12989 static __always_inline unsigned long
12990 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12991 {
12992 + if ((long)n < 0)
12993 + return n;
12994 +
12995 /* Avoid zeroing the tail if the copy fails..
12996 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12997 * but as the zeroing behaviour is only significant when n is not
12998 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12999 __copy_from_user(void *to, const void __user *from, unsigned long n)
13000 {
13001 might_fault();
13002 +
13003 + if ((long)n < 0)
13004 + return n;
13005 +
13006 if (__builtin_constant_p(n)) {
13007 unsigned long ret;
13008
13009 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13010 return ret;
13011 }
13012 }
13013 + if (!__builtin_constant_p(n))
13014 + check_object_size(to, n, false);
13015 return __copy_from_user_ll(to, from, n);
13016 }
13017
13018 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13019 const void __user *from, unsigned long n)
13020 {
13021 might_fault();
13022 +
13023 + if ((long)n < 0)
13024 + return n;
13025 +
13026 if (__builtin_constant_p(n)) {
13027 unsigned long ret;
13028
13029 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13030 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13031 unsigned long n)
13032 {
13033 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13034 + if ((long)n < 0)
13035 + return n;
13036 +
13037 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13038 }
13039
13040 -unsigned long __must_check copy_to_user(void __user *to,
13041 - const void *from, unsigned long n);
13042 -unsigned long __must_check _copy_from_user(void *to,
13043 - const void __user *from,
13044 - unsigned long n);
13045 -
13046 +extern void copy_to_user_overflow(void)
13047 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13048 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13049 +#else
13050 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13051 +#endif
13052 +;
13053
13054 extern void copy_from_user_overflow(void)
13055 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13056 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13057 #endif
13058 ;
13059
13060 -static inline unsigned long __must_check copy_from_user(void *to,
13061 - const void __user *from,
13062 - unsigned long n)
13063 +/**
13064 + * copy_to_user: - Copy a block of data into user space.
13065 + * @to: Destination address, in user space.
13066 + * @from: Source address, in kernel space.
13067 + * @n: Number of bytes to copy.
13068 + *
13069 + * Context: User context only. This function may sleep.
13070 + *
13071 + * Copy data from kernel space to user space.
13072 + *
13073 + * Returns number of bytes that could not be copied.
13074 + * On success, this will be zero.
13075 + */
13076 +static inline unsigned long __must_check
13077 +copy_to_user(void __user *to, const void *from, unsigned long n)
13078 {
13079 - int sz = __compiletime_object_size(to);
13080 + size_t sz = __compiletime_object_size(from);
13081
13082 - if (likely(sz == -1 || sz >= n))
13083 - n = _copy_from_user(to, from, n);
13084 - else
13085 + if (unlikely(sz != (size_t)-1 && sz < n))
13086 + copy_to_user_overflow();
13087 + else if (access_ok(VERIFY_WRITE, to, n))
13088 + n = __copy_to_user(to, from, n);
13089 + return n;
13090 +}
13091 +
13092 +/**
13093 + * copy_from_user: - Copy a block of data from user space.
13094 + * @to: Destination address, in kernel space.
13095 + * @from: Source address, in user space.
13096 + * @n: Number of bytes to copy.
13097 + *
13098 + * Context: User context only. This function may sleep.
13099 + *
13100 + * Copy data from user space to kernel space.
13101 + *
13102 + * Returns number of bytes that could not be copied.
13103 + * On success, this will be zero.
13104 + *
13105 + * If some data could not be copied, this function will pad the copied
13106 + * data to the requested size using zero bytes.
13107 + */
13108 +static inline unsigned long __must_check
13109 +copy_from_user(void *to, const void __user *from, unsigned long n)
13110 +{
13111 + size_t sz = __compiletime_object_size(to);
13112 +
13113 + if (unlikely(sz != (size_t)-1 && sz < n))
13114 copy_from_user_overflow();
13115 -
13116 + else if (access_ok(VERIFY_READ, from, n))
13117 + n = __copy_from_user(to, from, n);
13118 + else if ((long)n > 0) {
13119 + if (!__builtin_constant_p(n))
13120 + check_object_size(to, n, false);
13121 + memset(to, 0, n);
13122 + }
13123 return n;
13124 }
13125
13126 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13127 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13128 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13129 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13130
13131 #endif /* _ASM_X86_UACCESS_32_H */
13132 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13133 index d8def8b..ac7fc15 100644
13134 --- a/arch/x86/include/asm/uaccess_64.h
13135 +++ b/arch/x86/include/asm/uaccess_64.h
13136 @@ -10,6 +10,9 @@
13137 #include <asm/alternative.h>
13138 #include <asm/cpufeature.h>
13139 #include <asm/page.h>
13140 +#include <asm/pgtable.h>
13141 +
13142 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13143
13144 /*
13145 * Copy To/From Userspace
13146 @@ -17,13 +20,13 @@
13147
13148 /* Handles exceptions in both to and from, but doesn't do access_ok */
13149 __must_check unsigned long
13150 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13151 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13152 __must_check unsigned long
13153 -copy_user_generic_string(void *to, const void *from, unsigned len);
13154 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13155 __must_check unsigned long
13156 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13157 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13158
13159 -static __always_inline __must_check unsigned long
13160 +static __always_inline __must_check __size_overflow(3) unsigned long
13161 copy_user_generic(void *to, const void *from, unsigned len)
13162 {
13163 unsigned ret;
13164 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13165 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13166 "=d" (len)),
13167 "1" (to), "2" (from), "3" (len)
13168 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13169 + : "memory", "rcx", "r8", "r9", "r11");
13170 return ret;
13171 }
13172
13173 +static __always_inline __must_check unsigned long
13174 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13175 +static __always_inline __must_check unsigned long
13176 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13177 __must_check unsigned long
13178 -_copy_to_user(void __user *to, const void *from, unsigned len);
13179 -__must_check unsigned long
13180 -_copy_from_user(void *to, const void __user *from, unsigned len);
13181 -__must_check unsigned long
13182 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13183 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13184 +
13185 +extern void copy_to_user_overflow(void)
13186 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13187 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13188 +#else
13189 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13190 +#endif
13191 +;
13192 +
13193 +extern void copy_from_user_overflow(void)
13194 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13195 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13196 +#else
13197 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13198 +#endif
13199 +;
13200
13201 static inline unsigned long __must_check copy_from_user(void *to,
13202 const void __user *from,
13203 unsigned long n)
13204 {
13205 - int sz = __compiletime_object_size(to);
13206 -
13207 might_fault();
13208 - if (likely(sz == -1 || sz >= n))
13209 - n = _copy_from_user(to, from, n);
13210 -#ifdef CONFIG_DEBUG_VM
13211 - else
13212 - WARN(1, "Buffer overflow detected!\n");
13213 -#endif
13214 +
13215 + if (access_ok(VERIFY_READ, from, n))
13216 + n = __copy_from_user(to, from, n);
13217 + else if (n < INT_MAX) {
13218 + if (!__builtin_constant_p(n))
13219 + check_object_size(to, n, false);
13220 + memset(to, 0, n);
13221 + }
13222 return n;
13223 }
13224
13225 static __always_inline __must_check
13226 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13227 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13228 {
13229 might_fault();
13230
13231 - return _copy_to_user(dst, src, size);
13232 + if (access_ok(VERIFY_WRITE, dst, size))
13233 + size = __copy_to_user(dst, src, size);
13234 + return size;
13235 }
13236
13237 static __always_inline __must_check
13238 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13239 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13240 {
13241 - int ret = 0;
13242 + size_t sz = __compiletime_object_size(dst);
13243 + unsigned ret = 0;
13244
13245 might_fault();
13246 - if (!__builtin_constant_p(size))
13247 - return copy_user_generic(dst, (__force void *)src, size);
13248 +
13249 + if (size > INT_MAX)
13250 + return size;
13251 +
13252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13253 + if (!__access_ok(VERIFY_READ, src, size))
13254 + return size;
13255 +#endif
13256 +
13257 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13258 + copy_from_user_overflow();
13259 + return size;
13260 + }
13261 +
13262 + if (!__builtin_constant_p(size)) {
13263 + check_object_size(dst, size, false);
13264 +
13265 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13266 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13267 + src += PAX_USER_SHADOW_BASE;
13268 +#endif
13269 +
13270 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13271 + }
13272 switch (size) {
13273 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13274 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13275 ret, "b", "b", "=q", 1);
13276 return ret;
13277 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13278 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13279 ret, "w", "w", "=r", 2);
13280 return ret;
13281 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13282 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13283 ret, "l", "k", "=r", 4);
13284 return ret;
13285 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13286 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13287 ret, "q", "", "=r", 8);
13288 return ret;
13289 case 10:
13290 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13291 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13292 ret, "q", "", "=r", 10);
13293 if (unlikely(ret))
13294 return ret;
13295 __get_user_asm(*(u16 *)(8 + (char *)dst),
13296 - (u16 __user *)(8 + (char __user *)src),
13297 + (const u16 __user *)(8 + (const char __user *)src),
13298 ret, "w", "w", "=r", 2);
13299 return ret;
13300 case 16:
13301 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13302 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13303 ret, "q", "", "=r", 16);
13304 if (unlikely(ret))
13305 return ret;
13306 __get_user_asm(*(u64 *)(8 + (char *)dst),
13307 - (u64 __user *)(8 + (char __user *)src),
13308 + (const u64 __user *)(8 + (const char __user *)src),
13309 ret, "q", "", "=r", 8);
13310 return ret;
13311 default:
13312 - return copy_user_generic(dst, (__force void *)src, size);
13313 +
13314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13315 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13316 + src += PAX_USER_SHADOW_BASE;
13317 +#endif
13318 +
13319 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13320 }
13321 }
13322
13323 static __always_inline __must_check
13324 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13325 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13326 {
13327 - int ret = 0;
13328 + size_t sz = __compiletime_object_size(src);
13329 + unsigned ret = 0;
13330
13331 might_fault();
13332 - if (!__builtin_constant_p(size))
13333 - return copy_user_generic((__force void *)dst, src, size);
13334 +
13335 + if (size > INT_MAX)
13336 + return size;
13337 +
13338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13339 + if (!__access_ok(VERIFY_WRITE, dst, size))
13340 + return size;
13341 +#endif
13342 +
13343 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13344 + copy_to_user_overflow();
13345 + return size;
13346 + }
13347 +
13348 + if (!__builtin_constant_p(size)) {
13349 + check_object_size(src, size, true);
13350 +
13351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13352 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13353 + dst += PAX_USER_SHADOW_BASE;
13354 +#endif
13355 +
13356 + return copy_user_generic((__force_kernel void *)dst, src, size);
13357 + }
13358 switch (size) {
13359 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13360 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13361 ret, "b", "b", "iq", 1);
13362 return ret;
13363 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13364 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13365 ret, "w", "w", "ir", 2);
13366 return ret;
13367 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13368 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13369 ret, "l", "k", "ir", 4);
13370 return ret;
13371 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13372 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13373 ret, "q", "", "er", 8);
13374 return ret;
13375 case 10:
13376 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13377 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13378 ret, "q", "", "er", 10);
13379 if (unlikely(ret))
13380 return ret;
13381 asm("":::"memory");
13382 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13383 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13384 ret, "w", "w", "ir", 2);
13385 return ret;
13386 case 16:
13387 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13388 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13389 ret, "q", "", "er", 16);
13390 if (unlikely(ret))
13391 return ret;
13392 asm("":::"memory");
13393 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13394 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13395 ret, "q", "", "er", 8);
13396 return ret;
13397 default:
13398 - return copy_user_generic((__force void *)dst, src, size);
13399 +
13400 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13401 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13402 + dst += PAX_USER_SHADOW_BASE;
13403 +#endif
13404 +
13405 + return copy_user_generic((__force_kernel void *)dst, src, size);
13406 }
13407 }
13408
13409 static __always_inline __must_check
13410 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13411 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13412 {
13413 - int ret = 0;
13414 + unsigned ret = 0;
13415
13416 might_fault();
13417 - if (!__builtin_constant_p(size))
13418 - return copy_user_generic((__force void *)dst,
13419 - (__force void *)src, size);
13420 +
13421 + if (size > INT_MAX)
13422 + return size;
13423 +
13424 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13425 + if (!__access_ok(VERIFY_READ, src, size))
13426 + return size;
13427 + if (!__access_ok(VERIFY_WRITE, dst, size))
13428 + return size;
13429 +#endif
13430 +
13431 + if (!__builtin_constant_p(size)) {
13432 +
13433 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13434 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13435 + src += PAX_USER_SHADOW_BASE;
13436 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13437 + dst += PAX_USER_SHADOW_BASE;
13438 +#endif
13439 +
13440 + return copy_user_generic((__force_kernel void *)dst,
13441 + (__force_kernel const void *)src, size);
13442 + }
13443 switch (size) {
13444 case 1: {
13445 u8 tmp;
13446 - __get_user_asm(tmp, (u8 __user *)src,
13447 + __get_user_asm(tmp, (const u8 __user *)src,
13448 ret, "b", "b", "=q", 1);
13449 if (likely(!ret))
13450 __put_user_asm(tmp, (u8 __user *)dst,
13451 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13452 }
13453 case 2: {
13454 u16 tmp;
13455 - __get_user_asm(tmp, (u16 __user *)src,
13456 + __get_user_asm(tmp, (const u16 __user *)src,
13457 ret, "w", "w", "=r", 2);
13458 if (likely(!ret))
13459 __put_user_asm(tmp, (u16 __user *)dst,
13460 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13461
13462 case 4: {
13463 u32 tmp;
13464 - __get_user_asm(tmp, (u32 __user *)src,
13465 + __get_user_asm(tmp, (const u32 __user *)src,
13466 ret, "l", "k", "=r", 4);
13467 if (likely(!ret))
13468 __put_user_asm(tmp, (u32 __user *)dst,
13469 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13470 }
13471 case 8: {
13472 u64 tmp;
13473 - __get_user_asm(tmp, (u64 __user *)src,
13474 + __get_user_asm(tmp, (const u64 __user *)src,
13475 ret, "q", "", "=r", 8);
13476 if (likely(!ret))
13477 __put_user_asm(tmp, (u64 __user *)dst,
13478 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13479 return ret;
13480 }
13481 default:
13482 - return copy_user_generic((__force void *)dst,
13483 - (__force void *)src, size);
13484 +
13485 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13486 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487 + src += PAX_USER_SHADOW_BASE;
13488 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13489 + dst += PAX_USER_SHADOW_BASE;
13490 +#endif
13491 +
13492 + return copy_user_generic((__force_kernel void *)dst,
13493 + (__force_kernel const void *)src, size);
13494 }
13495 }
13496
13497 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13498 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13499 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13500 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13501
13502 static __must_check __always_inline int
13503 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13504 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13505 {
13506 - return copy_user_generic(dst, (__force const void *)src, size);
13507 + if (size > INT_MAX)
13508 + return size;
13509 +
13510 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13511 + if (!__access_ok(VERIFY_READ, src, size))
13512 + return size;
13513 +
13514 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13515 + src += PAX_USER_SHADOW_BASE;
13516 +#endif
13517 +
13518 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13519 }
13520
13521 -static __must_check __always_inline int
13522 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13523 +static __must_check __always_inline unsigned long
13524 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13525 {
13526 - return copy_user_generic((__force void *)dst, src, size);
13527 + if (size > INT_MAX)
13528 + return size;
13529 +
13530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13531 + if (!__access_ok(VERIFY_WRITE, dst, size))
13532 + return size;
13533 +
13534 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13535 + dst += PAX_USER_SHADOW_BASE;
13536 +#endif
13537 +
13538 + return copy_user_generic((__force_kernel void *)dst, src, size);
13539 }
13540
13541 -extern long __copy_user_nocache(void *dst, const void __user *src,
13542 - unsigned size, int zerorest);
13543 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13544 + unsigned long size, int zerorest) __size_overflow(3);
13545
13546 -static inline int
13547 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13548 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13549 {
13550 might_sleep();
13551 +
13552 + if (size > INT_MAX)
13553 + return size;
13554 +
13555 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13556 + if (!__access_ok(VERIFY_READ, src, size))
13557 + return size;
13558 +#endif
13559 +
13560 return __copy_user_nocache(dst, src, size, 1);
13561 }
13562
13563 -static inline int
13564 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13565 - unsigned size)
13566 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13567 + unsigned long size)
13568 {
13569 + if (size > INT_MAX)
13570 + return size;
13571 +
13572 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13573 + if (!__access_ok(VERIFY_READ, src, size))
13574 + return size;
13575 +#endif
13576 +
13577 return __copy_user_nocache(dst, src, size, 0);
13578 }
13579
13580 -unsigned long
13581 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13582 +extern unsigned long
13583 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13584
13585 #endif /* _ASM_X86_UACCESS_64_H */
13586 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13587 index bb05228..d763d5b 100644
13588 --- a/arch/x86/include/asm/vdso.h
13589 +++ b/arch/x86/include/asm/vdso.h
13590 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13591 #define VDSO32_SYMBOL(base, name) \
13592 ({ \
13593 extern const char VDSO32_##name[]; \
13594 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13595 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13596 })
13597 #endif
13598
13599 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13600 index 5b238981..77fdd78 100644
13601 --- a/arch/x86/include/asm/word-at-a-time.h
13602 +++ b/arch/x86/include/asm/word-at-a-time.h
13603 @@ -11,7 +11,7 @@
13604 * and shift, for example.
13605 */
13606 struct word_at_a_time {
13607 - const unsigned long one_bits, high_bits;
13608 + unsigned long one_bits, high_bits;
13609 };
13610
13611 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13612 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13613 index 38155f6..e4184ba 100644
13614 --- a/arch/x86/include/asm/x86_init.h
13615 +++ b/arch/x86/include/asm/x86_init.h
13616 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13617 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13618 void (*find_smp_config)(void);
13619 void (*get_smp_config)(unsigned int early);
13620 -};
13621 +} __no_const;
13622
13623 /**
13624 * struct x86_init_resources - platform specific resource related ops
13625 @@ -43,7 +43,7 @@ struct x86_init_resources {
13626 void (*probe_roms)(void);
13627 void (*reserve_resources)(void);
13628 char *(*memory_setup)(void);
13629 -};
13630 +} __no_const;
13631
13632 /**
13633 * struct x86_init_irqs - platform specific interrupt setup
13634 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13635 void (*pre_vector_init)(void);
13636 void (*intr_init)(void);
13637 void (*trap_init)(void);
13638 -};
13639 +} __no_const;
13640
13641 /**
13642 * struct x86_init_oem - oem platform specific customizing functions
13643 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13644 struct x86_init_oem {
13645 void (*arch_setup)(void);
13646 void (*banner)(void);
13647 -};
13648 +} __no_const;
13649
13650 /**
13651 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13652 @@ -77,7 +77,7 @@ struct x86_init_oem {
13653 */
13654 struct x86_init_mapping {
13655 void (*pagetable_reserve)(u64 start, u64 end);
13656 -};
13657 +} __no_const;
13658
13659 /**
13660 * struct x86_init_paging - platform specific paging functions
13661 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13662 struct x86_init_paging {
13663 void (*pagetable_setup_start)(pgd_t *base);
13664 void (*pagetable_setup_done)(pgd_t *base);
13665 -};
13666 +} __no_const;
13667
13668 /**
13669 * struct x86_init_timers - platform specific timer setup
13670 @@ -102,7 +102,7 @@ struct x86_init_timers {
13671 void (*tsc_pre_init)(void);
13672 void (*timer_init)(void);
13673 void (*wallclock_init)(void);
13674 -};
13675 +} __no_const;
13676
13677 /**
13678 * struct x86_init_iommu - platform specific iommu setup
13679 @@ -110,7 +110,7 @@ struct x86_init_timers {
13680 */
13681 struct x86_init_iommu {
13682 int (*iommu_init)(void);
13683 -};
13684 +} __no_const;
13685
13686 /**
13687 * struct x86_init_pci - platform specific pci init functions
13688 @@ -124,7 +124,7 @@ struct x86_init_pci {
13689 int (*init)(void);
13690 void (*init_irq)(void);
13691 void (*fixup_irqs)(void);
13692 -};
13693 +} __no_const;
13694
13695 /**
13696 * struct x86_init_ops - functions for platform specific setup
13697 @@ -140,7 +140,7 @@ struct x86_init_ops {
13698 struct x86_init_timers timers;
13699 struct x86_init_iommu iommu;
13700 struct x86_init_pci pci;
13701 -};
13702 +} __no_const;
13703
13704 /**
13705 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13706 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13707 void (*setup_percpu_clockev)(void);
13708 void (*early_percpu_clock_init)(void);
13709 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13710 -};
13711 +} __no_const;
13712
13713 /**
13714 * struct x86_platform_ops - platform specific runtime functions
13715 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13716 void (*save_sched_clock_state)(void);
13717 void (*restore_sched_clock_state)(void);
13718 void (*apic_post_init)(void);
13719 -};
13720 +} __no_const;
13721
13722 struct pci_dev;
13723
13724 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13725 void (*teardown_msi_irq)(unsigned int irq);
13726 void (*teardown_msi_irqs)(struct pci_dev *dev);
13727 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13728 -};
13729 +} __no_const;
13730
13731 struct x86_io_apic_ops {
13732 void (*init) (void);
13733 unsigned int (*read) (unsigned int apic, unsigned int reg);
13734 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13735 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13736 -};
13737 +} __no_const;
13738
13739 extern struct x86_init_ops x86_init;
13740 extern struct x86_cpuinit_ops x86_cpuinit;
13741 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13742 index 8a1b6f9..a29c4e4 100644
13743 --- a/arch/x86/include/asm/xsave.h
13744 +++ b/arch/x86/include/asm/xsave.h
13745 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13746 {
13747 int err;
13748
13749 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13750 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13751 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13752 +#endif
13753 +
13754 /*
13755 * Clear the xsave header first, so that reserved fields are
13756 * initialized to zero.
13757 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13758 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13759 {
13760 int err;
13761 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13762 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13763 u32 lmask = mask;
13764 u32 hmask = mask >> 32;
13765
13766 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13767 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13768 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13769 +#endif
13770 +
13771 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13772 "2:\n"
13773 ".section .fixup,\"ax\"\n"
13774 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13775 index 1b8e5a0..354fd59 100644
13776 --- a/arch/x86/kernel/acpi/sleep.c
13777 +++ b/arch/x86/kernel/acpi/sleep.c
13778 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13779 #else /* CONFIG_64BIT */
13780 #ifdef CONFIG_SMP
13781 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13782 +
13783 + pax_open_kernel();
13784 early_gdt_descr.address =
13785 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13786 + pax_close_kernel();
13787 +
13788 initial_gs = per_cpu_offset(smp_processor_id());
13789 #endif
13790 initial_code = (unsigned long)wakeup_long64;
13791 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13792 index 13ab720..95d5442 100644
13793 --- a/arch/x86/kernel/acpi/wakeup_32.S
13794 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13795 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13796 # and restore the stack ... but you need gdt for this to work
13797 movl saved_context_esp, %esp
13798
13799 - movl %cs:saved_magic, %eax
13800 - cmpl $0x12345678, %eax
13801 + cmpl $0x12345678, saved_magic
13802 jne bogus_magic
13803
13804 # jump to place where we left off
13805 - movl saved_eip, %eax
13806 - jmp *%eax
13807 + jmp *(saved_eip)
13808
13809 bogus_magic:
13810 jmp bogus_magic
13811 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13812 index ced4534..3e75d69 100644
13813 --- a/arch/x86/kernel/alternative.c
13814 +++ b/arch/x86/kernel/alternative.c
13815 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13816 */
13817 for (a = start; a < end; a++) {
13818 instr = (u8 *)&a->instr_offset + a->instr_offset;
13819 +
13820 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13821 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13822 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13823 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13824 +#endif
13825 +
13826 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13827 BUG_ON(a->replacementlen > a->instrlen);
13828 BUG_ON(a->instrlen > sizeof(insnbuf));
13829 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13830 for (poff = start; poff < end; poff++) {
13831 u8 *ptr = (u8 *)poff + *poff;
13832
13833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13834 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13835 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13836 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13837 +#endif
13838 +
13839 if (!*poff || ptr < text || ptr >= text_end)
13840 continue;
13841 /* turn DS segment override prefix into lock prefix */
13842 - if (*ptr == 0x3e)
13843 + if (*ktla_ktva(ptr) == 0x3e)
13844 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13845 };
13846 mutex_unlock(&text_mutex);
13847 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13848 for (poff = start; poff < end; poff++) {
13849 u8 *ptr = (u8 *)poff + *poff;
13850
13851 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13852 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13853 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13854 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13855 +#endif
13856 +
13857 if (!*poff || ptr < text || ptr >= text_end)
13858 continue;
13859 /* turn lock prefix into DS segment override prefix */
13860 - if (*ptr == 0xf0)
13861 + if (*ktla_ktva(ptr) == 0xf0)
13862 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13863 };
13864 mutex_unlock(&text_mutex);
13865 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13866
13867 BUG_ON(p->len > MAX_PATCH_LEN);
13868 /* prep the buffer with the original instructions */
13869 - memcpy(insnbuf, p->instr, p->len);
13870 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13871 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13872 (unsigned long)p->instr, p->len);
13873
13874 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13875 if (smp_alt_once)
13876 free_init_pages("SMP alternatives",
13877 (unsigned long)__smp_locks,
13878 - (unsigned long)__smp_locks_end);
13879 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13880
13881 restart_nmi();
13882 }
13883 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13884 * instructions. And on the local CPU you need to be protected again NMI or MCE
13885 * handlers seeing an inconsistent instruction while you patch.
13886 */
13887 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13888 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13889 size_t len)
13890 {
13891 unsigned long flags;
13892 local_irq_save(flags);
13893 - memcpy(addr, opcode, len);
13894 +
13895 + pax_open_kernel();
13896 + memcpy(ktla_ktva(addr), opcode, len);
13897 sync_core();
13898 + pax_close_kernel();
13899 +
13900 local_irq_restore(flags);
13901 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13902 that causes hangs on some VIA CPUs. */
13903 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13904 */
13905 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13906 {
13907 - unsigned long flags;
13908 - char *vaddr;
13909 + unsigned char *vaddr = ktla_ktva(addr);
13910 struct page *pages[2];
13911 - int i;
13912 + size_t i;
13913
13914 if (!core_kernel_text((unsigned long)addr)) {
13915 - pages[0] = vmalloc_to_page(addr);
13916 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13917 + pages[0] = vmalloc_to_page(vaddr);
13918 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13919 } else {
13920 - pages[0] = virt_to_page(addr);
13921 + pages[0] = virt_to_page(vaddr);
13922 WARN_ON(!PageReserved(pages[0]));
13923 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13924 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13925 }
13926 BUG_ON(!pages[0]);
13927 - local_irq_save(flags);
13928 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13929 - if (pages[1])
13930 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13931 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13932 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13933 - clear_fixmap(FIX_TEXT_POKE0);
13934 - if (pages[1])
13935 - clear_fixmap(FIX_TEXT_POKE1);
13936 - local_flush_tlb();
13937 - sync_core();
13938 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13939 - that causes hangs on some VIA CPUs. */
13940 + text_poke_early(addr, opcode, len);
13941 for (i = 0; i < len; i++)
13942 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13943 - local_irq_restore(flags);
13944 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13945 return addr;
13946 }
13947
13948 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13949 index 24deb30..94a3426 100644
13950 --- a/arch/x86/kernel/apic/apic.c
13951 +++ b/arch/x86/kernel/apic/apic.c
13952 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13953 /*
13954 * Debug level, exported for io_apic.c
13955 */
13956 -unsigned int apic_verbosity;
13957 +int apic_verbosity;
13958
13959 int pic_mode;
13960
13961 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13962 apic_write(APIC_ESR, 0);
13963 v1 = apic_read(APIC_ESR);
13964 ack_APIC_irq();
13965 - atomic_inc(&irq_err_count);
13966 + atomic_inc_unchecked(&irq_err_count);
13967
13968 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13969 smp_processor_id(), v0 , v1);
13970 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13971 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13972 /* Should happen once for each apic */
13973 WARN_ON((*drv)->eoi_write == eoi_write);
13974 - (*drv)->eoi_write = eoi_write;
13975 + pax_open_kernel();
13976 + *(void **)&(*drv)->eoi_write = eoi_write;
13977 + pax_close_kernel();
13978 }
13979 }
13980
13981 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13982 index c265593..137c4ac 100644
13983 --- a/arch/x86/kernel/apic/io_apic.c
13984 +++ b/arch/x86/kernel/apic/io_apic.c
13985 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13986 }
13987 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13988
13989 -void lock_vector_lock(void)
13990 +void lock_vector_lock(void) __acquires(vector_lock)
13991 {
13992 /* Used to the online set of cpus does not change
13993 * during assign_irq_vector.
13994 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13995 raw_spin_lock(&vector_lock);
13996 }
13997
13998 -void unlock_vector_lock(void)
13999 +void unlock_vector_lock(void) __releases(vector_lock)
14000 {
14001 raw_spin_unlock(&vector_lock);
14002 }
14003 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
14004 ack_APIC_irq();
14005 }
14006
14007 -atomic_t irq_mis_count;
14008 +atomic_unchecked_t irq_mis_count;
14009
14010 #ifdef CONFIG_GENERIC_PENDING_IRQ
14011 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14012 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14013 * at the cpu.
14014 */
14015 if (!(v & (1 << (i & 0x1f)))) {
14016 - atomic_inc(&irq_mis_count);
14017 + atomic_inc_unchecked(&irq_mis_count);
14018
14019 eoi_ioapic_irq(irq, cfg);
14020 }
14021 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14022 index d65464e..1035d31 100644
14023 --- a/arch/x86/kernel/apm_32.c
14024 +++ b/arch/x86/kernel/apm_32.c
14025 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14026 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14027 * even though they are called in protected mode.
14028 */
14029 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14030 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14031 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14032
14033 static const char driver_version[] = "1.16ac"; /* no spaces */
14034 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14035 BUG_ON(cpu != 0);
14036 gdt = get_cpu_gdt_table(cpu);
14037 save_desc_40 = gdt[0x40 / 8];
14038 +
14039 + pax_open_kernel();
14040 gdt[0x40 / 8] = bad_bios_desc;
14041 + pax_close_kernel();
14042
14043 apm_irq_save(flags);
14044 APM_DO_SAVE_SEGS;
14045 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14046 &call->esi);
14047 APM_DO_RESTORE_SEGS;
14048 apm_irq_restore(flags);
14049 +
14050 + pax_open_kernel();
14051 gdt[0x40 / 8] = save_desc_40;
14052 + pax_close_kernel();
14053 +
14054 put_cpu();
14055
14056 return call->eax & 0xff;
14057 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14058 BUG_ON(cpu != 0);
14059 gdt = get_cpu_gdt_table(cpu);
14060 save_desc_40 = gdt[0x40 / 8];
14061 +
14062 + pax_open_kernel();
14063 gdt[0x40 / 8] = bad_bios_desc;
14064 + pax_close_kernel();
14065
14066 apm_irq_save(flags);
14067 APM_DO_SAVE_SEGS;
14068 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14069 &call->eax);
14070 APM_DO_RESTORE_SEGS;
14071 apm_irq_restore(flags);
14072 +
14073 + pax_open_kernel();
14074 gdt[0x40 / 8] = save_desc_40;
14075 + pax_close_kernel();
14076 +
14077 put_cpu();
14078 return error;
14079 }
14080 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14081 * code to that CPU.
14082 */
14083 gdt = get_cpu_gdt_table(0);
14084 +
14085 + pax_open_kernel();
14086 set_desc_base(&gdt[APM_CS >> 3],
14087 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14088 set_desc_base(&gdt[APM_CS_16 >> 3],
14089 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14090 set_desc_base(&gdt[APM_DS >> 3],
14091 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14092 + pax_close_kernel();
14093
14094 proc_create("apm", 0, NULL, &apm_file_ops);
14095
14096 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14097 index 68de2dc..1f3c720 100644
14098 --- a/arch/x86/kernel/asm-offsets.c
14099 +++ b/arch/x86/kernel/asm-offsets.c
14100 @@ -33,6 +33,8 @@ void common(void) {
14101 OFFSET(TI_status, thread_info, status);
14102 OFFSET(TI_addr_limit, thread_info, addr_limit);
14103 OFFSET(TI_preempt_count, thread_info, preempt_count);
14104 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14105 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14106
14107 BLANK();
14108 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14109 @@ -53,8 +55,26 @@ void common(void) {
14110 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14111 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14112 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14113 +
14114 +#ifdef CONFIG_PAX_KERNEXEC
14115 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14116 #endif
14117
14118 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14119 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14120 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14121 +#ifdef CONFIG_X86_64
14122 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14123 +#endif
14124 +#endif
14125 +
14126 +#endif
14127 +
14128 + BLANK();
14129 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14130 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14131 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14132 +
14133 #ifdef CONFIG_XEN
14134 BLANK();
14135 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14136 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14137 index 1b4754f..fbb4227 100644
14138 --- a/arch/x86/kernel/asm-offsets_64.c
14139 +++ b/arch/x86/kernel/asm-offsets_64.c
14140 @@ -76,6 +76,7 @@ int main(void)
14141 BLANK();
14142 #undef ENTRY
14143
14144 + DEFINE(TSS_size, sizeof(struct tss_struct));
14145 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14146 BLANK();
14147
14148 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14149 index d30a6a9..79becab 100644
14150 --- a/arch/x86/kernel/cpu/Makefile
14151 +++ b/arch/x86/kernel/cpu/Makefile
14152 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14153 CFLAGS_REMOVE_perf_event.o = -pg
14154 endif
14155
14156 -# Make sure load_percpu_segment has no stackprotector
14157 -nostackp := $(call cc-option, -fno-stack-protector)
14158 -CFLAGS_common.o := $(nostackp)
14159 -
14160 obj-y := intel_cacheinfo.o scattered.o topology.o
14161 obj-y += proc.o capflags.o powerflags.o common.o
14162 obj-y += vmware.o hypervisor.o mshyperv.o
14163 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14164 index 9d92e19..49d7d79 100644
14165 --- a/arch/x86/kernel/cpu/amd.c
14166 +++ b/arch/x86/kernel/cpu/amd.c
14167 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14168 unsigned int size)
14169 {
14170 /* AMD errata T13 (order #21922) */
14171 - if ((c->x86 == 6)) {
14172 + if (c->x86 == 6) {
14173 /* Duron Rev A0 */
14174 if (c->x86_model == 3 && c->x86_mask == 0)
14175 size = 64;
14176 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14177 index a5fbc3c..2254849 100644
14178 --- a/arch/x86/kernel/cpu/common.c
14179 +++ b/arch/x86/kernel/cpu/common.c
14180 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14181
14182 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14183
14184 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14185 -#ifdef CONFIG_X86_64
14186 - /*
14187 - * We need valid kernel segments for data and code in long mode too
14188 - * IRET will check the segment types kkeil 2000/10/28
14189 - * Also sysret mandates a special GDT layout
14190 - *
14191 - * TLS descriptors are currently at a different place compared to i386.
14192 - * Hopefully nobody expects them at a fixed place (Wine?)
14193 - */
14194 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14195 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14196 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14197 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14198 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14199 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14200 -#else
14201 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14202 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14203 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14204 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14205 - /*
14206 - * Segments used for calling PnP BIOS have byte granularity.
14207 - * They code segments and data segments have fixed 64k limits,
14208 - * the transfer segment sizes are set at run time.
14209 - */
14210 - /* 32-bit code */
14211 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14212 - /* 16-bit code */
14213 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14214 - /* 16-bit data */
14215 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14216 - /* 16-bit data */
14217 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14218 - /* 16-bit data */
14219 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14220 - /*
14221 - * The APM segments have byte granularity and their bases
14222 - * are set at run time. All have 64k limits.
14223 - */
14224 - /* 32-bit code */
14225 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14226 - /* 16-bit code */
14227 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14228 - /* data */
14229 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14230 -
14231 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14232 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14233 - GDT_STACK_CANARY_INIT
14234 -#endif
14235 -} };
14236 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14237 -
14238 static int __init x86_xsave_setup(char *s)
14239 {
14240 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14241 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14242 {
14243 struct desc_ptr gdt_descr;
14244
14245 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14246 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14247 gdt_descr.size = GDT_SIZE - 1;
14248 load_gdt(&gdt_descr);
14249 /* Reload the per-cpu base */
14250 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14251 /* Filter out anything that depends on CPUID levels we don't have */
14252 filter_cpuid_features(c, true);
14253
14254 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14255 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14256 +#endif
14257 +
14258 /* If the model name is still unset, do table lookup. */
14259 if (!c->x86_model_id[0]) {
14260 const char *p;
14261 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14262 }
14263 __setup("clearcpuid=", setup_disablecpuid);
14264
14265 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14266 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14267 +
14268 #ifdef CONFIG_X86_64
14269 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14270 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14271 - (unsigned long) nmi_idt_table };
14272 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14273
14274 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14275 irq_stack_union) __aligned(PAGE_SIZE);
14276 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14277 EXPORT_PER_CPU_SYMBOL(current_task);
14278
14279 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14280 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14281 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14282 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14283
14284 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14285 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14286 {
14287 memset(regs, 0, sizeof(struct pt_regs));
14288 regs->fs = __KERNEL_PERCPU;
14289 - regs->gs = __KERNEL_STACK_CANARY;
14290 + savesegment(gs, regs->gs);
14291
14292 return regs;
14293 }
14294 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14295 int i;
14296
14297 cpu = stack_smp_processor_id();
14298 - t = &per_cpu(init_tss, cpu);
14299 + t = init_tss + cpu;
14300 oist = &per_cpu(orig_ist, cpu);
14301
14302 #ifdef CONFIG_NUMA
14303 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14304 switch_to_new_gdt(cpu);
14305 loadsegment(fs, 0);
14306
14307 - load_idt((const struct desc_ptr *)&idt_descr);
14308 + load_idt(&idt_descr);
14309
14310 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14311 syscall_init();
14312 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14313 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14314 barrier();
14315
14316 - x86_configure_nx();
14317 if (cpu != 0)
14318 enable_x2apic();
14319
14320 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14321 {
14322 int cpu = smp_processor_id();
14323 struct task_struct *curr = current;
14324 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14325 + struct tss_struct *t = init_tss + cpu;
14326 struct thread_struct *thread = &curr->thread;
14327
14328 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14329 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14330 index 0a4ce29..f211176 100644
14331 --- a/arch/x86/kernel/cpu/intel.c
14332 +++ b/arch/x86/kernel/cpu/intel.c
14333 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14334 * Update the IDT descriptor and reload the IDT so that
14335 * it uses the read-only mapped virtual address.
14336 */
14337 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14338 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14339 load_idt(&idt_descr);
14340 }
14341 #endif
14342 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14343 index 292d025..b520c94 100644
14344 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14345 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14346 @@ -45,6 +45,7 @@
14347 #include <asm/processor.h>
14348 #include <asm/mce.h>
14349 #include <asm/msr.h>
14350 +#include <asm/local.h>
14351
14352 #include "mce-internal.h"
14353
14354 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14355 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14356 m->cs, m->ip);
14357
14358 - if (m->cs == __KERNEL_CS)
14359 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14360 print_symbol("{%s}", m->ip);
14361 pr_cont("\n");
14362 }
14363 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14364
14365 #define PANIC_TIMEOUT 5 /* 5 seconds */
14366
14367 -static atomic_t mce_paniced;
14368 +static atomic_unchecked_t mce_paniced;
14369
14370 static int fake_panic;
14371 -static atomic_t mce_fake_paniced;
14372 +static atomic_unchecked_t mce_fake_paniced;
14373
14374 /* Panic in progress. Enable interrupts and wait for final IPI */
14375 static void wait_for_panic(void)
14376 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14377 /*
14378 * Make sure only one CPU runs in machine check panic
14379 */
14380 - if (atomic_inc_return(&mce_paniced) > 1)
14381 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14382 wait_for_panic();
14383 barrier();
14384
14385 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14386 console_verbose();
14387 } else {
14388 /* Don't log too much for fake panic */
14389 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14390 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14391 return;
14392 }
14393 /* First print corrected ones that are still unlogged */
14394 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14395 * might have been modified by someone else.
14396 */
14397 rmb();
14398 - if (atomic_read(&mce_paniced))
14399 + if (atomic_read_unchecked(&mce_paniced))
14400 wait_for_panic();
14401 if (!monarch_timeout)
14402 goto out;
14403 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14404 }
14405
14406 /* Call the installed machine check handler for this CPU setup. */
14407 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14408 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14409 unexpected_machine_check;
14410
14411 /*
14412 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14413 return;
14414 }
14415
14416 + pax_open_kernel();
14417 machine_check_vector = do_machine_check;
14418 + pax_close_kernel();
14419
14420 __mcheck_cpu_init_generic();
14421 __mcheck_cpu_init_vendor(c);
14422 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14423 */
14424
14425 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14426 -static int mce_chrdev_open_count; /* #times opened */
14427 +static local_t mce_chrdev_open_count; /* #times opened */
14428 static int mce_chrdev_open_exclu; /* already open exclusive? */
14429
14430 static int mce_chrdev_open(struct inode *inode, struct file *file)
14431 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14432 spin_lock(&mce_chrdev_state_lock);
14433
14434 if (mce_chrdev_open_exclu ||
14435 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14436 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14437 spin_unlock(&mce_chrdev_state_lock);
14438
14439 return -EBUSY;
14440 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14441
14442 if (file->f_flags & O_EXCL)
14443 mce_chrdev_open_exclu = 1;
14444 - mce_chrdev_open_count++;
14445 + local_inc(&mce_chrdev_open_count);
14446
14447 spin_unlock(&mce_chrdev_state_lock);
14448
14449 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14450 {
14451 spin_lock(&mce_chrdev_state_lock);
14452
14453 - mce_chrdev_open_count--;
14454 + local_dec(&mce_chrdev_open_count);
14455 mce_chrdev_open_exclu = 0;
14456
14457 spin_unlock(&mce_chrdev_state_lock);
14458 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14459 static void mce_reset(void)
14460 {
14461 cpu_missing = 0;
14462 - atomic_set(&mce_fake_paniced, 0);
14463 + atomic_set_unchecked(&mce_fake_paniced, 0);
14464 atomic_set(&mce_executing, 0);
14465 atomic_set(&mce_callin, 0);
14466 atomic_set(&global_nwo, 0);
14467 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14468 index 2d5454c..51987eb 100644
14469 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14470 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14471 @@ -11,6 +11,7 @@
14472 #include <asm/processor.h>
14473 #include <asm/mce.h>
14474 #include <asm/msr.h>
14475 +#include <asm/pgtable.h>
14476
14477 /* By default disabled */
14478 int mce_p5_enabled __read_mostly;
14479 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14480 if (!cpu_has(c, X86_FEATURE_MCE))
14481 return;
14482
14483 + pax_open_kernel();
14484 machine_check_vector = pentium_machine_check;
14485 + pax_close_kernel();
14486 /* Make sure the vector pointer is visible before we enable MCEs: */
14487 wmb();
14488
14489 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14490 index 2d7998f..17c9de1 100644
14491 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14492 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14493 @@ -10,6 +10,7 @@
14494 #include <asm/processor.h>
14495 #include <asm/mce.h>
14496 #include <asm/msr.h>
14497 +#include <asm/pgtable.h>
14498
14499 /* Machine check handler for WinChip C6: */
14500 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14501 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14502 {
14503 u32 lo, hi;
14504
14505 + pax_open_kernel();
14506 machine_check_vector = winchip_machine_check;
14507 + pax_close_kernel();
14508 /* Make sure the vector pointer is visible before we enable MCEs: */
14509 wmb();
14510
14511 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14512 index 6b96110..0da73eb 100644
14513 --- a/arch/x86/kernel/cpu/mtrr/main.c
14514 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14515 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14516 u64 size_or_mask, size_and_mask;
14517 static bool mtrr_aps_delayed_init;
14518
14519 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14520 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14521
14522 const struct mtrr_ops *mtrr_if;
14523
14524 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14525 index df5e41f..816c719 100644
14526 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14527 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14528 @@ -25,7 +25,7 @@ struct mtrr_ops {
14529 int (*validate_add_page)(unsigned long base, unsigned long size,
14530 unsigned int type);
14531 int (*have_wrcomb)(void);
14532 -};
14533 +} __do_const;
14534
14535 extern int generic_get_free_region(unsigned long base, unsigned long size,
14536 int replace_reg);
14537 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14538 index 915b876..171f845 100644
14539 --- a/arch/x86/kernel/cpu/perf_event.c
14540 +++ b/arch/x86/kernel/cpu/perf_event.c
14541 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14542 if (idx > GDT_ENTRIES)
14543 return 0;
14544
14545 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14546 + desc = get_cpu_gdt_table(smp_processor_id());
14547 }
14548
14549 return get_desc_base(desc + idx);
14550 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14551 break;
14552
14553 perf_callchain_store(entry, frame.return_address);
14554 - fp = frame.next_frame;
14555 + fp = (const void __force_user *)frame.next_frame;
14556 }
14557 }
14558
14559 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14560 index 6bca492..36e4496 100644
14561 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14562 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14563 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14564 * v2 and above have a perf capabilities MSR
14565 */
14566 if (version > 1) {
14567 - u64 capabilities;
14568 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14569
14570 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14571 - x86_pmu.intel_cap.capabilities = capabilities;
14572 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14573 + x86_pmu.intel_cap.capabilities = capabilities;
14574 }
14575
14576 intel_ds_init();
14577 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14578 index 13ad899..f642b9a 100644
14579 --- a/arch/x86/kernel/crash.c
14580 +++ b/arch/x86/kernel/crash.c
14581 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14582 {
14583 #ifdef CONFIG_X86_32
14584 struct pt_regs fixed_regs;
14585 -#endif
14586
14587 -#ifdef CONFIG_X86_32
14588 - if (!user_mode_vm(regs)) {
14589 + if (!user_mode(regs)) {
14590 crash_fixup_ss_esp(&fixed_regs, regs);
14591 regs = &fixed_regs;
14592 }
14593 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14594 index 37250fe..bf2ec74 100644
14595 --- a/arch/x86/kernel/doublefault_32.c
14596 +++ b/arch/x86/kernel/doublefault_32.c
14597 @@ -11,7 +11,7 @@
14598
14599 #define DOUBLEFAULT_STACKSIZE (1024)
14600 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14601 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14602 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14603
14604 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14605
14606 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14607 unsigned long gdt, tss;
14608
14609 store_gdt(&gdt_desc);
14610 - gdt = gdt_desc.address;
14611 + gdt = (unsigned long)gdt_desc.address;
14612
14613 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14614
14615 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14616 /* 0x2 bit is always set */
14617 .flags = X86_EFLAGS_SF | 0x2,
14618 .sp = STACK_START,
14619 - .es = __USER_DS,
14620 + .es = __KERNEL_DS,
14621 .cs = __KERNEL_CS,
14622 .ss = __KERNEL_DS,
14623 - .ds = __USER_DS,
14624 + .ds = __KERNEL_DS,
14625 .fs = __KERNEL_PERCPU,
14626
14627 .__cr3 = __pa_nodebug(swapper_pg_dir),
14628 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14629 index ae42418b..787c16b 100644
14630 --- a/arch/x86/kernel/dumpstack.c
14631 +++ b/arch/x86/kernel/dumpstack.c
14632 @@ -2,6 +2,9 @@
14633 * Copyright (C) 1991, 1992 Linus Torvalds
14634 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14635 */
14636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14637 +#define __INCLUDED_BY_HIDESYM 1
14638 +#endif
14639 #include <linux/kallsyms.h>
14640 #include <linux/kprobes.h>
14641 #include <linux/uaccess.h>
14642 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14643 static void
14644 print_ftrace_graph_addr(unsigned long addr, void *data,
14645 const struct stacktrace_ops *ops,
14646 - struct thread_info *tinfo, int *graph)
14647 + struct task_struct *task, int *graph)
14648 {
14649 - struct task_struct *task;
14650 unsigned long ret_addr;
14651 int index;
14652
14653 if (addr != (unsigned long)return_to_handler)
14654 return;
14655
14656 - task = tinfo->task;
14657 index = task->curr_ret_stack;
14658
14659 if (!task->ret_stack || index < *graph)
14660 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14661 static inline void
14662 print_ftrace_graph_addr(unsigned long addr, void *data,
14663 const struct stacktrace_ops *ops,
14664 - struct thread_info *tinfo, int *graph)
14665 + struct task_struct *task, int *graph)
14666 { }
14667 #endif
14668
14669 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14670 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14671 */
14672
14673 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14674 - void *p, unsigned int size, void *end)
14675 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14676 {
14677 - void *t = tinfo;
14678 if (end) {
14679 if (p < end && p >= (end-THREAD_SIZE))
14680 return 1;
14681 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14682 }
14683
14684 unsigned long
14685 -print_context_stack(struct thread_info *tinfo,
14686 +print_context_stack(struct task_struct *task, void *stack_start,
14687 unsigned long *stack, unsigned long bp,
14688 const struct stacktrace_ops *ops, void *data,
14689 unsigned long *end, int *graph)
14690 {
14691 struct stack_frame *frame = (struct stack_frame *)bp;
14692
14693 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14694 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14695 unsigned long addr;
14696
14697 addr = *stack;
14698 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14699 } else {
14700 ops->address(data, addr, 0);
14701 }
14702 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14703 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14704 }
14705 stack++;
14706 }
14707 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14708 EXPORT_SYMBOL_GPL(print_context_stack);
14709
14710 unsigned long
14711 -print_context_stack_bp(struct thread_info *tinfo,
14712 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14713 unsigned long *stack, unsigned long bp,
14714 const struct stacktrace_ops *ops, void *data,
14715 unsigned long *end, int *graph)
14716 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14717 struct stack_frame *frame = (struct stack_frame *)bp;
14718 unsigned long *ret_addr = &frame->return_address;
14719
14720 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14721 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14722 unsigned long addr = *ret_addr;
14723
14724 if (!__kernel_text_address(addr))
14725 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14726 ops->address(data, addr, 1);
14727 frame = frame->next_frame;
14728 ret_addr = &frame->return_address;
14729 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14730 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14731 }
14732
14733 return (unsigned long)frame;
14734 @@ -189,7 +188,7 @@ void dump_stack(void)
14735
14736 bp = stack_frame(current, NULL);
14737 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14738 - current->pid, current->comm, print_tainted(),
14739 + task_pid_nr(current), current->comm, print_tainted(),
14740 init_utsname()->release,
14741 (int)strcspn(init_utsname()->version, " "),
14742 init_utsname()->version);
14743 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14744 }
14745 EXPORT_SYMBOL_GPL(oops_begin);
14746
14747 +extern void gr_handle_kernel_exploit(void);
14748 +
14749 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14750 {
14751 if (regs && kexec_should_crash(current))
14752 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14753 panic("Fatal exception in interrupt");
14754 if (panic_on_oops)
14755 panic("Fatal exception");
14756 - do_exit(signr);
14757 +
14758 + gr_handle_kernel_exploit();
14759 +
14760 + do_group_exit(signr);
14761 }
14762
14763 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14764 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14765 print_modules();
14766 show_regs(regs);
14767 #ifdef CONFIG_X86_32
14768 - if (user_mode_vm(regs)) {
14769 + if (user_mode(regs)) {
14770 sp = regs->sp;
14771 ss = regs->ss & 0xffff;
14772 } else {
14773 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14774 unsigned long flags = oops_begin();
14775 int sig = SIGSEGV;
14776
14777 - if (!user_mode_vm(regs))
14778 + if (!user_mode(regs))
14779 report_bug(regs->ip, regs);
14780
14781 if (__die(str, regs, err))
14782 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14783 index 1038a41..ac7e5f6 100644
14784 --- a/arch/x86/kernel/dumpstack_32.c
14785 +++ b/arch/x86/kernel/dumpstack_32.c
14786 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14787 bp = stack_frame(task, regs);
14788
14789 for (;;) {
14790 - struct thread_info *context;
14791 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14792
14793 - context = (struct thread_info *)
14794 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14795 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14796 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14797
14798 - stack = (unsigned long *)context->previous_esp;
14799 - if (!stack)
14800 + if (stack_start == task_stack_page(task))
14801 break;
14802 + stack = *(unsigned long **)stack_start;
14803 if (ops->stack(data, "IRQ") < 0)
14804 break;
14805 touch_nmi_watchdog();
14806 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14807 {
14808 int i;
14809
14810 - __show_regs(regs, !user_mode_vm(regs));
14811 + __show_regs(regs, !user_mode(regs));
14812
14813 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14814 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14815 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14816 * When in-kernel, we also print out the stack and code at the
14817 * time of the fault..
14818 */
14819 - if (!user_mode_vm(regs)) {
14820 + if (!user_mode(regs)) {
14821 unsigned int code_prologue = code_bytes * 43 / 64;
14822 unsigned int code_len = code_bytes;
14823 unsigned char c;
14824 u8 *ip;
14825 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14826
14827 pr_emerg("Stack:\n");
14828 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14829
14830 pr_emerg("Code:");
14831
14832 - ip = (u8 *)regs->ip - code_prologue;
14833 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14834 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14835 /* try starting at IP */
14836 - ip = (u8 *)regs->ip;
14837 + ip = (u8 *)regs->ip + cs_base;
14838 code_len = code_len - code_prologue + 1;
14839 }
14840 for (i = 0; i < code_len; i++, ip++) {
14841 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14842 pr_cont(" Bad EIP value.");
14843 break;
14844 }
14845 - if (ip == (u8 *)regs->ip)
14846 + if (ip == (u8 *)regs->ip + cs_base)
14847 pr_cont(" <%02x>", c);
14848 else
14849 pr_cont(" %02x", c);
14850 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14851 {
14852 unsigned short ud2;
14853
14854 + ip = ktla_ktva(ip);
14855 if (ip < PAGE_OFFSET)
14856 return 0;
14857 if (probe_kernel_address((unsigned short *)ip, ud2))
14858 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14859
14860 return ud2 == 0x0b0f;
14861 }
14862 +
14863 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14864 +void pax_check_alloca(unsigned long size)
14865 +{
14866 + unsigned long sp = (unsigned long)&sp, stack_left;
14867 +
14868 + /* all kernel stacks are of the same size */
14869 + stack_left = sp & (THREAD_SIZE - 1);
14870 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14871 +}
14872 +EXPORT_SYMBOL(pax_check_alloca);
14873 +#endif
14874 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14875 index b653675..33190c0 100644
14876 --- a/arch/x86/kernel/dumpstack_64.c
14877 +++ b/arch/x86/kernel/dumpstack_64.c
14878 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14879 unsigned long *irq_stack_end =
14880 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14881 unsigned used = 0;
14882 - struct thread_info *tinfo;
14883 int graph = 0;
14884 unsigned long dummy;
14885 + void *stack_start;
14886
14887 if (!task)
14888 task = current;
14889 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14890 * current stack address. If the stacks consist of nested
14891 * exceptions
14892 */
14893 - tinfo = task_thread_info(task);
14894 for (;;) {
14895 char *id;
14896 unsigned long *estack_end;
14897 +
14898 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14899 &used, &id);
14900
14901 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14902 if (ops->stack(data, id) < 0)
14903 break;
14904
14905 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14906 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14907 data, estack_end, &graph);
14908 ops->stack(data, "<EOE>");
14909 /*
14910 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14911 * second-to-last pointer (index -2 to end) in the
14912 * exception stack:
14913 */
14914 + if ((u16)estack_end[-1] != __KERNEL_DS)
14915 + goto out;
14916 stack = (unsigned long *) estack_end[-2];
14917 continue;
14918 }
14919 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14920 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14921 if (ops->stack(data, "IRQ") < 0)
14922 break;
14923 - bp = ops->walk_stack(tinfo, stack, bp,
14924 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14925 ops, data, irq_stack_end, &graph);
14926 /*
14927 * We link to the next stack (which would be
14928 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14929 /*
14930 * This handles the process stack:
14931 */
14932 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14933 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14934 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14935 +out:
14936 put_cpu();
14937 }
14938 EXPORT_SYMBOL(dump_trace);
14939 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14940
14941 return ud2 == 0x0b0f;
14942 }
14943 +
14944 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14945 +void pax_check_alloca(unsigned long size)
14946 +{
14947 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14948 + unsigned cpu, used;
14949 + char *id;
14950 +
14951 + /* check the process stack first */
14952 + stack_start = (unsigned long)task_stack_page(current);
14953 + stack_end = stack_start + THREAD_SIZE;
14954 + if (likely(stack_start <= sp && sp < stack_end)) {
14955 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14956 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14957 + return;
14958 + }
14959 +
14960 + cpu = get_cpu();
14961 +
14962 + /* check the irq stacks */
14963 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14964 + stack_start = stack_end - IRQ_STACK_SIZE;
14965 + if (stack_start <= sp && sp < stack_end) {
14966 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14967 + put_cpu();
14968 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14969 + return;
14970 + }
14971 +
14972 + /* check the exception stacks */
14973 + used = 0;
14974 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14975 + stack_start = stack_end - EXCEPTION_STKSZ;
14976 + if (stack_end && stack_start <= sp && sp < stack_end) {
14977 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14978 + put_cpu();
14979 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14980 + return;
14981 + }
14982 +
14983 + put_cpu();
14984 +
14985 + /* unknown stack */
14986 + BUG();
14987 +}
14988 +EXPORT_SYMBOL(pax_check_alloca);
14989 +#endif
14990 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14991 index 9b9f18b..9fcaa04 100644
14992 --- a/arch/x86/kernel/early_printk.c
14993 +++ b/arch/x86/kernel/early_printk.c
14994 @@ -7,6 +7,7 @@
14995 #include <linux/pci_regs.h>
14996 #include <linux/pci_ids.h>
14997 #include <linux/errno.h>
14998 +#include <linux/sched.h>
14999 #include <asm/io.h>
15000 #include <asm/processor.h>
15001 #include <asm/fcntl.h>
15002 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15003 index 8f8e8ee..3617d6e 100644
15004 --- a/arch/x86/kernel/entry_32.S
15005 +++ b/arch/x86/kernel/entry_32.S
15006 @@ -176,13 +176,153 @@
15007 /*CFI_REL_OFFSET gs, PT_GS*/
15008 .endm
15009 .macro SET_KERNEL_GS reg
15010 +
15011 +#ifdef CONFIG_CC_STACKPROTECTOR
15012 movl $(__KERNEL_STACK_CANARY), \reg
15013 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15014 + movl $(__USER_DS), \reg
15015 +#else
15016 + xorl \reg, \reg
15017 +#endif
15018 +
15019 movl \reg, %gs
15020 .endm
15021
15022 #endif /* CONFIG_X86_32_LAZY_GS */
15023
15024 -.macro SAVE_ALL
15025 +.macro pax_enter_kernel
15026 +#ifdef CONFIG_PAX_KERNEXEC
15027 + call pax_enter_kernel
15028 +#endif
15029 +.endm
15030 +
15031 +.macro pax_exit_kernel
15032 +#ifdef CONFIG_PAX_KERNEXEC
15033 + call pax_exit_kernel
15034 +#endif
15035 +.endm
15036 +
15037 +#ifdef CONFIG_PAX_KERNEXEC
15038 +ENTRY(pax_enter_kernel)
15039 +#ifdef CONFIG_PARAVIRT
15040 + pushl %eax
15041 + pushl %ecx
15042 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15043 + mov %eax, %esi
15044 +#else
15045 + mov %cr0, %esi
15046 +#endif
15047 + bts $16, %esi
15048 + jnc 1f
15049 + mov %cs, %esi
15050 + cmp $__KERNEL_CS, %esi
15051 + jz 3f
15052 + ljmp $__KERNEL_CS, $3f
15053 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15054 +2:
15055 +#ifdef CONFIG_PARAVIRT
15056 + mov %esi, %eax
15057 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15058 +#else
15059 + mov %esi, %cr0
15060 +#endif
15061 +3:
15062 +#ifdef CONFIG_PARAVIRT
15063 + popl %ecx
15064 + popl %eax
15065 +#endif
15066 + ret
15067 +ENDPROC(pax_enter_kernel)
15068 +
15069 +ENTRY(pax_exit_kernel)
15070 +#ifdef CONFIG_PARAVIRT
15071 + pushl %eax
15072 + pushl %ecx
15073 +#endif
15074 + mov %cs, %esi
15075 + cmp $__KERNEXEC_KERNEL_CS, %esi
15076 + jnz 2f
15077 +#ifdef CONFIG_PARAVIRT
15078 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15079 + mov %eax, %esi
15080 +#else
15081 + mov %cr0, %esi
15082 +#endif
15083 + btr $16, %esi
15084 + ljmp $__KERNEL_CS, $1f
15085 +1:
15086 +#ifdef CONFIG_PARAVIRT
15087 + mov %esi, %eax
15088 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15089 +#else
15090 + mov %esi, %cr0
15091 +#endif
15092 +2:
15093 +#ifdef CONFIG_PARAVIRT
15094 + popl %ecx
15095 + popl %eax
15096 +#endif
15097 + ret
15098 +ENDPROC(pax_exit_kernel)
15099 +#endif
15100 +
15101 +.macro pax_erase_kstack
15102 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15103 + call pax_erase_kstack
15104 +#endif
15105 +.endm
15106 +
15107 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15108 +/*
15109 + * ebp: thread_info
15110 + */
15111 +ENTRY(pax_erase_kstack)
15112 + pushl %edi
15113 + pushl %ecx
15114 + pushl %eax
15115 +
15116 + mov TI_lowest_stack(%ebp), %edi
15117 + mov $-0xBEEF, %eax
15118 + std
15119 +
15120 +1: mov %edi, %ecx
15121 + and $THREAD_SIZE_asm - 1, %ecx
15122 + shr $2, %ecx
15123 + repne scasl
15124 + jecxz 2f
15125 +
15126 + cmp $2*16, %ecx
15127 + jc 2f
15128 +
15129 + mov $2*16, %ecx
15130 + repe scasl
15131 + jecxz 2f
15132 + jne 1b
15133 +
15134 +2: cld
15135 + mov %esp, %ecx
15136 + sub %edi, %ecx
15137 +
15138 + cmp $THREAD_SIZE_asm, %ecx
15139 + jb 3f
15140 + ud2
15141 +3:
15142 +
15143 + shr $2, %ecx
15144 + rep stosl
15145 +
15146 + mov TI_task_thread_sp0(%ebp), %edi
15147 + sub $128, %edi
15148 + mov %edi, TI_lowest_stack(%ebp)
15149 +
15150 + popl %eax
15151 + popl %ecx
15152 + popl %edi
15153 + ret
15154 +ENDPROC(pax_erase_kstack)
15155 +#endif
15156 +
15157 +.macro __SAVE_ALL _DS
15158 cld
15159 PUSH_GS
15160 pushl_cfi %fs
15161 @@ -205,7 +345,7 @@
15162 CFI_REL_OFFSET ecx, 0
15163 pushl_cfi %ebx
15164 CFI_REL_OFFSET ebx, 0
15165 - movl $(__USER_DS), %edx
15166 + movl $\_DS, %edx
15167 movl %edx, %ds
15168 movl %edx, %es
15169 movl $(__KERNEL_PERCPU), %edx
15170 @@ -213,6 +353,15 @@
15171 SET_KERNEL_GS %edx
15172 .endm
15173
15174 +.macro SAVE_ALL
15175 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15176 + __SAVE_ALL __KERNEL_DS
15177 + pax_enter_kernel
15178 +#else
15179 + __SAVE_ALL __USER_DS
15180 +#endif
15181 +.endm
15182 +
15183 .macro RESTORE_INT_REGS
15184 popl_cfi %ebx
15185 CFI_RESTORE ebx
15186 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15187 popfl_cfi
15188 jmp syscall_exit
15189 CFI_ENDPROC
15190 -END(ret_from_fork)
15191 +ENDPROC(ret_from_fork)
15192
15193 /*
15194 * Interrupt exit functions should be protected against kprobes
15195 @@ -329,7 +478,15 @@ ret_from_intr:
15196 andl $SEGMENT_RPL_MASK, %eax
15197 #endif
15198 cmpl $USER_RPL, %eax
15199 +
15200 +#ifdef CONFIG_PAX_KERNEXEC
15201 + jae resume_userspace
15202 +
15203 + pax_exit_kernel
15204 + jmp resume_kernel
15205 +#else
15206 jb resume_kernel # not returning to v8086 or userspace
15207 +#endif
15208
15209 ENTRY(resume_userspace)
15210 LOCKDEP_SYS_EXIT
15211 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15212 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15213 # int/exception return?
15214 jne work_pending
15215 - jmp restore_all
15216 -END(ret_from_exception)
15217 + jmp restore_all_pax
15218 +ENDPROC(ret_from_exception)
15219
15220 #ifdef CONFIG_PREEMPT
15221 ENTRY(resume_kernel)
15222 @@ -357,7 +514,7 @@ need_resched:
15223 jz restore_all
15224 call preempt_schedule_irq
15225 jmp need_resched
15226 -END(resume_kernel)
15227 +ENDPROC(resume_kernel)
15228 #endif
15229 CFI_ENDPROC
15230 /*
15231 @@ -391,28 +548,43 @@ sysenter_past_esp:
15232 /*CFI_REL_OFFSET cs, 0*/
15233 /*
15234 * Push current_thread_info()->sysenter_return to the stack.
15235 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15236 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15237 */
15238 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15239 + pushl_cfi $0
15240 CFI_REL_OFFSET eip, 0
15241
15242 pushl_cfi %eax
15243 SAVE_ALL
15244 + GET_THREAD_INFO(%ebp)
15245 + movl TI_sysenter_return(%ebp),%ebp
15246 + movl %ebp,PT_EIP(%esp)
15247 ENABLE_INTERRUPTS(CLBR_NONE)
15248
15249 /*
15250 * Load the potential sixth argument from user stack.
15251 * Careful about security.
15252 */
15253 + movl PT_OLDESP(%esp),%ebp
15254 +
15255 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15256 + mov PT_OLDSS(%esp),%ds
15257 +1: movl %ds:(%ebp),%ebp
15258 + push %ss
15259 + pop %ds
15260 +#else
15261 cmpl $__PAGE_OFFSET-3,%ebp
15262 jae syscall_fault
15263 1: movl (%ebp),%ebp
15264 +#endif
15265 +
15266 movl %ebp,PT_EBP(%esp)
15267 _ASM_EXTABLE(1b,syscall_fault)
15268
15269 GET_THREAD_INFO(%ebp)
15270
15271 +#ifdef CONFIG_PAX_RANDKSTACK
15272 + pax_erase_kstack
15273 +#endif
15274 +
15275 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15276 jnz sysenter_audit
15277 sysenter_do_call:
15278 @@ -427,12 +599,24 @@ sysenter_do_call:
15279 testl $_TIF_ALLWORK_MASK, %ecx
15280 jne sysexit_audit
15281 sysenter_exit:
15282 +
15283 +#ifdef CONFIG_PAX_RANDKSTACK
15284 + pushl_cfi %eax
15285 + movl %esp, %eax
15286 + call pax_randomize_kstack
15287 + popl_cfi %eax
15288 +#endif
15289 +
15290 + pax_erase_kstack
15291 +
15292 /* if something modifies registers it must also disable sysexit */
15293 movl PT_EIP(%esp), %edx
15294 movl PT_OLDESP(%esp), %ecx
15295 xorl %ebp,%ebp
15296 TRACE_IRQS_ON
15297 1: mov PT_FS(%esp), %fs
15298 +2: mov PT_DS(%esp), %ds
15299 +3: mov PT_ES(%esp), %es
15300 PTGS_TO_GS
15301 ENABLE_INTERRUPTS_SYSEXIT
15302
15303 @@ -449,6 +633,9 @@ sysenter_audit:
15304 movl %eax,%edx /* 2nd arg: syscall number */
15305 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15306 call __audit_syscall_entry
15307 +
15308 + pax_erase_kstack
15309 +
15310 pushl_cfi %ebx
15311 movl PT_EAX(%esp),%eax /* reload syscall number */
15312 jmp sysenter_do_call
15313 @@ -474,10 +661,16 @@ sysexit_audit:
15314
15315 CFI_ENDPROC
15316 .pushsection .fixup,"ax"
15317 -2: movl $0,PT_FS(%esp)
15318 +4: movl $0,PT_FS(%esp)
15319 + jmp 1b
15320 +5: movl $0,PT_DS(%esp)
15321 + jmp 1b
15322 +6: movl $0,PT_ES(%esp)
15323 jmp 1b
15324 .popsection
15325 - _ASM_EXTABLE(1b,2b)
15326 + _ASM_EXTABLE(1b,4b)
15327 + _ASM_EXTABLE(2b,5b)
15328 + _ASM_EXTABLE(3b,6b)
15329 PTGS_TO_GS_EX
15330 ENDPROC(ia32_sysenter_target)
15331
15332 @@ -491,6 +684,11 @@ ENTRY(system_call)
15333 pushl_cfi %eax # save orig_eax
15334 SAVE_ALL
15335 GET_THREAD_INFO(%ebp)
15336 +
15337 +#ifdef CONFIG_PAX_RANDKSTACK
15338 + pax_erase_kstack
15339 +#endif
15340 +
15341 # system call tracing in operation / emulation
15342 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15343 jnz syscall_trace_entry
15344 @@ -509,6 +707,15 @@ syscall_exit:
15345 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15346 jne syscall_exit_work
15347
15348 +restore_all_pax:
15349 +
15350 +#ifdef CONFIG_PAX_RANDKSTACK
15351 + movl %esp, %eax
15352 + call pax_randomize_kstack
15353 +#endif
15354 +
15355 + pax_erase_kstack
15356 +
15357 restore_all:
15358 TRACE_IRQS_IRET
15359 restore_all_notrace:
15360 @@ -565,14 +772,34 @@ ldt_ss:
15361 * compensating for the offset by changing to the ESPFIX segment with
15362 * a base address that matches for the difference.
15363 */
15364 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15365 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15366 mov %esp, %edx /* load kernel esp */
15367 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15368 mov %dx, %ax /* eax: new kernel esp */
15369 sub %eax, %edx /* offset (low word is 0) */
15370 +#ifdef CONFIG_SMP
15371 + movl PER_CPU_VAR(cpu_number), %ebx
15372 + shll $PAGE_SHIFT_asm, %ebx
15373 + addl $cpu_gdt_table, %ebx
15374 +#else
15375 + movl $cpu_gdt_table, %ebx
15376 +#endif
15377 shr $16, %edx
15378 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15379 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15380 +
15381 +#ifdef CONFIG_PAX_KERNEXEC
15382 + mov %cr0, %esi
15383 + btr $16, %esi
15384 + mov %esi, %cr0
15385 +#endif
15386 +
15387 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15388 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15389 +
15390 +#ifdef CONFIG_PAX_KERNEXEC
15391 + bts $16, %esi
15392 + mov %esi, %cr0
15393 +#endif
15394 +
15395 pushl_cfi $__ESPFIX_SS
15396 pushl_cfi %eax /* new kernel esp */
15397 /* Disable interrupts, but do not irqtrace this section: we
15398 @@ -601,35 +828,23 @@ work_resched:
15399 movl TI_flags(%ebp), %ecx
15400 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15401 # than syscall tracing?
15402 - jz restore_all
15403 + jz restore_all_pax
15404 testb $_TIF_NEED_RESCHED, %cl
15405 jnz work_resched
15406
15407 work_notifysig: # deal with pending signals and
15408 # notify-resume requests
15409 + movl %esp, %eax
15410 #ifdef CONFIG_VM86
15411 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15412 - movl %esp, %eax
15413 - jne work_notifysig_v86 # returning to kernel-space or
15414 + jz 1f # returning to kernel-space or
15415 # vm86-space
15416 - TRACE_IRQS_ON
15417 - ENABLE_INTERRUPTS(CLBR_NONE)
15418 - movb PT_CS(%esp), %bl
15419 - andb $SEGMENT_RPL_MASK, %bl
15420 - cmpb $USER_RPL, %bl
15421 - jb resume_kernel
15422 - xorl %edx, %edx
15423 - call do_notify_resume
15424 - jmp resume_userspace
15425
15426 - ALIGN
15427 -work_notifysig_v86:
15428 pushl_cfi %ecx # save ti_flags for do_notify_resume
15429 call save_v86_state # %eax contains pt_regs pointer
15430 popl_cfi %ecx
15431 movl %eax, %esp
15432 -#else
15433 - movl %esp, %eax
15434 +1:
15435 #endif
15436 TRACE_IRQS_ON
15437 ENABLE_INTERRUPTS(CLBR_NONE)
15438 @@ -640,7 +855,7 @@ work_notifysig_v86:
15439 xorl %edx, %edx
15440 call do_notify_resume
15441 jmp resume_userspace
15442 -END(work_pending)
15443 +ENDPROC(work_pending)
15444
15445 # perform syscall exit tracing
15446 ALIGN
15447 @@ -648,11 +863,14 @@ syscall_trace_entry:
15448 movl $-ENOSYS,PT_EAX(%esp)
15449 movl %esp, %eax
15450 call syscall_trace_enter
15451 +
15452 + pax_erase_kstack
15453 +
15454 /* What it returned is what we'll actually use. */
15455 cmpl $(NR_syscalls), %eax
15456 jnae syscall_call
15457 jmp syscall_exit
15458 -END(syscall_trace_entry)
15459 +ENDPROC(syscall_trace_entry)
15460
15461 # perform syscall exit tracing
15462 ALIGN
15463 @@ -665,20 +883,24 @@ syscall_exit_work:
15464 movl %esp, %eax
15465 call syscall_trace_leave
15466 jmp resume_userspace
15467 -END(syscall_exit_work)
15468 +ENDPROC(syscall_exit_work)
15469 CFI_ENDPROC
15470
15471 RING0_INT_FRAME # can't unwind into user space anyway
15472 syscall_fault:
15473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15474 + push %ss
15475 + pop %ds
15476 +#endif
15477 GET_THREAD_INFO(%ebp)
15478 movl $-EFAULT,PT_EAX(%esp)
15479 jmp resume_userspace
15480 -END(syscall_fault)
15481 +ENDPROC(syscall_fault)
15482
15483 syscall_badsys:
15484 movl $-ENOSYS,PT_EAX(%esp)
15485 jmp resume_userspace
15486 -END(syscall_badsys)
15487 +ENDPROC(syscall_badsys)
15488 CFI_ENDPROC
15489 /*
15490 * End of kprobes section
15491 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15492 CFI_ENDPROC
15493 ENDPROC(ptregs_clone)
15494
15495 + ALIGN;
15496 +ENTRY(kernel_execve)
15497 + CFI_STARTPROC
15498 + pushl_cfi %ebp
15499 + sub $PT_OLDSS+4,%esp
15500 + pushl_cfi %edi
15501 + pushl_cfi %ecx
15502 + pushl_cfi %eax
15503 + lea 3*4(%esp),%edi
15504 + mov $PT_OLDSS/4+1,%ecx
15505 + xorl %eax,%eax
15506 + rep stosl
15507 + popl_cfi %eax
15508 + popl_cfi %ecx
15509 + popl_cfi %edi
15510 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15511 + pushl_cfi %esp
15512 + call sys_execve
15513 + add $4,%esp
15514 + CFI_ADJUST_CFA_OFFSET -4
15515 + GET_THREAD_INFO(%ebp)
15516 + test %eax,%eax
15517 + jz syscall_exit
15518 + add $PT_OLDSS+4,%esp
15519 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15520 + popl_cfi %ebp
15521 + ret
15522 + CFI_ENDPROC
15523 +ENDPROC(kernel_execve)
15524 +
15525 .macro FIXUP_ESPFIX_STACK
15526 /*
15527 * Switch back for ESPFIX stack to the normal zerobased stack
15528 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15529 * normal stack and adjusts ESP with the matching offset.
15530 */
15531 /* fixup the stack */
15532 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15533 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15534 +#ifdef CONFIG_SMP
15535 + movl PER_CPU_VAR(cpu_number), %ebx
15536 + shll $PAGE_SHIFT_asm, %ebx
15537 + addl $cpu_gdt_table, %ebx
15538 +#else
15539 + movl $cpu_gdt_table, %ebx
15540 +#endif
15541 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15542 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15543 shl $16, %eax
15544 addl %esp, %eax /* the adjusted stack pointer */
15545 pushl_cfi $__KERNEL_DS
15546 @@ -813,7 +1072,7 @@ vector=vector+1
15547 .endr
15548 2: jmp common_interrupt
15549 .endr
15550 -END(irq_entries_start)
15551 +ENDPROC(irq_entries_start)
15552
15553 .previous
15554 END(interrupt)
15555 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15556 pushl_cfi $do_coprocessor_error
15557 jmp error_code
15558 CFI_ENDPROC
15559 -END(coprocessor_error)
15560 +ENDPROC(coprocessor_error)
15561
15562 ENTRY(simd_coprocessor_error)
15563 RING0_INT_FRAME
15564 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15565 #endif
15566 jmp error_code
15567 CFI_ENDPROC
15568 -END(simd_coprocessor_error)
15569 +ENDPROC(simd_coprocessor_error)
15570
15571 ENTRY(device_not_available)
15572 RING0_INT_FRAME
15573 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15574 pushl_cfi $do_device_not_available
15575 jmp error_code
15576 CFI_ENDPROC
15577 -END(device_not_available)
15578 +ENDPROC(device_not_available)
15579
15580 #ifdef CONFIG_PARAVIRT
15581 ENTRY(native_iret)
15582 iret
15583 _ASM_EXTABLE(native_iret, iret_exc)
15584 -END(native_iret)
15585 +ENDPROC(native_iret)
15586
15587 ENTRY(native_irq_enable_sysexit)
15588 sti
15589 sysexit
15590 -END(native_irq_enable_sysexit)
15591 +ENDPROC(native_irq_enable_sysexit)
15592 #endif
15593
15594 ENTRY(overflow)
15595 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15596 pushl_cfi $do_overflow
15597 jmp error_code
15598 CFI_ENDPROC
15599 -END(overflow)
15600 +ENDPROC(overflow)
15601
15602 ENTRY(bounds)
15603 RING0_INT_FRAME
15604 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15605 pushl_cfi $do_bounds
15606 jmp error_code
15607 CFI_ENDPROC
15608 -END(bounds)
15609 +ENDPROC(bounds)
15610
15611 ENTRY(invalid_op)
15612 RING0_INT_FRAME
15613 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15614 pushl_cfi $do_invalid_op
15615 jmp error_code
15616 CFI_ENDPROC
15617 -END(invalid_op)
15618 +ENDPROC(invalid_op)
15619
15620 ENTRY(coprocessor_segment_overrun)
15621 RING0_INT_FRAME
15622 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15623 pushl_cfi $do_coprocessor_segment_overrun
15624 jmp error_code
15625 CFI_ENDPROC
15626 -END(coprocessor_segment_overrun)
15627 +ENDPROC(coprocessor_segment_overrun)
15628
15629 ENTRY(invalid_TSS)
15630 RING0_EC_FRAME
15631 pushl_cfi $do_invalid_TSS
15632 jmp error_code
15633 CFI_ENDPROC
15634 -END(invalid_TSS)
15635 +ENDPROC(invalid_TSS)
15636
15637 ENTRY(segment_not_present)
15638 RING0_EC_FRAME
15639 pushl_cfi $do_segment_not_present
15640 jmp error_code
15641 CFI_ENDPROC
15642 -END(segment_not_present)
15643 +ENDPROC(segment_not_present)
15644
15645 ENTRY(stack_segment)
15646 RING0_EC_FRAME
15647 pushl_cfi $do_stack_segment
15648 jmp error_code
15649 CFI_ENDPROC
15650 -END(stack_segment)
15651 +ENDPROC(stack_segment)
15652
15653 ENTRY(alignment_check)
15654 RING0_EC_FRAME
15655 pushl_cfi $do_alignment_check
15656 jmp error_code
15657 CFI_ENDPROC
15658 -END(alignment_check)
15659 +ENDPROC(alignment_check)
15660
15661 ENTRY(divide_error)
15662 RING0_INT_FRAME
15663 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15664 pushl_cfi $do_divide_error
15665 jmp error_code
15666 CFI_ENDPROC
15667 -END(divide_error)
15668 +ENDPROC(divide_error)
15669
15670 #ifdef CONFIG_X86_MCE
15671 ENTRY(machine_check)
15672 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15673 pushl_cfi machine_check_vector
15674 jmp error_code
15675 CFI_ENDPROC
15676 -END(machine_check)
15677 +ENDPROC(machine_check)
15678 #endif
15679
15680 ENTRY(spurious_interrupt_bug)
15681 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15682 pushl_cfi $do_spurious_interrupt_bug
15683 jmp error_code
15684 CFI_ENDPROC
15685 -END(spurious_interrupt_bug)
15686 +ENDPROC(spurious_interrupt_bug)
15687 /*
15688 * End of kprobes section
15689 */
15690 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15691
15692 ENTRY(mcount)
15693 ret
15694 -END(mcount)
15695 +ENDPROC(mcount)
15696
15697 ENTRY(ftrace_caller)
15698 cmpl $0, function_trace_stop
15699 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15700 .globl ftrace_stub
15701 ftrace_stub:
15702 ret
15703 -END(ftrace_caller)
15704 +ENDPROC(ftrace_caller)
15705
15706 #else /* ! CONFIG_DYNAMIC_FTRACE */
15707
15708 @@ -1167,7 +1426,7 @@ trace:
15709 popl %ecx
15710 popl %eax
15711 jmp ftrace_stub
15712 -END(mcount)
15713 +ENDPROC(mcount)
15714 #endif /* CONFIG_DYNAMIC_FTRACE */
15715 #endif /* CONFIG_FUNCTION_TRACER */
15716
15717 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15718 popl %ecx
15719 popl %eax
15720 ret
15721 -END(ftrace_graph_caller)
15722 +ENDPROC(ftrace_graph_caller)
15723
15724 .globl return_to_handler
15725 return_to_handler:
15726 @@ -1243,15 +1502,18 @@ error_code:
15727 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15728 REG_TO_PTGS %ecx
15729 SET_KERNEL_GS %ecx
15730 - movl $(__USER_DS), %ecx
15731 + movl $(__KERNEL_DS), %ecx
15732 movl %ecx, %ds
15733 movl %ecx, %es
15734 +
15735 + pax_enter_kernel
15736 +
15737 TRACE_IRQS_OFF
15738 movl %esp,%eax # pt_regs pointer
15739 call *%edi
15740 jmp ret_from_exception
15741 CFI_ENDPROC
15742 -END(page_fault)
15743 +ENDPROC(page_fault)
15744
15745 /*
15746 * Debug traps and NMI can happen at the one SYSENTER instruction
15747 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15748 call do_debug
15749 jmp ret_from_exception
15750 CFI_ENDPROC
15751 -END(debug)
15752 +ENDPROC(debug)
15753
15754 /*
15755 * NMI is doubly nasty. It can happen _while_ we're handling
15756 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15757 xorl %edx,%edx # zero error code
15758 movl %esp,%eax # pt_regs pointer
15759 call do_nmi
15760 +
15761 + pax_exit_kernel
15762 +
15763 jmp restore_all_notrace
15764 CFI_ENDPROC
15765
15766 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15767 FIXUP_ESPFIX_STACK # %eax == %esp
15768 xorl %edx,%edx # zero error code
15769 call do_nmi
15770 +
15771 + pax_exit_kernel
15772 +
15773 RESTORE_REGS
15774 lss 12+4(%esp), %esp # back to espfix stack
15775 CFI_ADJUST_CFA_OFFSET -24
15776 jmp irq_return
15777 CFI_ENDPROC
15778 -END(nmi)
15779 +ENDPROC(nmi)
15780
15781 ENTRY(int3)
15782 RING0_INT_FRAME
15783 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15784 call do_int3
15785 jmp ret_from_exception
15786 CFI_ENDPROC
15787 -END(int3)
15788 +ENDPROC(int3)
15789
15790 ENTRY(general_protection)
15791 RING0_EC_FRAME
15792 pushl_cfi $do_general_protection
15793 jmp error_code
15794 CFI_ENDPROC
15795 -END(general_protection)
15796 +ENDPROC(general_protection)
15797
15798 #ifdef CONFIG_KVM_GUEST
15799 ENTRY(async_page_fault)
15800 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15801 pushl_cfi $do_async_page_fault
15802 jmp error_code
15803 CFI_ENDPROC
15804 -END(async_page_fault)
15805 +ENDPROC(async_page_fault)
15806 #endif
15807
15808 /*
15809 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15810 index dcdd0ea..8f32835 100644
15811 --- a/arch/x86/kernel/entry_64.S
15812 +++ b/arch/x86/kernel/entry_64.S
15813 @@ -57,6 +57,8 @@
15814 #include <asm/percpu.h>
15815 #include <asm/asm.h>
15816 #include <linux/err.h>
15817 +#include <asm/pgtable.h>
15818 +#include <asm/alternative-asm.h>
15819
15820 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15821 #include <linux/elf-em.h>
15822 @@ -70,8 +72,9 @@
15823 #ifdef CONFIG_FUNCTION_TRACER
15824 #ifdef CONFIG_DYNAMIC_FTRACE
15825 ENTRY(mcount)
15826 + pax_force_retaddr
15827 retq
15828 -END(mcount)
15829 +ENDPROC(mcount)
15830
15831 ENTRY(ftrace_caller)
15832 cmpl $0, function_trace_stop
15833 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15834 #endif
15835
15836 GLOBAL(ftrace_stub)
15837 + pax_force_retaddr
15838 retq
15839 -END(ftrace_caller)
15840 +ENDPROC(ftrace_caller)
15841
15842 #else /* ! CONFIG_DYNAMIC_FTRACE */
15843 ENTRY(mcount)
15844 @@ -114,6 +118,7 @@ ENTRY(mcount)
15845 #endif
15846
15847 GLOBAL(ftrace_stub)
15848 + pax_force_retaddr
15849 retq
15850
15851 trace:
15852 @@ -123,12 +128,13 @@ trace:
15853 movq 8(%rbp), %rsi
15854 subq $MCOUNT_INSN_SIZE, %rdi
15855
15856 + pax_force_fptr ftrace_trace_function
15857 call *ftrace_trace_function
15858
15859 MCOUNT_RESTORE_FRAME
15860
15861 jmp ftrace_stub
15862 -END(mcount)
15863 +ENDPROC(mcount)
15864 #endif /* CONFIG_DYNAMIC_FTRACE */
15865 #endif /* CONFIG_FUNCTION_TRACER */
15866
15867 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15868
15869 MCOUNT_RESTORE_FRAME
15870
15871 + pax_force_retaddr
15872 retq
15873 -END(ftrace_graph_caller)
15874 +ENDPROC(ftrace_graph_caller)
15875
15876 GLOBAL(return_to_handler)
15877 subq $24, %rsp
15878 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15879 movq 8(%rsp), %rdx
15880 movq (%rsp), %rax
15881 addq $24, %rsp
15882 + pax_force_fptr %rdi
15883 jmp *%rdi
15884 #endif
15885
15886 @@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15887 ENDPROC(native_usergs_sysret64)
15888 #endif /* CONFIG_PARAVIRT */
15889
15890 + .macro ljmpq sel, off
15891 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15892 + .byte 0x48; ljmp *1234f(%rip)
15893 + .pushsection .rodata
15894 + .align 16
15895 + 1234: .quad \off; .word \sel
15896 + .popsection
15897 +#else
15898 + pushq $\sel
15899 + pushq $\off
15900 + lretq
15901 +#endif
15902 + .endm
15903 +
15904 + .macro pax_enter_kernel
15905 + pax_set_fptr_mask
15906 +#ifdef CONFIG_PAX_KERNEXEC
15907 + call pax_enter_kernel
15908 +#endif
15909 + .endm
15910 +
15911 + .macro pax_exit_kernel
15912 +#ifdef CONFIG_PAX_KERNEXEC
15913 + call pax_exit_kernel
15914 +#endif
15915 + .endm
15916 +
15917 +#ifdef CONFIG_PAX_KERNEXEC
15918 +ENTRY(pax_enter_kernel)
15919 + pushq %rdi
15920 +
15921 +#ifdef CONFIG_PARAVIRT
15922 + PV_SAVE_REGS(CLBR_RDI)
15923 +#endif
15924 +
15925 + GET_CR0_INTO_RDI
15926 + bts $16,%rdi
15927 + jnc 3f
15928 + mov %cs,%edi
15929 + cmp $__KERNEL_CS,%edi
15930 + jnz 2f
15931 +1:
15932 +
15933 +#ifdef CONFIG_PARAVIRT
15934 + PV_RESTORE_REGS(CLBR_RDI)
15935 +#endif
15936 +
15937 + popq %rdi
15938 + pax_force_retaddr
15939 + retq
15940 +
15941 +2: ljmpq __KERNEL_CS,1f
15942 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15943 +4: SET_RDI_INTO_CR0
15944 + jmp 1b
15945 +ENDPROC(pax_enter_kernel)
15946 +
15947 +ENTRY(pax_exit_kernel)
15948 + pushq %rdi
15949 +
15950 +#ifdef CONFIG_PARAVIRT
15951 + PV_SAVE_REGS(CLBR_RDI)
15952 +#endif
15953 +
15954 + mov %cs,%rdi
15955 + cmp $__KERNEXEC_KERNEL_CS,%edi
15956 + jz 2f
15957 +1:
15958 +
15959 +#ifdef CONFIG_PARAVIRT
15960 + PV_RESTORE_REGS(CLBR_RDI);
15961 +#endif
15962 +
15963 + popq %rdi
15964 + pax_force_retaddr
15965 + retq
15966 +
15967 +2: GET_CR0_INTO_RDI
15968 + btr $16,%rdi
15969 + ljmpq __KERNEL_CS,3f
15970 +3: SET_RDI_INTO_CR0
15971 + jmp 1b
15972 +ENDPROC(pax_exit_kernel)
15973 +#endif
15974 +
15975 + .macro pax_enter_kernel_user
15976 + pax_set_fptr_mask
15977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15978 + call pax_enter_kernel_user
15979 +#endif
15980 + .endm
15981 +
15982 + .macro pax_exit_kernel_user
15983 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15984 + call pax_exit_kernel_user
15985 +#endif
15986 +#ifdef CONFIG_PAX_RANDKSTACK
15987 + pushq %rax
15988 + call pax_randomize_kstack
15989 + popq %rax
15990 +#endif
15991 + .endm
15992 +
15993 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15994 +ENTRY(pax_enter_kernel_user)
15995 + pushq %rdi
15996 + pushq %rbx
15997 +
15998 +#ifdef CONFIG_PARAVIRT
15999 + PV_SAVE_REGS(CLBR_RDI)
16000 +#endif
16001 +
16002 + GET_CR3_INTO_RDI
16003 + mov %rdi,%rbx
16004 + add $__START_KERNEL_map,%rbx
16005 + sub phys_base(%rip),%rbx
16006 +
16007 +#ifdef CONFIG_PARAVIRT
16008 + pushq %rdi
16009 + cmpl $0, pv_info+PARAVIRT_enabled
16010 + jz 1f
16011 + i = 0
16012 + .rept USER_PGD_PTRS
16013 + mov i*8(%rbx),%rsi
16014 + mov $0,%sil
16015 + lea i*8(%rbx),%rdi
16016 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16017 + i = i + 1
16018 + .endr
16019 + jmp 2f
16020 +1:
16021 +#endif
16022 +
16023 + i = 0
16024 + .rept USER_PGD_PTRS
16025 + movb $0,i*8(%rbx)
16026 + i = i + 1
16027 + .endr
16028 +
16029 +#ifdef CONFIG_PARAVIRT
16030 +2: popq %rdi
16031 +#endif
16032 + SET_RDI_INTO_CR3
16033 +
16034 +#ifdef CONFIG_PAX_KERNEXEC
16035 + GET_CR0_INTO_RDI
16036 + bts $16,%rdi
16037 + SET_RDI_INTO_CR0
16038 +#endif
16039 +
16040 +#ifdef CONFIG_PARAVIRT
16041 + PV_RESTORE_REGS(CLBR_RDI)
16042 +#endif
16043 +
16044 + popq %rbx
16045 + popq %rdi
16046 + pax_force_retaddr
16047 + retq
16048 +ENDPROC(pax_enter_kernel_user)
16049 +
16050 +ENTRY(pax_exit_kernel_user)
16051 + push %rdi
16052 +
16053 +#ifdef CONFIG_PARAVIRT
16054 + pushq %rbx
16055 + PV_SAVE_REGS(CLBR_RDI)
16056 +#endif
16057 +
16058 +#ifdef CONFIG_PAX_KERNEXEC
16059 + GET_CR0_INTO_RDI
16060 + btr $16,%rdi
16061 + SET_RDI_INTO_CR0
16062 +#endif
16063 +
16064 + GET_CR3_INTO_RDI
16065 + add $__START_KERNEL_map,%rdi
16066 + sub phys_base(%rip),%rdi
16067 +
16068 +#ifdef CONFIG_PARAVIRT
16069 + cmpl $0, pv_info+PARAVIRT_enabled
16070 + jz 1f
16071 + mov %rdi,%rbx
16072 + i = 0
16073 + .rept USER_PGD_PTRS
16074 + mov i*8(%rbx),%rsi
16075 + mov $0x67,%sil
16076 + lea i*8(%rbx),%rdi
16077 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16078 + i = i + 1
16079 + .endr
16080 + jmp 2f
16081 +1:
16082 +#endif
16083 +
16084 + i = 0
16085 + .rept USER_PGD_PTRS
16086 + movb $0x67,i*8(%rdi)
16087 + i = i + 1
16088 + .endr
16089 +
16090 +#ifdef CONFIG_PARAVIRT
16091 +2: PV_RESTORE_REGS(CLBR_RDI)
16092 + popq %rbx
16093 +#endif
16094 +
16095 + popq %rdi
16096 + pax_force_retaddr
16097 + retq
16098 +ENDPROC(pax_exit_kernel_user)
16099 +#endif
16100 +
16101 +.macro pax_erase_kstack
16102 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16103 + call pax_erase_kstack
16104 +#endif
16105 +.endm
16106 +
16107 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16108 +ENTRY(pax_erase_kstack)
16109 + pushq %rdi
16110 + pushq %rcx
16111 + pushq %rax
16112 + pushq %r11
16113 +
16114 + GET_THREAD_INFO(%r11)
16115 + mov TI_lowest_stack(%r11), %rdi
16116 + mov $-0xBEEF, %rax
16117 + std
16118 +
16119 +1: mov %edi, %ecx
16120 + and $THREAD_SIZE_asm - 1, %ecx
16121 + shr $3, %ecx
16122 + repne scasq
16123 + jecxz 2f
16124 +
16125 + cmp $2*8, %ecx
16126 + jc 2f
16127 +
16128 + mov $2*8, %ecx
16129 + repe scasq
16130 + jecxz 2f
16131 + jne 1b
16132 +
16133 +2: cld
16134 + mov %esp, %ecx
16135 + sub %edi, %ecx
16136 +
16137 + cmp $THREAD_SIZE_asm, %rcx
16138 + jb 3f
16139 + ud2
16140 +3:
16141 +
16142 + shr $3, %ecx
16143 + rep stosq
16144 +
16145 + mov TI_task_thread_sp0(%r11), %rdi
16146 + sub $256, %rdi
16147 + mov %rdi, TI_lowest_stack(%r11)
16148 +
16149 + popq %r11
16150 + popq %rax
16151 + popq %rcx
16152 + popq %rdi
16153 + pax_force_retaddr
16154 + ret
16155 +ENDPROC(pax_erase_kstack)
16156 +#endif
16157
16158 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16159 #ifdef CONFIG_TRACE_IRQFLAGS
16160 @@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16161 .endm
16162
16163 .macro UNFAKE_STACK_FRAME
16164 - addq $8*6, %rsp
16165 - CFI_ADJUST_CFA_OFFSET -(6*8)
16166 + addq $8*6 + ARG_SKIP, %rsp
16167 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16168 .endm
16169
16170 /*
16171 @@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16172 movq %rsp, %rsi
16173
16174 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16175 - testl $3, CS-RBP(%rsi)
16176 + testb $3, CS-RBP(%rsi)
16177 je 1f
16178 SWAPGS
16179 /*
16180 @@ -394,9 +669,10 @@ ENTRY(save_rest)
16181 movq_cfi r15, R15+16
16182 movq %r11, 8(%rsp) /* return address */
16183 FIXUP_TOP_OF_STACK %r11, 16
16184 + pax_force_retaddr
16185 ret
16186 CFI_ENDPROC
16187 -END(save_rest)
16188 +ENDPROC(save_rest)
16189
16190 /* save complete stack frame */
16191 .pushsection .kprobes.text, "ax"
16192 @@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16193 js 1f /* negative -> in kernel */
16194 SWAPGS
16195 xorl %ebx,%ebx
16196 -1: ret
16197 +1: pax_force_retaddr_bts
16198 + ret
16199 CFI_ENDPROC
16200 -END(save_paranoid)
16201 +ENDPROC(save_paranoid)
16202 .popsection
16203
16204 /*
16205 @@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16206
16207 RESTORE_REST
16208
16209 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16210 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16211 jz retint_restore_args
16212
16213 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16214 @@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16215 jmp ret_from_sys_call # go to the SYSRET fastpath
16216
16217 CFI_ENDPROC
16218 -END(ret_from_fork)
16219 +ENDPROC(ret_from_fork)
16220
16221 /*
16222 * System call entry. Up to 6 arguments in registers are supported.
16223 @@ -495,7 +772,7 @@ END(ret_from_fork)
16224 ENTRY(system_call)
16225 CFI_STARTPROC simple
16226 CFI_SIGNAL_FRAME
16227 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16228 + CFI_DEF_CFA rsp,0
16229 CFI_REGISTER rip,rcx
16230 /*CFI_REGISTER rflags,r11*/
16231 SWAPGS_UNSAFE_STACK
16232 @@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16233
16234 movq %rsp,PER_CPU_VAR(old_rsp)
16235 movq PER_CPU_VAR(kernel_stack),%rsp
16236 + SAVE_ARGS 8*6,0
16237 + pax_enter_kernel_user
16238 +
16239 +#ifdef CONFIG_PAX_RANDKSTACK
16240 + pax_erase_kstack
16241 +#endif
16242 +
16243 /*
16244 * No need to follow this irqs off/on section - it's straight
16245 * and short:
16246 */
16247 ENABLE_INTERRUPTS(CLBR_NONE)
16248 - SAVE_ARGS 8,0
16249 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16250 movq %rcx,RIP-ARGOFFSET(%rsp)
16251 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16252 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16253 + GET_THREAD_INFO(%rcx)
16254 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16255 jnz tracesys
16256 system_call_fastpath:
16257 #if __SYSCALL_MASK == ~0
16258 @@ -527,7 +811,7 @@ system_call_fastpath:
16259 cmpl $__NR_syscall_max,%eax
16260 #endif
16261 ja badsys
16262 - movq %r10,%rcx
16263 + movq R10-ARGOFFSET(%rsp),%rcx
16264 call *sys_call_table(,%rax,8) # XXX: rip relative
16265 movq %rax,RAX-ARGOFFSET(%rsp)
16266 /*
16267 @@ -541,10 +825,13 @@ sysret_check:
16268 LOCKDEP_SYS_EXIT
16269 DISABLE_INTERRUPTS(CLBR_NONE)
16270 TRACE_IRQS_OFF
16271 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16272 + GET_THREAD_INFO(%rcx)
16273 + movl TI_flags(%rcx),%edx
16274 andl %edi,%edx
16275 jnz sysret_careful
16276 CFI_REMEMBER_STATE
16277 + pax_exit_kernel_user
16278 + pax_erase_kstack
16279 /*
16280 * sysretq will re-enable interrupts:
16281 */
16282 @@ -596,14 +883,18 @@ badsys:
16283 * jump back to the normal fast path.
16284 */
16285 auditsys:
16286 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16287 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16288 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16289 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16290 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16291 movq %rax,%rsi /* 2nd arg: syscall number */
16292 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16293 call __audit_syscall_entry
16294 +
16295 + pax_erase_kstack
16296 +
16297 LOAD_ARGS 0 /* reload call-clobbered registers */
16298 + pax_set_fptr_mask
16299 jmp system_call_fastpath
16300
16301 /*
16302 @@ -624,7 +915,7 @@ sysret_audit:
16303 /* Do syscall tracing */
16304 tracesys:
16305 #ifdef CONFIG_AUDITSYSCALL
16306 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16307 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16308 jz auditsys
16309 #endif
16310 SAVE_REST
16311 @@ -632,12 +923,16 @@ tracesys:
16312 FIXUP_TOP_OF_STACK %rdi
16313 movq %rsp,%rdi
16314 call syscall_trace_enter
16315 +
16316 + pax_erase_kstack
16317 +
16318 /*
16319 * Reload arg registers from stack in case ptrace changed them.
16320 * We don't reload %rax because syscall_trace_enter() returned
16321 * the value it wants us to use in the table lookup.
16322 */
16323 LOAD_ARGS ARGOFFSET, 1
16324 + pax_set_fptr_mask
16325 RESTORE_REST
16326 #if __SYSCALL_MASK == ~0
16327 cmpq $__NR_syscall_max,%rax
16328 @@ -646,7 +941,7 @@ tracesys:
16329 cmpl $__NR_syscall_max,%eax
16330 #endif
16331 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16332 - movq %r10,%rcx /* fixup for C */
16333 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16334 call *sys_call_table(,%rax,8)
16335 movq %rax,RAX-ARGOFFSET(%rsp)
16336 /* Use IRET because user could have changed frame */
16337 @@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16338 andl %edi,%edx
16339 jnz int_careful
16340 andl $~TS_COMPAT,TI_status(%rcx)
16341 - jmp retint_swapgs
16342 + pax_exit_kernel_user
16343 + pax_erase_kstack
16344 + jmp retint_swapgs_pax
16345
16346 /* Either reschedule or signal or syscall exit tracking needed. */
16347 /* First do a reschedule test. */
16348 @@ -713,7 +1010,7 @@ int_restore_rest:
16349 TRACE_IRQS_OFF
16350 jmp int_with_check
16351 CFI_ENDPROC
16352 -END(system_call)
16353 +ENDPROC(system_call)
16354
16355 /*
16356 * Certain special system calls that need to save a complete full stack frame.
16357 @@ -729,7 +1026,7 @@ ENTRY(\label)
16358 call \func
16359 jmp ptregscall_common
16360 CFI_ENDPROC
16361 -END(\label)
16362 +ENDPROC(\label)
16363 .endm
16364
16365 PTREGSCALL stub_clone, sys_clone, %r8
16366 @@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16367 movq_cfi_restore R12+8, r12
16368 movq_cfi_restore RBP+8, rbp
16369 movq_cfi_restore RBX+8, rbx
16370 + pax_force_retaddr
16371 ret $REST_SKIP /* pop extended registers */
16372 CFI_ENDPROC
16373 -END(ptregscall_common)
16374 +ENDPROC(ptregscall_common)
16375
16376 ENTRY(stub_execve)
16377 CFI_STARTPROC
16378 @@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16379 RESTORE_REST
16380 jmp int_ret_from_sys_call
16381 CFI_ENDPROC
16382 -END(stub_execve)
16383 +ENDPROC(stub_execve)
16384
16385 /*
16386 * sigreturn is special because it needs to restore all registers on return.
16387 @@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16388 RESTORE_REST
16389 jmp int_ret_from_sys_call
16390 CFI_ENDPROC
16391 -END(stub_rt_sigreturn)
16392 +ENDPROC(stub_rt_sigreturn)
16393
16394 #ifdef CONFIG_X86_X32_ABI
16395 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16396 @@ -851,7 +1149,7 @@ vector=vector+1
16397 2: jmp common_interrupt
16398 .endr
16399 CFI_ENDPROC
16400 -END(irq_entries_start)
16401 +ENDPROC(irq_entries_start)
16402
16403 .previous
16404 END(interrupt)
16405 @@ -871,6 +1169,16 @@ END(interrupt)
16406 subq $ORIG_RAX-RBP, %rsp
16407 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16408 SAVE_ARGS_IRQ
16409 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16410 + testb $3, CS(%rdi)
16411 + jnz 1f
16412 + pax_enter_kernel
16413 + jmp 2f
16414 +1: pax_enter_kernel_user
16415 +2:
16416 +#else
16417 + pax_enter_kernel
16418 +#endif
16419 call \func
16420 .endm
16421
16422 @@ -902,7 +1210,7 @@ ret_from_intr:
16423
16424 exit_intr:
16425 GET_THREAD_INFO(%rcx)
16426 - testl $3,CS-ARGOFFSET(%rsp)
16427 + testb $3,CS-ARGOFFSET(%rsp)
16428 je retint_kernel
16429
16430 /* Interrupt came from user space */
16431 @@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16432 * The iretq could re-enable interrupts:
16433 */
16434 DISABLE_INTERRUPTS(CLBR_ANY)
16435 + pax_exit_kernel_user
16436 +retint_swapgs_pax:
16437 TRACE_IRQS_IRETQ
16438 SWAPGS
16439 jmp restore_args
16440
16441 retint_restore_args: /* return to kernel space */
16442 DISABLE_INTERRUPTS(CLBR_ANY)
16443 + pax_exit_kernel
16444 + pax_force_retaddr RIP-ARGOFFSET
16445 /*
16446 * The iretq could re-enable interrupts:
16447 */
16448 @@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16449 #endif
16450
16451 CFI_ENDPROC
16452 -END(common_interrupt)
16453 +ENDPROC(common_interrupt)
16454 /*
16455 * End of kprobes section
16456 */
16457 @@ -1029,7 +1341,7 @@ ENTRY(\sym)
16458 interrupt \do_sym
16459 jmp ret_from_intr
16460 CFI_ENDPROC
16461 -END(\sym)
16462 +ENDPROC(\sym)
16463 .endm
16464
16465 #ifdef CONFIG_SMP
16466 @@ -1084,12 +1396,22 @@ ENTRY(\sym)
16467 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16468 call error_entry
16469 DEFAULT_FRAME 0
16470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16471 + testb $3, CS(%rsp)
16472 + jnz 1f
16473 + pax_enter_kernel
16474 + jmp 2f
16475 +1: pax_enter_kernel_user
16476 +2:
16477 +#else
16478 + pax_enter_kernel
16479 +#endif
16480 movq %rsp,%rdi /* pt_regs pointer */
16481 xorl %esi,%esi /* no error code */
16482 call \do_sym
16483 jmp error_exit /* %ebx: no swapgs flag */
16484 CFI_ENDPROC
16485 -END(\sym)
16486 +ENDPROC(\sym)
16487 .endm
16488
16489 .macro paranoidzeroentry sym do_sym
16490 @@ -1101,15 +1423,25 @@ ENTRY(\sym)
16491 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16492 call save_paranoid
16493 TRACE_IRQS_OFF
16494 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16495 + testb $3, CS(%rsp)
16496 + jnz 1f
16497 + pax_enter_kernel
16498 + jmp 2f
16499 +1: pax_enter_kernel_user
16500 +2:
16501 +#else
16502 + pax_enter_kernel
16503 +#endif
16504 movq %rsp,%rdi /* pt_regs pointer */
16505 xorl %esi,%esi /* no error code */
16506 call \do_sym
16507 jmp paranoid_exit /* %ebx: no swapgs flag */
16508 CFI_ENDPROC
16509 -END(\sym)
16510 +ENDPROC(\sym)
16511 .endm
16512
16513 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16514 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16515 .macro paranoidzeroentry_ist sym do_sym ist
16516 ENTRY(\sym)
16517 INTR_FRAME
16518 @@ -1119,14 +1451,30 @@ ENTRY(\sym)
16519 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16520 call save_paranoid
16521 TRACE_IRQS_OFF_DEBUG
16522 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16523 + testb $3, CS(%rsp)
16524 + jnz 1f
16525 + pax_enter_kernel
16526 + jmp 2f
16527 +1: pax_enter_kernel_user
16528 +2:
16529 +#else
16530 + pax_enter_kernel
16531 +#endif
16532 movq %rsp,%rdi /* pt_regs pointer */
16533 xorl %esi,%esi /* no error code */
16534 +#ifdef CONFIG_SMP
16535 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16536 + lea init_tss(%r12), %r12
16537 +#else
16538 + lea init_tss(%rip), %r12
16539 +#endif
16540 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16541 call \do_sym
16542 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16543 jmp paranoid_exit /* %ebx: no swapgs flag */
16544 CFI_ENDPROC
16545 -END(\sym)
16546 +ENDPROC(\sym)
16547 .endm
16548
16549 .macro errorentry sym do_sym
16550 @@ -1137,13 +1485,23 @@ ENTRY(\sym)
16551 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16552 call error_entry
16553 DEFAULT_FRAME 0
16554 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16555 + testb $3, CS(%rsp)
16556 + jnz 1f
16557 + pax_enter_kernel
16558 + jmp 2f
16559 +1: pax_enter_kernel_user
16560 +2:
16561 +#else
16562 + pax_enter_kernel
16563 +#endif
16564 movq %rsp,%rdi /* pt_regs pointer */
16565 movq ORIG_RAX(%rsp),%rsi /* get error code */
16566 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16567 call \do_sym
16568 jmp error_exit /* %ebx: no swapgs flag */
16569 CFI_ENDPROC
16570 -END(\sym)
16571 +ENDPROC(\sym)
16572 .endm
16573
16574 /* error code is on the stack already */
16575 @@ -1156,13 +1514,23 @@ ENTRY(\sym)
16576 call save_paranoid
16577 DEFAULT_FRAME 0
16578 TRACE_IRQS_OFF
16579 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16580 + testb $3, CS(%rsp)
16581 + jnz 1f
16582 + pax_enter_kernel
16583 + jmp 2f
16584 +1: pax_enter_kernel_user
16585 +2:
16586 +#else
16587 + pax_enter_kernel
16588 +#endif
16589 movq %rsp,%rdi /* pt_regs pointer */
16590 movq ORIG_RAX(%rsp),%rsi /* get error code */
16591 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16592 call \do_sym
16593 jmp paranoid_exit /* %ebx: no swapgs flag */
16594 CFI_ENDPROC
16595 -END(\sym)
16596 +ENDPROC(\sym)
16597 .endm
16598
16599 zeroentry divide_error do_divide_error
16600 @@ -1192,9 +1560,10 @@ gs_change:
16601 2: mfence /* workaround */
16602 SWAPGS
16603 popfq_cfi
16604 + pax_force_retaddr
16605 ret
16606 CFI_ENDPROC
16607 -END(native_load_gs_index)
16608 +ENDPROC(native_load_gs_index)
16609
16610 _ASM_EXTABLE(gs_change,bad_gs)
16611 .section .fixup,"ax"
16612 @@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16613 * Here we are in the child and the registers are set as they were
16614 * at kernel_thread() invocation in the parent.
16615 */
16616 + pax_force_fptr %rsi
16617 call *%rsi
16618 # exit
16619 mov %eax, %edi
16620 call do_exit
16621 ud2 # padding for call trace
16622 CFI_ENDPROC
16623 -END(kernel_thread_helper)
16624 +ENDPROC(kernel_thread_helper)
16625
16626 /*
16627 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16628 @@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16629 RESTORE_REST
16630 testq %rax,%rax
16631 je int_ret_from_sys_call
16632 - RESTORE_ARGS
16633 UNFAKE_STACK_FRAME
16634 + pax_force_retaddr
16635 ret
16636 CFI_ENDPROC
16637 -END(kernel_execve)
16638 +ENDPROC(kernel_execve)
16639
16640 /* Call softirq on interrupt stack. Interrupts are off. */
16641 ENTRY(call_softirq)
16642 @@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16643 CFI_DEF_CFA_REGISTER rsp
16644 CFI_ADJUST_CFA_OFFSET -8
16645 decl PER_CPU_VAR(irq_count)
16646 + pax_force_retaddr
16647 ret
16648 CFI_ENDPROC
16649 -END(call_softirq)
16650 +ENDPROC(call_softirq)
16651
16652 #ifdef CONFIG_XEN
16653 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16654 @@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16655 decl PER_CPU_VAR(irq_count)
16656 jmp error_exit
16657 CFI_ENDPROC
16658 -END(xen_do_hypervisor_callback)
16659 +ENDPROC(xen_do_hypervisor_callback)
16660
16661 /*
16662 * Hypervisor uses this for application faults while it executes.
16663 @@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16664 SAVE_ALL
16665 jmp error_exit
16666 CFI_ENDPROC
16667 -END(xen_failsafe_callback)
16668 +ENDPROC(xen_failsafe_callback)
16669
16670 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16671 xen_hvm_callback_vector xen_evtchn_do_upcall
16672 @@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16673 TRACE_IRQS_OFF_DEBUG
16674 testl %ebx,%ebx /* swapgs needed? */
16675 jnz paranoid_restore
16676 - testl $3,CS(%rsp)
16677 + testb $3,CS(%rsp)
16678 jnz paranoid_userspace
16679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16680 + pax_exit_kernel
16681 + TRACE_IRQS_IRETQ 0
16682 + SWAPGS_UNSAFE_STACK
16683 + RESTORE_ALL 8
16684 + pax_force_retaddr_bts
16685 + jmp irq_return
16686 +#endif
16687 paranoid_swapgs:
16688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16689 + pax_exit_kernel_user
16690 +#else
16691 + pax_exit_kernel
16692 +#endif
16693 TRACE_IRQS_IRETQ 0
16694 SWAPGS_UNSAFE_STACK
16695 RESTORE_ALL 8
16696 jmp irq_return
16697 paranoid_restore:
16698 + pax_exit_kernel
16699 TRACE_IRQS_IRETQ_DEBUG 0
16700 RESTORE_ALL 8
16701 + pax_force_retaddr_bts
16702 jmp irq_return
16703 paranoid_userspace:
16704 GET_THREAD_INFO(%rcx)
16705 @@ -1454,7 +1840,7 @@ paranoid_schedule:
16706 TRACE_IRQS_OFF
16707 jmp paranoid_userspace
16708 CFI_ENDPROC
16709 -END(paranoid_exit)
16710 +ENDPROC(paranoid_exit)
16711
16712 /*
16713 * Exception entry point. This expects an error code/orig_rax on the stack.
16714 @@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16715 movq_cfi r14, R14+8
16716 movq_cfi r15, R15+8
16717 xorl %ebx,%ebx
16718 - testl $3,CS+8(%rsp)
16719 + testb $3,CS+8(%rsp)
16720 je error_kernelspace
16721 error_swapgs:
16722 SWAPGS
16723 error_sti:
16724 TRACE_IRQS_OFF
16725 + pax_force_retaddr_bts
16726 ret
16727
16728 /*
16729 @@ -1513,7 +1900,7 @@ bstep_iret:
16730 movq %rcx,RIP+8(%rsp)
16731 jmp error_swapgs
16732 CFI_ENDPROC
16733 -END(error_entry)
16734 +ENDPROC(error_entry)
16735
16736
16737 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16738 @@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16739 jnz retint_careful
16740 jmp retint_swapgs
16741 CFI_ENDPROC
16742 -END(error_exit)
16743 +ENDPROC(error_exit)
16744
16745 /*
16746 * Test if a given stack is an NMI stack or not.
16747 @@ -1591,9 +1978,11 @@ ENTRY(nmi)
16748 * If %cs was not the kernel segment, then the NMI triggered in user
16749 * space, which means it is definitely not nested.
16750 */
16751 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16752 + je 1f
16753 cmpl $__KERNEL_CS, 16(%rsp)
16754 jne first_nmi
16755 -
16756 +1:
16757 /*
16758 * Check the special variable on the stack to see if NMIs are
16759 * executing.
16760 @@ -1752,6 +2141,17 @@ end_repeat_nmi:
16761 */
16762 movq %cr2, %r12
16763
16764 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16765 + testb $3, CS(%rsp)
16766 + jnz 1f
16767 + pax_enter_kernel
16768 + jmp 2f
16769 +1: pax_enter_kernel_user
16770 +2:
16771 +#else
16772 + pax_enter_kernel
16773 +#endif
16774 +
16775 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16776 movq %rsp,%rdi
16777 movq $-1,%rsi
16778 @@ -1767,21 +2167,32 @@ end_repeat_nmi:
16779 testl %ebx,%ebx /* swapgs needed? */
16780 jnz nmi_restore
16781 nmi_swapgs:
16782 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16783 + pax_exit_kernel_user
16784 +#else
16785 + pax_exit_kernel
16786 +#endif
16787 SWAPGS_UNSAFE_STACK
16788 + RESTORE_ALL 8
16789 + /* Clear the NMI executing stack variable */
16790 + movq $0, 10*8(%rsp)
16791 + jmp irq_return
16792 nmi_restore:
16793 + pax_exit_kernel
16794 RESTORE_ALL 8
16795 + pax_force_retaddr_bts
16796 /* Clear the NMI executing stack variable */
16797 movq $0, 10*8(%rsp)
16798 jmp irq_return
16799 CFI_ENDPROC
16800 -END(nmi)
16801 +ENDPROC(nmi)
16802
16803 ENTRY(ignore_sysret)
16804 CFI_STARTPROC
16805 mov $-ENOSYS,%eax
16806 sysret
16807 CFI_ENDPROC
16808 -END(ignore_sysret)
16809 +ENDPROC(ignore_sysret)
16810
16811 /*
16812 * End of kprobes section
16813 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16814 index c3a7cb4..3ad00dc 100644
16815 --- a/arch/x86/kernel/ftrace.c
16816 +++ b/arch/x86/kernel/ftrace.c
16817 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16818 {
16819 unsigned char replaced[MCOUNT_INSN_SIZE];
16820
16821 + ip = ktla_ktva(ip);
16822 +
16823 /*
16824 * Note: Due to modules and __init, code can
16825 * disappear and change, we need to protect against faulting
16826 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16827 unsigned char old[MCOUNT_INSN_SIZE], *new;
16828 int ret;
16829
16830 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16831 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16832 new = ftrace_call_replace(ip, (unsigned long)func);
16833
16834 /* See comment above by declaration of modifying_ftrace_code */
16835 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16836 {
16837 unsigned char code[MCOUNT_INSN_SIZE];
16838
16839 + ip = ktla_ktva(ip);
16840 +
16841 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16842 return -EFAULT;
16843
16844 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16845 index c18f59d..9c0c9f6 100644
16846 --- a/arch/x86/kernel/head32.c
16847 +++ b/arch/x86/kernel/head32.c
16848 @@ -18,6 +18,7 @@
16849 #include <asm/io_apic.h>
16850 #include <asm/bios_ebda.h>
16851 #include <asm/tlbflush.h>
16852 +#include <asm/boot.h>
16853
16854 static void __init i386_default_early_setup(void)
16855 {
16856 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16857
16858 void __init i386_start_kernel(void)
16859 {
16860 - memblock_reserve(__pa_symbol(&_text),
16861 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16862 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16863
16864 #ifdef CONFIG_BLK_DEV_INITRD
16865 /* Reserve INITRD */
16866 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16867 index d42ab17..87b9555 100644
16868 --- a/arch/x86/kernel/head_32.S
16869 +++ b/arch/x86/kernel/head_32.S
16870 @@ -26,6 +26,12 @@
16871 /* Physical address */
16872 #define pa(X) ((X) - __PAGE_OFFSET)
16873
16874 +#ifdef CONFIG_PAX_KERNEXEC
16875 +#define ta(X) (X)
16876 +#else
16877 +#define ta(X) ((X) - __PAGE_OFFSET)
16878 +#endif
16879 +
16880 /*
16881 * References to members of the new_cpu_data structure.
16882 */
16883 @@ -55,11 +61,7 @@
16884 * and small than max_low_pfn, otherwise will waste some page table entries
16885 */
16886
16887 -#if PTRS_PER_PMD > 1
16888 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16889 -#else
16890 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16891 -#endif
16892 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16893
16894 /* Number of possible pages in the lowmem region */
16895 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16896 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16897 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16898
16899 /*
16900 + * Real beginning of normal "text" segment
16901 + */
16902 +ENTRY(stext)
16903 +ENTRY(_stext)
16904 +
16905 +/*
16906 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16907 * %esi points to the real-mode code as a 32-bit pointer.
16908 * CS and DS must be 4 GB flat segments, but we don't depend on
16909 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16910 * can.
16911 */
16912 __HEAD
16913 +
16914 +#ifdef CONFIG_PAX_KERNEXEC
16915 + jmp startup_32
16916 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16917 +.fill PAGE_SIZE-5,1,0xcc
16918 +#endif
16919 +
16920 ENTRY(startup_32)
16921 movl pa(stack_start),%ecx
16922
16923 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16924 2:
16925 leal -__PAGE_OFFSET(%ecx),%esp
16926
16927 +#ifdef CONFIG_SMP
16928 + movl $pa(cpu_gdt_table),%edi
16929 + movl $__per_cpu_load,%eax
16930 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16931 + rorl $16,%eax
16932 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16933 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16934 + movl $__per_cpu_end - 1,%eax
16935 + subl $__per_cpu_start,%eax
16936 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16937 +#endif
16938 +
16939 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16940 + movl $NR_CPUS,%ecx
16941 + movl $pa(cpu_gdt_table),%edi
16942 +1:
16943 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16944 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16945 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16946 + addl $PAGE_SIZE_asm,%edi
16947 + loop 1b
16948 +#endif
16949 +
16950 +#ifdef CONFIG_PAX_KERNEXEC
16951 + movl $pa(boot_gdt),%edi
16952 + movl $__LOAD_PHYSICAL_ADDR,%eax
16953 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16954 + rorl $16,%eax
16955 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16956 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16957 + rorl $16,%eax
16958 +
16959 + ljmp $(__BOOT_CS),$1f
16960 +1:
16961 +
16962 + movl $NR_CPUS,%ecx
16963 + movl $pa(cpu_gdt_table),%edi
16964 + addl $__PAGE_OFFSET,%eax
16965 +1:
16966 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16967 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16968 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16969 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16970 + rorl $16,%eax
16971 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16972 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16973 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16974 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16975 + rorl $16,%eax
16976 + addl $PAGE_SIZE_asm,%edi
16977 + loop 1b
16978 +#endif
16979 +
16980 /*
16981 * Clear BSS first so that there are no surprises...
16982 */
16983 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16984 movl %eax, pa(max_pfn_mapped)
16985
16986 /* Do early initialization of the fixmap area */
16987 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16988 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16989 +#ifdef CONFIG_COMPAT_VDSO
16990 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16991 +#else
16992 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16993 +#endif
16994 #else /* Not PAE */
16995
16996 page_pde_offset = (__PAGE_OFFSET >> 20);
16997 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16998 movl %eax, pa(max_pfn_mapped)
16999
17000 /* Do early initialization of the fixmap area */
17001 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17002 - movl %eax,pa(initial_page_table+0xffc)
17003 +#ifdef CONFIG_COMPAT_VDSO
17004 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17005 +#else
17006 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17007 +#endif
17008 #endif
17009
17010 #ifdef CONFIG_PARAVIRT
17011 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17012 cmpl $num_subarch_entries, %eax
17013 jae bad_subarch
17014
17015 - movl pa(subarch_entries)(,%eax,4), %eax
17016 - subl $__PAGE_OFFSET, %eax
17017 - jmp *%eax
17018 + jmp *pa(subarch_entries)(,%eax,4)
17019
17020 bad_subarch:
17021 WEAK(lguest_entry)
17022 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17023 __INITDATA
17024
17025 subarch_entries:
17026 - .long default_entry /* normal x86/PC */
17027 - .long lguest_entry /* lguest hypervisor */
17028 - .long xen_entry /* Xen hypervisor */
17029 - .long default_entry /* Moorestown MID */
17030 + .long ta(default_entry) /* normal x86/PC */
17031 + .long ta(lguest_entry) /* lguest hypervisor */
17032 + .long ta(xen_entry) /* Xen hypervisor */
17033 + .long ta(default_entry) /* Moorestown MID */
17034 num_subarch_entries = (. - subarch_entries) / 4
17035 .previous
17036 #else
17037 @@ -310,6 +382,7 @@ default_entry:
17038 orl %edx,%eax
17039 movl %eax,%cr4
17040
17041 +#ifdef CONFIG_X86_PAE
17042 testb $X86_CR4_PAE, %al # check if PAE is enabled
17043 jz 6f
17044
17045 @@ -338,6 +411,9 @@ default_entry:
17046 /* Make changes effective */
17047 wrmsr
17048
17049 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17050 +#endif
17051 +
17052 6:
17053
17054 /*
17055 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17056 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17057 movl %eax,%ss # after changing gdt.
17058
17059 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17060 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17061 movl %eax,%ds
17062 movl %eax,%es
17063
17064 movl $(__KERNEL_PERCPU), %eax
17065 movl %eax,%fs # set this cpu's percpu
17066
17067 +#ifdef CONFIG_CC_STACKPROTECTOR
17068 movl $(__KERNEL_STACK_CANARY),%eax
17069 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17070 + movl $(__USER_DS),%eax
17071 +#else
17072 + xorl %eax,%eax
17073 +#endif
17074 movl %eax,%gs
17075
17076 xorl %eax,%eax # Clear LDT
17077 @@ -520,8 +602,11 @@ setup_once:
17078 * relocation. Manually set base address in stack canary
17079 * segment descriptor.
17080 */
17081 - movl $gdt_page,%eax
17082 + movl $cpu_gdt_table,%eax
17083 movl $stack_canary,%ecx
17084 +#ifdef CONFIG_SMP
17085 + addl $__per_cpu_load,%ecx
17086 +#endif
17087 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17088 shrl $16, %ecx
17089 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17090 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17091 /* This is global to keep gas from relaxing the jumps */
17092 ENTRY(early_idt_handler)
17093 cld
17094 - cmpl $2,%ss:early_recursion_flag
17095 + cmpl $1,%ss:early_recursion_flag
17096 je hlt_loop
17097 incl %ss:early_recursion_flag
17098
17099 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17100 pushl (20+6*4)(%esp) /* trapno */
17101 pushl $fault_msg
17102 call printk
17103 -#endif
17104 call dump_stack
17105 +#endif
17106 hlt_loop:
17107 hlt
17108 jmp hlt_loop
17109 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17110 /* This is the default interrupt "handler" :-) */
17111 ALIGN
17112 ignore_int:
17113 - cld
17114 #ifdef CONFIG_PRINTK
17115 + cmpl $2,%ss:early_recursion_flag
17116 + je hlt_loop
17117 + incl %ss:early_recursion_flag
17118 + cld
17119 pushl %eax
17120 pushl %ecx
17121 pushl %edx
17122 @@ -620,9 +708,6 @@ ignore_int:
17123 movl $(__KERNEL_DS),%eax
17124 movl %eax,%ds
17125 movl %eax,%es
17126 - cmpl $2,early_recursion_flag
17127 - je hlt_loop
17128 - incl early_recursion_flag
17129 pushl 16(%esp)
17130 pushl 24(%esp)
17131 pushl 32(%esp)
17132 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17133 /*
17134 * BSS section
17135 */
17136 -__PAGE_ALIGNED_BSS
17137 - .align PAGE_SIZE
17138 #ifdef CONFIG_X86_PAE
17139 +.section .initial_pg_pmd,"a",@progbits
17140 initial_pg_pmd:
17141 .fill 1024*KPMDS,4,0
17142 #else
17143 +.section .initial_page_table,"a",@progbits
17144 ENTRY(initial_page_table)
17145 .fill 1024,4,0
17146 #endif
17147 +.section .initial_pg_fixmap,"a",@progbits
17148 initial_pg_fixmap:
17149 .fill 1024,4,0
17150 +.section .empty_zero_page,"a",@progbits
17151 ENTRY(empty_zero_page)
17152 .fill 4096,1,0
17153 +.section .swapper_pg_dir,"a",@progbits
17154 ENTRY(swapper_pg_dir)
17155 +#ifdef CONFIG_X86_PAE
17156 + .fill 4,8,0
17157 +#else
17158 .fill 1024,4,0
17159 +#endif
17160 +
17161 +/*
17162 + * The IDT has to be page-aligned to simplify the Pentium
17163 + * F0 0F bug workaround.. We have a special link segment
17164 + * for this.
17165 + */
17166 +.section .idt,"a",@progbits
17167 +ENTRY(idt_table)
17168 + .fill 256,8,0
17169
17170 /*
17171 * This starts the data section.
17172 */
17173 #ifdef CONFIG_X86_PAE
17174 -__PAGE_ALIGNED_DATA
17175 - /* Page-aligned for the benefit of paravirt? */
17176 - .align PAGE_SIZE
17177 +.section .initial_page_table,"a",@progbits
17178 ENTRY(initial_page_table)
17179 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17180 # if KPMDS == 3
17181 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17182 # error "Kernel PMDs should be 1, 2 or 3"
17183 # endif
17184 .align PAGE_SIZE /* needs to be page-sized too */
17185 +
17186 +#ifdef CONFIG_PAX_PER_CPU_PGD
17187 +ENTRY(cpu_pgd)
17188 + .rept NR_CPUS
17189 + .fill 4,8,0
17190 + .endr
17191 +#endif
17192 +
17193 #endif
17194
17195 .data
17196 .balign 4
17197 ENTRY(stack_start)
17198 - .long init_thread_union+THREAD_SIZE
17199 + .long init_thread_union+THREAD_SIZE-8
17200
17201 __INITRODATA
17202 int_msg:
17203 @@ -730,7 +837,7 @@ fault_msg:
17204 * segment size, and 32-bit linear address value:
17205 */
17206
17207 - .data
17208 +.section .rodata,"a",@progbits
17209 .globl boot_gdt_descr
17210 .globl idt_descr
17211
17212 @@ -739,7 +846,7 @@ fault_msg:
17213 .word 0 # 32 bit align gdt_desc.address
17214 boot_gdt_descr:
17215 .word __BOOT_DS+7
17216 - .long boot_gdt - __PAGE_OFFSET
17217 + .long pa(boot_gdt)
17218
17219 .word 0 # 32-bit align idt_desc.address
17220 idt_descr:
17221 @@ -750,7 +857,7 @@ idt_descr:
17222 .word 0 # 32 bit align gdt_desc.address
17223 ENTRY(early_gdt_descr)
17224 .word GDT_ENTRIES*8-1
17225 - .long gdt_page /* Overwritten for secondary CPUs */
17226 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17227
17228 /*
17229 * The boot_gdt must mirror the equivalent in setup.S and is
17230 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17231 .align L1_CACHE_BYTES
17232 ENTRY(boot_gdt)
17233 .fill GDT_ENTRY_BOOT_CS,8,0
17234 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17235 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17236 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17237 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17238 +
17239 + .align PAGE_SIZE_asm
17240 +ENTRY(cpu_gdt_table)
17241 + .rept NR_CPUS
17242 + .quad 0x0000000000000000 /* NULL descriptor */
17243 + .quad 0x0000000000000000 /* 0x0b reserved */
17244 + .quad 0x0000000000000000 /* 0x13 reserved */
17245 + .quad 0x0000000000000000 /* 0x1b reserved */
17246 +
17247 +#ifdef CONFIG_PAX_KERNEXEC
17248 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17249 +#else
17250 + .quad 0x0000000000000000 /* 0x20 unused */
17251 +#endif
17252 +
17253 + .quad 0x0000000000000000 /* 0x28 unused */
17254 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17255 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17256 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17257 + .quad 0x0000000000000000 /* 0x4b reserved */
17258 + .quad 0x0000000000000000 /* 0x53 reserved */
17259 + .quad 0x0000000000000000 /* 0x5b reserved */
17260 +
17261 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17262 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17263 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17264 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17265 +
17266 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17267 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17268 +
17269 + /*
17270 + * Segments used for calling PnP BIOS have byte granularity.
17271 + * The code segments and data segments have fixed 64k limits,
17272 + * the transfer segment sizes are set at run time.
17273 + */
17274 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17275 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17276 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17277 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17278 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17279 +
17280 + /*
17281 + * The APM segments have byte granularity and their bases
17282 + * are set at run time. All have 64k limits.
17283 + */
17284 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17285 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17286 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17287 +
17288 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17289 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17290 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17291 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17292 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17293 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17294 +
17295 + /* Be sure this is zeroed to avoid false validations in Xen */
17296 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17297 + .endr
17298 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17299 index 94bf9cc..400455a 100644
17300 --- a/arch/x86/kernel/head_64.S
17301 +++ b/arch/x86/kernel/head_64.S
17302 @@ -20,6 +20,8 @@
17303 #include <asm/processor-flags.h>
17304 #include <asm/percpu.h>
17305 #include <asm/nops.h>
17306 +#include <asm/cpufeature.h>
17307 +#include <asm/alternative-asm.h>
17308
17309 #ifdef CONFIG_PARAVIRT
17310 #include <asm/asm-offsets.h>
17311 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17312 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17313 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17314 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17315 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17316 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17317 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17318 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17319 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17320 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17321
17322 .text
17323 __HEAD
17324 @@ -88,35 +96,23 @@ startup_64:
17325 */
17326 addq %rbp, init_level4_pgt + 0(%rip)
17327 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17328 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17329 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17330 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17331 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17332
17333 addq %rbp, level3_ident_pgt + 0(%rip)
17334 +#ifndef CONFIG_XEN
17335 + addq %rbp, level3_ident_pgt + 8(%rip)
17336 +#endif
17337
17338 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17339 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17340 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17341 +
17342 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17343 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17344
17345 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17346 -
17347 - /* Add an Identity mapping if I am above 1G */
17348 - leaq _text(%rip), %rdi
17349 - andq $PMD_PAGE_MASK, %rdi
17350 -
17351 - movq %rdi, %rax
17352 - shrq $PUD_SHIFT, %rax
17353 - andq $(PTRS_PER_PUD - 1), %rax
17354 - jz ident_complete
17355 -
17356 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17357 - leaq level3_ident_pgt(%rip), %rbx
17358 - movq %rdx, 0(%rbx, %rax, 8)
17359 -
17360 - movq %rdi, %rax
17361 - shrq $PMD_SHIFT, %rax
17362 - andq $(PTRS_PER_PMD - 1), %rax
17363 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17364 - leaq level2_spare_pgt(%rip), %rbx
17365 - movq %rdx, 0(%rbx, %rax, 8)
17366 -ident_complete:
17367 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17368
17369 /*
17370 * Fixup the kernel text+data virtual addresses. Note that
17371 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17372 * after the boot processor executes this code.
17373 */
17374
17375 - /* Enable PAE mode and PGE */
17376 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17377 + /* Enable PAE mode and PSE/PGE */
17378 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17379 movq %rax, %cr4
17380
17381 /* Setup early boot stage 4 level pagetables. */
17382 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17383 movl $MSR_EFER, %ecx
17384 rdmsr
17385 btsl $_EFER_SCE, %eax /* Enable System Call */
17386 - btl $20,%edi /* No Execute supported? */
17387 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17388 jnc 1f
17389 btsl $_EFER_NX, %eax
17390 + leaq init_level4_pgt(%rip), %rdi
17391 +#ifndef CONFIG_EFI
17392 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17393 +#endif
17394 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17395 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17396 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17397 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17398 1: wrmsr /* Make changes effective */
17399
17400 /* Setup cr0 */
17401 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17402 * jump. In addition we need to ensure %cs is set so we make this
17403 * a far return.
17404 */
17405 + pax_set_fptr_mask
17406 movq initial_code(%rip),%rax
17407 pushq $0 # fake return address to stop unwinder
17408 pushq $__KERNEL_CS # set correct cs
17409 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17410 bad_address:
17411 jmp bad_address
17412
17413 - .section ".init.text","ax"
17414 + __INIT
17415 .globl early_idt_handlers
17416 early_idt_handlers:
17417 # 104(%rsp) %rflags
17418 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17419 addq $16,%rsp # drop vector number and error code
17420 decl early_recursion_flag(%rip)
17421 INTERRUPT_RETURN
17422 + .previous
17423
17424 + __INITDATA
17425 .balign 4
17426 early_recursion_flag:
17427 .long 0
17428 + .previous
17429
17430 + .section .rodata,"a",@progbits
17431 #ifdef CONFIG_EARLY_PRINTK
17432 early_idt_msg:
17433 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17434 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17435 #endif /* CONFIG_EARLY_PRINTK */
17436 .previous
17437
17438 + .section .rodata,"a",@progbits
17439 #define NEXT_PAGE(name) \
17440 .balign PAGE_SIZE; \
17441 ENTRY(name)
17442 @@ -372,7 +382,6 @@ ENTRY(name)
17443 i = i + 1 ; \
17444 .endr
17445
17446 - .data
17447 /*
17448 * This default setting generates an ident mapping at address 0x100000
17449 * and a mapping for the kernel that precisely maps virtual address
17450 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17451 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17452 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17453 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17454 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17455 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17456 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17457 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17458 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17459 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17460 .org init_level4_pgt + L4_START_KERNEL*8, 0
17461 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17462 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17463
17464 +#ifdef CONFIG_PAX_PER_CPU_PGD
17465 +NEXT_PAGE(cpu_pgd)
17466 + .rept NR_CPUS
17467 + .fill 512,8,0
17468 + .endr
17469 +#endif
17470 +
17471 NEXT_PAGE(level3_ident_pgt)
17472 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17473 +#ifdef CONFIG_XEN
17474 .fill 511,8,0
17475 +#else
17476 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17477 + .fill 510,8,0
17478 +#endif
17479 +
17480 +NEXT_PAGE(level3_vmalloc_start_pgt)
17481 + .fill 512,8,0
17482 +
17483 +NEXT_PAGE(level3_vmalloc_end_pgt)
17484 + .fill 512,8,0
17485 +
17486 +NEXT_PAGE(level3_vmemmap_pgt)
17487 + .fill L3_VMEMMAP_START,8,0
17488 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17489
17490 NEXT_PAGE(level3_kernel_pgt)
17491 .fill L3_START_KERNEL,8,0
17492 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17493 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17494 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17495
17496 +NEXT_PAGE(level2_vmemmap_pgt)
17497 + .fill 512,8,0
17498 +
17499 NEXT_PAGE(level2_fixmap_pgt)
17500 - .fill 506,8,0
17501 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17502 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17503 - .fill 5,8,0
17504 + .fill 507,8,0
17505 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17506 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17507 + .fill 4,8,0
17508
17509 -NEXT_PAGE(level1_fixmap_pgt)
17510 +NEXT_PAGE(level1_vsyscall_pgt)
17511 .fill 512,8,0
17512
17513 -NEXT_PAGE(level2_ident_pgt)
17514 - /* Since I easily can, map the first 1G.
17515 + /* Since I easily can, map the first 2G.
17516 * Don't set NX because code runs from these pages.
17517 */
17518 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17519 +NEXT_PAGE(level2_ident_pgt)
17520 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17521
17522 NEXT_PAGE(level2_kernel_pgt)
17523 /*
17524 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17525 * If you want to increase this then increase MODULES_VADDR
17526 * too.)
17527 */
17528 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17529 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17530 -
17531 -NEXT_PAGE(level2_spare_pgt)
17532 - .fill 512, 8, 0
17533 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17534
17535 #undef PMDS
17536 #undef NEXT_PAGE
17537
17538 - .data
17539 + .align PAGE_SIZE
17540 +ENTRY(cpu_gdt_table)
17541 + .rept NR_CPUS
17542 + .quad 0x0000000000000000 /* NULL descriptor */
17543 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17544 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17545 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17546 + .quad 0x00cffb000000ffff /* __USER32_CS */
17547 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17548 + .quad 0x00affb000000ffff /* __USER_CS */
17549 +
17550 +#ifdef CONFIG_PAX_KERNEXEC
17551 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17552 +#else
17553 + .quad 0x0 /* unused */
17554 +#endif
17555 +
17556 + .quad 0,0 /* TSS */
17557 + .quad 0,0 /* LDT */
17558 + .quad 0,0,0 /* three TLS descriptors */
17559 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17560 + /* asm/segment.h:GDT_ENTRIES must match this */
17561 +
17562 + /* zero the remaining page */
17563 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17564 + .endr
17565 +
17566 .align 16
17567 .globl early_gdt_descr
17568 early_gdt_descr:
17569 .word GDT_ENTRIES*8-1
17570 early_gdt_descr_base:
17571 - .quad INIT_PER_CPU_VAR(gdt_page)
17572 + .quad cpu_gdt_table
17573
17574 ENTRY(phys_base)
17575 /* This must match the first entry in level2_kernel_pgt */
17576 .quad 0x0000000000000000
17577
17578 #include "../../x86/xen/xen-head.S"
17579 -
17580 - .section .bss, "aw", @nobits
17581 +
17582 + .section .rodata,"a",@progbits
17583 .align L1_CACHE_BYTES
17584 ENTRY(idt_table)
17585 - .skip IDT_ENTRIES * 16
17586 + .fill 512,8,0
17587
17588 .align L1_CACHE_BYTES
17589 ENTRY(nmi_idt_table)
17590 - .skip IDT_ENTRIES * 16
17591 + .fill 512,8,0
17592
17593 __PAGE_ALIGNED_BSS
17594 .align PAGE_SIZE
17595 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17596 index 9c3bd4a..e1d9b35 100644
17597 --- a/arch/x86/kernel/i386_ksyms_32.c
17598 +++ b/arch/x86/kernel/i386_ksyms_32.c
17599 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17600 EXPORT_SYMBOL(cmpxchg8b_emu);
17601 #endif
17602
17603 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17604 +
17605 /* Networking helper routines. */
17606 EXPORT_SYMBOL(csum_partial_copy_generic);
17607 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17608 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17609
17610 EXPORT_SYMBOL(__get_user_1);
17611 EXPORT_SYMBOL(__get_user_2);
17612 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17613
17614 EXPORT_SYMBOL(csum_partial);
17615 EXPORT_SYMBOL(empty_zero_page);
17616 +
17617 +#ifdef CONFIG_PAX_KERNEXEC
17618 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17619 +#endif
17620 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17621 index f250431..54097e7 100644
17622 --- a/arch/x86/kernel/i387.c
17623 +++ b/arch/x86/kernel/i387.c
17624 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17625 static inline bool interrupted_user_mode(void)
17626 {
17627 struct pt_regs *regs = get_irq_regs();
17628 - return regs && user_mode_vm(regs);
17629 + return regs && user_mode(regs);
17630 }
17631
17632 /*
17633 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17634 index 36d1853..bf25736 100644
17635 --- a/arch/x86/kernel/i8259.c
17636 +++ b/arch/x86/kernel/i8259.c
17637 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17638 "spurious 8259A interrupt: IRQ%d.\n", irq);
17639 spurious_irq_mask |= irqmask;
17640 }
17641 - atomic_inc(&irq_err_count);
17642 + atomic_inc_unchecked(&irq_err_count);
17643 /*
17644 * Theoretically we do not have to handle this IRQ,
17645 * but in Linux this does not cause problems and is
17646 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17647 index 8c96897..be66bfa 100644
17648 --- a/arch/x86/kernel/ioport.c
17649 +++ b/arch/x86/kernel/ioport.c
17650 @@ -6,6 +6,7 @@
17651 #include <linux/sched.h>
17652 #include <linux/kernel.h>
17653 #include <linux/capability.h>
17654 +#include <linux/security.h>
17655 #include <linux/errno.h>
17656 #include <linux/types.h>
17657 #include <linux/ioport.h>
17658 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17659
17660 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17661 return -EINVAL;
17662 +#ifdef CONFIG_GRKERNSEC_IO
17663 + if (turn_on && grsec_disable_privio) {
17664 + gr_handle_ioperm();
17665 + return -EPERM;
17666 + }
17667 +#endif
17668 if (turn_on && !capable(CAP_SYS_RAWIO))
17669 return -EPERM;
17670
17671 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17672 * because the ->io_bitmap_max value must match the bitmap
17673 * contents:
17674 */
17675 - tss = &per_cpu(init_tss, get_cpu());
17676 + tss = init_tss + get_cpu();
17677
17678 if (turn_on)
17679 bitmap_clear(t->io_bitmap_ptr, from, num);
17680 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17681 return -EINVAL;
17682 /* Trying to gain more privileges? */
17683 if (level > old) {
17684 +#ifdef CONFIG_GRKERNSEC_IO
17685 + if (grsec_disable_privio) {
17686 + gr_handle_iopl();
17687 + return -EPERM;
17688 + }
17689 +#endif
17690 if (!capable(CAP_SYS_RAWIO))
17691 return -EPERM;
17692 }
17693 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17694 index d44f782..31ab01e 100644
17695 --- a/arch/x86/kernel/irq.c
17696 +++ b/arch/x86/kernel/irq.c
17697 @@ -18,7 +18,7 @@
17698 #include <asm/mce.h>
17699 #include <asm/hw_irq.h>
17700
17701 -atomic_t irq_err_count;
17702 +atomic_unchecked_t irq_err_count;
17703
17704 /* Function pointer for generic interrupt vector handling */
17705 void (*x86_platform_ipi_callback)(void) = NULL;
17706 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17707 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17708 seq_printf(p, " Machine check polls\n");
17709 #endif
17710 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17711 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17712 #if defined(CONFIG_X86_IO_APIC)
17713 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17714 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17715 #endif
17716 return 0;
17717 }
17718 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17719
17720 u64 arch_irq_stat(void)
17721 {
17722 - u64 sum = atomic_read(&irq_err_count);
17723 + u64 sum = atomic_read_unchecked(&irq_err_count);
17724
17725 #ifdef CONFIG_X86_IO_APIC
17726 - sum += atomic_read(&irq_mis_count);
17727 + sum += atomic_read_unchecked(&irq_mis_count);
17728 #endif
17729 return sum;
17730 }
17731 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17732 index 344faf8..355f60d 100644
17733 --- a/arch/x86/kernel/irq_32.c
17734 +++ b/arch/x86/kernel/irq_32.c
17735 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17736 __asm__ __volatile__("andl %%esp,%0" :
17737 "=r" (sp) : "0" (THREAD_SIZE - 1));
17738
17739 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17740 + return sp < STACK_WARN;
17741 }
17742
17743 static void print_stack_overflow(void)
17744 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17745 * per-CPU IRQ handling contexts (thread information and stack)
17746 */
17747 union irq_ctx {
17748 - struct thread_info tinfo;
17749 - u32 stack[THREAD_SIZE/sizeof(u32)];
17750 + unsigned long previous_esp;
17751 + u32 stack[THREAD_SIZE/sizeof(u32)];
17752 } __attribute__((aligned(THREAD_SIZE)));
17753
17754 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17755 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17756 static inline int
17757 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17758 {
17759 - union irq_ctx *curctx, *irqctx;
17760 + union irq_ctx *irqctx;
17761 u32 *isp, arg1, arg2;
17762
17763 - curctx = (union irq_ctx *) current_thread_info();
17764 irqctx = __this_cpu_read(hardirq_ctx);
17765
17766 /*
17767 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 * handler) we can't do that and just have to keep using the
17769 * current stack (which is the irq stack already after all)
17770 */
17771 - if (unlikely(curctx == irqctx))
17772 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17773 return 0;
17774
17775 /* build the stack frame on the IRQ stack */
17776 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17777 - irqctx->tinfo.task = curctx->tinfo.task;
17778 - irqctx->tinfo.previous_esp = current_stack_pointer;
17779 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17780 + irqctx->previous_esp = current_stack_pointer;
17781
17782 - /* Copy the preempt_count so that the [soft]irq checks work. */
17783 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17784 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17785 + __set_fs(MAKE_MM_SEG(0));
17786 +#endif
17787
17788 if (unlikely(overflow))
17789 call_on_stack(print_stack_overflow, isp);
17790 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17791 : "0" (irq), "1" (desc), "2" (isp),
17792 "D" (desc->handle_irq)
17793 : "memory", "cc", "ecx");
17794 +
17795 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17796 + __set_fs(current_thread_info()->addr_limit);
17797 +#endif
17798 +
17799 return 1;
17800 }
17801
17802 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17803 */
17804 void __cpuinit irq_ctx_init(int cpu)
17805 {
17806 - union irq_ctx *irqctx;
17807 -
17808 if (per_cpu(hardirq_ctx, cpu))
17809 return;
17810
17811 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17812 - THREADINFO_GFP,
17813 - THREAD_SIZE_ORDER));
17814 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17815 - irqctx->tinfo.cpu = cpu;
17816 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17817 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17818 -
17819 - per_cpu(hardirq_ctx, cpu) = irqctx;
17820 -
17821 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17822 - THREADINFO_GFP,
17823 - THREAD_SIZE_ORDER));
17824 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17825 - irqctx->tinfo.cpu = cpu;
17826 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17827 -
17828 - per_cpu(softirq_ctx, cpu) = irqctx;
17829 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17830 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17831 +
17832 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17833 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17834
17835 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17836 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17837 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17838 asmlinkage void do_softirq(void)
17839 {
17840 unsigned long flags;
17841 - struct thread_info *curctx;
17842 union irq_ctx *irqctx;
17843 u32 *isp;
17844
17845 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17846 local_irq_save(flags);
17847
17848 if (local_softirq_pending()) {
17849 - curctx = current_thread_info();
17850 irqctx = __this_cpu_read(softirq_ctx);
17851 - irqctx->tinfo.task = curctx->task;
17852 - irqctx->tinfo.previous_esp = current_stack_pointer;
17853 + irqctx->previous_esp = current_stack_pointer;
17854
17855 /* build the stack frame on the softirq stack */
17856 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17857 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17858 +
17859 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17860 + __set_fs(MAKE_MM_SEG(0));
17861 +#endif
17862
17863 call_on_stack(__do_softirq, isp);
17864 +
17865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17866 + __set_fs(current_thread_info()->addr_limit);
17867 +#endif
17868 +
17869 /*
17870 * Shouldn't happen, we returned above if in_interrupt():
17871 */
17872 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17873 if (unlikely(!desc))
17874 return false;
17875
17876 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17877 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17878 if (unlikely(overflow))
17879 print_stack_overflow();
17880 desc->handle_irq(irq, desc);
17881 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17882 index d04d3ec..ea4b374 100644
17883 --- a/arch/x86/kernel/irq_64.c
17884 +++ b/arch/x86/kernel/irq_64.c
17885 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17886 u64 estack_top, estack_bottom;
17887 u64 curbase = (u64)task_stack_page(current);
17888
17889 - if (user_mode_vm(regs))
17890 + if (user_mode(regs))
17891 return;
17892
17893 if (regs->sp >= curbase + sizeof(struct thread_info) +
17894 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17895 index dc1404b..bbc43e7 100644
17896 --- a/arch/x86/kernel/kdebugfs.c
17897 +++ b/arch/x86/kernel/kdebugfs.c
17898 @@ -27,7 +27,7 @@ struct setup_data_node {
17899 u32 len;
17900 };
17901
17902 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17903 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17904 size_t count, loff_t *ppos)
17905 {
17906 struct setup_data_node *node = file->private_data;
17907 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17908 index 3f61904..873cea9 100644
17909 --- a/arch/x86/kernel/kgdb.c
17910 +++ b/arch/x86/kernel/kgdb.c
17911 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17912 #ifdef CONFIG_X86_32
17913 switch (regno) {
17914 case GDB_SS:
17915 - if (!user_mode_vm(regs))
17916 + if (!user_mode(regs))
17917 *(unsigned long *)mem = __KERNEL_DS;
17918 break;
17919 case GDB_SP:
17920 - if (!user_mode_vm(regs))
17921 + if (!user_mode(regs))
17922 *(unsigned long *)mem = kernel_stack_pointer(regs);
17923 break;
17924 case GDB_GS:
17925 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17926 case 'k':
17927 /* clear the trace bit */
17928 linux_regs->flags &= ~X86_EFLAGS_TF;
17929 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17930 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17931
17932 /* set the trace bit if we're stepping */
17933 if (remcomInBuffer[0] == 's') {
17934 linux_regs->flags |= X86_EFLAGS_TF;
17935 - atomic_set(&kgdb_cpu_doing_single_step,
17936 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17937 raw_smp_processor_id());
17938 }
17939
17940 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17941
17942 switch (cmd) {
17943 case DIE_DEBUG:
17944 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17945 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17946 if (user_mode(regs))
17947 return single_step_cont(regs, args);
17948 break;
17949 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17950 index c5e410e..da6aaf9 100644
17951 --- a/arch/x86/kernel/kprobes-opt.c
17952 +++ b/arch/x86/kernel/kprobes-opt.c
17953 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17954 * Verify if the address gap is in 2GB range, because this uses
17955 * a relative jump.
17956 */
17957 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17958 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17959 if (abs(rel) > 0x7fffffff)
17960 return -ERANGE;
17961
17962 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17963 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17964
17965 /* Set probe function call */
17966 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17967 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17968
17969 /* Set returning jmp instruction at the tail of out-of-line buffer */
17970 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17971 - (u8 *)op->kp.addr + op->optinsn.size);
17972 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17973
17974 flush_icache_range((unsigned long) buf,
17975 (unsigned long) buf + TMPL_END_IDX +
17976 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17977 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17978
17979 /* Backup instructions which will be replaced by jump address */
17980 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17981 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17982 RELATIVE_ADDR_SIZE);
17983
17984 insn_buf[0] = RELATIVEJUMP_OPCODE;
17985 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17986 index e2f751e..dffa2a0 100644
17987 --- a/arch/x86/kernel/kprobes.c
17988 +++ b/arch/x86/kernel/kprobes.c
17989 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17990 } __attribute__((packed)) *insn;
17991
17992 insn = (struct __arch_relative_insn *)from;
17993 +
17994 + pax_open_kernel();
17995 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17996 insn->op = op;
17997 + pax_close_kernel();
17998 }
17999
18000 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18001 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18002 kprobe_opcode_t opcode;
18003 kprobe_opcode_t *orig_opcodes = opcodes;
18004
18005 - if (search_exception_tables((unsigned long)opcodes))
18006 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18007 return 0; /* Page fault may occur on this address. */
18008
18009 retry:
18010 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18011 /* Another subsystem puts a breakpoint, failed to recover */
18012 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18013 return 0;
18014 + pax_open_kernel();
18015 memcpy(dest, insn.kaddr, insn.length);
18016 + pax_close_kernel();
18017
18018 #ifdef CONFIG_X86_64
18019 if (insn_rip_relative(&insn)) {
18020 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18021 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18022 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18023 disp = (u8 *) dest + insn_offset_displacement(&insn);
18024 + pax_open_kernel();
18025 *(s32 *) disp = (s32) newdisp;
18026 + pax_close_kernel();
18027 }
18028 #endif
18029 return insn.length;
18030 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18031 * nor set current_kprobe, because it doesn't use single
18032 * stepping.
18033 */
18034 - regs->ip = (unsigned long)p->ainsn.insn;
18035 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18036 preempt_enable_no_resched();
18037 return;
18038 }
18039 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18040 if (p->opcode == BREAKPOINT_INSTRUCTION)
18041 regs->ip = (unsigned long)p->addr;
18042 else
18043 - regs->ip = (unsigned long)p->ainsn.insn;
18044 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18045 }
18046
18047 /*
18048 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18049 setup_singlestep(p, regs, kcb, 0);
18050 return 1;
18051 }
18052 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18053 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18054 /*
18055 * The breakpoint instruction was removed right
18056 * after we hit it. Another cpu has removed
18057 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18058 " movq %rax, 152(%rsp)\n"
18059 RESTORE_REGS_STRING
18060 " popfq\n"
18061 +#ifdef KERNEXEC_PLUGIN
18062 + " btsq $63,(%rsp)\n"
18063 +#endif
18064 #else
18065 " pushf\n"
18066 SAVE_REGS_STRING
18067 @@ -765,7 +775,7 @@ static void __kprobes
18068 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18069 {
18070 unsigned long *tos = stack_addr(regs);
18071 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18072 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18073 unsigned long orig_ip = (unsigned long)p->addr;
18074 kprobe_opcode_t *insn = p->ainsn.insn;
18075
18076 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18077 struct die_args *args = data;
18078 int ret = NOTIFY_DONE;
18079
18080 - if (args->regs && user_mode_vm(args->regs))
18081 + if (args->regs && user_mode(args->regs))
18082 return ret;
18083
18084 switch (val) {
18085 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18086 index ebc9873..1b9724b 100644
18087 --- a/arch/x86/kernel/ldt.c
18088 +++ b/arch/x86/kernel/ldt.c
18089 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18090 if (reload) {
18091 #ifdef CONFIG_SMP
18092 preempt_disable();
18093 - load_LDT(pc);
18094 + load_LDT_nolock(pc);
18095 if (!cpumask_equal(mm_cpumask(current->mm),
18096 cpumask_of(smp_processor_id())))
18097 smp_call_function(flush_ldt, current->mm, 1);
18098 preempt_enable();
18099 #else
18100 - load_LDT(pc);
18101 + load_LDT_nolock(pc);
18102 #endif
18103 }
18104 if (oldsize) {
18105 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18106 return err;
18107
18108 for (i = 0; i < old->size; i++)
18109 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18110 + write_ldt_entry(new->ldt, i, old->ldt + i);
18111 return 0;
18112 }
18113
18114 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18115 retval = copy_ldt(&mm->context, &old_mm->context);
18116 mutex_unlock(&old_mm->context.lock);
18117 }
18118 +
18119 + if (tsk == current) {
18120 + mm->context.vdso = 0;
18121 +
18122 +#ifdef CONFIG_X86_32
18123 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18124 + mm->context.user_cs_base = 0UL;
18125 + mm->context.user_cs_limit = ~0UL;
18126 +
18127 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18128 + cpus_clear(mm->context.cpu_user_cs_mask);
18129 +#endif
18130 +
18131 +#endif
18132 +#endif
18133 +
18134 + }
18135 +
18136 return retval;
18137 }
18138
18139 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18140 }
18141 }
18142
18143 +#ifdef CONFIG_PAX_SEGMEXEC
18144 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18145 + error = -EINVAL;
18146 + goto out_unlock;
18147 + }
18148 +#endif
18149 +
18150 fill_ldt(&ldt, &ldt_info);
18151 if (oldmode)
18152 ldt.avl = 0;
18153 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18154 index 5b19e4d..6476a76 100644
18155 --- a/arch/x86/kernel/machine_kexec_32.c
18156 +++ b/arch/x86/kernel/machine_kexec_32.c
18157 @@ -26,7 +26,7 @@
18158 #include <asm/cacheflush.h>
18159 #include <asm/debugreg.h>
18160
18161 -static void set_idt(void *newidt, __u16 limit)
18162 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18163 {
18164 struct desc_ptr curidt;
18165
18166 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18167 }
18168
18169
18170 -static void set_gdt(void *newgdt, __u16 limit)
18171 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18172 {
18173 struct desc_ptr curgdt;
18174
18175 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18176 }
18177
18178 control_page = page_address(image->control_code_page);
18179 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18180 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18181
18182 relocate_kernel_ptr = control_page;
18183 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18184 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18185 index 0327e2b..e43737b 100644
18186 --- a/arch/x86/kernel/microcode_intel.c
18187 +++ b/arch/x86/kernel/microcode_intel.c
18188 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18189
18190 static int get_ucode_user(void *to, const void *from, size_t n)
18191 {
18192 - return copy_from_user(to, from, n);
18193 + return copy_from_user(to, (const void __force_user *)from, n);
18194 }
18195
18196 static enum ucode_state
18197 request_microcode_user(int cpu, const void __user *buf, size_t size)
18198 {
18199 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18200 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18201 }
18202
18203 static void microcode_fini_cpu(int cpu)
18204 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18205 index 216a4d7..b328f09 100644
18206 --- a/arch/x86/kernel/module.c
18207 +++ b/arch/x86/kernel/module.c
18208 @@ -43,15 +43,60 @@ do { \
18209 } while (0)
18210 #endif
18211
18212 -void *module_alloc(unsigned long size)
18213 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18214 {
18215 - if (PAGE_ALIGN(size) > MODULES_LEN)
18216 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18217 return NULL;
18218 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18219 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18220 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18221 -1, __builtin_return_address(0));
18222 }
18223
18224 +void *module_alloc(unsigned long size)
18225 +{
18226 +
18227 +#ifdef CONFIG_PAX_KERNEXEC
18228 + return __module_alloc(size, PAGE_KERNEL);
18229 +#else
18230 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18231 +#endif
18232 +
18233 +}
18234 +
18235 +#ifdef CONFIG_PAX_KERNEXEC
18236 +#ifdef CONFIG_X86_32
18237 +void *module_alloc_exec(unsigned long size)
18238 +{
18239 + struct vm_struct *area;
18240 +
18241 + if (size == 0)
18242 + return NULL;
18243 +
18244 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18245 + return area ? area->addr : NULL;
18246 +}
18247 +EXPORT_SYMBOL(module_alloc_exec);
18248 +
18249 +void module_free_exec(struct module *mod, void *module_region)
18250 +{
18251 + vunmap(module_region);
18252 +}
18253 +EXPORT_SYMBOL(module_free_exec);
18254 +#else
18255 +void module_free_exec(struct module *mod, void *module_region)
18256 +{
18257 + module_free(mod, module_region);
18258 +}
18259 +EXPORT_SYMBOL(module_free_exec);
18260 +
18261 +void *module_alloc_exec(unsigned long size)
18262 +{
18263 + return __module_alloc(size, PAGE_KERNEL_RX);
18264 +}
18265 +EXPORT_SYMBOL(module_alloc_exec);
18266 +#endif
18267 +#endif
18268 +
18269 #ifdef CONFIG_X86_32
18270 int apply_relocate(Elf32_Shdr *sechdrs,
18271 const char *strtab,
18272 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18273 unsigned int i;
18274 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18275 Elf32_Sym *sym;
18276 - uint32_t *location;
18277 + uint32_t *plocation, location;
18278
18279 DEBUGP("Applying relocate section %u to %u\n",
18280 relsec, sechdrs[relsec].sh_info);
18281 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18282 /* This is where to make the change */
18283 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18284 - + rel[i].r_offset;
18285 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18286 + location = (uint32_t)plocation;
18287 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18288 + plocation = ktla_ktva((void *)plocation);
18289 /* This is the symbol it is referring to. Note that all
18290 undefined symbols have been resolved. */
18291 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18292 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18293 switch (ELF32_R_TYPE(rel[i].r_info)) {
18294 case R_386_32:
18295 /* We add the value into the location given */
18296 - *location += sym->st_value;
18297 + pax_open_kernel();
18298 + *plocation += sym->st_value;
18299 + pax_close_kernel();
18300 break;
18301 case R_386_PC32:
18302 /* Add the value, subtract its position */
18303 - *location += sym->st_value - (uint32_t)location;
18304 + pax_open_kernel();
18305 + *plocation += sym->st_value - location;
18306 + pax_close_kernel();
18307 break;
18308 default:
18309 pr_err("%s: Unknown relocation: %u\n",
18310 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18311 case R_X86_64_NONE:
18312 break;
18313 case R_X86_64_64:
18314 + pax_open_kernel();
18315 *(u64 *)loc = val;
18316 + pax_close_kernel();
18317 break;
18318 case R_X86_64_32:
18319 + pax_open_kernel();
18320 *(u32 *)loc = val;
18321 + pax_close_kernel();
18322 if (val != *(u32 *)loc)
18323 goto overflow;
18324 break;
18325 case R_X86_64_32S:
18326 + pax_open_kernel();
18327 *(s32 *)loc = val;
18328 + pax_close_kernel();
18329 if ((s64)val != *(s32 *)loc)
18330 goto overflow;
18331 break;
18332 case R_X86_64_PC32:
18333 val -= (u64)loc;
18334 + pax_open_kernel();
18335 *(u32 *)loc = val;
18336 + pax_close_kernel();
18337 +
18338 #if 0
18339 if ((s64)val != *(s32 *)loc)
18340 goto overflow;
18341 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18342 index f84f5c5..e27e54b 100644
18343 --- a/arch/x86/kernel/nmi.c
18344 +++ b/arch/x86/kernel/nmi.c
18345 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18346 dotraplinkage notrace __kprobes void
18347 do_nmi(struct pt_regs *regs, long error_code)
18348 {
18349 +
18350 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18351 + if (!user_mode(regs)) {
18352 + unsigned long cs = regs->cs & 0xFFFF;
18353 + unsigned long ip = ktva_ktla(regs->ip);
18354 +
18355 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18356 + regs->ip = ip;
18357 + }
18358 +#endif
18359 +
18360 nmi_nesting_preprocess(regs);
18361
18362 nmi_enter();
18363 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18364 index 676b8c7..870ba04 100644
18365 --- a/arch/x86/kernel/paravirt-spinlocks.c
18366 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18367 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18368 arch_spin_lock(lock);
18369 }
18370
18371 -struct pv_lock_ops pv_lock_ops = {
18372 +struct pv_lock_ops pv_lock_ops __read_only = {
18373 #ifdef CONFIG_SMP
18374 .spin_is_locked = __ticket_spin_is_locked,
18375 .spin_is_contended = __ticket_spin_is_contended,
18376 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18377 index 17fff18..7bb2088 100644
18378 --- a/arch/x86/kernel/paravirt.c
18379 +++ b/arch/x86/kernel/paravirt.c
18380 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18381 {
18382 return x;
18383 }
18384 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18385 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18386 +#endif
18387
18388 void __init default_banner(void)
18389 {
18390 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18391 if (opfunc == NULL)
18392 /* If there's no function, patch it with a ud2a (BUG) */
18393 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18394 - else if (opfunc == _paravirt_nop)
18395 + else if (opfunc == (void *)_paravirt_nop)
18396 /* If the operation is a nop, then nop the callsite */
18397 ret = paravirt_patch_nop();
18398
18399 /* identity functions just return their single argument */
18400 - else if (opfunc == _paravirt_ident_32)
18401 + else if (opfunc == (void *)_paravirt_ident_32)
18402 ret = paravirt_patch_ident_32(insnbuf, len);
18403 - else if (opfunc == _paravirt_ident_64)
18404 + else if (opfunc == (void *)_paravirt_ident_64)
18405 ret = paravirt_patch_ident_64(insnbuf, len);
18406 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18407 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18408 + ret = paravirt_patch_ident_64(insnbuf, len);
18409 +#endif
18410
18411 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18412 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18413 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18414 if (insn_len > len || start == NULL)
18415 insn_len = len;
18416 else
18417 - memcpy(insnbuf, start, insn_len);
18418 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18419
18420 return insn_len;
18421 }
18422 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18423 preempt_enable();
18424 }
18425
18426 -struct pv_info pv_info = {
18427 +struct pv_info pv_info __read_only = {
18428 .name = "bare hardware",
18429 .paravirt_enabled = 0,
18430 .kernel_rpl = 0,
18431 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18432 #endif
18433 };
18434
18435 -struct pv_init_ops pv_init_ops = {
18436 +struct pv_init_ops pv_init_ops __read_only = {
18437 .patch = native_patch,
18438 };
18439
18440 -struct pv_time_ops pv_time_ops = {
18441 +struct pv_time_ops pv_time_ops __read_only = {
18442 .sched_clock = native_sched_clock,
18443 .steal_clock = native_steal_clock,
18444 };
18445
18446 -struct pv_irq_ops pv_irq_ops = {
18447 +struct pv_irq_ops pv_irq_ops __read_only = {
18448 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18449 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18450 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18451 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18452 #endif
18453 };
18454
18455 -struct pv_cpu_ops pv_cpu_ops = {
18456 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18457 .cpuid = native_cpuid,
18458 .get_debugreg = native_get_debugreg,
18459 .set_debugreg = native_set_debugreg,
18460 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18461 .end_context_switch = paravirt_nop,
18462 };
18463
18464 -struct pv_apic_ops pv_apic_ops = {
18465 +struct pv_apic_ops pv_apic_ops __read_only = {
18466 #ifdef CONFIG_X86_LOCAL_APIC
18467 .startup_ipi_hook = paravirt_nop,
18468 #endif
18469 };
18470
18471 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18472 +#ifdef CONFIG_X86_32
18473 +#ifdef CONFIG_X86_PAE
18474 +/* 64-bit pagetable entries */
18475 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18476 +#else
18477 /* 32-bit pagetable entries */
18478 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18479 +#endif
18480 #else
18481 /* 64-bit pagetable entries */
18482 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18483 #endif
18484
18485 -struct pv_mmu_ops pv_mmu_ops = {
18486 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18487
18488 .read_cr2 = native_read_cr2,
18489 .write_cr2 = native_write_cr2,
18490 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18491 .make_pud = PTE_IDENT,
18492
18493 .set_pgd = native_set_pgd,
18494 + .set_pgd_batched = native_set_pgd_batched,
18495 #endif
18496 #endif /* PAGETABLE_LEVELS >= 3 */
18497
18498 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18499 },
18500
18501 .set_fixmap = native_set_fixmap,
18502 +
18503 +#ifdef CONFIG_PAX_KERNEXEC
18504 + .pax_open_kernel = native_pax_open_kernel,
18505 + .pax_close_kernel = native_pax_close_kernel,
18506 +#endif
18507 +
18508 };
18509
18510 EXPORT_SYMBOL_GPL(pv_time_ops);
18511 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18512 index 35ccf75..7a15747 100644
18513 --- a/arch/x86/kernel/pci-iommu_table.c
18514 +++ b/arch/x86/kernel/pci-iommu_table.c
18515 @@ -2,7 +2,7 @@
18516 #include <asm/iommu_table.h>
18517 #include <linux/string.h>
18518 #include <linux/kallsyms.h>
18519 -
18520 +#include <linux/sched.h>
18521
18522 #define DEBUG 1
18523
18524 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18525 index ef6a845..8028ed3 100644
18526 --- a/arch/x86/kernel/process.c
18527 +++ b/arch/x86/kernel/process.c
18528 @@ -36,7 +36,8 @@
18529 * section. Since TSS's are completely CPU-local, we want them
18530 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18531 */
18532 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18533 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18534 +EXPORT_SYMBOL(init_tss);
18535
18536 #ifdef CONFIG_X86_64
18537 static DEFINE_PER_CPU(unsigned char, is_idle);
18538 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18539 task_xstate_cachep =
18540 kmem_cache_create("task_xstate", xstate_size,
18541 __alignof__(union thread_xstate),
18542 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18543 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18544 }
18545
18546 static inline void drop_fpu(struct task_struct *tsk)
18547 @@ -117,7 +118,7 @@ void exit_thread(void)
18548 unsigned long *bp = t->io_bitmap_ptr;
18549
18550 if (bp) {
18551 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18552 + struct tss_struct *tss = init_tss + get_cpu();
18553
18554 t->io_bitmap_ptr = NULL;
18555 clear_thread_flag(TIF_IO_BITMAP);
18556 @@ -148,7 +149,7 @@ void show_regs_common(void)
18557 board = dmi_get_system_info(DMI_BOARD_NAME);
18558
18559 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18560 - current->pid, current->comm, print_tainted(),
18561 + task_pid_nr(current), current->comm, print_tainted(),
18562 init_utsname()->release,
18563 (int)strcspn(init_utsname()->version, " "),
18564 init_utsname()->version,
18565 @@ -161,6 +162,9 @@ void flush_thread(void)
18566 {
18567 struct task_struct *tsk = current;
18568
18569 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18570 + loadsegment(gs, 0);
18571 +#endif
18572 flush_ptrace_hw_breakpoint(tsk);
18573 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18574 drop_fpu(tsk);
18575 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18576 regs.di = (unsigned long) arg;
18577
18578 #ifdef CONFIG_X86_32
18579 - regs.ds = __USER_DS;
18580 - regs.es = __USER_DS;
18581 + regs.ds = __KERNEL_DS;
18582 + regs.es = __KERNEL_DS;
18583 regs.fs = __KERNEL_PERCPU;
18584 - regs.gs = __KERNEL_STACK_CANARY;
18585 + savesegment(gs, regs.gs);
18586 #else
18587 regs.ss = __KERNEL_DS;
18588 #endif
18589 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18590 void exit_idle(void)
18591 {
18592 /* idle loop has pid 0 */
18593 - if (current->pid)
18594 + if (task_pid_nr(current))
18595 return;
18596 __exit_idle();
18597 }
18598 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18599
18600 return ret;
18601 }
18602 -void stop_this_cpu(void *dummy)
18603 +__noreturn void stop_this_cpu(void *dummy)
18604 {
18605 local_irq_disable();
18606 /*
18607 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18608 }
18609 early_param("idle", idle_setup);
18610
18611 -unsigned long arch_align_stack(unsigned long sp)
18612 +#ifdef CONFIG_PAX_RANDKSTACK
18613 +void pax_randomize_kstack(struct pt_regs *regs)
18614 {
18615 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18616 - sp -= get_random_int() % 8192;
18617 - return sp & ~0xf;
18618 -}
18619 + struct thread_struct *thread = &current->thread;
18620 + unsigned long time;
18621
18622 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18623 -{
18624 - unsigned long range_end = mm->brk + 0x02000000;
18625 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18626 -}
18627 + if (!randomize_va_space)
18628 + return;
18629 +
18630 + if (v8086_mode(regs))
18631 + return;
18632
18633 + rdtscl(time);
18634 +
18635 + /* P4 seems to return a 0 LSB, ignore it */
18636 +#ifdef CONFIG_MPENTIUM4
18637 + time &= 0x3EUL;
18638 + time <<= 2;
18639 +#elif defined(CONFIG_X86_64)
18640 + time &= 0xFUL;
18641 + time <<= 4;
18642 +#else
18643 + time &= 0x1FUL;
18644 + time <<= 3;
18645 +#endif
18646 +
18647 + thread->sp0 ^= time;
18648 + load_sp0(init_tss + smp_processor_id(), thread);
18649 +
18650 +#ifdef CONFIG_X86_64
18651 + this_cpu_write(kernel_stack, thread->sp0);
18652 +#endif
18653 +}
18654 +#endif
18655 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18656 index 516fa18..80bd9e6 100644
18657 --- a/arch/x86/kernel/process_32.c
18658 +++ b/arch/x86/kernel/process_32.c
18659 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18660 unsigned long thread_saved_pc(struct task_struct *tsk)
18661 {
18662 return ((unsigned long *)tsk->thread.sp)[3];
18663 +//XXX return tsk->thread.eip;
18664 }
18665
18666 void __show_regs(struct pt_regs *regs, int all)
18667 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18668 unsigned long sp;
18669 unsigned short ss, gs;
18670
18671 - if (user_mode_vm(regs)) {
18672 + if (user_mode(regs)) {
18673 sp = regs->sp;
18674 ss = regs->ss & 0xffff;
18675 - gs = get_user_gs(regs);
18676 } else {
18677 sp = kernel_stack_pointer(regs);
18678 savesegment(ss, ss);
18679 - savesegment(gs, gs);
18680 }
18681 + gs = get_user_gs(regs);
18682
18683 show_regs_common();
18684
18685 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18686 struct task_struct *tsk;
18687 int err;
18688
18689 - childregs = task_pt_regs(p);
18690 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18691 *childregs = *regs;
18692 childregs->ax = 0;
18693 childregs->sp = sp;
18694
18695 p->thread.sp = (unsigned long) childregs;
18696 p->thread.sp0 = (unsigned long) (childregs+1);
18697 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18698
18699 p->thread.ip = (unsigned long) ret_from_fork;
18700
18701 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18702 struct thread_struct *prev = &prev_p->thread,
18703 *next = &next_p->thread;
18704 int cpu = smp_processor_id();
18705 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18706 + struct tss_struct *tss = init_tss + cpu;
18707 fpu_switch_t fpu;
18708
18709 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18710 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18711 */
18712 lazy_save_gs(prev->gs);
18713
18714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18715 + __set_fs(task_thread_info(next_p)->addr_limit);
18716 +#endif
18717 +
18718 /*
18719 * Load the per-thread Thread-Local Storage descriptor.
18720 */
18721 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18722 */
18723 arch_end_context_switch(next_p);
18724
18725 + this_cpu_write(current_task, next_p);
18726 + this_cpu_write(current_tinfo, &next_p->tinfo);
18727 +
18728 /*
18729 * Restore %gs if needed (which is common)
18730 */
18731 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18732
18733 switch_fpu_finish(next_p, fpu);
18734
18735 - this_cpu_write(current_task, next_p);
18736 -
18737 return prev_p;
18738 }
18739
18740 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18741 } while (count++ < 16);
18742 return 0;
18743 }
18744 -
18745 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18746 index 0a980c9..1d0e689 100644
18747 --- a/arch/x86/kernel/process_64.c
18748 +++ b/arch/x86/kernel/process_64.c
18749 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18750 struct pt_regs *childregs;
18751 struct task_struct *me = current;
18752
18753 - childregs = ((struct pt_regs *)
18754 - (THREAD_SIZE + task_stack_page(p))) - 1;
18755 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18756 *childregs = *regs;
18757
18758 childregs->ax = 0;
18759 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18760 p->thread.sp = (unsigned long) childregs;
18761 p->thread.sp0 = (unsigned long) (childregs+1);
18762 p->thread.usersp = me->thread.usersp;
18763 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18764
18765 set_tsk_thread_flag(p, TIF_FORK);
18766
18767 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18768 struct thread_struct *prev = &prev_p->thread;
18769 struct thread_struct *next = &next_p->thread;
18770 int cpu = smp_processor_id();
18771 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18772 + struct tss_struct *tss = init_tss + cpu;
18773 unsigned fsindex, gsindex;
18774 fpu_switch_t fpu;
18775
18776 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18777 prev->usersp = this_cpu_read(old_rsp);
18778 this_cpu_write(old_rsp, next->usersp);
18779 this_cpu_write(current_task, next_p);
18780 + this_cpu_write(current_tinfo, &next_p->tinfo);
18781
18782 - this_cpu_write(kernel_stack,
18783 - (unsigned long)task_stack_page(next_p) +
18784 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18785 + this_cpu_write(kernel_stack, next->sp0);
18786
18787 /*
18788 * Now maybe reload the debug registers and handle I/O bitmaps
18789 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18790 if (!p || p == current || p->state == TASK_RUNNING)
18791 return 0;
18792 stack = (unsigned long)task_stack_page(p);
18793 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18794 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18795 return 0;
18796 fp = *(u64 *)(p->thread.sp);
18797 do {
18798 - if (fp < (unsigned long)stack ||
18799 - fp >= (unsigned long)stack+THREAD_SIZE)
18800 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18801 return 0;
18802 ip = *(u64 *)(fp+8);
18803 if (!in_sched_functions(ip))
18804 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18805 index c4c6a5c..905f440 100644
18806 --- a/arch/x86/kernel/ptrace.c
18807 +++ b/arch/x86/kernel/ptrace.c
18808 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18809 unsigned long addr, unsigned long data)
18810 {
18811 int ret;
18812 - unsigned long __user *datap = (unsigned long __user *)data;
18813 + unsigned long __user *datap = (__force unsigned long __user *)data;
18814
18815 switch (request) {
18816 /* read the word at location addr in the USER area. */
18817 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18818 if ((int) addr < 0)
18819 return -EIO;
18820 ret = do_get_thread_area(child, addr,
18821 - (struct user_desc __user *)data);
18822 + (__force struct user_desc __user *) data);
18823 break;
18824
18825 case PTRACE_SET_THREAD_AREA:
18826 if ((int) addr < 0)
18827 return -EIO;
18828 ret = do_set_thread_area(child, addr,
18829 - (struct user_desc __user *)data, 0);
18830 + (__force struct user_desc __user *) data, 0);
18831 break;
18832 #endif
18833
18834 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18835 memset(info, 0, sizeof(*info));
18836 info->si_signo = SIGTRAP;
18837 info->si_code = si_code;
18838 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18839 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18840 }
18841
18842 void user_single_step_siginfo(struct task_struct *tsk,
18843 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18844 # define IS_IA32 0
18845 #endif
18846
18847 +#ifdef CONFIG_GRKERNSEC_SETXID
18848 +extern void gr_delayed_cred_worker(void);
18849 +#endif
18850 +
18851 /*
18852 * We must return the syscall number to actually look up in the table.
18853 * This can be -1L to skip running any syscall at all.
18854 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18855 {
18856 long ret = 0;
18857
18858 +#ifdef CONFIG_GRKERNSEC_SETXID
18859 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18860 + gr_delayed_cred_worker();
18861 +#endif
18862 +
18863 /*
18864 * If we stepped into a sysenter/syscall insn, it trapped in
18865 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18866 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18867 {
18868 bool step;
18869
18870 +#ifdef CONFIG_GRKERNSEC_SETXID
18871 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18872 + gr_delayed_cred_worker();
18873 +#endif
18874 +
18875 audit_syscall_exit(regs);
18876
18877 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18878 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18879 index 42eb330..139955c 100644
18880 --- a/arch/x86/kernel/pvclock.c
18881 +++ b/arch/x86/kernel/pvclock.c
18882 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18883 return pv_tsc_khz;
18884 }
18885
18886 -static atomic64_t last_value = ATOMIC64_INIT(0);
18887 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18888
18889 void pvclock_resume(void)
18890 {
18891 - atomic64_set(&last_value, 0);
18892 + atomic64_set_unchecked(&last_value, 0);
18893 }
18894
18895 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18896 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18897 * updating at the same time, and one of them could be slightly behind,
18898 * making the assumption that last_value always go forward fail to hold.
18899 */
18900 - last = atomic64_read(&last_value);
18901 + last = atomic64_read_unchecked(&last_value);
18902 do {
18903 if (ret < last)
18904 return last;
18905 - last = atomic64_cmpxchg(&last_value, last, ret);
18906 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18907 } while (unlikely(last != ret));
18908
18909 return ret;
18910 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18911 index 52190a9..8074389 100644
18912 --- a/arch/x86/kernel/reboot.c
18913 +++ b/arch/x86/kernel/reboot.c
18914 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18915 EXPORT_SYMBOL(pm_power_off);
18916
18917 static const struct desc_ptr no_idt = {};
18918 -static int reboot_mode;
18919 +static unsigned short reboot_mode;
18920 enum reboot_type reboot_type = BOOT_ACPI;
18921 int reboot_force;
18922
18923 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18924
18925 void __noreturn machine_real_restart(unsigned int type)
18926 {
18927 +
18928 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18929 + struct desc_struct *gdt;
18930 +#endif
18931 +
18932 local_irq_disable();
18933
18934 /*
18935 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18936
18937 /* Jump to the identity-mapped low memory code */
18938 #ifdef CONFIG_X86_32
18939 - asm volatile("jmpl *%0" : :
18940 +
18941 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18942 + gdt = get_cpu_gdt_table(smp_processor_id());
18943 + pax_open_kernel();
18944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18945 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18946 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18947 + loadsegment(ds, __KERNEL_DS);
18948 + loadsegment(es, __KERNEL_DS);
18949 + loadsegment(ss, __KERNEL_DS);
18950 +#endif
18951 +#ifdef CONFIG_PAX_KERNEXEC
18952 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18953 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18954 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18955 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18956 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18957 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18958 +#endif
18959 + pax_close_kernel();
18960 +#endif
18961 +
18962 + asm volatile("ljmpl *%0" : :
18963 "rm" (real_mode_header->machine_real_restart_asm),
18964 "a" (type));
18965 #else
18966 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18967 * try to force a triple fault and then cycle between hitting the keyboard
18968 * controller and doing that
18969 */
18970 -static void native_machine_emergency_restart(void)
18971 +static void __noreturn native_machine_emergency_restart(void)
18972 {
18973 int i;
18974 int attempt = 0;
18975 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18976 #endif
18977 }
18978
18979 -static void __machine_emergency_restart(int emergency)
18980 +static void __noreturn __machine_emergency_restart(int emergency)
18981 {
18982 reboot_emergency = emergency;
18983 machine_ops.emergency_restart();
18984 }
18985
18986 -static void native_machine_restart(char *__unused)
18987 +static void __noreturn native_machine_restart(char *__unused)
18988 {
18989 pr_notice("machine restart\n");
18990
18991 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18992 __machine_emergency_restart(0);
18993 }
18994
18995 -static void native_machine_halt(void)
18996 +static void __noreturn native_machine_halt(void)
18997 {
18998 /* Stop other cpus and apics */
18999 machine_shutdown();
19000 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
19001 stop_this_cpu(NULL);
19002 }
19003
19004 -static void native_machine_power_off(void)
19005 +static void __noreturn native_machine_power_off(void)
19006 {
19007 if (pm_power_off) {
19008 if (!reboot_force)
19009 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19010 }
19011 /* A fallback in case there is no PM info available */
19012 tboot_shutdown(TB_SHUTDOWN_HALT);
19013 + unreachable();
19014 }
19015
19016 struct machine_ops machine_ops = {
19017 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19018 index 7a6f3b3..bed145d7 100644
19019 --- a/arch/x86/kernel/relocate_kernel_64.S
19020 +++ b/arch/x86/kernel/relocate_kernel_64.S
19021 @@ -11,6 +11,7 @@
19022 #include <asm/kexec.h>
19023 #include <asm/processor-flags.h>
19024 #include <asm/pgtable_types.h>
19025 +#include <asm/alternative-asm.h>
19026
19027 /*
19028 * Must be relocatable PIC code callable as a C function
19029 @@ -160,13 +161,14 @@ identity_mapped:
19030 xorq %rbp, %rbp
19031 xorq %r8, %r8
19032 xorq %r9, %r9
19033 - xorq %r10, %r9
19034 + xorq %r10, %r10
19035 xorq %r11, %r11
19036 xorq %r12, %r12
19037 xorq %r13, %r13
19038 xorq %r14, %r14
19039 xorq %r15, %r15
19040
19041 + pax_force_retaddr 0, 1
19042 ret
19043
19044 1:
19045 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19046 index 5cee802..bc22bc3 100644
19047 --- a/arch/x86/kernel/setup.c
19048 +++ b/arch/x86/kernel/setup.c
19049 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19050
19051 switch (data->type) {
19052 case SETUP_E820_EXT:
19053 - parse_e820_ext(data);
19054 + parse_e820_ext((struct setup_data __force_kernel *)data);
19055 break;
19056 case SETUP_DTB:
19057 add_dtb(pa_data);
19058 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19059 * area (640->1Mb) as ram even though it is not.
19060 * take them out.
19061 */
19062 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19063 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19064 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19065 }
19066
19067 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19068
19069 if (!boot_params.hdr.root_flags)
19070 root_mountflags &= ~MS_RDONLY;
19071 - init_mm.start_code = (unsigned long) _text;
19072 - init_mm.end_code = (unsigned long) _etext;
19073 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19074 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19075 init_mm.end_data = (unsigned long) _edata;
19076 init_mm.brk = _brk_end;
19077
19078 - code_resource.start = virt_to_phys(_text);
19079 - code_resource.end = virt_to_phys(_etext)-1;
19080 - data_resource.start = virt_to_phys(_etext);
19081 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19082 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19083 + data_resource.start = virt_to_phys(_sdata);
19084 data_resource.end = virt_to_phys(_edata)-1;
19085 bss_resource.start = virt_to_phys(&__bss_start);
19086 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19087 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19088 index 5cdff03..5810740 100644
19089 --- a/arch/x86/kernel/setup_percpu.c
19090 +++ b/arch/x86/kernel/setup_percpu.c
19091 @@ -21,19 +21,17 @@
19092 #include <asm/cpu.h>
19093 #include <asm/stackprotector.h>
19094
19095 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19096 +#ifdef CONFIG_SMP
19097 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19098 EXPORT_PER_CPU_SYMBOL(cpu_number);
19099 +#endif
19100
19101 -#ifdef CONFIG_X86_64
19102 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19103 -#else
19104 -#define BOOT_PERCPU_OFFSET 0
19105 -#endif
19106
19107 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19108 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19109
19110 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19111 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19112 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19113 };
19114 EXPORT_SYMBOL(__per_cpu_offset);
19115 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19116 {
19117 #ifdef CONFIG_X86_32
19118 struct desc_struct gdt;
19119 + unsigned long base = per_cpu_offset(cpu);
19120
19121 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19122 - 0x2 | DESCTYPE_S, 0x8);
19123 - gdt.s = 1;
19124 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19125 + 0x83 | DESCTYPE_S, 0xC);
19126 write_gdt_entry(get_cpu_gdt_table(cpu),
19127 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19128 #endif
19129 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19130 /* alrighty, percpu areas up and running */
19131 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19132 for_each_possible_cpu(cpu) {
19133 +#ifdef CONFIG_CC_STACKPROTECTOR
19134 +#ifdef CONFIG_X86_32
19135 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19136 +#endif
19137 +#endif
19138 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19139 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19140 per_cpu(cpu_number, cpu) = cpu;
19141 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19142 */
19143 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19144 #endif
19145 +#ifdef CONFIG_CC_STACKPROTECTOR
19146 +#ifdef CONFIG_X86_32
19147 + if (!cpu)
19148 + per_cpu(stack_canary.canary, cpu) = canary;
19149 +#endif
19150 +#endif
19151 /*
19152 * Up to this point, the boot CPU has been using .init.data
19153 * area. Reload any changed state for the boot CPU.
19154 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19155 index b280908..6de349e 100644
19156 --- a/arch/x86/kernel/signal.c
19157 +++ b/arch/x86/kernel/signal.c
19158 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19159 * Align the stack pointer according to the i386 ABI,
19160 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19161 */
19162 - sp = ((sp + 4) & -16ul) - 4;
19163 + sp = ((sp - 12) & -16ul) - 4;
19164 #else /* !CONFIG_X86_32 */
19165 sp = round_down(sp, 16) - 8;
19166 #endif
19167 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19168 * Return an always-bogus address instead so we will die with SIGSEGV.
19169 */
19170 if (onsigstack && !likely(on_sig_stack(sp)))
19171 - return (void __user *)-1L;
19172 + return (__force void __user *)-1L;
19173
19174 /* save i387 state */
19175 if (used_math() && save_i387_xstate(*fpstate) < 0)
19176 - return (void __user *)-1L;
19177 + return (__force void __user *)-1L;
19178
19179 return (void __user *)sp;
19180 }
19181 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19182 }
19183
19184 if (current->mm->context.vdso)
19185 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19186 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19187 else
19188 - restorer = &frame->retcode;
19189 + restorer = (void __user *)&frame->retcode;
19190 if (ka->sa.sa_flags & SA_RESTORER)
19191 restorer = ka->sa.sa_restorer;
19192
19193 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19194 * reasons and because gdb uses it as a signature to notice
19195 * signal handler stack frames.
19196 */
19197 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19198 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19199
19200 if (err)
19201 return -EFAULT;
19202 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19203 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19204
19205 /* Set up to return from userspace. */
19206 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19207 + if (current->mm->context.vdso)
19208 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19209 + else
19210 + restorer = (void __user *)&frame->retcode;
19211 if (ka->sa.sa_flags & SA_RESTORER)
19212 restorer = ka->sa.sa_restorer;
19213 put_user_ex(restorer, &frame->pretcode);
19214 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19215 * reasons and because gdb uses it as a signature to notice
19216 * signal handler stack frames.
19217 */
19218 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19219 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19220 } put_user_catch(err);
19221
19222 if (err)
19223 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19224 index 7c5a8c3..88d422f 100644
19225 --- a/arch/x86/kernel/smpboot.c
19226 +++ b/arch/x86/kernel/smpboot.c
19227 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19228 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19229 (THREAD_SIZE + task_stack_page(idle))) - 1);
19230 per_cpu(current_task, cpu) = idle;
19231 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19232
19233 #ifdef CONFIG_X86_32
19234 /* Stack for startup_32 can be just as for start_secondary onwards */
19235 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19236 #else
19237 clear_tsk_thread_flag(idle, TIF_FORK);
19238 initial_gs = per_cpu_offset(cpu);
19239 - per_cpu(kernel_stack, cpu) =
19240 - (unsigned long)task_stack_page(idle) -
19241 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19242 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19243 #endif
19244 +
19245 + pax_open_kernel();
19246 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19247 + pax_close_kernel();
19248 +
19249 initial_code = (unsigned long)start_secondary;
19250 stack_start = idle->thread.sp;
19251
19252 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19253
19254 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19255
19256 +#ifdef CONFIG_PAX_PER_CPU_PGD
19257 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19258 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19259 + KERNEL_PGD_PTRS);
19260 +#endif
19261 +
19262 err = do_boot_cpu(apicid, cpu, tidle);
19263 if (err) {
19264 pr_debug("do_boot_cpu failed %d\n", err);
19265 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19266 index c346d11..d43b163 100644
19267 --- a/arch/x86/kernel/step.c
19268 +++ b/arch/x86/kernel/step.c
19269 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19270 struct desc_struct *desc;
19271 unsigned long base;
19272
19273 - seg &= ~7UL;
19274 + seg >>= 3;
19275
19276 mutex_lock(&child->mm->context.lock);
19277 - if (unlikely((seg >> 3) >= child->mm->context.size))
19278 + if (unlikely(seg >= child->mm->context.size))
19279 addr = -1L; /* bogus selector, access would fault */
19280 else {
19281 desc = child->mm->context.ldt + seg;
19282 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19283 addr += base;
19284 }
19285 mutex_unlock(&child->mm->context.lock);
19286 - }
19287 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19288 + addr = ktla_ktva(addr);
19289
19290 return addr;
19291 }
19292 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19293 unsigned char opcode[15];
19294 unsigned long addr = convert_ip_to_linear(child, regs);
19295
19296 + if (addr == -EINVAL)
19297 + return 0;
19298 +
19299 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19300 for (i = 0; i < copied; i++) {
19301 switch (opcode[i]) {
19302 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19303 index 0b0cb5f..db6b9ed 100644
19304 --- a/arch/x86/kernel/sys_i386_32.c
19305 +++ b/arch/x86/kernel/sys_i386_32.c
19306 @@ -24,17 +24,224 @@
19307
19308 #include <asm/syscalls.h>
19309
19310 -/*
19311 - * Do a system call from kernel instead of calling sys_execve so we
19312 - * end up with proper pt_regs.
19313 - */
19314 -int kernel_execve(const char *filename,
19315 - const char *const argv[],
19316 - const char *const envp[])
19317 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19318 {
19319 - long __res;
19320 - asm volatile ("int $0x80"
19321 - : "=a" (__res)
19322 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19323 - return __res;
19324 + unsigned long pax_task_size = TASK_SIZE;
19325 +
19326 +#ifdef CONFIG_PAX_SEGMEXEC
19327 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19328 + pax_task_size = SEGMEXEC_TASK_SIZE;
19329 +#endif
19330 +
19331 + if (len > pax_task_size || addr > pax_task_size - len)
19332 + return -EINVAL;
19333 +
19334 + return 0;
19335 +}
19336 +
19337 +unsigned long
19338 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19339 + unsigned long len, unsigned long pgoff, unsigned long flags)
19340 +{
19341 + struct mm_struct *mm = current->mm;
19342 + struct vm_area_struct *vma;
19343 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19344 +
19345 +#ifdef CONFIG_PAX_SEGMEXEC
19346 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19347 + pax_task_size = SEGMEXEC_TASK_SIZE;
19348 +#endif
19349 +
19350 + pax_task_size -= PAGE_SIZE;
19351 +
19352 + if (len > pax_task_size)
19353 + return -ENOMEM;
19354 +
19355 + if (flags & MAP_FIXED)
19356 + return addr;
19357 +
19358 +#ifdef CONFIG_PAX_RANDMMAP
19359 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19360 +#endif
19361 +
19362 + if (addr) {
19363 + addr = PAGE_ALIGN(addr);
19364 + if (pax_task_size - len >= addr) {
19365 + vma = find_vma(mm, addr);
19366 + if (check_heap_stack_gap(vma, addr, len))
19367 + return addr;
19368 + }
19369 + }
19370 + if (len > mm->cached_hole_size) {
19371 + start_addr = addr = mm->free_area_cache;
19372 + } else {
19373 + start_addr = addr = mm->mmap_base;
19374 + mm->cached_hole_size = 0;
19375 + }
19376 +
19377 +#ifdef CONFIG_PAX_PAGEEXEC
19378 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19379 + start_addr = 0x00110000UL;
19380 +
19381 +#ifdef CONFIG_PAX_RANDMMAP
19382 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19383 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19384 +#endif
19385 +
19386 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19387 + start_addr = addr = mm->mmap_base;
19388 + else
19389 + addr = start_addr;
19390 + }
19391 +#endif
19392 +
19393 +full_search:
19394 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19395 + /* At this point: (!vma || addr < vma->vm_end). */
19396 + if (pax_task_size - len < addr) {
19397 + /*
19398 + * Start a new search - just in case we missed
19399 + * some holes.
19400 + */
19401 + if (start_addr != mm->mmap_base) {
19402 + start_addr = addr = mm->mmap_base;
19403 + mm->cached_hole_size = 0;
19404 + goto full_search;
19405 + }
19406 + return -ENOMEM;
19407 + }
19408 + if (check_heap_stack_gap(vma, addr, len))
19409 + break;
19410 + if (addr + mm->cached_hole_size < vma->vm_start)
19411 + mm->cached_hole_size = vma->vm_start - addr;
19412 + addr = vma->vm_end;
19413 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19414 + start_addr = addr = mm->mmap_base;
19415 + mm->cached_hole_size = 0;
19416 + goto full_search;
19417 + }
19418 + }
19419 +
19420 + /*
19421 + * Remember the place where we stopped the search:
19422 + */
19423 + mm->free_area_cache = addr + len;
19424 + return addr;
19425 +}
19426 +
19427 +unsigned long
19428 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19429 + const unsigned long len, const unsigned long pgoff,
19430 + const unsigned long flags)
19431 +{
19432 + struct vm_area_struct *vma;
19433 + struct mm_struct *mm = current->mm;
19434 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19435 +
19436 +#ifdef CONFIG_PAX_SEGMEXEC
19437 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19438 + pax_task_size = SEGMEXEC_TASK_SIZE;
19439 +#endif
19440 +
19441 + pax_task_size -= PAGE_SIZE;
19442 +
19443 + /* requested length too big for entire address space */
19444 + if (len > pax_task_size)
19445 + return -ENOMEM;
19446 +
19447 + if (flags & MAP_FIXED)
19448 + return addr;
19449 +
19450 +#ifdef CONFIG_PAX_PAGEEXEC
19451 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19452 + goto bottomup;
19453 +#endif
19454 +
19455 +#ifdef CONFIG_PAX_RANDMMAP
19456 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19457 +#endif
19458 +
19459 + /* requesting a specific address */
19460 + if (addr) {
19461 + addr = PAGE_ALIGN(addr);
19462 + if (pax_task_size - len >= addr) {
19463 + vma = find_vma(mm, addr);
19464 + if (check_heap_stack_gap(vma, addr, len))
19465 + return addr;
19466 + }
19467 + }
19468 +
19469 + /* check if free_area_cache is useful for us */
19470 + if (len <= mm->cached_hole_size) {
19471 + mm->cached_hole_size = 0;
19472 + mm->free_area_cache = mm->mmap_base;
19473 + }
19474 +
19475 + /* either no address requested or can't fit in requested address hole */
19476 + addr = mm->free_area_cache;
19477 +
19478 + /* make sure it can fit in the remaining address space */
19479 + if (addr > len) {
19480 + vma = find_vma(mm, addr-len);
19481 + if (check_heap_stack_gap(vma, addr - len, len))
19482 + /* remember the address as a hint for next time */
19483 + return (mm->free_area_cache = addr-len);
19484 + }
19485 +
19486 + if (mm->mmap_base < len)
19487 + goto bottomup;
19488 +
19489 + addr = mm->mmap_base-len;
19490 +
19491 + do {
19492 + /*
19493 + * Lookup failure means no vma is above this address,
19494 + * else if new region fits below vma->vm_start,
19495 + * return with success:
19496 + */
19497 + vma = find_vma(mm, addr);
19498 + if (check_heap_stack_gap(vma, addr, len))
19499 + /* remember the address as a hint for next time */
19500 + return (mm->free_area_cache = addr);
19501 +
19502 + /* remember the largest hole we saw so far */
19503 + if (addr + mm->cached_hole_size < vma->vm_start)
19504 + mm->cached_hole_size = vma->vm_start - addr;
19505 +
19506 + /* try just below the current vma->vm_start */
19507 + addr = skip_heap_stack_gap(vma, len);
19508 + } while (!IS_ERR_VALUE(addr));
19509 +
19510 +bottomup:
19511 + /*
19512 + * A failed mmap() very likely causes application failure,
19513 + * so fall back to the bottom-up function here. This scenario
19514 + * can happen with large stack limits and large mmap()
19515 + * allocations.
19516 + */
19517 +
19518 +#ifdef CONFIG_PAX_SEGMEXEC
19519 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19520 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19521 + else
19522 +#endif
19523 +
19524 + mm->mmap_base = TASK_UNMAPPED_BASE;
19525 +
19526 +#ifdef CONFIG_PAX_RANDMMAP
19527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19528 + mm->mmap_base += mm->delta_mmap;
19529 +#endif
19530 +
19531 + mm->free_area_cache = mm->mmap_base;
19532 + mm->cached_hole_size = ~0UL;
19533 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19534 + /*
19535 + * Restore the topdown base:
19536 + */
19537 + mm->mmap_base = base;
19538 + mm->free_area_cache = base;
19539 + mm->cached_hole_size = ~0UL;
19540 +
19541 + return addr;
19542 }
19543 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19544 index b4d3c39..82bb73b 100644
19545 --- a/arch/x86/kernel/sys_x86_64.c
19546 +++ b/arch/x86/kernel/sys_x86_64.c
19547 @@ -95,8 +95,8 @@ out:
19548 return error;
19549 }
19550
19551 -static void find_start_end(unsigned long flags, unsigned long *begin,
19552 - unsigned long *end)
19553 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19554 + unsigned long *begin, unsigned long *end)
19555 {
19556 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19557 unsigned long new_begin;
19558 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19559 *begin = new_begin;
19560 }
19561 } else {
19562 - *begin = TASK_UNMAPPED_BASE;
19563 + *begin = mm->mmap_base;
19564 *end = TASK_SIZE;
19565 }
19566 }
19567 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19568 if (flags & MAP_FIXED)
19569 return addr;
19570
19571 - find_start_end(flags, &begin, &end);
19572 + find_start_end(mm, flags, &begin, &end);
19573
19574 if (len > end)
19575 return -ENOMEM;
19576
19577 +#ifdef CONFIG_PAX_RANDMMAP
19578 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19579 +#endif
19580 +
19581 if (addr) {
19582 addr = PAGE_ALIGN(addr);
19583 vma = find_vma(mm, addr);
19584 - if (end - len >= addr &&
19585 - (!vma || addr + len <= vma->vm_start))
19586 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19587 return addr;
19588 }
19589 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19590 @@ -172,7 +175,7 @@ full_search:
19591 }
19592 return -ENOMEM;
19593 }
19594 - if (!vma || addr + len <= vma->vm_start) {
19595 + if (check_heap_stack_gap(vma, addr, len)) {
19596 /*
19597 * Remember the place where we stopped the search:
19598 */
19599 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19600 {
19601 struct vm_area_struct *vma;
19602 struct mm_struct *mm = current->mm;
19603 - unsigned long addr = addr0, start_addr;
19604 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19605
19606 /* requested length too big for entire address space */
19607 if (len > TASK_SIZE)
19608 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19609 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19610 goto bottomup;
19611
19612 +#ifdef CONFIG_PAX_RANDMMAP
19613 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19614 +#endif
19615 +
19616 /* requesting a specific address */
19617 if (addr) {
19618 addr = PAGE_ALIGN(addr);
19619 - vma = find_vma(mm, addr);
19620 - if (TASK_SIZE - len >= addr &&
19621 - (!vma || addr + len <= vma->vm_start))
19622 - return addr;
19623 + if (TASK_SIZE - len >= addr) {
19624 + vma = find_vma(mm, addr);
19625 + if (check_heap_stack_gap(vma, addr, len))
19626 + return addr;
19627 + }
19628 }
19629
19630 /* check if free_area_cache is useful for us */
19631 @@ -240,7 +248,7 @@ try_again:
19632 * return with success:
19633 */
19634 vma = find_vma(mm, addr);
19635 - if (!vma || addr+len <= vma->vm_start)
19636 + if (check_heap_stack_gap(vma, addr, len))
19637 /* remember the address as a hint for next time */
19638 return mm->free_area_cache = addr;
19639
19640 @@ -249,8 +257,8 @@ try_again:
19641 mm->cached_hole_size = vma->vm_start - addr;
19642
19643 /* try just below the current vma->vm_start */
19644 - addr = vma->vm_start-len;
19645 - } while (len < vma->vm_start);
19646 + addr = skip_heap_stack_gap(vma, len);
19647 + } while (!IS_ERR_VALUE(addr));
19648
19649 fail:
19650 /*
19651 @@ -270,13 +278,21 @@ bottomup:
19652 * can happen with large stack limits and large mmap()
19653 * allocations.
19654 */
19655 + mm->mmap_base = TASK_UNMAPPED_BASE;
19656 +
19657 +#ifdef CONFIG_PAX_RANDMMAP
19658 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19659 + mm->mmap_base += mm->delta_mmap;
19660 +#endif
19661 +
19662 + mm->free_area_cache = mm->mmap_base;
19663 mm->cached_hole_size = ~0UL;
19664 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19665 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19666 /*
19667 * Restore the topdown base:
19668 */
19669 - mm->free_area_cache = mm->mmap_base;
19670 + mm->mmap_base = base;
19671 + mm->free_area_cache = base;
19672 mm->cached_hole_size = ~0UL;
19673
19674 return addr;
19675 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19676 index f84fe00..93fe08f 100644
19677 --- a/arch/x86/kernel/tboot.c
19678 +++ b/arch/x86/kernel/tboot.c
19679 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19680
19681 void tboot_shutdown(u32 shutdown_type)
19682 {
19683 - void (*shutdown)(void);
19684 + void (* __noreturn shutdown)(void);
19685
19686 if (!tboot_enabled())
19687 return;
19688 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19689
19690 switch_to_tboot_pt();
19691
19692 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19693 + shutdown = (void *)tboot->shutdown_entry;
19694 shutdown();
19695
19696 /* should not reach here */
19697 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19698 return 0;
19699 }
19700
19701 -static atomic_t ap_wfs_count;
19702 +static atomic_unchecked_t ap_wfs_count;
19703
19704 static int tboot_wait_for_aps(int num_aps)
19705 {
19706 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19707 {
19708 switch (action) {
19709 case CPU_DYING:
19710 - atomic_inc(&ap_wfs_count);
19711 + atomic_inc_unchecked(&ap_wfs_count);
19712 if (num_online_cpus() == 1)
19713 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19714 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19715 return NOTIFY_BAD;
19716 break;
19717 }
19718 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19719
19720 tboot_create_trampoline();
19721
19722 - atomic_set(&ap_wfs_count, 0);
19723 + atomic_set_unchecked(&ap_wfs_count, 0);
19724 register_hotcpu_notifier(&tboot_cpu_notifier);
19725
19726 acpi_os_set_prepare_sleep(&tboot_sleep);
19727 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19728 index 24d3c91..d06b473 100644
19729 --- a/arch/x86/kernel/time.c
19730 +++ b/arch/x86/kernel/time.c
19731 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19732 {
19733 unsigned long pc = instruction_pointer(regs);
19734
19735 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19736 + if (!user_mode(regs) && in_lock_functions(pc)) {
19737 #ifdef CONFIG_FRAME_POINTER
19738 - return *(unsigned long *)(regs->bp + sizeof(long));
19739 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19740 #else
19741 unsigned long *sp =
19742 (unsigned long *)kernel_stack_pointer(regs);
19743 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19744 * or above a saved flags. Eflags has bits 22-31 zero,
19745 * kernel addresses don't.
19746 */
19747 +
19748 +#ifdef CONFIG_PAX_KERNEXEC
19749 + return ktla_ktva(sp[0]);
19750 +#else
19751 if (sp[0] >> 22)
19752 return sp[0];
19753 if (sp[1] >> 22)
19754 return sp[1];
19755 #endif
19756 +
19757 +#endif
19758 }
19759 return pc;
19760 }
19761 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19762 index 9d9d2f9..cad418a 100644
19763 --- a/arch/x86/kernel/tls.c
19764 +++ b/arch/x86/kernel/tls.c
19765 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19766 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19767 return -EINVAL;
19768
19769 +#ifdef CONFIG_PAX_SEGMEXEC
19770 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19771 + return -EINVAL;
19772 +#endif
19773 +
19774 set_tls_desc(p, idx, &info, 1);
19775
19776 return 0;
19777 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19778
19779 if (kbuf)
19780 info = kbuf;
19781 - else if (__copy_from_user(infobuf, ubuf, count))
19782 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19783 return -EFAULT;
19784 else
19785 info = infobuf;
19786 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19787 index b481341..5918bbe 100644
19788 --- a/arch/x86/kernel/traps.c
19789 +++ b/arch/x86/kernel/traps.c
19790 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19791
19792 /* Do we ignore FPU interrupts ? */
19793 char ignore_fpu_irq;
19794 -
19795 -/*
19796 - * The IDT has to be page-aligned to simplify the Pentium
19797 - * F0 0F bug workaround.
19798 - */
19799 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19800 #endif
19801
19802 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19803 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19804 }
19805
19806 static void __kprobes
19807 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19808 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19809 long error_code, siginfo_t *info)
19810 {
19811 struct task_struct *tsk = current;
19812
19813 #ifdef CONFIG_X86_32
19814 - if (regs->flags & X86_VM_MASK) {
19815 + if (v8086_mode(regs)) {
19816 /*
19817 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19818 * On nmi (interrupt 2), do_trap should not be called.
19819 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19820 }
19821 #endif
19822
19823 - if (!user_mode(regs))
19824 + if (!user_mode_novm(regs))
19825 goto kernel_trap;
19826
19827 #ifdef CONFIG_X86_32
19828 @@ -147,7 +141,7 @@ trap_signal:
19829 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19830 printk_ratelimit()) {
19831 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19832 - tsk->comm, tsk->pid, str,
19833 + tsk->comm, task_pid_nr(tsk), str,
19834 regs->ip, regs->sp, error_code);
19835 print_vma_addr(" in ", regs->ip);
19836 pr_cont("\n");
19837 @@ -164,8 +158,20 @@ kernel_trap:
19838 if (!fixup_exception(regs)) {
19839 tsk->thread.error_code = error_code;
19840 tsk->thread.trap_nr = trapnr;
19841 +
19842 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19843 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19844 + str = "PAX: suspicious stack segment fault";
19845 +#endif
19846 +
19847 die(str, regs, error_code);
19848 }
19849 +
19850 +#ifdef CONFIG_PAX_REFCOUNT
19851 + if (trapnr == 4)
19852 + pax_report_refcount_overflow(regs);
19853 +#endif
19854 +
19855 return;
19856
19857 #ifdef CONFIG_X86_32
19858 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19859 conditional_sti(regs);
19860
19861 #ifdef CONFIG_X86_32
19862 - if (regs->flags & X86_VM_MASK)
19863 + if (v8086_mode(regs))
19864 goto gp_in_vm86;
19865 #endif
19866
19867 tsk = current;
19868 - if (!user_mode(regs))
19869 + if (!user_mode_novm(regs))
19870 goto gp_in_kernel;
19871
19872 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19873 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19874 + struct mm_struct *mm = tsk->mm;
19875 + unsigned long limit;
19876 +
19877 + down_write(&mm->mmap_sem);
19878 + limit = mm->context.user_cs_limit;
19879 + if (limit < TASK_SIZE) {
19880 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19881 + up_write(&mm->mmap_sem);
19882 + return;
19883 + }
19884 + up_write(&mm->mmap_sem);
19885 + }
19886 +#endif
19887 +
19888 tsk->thread.error_code = error_code;
19889 tsk->thread.trap_nr = X86_TRAP_GP;
19890
19891 @@ -297,6 +319,13 @@ gp_in_kernel:
19892 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19893 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19894 return;
19895 +
19896 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19897 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19898 + die("PAX: suspicious general protection fault", regs, error_code);
19899 + else
19900 +#endif
19901 +
19902 die("general protection fault", regs, error_code);
19903 }
19904
19905 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19906 /* It's safe to allow irq's after DR6 has been saved */
19907 preempt_conditional_sti(regs);
19908
19909 - if (regs->flags & X86_VM_MASK) {
19910 + if (v8086_mode(regs)) {
19911 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19912 X86_TRAP_DB);
19913 preempt_conditional_cli(regs);
19914 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19915 * We already checked v86 mode above, so we can check for kernel mode
19916 * by just checking the CPL of CS.
19917 */
19918 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19919 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19920 tsk->thread.debugreg6 &= ~DR_STEP;
19921 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19922 regs->flags &= ~X86_EFLAGS_TF;
19923 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19924 return;
19925 conditional_sti(regs);
19926
19927 - if (!user_mode_vm(regs))
19928 + if (!user_mode(regs))
19929 {
19930 if (!fixup_exception(regs)) {
19931 task->thread.error_code = error_code;
19932 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19933 index 36fd420..7e5892d 100644
19934 --- a/arch/x86/kernel/uprobes.c
19935 +++ b/arch/x86/kernel/uprobes.c
19936 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19937 int ret = NOTIFY_DONE;
19938
19939 /* We are only interested in userspace traps */
19940 - if (regs && !user_mode_vm(regs))
19941 + if (regs && !user_mode(regs))
19942 return NOTIFY_DONE;
19943
19944 switch (val) {
19945 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19946 index b9242ba..50c5edd 100644
19947 --- a/arch/x86/kernel/verify_cpu.S
19948 +++ b/arch/x86/kernel/verify_cpu.S
19949 @@ -20,6 +20,7 @@
19950 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19951 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19952 * arch/x86/kernel/head_32.S: processor startup
19953 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19954 *
19955 * verify_cpu, returns the status of longmode and SSE in register %eax.
19956 * 0: Success 1: Failure
19957 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19958 index 54abcc0..eb6c848 100644
19959 --- a/arch/x86/kernel/vm86_32.c
19960 +++ b/arch/x86/kernel/vm86_32.c
19961 @@ -43,6 +43,7 @@
19962 #include <linux/ptrace.h>
19963 #include <linux/audit.h>
19964 #include <linux/stddef.h>
19965 +#include <linux/grsecurity.h>
19966
19967 #include <asm/uaccess.h>
19968 #include <asm/io.h>
19969 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19970 do_exit(SIGSEGV);
19971 }
19972
19973 - tss = &per_cpu(init_tss, get_cpu());
19974 + tss = init_tss + get_cpu();
19975 current->thread.sp0 = current->thread.saved_sp0;
19976 current->thread.sysenter_cs = __KERNEL_CS;
19977 load_sp0(tss, &current->thread);
19978 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19979 struct task_struct *tsk;
19980 int tmp, ret = -EPERM;
19981
19982 +#ifdef CONFIG_GRKERNSEC_VM86
19983 + if (!capable(CAP_SYS_RAWIO)) {
19984 + gr_handle_vm86();
19985 + goto out;
19986 + }
19987 +#endif
19988 +
19989 tsk = current;
19990 if (tsk->thread.saved_sp0)
19991 goto out;
19992 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19993 int tmp, ret;
19994 struct vm86plus_struct __user *v86;
19995
19996 +#ifdef CONFIG_GRKERNSEC_VM86
19997 + if (!capable(CAP_SYS_RAWIO)) {
19998 + gr_handle_vm86();
19999 + ret = -EPERM;
20000 + goto out;
20001 + }
20002 +#endif
20003 +
20004 tsk = current;
20005 switch (cmd) {
20006 case VM86_REQUEST_IRQ:
20007 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20008 tsk->thread.saved_fs = info->regs32->fs;
20009 tsk->thread.saved_gs = get_user_gs(info->regs32);
20010
20011 - tss = &per_cpu(init_tss, get_cpu());
20012 + tss = init_tss + get_cpu();
20013 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20014 if (cpu_has_sep)
20015 tsk->thread.sysenter_cs = 0;
20016 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20017 goto cannot_handle;
20018 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20019 goto cannot_handle;
20020 - intr_ptr = (unsigned long __user *) (i << 2);
20021 + intr_ptr = (__force unsigned long __user *) (i << 2);
20022 if (get_user(segoffs, intr_ptr))
20023 goto cannot_handle;
20024 if ((segoffs >> 16) == BIOSSEG)
20025 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20026 index 22a1530..8fbaaad 100644
20027 --- a/arch/x86/kernel/vmlinux.lds.S
20028 +++ b/arch/x86/kernel/vmlinux.lds.S
20029 @@ -26,6 +26,13 @@
20030 #include <asm/page_types.h>
20031 #include <asm/cache.h>
20032 #include <asm/boot.h>
20033 +#include <asm/segment.h>
20034 +
20035 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20036 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20037 +#else
20038 +#define __KERNEL_TEXT_OFFSET 0
20039 +#endif
20040
20041 #undef i386 /* in case the preprocessor is a 32bit one */
20042
20043 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20044
20045 PHDRS {
20046 text PT_LOAD FLAGS(5); /* R_E */
20047 +#ifdef CONFIG_X86_32
20048 + module PT_LOAD FLAGS(5); /* R_E */
20049 +#endif
20050 +#ifdef CONFIG_XEN
20051 + rodata PT_LOAD FLAGS(5); /* R_E */
20052 +#else
20053 + rodata PT_LOAD FLAGS(4); /* R__ */
20054 +#endif
20055 data PT_LOAD FLAGS(6); /* RW_ */
20056 -#ifdef CONFIG_X86_64
20057 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20058 #ifdef CONFIG_SMP
20059 percpu PT_LOAD FLAGS(6); /* RW_ */
20060 #endif
20061 + text.init PT_LOAD FLAGS(5); /* R_E */
20062 + text.exit PT_LOAD FLAGS(5); /* R_E */
20063 init PT_LOAD FLAGS(7); /* RWE */
20064 -#endif
20065 note PT_NOTE FLAGS(0); /* ___ */
20066 }
20067
20068 SECTIONS
20069 {
20070 #ifdef CONFIG_X86_32
20071 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20072 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20073 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20074 #else
20075 - . = __START_KERNEL;
20076 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20077 + . = __START_KERNEL;
20078 #endif
20079
20080 /* Text and read-only data */
20081 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20082 - _text = .;
20083 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20084 /* bootstrapping code */
20085 +#ifdef CONFIG_X86_32
20086 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20087 +#else
20088 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20089 +#endif
20090 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20091 + _text = .;
20092 HEAD_TEXT
20093 #ifdef CONFIG_X86_32
20094 . = ALIGN(PAGE_SIZE);
20095 @@ -108,13 +128,48 @@ SECTIONS
20096 IRQENTRY_TEXT
20097 *(.fixup)
20098 *(.gnu.warning)
20099 - /* End of text section */
20100 - _etext = .;
20101 } :text = 0x9090
20102
20103 - NOTES :text :note
20104 + . += __KERNEL_TEXT_OFFSET;
20105
20106 - EXCEPTION_TABLE(16) :text = 0x9090
20107 +#ifdef CONFIG_X86_32
20108 + . = ALIGN(PAGE_SIZE);
20109 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20110 +
20111 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20112 + MODULES_EXEC_VADDR = .;
20113 + BYTE(0)
20114 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20115 + . = ALIGN(HPAGE_SIZE) - 1;
20116 + MODULES_EXEC_END = .;
20117 +#endif
20118 +
20119 + } :module
20120 +#endif
20121 +
20122 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20123 + /* End of text section */
20124 + BYTE(0)
20125 + _etext = . - __KERNEL_TEXT_OFFSET;
20126 + }
20127 +
20128 +#ifdef CONFIG_X86_32
20129 + . = ALIGN(PAGE_SIZE);
20130 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20131 + *(.idt)
20132 + . = ALIGN(PAGE_SIZE);
20133 + *(.empty_zero_page)
20134 + *(.initial_pg_fixmap)
20135 + *(.initial_pg_pmd)
20136 + *(.initial_page_table)
20137 + *(.swapper_pg_dir)
20138 + } :rodata
20139 +#endif
20140 +
20141 + . = ALIGN(PAGE_SIZE);
20142 + NOTES :rodata :note
20143 +
20144 + EXCEPTION_TABLE(16) :rodata
20145
20146 #if defined(CONFIG_DEBUG_RODATA)
20147 /* .text should occupy whole number of pages */
20148 @@ -126,16 +181,20 @@ SECTIONS
20149
20150 /* Data */
20151 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20152 +
20153 +#ifdef CONFIG_PAX_KERNEXEC
20154 + . = ALIGN(HPAGE_SIZE);
20155 +#else
20156 + . = ALIGN(PAGE_SIZE);
20157 +#endif
20158 +
20159 /* Start of data section */
20160 _sdata = .;
20161
20162 /* init_task */
20163 INIT_TASK_DATA(THREAD_SIZE)
20164
20165 -#ifdef CONFIG_X86_32
20166 - /* 32 bit has nosave before _edata */
20167 NOSAVE_DATA
20168 -#endif
20169
20170 PAGE_ALIGNED_DATA(PAGE_SIZE)
20171
20172 @@ -176,12 +235,19 @@ SECTIONS
20173 #endif /* CONFIG_X86_64 */
20174
20175 /* Init code and data - will be freed after init */
20176 - . = ALIGN(PAGE_SIZE);
20177 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20178 + BYTE(0)
20179 +
20180 +#ifdef CONFIG_PAX_KERNEXEC
20181 + . = ALIGN(HPAGE_SIZE);
20182 +#else
20183 + . = ALIGN(PAGE_SIZE);
20184 +#endif
20185 +
20186 __init_begin = .; /* paired with __init_end */
20187 - }
20188 + } :init.begin
20189
20190 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20191 +#ifdef CONFIG_SMP
20192 /*
20193 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20194 * output PHDR, so the next output section - .init.text - should
20195 @@ -190,12 +256,27 @@ SECTIONS
20196 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20197 #endif
20198
20199 - INIT_TEXT_SECTION(PAGE_SIZE)
20200 -#ifdef CONFIG_X86_64
20201 - :init
20202 -#endif
20203 + . = ALIGN(PAGE_SIZE);
20204 + init_begin = .;
20205 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20206 + VMLINUX_SYMBOL(_sinittext) = .;
20207 + INIT_TEXT
20208 + VMLINUX_SYMBOL(_einittext) = .;
20209 + . = ALIGN(PAGE_SIZE);
20210 + } :text.init
20211
20212 - INIT_DATA_SECTION(16)
20213 + /*
20214 + * .exit.text is discard at runtime, not link time, to deal with
20215 + * references from .altinstructions and .eh_frame
20216 + */
20217 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20218 + EXIT_TEXT
20219 + . = ALIGN(16);
20220 + } :text.exit
20221 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20222 +
20223 + . = ALIGN(PAGE_SIZE);
20224 + INIT_DATA_SECTION(16) :init
20225
20226 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20227 __x86_cpu_dev_start = .;
20228 @@ -257,19 +338,12 @@ SECTIONS
20229 }
20230
20231 . = ALIGN(8);
20232 - /*
20233 - * .exit.text is discard at runtime, not link time, to deal with
20234 - * references from .altinstructions and .eh_frame
20235 - */
20236 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20237 - EXIT_TEXT
20238 - }
20239
20240 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20241 EXIT_DATA
20242 }
20243
20244 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20245 +#ifndef CONFIG_SMP
20246 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20247 #endif
20248
20249 @@ -288,16 +362,10 @@ SECTIONS
20250 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20251 __smp_locks = .;
20252 *(.smp_locks)
20253 - . = ALIGN(PAGE_SIZE);
20254 __smp_locks_end = .;
20255 + . = ALIGN(PAGE_SIZE);
20256 }
20257
20258 -#ifdef CONFIG_X86_64
20259 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20260 - NOSAVE_DATA
20261 - }
20262 -#endif
20263 -
20264 /* BSS */
20265 . = ALIGN(PAGE_SIZE);
20266 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20267 @@ -313,6 +381,7 @@ SECTIONS
20268 __brk_base = .;
20269 . += 64 * 1024; /* 64k alignment slop space */
20270 *(.brk_reservation) /* areas brk users have reserved */
20271 + . = ALIGN(HPAGE_SIZE);
20272 __brk_limit = .;
20273 }
20274
20275 @@ -339,13 +408,12 @@ SECTIONS
20276 * for the boot processor.
20277 */
20278 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20279 -INIT_PER_CPU(gdt_page);
20280 INIT_PER_CPU(irq_stack_union);
20281
20282 /*
20283 * Build-time check on the image size:
20284 */
20285 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20286 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20287 "kernel image bigger than KERNEL_IMAGE_SIZE");
20288
20289 #ifdef CONFIG_SMP
20290 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20291 index 992f890..fc38904 100644
20292 --- a/arch/x86/kernel/vsmp_64.c
20293 +++ b/arch/x86/kernel/vsmp_64.c
20294 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20295 static void vsmp_apic_post_init(void)
20296 {
20297 /* need to update phys_pkg_id */
20298 - apic->phys_pkg_id = apicid_phys_pkg_id;
20299 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20300 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20301 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20302 }
20303
20304 void __init vsmp_init(void)
20305 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20306 index 8d141b3..40a0fe4 100644
20307 --- a/arch/x86/kernel/vsyscall_64.c
20308 +++ b/arch/x86/kernel/vsyscall_64.c
20309 @@ -56,15 +56,13 @@
20310 DEFINE_VVAR(int, vgetcpu_mode);
20311 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20312
20313 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20314 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20315
20316 static int __init vsyscall_setup(char *str)
20317 {
20318 if (str) {
20319 if (!strcmp("emulate", str))
20320 vsyscall_mode = EMULATE;
20321 - else if (!strcmp("native", str))
20322 - vsyscall_mode = NATIVE;
20323 else if (!strcmp("none", str))
20324 vsyscall_mode = NONE;
20325 else
20326 @@ -306,8 +304,7 @@ done:
20327 return true;
20328
20329 sigsegv:
20330 - force_sig(SIGSEGV, current);
20331 - return true;
20332 + do_group_exit(SIGKILL);
20333 }
20334
20335 /*
20336 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20337 extern char __vvar_page;
20338 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20339
20340 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20341 - vsyscall_mode == NATIVE
20342 - ? PAGE_KERNEL_VSYSCALL
20343 - : PAGE_KERNEL_VVAR);
20344 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20345 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20346 (unsigned long)VSYSCALL_START);
20347
20348 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20349 index 6020f6f..bedd6e3 100644
20350 --- a/arch/x86/kernel/x8664_ksyms_64.c
20351 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20352 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20353 EXPORT_SYMBOL(copy_user_generic_unrolled);
20354 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20355 EXPORT_SYMBOL(__copy_user_nocache);
20356 -EXPORT_SYMBOL(_copy_from_user);
20357 -EXPORT_SYMBOL(_copy_to_user);
20358
20359 EXPORT_SYMBOL(copy_page);
20360 EXPORT_SYMBOL(clear_page);
20361 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20362 index 3d3e207..1a73ab2 100644
20363 --- a/arch/x86/kernel/xsave.c
20364 +++ b/arch/x86/kernel/xsave.c
20365 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20366 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20367 return -EINVAL;
20368
20369 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20370 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20371 fx_sw_user->extended_size -
20372 FP_XSTATE_MAGIC2_SIZE));
20373 if (err)
20374 @@ -268,7 +268,7 @@ fx_only:
20375 * the other extended state.
20376 */
20377 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20378 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20379 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20380 }
20381
20382 /*
20383 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20384 if (use_xsave())
20385 err = restore_user_xstate(buf);
20386 else
20387 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20388 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20389 buf);
20390 if (unlikely(err)) {
20391 /*
20392 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20393 index 0595f13..b544fa3 100644
20394 --- a/arch/x86/kvm/cpuid.c
20395 +++ b/arch/x86/kvm/cpuid.c
20396 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20397 struct kvm_cpuid2 *cpuid,
20398 struct kvm_cpuid_entry2 __user *entries)
20399 {
20400 - int r;
20401 + int r, i;
20402
20403 r = -E2BIG;
20404 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20405 goto out;
20406 r = -EFAULT;
20407 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20408 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20409 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20410 goto out;
20411 + for (i = 0; i < cpuid->nent; ++i) {
20412 + struct kvm_cpuid_entry2 cpuid_entry;
20413 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20414 + goto out;
20415 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20416 + }
20417 vcpu->arch.cpuid_nent = cpuid->nent;
20418 kvm_apic_set_version(vcpu);
20419 kvm_x86_ops->cpuid_update(vcpu);
20420 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20421 struct kvm_cpuid2 *cpuid,
20422 struct kvm_cpuid_entry2 __user *entries)
20423 {
20424 - int r;
20425 + int r, i;
20426
20427 r = -E2BIG;
20428 if (cpuid->nent < vcpu->arch.cpuid_nent)
20429 goto out;
20430 r = -EFAULT;
20431 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20432 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20433 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20434 goto out;
20435 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20436 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20437 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20438 + goto out;
20439 + }
20440 return 0;
20441
20442 out:
20443 diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
20444 index a10e460..58fc514 100644
20445 --- a/arch/x86/kvm/cpuid.h
20446 +++ b/arch/x86/kvm/cpuid.h
20447 @@ -24,6 +24,9 @@ static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
20448 {
20449 struct kvm_cpuid_entry2 *best;
20450
20451 + if (!static_cpu_has(X86_FEATURE_XSAVE))
20452 + return 0;
20453 +
20454 best = kvm_find_cpuid_entry(vcpu, 1, 0);
20455 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
20456 }
20457 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20458 index a3b57a2..ebbe732 100644
20459 --- a/arch/x86/kvm/emulate.c
20460 +++ b/arch/x86/kvm/emulate.c
20461 @@ -256,6 +256,7 @@ struct gprefix {
20462
20463 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20464 do { \
20465 + unsigned long _tmp; \
20466 __asm__ __volatile__ ( \
20467 _PRE_EFLAGS("0", "4", "2") \
20468 _op _suffix " %"_x"3,%1; " \
20469 @@ -270,8 +271,6 @@ struct gprefix {
20470 /* Raw emulation: instruction has two explicit operands. */
20471 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20472 do { \
20473 - unsigned long _tmp; \
20474 - \
20475 switch ((ctxt)->dst.bytes) { \
20476 case 2: \
20477 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20478 @@ -287,7 +286,6 @@ struct gprefix {
20479
20480 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20481 do { \
20482 - unsigned long _tmp; \
20483 switch ((ctxt)->dst.bytes) { \
20484 case 1: \
20485 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20486 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20487 index ce87878..ab48aa3 100644
20488 --- a/arch/x86/kvm/lapic.c
20489 +++ b/arch/x86/kvm/lapic.c
20490 @@ -54,7 +54,7 @@
20491 #define APIC_BUS_CYCLE_NS 1
20492
20493 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20494 -#define apic_debug(fmt, arg...)
20495 +#define apic_debug(fmt, arg...) do {} while (0)
20496
20497 #define APIC_LVT_NUM 6
20498 /* 14 is the version for Xeon and Pentium 8.4.8*/
20499 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20500 index bb7cf01..0348a05 100644
20501 --- a/arch/x86/kvm/paging_tmpl.h
20502 +++ b/arch/x86/kvm/paging_tmpl.h
20503 @@ -196,7 +196,7 @@ retry_walk:
20504 if (unlikely(kvm_is_error_hva(host_addr)))
20505 goto error;
20506
20507 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20508 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20509 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20510 goto error;
20511
20512 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20513 index baead95..90feeb4 100644
20514 --- a/arch/x86/kvm/svm.c
20515 +++ b/arch/x86/kvm/svm.c
20516 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20517 int cpu = raw_smp_processor_id();
20518
20519 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20520 +
20521 + pax_open_kernel();
20522 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20523 + pax_close_kernel();
20524 +
20525 load_TR_desc();
20526 }
20527
20528 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20529 #endif
20530 #endif
20531
20532 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20533 + __set_fs(current_thread_info()->addr_limit);
20534 +#endif
20535 +
20536 reload_tss(vcpu);
20537
20538 local_irq_disable();
20539 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20540 index b1eb202..254e292 100644
20541 --- a/arch/x86/kvm/vmx.c
20542 +++ b/arch/x86/kvm/vmx.c
20543 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20544 struct desc_struct *descs;
20545
20546 descs = (void *)gdt->address;
20547 +
20548 + pax_open_kernel();
20549 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20550 + pax_close_kernel();
20551 +
20552 load_TR_desc();
20553 }
20554
20555 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20556 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20557 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20558
20559 +#ifdef CONFIG_PAX_PER_CPU_PGD
20560 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20561 +#endif
20562 +
20563 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20564 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20565 vmx->loaded_vmcs->cpu = cpu;
20566 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20567 if (!cpu_has_vmx_flexpriority())
20568 flexpriority_enabled = 0;
20569
20570 - if (!cpu_has_vmx_tpr_shadow())
20571 - kvm_x86_ops->update_cr8_intercept = NULL;
20572 + if (!cpu_has_vmx_tpr_shadow()) {
20573 + pax_open_kernel();
20574 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20575 + pax_close_kernel();
20576 + }
20577
20578 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20579 kvm_disable_largepages();
20580 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20581
20582 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20583 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20584 +
20585 +#ifndef CONFIG_PAX_PER_CPU_PGD
20586 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20587 +#endif
20588
20589 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20590 #ifdef CONFIG_X86_64
20591 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20592 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20593
20594 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20595 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20596 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20597
20598 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20599 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20600 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20601 "jmp .Lkvm_vmx_return \n\t"
20602 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20603 ".Lkvm_vmx_return: "
20604 +
20605 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20606 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20607 + ".Lkvm_vmx_return2: "
20608 +#endif
20609 +
20610 /* Save guest registers, load host registers, keep flags */
20611 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20612 "pop %0 \n\t"
20613 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20614 #endif
20615 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20616 [wordsize]"i"(sizeof(ulong))
20617 +
20618 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20619 + ,[cs]"i"(__KERNEL_CS)
20620 +#endif
20621 +
20622 : "cc", "memory"
20623 , R"ax", R"bx", R"di", R"si"
20624 #ifdef CONFIG_X86_64
20625 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20626 #endif
20627 );
20628
20629 -#ifndef CONFIG_X86_64
20630 +#ifdef CONFIG_X86_32
20631 /*
20632 * The sysexit path does not restore ds/es, so we must set them to
20633 * a reasonable value ourselves.
20634 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20635 * may be executed in interrupt context, which saves and restore segments
20636 * around it, nullifying its effect.
20637 */
20638 - loadsegment(ds, __USER_DS);
20639 - loadsegment(es, __USER_DS);
20640 + loadsegment(ds, __KERNEL_DS);
20641 + loadsegment(es, __KERNEL_DS);
20642 + loadsegment(ss, __KERNEL_DS);
20643 +
20644 +#ifdef CONFIG_PAX_KERNEXEC
20645 + loadsegment(fs, __KERNEL_PERCPU);
20646 +#endif
20647 +
20648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20649 + __set_fs(current_thread_info()->addr_limit);
20650 +#endif
20651 +
20652 #endif
20653
20654 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20655 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20656 index 2966c84..9ac0c3c 100644
20657 --- a/arch/x86/kvm/x86.c
20658 +++ b/arch/x86/kvm/x86.c
20659 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20660 {
20661 struct kvm *kvm = vcpu->kvm;
20662 int lm = is_long_mode(vcpu);
20663 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20664 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20665 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20666 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20667 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20668 : kvm->arch.xen_hvm_config.blob_size_32;
20669 u32 page_num = data & ~PAGE_MASK;
20670 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20671 if (n < msr_list.nmsrs)
20672 goto out;
20673 r = -EFAULT;
20674 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20675 + goto out;
20676 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20677 num_msrs_to_save * sizeof(u32)))
20678 goto out;
20679 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20680 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20681 struct kvm_interrupt *irq)
20682 {
20683 - if (irq->irq < 0 || irq->irq >= 256)
20684 + if (irq->irq >= 256)
20685 return -EINVAL;
20686 if (irqchip_in_kernel(vcpu->kvm))
20687 return -ENXIO;
20688 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20689 kvm_mmu_set_mmio_spte_mask(mask);
20690 }
20691
20692 -int kvm_arch_init(void *opaque)
20693 +int kvm_arch_init(const void *opaque)
20694 {
20695 int r;
20696 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20697 @@ -5762,6 +5764,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
20698 int pending_vec, max_bits, idx;
20699 struct desc_ptr dt;
20700
20701 + if (!guest_cpuid_has_xsave(vcpu) && (sregs->cr4 & X86_CR4_OSXSAVE))
20702 + return -EINVAL;
20703 +
20704 dt.size = sregs->idt.limit;
20705 dt.address = sregs->idt.base;
20706 kvm_x86_ops->set_idt(vcpu, &dt);
20707 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20708 index 642d880..cc9ebac 100644
20709 --- a/arch/x86/lguest/boot.c
20710 +++ b/arch/x86/lguest/boot.c
20711 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20712
20713 static void set_lguest_basic_apic_ops(void)
20714 {
20715 - apic->read = lguest_apic_read;
20716 - apic->write = lguest_apic_write;
20717 - apic->icr_read = lguest_apic_icr_read;
20718 - apic->icr_write = lguest_apic_icr_write;
20719 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20720 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20721 + *(void **)&apic->read = lguest_apic_read;
20722 + *(void **)&apic->write = lguest_apic_write;
20723 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20724 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20725 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20726 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20727 };
20728 #endif
20729
20730 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20731 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20732 * Launcher to reboot us.
20733 */
20734 -static void lguest_restart(char *reason)
20735 +static __noreturn void lguest_restart(char *reason)
20736 {
20737 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20738 + BUG();
20739 }
20740
20741 /*G:050
20742 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20743 index 00933d5..3a64af9 100644
20744 --- a/arch/x86/lib/atomic64_386_32.S
20745 +++ b/arch/x86/lib/atomic64_386_32.S
20746 @@ -48,6 +48,10 @@ BEGIN(read)
20747 movl (v), %eax
20748 movl 4(v), %edx
20749 RET_ENDP
20750 +BEGIN(read_unchecked)
20751 + movl (v), %eax
20752 + movl 4(v), %edx
20753 +RET_ENDP
20754 #undef v
20755
20756 #define v %esi
20757 @@ -55,6 +59,10 @@ BEGIN(set)
20758 movl %ebx, (v)
20759 movl %ecx, 4(v)
20760 RET_ENDP
20761 +BEGIN(set_unchecked)
20762 + movl %ebx, (v)
20763 + movl %ecx, 4(v)
20764 +RET_ENDP
20765 #undef v
20766
20767 #define v %esi
20768 @@ -70,6 +78,20 @@ RET_ENDP
20769 BEGIN(add)
20770 addl %eax, (v)
20771 adcl %edx, 4(v)
20772 +
20773 +#ifdef CONFIG_PAX_REFCOUNT
20774 + jno 0f
20775 + subl %eax, (v)
20776 + sbbl %edx, 4(v)
20777 + int $4
20778 +0:
20779 + _ASM_EXTABLE(0b, 0b)
20780 +#endif
20781 +
20782 +RET_ENDP
20783 +BEGIN(add_unchecked)
20784 + addl %eax, (v)
20785 + adcl %edx, 4(v)
20786 RET_ENDP
20787 #undef v
20788
20789 @@ -77,6 +99,24 @@ RET_ENDP
20790 BEGIN(add_return)
20791 addl (v), %eax
20792 adcl 4(v), %edx
20793 +
20794 +#ifdef CONFIG_PAX_REFCOUNT
20795 + into
20796 +1234:
20797 + _ASM_EXTABLE(1234b, 2f)
20798 +#endif
20799 +
20800 + movl %eax, (v)
20801 + movl %edx, 4(v)
20802 +
20803 +#ifdef CONFIG_PAX_REFCOUNT
20804 +2:
20805 +#endif
20806 +
20807 +RET_ENDP
20808 +BEGIN(add_return_unchecked)
20809 + addl (v), %eax
20810 + adcl 4(v), %edx
20811 movl %eax, (v)
20812 movl %edx, 4(v)
20813 RET_ENDP
20814 @@ -86,6 +126,20 @@ RET_ENDP
20815 BEGIN(sub)
20816 subl %eax, (v)
20817 sbbl %edx, 4(v)
20818 +
20819 +#ifdef CONFIG_PAX_REFCOUNT
20820 + jno 0f
20821 + addl %eax, (v)
20822 + adcl %edx, 4(v)
20823 + int $4
20824 +0:
20825 + _ASM_EXTABLE(0b, 0b)
20826 +#endif
20827 +
20828 +RET_ENDP
20829 +BEGIN(sub_unchecked)
20830 + subl %eax, (v)
20831 + sbbl %edx, 4(v)
20832 RET_ENDP
20833 #undef v
20834
20835 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20836 sbbl $0, %edx
20837 addl (v), %eax
20838 adcl 4(v), %edx
20839 +
20840 +#ifdef CONFIG_PAX_REFCOUNT
20841 + into
20842 +1234:
20843 + _ASM_EXTABLE(1234b, 2f)
20844 +#endif
20845 +
20846 + movl %eax, (v)
20847 + movl %edx, 4(v)
20848 +
20849 +#ifdef CONFIG_PAX_REFCOUNT
20850 +2:
20851 +#endif
20852 +
20853 +RET_ENDP
20854 +BEGIN(sub_return_unchecked)
20855 + negl %edx
20856 + negl %eax
20857 + sbbl $0, %edx
20858 + addl (v), %eax
20859 + adcl 4(v), %edx
20860 movl %eax, (v)
20861 movl %edx, 4(v)
20862 RET_ENDP
20863 @@ -105,6 +180,20 @@ RET_ENDP
20864 BEGIN(inc)
20865 addl $1, (v)
20866 adcl $0, 4(v)
20867 +
20868 +#ifdef CONFIG_PAX_REFCOUNT
20869 + jno 0f
20870 + subl $1, (v)
20871 + sbbl $0, 4(v)
20872 + int $4
20873 +0:
20874 + _ASM_EXTABLE(0b, 0b)
20875 +#endif
20876 +
20877 +RET_ENDP
20878 +BEGIN(inc_unchecked)
20879 + addl $1, (v)
20880 + adcl $0, 4(v)
20881 RET_ENDP
20882 #undef v
20883
20884 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20885 movl 4(v), %edx
20886 addl $1, %eax
20887 adcl $0, %edx
20888 +
20889 +#ifdef CONFIG_PAX_REFCOUNT
20890 + into
20891 +1234:
20892 + _ASM_EXTABLE(1234b, 2f)
20893 +#endif
20894 +
20895 + movl %eax, (v)
20896 + movl %edx, 4(v)
20897 +
20898 +#ifdef CONFIG_PAX_REFCOUNT
20899 +2:
20900 +#endif
20901 +
20902 +RET_ENDP
20903 +BEGIN(inc_return_unchecked)
20904 + movl (v), %eax
20905 + movl 4(v), %edx
20906 + addl $1, %eax
20907 + adcl $0, %edx
20908 movl %eax, (v)
20909 movl %edx, 4(v)
20910 RET_ENDP
20911 @@ -123,6 +232,20 @@ RET_ENDP
20912 BEGIN(dec)
20913 subl $1, (v)
20914 sbbl $0, 4(v)
20915 +
20916 +#ifdef CONFIG_PAX_REFCOUNT
20917 + jno 0f
20918 + addl $1, (v)
20919 + adcl $0, 4(v)
20920 + int $4
20921 +0:
20922 + _ASM_EXTABLE(0b, 0b)
20923 +#endif
20924 +
20925 +RET_ENDP
20926 +BEGIN(dec_unchecked)
20927 + subl $1, (v)
20928 + sbbl $0, 4(v)
20929 RET_ENDP
20930 #undef v
20931
20932 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20933 movl 4(v), %edx
20934 subl $1, %eax
20935 sbbl $0, %edx
20936 +
20937 +#ifdef CONFIG_PAX_REFCOUNT
20938 + into
20939 +1234:
20940 + _ASM_EXTABLE(1234b, 2f)
20941 +#endif
20942 +
20943 + movl %eax, (v)
20944 + movl %edx, 4(v)
20945 +
20946 +#ifdef CONFIG_PAX_REFCOUNT
20947 +2:
20948 +#endif
20949 +
20950 +RET_ENDP
20951 +BEGIN(dec_return_unchecked)
20952 + movl (v), %eax
20953 + movl 4(v), %edx
20954 + subl $1, %eax
20955 + sbbl $0, %edx
20956 movl %eax, (v)
20957 movl %edx, 4(v)
20958 RET_ENDP
20959 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20960 adcl %edx, %edi
20961 addl (v), %eax
20962 adcl 4(v), %edx
20963 +
20964 +#ifdef CONFIG_PAX_REFCOUNT
20965 + into
20966 +1234:
20967 + _ASM_EXTABLE(1234b, 2f)
20968 +#endif
20969 +
20970 cmpl %eax, %ecx
20971 je 3f
20972 1:
20973 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20974 1:
20975 addl $1, %eax
20976 adcl $0, %edx
20977 +
20978 +#ifdef CONFIG_PAX_REFCOUNT
20979 + into
20980 +1234:
20981 + _ASM_EXTABLE(1234b, 2f)
20982 +#endif
20983 +
20984 movl %eax, (v)
20985 movl %edx, 4(v)
20986 movl $1, %eax
20987 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20988 movl 4(v), %edx
20989 subl $1, %eax
20990 sbbl $0, %edx
20991 +
20992 +#ifdef CONFIG_PAX_REFCOUNT
20993 + into
20994 +1234:
20995 + _ASM_EXTABLE(1234b, 1f)
20996 +#endif
20997 +
20998 js 1f
20999 movl %eax, (v)
21000 movl %edx, 4(v)
21001 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21002 index f5cc9eb..51fa319 100644
21003 --- a/arch/x86/lib/atomic64_cx8_32.S
21004 +++ b/arch/x86/lib/atomic64_cx8_32.S
21005 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21006 CFI_STARTPROC
21007
21008 read64 %ecx
21009 + pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_read_cx8)
21013
21014 +ENTRY(atomic64_read_unchecked_cx8)
21015 + CFI_STARTPROC
21016 +
21017 + read64 %ecx
21018 + pax_force_retaddr
21019 + ret
21020 + CFI_ENDPROC
21021 +ENDPROC(atomic64_read_unchecked_cx8)
21022 +
21023 ENTRY(atomic64_set_cx8)
21024 CFI_STARTPROC
21025
21026 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21027 cmpxchg8b (%esi)
21028 jne 1b
21029
21030 + pax_force_retaddr
21031 ret
21032 CFI_ENDPROC
21033 ENDPROC(atomic64_set_cx8)
21034
21035 +ENTRY(atomic64_set_unchecked_cx8)
21036 + CFI_STARTPROC
21037 +
21038 +1:
21039 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21040 + * are atomic on 586 and newer */
21041 + cmpxchg8b (%esi)
21042 + jne 1b
21043 +
21044 + pax_force_retaddr
21045 + ret
21046 + CFI_ENDPROC
21047 +ENDPROC(atomic64_set_unchecked_cx8)
21048 +
21049 ENTRY(atomic64_xchg_cx8)
21050 CFI_STARTPROC
21051
21052 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21053 cmpxchg8b (%esi)
21054 jne 1b
21055
21056 + pax_force_retaddr
21057 ret
21058 CFI_ENDPROC
21059 ENDPROC(atomic64_xchg_cx8)
21060
21061 -.macro addsub_return func ins insc
21062 -ENTRY(atomic64_\func\()_return_cx8)
21063 +.macro addsub_return func ins insc unchecked=""
21064 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21065 CFI_STARTPROC
21066 SAVE ebp
21067 SAVE ebx
21068 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21069 movl %edx, %ecx
21070 \ins\()l %esi, %ebx
21071 \insc\()l %edi, %ecx
21072 +
21073 +.ifb \unchecked
21074 +#ifdef CONFIG_PAX_REFCOUNT
21075 + into
21076 +2:
21077 + _ASM_EXTABLE(2b, 3f)
21078 +#endif
21079 +.endif
21080 +
21081 LOCK_PREFIX
21082 cmpxchg8b (%ebp)
21083 jne 1b
21084 -
21085 -10:
21086 movl %ebx, %eax
21087 movl %ecx, %edx
21088 +
21089 +.ifb \unchecked
21090 +#ifdef CONFIG_PAX_REFCOUNT
21091 +3:
21092 +#endif
21093 +.endif
21094 +
21095 RESTORE edi
21096 RESTORE esi
21097 RESTORE ebx
21098 RESTORE ebp
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 addsub_return add add adc
21107 addsub_return sub sub sbb
21108 +addsub_return add add adc _unchecked
21109 +addsub_return sub sub sbb _unchecked
21110
21111 -.macro incdec_return func ins insc
21112 -ENTRY(atomic64_\func\()_return_cx8)
21113 +.macro incdec_return func ins insc unchecked=""
21114 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21115 CFI_STARTPROC
21116 SAVE ebx
21117
21118 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21119 movl %edx, %ecx
21120 \ins\()l $1, %ebx
21121 \insc\()l $0, %ecx
21122 +
21123 +.ifb \unchecked
21124 +#ifdef CONFIG_PAX_REFCOUNT
21125 + into
21126 +2:
21127 + _ASM_EXTABLE(2b, 3f)
21128 +#endif
21129 +.endif
21130 +
21131 LOCK_PREFIX
21132 cmpxchg8b (%esi)
21133 jne 1b
21134
21135 -10:
21136 movl %ebx, %eax
21137 movl %ecx, %edx
21138 +
21139 +.ifb \unchecked
21140 +#ifdef CONFIG_PAX_REFCOUNT
21141 +3:
21142 +#endif
21143 +.endif
21144 +
21145 RESTORE ebx
21146 + pax_force_retaddr
21147 ret
21148 CFI_ENDPROC
21149 -ENDPROC(atomic64_\func\()_return_cx8)
21150 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21151 .endm
21152
21153 incdec_return inc add adc
21154 incdec_return dec sub sbb
21155 +incdec_return inc add adc _unchecked
21156 +incdec_return dec sub sbb _unchecked
21157
21158 ENTRY(atomic64_dec_if_positive_cx8)
21159 CFI_STARTPROC
21160 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21161 movl %edx, %ecx
21162 subl $1, %ebx
21163 sbb $0, %ecx
21164 +
21165 +#ifdef CONFIG_PAX_REFCOUNT
21166 + into
21167 +1234:
21168 + _ASM_EXTABLE(1234b, 2f)
21169 +#endif
21170 +
21171 js 2f
21172 LOCK_PREFIX
21173 cmpxchg8b (%esi)
21174 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21175 movl %ebx, %eax
21176 movl %ecx, %edx
21177 RESTORE ebx
21178 + pax_force_retaddr
21179 ret
21180 CFI_ENDPROC
21181 ENDPROC(atomic64_dec_if_positive_cx8)
21182 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21183 movl %edx, %ecx
21184 addl %ebp, %ebx
21185 adcl %edi, %ecx
21186 +
21187 +#ifdef CONFIG_PAX_REFCOUNT
21188 + into
21189 +1234:
21190 + _ASM_EXTABLE(1234b, 3f)
21191 +#endif
21192 +
21193 LOCK_PREFIX
21194 cmpxchg8b (%esi)
21195 jne 1b
21196 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21197 CFI_ADJUST_CFA_OFFSET -8
21198 RESTORE ebx
21199 RESTORE ebp
21200 + pax_force_retaddr
21201 ret
21202 4:
21203 cmpl %edx, 4(%esp)
21204 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21205 xorl %ecx, %ecx
21206 addl $1, %ebx
21207 adcl %edx, %ecx
21208 +
21209 +#ifdef CONFIG_PAX_REFCOUNT
21210 + into
21211 +1234:
21212 + _ASM_EXTABLE(1234b, 3f)
21213 +#endif
21214 +
21215 LOCK_PREFIX
21216 cmpxchg8b (%esi)
21217 jne 1b
21218 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21219 movl $1, %eax
21220 3:
21221 RESTORE ebx
21222 + pax_force_retaddr
21223 ret
21224 CFI_ENDPROC
21225 ENDPROC(atomic64_inc_not_zero_cx8)
21226 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21227 index 2af5df3..62b1a5a 100644
21228 --- a/arch/x86/lib/checksum_32.S
21229 +++ b/arch/x86/lib/checksum_32.S
21230 @@ -29,7 +29,8 @@
21231 #include <asm/dwarf2.h>
21232 #include <asm/errno.h>
21233 #include <asm/asm.h>
21234 -
21235 +#include <asm/segment.h>
21236 +
21237 /*
21238 * computes a partial checksum, e.g. for TCP/UDP fragments
21239 */
21240 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21241
21242 #define ARGBASE 16
21243 #define FP 12
21244 -
21245 -ENTRY(csum_partial_copy_generic)
21246 +
21247 +ENTRY(csum_partial_copy_generic_to_user)
21248 CFI_STARTPROC
21249 +
21250 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21251 + pushl_cfi %gs
21252 + popl_cfi %es
21253 + jmp csum_partial_copy_generic
21254 +#endif
21255 +
21256 +ENTRY(csum_partial_copy_generic_from_user)
21257 +
21258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21259 + pushl_cfi %gs
21260 + popl_cfi %ds
21261 +#endif
21262 +
21263 +ENTRY(csum_partial_copy_generic)
21264 subl $4,%esp
21265 CFI_ADJUST_CFA_OFFSET 4
21266 pushl_cfi %edi
21267 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21268 jmp 4f
21269 SRC(1: movw (%esi), %bx )
21270 addl $2, %esi
21271 -DST( movw %bx, (%edi) )
21272 +DST( movw %bx, %es:(%edi) )
21273 addl $2, %edi
21274 addw %bx, %ax
21275 adcl $0, %eax
21276 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21277 SRC(1: movl (%esi), %ebx )
21278 SRC( movl 4(%esi), %edx )
21279 adcl %ebx, %eax
21280 -DST( movl %ebx, (%edi) )
21281 +DST( movl %ebx, %es:(%edi) )
21282 adcl %edx, %eax
21283 -DST( movl %edx, 4(%edi) )
21284 +DST( movl %edx, %es:4(%edi) )
21285
21286 SRC( movl 8(%esi), %ebx )
21287 SRC( movl 12(%esi), %edx )
21288 adcl %ebx, %eax
21289 -DST( movl %ebx, 8(%edi) )
21290 +DST( movl %ebx, %es:8(%edi) )
21291 adcl %edx, %eax
21292 -DST( movl %edx, 12(%edi) )
21293 +DST( movl %edx, %es:12(%edi) )
21294
21295 SRC( movl 16(%esi), %ebx )
21296 SRC( movl 20(%esi), %edx )
21297 adcl %ebx, %eax
21298 -DST( movl %ebx, 16(%edi) )
21299 +DST( movl %ebx, %es:16(%edi) )
21300 adcl %edx, %eax
21301 -DST( movl %edx, 20(%edi) )
21302 +DST( movl %edx, %es:20(%edi) )
21303
21304 SRC( movl 24(%esi), %ebx )
21305 SRC( movl 28(%esi), %edx )
21306 adcl %ebx, %eax
21307 -DST( movl %ebx, 24(%edi) )
21308 +DST( movl %ebx, %es:24(%edi) )
21309 adcl %edx, %eax
21310 -DST( movl %edx, 28(%edi) )
21311 +DST( movl %edx, %es:28(%edi) )
21312
21313 lea 32(%esi), %esi
21314 lea 32(%edi), %edi
21315 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21316 shrl $2, %edx # This clears CF
21317 SRC(3: movl (%esi), %ebx )
21318 adcl %ebx, %eax
21319 -DST( movl %ebx, (%edi) )
21320 +DST( movl %ebx, %es:(%edi) )
21321 lea 4(%esi), %esi
21322 lea 4(%edi), %edi
21323 dec %edx
21324 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21325 jb 5f
21326 SRC( movw (%esi), %cx )
21327 leal 2(%esi), %esi
21328 -DST( movw %cx, (%edi) )
21329 +DST( movw %cx, %es:(%edi) )
21330 leal 2(%edi), %edi
21331 je 6f
21332 shll $16,%ecx
21333 SRC(5: movb (%esi), %cl )
21334 -DST( movb %cl, (%edi) )
21335 +DST( movb %cl, %es:(%edi) )
21336 6: addl %ecx, %eax
21337 adcl $0, %eax
21338 7:
21339 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21340
21341 6001:
21342 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21343 - movl $-EFAULT, (%ebx)
21344 + movl $-EFAULT, %ss:(%ebx)
21345
21346 # zero the complete destination - computing the rest
21347 # is too much work
21348 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21349
21350 6002:
21351 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21352 - movl $-EFAULT,(%ebx)
21353 + movl $-EFAULT,%ss:(%ebx)
21354 jmp 5000b
21355
21356 .previous
21357
21358 + pushl_cfi %ss
21359 + popl_cfi %ds
21360 + pushl_cfi %ss
21361 + popl_cfi %es
21362 popl_cfi %ebx
21363 CFI_RESTORE ebx
21364 popl_cfi %esi
21365 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21366 popl_cfi %ecx # equivalent to addl $4,%esp
21367 ret
21368 CFI_ENDPROC
21369 -ENDPROC(csum_partial_copy_generic)
21370 +ENDPROC(csum_partial_copy_generic_to_user)
21371
21372 #else
21373
21374 /* Version for PentiumII/PPro */
21375
21376 #define ROUND1(x) \
21377 + nop; nop; nop; \
21378 SRC(movl x(%esi), %ebx ) ; \
21379 addl %ebx, %eax ; \
21380 - DST(movl %ebx, x(%edi) ) ;
21381 + DST(movl %ebx, %es:x(%edi)) ;
21382
21383 #define ROUND(x) \
21384 + nop; nop; nop; \
21385 SRC(movl x(%esi), %ebx ) ; \
21386 adcl %ebx, %eax ; \
21387 - DST(movl %ebx, x(%edi) ) ;
21388 + DST(movl %ebx, %es:x(%edi)) ;
21389
21390 #define ARGBASE 12
21391 -
21392 -ENTRY(csum_partial_copy_generic)
21393 +
21394 +ENTRY(csum_partial_copy_generic_to_user)
21395 CFI_STARTPROC
21396 +
21397 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21398 + pushl_cfi %gs
21399 + popl_cfi %es
21400 + jmp csum_partial_copy_generic
21401 +#endif
21402 +
21403 +ENTRY(csum_partial_copy_generic_from_user)
21404 +
21405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21406 + pushl_cfi %gs
21407 + popl_cfi %ds
21408 +#endif
21409 +
21410 +ENTRY(csum_partial_copy_generic)
21411 pushl_cfi %ebx
21412 CFI_REL_OFFSET ebx, 0
21413 pushl_cfi %edi
21414 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21415 subl %ebx, %edi
21416 lea -1(%esi),%edx
21417 andl $-32,%edx
21418 - lea 3f(%ebx,%ebx), %ebx
21419 + lea 3f(%ebx,%ebx,2), %ebx
21420 testl %esi, %esi
21421 jmp *%ebx
21422 1: addl $64,%esi
21423 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21424 jb 5f
21425 SRC( movw (%esi), %dx )
21426 leal 2(%esi), %esi
21427 -DST( movw %dx, (%edi) )
21428 +DST( movw %dx, %es:(%edi) )
21429 leal 2(%edi), %edi
21430 je 6f
21431 shll $16,%edx
21432 5:
21433 SRC( movb (%esi), %dl )
21434 -DST( movb %dl, (%edi) )
21435 +DST( movb %dl, %es:(%edi) )
21436 6: addl %edx, %eax
21437 adcl $0, %eax
21438 7:
21439 .section .fixup, "ax"
21440 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21441 - movl $-EFAULT, (%ebx)
21442 + movl $-EFAULT, %ss:(%ebx)
21443 # zero the complete destination (computing the rest is too much work)
21444 movl ARGBASE+8(%esp),%edi # dst
21445 movl ARGBASE+12(%esp),%ecx # len
21446 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21447 rep; stosb
21448 jmp 7b
21449 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21450 - movl $-EFAULT, (%ebx)
21451 + movl $-EFAULT, %ss:(%ebx)
21452 jmp 7b
21453 .previous
21454
21455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21456 + pushl_cfi %ss
21457 + popl_cfi %ds
21458 + pushl_cfi %ss
21459 + popl_cfi %es
21460 +#endif
21461 +
21462 popl_cfi %esi
21463 CFI_RESTORE esi
21464 popl_cfi %edi
21465 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21466 CFI_RESTORE ebx
21467 ret
21468 CFI_ENDPROC
21469 -ENDPROC(csum_partial_copy_generic)
21470 +ENDPROC(csum_partial_copy_generic_to_user)
21471
21472 #undef ROUND
21473 #undef ROUND1
21474 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21475 index f2145cf..cea889d 100644
21476 --- a/arch/x86/lib/clear_page_64.S
21477 +++ b/arch/x86/lib/clear_page_64.S
21478 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21479 movl $4096/8,%ecx
21480 xorl %eax,%eax
21481 rep stosq
21482 + pax_force_retaddr
21483 ret
21484 CFI_ENDPROC
21485 ENDPROC(clear_page_c)
21486 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21487 movl $4096,%ecx
21488 xorl %eax,%eax
21489 rep stosb
21490 + pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(clear_page_c_e)
21494 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21495 leaq 64(%rdi),%rdi
21496 jnz .Lloop
21497 nop
21498 + pax_force_retaddr
21499 ret
21500 CFI_ENDPROC
21501 .Lclear_page_end:
21502 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21503
21504 #include <asm/cpufeature.h>
21505
21506 - .section .altinstr_replacement,"ax"
21507 + .section .altinstr_replacement,"a"
21508 1: .byte 0xeb /* jmp <disp8> */
21509 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21510 2: .byte 0xeb /* jmp <disp8> */
21511 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21512 index 1e572c5..2a162cd 100644
21513 --- a/arch/x86/lib/cmpxchg16b_emu.S
21514 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21515 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21516
21517 popf
21518 mov $1, %al
21519 + pax_force_retaddr
21520 ret
21521
21522 not_same:
21523 popf
21524 xor %al,%al
21525 + pax_force_retaddr
21526 ret
21527
21528 CFI_ENDPROC
21529 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21530 index 6b34d04..dccb07f 100644
21531 --- a/arch/x86/lib/copy_page_64.S
21532 +++ b/arch/x86/lib/copy_page_64.S
21533 @@ -9,6 +9,7 @@ copy_page_c:
21534 CFI_STARTPROC
21535 movl $4096/8,%ecx
21536 rep movsq
21537 + pax_force_retaddr
21538 ret
21539 CFI_ENDPROC
21540 ENDPROC(copy_page_c)
21541 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21542
21543 ENTRY(copy_page)
21544 CFI_STARTPROC
21545 - subq $2*8,%rsp
21546 - CFI_ADJUST_CFA_OFFSET 2*8
21547 + subq $3*8,%rsp
21548 + CFI_ADJUST_CFA_OFFSET 3*8
21549 movq %rbx,(%rsp)
21550 CFI_REL_OFFSET rbx, 0
21551 movq %r12,1*8(%rsp)
21552 CFI_REL_OFFSET r12, 1*8
21553 + movq %r13,2*8(%rsp)
21554 + CFI_REL_OFFSET r13, 2*8
21555
21556 movl $(4096/64)-5,%ecx
21557 .p2align 4
21558 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21559 movq 16 (%rsi), %rdx
21560 movq 24 (%rsi), %r8
21561 movq 32 (%rsi), %r9
21562 - movq 40 (%rsi), %r10
21563 + movq 40 (%rsi), %r13
21564 movq 48 (%rsi), %r11
21565 movq 56 (%rsi), %r12
21566
21567 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21568 movq %rdx, 16 (%rdi)
21569 movq %r8, 24 (%rdi)
21570 movq %r9, 32 (%rdi)
21571 - movq %r10, 40 (%rdi)
21572 + movq %r13, 40 (%rdi)
21573 movq %r11, 48 (%rdi)
21574 movq %r12, 56 (%rdi)
21575
21576 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21577 movq 16 (%rsi), %rdx
21578 movq 24 (%rsi), %r8
21579 movq 32 (%rsi), %r9
21580 - movq 40 (%rsi), %r10
21581 + movq 40 (%rsi), %r13
21582 movq 48 (%rsi), %r11
21583 movq 56 (%rsi), %r12
21584
21585 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21586 movq %rdx, 16 (%rdi)
21587 movq %r8, 24 (%rdi)
21588 movq %r9, 32 (%rdi)
21589 - movq %r10, 40 (%rdi)
21590 + movq %r13, 40 (%rdi)
21591 movq %r11, 48 (%rdi)
21592 movq %r12, 56 (%rdi)
21593
21594 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21595 CFI_RESTORE rbx
21596 movq 1*8(%rsp),%r12
21597 CFI_RESTORE r12
21598 - addq $2*8,%rsp
21599 - CFI_ADJUST_CFA_OFFSET -2*8
21600 + movq 2*8(%rsp),%r13
21601 + CFI_RESTORE r13
21602 + addq $3*8,%rsp
21603 + CFI_ADJUST_CFA_OFFSET -3*8
21604 + pax_force_retaddr
21605 ret
21606 .Lcopy_page_end:
21607 CFI_ENDPROC
21608 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21609
21610 #include <asm/cpufeature.h>
21611
21612 - .section .altinstr_replacement,"ax"
21613 + .section .altinstr_replacement,"a"
21614 1: .byte 0xeb /* jmp <disp8> */
21615 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21616 2:
21617 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21618 index 5b2995f..78e7644 100644
21619 --- a/arch/x86/lib/copy_user_64.S
21620 +++ b/arch/x86/lib/copy_user_64.S
21621 @@ -17,6 +17,7 @@
21622 #include <asm/cpufeature.h>
21623 #include <asm/alternative-asm.h>
21624 #include <asm/asm.h>
21625 +#include <asm/pgtable.h>
21626
21627 /*
21628 * By placing feature2 after feature1 in altinstructions section, we logically
21629 @@ -30,7 +31,7 @@
21630 .byte 0xe9 /* 32bit jump */
21631 .long \orig-1f /* by default jump to orig */
21632 1:
21633 - .section .altinstr_replacement,"ax"
21634 + .section .altinstr_replacement,"a"
21635 2: .byte 0xe9 /* near jump with 32bit immediate */
21636 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21637 3: .byte 0xe9 /* near jump with 32bit immediate */
21638 @@ -69,47 +70,20 @@
21639 #endif
21640 .endm
21641
21642 -/* Standard copy_to_user with segment limit checking */
21643 -ENTRY(_copy_to_user)
21644 - CFI_STARTPROC
21645 - GET_THREAD_INFO(%rax)
21646 - movq %rdi,%rcx
21647 - addq %rdx,%rcx
21648 - jc bad_to_user
21649 - cmpq TI_addr_limit(%rax),%rcx
21650 - ja bad_to_user
21651 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21652 - copy_user_generic_unrolled,copy_user_generic_string, \
21653 - copy_user_enhanced_fast_string
21654 - CFI_ENDPROC
21655 -ENDPROC(_copy_to_user)
21656 -
21657 -/* Standard copy_from_user with segment limit checking */
21658 -ENTRY(_copy_from_user)
21659 - CFI_STARTPROC
21660 - GET_THREAD_INFO(%rax)
21661 - movq %rsi,%rcx
21662 - addq %rdx,%rcx
21663 - jc bad_from_user
21664 - cmpq TI_addr_limit(%rax),%rcx
21665 - ja bad_from_user
21666 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21667 - copy_user_generic_unrolled,copy_user_generic_string, \
21668 - copy_user_enhanced_fast_string
21669 - CFI_ENDPROC
21670 -ENDPROC(_copy_from_user)
21671 -
21672 .section .fixup,"ax"
21673 /* must zero dest */
21674 ENTRY(bad_from_user)
21675 bad_from_user:
21676 CFI_STARTPROC
21677 + testl %edx,%edx
21678 + js bad_to_user
21679 movl %edx,%ecx
21680 xorl %eax,%eax
21681 rep
21682 stosb
21683 bad_to_user:
21684 movl %edx,%eax
21685 + pax_force_retaddr
21686 ret
21687 CFI_ENDPROC
21688 ENDPROC(bad_from_user)
21689 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21690 jz 17f
21691 1: movq (%rsi),%r8
21692 2: movq 1*8(%rsi),%r9
21693 -3: movq 2*8(%rsi),%r10
21694 +3: movq 2*8(%rsi),%rax
21695 4: movq 3*8(%rsi),%r11
21696 5: movq %r8,(%rdi)
21697 6: movq %r9,1*8(%rdi)
21698 -7: movq %r10,2*8(%rdi)
21699 +7: movq %rax,2*8(%rdi)
21700 8: movq %r11,3*8(%rdi)
21701 9: movq 4*8(%rsi),%r8
21702 10: movq 5*8(%rsi),%r9
21703 -11: movq 6*8(%rsi),%r10
21704 +11: movq 6*8(%rsi),%rax
21705 12: movq 7*8(%rsi),%r11
21706 13: movq %r8,4*8(%rdi)
21707 14: movq %r9,5*8(%rdi)
21708 -15: movq %r10,6*8(%rdi)
21709 +15: movq %rax,6*8(%rdi)
21710 16: movq %r11,7*8(%rdi)
21711 leaq 64(%rsi),%rsi
21712 leaq 64(%rdi),%rdi
21713 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21714 decl %ecx
21715 jnz 21b
21716 23: xor %eax,%eax
21717 + pax_force_retaddr
21718 ret
21719
21720 .section .fixup,"ax"
21721 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21722 3: rep
21723 movsb
21724 4: xorl %eax,%eax
21725 + pax_force_retaddr
21726 ret
21727
21728 .section .fixup,"ax"
21729 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21730 1: rep
21731 movsb
21732 2: xorl %eax,%eax
21733 + pax_force_retaddr
21734 ret
21735
21736 .section .fixup,"ax"
21737 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21738 index cacddc7..09d49e4 100644
21739 --- a/arch/x86/lib/copy_user_nocache_64.S
21740 +++ b/arch/x86/lib/copy_user_nocache_64.S
21741 @@ -8,6 +8,7 @@
21742
21743 #include <linux/linkage.h>
21744 #include <asm/dwarf2.h>
21745 +#include <asm/alternative-asm.h>
21746
21747 #define FIX_ALIGNMENT 1
21748
21749 @@ -15,6 +16,7 @@
21750 #include <asm/asm-offsets.h>
21751 #include <asm/thread_info.h>
21752 #include <asm/asm.h>
21753 +#include <asm/pgtable.h>
21754
21755 .macro ALIGN_DESTINATION
21756 #ifdef FIX_ALIGNMENT
21757 @@ -48,6 +50,15 @@
21758 */
21759 ENTRY(__copy_user_nocache)
21760 CFI_STARTPROC
21761 +
21762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21763 + mov $PAX_USER_SHADOW_BASE,%rcx
21764 + cmp %rcx,%rsi
21765 + jae 1f
21766 + add %rcx,%rsi
21767 +1:
21768 +#endif
21769 +
21770 cmpl $8,%edx
21771 jb 20f /* less then 8 bytes, go to byte copy loop */
21772 ALIGN_DESTINATION
21773 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21774 jz 17f
21775 1: movq (%rsi),%r8
21776 2: movq 1*8(%rsi),%r9
21777 -3: movq 2*8(%rsi),%r10
21778 +3: movq 2*8(%rsi),%rax
21779 4: movq 3*8(%rsi),%r11
21780 5: movnti %r8,(%rdi)
21781 6: movnti %r9,1*8(%rdi)
21782 -7: movnti %r10,2*8(%rdi)
21783 +7: movnti %rax,2*8(%rdi)
21784 8: movnti %r11,3*8(%rdi)
21785 9: movq 4*8(%rsi),%r8
21786 10: movq 5*8(%rsi),%r9
21787 -11: movq 6*8(%rsi),%r10
21788 +11: movq 6*8(%rsi),%rax
21789 12: movq 7*8(%rsi),%r11
21790 13: movnti %r8,4*8(%rdi)
21791 14: movnti %r9,5*8(%rdi)
21792 -15: movnti %r10,6*8(%rdi)
21793 +15: movnti %rax,6*8(%rdi)
21794 16: movnti %r11,7*8(%rdi)
21795 leaq 64(%rsi),%rsi
21796 leaq 64(%rdi),%rdi
21797 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21798 jnz 21b
21799 23: xorl %eax,%eax
21800 sfence
21801 + pax_force_retaddr
21802 ret
21803
21804 .section .fixup,"ax"
21805 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21806 index 2419d5f..953ee51 100644
21807 --- a/arch/x86/lib/csum-copy_64.S
21808 +++ b/arch/x86/lib/csum-copy_64.S
21809 @@ -9,6 +9,7 @@
21810 #include <asm/dwarf2.h>
21811 #include <asm/errno.h>
21812 #include <asm/asm.h>
21813 +#include <asm/alternative-asm.h>
21814
21815 /*
21816 * Checksum copy with exception handling.
21817 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21818 CFI_RESTORE rbp
21819 addq $7*8, %rsp
21820 CFI_ADJUST_CFA_OFFSET -7*8
21821 + pax_force_retaddr 0, 1
21822 ret
21823 CFI_RESTORE_STATE
21824
21825 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21826 index 25b7ae8..3b52ccd 100644
21827 --- a/arch/x86/lib/csum-wrappers_64.c
21828 +++ b/arch/x86/lib/csum-wrappers_64.c
21829 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21830 len -= 2;
21831 }
21832 }
21833 - isum = csum_partial_copy_generic((__force const void *)src,
21834 +
21835 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21836 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21837 + src += PAX_USER_SHADOW_BASE;
21838 +#endif
21839 +
21840 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21841 dst, len, isum, errp, NULL);
21842 if (unlikely(*errp))
21843 goto out_err;
21844 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21845 }
21846
21847 *errp = 0;
21848 - return csum_partial_copy_generic(src, (void __force *)dst,
21849 +
21850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21851 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21852 + dst += PAX_USER_SHADOW_BASE;
21853 +#endif
21854 +
21855 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21856 len, isum, NULL, errp);
21857 }
21858 EXPORT_SYMBOL(csum_partial_copy_to_user);
21859 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21860 index b33b1fb..219f389 100644
21861 --- a/arch/x86/lib/getuser.S
21862 +++ b/arch/x86/lib/getuser.S
21863 @@ -33,15 +33,38 @@
21864 #include <asm/asm-offsets.h>
21865 #include <asm/thread_info.h>
21866 #include <asm/asm.h>
21867 +#include <asm/segment.h>
21868 +#include <asm/pgtable.h>
21869 +#include <asm/alternative-asm.h>
21870 +
21871 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21872 +#define __copyuser_seg gs;
21873 +#else
21874 +#define __copyuser_seg
21875 +#endif
21876
21877 .text
21878 ENTRY(__get_user_1)
21879 CFI_STARTPROC
21880 +
21881 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21882 GET_THREAD_INFO(%_ASM_DX)
21883 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21884 jae bad_get_user
21885 -1: movzb (%_ASM_AX),%edx
21886 +
21887 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21888 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21889 + cmp %_ASM_DX,%_ASM_AX
21890 + jae 1234f
21891 + add %_ASM_DX,%_ASM_AX
21892 +1234:
21893 +#endif
21894 +
21895 +#endif
21896 +
21897 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21898 xor %eax,%eax
21899 + pax_force_retaddr
21900 ret
21901 CFI_ENDPROC
21902 ENDPROC(__get_user_1)
21903 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21904 ENTRY(__get_user_2)
21905 CFI_STARTPROC
21906 add $1,%_ASM_AX
21907 +
21908 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21909 jc bad_get_user
21910 GET_THREAD_INFO(%_ASM_DX)
21911 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21912 jae bad_get_user
21913 -2: movzwl -1(%_ASM_AX),%edx
21914 +
21915 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21916 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21917 + cmp %_ASM_DX,%_ASM_AX
21918 + jae 1234f
21919 + add %_ASM_DX,%_ASM_AX
21920 +1234:
21921 +#endif
21922 +
21923 +#endif
21924 +
21925 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21926 xor %eax,%eax
21927 + pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_2)
21931 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21932 ENTRY(__get_user_4)
21933 CFI_STARTPROC
21934 add $3,%_ASM_AX
21935 +
21936 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21937 jc bad_get_user
21938 GET_THREAD_INFO(%_ASM_DX)
21939 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21940 jae bad_get_user
21941 -3: mov -3(%_ASM_AX),%edx
21942 +
21943 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21944 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21945 + cmp %_ASM_DX,%_ASM_AX
21946 + jae 1234f
21947 + add %_ASM_DX,%_ASM_AX
21948 +1234:
21949 +#endif
21950 +
21951 +#endif
21952 +
21953 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21954 xor %eax,%eax
21955 + pax_force_retaddr
21956 ret
21957 CFI_ENDPROC
21958 ENDPROC(__get_user_4)
21959 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21960 GET_THREAD_INFO(%_ASM_DX)
21961 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21962 jae bad_get_user
21963 +
21964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21965 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21966 + cmp %_ASM_DX,%_ASM_AX
21967 + jae 1234f
21968 + add %_ASM_DX,%_ASM_AX
21969 +1234:
21970 +#endif
21971 +
21972 4: movq -7(%_ASM_AX),%_ASM_DX
21973 xor %eax,%eax
21974 + pax_force_retaddr
21975 ret
21976 CFI_ENDPROC
21977 ENDPROC(__get_user_8)
21978 @@ -91,6 +152,7 @@ bad_get_user:
21979 CFI_STARTPROC
21980 xor %edx,%edx
21981 mov $(-EFAULT),%_ASM_AX
21982 + pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 END(bad_get_user)
21986 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21987 index b1e6c4b..21ae8fc 100644
21988 --- a/arch/x86/lib/insn.c
21989 +++ b/arch/x86/lib/insn.c
21990 @@ -21,6 +21,11 @@
21991 #include <linux/string.h>
21992 #include <asm/inat.h>
21993 #include <asm/insn.h>
21994 +#ifdef __KERNEL__
21995 +#include <asm/pgtable_types.h>
21996 +#else
21997 +#define ktla_ktva(addr) addr
21998 +#endif
21999
22000 /* Verify next sizeof(t) bytes can be on the same instruction */
22001 #define validate_next(t, insn, n) \
22002 @@ -49,8 +54,8 @@
22003 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22004 {
22005 memset(insn, 0, sizeof(*insn));
22006 - insn->kaddr = kaddr;
22007 - insn->next_byte = kaddr;
22008 + insn->kaddr = ktla_ktva(kaddr);
22009 + insn->next_byte = ktla_ktva(kaddr);
22010 insn->x86_64 = x86_64 ? 1 : 0;
22011 insn->opnd_bytes = 4;
22012 if (x86_64)
22013 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22014 index 05a95e7..326f2fa 100644
22015 --- a/arch/x86/lib/iomap_copy_64.S
22016 +++ b/arch/x86/lib/iomap_copy_64.S
22017 @@ -17,6 +17,7 @@
22018
22019 #include <linux/linkage.h>
22020 #include <asm/dwarf2.h>
22021 +#include <asm/alternative-asm.h>
22022
22023 /*
22024 * override generic version in lib/iomap_copy.c
22025 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22026 CFI_STARTPROC
22027 movl %edx,%ecx
22028 rep movsd
22029 + pax_force_retaddr
22030 ret
22031 CFI_ENDPROC
22032 ENDPROC(__iowrite32_copy)
22033 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22034 index 1c273be..da9cc0e 100644
22035 --- a/arch/x86/lib/memcpy_64.S
22036 +++ b/arch/x86/lib/memcpy_64.S
22037 @@ -33,6 +33,7 @@
22038 rep movsq
22039 movl %edx, %ecx
22040 rep movsb
22041 + pax_force_retaddr
22042 ret
22043 .Lmemcpy_e:
22044 .previous
22045 @@ -49,6 +50,7 @@
22046 movq %rdi, %rax
22047 movq %rdx, %rcx
22048 rep movsb
22049 + pax_force_retaddr
22050 ret
22051 .Lmemcpy_e_e:
22052 .previous
22053 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22054 */
22055 movq 0*8(%rsi), %r8
22056 movq 1*8(%rsi), %r9
22057 - movq 2*8(%rsi), %r10
22058 + movq 2*8(%rsi), %rcx
22059 movq 3*8(%rsi), %r11
22060 leaq 4*8(%rsi), %rsi
22061
22062 movq %r8, 0*8(%rdi)
22063 movq %r9, 1*8(%rdi)
22064 - movq %r10, 2*8(%rdi)
22065 + movq %rcx, 2*8(%rdi)
22066 movq %r11, 3*8(%rdi)
22067 leaq 4*8(%rdi), %rdi
22068 jae .Lcopy_forward_loop
22069 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22070 subq $0x20, %rdx
22071 movq -1*8(%rsi), %r8
22072 movq -2*8(%rsi), %r9
22073 - movq -3*8(%rsi), %r10
22074 + movq -3*8(%rsi), %rcx
22075 movq -4*8(%rsi), %r11
22076 leaq -4*8(%rsi), %rsi
22077 movq %r8, -1*8(%rdi)
22078 movq %r9, -2*8(%rdi)
22079 - movq %r10, -3*8(%rdi)
22080 + movq %rcx, -3*8(%rdi)
22081 movq %r11, -4*8(%rdi)
22082 leaq -4*8(%rdi), %rdi
22083 jae .Lcopy_backward_loop
22084 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22085 */
22086 movq 0*8(%rsi), %r8
22087 movq 1*8(%rsi), %r9
22088 - movq -2*8(%rsi, %rdx), %r10
22089 + movq -2*8(%rsi, %rdx), %rcx
22090 movq -1*8(%rsi, %rdx), %r11
22091 movq %r8, 0*8(%rdi)
22092 movq %r9, 1*8(%rdi)
22093 - movq %r10, -2*8(%rdi, %rdx)
22094 + movq %rcx, -2*8(%rdi, %rdx)
22095 movq %r11, -1*8(%rdi, %rdx)
22096 + pax_force_retaddr
22097 retq
22098 .p2align 4
22099 .Lless_16bytes:
22100 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22101 movq -1*8(%rsi, %rdx), %r9
22102 movq %r8, 0*8(%rdi)
22103 movq %r9, -1*8(%rdi, %rdx)
22104 + pax_force_retaddr
22105 retq
22106 .p2align 4
22107 .Lless_8bytes:
22108 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22109 movl -4(%rsi, %rdx), %r8d
22110 movl %ecx, (%rdi)
22111 movl %r8d, -4(%rdi, %rdx)
22112 + pax_force_retaddr
22113 retq
22114 .p2align 4
22115 .Lless_3bytes:
22116 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22117 movb %cl, (%rdi)
22118
22119 .Lend:
22120 + pax_force_retaddr
22121 retq
22122 CFI_ENDPROC
22123 ENDPROC(memcpy)
22124 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22125 index ee16461..c39c199 100644
22126 --- a/arch/x86/lib/memmove_64.S
22127 +++ b/arch/x86/lib/memmove_64.S
22128 @@ -61,13 +61,13 @@ ENTRY(memmove)
22129 5:
22130 sub $0x20, %rdx
22131 movq 0*8(%rsi), %r11
22132 - movq 1*8(%rsi), %r10
22133 + movq 1*8(%rsi), %rcx
22134 movq 2*8(%rsi), %r9
22135 movq 3*8(%rsi), %r8
22136 leaq 4*8(%rsi), %rsi
22137
22138 movq %r11, 0*8(%rdi)
22139 - movq %r10, 1*8(%rdi)
22140 + movq %rcx, 1*8(%rdi)
22141 movq %r9, 2*8(%rdi)
22142 movq %r8, 3*8(%rdi)
22143 leaq 4*8(%rdi), %rdi
22144 @@ -81,10 +81,10 @@ ENTRY(memmove)
22145 4:
22146 movq %rdx, %rcx
22147 movq -8(%rsi, %rdx), %r11
22148 - lea -8(%rdi, %rdx), %r10
22149 + lea -8(%rdi, %rdx), %r9
22150 shrq $3, %rcx
22151 rep movsq
22152 - movq %r11, (%r10)
22153 + movq %r11, (%r9)
22154 jmp 13f
22155 .Lmemmove_end_forward:
22156
22157 @@ -95,14 +95,14 @@ ENTRY(memmove)
22158 7:
22159 movq %rdx, %rcx
22160 movq (%rsi), %r11
22161 - movq %rdi, %r10
22162 + movq %rdi, %r9
22163 leaq -8(%rsi, %rdx), %rsi
22164 leaq -8(%rdi, %rdx), %rdi
22165 shrq $3, %rcx
22166 std
22167 rep movsq
22168 cld
22169 - movq %r11, (%r10)
22170 + movq %r11, (%r9)
22171 jmp 13f
22172
22173 /*
22174 @@ -127,13 +127,13 @@ ENTRY(memmove)
22175 8:
22176 subq $0x20, %rdx
22177 movq -1*8(%rsi), %r11
22178 - movq -2*8(%rsi), %r10
22179 + movq -2*8(%rsi), %rcx
22180 movq -3*8(%rsi), %r9
22181 movq -4*8(%rsi), %r8
22182 leaq -4*8(%rsi), %rsi
22183
22184 movq %r11, -1*8(%rdi)
22185 - movq %r10, -2*8(%rdi)
22186 + movq %rcx, -2*8(%rdi)
22187 movq %r9, -3*8(%rdi)
22188 movq %r8, -4*8(%rdi)
22189 leaq -4*8(%rdi), %rdi
22190 @@ -151,11 +151,11 @@ ENTRY(memmove)
22191 * Move data from 16 bytes to 31 bytes.
22192 */
22193 movq 0*8(%rsi), %r11
22194 - movq 1*8(%rsi), %r10
22195 + movq 1*8(%rsi), %rcx
22196 movq -2*8(%rsi, %rdx), %r9
22197 movq -1*8(%rsi, %rdx), %r8
22198 movq %r11, 0*8(%rdi)
22199 - movq %r10, 1*8(%rdi)
22200 + movq %rcx, 1*8(%rdi)
22201 movq %r9, -2*8(%rdi, %rdx)
22202 movq %r8, -1*8(%rdi, %rdx)
22203 jmp 13f
22204 @@ -167,9 +167,9 @@ ENTRY(memmove)
22205 * Move data from 8 bytes to 15 bytes.
22206 */
22207 movq 0*8(%rsi), %r11
22208 - movq -1*8(%rsi, %rdx), %r10
22209 + movq -1*8(%rsi, %rdx), %r9
22210 movq %r11, 0*8(%rdi)
22211 - movq %r10, -1*8(%rdi, %rdx)
22212 + movq %r9, -1*8(%rdi, %rdx)
22213 jmp 13f
22214 10:
22215 cmpq $4, %rdx
22216 @@ -178,9 +178,9 @@ ENTRY(memmove)
22217 * Move data from 4 bytes to 7 bytes.
22218 */
22219 movl (%rsi), %r11d
22220 - movl -4(%rsi, %rdx), %r10d
22221 + movl -4(%rsi, %rdx), %r9d
22222 movl %r11d, (%rdi)
22223 - movl %r10d, -4(%rdi, %rdx)
22224 + movl %r9d, -4(%rdi, %rdx)
22225 jmp 13f
22226 11:
22227 cmp $2, %rdx
22228 @@ -189,9 +189,9 @@ ENTRY(memmove)
22229 * Move data from 2 bytes to 3 bytes.
22230 */
22231 movw (%rsi), %r11w
22232 - movw -2(%rsi, %rdx), %r10w
22233 + movw -2(%rsi, %rdx), %r9w
22234 movw %r11w, (%rdi)
22235 - movw %r10w, -2(%rdi, %rdx)
22236 + movw %r9w, -2(%rdi, %rdx)
22237 jmp 13f
22238 12:
22239 cmp $1, %rdx
22240 @@ -202,6 +202,7 @@ ENTRY(memmove)
22241 movb (%rsi), %r11b
22242 movb %r11b, (%rdi)
22243 13:
22244 + pax_force_retaddr
22245 retq
22246 CFI_ENDPROC
22247
22248 @@ -210,6 +211,7 @@ ENTRY(memmove)
22249 /* Forward moving data. */
22250 movq %rdx, %rcx
22251 rep movsb
22252 + pax_force_retaddr
22253 retq
22254 .Lmemmove_end_forward_efs:
22255 .previous
22256 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22257 index 2dcb380..963660a 100644
22258 --- a/arch/x86/lib/memset_64.S
22259 +++ b/arch/x86/lib/memset_64.S
22260 @@ -30,6 +30,7 @@
22261 movl %edx,%ecx
22262 rep stosb
22263 movq %r9,%rax
22264 + pax_force_retaddr
22265 ret
22266 .Lmemset_e:
22267 .previous
22268 @@ -52,6 +53,7 @@
22269 movq %rdx,%rcx
22270 rep stosb
22271 movq %r9,%rax
22272 + pax_force_retaddr
22273 ret
22274 .Lmemset_e_e:
22275 .previous
22276 @@ -59,7 +61,7 @@
22277 ENTRY(memset)
22278 ENTRY(__memset)
22279 CFI_STARTPROC
22280 - movq %rdi,%r10
22281 + movq %rdi,%r11
22282
22283 /* expand byte value */
22284 movzbl %sil,%ecx
22285 @@ -117,7 +119,8 @@ ENTRY(__memset)
22286 jnz .Lloop_1
22287
22288 .Lende:
22289 - movq %r10,%rax
22290 + movq %r11,%rax
22291 + pax_force_retaddr
22292 ret
22293
22294 CFI_RESTORE_STATE
22295 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22296 index c9f2d9b..e7fd2c0 100644
22297 --- a/arch/x86/lib/mmx_32.c
22298 +++ b/arch/x86/lib/mmx_32.c
22299 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22300 {
22301 void *p;
22302 int i;
22303 + unsigned long cr0;
22304
22305 if (unlikely(in_interrupt()))
22306 return __memcpy(to, from, len);
22307 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22308 kernel_fpu_begin();
22309
22310 __asm__ __volatile__ (
22311 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22312 - " prefetch 64(%0)\n"
22313 - " prefetch 128(%0)\n"
22314 - " prefetch 192(%0)\n"
22315 - " prefetch 256(%0)\n"
22316 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22317 + " prefetch 64(%1)\n"
22318 + " prefetch 128(%1)\n"
22319 + " prefetch 192(%1)\n"
22320 + " prefetch 256(%1)\n"
22321 "2: \n"
22322 ".section .fixup, \"ax\"\n"
22323 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22324 + "3: \n"
22325 +
22326 +#ifdef CONFIG_PAX_KERNEXEC
22327 + " movl %%cr0, %0\n"
22328 + " movl %0, %%eax\n"
22329 + " andl $0xFFFEFFFF, %%eax\n"
22330 + " movl %%eax, %%cr0\n"
22331 +#endif
22332 +
22333 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22334 +
22335 +#ifdef CONFIG_PAX_KERNEXEC
22336 + " movl %0, %%cr0\n"
22337 +#endif
22338 +
22339 " jmp 2b\n"
22340 ".previous\n"
22341 _ASM_EXTABLE(1b, 3b)
22342 - : : "r" (from));
22343 + : "=&r" (cr0) : "r" (from) : "ax");
22344
22345 for ( ; i > 5; i--) {
22346 __asm__ __volatile__ (
22347 - "1: prefetch 320(%0)\n"
22348 - "2: movq (%0), %%mm0\n"
22349 - " movq 8(%0), %%mm1\n"
22350 - " movq 16(%0), %%mm2\n"
22351 - " movq 24(%0), %%mm3\n"
22352 - " movq %%mm0, (%1)\n"
22353 - " movq %%mm1, 8(%1)\n"
22354 - " movq %%mm2, 16(%1)\n"
22355 - " movq %%mm3, 24(%1)\n"
22356 - " movq 32(%0), %%mm0\n"
22357 - " movq 40(%0), %%mm1\n"
22358 - " movq 48(%0), %%mm2\n"
22359 - " movq 56(%0), %%mm3\n"
22360 - " movq %%mm0, 32(%1)\n"
22361 - " movq %%mm1, 40(%1)\n"
22362 - " movq %%mm2, 48(%1)\n"
22363 - " movq %%mm3, 56(%1)\n"
22364 + "1: prefetch 320(%1)\n"
22365 + "2: movq (%1), %%mm0\n"
22366 + " movq 8(%1), %%mm1\n"
22367 + " movq 16(%1), %%mm2\n"
22368 + " movq 24(%1), %%mm3\n"
22369 + " movq %%mm0, (%2)\n"
22370 + " movq %%mm1, 8(%2)\n"
22371 + " movq %%mm2, 16(%2)\n"
22372 + " movq %%mm3, 24(%2)\n"
22373 + " movq 32(%1), %%mm0\n"
22374 + " movq 40(%1), %%mm1\n"
22375 + " movq 48(%1), %%mm2\n"
22376 + " movq 56(%1), %%mm3\n"
22377 + " movq %%mm0, 32(%2)\n"
22378 + " movq %%mm1, 40(%2)\n"
22379 + " movq %%mm2, 48(%2)\n"
22380 + " movq %%mm3, 56(%2)\n"
22381 ".section .fixup, \"ax\"\n"
22382 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22383 + "3:\n"
22384 +
22385 +#ifdef CONFIG_PAX_KERNEXEC
22386 + " movl %%cr0, %0\n"
22387 + " movl %0, %%eax\n"
22388 + " andl $0xFFFEFFFF, %%eax\n"
22389 + " movl %%eax, %%cr0\n"
22390 +#endif
22391 +
22392 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22393 +
22394 +#ifdef CONFIG_PAX_KERNEXEC
22395 + " movl %0, %%cr0\n"
22396 +#endif
22397 +
22398 " jmp 2b\n"
22399 ".previous\n"
22400 _ASM_EXTABLE(1b, 3b)
22401 - : : "r" (from), "r" (to) : "memory");
22402 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22403
22404 from += 64;
22405 to += 64;
22406 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22407 static void fast_copy_page(void *to, void *from)
22408 {
22409 int i;
22410 + unsigned long cr0;
22411
22412 kernel_fpu_begin();
22413
22414 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22415 * but that is for later. -AV
22416 */
22417 __asm__ __volatile__(
22418 - "1: prefetch (%0)\n"
22419 - " prefetch 64(%0)\n"
22420 - " prefetch 128(%0)\n"
22421 - " prefetch 192(%0)\n"
22422 - " prefetch 256(%0)\n"
22423 + "1: prefetch (%1)\n"
22424 + " prefetch 64(%1)\n"
22425 + " prefetch 128(%1)\n"
22426 + " prefetch 192(%1)\n"
22427 + " prefetch 256(%1)\n"
22428 "2: \n"
22429 ".section .fixup, \"ax\"\n"
22430 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22431 + "3: \n"
22432 +
22433 +#ifdef CONFIG_PAX_KERNEXEC
22434 + " movl %%cr0, %0\n"
22435 + " movl %0, %%eax\n"
22436 + " andl $0xFFFEFFFF, %%eax\n"
22437 + " movl %%eax, %%cr0\n"
22438 +#endif
22439 +
22440 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22441 +
22442 +#ifdef CONFIG_PAX_KERNEXEC
22443 + " movl %0, %%cr0\n"
22444 +#endif
22445 +
22446 " jmp 2b\n"
22447 ".previous\n"
22448 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22449 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22450
22451 for (i = 0; i < (4096-320)/64; i++) {
22452 __asm__ __volatile__ (
22453 - "1: prefetch 320(%0)\n"
22454 - "2: movq (%0), %%mm0\n"
22455 - " movntq %%mm0, (%1)\n"
22456 - " movq 8(%0), %%mm1\n"
22457 - " movntq %%mm1, 8(%1)\n"
22458 - " movq 16(%0), %%mm2\n"
22459 - " movntq %%mm2, 16(%1)\n"
22460 - " movq 24(%0), %%mm3\n"
22461 - " movntq %%mm3, 24(%1)\n"
22462 - " movq 32(%0), %%mm4\n"
22463 - " movntq %%mm4, 32(%1)\n"
22464 - " movq 40(%0), %%mm5\n"
22465 - " movntq %%mm5, 40(%1)\n"
22466 - " movq 48(%0), %%mm6\n"
22467 - " movntq %%mm6, 48(%1)\n"
22468 - " movq 56(%0), %%mm7\n"
22469 - " movntq %%mm7, 56(%1)\n"
22470 + "1: prefetch 320(%1)\n"
22471 + "2: movq (%1), %%mm0\n"
22472 + " movntq %%mm0, (%2)\n"
22473 + " movq 8(%1), %%mm1\n"
22474 + " movntq %%mm1, 8(%2)\n"
22475 + " movq 16(%1), %%mm2\n"
22476 + " movntq %%mm2, 16(%2)\n"
22477 + " movq 24(%1), %%mm3\n"
22478 + " movntq %%mm3, 24(%2)\n"
22479 + " movq 32(%1), %%mm4\n"
22480 + " movntq %%mm4, 32(%2)\n"
22481 + " movq 40(%1), %%mm5\n"
22482 + " movntq %%mm5, 40(%2)\n"
22483 + " movq 48(%1), %%mm6\n"
22484 + " movntq %%mm6, 48(%2)\n"
22485 + " movq 56(%1), %%mm7\n"
22486 + " movntq %%mm7, 56(%2)\n"
22487 ".section .fixup, \"ax\"\n"
22488 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22489 + "3:\n"
22490 +
22491 +#ifdef CONFIG_PAX_KERNEXEC
22492 + " movl %%cr0, %0\n"
22493 + " movl %0, %%eax\n"
22494 + " andl $0xFFFEFFFF, %%eax\n"
22495 + " movl %%eax, %%cr0\n"
22496 +#endif
22497 +
22498 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22499 +
22500 +#ifdef CONFIG_PAX_KERNEXEC
22501 + " movl %0, %%cr0\n"
22502 +#endif
22503 +
22504 " jmp 2b\n"
22505 ".previous\n"
22506 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22507 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22508
22509 from += 64;
22510 to += 64;
22511 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22512 static void fast_copy_page(void *to, void *from)
22513 {
22514 int i;
22515 + unsigned long cr0;
22516
22517 kernel_fpu_begin();
22518
22519 __asm__ __volatile__ (
22520 - "1: prefetch (%0)\n"
22521 - " prefetch 64(%0)\n"
22522 - " prefetch 128(%0)\n"
22523 - " prefetch 192(%0)\n"
22524 - " prefetch 256(%0)\n"
22525 + "1: prefetch (%1)\n"
22526 + " prefetch 64(%1)\n"
22527 + " prefetch 128(%1)\n"
22528 + " prefetch 192(%1)\n"
22529 + " prefetch 256(%1)\n"
22530 "2: \n"
22531 ".section .fixup, \"ax\"\n"
22532 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22533 + "3: \n"
22534 +
22535 +#ifdef CONFIG_PAX_KERNEXEC
22536 + " movl %%cr0, %0\n"
22537 + " movl %0, %%eax\n"
22538 + " andl $0xFFFEFFFF, %%eax\n"
22539 + " movl %%eax, %%cr0\n"
22540 +#endif
22541 +
22542 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22543 +
22544 +#ifdef CONFIG_PAX_KERNEXEC
22545 + " movl %0, %%cr0\n"
22546 +#endif
22547 +
22548 " jmp 2b\n"
22549 ".previous\n"
22550 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22551 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22552
22553 for (i = 0; i < 4096/64; i++) {
22554 __asm__ __volatile__ (
22555 - "1: prefetch 320(%0)\n"
22556 - "2: movq (%0), %%mm0\n"
22557 - " movq 8(%0), %%mm1\n"
22558 - " movq 16(%0), %%mm2\n"
22559 - " movq 24(%0), %%mm3\n"
22560 - " movq %%mm0, (%1)\n"
22561 - " movq %%mm1, 8(%1)\n"
22562 - " movq %%mm2, 16(%1)\n"
22563 - " movq %%mm3, 24(%1)\n"
22564 - " movq 32(%0), %%mm0\n"
22565 - " movq 40(%0), %%mm1\n"
22566 - " movq 48(%0), %%mm2\n"
22567 - " movq 56(%0), %%mm3\n"
22568 - " movq %%mm0, 32(%1)\n"
22569 - " movq %%mm1, 40(%1)\n"
22570 - " movq %%mm2, 48(%1)\n"
22571 - " movq %%mm3, 56(%1)\n"
22572 + "1: prefetch 320(%1)\n"
22573 + "2: movq (%1), %%mm0\n"
22574 + " movq 8(%1), %%mm1\n"
22575 + " movq 16(%1), %%mm2\n"
22576 + " movq 24(%1), %%mm3\n"
22577 + " movq %%mm0, (%2)\n"
22578 + " movq %%mm1, 8(%2)\n"
22579 + " movq %%mm2, 16(%2)\n"
22580 + " movq %%mm3, 24(%2)\n"
22581 + " movq 32(%1), %%mm0\n"
22582 + " movq 40(%1), %%mm1\n"
22583 + " movq 48(%1), %%mm2\n"
22584 + " movq 56(%1), %%mm3\n"
22585 + " movq %%mm0, 32(%2)\n"
22586 + " movq %%mm1, 40(%2)\n"
22587 + " movq %%mm2, 48(%2)\n"
22588 + " movq %%mm3, 56(%2)\n"
22589 ".section .fixup, \"ax\"\n"
22590 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22591 + "3:\n"
22592 +
22593 +#ifdef CONFIG_PAX_KERNEXEC
22594 + " movl %%cr0, %0\n"
22595 + " movl %0, %%eax\n"
22596 + " andl $0xFFFEFFFF, %%eax\n"
22597 + " movl %%eax, %%cr0\n"
22598 +#endif
22599 +
22600 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22601 +
22602 +#ifdef CONFIG_PAX_KERNEXEC
22603 + " movl %0, %%cr0\n"
22604 +#endif
22605 +
22606 " jmp 2b\n"
22607 ".previous\n"
22608 _ASM_EXTABLE(1b, 3b)
22609 - : : "r" (from), "r" (to) : "memory");
22610 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22611
22612 from += 64;
22613 to += 64;
22614 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22615 index f6d13ee..aca5f0b 100644
22616 --- a/arch/x86/lib/msr-reg.S
22617 +++ b/arch/x86/lib/msr-reg.S
22618 @@ -3,6 +3,7 @@
22619 #include <asm/dwarf2.h>
22620 #include <asm/asm.h>
22621 #include <asm/msr.h>
22622 +#include <asm/alternative-asm.h>
22623
22624 #ifdef CONFIG_X86_64
22625 /*
22626 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22627 CFI_STARTPROC
22628 pushq_cfi %rbx
22629 pushq_cfi %rbp
22630 - movq %rdi, %r10 /* Save pointer */
22631 + movq %rdi, %r9 /* Save pointer */
22632 xorl %r11d, %r11d /* Return value */
22633 movl (%rdi), %eax
22634 movl 4(%rdi), %ecx
22635 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22636 movl 28(%rdi), %edi
22637 CFI_REMEMBER_STATE
22638 1: \op
22639 -2: movl %eax, (%r10)
22640 +2: movl %eax, (%r9)
22641 movl %r11d, %eax /* Return value */
22642 - movl %ecx, 4(%r10)
22643 - movl %edx, 8(%r10)
22644 - movl %ebx, 12(%r10)
22645 - movl %ebp, 20(%r10)
22646 - movl %esi, 24(%r10)
22647 - movl %edi, 28(%r10)
22648 + movl %ecx, 4(%r9)
22649 + movl %edx, 8(%r9)
22650 + movl %ebx, 12(%r9)
22651 + movl %ebp, 20(%r9)
22652 + movl %esi, 24(%r9)
22653 + movl %edi, 28(%r9)
22654 popq_cfi %rbp
22655 popq_cfi %rbx
22656 + pax_force_retaddr
22657 ret
22658 3:
22659 CFI_RESTORE_STATE
22660 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22661 index 7f951c8..ebd573a 100644
22662 --- a/arch/x86/lib/putuser.S
22663 +++ b/arch/x86/lib/putuser.S
22664 @@ -15,7 +15,9 @@
22665 #include <asm/thread_info.h>
22666 #include <asm/errno.h>
22667 #include <asm/asm.h>
22668 -
22669 +#include <asm/segment.h>
22670 +#include <asm/pgtable.h>
22671 +#include <asm/alternative-asm.h>
22672
22673 /*
22674 * __put_user_X
22675 @@ -29,52 +31,119 @@
22676 * as they get called from within inline assembly.
22677 */
22678
22679 -#define ENTER CFI_STARTPROC ; \
22680 - GET_THREAD_INFO(%_ASM_BX)
22681 -#define EXIT ret ; \
22682 +#define ENTER CFI_STARTPROC
22683 +#define EXIT pax_force_retaddr; ret ; \
22684 CFI_ENDPROC
22685
22686 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22687 +#define _DEST %_ASM_CX,%_ASM_BX
22688 +#else
22689 +#define _DEST %_ASM_CX
22690 +#endif
22691 +
22692 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22693 +#define __copyuser_seg gs;
22694 +#else
22695 +#define __copyuser_seg
22696 +#endif
22697 +
22698 .text
22699 ENTRY(__put_user_1)
22700 ENTER
22701 +
22702 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22703 + GET_THREAD_INFO(%_ASM_BX)
22704 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22705 jae bad_put_user
22706 -1: movb %al,(%_ASM_CX)
22707 +
22708 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22709 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22710 + cmp %_ASM_BX,%_ASM_CX
22711 + jb 1234f
22712 + xor %ebx,%ebx
22713 +1234:
22714 +#endif
22715 +
22716 +#endif
22717 +
22718 +1: __copyuser_seg movb %al,(_DEST)
22719 xor %eax,%eax
22720 EXIT
22721 ENDPROC(__put_user_1)
22722
22723 ENTRY(__put_user_2)
22724 ENTER
22725 +
22726 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22727 + GET_THREAD_INFO(%_ASM_BX)
22728 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22729 sub $1,%_ASM_BX
22730 cmp %_ASM_BX,%_ASM_CX
22731 jae bad_put_user
22732 -2: movw %ax,(%_ASM_CX)
22733 +
22734 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22735 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22736 + cmp %_ASM_BX,%_ASM_CX
22737 + jb 1234f
22738 + xor %ebx,%ebx
22739 +1234:
22740 +#endif
22741 +
22742 +#endif
22743 +
22744 +2: __copyuser_seg movw %ax,(_DEST)
22745 xor %eax,%eax
22746 EXIT
22747 ENDPROC(__put_user_2)
22748
22749 ENTRY(__put_user_4)
22750 ENTER
22751 +
22752 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22753 + GET_THREAD_INFO(%_ASM_BX)
22754 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22755 sub $3,%_ASM_BX
22756 cmp %_ASM_BX,%_ASM_CX
22757 jae bad_put_user
22758 -3: movl %eax,(%_ASM_CX)
22759 +
22760 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22761 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22762 + cmp %_ASM_BX,%_ASM_CX
22763 + jb 1234f
22764 + xor %ebx,%ebx
22765 +1234:
22766 +#endif
22767 +
22768 +#endif
22769 +
22770 +3: __copyuser_seg movl %eax,(_DEST)
22771 xor %eax,%eax
22772 EXIT
22773 ENDPROC(__put_user_4)
22774
22775 ENTRY(__put_user_8)
22776 ENTER
22777 +
22778 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22779 + GET_THREAD_INFO(%_ASM_BX)
22780 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22781 sub $7,%_ASM_BX
22782 cmp %_ASM_BX,%_ASM_CX
22783 jae bad_put_user
22784 -4: mov %_ASM_AX,(%_ASM_CX)
22785 +
22786 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22787 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22788 + cmp %_ASM_BX,%_ASM_CX
22789 + jb 1234f
22790 + xor %ebx,%ebx
22791 +1234:
22792 +#endif
22793 +
22794 +#endif
22795 +
22796 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22797 #ifdef CONFIG_X86_32
22798 -5: movl %edx,4(%_ASM_CX)
22799 +5: __copyuser_seg movl %edx,4(_DEST)
22800 #endif
22801 xor %eax,%eax
22802 EXIT
22803 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22804 index 1cad221..de671ee 100644
22805 --- a/arch/x86/lib/rwlock.S
22806 +++ b/arch/x86/lib/rwlock.S
22807 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22808 FRAME
22809 0: LOCK_PREFIX
22810 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22811 +
22812 +#ifdef CONFIG_PAX_REFCOUNT
22813 + jno 1234f
22814 + LOCK_PREFIX
22815 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22816 + int $4
22817 +1234:
22818 + _ASM_EXTABLE(1234b, 1234b)
22819 +#endif
22820 +
22821 1: rep; nop
22822 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22823 jne 1b
22824 LOCK_PREFIX
22825 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22826 +
22827 +#ifdef CONFIG_PAX_REFCOUNT
22828 + jno 1234f
22829 + LOCK_PREFIX
22830 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22831 + int $4
22832 +1234:
22833 + _ASM_EXTABLE(1234b, 1234b)
22834 +#endif
22835 +
22836 jnz 0b
22837 ENDFRAME
22838 + pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 END(__write_lock_failed)
22842 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22843 FRAME
22844 0: LOCK_PREFIX
22845 READ_LOCK_SIZE(inc) (%__lock_ptr)
22846 +
22847 +#ifdef CONFIG_PAX_REFCOUNT
22848 + jno 1234f
22849 + LOCK_PREFIX
22850 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22851 + int $4
22852 +1234:
22853 + _ASM_EXTABLE(1234b, 1234b)
22854 +#endif
22855 +
22856 1: rep; nop
22857 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22858 js 1b
22859 LOCK_PREFIX
22860 READ_LOCK_SIZE(dec) (%__lock_ptr)
22861 +
22862 +#ifdef CONFIG_PAX_REFCOUNT
22863 + jno 1234f
22864 + LOCK_PREFIX
22865 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22866 + int $4
22867 +1234:
22868 + _ASM_EXTABLE(1234b, 1234b)
22869 +#endif
22870 +
22871 js 0b
22872 ENDFRAME
22873 + pax_force_retaddr
22874 ret
22875 CFI_ENDPROC
22876 END(__read_lock_failed)
22877 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22878 index 5dff5f0..cadebf4 100644
22879 --- a/arch/x86/lib/rwsem.S
22880 +++ b/arch/x86/lib/rwsem.S
22881 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22882 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22883 CFI_RESTORE __ASM_REG(dx)
22884 restore_common_regs
22885 + pax_force_retaddr
22886 ret
22887 CFI_ENDPROC
22888 ENDPROC(call_rwsem_down_read_failed)
22889 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22890 movq %rax,%rdi
22891 call rwsem_down_write_failed
22892 restore_common_regs
22893 + pax_force_retaddr
22894 ret
22895 CFI_ENDPROC
22896 ENDPROC(call_rwsem_down_write_failed)
22897 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22898 movq %rax,%rdi
22899 call rwsem_wake
22900 restore_common_regs
22901 -1: ret
22902 +1: pax_force_retaddr
22903 + ret
22904 CFI_ENDPROC
22905 ENDPROC(call_rwsem_wake)
22906
22907 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22908 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22909 CFI_RESTORE __ASM_REG(dx)
22910 restore_common_regs
22911 + pax_force_retaddr
22912 ret
22913 CFI_ENDPROC
22914 ENDPROC(call_rwsem_downgrade_wake)
22915 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22916 index a63efd6..ccecad8 100644
22917 --- a/arch/x86/lib/thunk_64.S
22918 +++ b/arch/x86/lib/thunk_64.S
22919 @@ -8,6 +8,7 @@
22920 #include <linux/linkage.h>
22921 #include <asm/dwarf2.h>
22922 #include <asm/calling.h>
22923 +#include <asm/alternative-asm.h>
22924
22925 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22926 .macro THUNK name, func, put_ret_addr_in_rdi=0
22927 @@ -41,5 +42,6 @@
22928 SAVE_ARGS
22929 restore:
22930 RESTORE_ARGS
22931 + pax_force_retaddr
22932 ret
22933 CFI_ENDPROC
22934 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22935 index 1781b2f..90368dd 100644
22936 --- a/arch/x86/lib/usercopy_32.c
22937 +++ b/arch/x86/lib/usercopy_32.c
22938 @@ -42,10 +42,12 @@ do { \
22939 int __d0; \
22940 might_fault(); \
22941 __asm__ __volatile__( \
22942 + __COPYUSER_SET_ES \
22943 "0: rep; stosl\n" \
22944 " movl %2,%0\n" \
22945 "1: rep; stosb\n" \
22946 "2:\n" \
22947 + __COPYUSER_RESTORE_ES \
22948 ".section .fixup,\"ax\"\n" \
22949 "3: lea 0(%2,%0,4),%0\n" \
22950 " jmp 2b\n" \
22951 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22952
22953 #ifdef CONFIG_X86_INTEL_USERCOPY
22954 static unsigned long
22955 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22956 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22957 {
22958 int d0, d1;
22959 __asm__ __volatile__(
22960 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22961 " .align 2,0x90\n"
22962 "3: movl 0(%4), %%eax\n"
22963 "4: movl 4(%4), %%edx\n"
22964 - "5: movl %%eax, 0(%3)\n"
22965 - "6: movl %%edx, 4(%3)\n"
22966 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22967 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22968 "7: movl 8(%4), %%eax\n"
22969 "8: movl 12(%4),%%edx\n"
22970 - "9: movl %%eax, 8(%3)\n"
22971 - "10: movl %%edx, 12(%3)\n"
22972 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22973 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22974 "11: movl 16(%4), %%eax\n"
22975 "12: movl 20(%4), %%edx\n"
22976 - "13: movl %%eax, 16(%3)\n"
22977 - "14: movl %%edx, 20(%3)\n"
22978 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22979 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22980 "15: movl 24(%4), %%eax\n"
22981 "16: movl 28(%4), %%edx\n"
22982 - "17: movl %%eax, 24(%3)\n"
22983 - "18: movl %%edx, 28(%3)\n"
22984 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22985 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22986 "19: movl 32(%4), %%eax\n"
22987 "20: movl 36(%4), %%edx\n"
22988 - "21: movl %%eax, 32(%3)\n"
22989 - "22: movl %%edx, 36(%3)\n"
22990 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22991 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22992 "23: movl 40(%4), %%eax\n"
22993 "24: movl 44(%4), %%edx\n"
22994 - "25: movl %%eax, 40(%3)\n"
22995 - "26: movl %%edx, 44(%3)\n"
22996 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22997 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22998 "27: movl 48(%4), %%eax\n"
22999 "28: movl 52(%4), %%edx\n"
23000 - "29: movl %%eax, 48(%3)\n"
23001 - "30: movl %%edx, 52(%3)\n"
23002 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23003 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23004 "31: movl 56(%4), %%eax\n"
23005 "32: movl 60(%4), %%edx\n"
23006 - "33: movl %%eax, 56(%3)\n"
23007 - "34: movl %%edx, 60(%3)\n"
23008 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23009 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23010 " addl $-64, %0\n"
23011 " addl $64, %4\n"
23012 " addl $64, %3\n"
23013 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23014 " shrl $2, %0\n"
23015 " andl $3, %%eax\n"
23016 " cld\n"
23017 + __COPYUSER_SET_ES
23018 "99: rep; movsl\n"
23019 "36: movl %%eax, %0\n"
23020 "37: rep; movsb\n"
23021 "100:\n"
23022 + __COPYUSER_RESTORE_ES
23023 ".section .fixup,\"ax\"\n"
23024 "101: lea 0(%%eax,%0,4),%0\n"
23025 " jmp 100b\n"
23026 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23027 }
23028
23029 static unsigned long
23030 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23031 +{
23032 + int d0, d1;
23033 + __asm__ __volatile__(
23034 + " .align 2,0x90\n"
23035 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23036 + " cmpl $67, %0\n"
23037 + " jbe 3f\n"
23038 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23039 + " .align 2,0x90\n"
23040 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23041 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23042 + "5: movl %%eax, 0(%3)\n"
23043 + "6: movl %%edx, 4(%3)\n"
23044 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23045 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23046 + "9: movl %%eax, 8(%3)\n"
23047 + "10: movl %%edx, 12(%3)\n"
23048 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23049 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23050 + "13: movl %%eax, 16(%3)\n"
23051 + "14: movl %%edx, 20(%3)\n"
23052 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23053 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23054 + "17: movl %%eax, 24(%3)\n"
23055 + "18: movl %%edx, 28(%3)\n"
23056 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23057 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23058 + "21: movl %%eax, 32(%3)\n"
23059 + "22: movl %%edx, 36(%3)\n"
23060 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23061 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23062 + "25: movl %%eax, 40(%3)\n"
23063 + "26: movl %%edx, 44(%3)\n"
23064 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23065 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23066 + "29: movl %%eax, 48(%3)\n"
23067 + "30: movl %%edx, 52(%3)\n"
23068 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23069 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23070 + "33: movl %%eax, 56(%3)\n"
23071 + "34: movl %%edx, 60(%3)\n"
23072 + " addl $-64, %0\n"
23073 + " addl $64, %4\n"
23074 + " addl $64, %3\n"
23075 + " cmpl $63, %0\n"
23076 + " ja 1b\n"
23077 + "35: movl %0, %%eax\n"
23078 + " shrl $2, %0\n"
23079 + " andl $3, %%eax\n"
23080 + " cld\n"
23081 + "99: rep; "__copyuser_seg" movsl\n"
23082 + "36: movl %%eax, %0\n"
23083 + "37: rep; "__copyuser_seg" movsb\n"
23084 + "100:\n"
23085 + ".section .fixup,\"ax\"\n"
23086 + "101: lea 0(%%eax,%0,4),%0\n"
23087 + " jmp 100b\n"
23088 + ".previous\n"
23089 + _ASM_EXTABLE(1b,100b)
23090 + _ASM_EXTABLE(2b,100b)
23091 + _ASM_EXTABLE(3b,100b)
23092 + _ASM_EXTABLE(4b,100b)
23093 + _ASM_EXTABLE(5b,100b)
23094 + _ASM_EXTABLE(6b,100b)
23095 + _ASM_EXTABLE(7b,100b)
23096 + _ASM_EXTABLE(8b,100b)
23097 + _ASM_EXTABLE(9b,100b)
23098 + _ASM_EXTABLE(10b,100b)
23099 + _ASM_EXTABLE(11b,100b)
23100 + _ASM_EXTABLE(12b,100b)
23101 + _ASM_EXTABLE(13b,100b)
23102 + _ASM_EXTABLE(14b,100b)
23103 + _ASM_EXTABLE(15b,100b)
23104 + _ASM_EXTABLE(16b,100b)
23105 + _ASM_EXTABLE(17b,100b)
23106 + _ASM_EXTABLE(18b,100b)
23107 + _ASM_EXTABLE(19b,100b)
23108 + _ASM_EXTABLE(20b,100b)
23109 + _ASM_EXTABLE(21b,100b)
23110 + _ASM_EXTABLE(22b,100b)
23111 + _ASM_EXTABLE(23b,100b)
23112 + _ASM_EXTABLE(24b,100b)
23113 + _ASM_EXTABLE(25b,100b)
23114 + _ASM_EXTABLE(26b,100b)
23115 + _ASM_EXTABLE(27b,100b)
23116 + _ASM_EXTABLE(28b,100b)
23117 + _ASM_EXTABLE(29b,100b)
23118 + _ASM_EXTABLE(30b,100b)
23119 + _ASM_EXTABLE(31b,100b)
23120 + _ASM_EXTABLE(32b,100b)
23121 + _ASM_EXTABLE(33b,100b)
23122 + _ASM_EXTABLE(34b,100b)
23123 + _ASM_EXTABLE(35b,100b)
23124 + _ASM_EXTABLE(36b,100b)
23125 + _ASM_EXTABLE(37b,100b)
23126 + _ASM_EXTABLE(99b,101b)
23127 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23128 + : "1"(to), "2"(from), "0"(size)
23129 + : "eax", "edx", "memory");
23130 + return size;
23131 +}
23132 +
23133 +static unsigned long __size_overflow(3)
23134 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23135 {
23136 int d0, d1;
23137 __asm__ __volatile__(
23138 " .align 2,0x90\n"
23139 - "0: movl 32(%4), %%eax\n"
23140 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23141 " cmpl $67, %0\n"
23142 " jbe 2f\n"
23143 - "1: movl 64(%4), %%eax\n"
23144 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23145 " .align 2,0x90\n"
23146 - "2: movl 0(%4), %%eax\n"
23147 - "21: movl 4(%4), %%edx\n"
23148 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23149 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23150 " movl %%eax, 0(%3)\n"
23151 " movl %%edx, 4(%3)\n"
23152 - "3: movl 8(%4), %%eax\n"
23153 - "31: movl 12(%4),%%edx\n"
23154 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23155 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23156 " movl %%eax, 8(%3)\n"
23157 " movl %%edx, 12(%3)\n"
23158 - "4: movl 16(%4), %%eax\n"
23159 - "41: movl 20(%4), %%edx\n"
23160 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23161 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23162 " movl %%eax, 16(%3)\n"
23163 " movl %%edx, 20(%3)\n"
23164 - "10: movl 24(%4), %%eax\n"
23165 - "51: movl 28(%4), %%edx\n"
23166 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23167 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23168 " movl %%eax, 24(%3)\n"
23169 " movl %%edx, 28(%3)\n"
23170 - "11: movl 32(%4), %%eax\n"
23171 - "61: movl 36(%4), %%edx\n"
23172 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23173 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23174 " movl %%eax, 32(%3)\n"
23175 " movl %%edx, 36(%3)\n"
23176 - "12: movl 40(%4), %%eax\n"
23177 - "71: movl 44(%4), %%edx\n"
23178 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23179 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23180 " movl %%eax, 40(%3)\n"
23181 " movl %%edx, 44(%3)\n"
23182 - "13: movl 48(%4), %%eax\n"
23183 - "81: movl 52(%4), %%edx\n"
23184 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23185 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23186 " movl %%eax, 48(%3)\n"
23187 " movl %%edx, 52(%3)\n"
23188 - "14: movl 56(%4), %%eax\n"
23189 - "91: movl 60(%4), %%edx\n"
23190 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23191 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23192 " movl %%eax, 56(%3)\n"
23193 " movl %%edx, 60(%3)\n"
23194 " addl $-64, %0\n"
23195 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23196 " shrl $2, %0\n"
23197 " andl $3, %%eax\n"
23198 " cld\n"
23199 - "6: rep; movsl\n"
23200 + "6: rep; "__copyuser_seg" movsl\n"
23201 " movl %%eax,%0\n"
23202 - "7: rep; movsb\n"
23203 + "7: rep; "__copyuser_seg" movsb\n"
23204 "8:\n"
23205 ".section .fixup,\"ax\"\n"
23206 "9: lea 0(%%eax,%0,4),%0\n"
23207 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23208 * hyoshiok@miraclelinux.com
23209 */
23210
23211 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23212 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23213 const void __user *from, unsigned long size)
23214 {
23215 int d0, d1;
23216
23217 __asm__ __volatile__(
23218 " .align 2,0x90\n"
23219 - "0: movl 32(%4), %%eax\n"
23220 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23221 " cmpl $67, %0\n"
23222 " jbe 2f\n"
23223 - "1: movl 64(%4), %%eax\n"
23224 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23225 " .align 2,0x90\n"
23226 - "2: movl 0(%4), %%eax\n"
23227 - "21: movl 4(%4), %%edx\n"
23228 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23229 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23230 " movnti %%eax, 0(%3)\n"
23231 " movnti %%edx, 4(%3)\n"
23232 - "3: movl 8(%4), %%eax\n"
23233 - "31: movl 12(%4),%%edx\n"
23234 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23235 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23236 " movnti %%eax, 8(%3)\n"
23237 " movnti %%edx, 12(%3)\n"
23238 - "4: movl 16(%4), %%eax\n"
23239 - "41: movl 20(%4), %%edx\n"
23240 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23241 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23242 " movnti %%eax, 16(%3)\n"
23243 " movnti %%edx, 20(%3)\n"
23244 - "10: movl 24(%4), %%eax\n"
23245 - "51: movl 28(%4), %%edx\n"
23246 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23247 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23248 " movnti %%eax, 24(%3)\n"
23249 " movnti %%edx, 28(%3)\n"
23250 - "11: movl 32(%4), %%eax\n"
23251 - "61: movl 36(%4), %%edx\n"
23252 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23253 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23254 " movnti %%eax, 32(%3)\n"
23255 " movnti %%edx, 36(%3)\n"
23256 - "12: movl 40(%4), %%eax\n"
23257 - "71: movl 44(%4), %%edx\n"
23258 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23259 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23260 " movnti %%eax, 40(%3)\n"
23261 " movnti %%edx, 44(%3)\n"
23262 - "13: movl 48(%4), %%eax\n"
23263 - "81: movl 52(%4), %%edx\n"
23264 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23265 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23266 " movnti %%eax, 48(%3)\n"
23267 " movnti %%edx, 52(%3)\n"
23268 - "14: movl 56(%4), %%eax\n"
23269 - "91: movl 60(%4), %%edx\n"
23270 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23271 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23272 " movnti %%eax, 56(%3)\n"
23273 " movnti %%edx, 60(%3)\n"
23274 " addl $-64, %0\n"
23275 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23276 " shrl $2, %0\n"
23277 " andl $3, %%eax\n"
23278 " cld\n"
23279 - "6: rep; movsl\n"
23280 + "6: rep; "__copyuser_seg" movsl\n"
23281 " movl %%eax,%0\n"
23282 - "7: rep; movsb\n"
23283 + "7: rep; "__copyuser_seg" movsb\n"
23284 "8:\n"
23285 ".section .fixup,\"ax\"\n"
23286 "9: lea 0(%%eax,%0,4),%0\n"
23287 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23288 return size;
23289 }
23290
23291 -static unsigned long __copy_user_intel_nocache(void *to,
23292 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23293 const void __user *from, unsigned long size)
23294 {
23295 int d0, d1;
23296
23297 __asm__ __volatile__(
23298 " .align 2,0x90\n"
23299 - "0: movl 32(%4), %%eax\n"
23300 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23301 " cmpl $67, %0\n"
23302 " jbe 2f\n"
23303 - "1: movl 64(%4), %%eax\n"
23304 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23305 " .align 2,0x90\n"
23306 - "2: movl 0(%4), %%eax\n"
23307 - "21: movl 4(%4), %%edx\n"
23308 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23309 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23310 " movnti %%eax, 0(%3)\n"
23311 " movnti %%edx, 4(%3)\n"
23312 - "3: movl 8(%4), %%eax\n"
23313 - "31: movl 12(%4),%%edx\n"
23314 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23315 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23316 " movnti %%eax, 8(%3)\n"
23317 " movnti %%edx, 12(%3)\n"
23318 - "4: movl 16(%4), %%eax\n"
23319 - "41: movl 20(%4), %%edx\n"
23320 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23321 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23322 " movnti %%eax, 16(%3)\n"
23323 " movnti %%edx, 20(%3)\n"
23324 - "10: movl 24(%4), %%eax\n"
23325 - "51: movl 28(%4), %%edx\n"
23326 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23327 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23328 " movnti %%eax, 24(%3)\n"
23329 " movnti %%edx, 28(%3)\n"
23330 - "11: movl 32(%4), %%eax\n"
23331 - "61: movl 36(%4), %%edx\n"
23332 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23333 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23334 " movnti %%eax, 32(%3)\n"
23335 " movnti %%edx, 36(%3)\n"
23336 - "12: movl 40(%4), %%eax\n"
23337 - "71: movl 44(%4), %%edx\n"
23338 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23339 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23340 " movnti %%eax, 40(%3)\n"
23341 " movnti %%edx, 44(%3)\n"
23342 - "13: movl 48(%4), %%eax\n"
23343 - "81: movl 52(%4), %%edx\n"
23344 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23345 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23346 " movnti %%eax, 48(%3)\n"
23347 " movnti %%edx, 52(%3)\n"
23348 - "14: movl 56(%4), %%eax\n"
23349 - "91: movl 60(%4), %%edx\n"
23350 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23351 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23352 " movnti %%eax, 56(%3)\n"
23353 " movnti %%edx, 60(%3)\n"
23354 " addl $-64, %0\n"
23355 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23356 " shrl $2, %0\n"
23357 " andl $3, %%eax\n"
23358 " cld\n"
23359 - "6: rep; movsl\n"
23360 + "6: rep; "__copyuser_seg" movsl\n"
23361 " movl %%eax,%0\n"
23362 - "7: rep; movsb\n"
23363 + "7: rep; "__copyuser_seg" movsb\n"
23364 "8:\n"
23365 ".section .fixup,\"ax\"\n"
23366 "9: lea 0(%%eax,%0,4),%0\n"
23367 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23368 */
23369 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23370 unsigned long size);
23371 -unsigned long __copy_user_intel(void __user *to, const void *from,
23372 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23373 + unsigned long size);
23374 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23375 unsigned long size);
23376 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23377 const void __user *from, unsigned long size);
23378 #endif /* CONFIG_X86_INTEL_USERCOPY */
23379
23380 /* Generic arbitrary sized copy. */
23381 -#define __copy_user(to, from, size) \
23382 +#define __copy_user(to, from, size, prefix, set, restore) \
23383 do { \
23384 int __d0, __d1, __d2; \
23385 __asm__ __volatile__( \
23386 + set \
23387 " cmp $7,%0\n" \
23388 " jbe 1f\n" \
23389 " movl %1,%0\n" \
23390 " negl %0\n" \
23391 " andl $7,%0\n" \
23392 " subl %0,%3\n" \
23393 - "4: rep; movsb\n" \
23394 + "4: rep; "prefix"movsb\n" \
23395 " movl %3,%0\n" \
23396 " shrl $2,%0\n" \
23397 " andl $3,%3\n" \
23398 " .align 2,0x90\n" \
23399 - "0: rep; movsl\n" \
23400 + "0: rep; "prefix"movsl\n" \
23401 " movl %3,%0\n" \
23402 - "1: rep; movsb\n" \
23403 + "1: rep; "prefix"movsb\n" \
23404 "2:\n" \
23405 + restore \
23406 ".section .fixup,\"ax\"\n" \
23407 "5: addl %3,%0\n" \
23408 " jmp 2b\n" \
23409 @@ -537,14 +649,14 @@ do { \
23410 " negl %0\n" \
23411 " andl $7,%0\n" \
23412 " subl %0,%3\n" \
23413 - "4: rep; movsb\n" \
23414 + "4: rep; "__copyuser_seg"movsb\n" \
23415 " movl %3,%0\n" \
23416 " shrl $2,%0\n" \
23417 " andl $3,%3\n" \
23418 " .align 2,0x90\n" \
23419 - "0: rep; movsl\n" \
23420 + "0: rep; "__copyuser_seg"movsl\n" \
23421 " movl %3,%0\n" \
23422 - "1: rep; movsb\n" \
23423 + "1: rep; "__copyuser_seg"movsb\n" \
23424 "2:\n" \
23425 ".section .fixup,\"ax\"\n" \
23426 "5: addl %3,%0\n" \
23427 @@ -627,9 +739,9 @@ survive:
23428 }
23429 #endif
23430 if (movsl_is_ok(to, from, n))
23431 - __copy_user(to, from, n);
23432 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23433 else
23434 - n = __copy_user_intel(to, from, n);
23435 + n = __generic_copy_to_user_intel(to, from, n);
23436 return n;
23437 }
23438 EXPORT_SYMBOL(__copy_to_user_ll);
23439 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23440 unsigned long n)
23441 {
23442 if (movsl_is_ok(to, from, n))
23443 - __copy_user(to, from, n);
23444 + __copy_user(to, from, n, __copyuser_seg, "", "");
23445 else
23446 - n = __copy_user_intel((void __user *)to,
23447 - (const void *)from, n);
23448 + n = __generic_copy_from_user_intel(to, from, n);
23449 return n;
23450 }
23451 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23452 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23453 if (n > 64 && cpu_has_xmm2)
23454 n = __copy_user_intel_nocache(to, from, n);
23455 else
23456 - __copy_user(to, from, n);
23457 + __copy_user(to, from, n, __copyuser_seg, "", "");
23458 #else
23459 - __copy_user(to, from, n);
23460 + __copy_user(to, from, n, __copyuser_seg, "", "");
23461 #endif
23462 return n;
23463 }
23464 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23465
23466 -/**
23467 - * copy_to_user: - Copy a block of data into user space.
23468 - * @to: Destination address, in user space.
23469 - * @from: Source address, in kernel space.
23470 - * @n: Number of bytes to copy.
23471 - *
23472 - * Context: User context only. This function may sleep.
23473 - *
23474 - * Copy data from kernel space to user space.
23475 - *
23476 - * Returns number of bytes that could not be copied.
23477 - * On success, this will be zero.
23478 - */
23479 -unsigned long
23480 -copy_to_user(void __user *to, const void *from, unsigned long n)
23481 -{
23482 - if (access_ok(VERIFY_WRITE, to, n))
23483 - n = __copy_to_user(to, from, n);
23484 - return n;
23485 -}
23486 -EXPORT_SYMBOL(copy_to_user);
23487 -
23488 -/**
23489 - * copy_from_user: - Copy a block of data from user space.
23490 - * @to: Destination address, in kernel space.
23491 - * @from: Source address, in user space.
23492 - * @n: Number of bytes to copy.
23493 - *
23494 - * Context: User context only. This function may sleep.
23495 - *
23496 - * Copy data from user space to kernel space.
23497 - *
23498 - * Returns number of bytes that could not be copied.
23499 - * On success, this will be zero.
23500 - *
23501 - * If some data could not be copied, this function will pad the copied
23502 - * data to the requested size using zero bytes.
23503 - */
23504 -unsigned long
23505 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23506 -{
23507 - if (access_ok(VERIFY_READ, from, n))
23508 - n = __copy_from_user(to, from, n);
23509 - else
23510 - memset(to, 0, n);
23511 - return n;
23512 -}
23513 -EXPORT_SYMBOL(_copy_from_user);
23514 -
23515 void copy_from_user_overflow(void)
23516 {
23517 WARN(1, "Buffer overflow detected!\n");
23518 }
23519 EXPORT_SYMBOL(copy_from_user_overflow);
23520 +
23521 +void copy_to_user_overflow(void)
23522 +{
23523 + WARN(1, "Buffer overflow detected!\n");
23524 +}
23525 +EXPORT_SYMBOL(copy_to_user_overflow);
23526 +
23527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23528 +void __set_fs(mm_segment_t x)
23529 +{
23530 + switch (x.seg) {
23531 + case 0:
23532 + loadsegment(gs, 0);
23533 + break;
23534 + case TASK_SIZE_MAX:
23535 + loadsegment(gs, __USER_DS);
23536 + break;
23537 + case -1UL:
23538 + loadsegment(gs, __KERNEL_DS);
23539 + break;
23540 + default:
23541 + BUG();
23542 + }
23543 + return;
23544 +}
23545 +EXPORT_SYMBOL(__set_fs);
23546 +
23547 +void set_fs(mm_segment_t x)
23548 +{
23549 + current_thread_info()->addr_limit = x;
23550 + __set_fs(x);
23551 +}
23552 +EXPORT_SYMBOL(set_fs);
23553 +#endif
23554 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23555 index e5b130b..6690d31 100644
23556 --- a/arch/x86/lib/usercopy_64.c
23557 +++ b/arch/x86/lib/usercopy_64.c
23558 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23559 {
23560 long __d0;
23561 might_fault();
23562 +
23563 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23564 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23565 + addr += PAX_USER_SHADOW_BASE;
23566 +#endif
23567 +
23568 /* no memory constraint because it doesn't change any memory gcc knows
23569 about */
23570 asm volatile(
23571 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23572 }
23573 EXPORT_SYMBOL(clear_user);
23574
23575 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23576 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23577 {
23578 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23579 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23580 - }
23581 - return len;
23582 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23583 +
23584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23585 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23586 + to += PAX_USER_SHADOW_BASE;
23587 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23588 + from += PAX_USER_SHADOW_BASE;
23589 +#endif
23590 +
23591 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23592 + }
23593 + return len;
23594 }
23595 EXPORT_SYMBOL(copy_in_user);
23596
23597 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23598 * it is not necessary to optimize tail handling.
23599 */
23600 unsigned long
23601 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23602 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23603 {
23604 char c;
23605 unsigned zero_len;
23606 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23607 break;
23608 return len;
23609 }
23610 +
23611 +void copy_from_user_overflow(void)
23612 +{
23613 + WARN(1, "Buffer overflow detected!\n");
23614 +}
23615 +EXPORT_SYMBOL(copy_from_user_overflow);
23616 +
23617 +void copy_to_user_overflow(void)
23618 +{
23619 + WARN(1, "Buffer overflow detected!\n");
23620 +}
23621 +EXPORT_SYMBOL(copy_to_user_overflow);
23622 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23623 index 903ec1e..c4166b2 100644
23624 --- a/arch/x86/mm/extable.c
23625 +++ b/arch/x86/mm/extable.c
23626 @@ -6,12 +6,24 @@
23627 static inline unsigned long
23628 ex_insn_addr(const struct exception_table_entry *x)
23629 {
23630 - return (unsigned long)&x->insn + x->insn;
23631 + unsigned long reloc = 0;
23632 +
23633 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23634 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23635 +#endif
23636 +
23637 + return (unsigned long)&x->insn + x->insn + reloc;
23638 }
23639 static inline unsigned long
23640 ex_fixup_addr(const struct exception_table_entry *x)
23641 {
23642 - return (unsigned long)&x->fixup + x->fixup;
23643 + unsigned long reloc = 0;
23644 +
23645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23646 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23647 +#endif
23648 +
23649 + return (unsigned long)&x->fixup + x->fixup + reloc;
23650 }
23651
23652 int fixup_exception(struct pt_regs *regs)
23653 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23654 unsigned long new_ip;
23655
23656 #ifdef CONFIG_PNPBIOS
23657 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23658 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23659 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23660 extern u32 pnp_bios_is_utter_crap;
23661 pnp_bios_is_utter_crap = 1;
23662 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23663 i += 4;
23664 p->fixup -= i;
23665 i += 4;
23666 +
23667 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23668 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23669 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23670 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23671 +#endif
23672 +
23673 }
23674 }
23675
23676 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23677 index 76dcd9d..e9dffde 100644
23678 --- a/arch/x86/mm/fault.c
23679 +++ b/arch/x86/mm/fault.c
23680 @@ -13,11 +13,18 @@
23681 #include <linux/perf_event.h> /* perf_sw_event */
23682 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23683 #include <linux/prefetch.h> /* prefetchw */
23684 +#include <linux/unistd.h>
23685 +#include <linux/compiler.h>
23686
23687 #include <asm/traps.h> /* dotraplinkage, ... */
23688 #include <asm/pgalloc.h> /* pgd_*(), ... */
23689 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23690 #include <asm/fixmap.h> /* VSYSCALL_START */
23691 +#include <asm/tlbflush.h>
23692 +
23693 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23694 +#include <asm/stacktrace.h>
23695 +#endif
23696
23697 /*
23698 * Page fault error code bits:
23699 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23700 int ret = 0;
23701
23702 /* kprobe_running() needs smp_processor_id() */
23703 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23704 + if (kprobes_built_in() && !user_mode(regs)) {
23705 preempt_disable();
23706 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23707 ret = 1;
23708 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23709 return !instr_lo || (instr_lo>>1) == 1;
23710 case 0x00:
23711 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23712 - if (probe_kernel_address(instr, opcode))
23713 + if (user_mode(regs)) {
23714 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23715 + return 0;
23716 + } else if (probe_kernel_address(instr, opcode))
23717 return 0;
23718
23719 *prefetch = (instr_lo == 0xF) &&
23720 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23721 while (instr < max_instr) {
23722 unsigned char opcode;
23723
23724 - if (probe_kernel_address(instr, opcode))
23725 + if (user_mode(regs)) {
23726 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23727 + break;
23728 + } else if (probe_kernel_address(instr, opcode))
23729 break;
23730
23731 instr++;
23732 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23733 force_sig_info(si_signo, &info, tsk);
23734 }
23735
23736 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23737 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23738 +#endif
23739 +
23740 +#ifdef CONFIG_PAX_EMUTRAMP
23741 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23742 +#endif
23743 +
23744 +#ifdef CONFIG_PAX_PAGEEXEC
23745 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23746 +{
23747 + pgd_t *pgd;
23748 + pud_t *pud;
23749 + pmd_t *pmd;
23750 +
23751 + pgd = pgd_offset(mm, address);
23752 + if (!pgd_present(*pgd))
23753 + return NULL;
23754 + pud = pud_offset(pgd, address);
23755 + if (!pud_present(*pud))
23756 + return NULL;
23757 + pmd = pmd_offset(pud, address);
23758 + if (!pmd_present(*pmd))
23759 + return NULL;
23760 + return pmd;
23761 +}
23762 +#endif
23763 +
23764 DEFINE_SPINLOCK(pgd_lock);
23765 LIST_HEAD(pgd_list);
23766
23767 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23768 for (address = VMALLOC_START & PMD_MASK;
23769 address >= TASK_SIZE && address < FIXADDR_TOP;
23770 address += PMD_SIZE) {
23771 +
23772 +#ifdef CONFIG_PAX_PER_CPU_PGD
23773 + unsigned long cpu;
23774 +#else
23775 struct page *page;
23776 +#endif
23777
23778 spin_lock(&pgd_lock);
23779 +
23780 +#ifdef CONFIG_PAX_PER_CPU_PGD
23781 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23782 + pgd_t *pgd = get_cpu_pgd(cpu);
23783 + pmd_t *ret;
23784 +#else
23785 list_for_each_entry(page, &pgd_list, lru) {
23786 + pgd_t *pgd = page_address(page);
23787 spinlock_t *pgt_lock;
23788 pmd_t *ret;
23789
23790 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23791 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23792
23793 spin_lock(pgt_lock);
23794 - ret = vmalloc_sync_one(page_address(page), address);
23795 +#endif
23796 +
23797 + ret = vmalloc_sync_one(pgd, address);
23798 +
23799 +#ifndef CONFIG_PAX_PER_CPU_PGD
23800 spin_unlock(pgt_lock);
23801 +#endif
23802
23803 if (!ret)
23804 break;
23805 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23806 * an interrupt in the middle of a task switch..
23807 */
23808 pgd_paddr = read_cr3();
23809 +
23810 +#ifdef CONFIG_PAX_PER_CPU_PGD
23811 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23812 +#endif
23813 +
23814 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23815 if (!pmd_k)
23816 return -1;
23817 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23818 * happen within a race in page table update. In the later
23819 * case just flush:
23820 */
23821 +
23822 +#ifdef CONFIG_PAX_PER_CPU_PGD
23823 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23824 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23825 +#else
23826 pgd = pgd_offset(current->active_mm, address);
23827 +#endif
23828 +
23829 pgd_ref = pgd_offset_k(address);
23830 if (pgd_none(*pgd_ref))
23831 return -1;
23832 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23833 static int is_errata100(struct pt_regs *regs, unsigned long address)
23834 {
23835 #ifdef CONFIG_X86_64
23836 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23837 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23838 return 1;
23839 #endif
23840 return 0;
23841 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23842 }
23843
23844 static const char nx_warning[] = KERN_CRIT
23845 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23846 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23847
23848 static void
23849 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23850 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23851 if (!oops_may_print())
23852 return;
23853
23854 - if (error_code & PF_INSTR) {
23855 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23856 unsigned int level;
23857
23858 pte_t *pte = lookup_address(address, &level);
23859
23860 if (pte && pte_present(*pte) && !pte_exec(*pte))
23861 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23862 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23863 }
23864
23865 +#ifdef CONFIG_PAX_KERNEXEC
23866 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23867 + if (current->signal->curr_ip)
23868 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23869 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23870 + else
23871 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23872 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23873 + }
23874 +#endif
23875 +
23876 printk(KERN_ALERT "BUG: unable to handle kernel ");
23877 if (address < PAGE_SIZE)
23878 printk(KERN_CONT "NULL pointer dereference");
23879 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23880 }
23881 #endif
23882
23883 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23884 + if (pax_is_fetch_fault(regs, error_code, address)) {
23885 +
23886 +#ifdef CONFIG_PAX_EMUTRAMP
23887 + switch (pax_handle_fetch_fault(regs)) {
23888 + case 2:
23889 + return;
23890 + }
23891 +#endif
23892 +
23893 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894 + do_group_exit(SIGKILL);
23895 + }
23896 +#endif
23897 +
23898 if (unlikely(show_unhandled_signals))
23899 show_signal_msg(regs, error_code, address, tsk);
23900
23901 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23902 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23903 printk(KERN_ERR
23904 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23905 - tsk->comm, tsk->pid, address);
23906 + tsk->comm, task_pid_nr(tsk), address);
23907 code = BUS_MCEERR_AR;
23908 }
23909 #endif
23910 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23911 return 1;
23912 }
23913
23914 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23915 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23916 +{
23917 + pte_t *pte;
23918 + pmd_t *pmd;
23919 + spinlock_t *ptl;
23920 + unsigned char pte_mask;
23921 +
23922 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23923 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23924 + return 0;
23925 +
23926 + /* PaX: it's our fault, let's handle it if we can */
23927 +
23928 + /* PaX: take a look at read faults before acquiring any locks */
23929 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23930 + /* instruction fetch attempt from a protected page in user mode */
23931 + up_read(&mm->mmap_sem);
23932 +
23933 +#ifdef CONFIG_PAX_EMUTRAMP
23934 + switch (pax_handle_fetch_fault(regs)) {
23935 + case 2:
23936 + return 1;
23937 + }
23938 +#endif
23939 +
23940 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23941 + do_group_exit(SIGKILL);
23942 + }
23943 +
23944 + pmd = pax_get_pmd(mm, address);
23945 + if (unlikely(!pmd))
23946 + return 0;
23947 +
23948 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23949 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23950 + pte_unmap_unlock(pte, ptl);
23951 + return 0;
23952 + }
23953 +
23954 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23955 + /* write attempt to a protected page in user mode */
23956 + pte_unmap_unlock(pte, ptl);
23957 + return 0;
23958 + }
23959 +
23960 +#ifdef CONFIG_SMP
23961 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23962 +#else
23963 + if (likely(address > get_limit(regs->cs)))
23964 +#endif
23965 + {
23966 + set_pte(pte, pte_mkread(*pte));
23967 + __flush_tlb_one(address);
23968 + pte_unmap_unlock(pte, ptl);
23969 + up_read(&mm->mmap_sem);
23970 + return 1;
23971 + }
23972 +
23973 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23974 +
23975 + /*
23976 + * PaX: fill DTLB with user rights and retry
23977 + */
23978 + __asm__ __volatile__ (
23979 + "orb %2,(%1)\n"
23980 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23981 +/*
23982 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23983 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23984 + * page fault when examined during a TLB load attempt. this is true not only
23985 + * for PTEs holding a non-present entry but also present entries that will
23986 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23987 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23988 + * for our target pages since their PTEs are simply not in the TLBs at all.
23989 +
23990 + * the best thing in omitting it is that we gain around 15-20% speed in the
23991 + * fast path of the page fault handler and can get rid of tracing since we
23992 + * can no longer flush unintended entries.
23993 + */
23994 + "invlpg (%0)\n"
23995 +#endif
23996 + __copyuser_seg"testb $0,(%0)\n"
23997 + "xorb %3,(%1)\n"
23998 + :
23999 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24000 + : "memory", "cc");
24001 + pte_unmap_unlock(pte, ptl);
24002 + up_read(&mm->mmap_sem);
24003 + return 1;
24004 +}
24005 +#endif
24006 +
24007 /*
24008 * Handle a spurious fault caused by a stale TLB entry.
24009 *
24010 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24011 static inline int
24012 access_error(unsigned long error_code, struct vm_area_struct *vma)
24013 {
24014 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24015 + return 1;
24016 +
24017 if (error_code & PF_WRITE) {
24018 /* write, present and write, not present: */
24019 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24020 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24021 {
24022 struct vm_area_struct *vma;
24023 struct task_struct *tsk;
24024 - unsigned long address;
24025 struct mm_struct *mm;
24026 int fault;
24027 int write = error_code & PF_WRITE;
24028 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24029 (write ? FAULT_FLAG_WRITE : 0);
24030
24031 - tsk = current;
24032 - mm = tsk->mm;
24033 -
24034 /* Get the faulting address: */
24035 - address = read_cr2();
24036 + unsigned long address = read_cr2();
24037 +
24038 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24039 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24040 + if (!search_exception_tables(regs->ip)) {
24041 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24042 + bad_area_nosemaphore(regs, error_code, address);
24043 + return;
24044 + }
24045 + if (address < PAX_USER_SHADOW_BASE) {
24046 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24047 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24048 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24049 + } else
24050 + address -= PAX_USER_SHADOW_BASE;
24051 + }
24052 +#endif
24053 +
24054 + tsk = current;
24055 + mm = tsk->mm;
24056
24057 /*
24058 * Detect and handle instructions that would cause a page fault for
24059 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24060 * User-mode registers count as a user access even for any
24061 * potential system fault or CPU buglet:
24062 */
24063 - if (user_mode_vm(regs)) {
24064 + if (user_mode(regs)) {
24065 local_irq_enable();
24066 error_code |= PF_USER;
24067 } else {
24068 @@ -1132,6 +1339,11 @@ retry:
24069 might_sleep();
24070 }
24071
24072 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24073 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24074 + return;
24075 +#endif
24076 +
24077 vma = find_vma(mm, address);
24078 if (unlikely(!vma)) {
24079 bad_area(regs, error_code, address);
24080 @@ -1143,18 +1355,24 @@ retry:
24081 bad_area(regs, error_code, address);
24082 return;
24083 }
24084 - if (error_code & PF_USER) {
24085 - /*
24086 - * Accessing the stack below %sp is always a bug.
24087 - * The large cushion allows instructions like enter
24088 - * and pusha to work. ("enter $65535, $31" pushes
24089 - * 32 pointers and then decrements %sp by 65535.)
24090 - */
24091 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24092 - bad_area(regs, error_code, address);
24093 - return;
24094 - }
24095 + /*
24096 + * Accessing the stack below %sp is always a bug.
24097 + * The large cushion allows instructions like enter
24098 + * and pusha to work. ("enter $65535, $31" pushes
24099 + * 32 pointers and then decrements %sp by 65535.)
24100 + */
24101 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24102 + bad_area(regs, error_code, address);
24103 + return;
24104 }
24105 +
24106 +#ifdef CONFIG_PAX_SEGMEXEC
24107 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24108 + bad_area(regs, error_code, address);
24109 + return;
24110 + }
24111 +#endif
24112 +
24113 if (unlikely(expand_stack(vma, address))) {
24114 bad_area(regs, error_code, address);
24115 return;
24116 @@ -1209,3 +1427,292 @@ good_area:
24117
24118 up_read(&mm->mmap_sem);
24119 }
24120 +
24121 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24122 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24123 +{
24124 + struct mm_struct *mm = current->mm;
24125 + unsigned long ip = regs->ip;
24126 +
24127 + if (v8086_mode(regs))
24128 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24129 +
24130 +#ifdef CONFIG_PAX_PAGEEXEC
24131 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24132 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24133 + return true;
24134 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24135 + return true;
24136 + return false;
24137 + }
24138 +#endif
24139 +
24140 +#ifdef CONFIG_PAX_SEGMEXEC
24141 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24142 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24143 + return true;
24144 + return false;
24145 + }
24146 +#endif
24147 +
24148 + return false;
24149 +}
24150 +#endif
24151 +
24152 +#ifdef CONFIG_PAX_EMUTRAMP
24153 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24154 +{
24155 + int err;
24156 +
24157 + do { /* PaX: libffi trampoline emulation */
24158 + unsigned char mov, jmp;
24159 + unsigned int addr1, addr2;
24160 +
24161 +#ifdef CONFIG_X86_64
24162 + if ((regs->ip + 9) >> 32)
24163 + break;
24164 +#endif
24165 +
24166 + err = get_user(mov, (unsigned char __user *)regs->ip);
24167 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24168 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24169 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24170 +
24171 + if (err)
24172 + break;
24173 +
24174 + if (mov == 0xB8 && jmp == 0xE9) {
24175 + regs->ax = addr1;
24176 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24177 + return 2;
24178 + }
24179 + } while (0);
24180 +
24181 + do { /* PaX: gcc trampoline emulation #1 */
24182 + unsigned char mov1, mov2;
24183 + unsigned short jmp;
24184 + unsigned int addr1, addr2;
24185 +
24186 +#ifdef CONFIG_X86_64
24187 + if ((regs->ip + 11) >> 32)
24188 + break;
24189 +#endif
24190 +
24191 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24192 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24193 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24194 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24195 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24196 +
24197 + if (err)
24198 + break;
24199 +
24200 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24201 + regs->cx = addr1;
24202 + regs->ax = addr2;
24203 + regs->ip = addr2;
24204 + return 2;
24205 + }
24206 + } while (0);
24207 +
24208 + do { /* PaX: gcc trampoline emulation #2 */
24209 + unsigned char mov, jmp;
24210 + unsigned int addr1, addr2;
24211 +
24212 +#ifdef CONFIG_X86_64
24213 + if ((regs->ip + 9) >> 32)
24214 + break;
24215 +#endif
24216 +
24217 + err = get_user(mov, (unsigned char __user *)regs->ip);
24218 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24219 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24220 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24221 +
24222 + if (err)
24223 + break;
24224 +
24225 + if (mov == 0xB9 && jmp == 0xE9) {
24226 + regs->cx = addr1;
24227 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24228 + return 2;
24229 + }
24230 + } while (0);
24231 +
24232 + return 1; /* PaX in action */
24233 +}
24234 +
24235 +#ifdef CONFIG_X86_64
24236 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24237 +{
24238 + int err;
24239 +
24240 + do { /* PaX: libffi trampoline emulation */
24241 + unsigned short mov1, mov2, jmp1;
24242 + unsigned char stcclc, jmp2;
24243 + unsigned long addr1, addr2;
24244 +
24245 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24246 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24247 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24248 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24249 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24250 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24251 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24252 +
24253 + if (err)
24254 + break;
24255 +
24256 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24257 + regs->r11 = addr1;
24258 + regs->r10 = addr2;
24259 + if (stcclc == 0xF8)
24260 + regs->flags &= ~X86_EFLAGS_CF;
24261 + else
24262 + regs->flags |= X86_EFLAGS_CF;
24263 + regs->ip = addr1;
24264 + return 2;
24265 + }
24266 + } while (0);
24267 +
24268 + do { /* PaX: gcc trampoline emulation #1 */
24269 + unsigned short mov1, mov2, jmp1;
24270 + unsigned char jmp2;
24271 + unsigned int addr1;
24272 + unsigned long addr2;
24273 +
24274 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24275 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24276 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24277 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24278 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24279 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24280 +
24281 + if (err)
24282 + break;
24283 +
24284 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24285 + regs->r11 = addr1;
24286 + regs->r10 = addr2;
24287 + regs->ip = addr1;
24288 + return 2;
24289 + }
24290 + } while (0);
24291 +
24292 + do { /* PaX: gcc trampoline emulation #2 */
24293 + unsigned short mov1, mov2, jmp1;
24294 + unsigned char jmp2;
24295 + unsigned long addr1, addr2;
24296 +
24297 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24298 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24299 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24300 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24301 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24302 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24303 +
24304 + if (err)
24305 + break;
24306 +
24307 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24308 + regs->r11 = addr1;
24309 + regs->r10 = addr2;
24310 + regs->ip = addr1;
24311 + return 2;
24312 + }
24313 + } while (0);
24314 +
24315 + return 1; /* PaX in action */
24316 +}
24317 +#endif
24318 +
24319 +/*
24320 + * PaX: decide what to do with offenders (regs->ip = fault address)
24321 + *
24322 + * returns 1 when task should be killed
24323 + * 2 when gcc trampoline was detected
24324 + */
24325 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24326 +{
24327 + if (v8086_mode(regs))
24328 + return 1;
24329 +
24330 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24331 + return 1;
24332 +
24333 +#ifdef CONFIG_X86_32
24334 + return pax_handle_fetch_fault_32(regs);
24335 +#else
24336 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24337 + return pax_handle_fetch_fault_32(regs);
24338 + else
24339 + return pax_handle_fetch_fault_64(regs);
24340 +#endif
24341 +}
24342 +#endif
24343 +
24344 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24345 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24346 +{
24347 + long i;
24348 +
24349 + printk(KERN_ERR "PAX: bytes at PC: ");
24350 + for (i = 0; i < 20; i++) {
24351 + unsigned char c;
24352 + if (get_user(c, (unsigned char __force_user *)pc+i))
24353 + printk(KERN_CONT "?? ");
24354 + else
24355 + printk(KERN_CONT "%02x ", c);
24356 + }
24357 + printk("\n");
24358 +
24359 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24360 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24361 + unsigned long c;
24362 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24363 +#ifdef CONFIG_X86_32
24364 + printk(KERN_CONT "???????? ");
24365 +#else
24366 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24367 + printk(KERN_CONT "???????? ???????? ");
24368 + else
24369 + printk(KERN_CONT "???????????????? ");
24370 +#endif
24371 + } else {
24372 +#ifdef CONFIG_X86_64
24373 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24374 + printk(KERN_CONT "%08x ", (unsigned int)c);
24375 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24376 + } else
24377 +#endif
24378 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24379 + }
24380 + }
24381 + printk("\n");
24382 +}
24383 +#endif
24384 +
24385 +/**
24386 + * probe_kernel_write(): safely attempt to write to a location
24387 + * @dst: address to write to
24388 + * @src: pointer to the data that shall be written
24389 + * @size: size of the data chunk
24390 + *
24391 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24392 + * happens, handle that and return -EFAULT.
24393 + */
24394 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24395 +{
24396 + long ret;
24397 + mm_segment_t old_fs = get_fs();
24398 +
24399 + set_fs(KERNEL_DS);
24400 + pagefault_disable();
24401 + pax_open_kernel();
24402 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24403 + pax_close_kernel();
24404 + pagefault_enable();
24405 + set_fs(old_fs);
24406 +
24407 + return ret ? -EFAULT : 0;
24408 +}
24409 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24410 index dd74e46..7d26398 100644
24411 --- a/arch/x86/mm/gup.c
24412 +++ b/arch/x86/mm/gup.c
24413 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24414 addr = start;
24415 len = (unsigned long) nr_pages << PAGE_SHIFT;
24416 end = start + len;
24417 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24418 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24419 (void __user *)start, len)))
24420 return 0;
24421
24422 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24423 index 6f31ee5..8ee4164 100644
24424 --- a/arch/x86/mm/highmem_32.c
24425 +++ b/arch/x86/mm/highmem_32.c
24426 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24427 idx = type + KM_TYPE_NR*smp_processor_id();
24428 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24429 BUG_ON(!pte_none(*(kmap_pte-idx)));
24430 +
24431 + pax_open_kernel();
24432 set_pte(kmap_pte-idx, mk_pte(page, prot));
24433 + pax_close_kernel();
24434 +
24435 arch_flush_lazy_mmu_mode();
24436
24437 return (void *)vaddr;
24438 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24439 index b91e485..d00e7c9 100644
24440 --- a/arch/x86/mm/hugetlbpage.c
24441 +++ b/arch/x86/mm/hugetlbpage.c
24442 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24443 struct hstate *h = hstate_file(file);
24444 struct mm_struct *mm = current->mm;
24445 struct vm_area_struct *vma;
24446 - unsigned long start_addr;
24447 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24448 +
24449 +#ifdef CONFIG_PAX_SEGMEXEC
24450 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24451 + pax_task_size = SEGMEXEC_TASK_SIZE;
24452 +#endif
24453 +
24454 + pax_task_size -= PAGE_SIZE;
24455
24456 if (len > mm->cached_hole_size) {
24457 - start_addr = mm->free_area_cache;
24458 + start_addr = mm->free_area_cache;
24459 } else {
24460 - start_addr = TASK_UNMAPPED_BASE;
24461 - mm->cached_hole_size = 0;
24462 + start_addr = mm->mmap_base;
24463 + mm->cached_hole_size = 0;
24464 }
24465
24466 full_search:
24467 @@ -291,26 +298,27 @@ full_search:
24468
24469 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24470 /* At this point: (!vma || addr < vma->vm_end). */
24471 - if (TASK_SIZE - len < addr) {
24472 + if (pax_task_size - len < addr) {
24473 /*
24474 * Start a new search - just in case we missed
24475 * some holes.
24476 */
24477 - if (start_addr != TASK_UNMAPPED_BASE) {
24478 - start_addr = TASK_UNMAPPED_BASE;
24479 + if (start_addr != mm->mmap_base) {
24480 + start_addr = mm->mmap_base;
24481 mm->cached_hole_size = 0;
24482 goto full_search;
24483 }
24484 return -ENOMEM;
24485 }
24486 - if (!vma || addr + len <= vma->vm_start) {
24487 - mm->free_area_cache = addr + len;
24488 - return addr;
24489 - }
24490 + if (check_heap_stack_gap(vma, addr, len))
24491 + break;
24492 if (addr + mm->cached_hole_size < vma->vm_start)
24493 mm->cached_hole_size = vma->vm_start - addr;
24494 addr = ALIGN(vma->vm_end, huge_page_size(h));
24495 }
24496 +
24497 + mm->free_area_cache = addr + len;
24498 + return addr;
24499 }
24500
24501 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24502 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24503 struct mm_struct *mm = current->mm;
24504 struct vm_area_struct *vma;
24505 unsigned long base = mm->mmap_base;
24506 - unsigned long addr = addr0;
24507 + unsigned long addr;
24508 unsigned long largest_hole = mm->cached_hole_size;
24509 - unsigned long start_addr;
24510
24511 /* don't allow allocations above current base */
24512 if (mm->free_area_cache > base)
24513 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24514 largest_hole = 0;
24515 mm->free_area_cache = base;
24516 }
24517 -try_again:
24518 - start_addr = mm->free_area_cache;
24519
24520 /* make sure it can fit in the remaining address space */
24521 if (mm->free_area_cache < len)
24522 goto fail;
24523
24524 /* either no address requested or can't fit in requested address hole */
24525 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24526 + addr = mm->free_area_cache - len;
24527 do {
24528 + addr &= huge_page_mask(h);
24529 /*
24530 * Lookup failure means no vma is above this address,
24531 * i.e. return with success:
24532 @@ -351,10 +357,10 @@ try_again:
24533 if (!vma)
24534 return addr;
24535
24536 - if (addr + len <= vma->vm_start) {
24537 + if (check_heap_stack_gap(vma, addr, len)) {
24538 /* remember the address as a hint for next time */
24539 - mm->cached_hole_size = largest_hole;
24540 - return (mm->free_area_cache = addr);
24541 + mm->cached_hole_size = largest_hole;
24542 + return (mm->free_area_cache = addr);
24543 } else if (mm->free_area_cache == vma->vm_end) {
24544 /* pull free_area_cache down to the first hole */
24545 mm->free_area_cache = vma->vm_start;
24546 @@ -363,29 +369,34 @@ try_again:
24547
24548 /* remember the largest hole we saw so far */
24549 if (addr + largest_hole < vma->vm_start)
24550 - largest_hole = vma->vm_start - addr;
24551 + largest_hole = vma->vm_start - addr;
24552
24553 /* try just below the current vma->vm_start */
24554 - addr = (vma->vm_start - len) & huge_page_mask(h);
24555 - } while (len <= vma->vm_start);
24556 + addr = skip_heap_stack_gap(vma, len);
24557 + } while (!IS_ERR_VALUE(addr));
24558
24559 fail:
24560 /*
24561 - * if hint left us with no space for the requested
24562 - * mapping then try again:
24563 - */
24564 - if (start_addr != base) {
24565 - mm->free_area_cache = base;
24566 - largest_hole = 0;
24567 - goto try_again;
24568 - }
24569 - /*
24570 * A failed mmap() very likely causes application failure,
24571 * so fall back to the bottom-up function here. This scenario
24572 * can happen with large stack limits and large mmap()
24573 * allocations.
24574 */
24575 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24576 +
24577 +#ifdef CONFIG_PAX_SEGMEXEC
24578 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24579 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24580 + else
24581 +#endif
24582 +
24583 + mm->mmap_base = TASK_UNMAPPED_BASE;
24584 +
24585 +#ifdef CONFIG_PAX_RANDMMAP
24586 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24587 + mm->mmap_base += mm->delta_mmap;
24588 +#endif
24589 +
24590 + mm->free_area_cache = mm->mmap_base;
24591 mm->cached_hole_size = ~0UL;
24592 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24593 len, pgoff, flags);
24594 @@ -393,6 +404,7 @@ fail:
24595 /*
24596 * Restore the topdown base:
24597 */
24598 + mm->mmap_base = base;
24599 mm->free_area_cache = base;
24600 mm->cached_hole_size = ~0UL;
24601
24602 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24603 struct hstate *h = hstate_file(file);
24604 struct mm_struct *mm = current->mm;
24605 struct vm_area_struct *vma;
24606 + unsigned long pax_task_size = TASK_SIZE;
24607
24608 if (len & ~huge_page_mask(h))
24609 return -EINVAL;
24610 - if (len > TASK_SIZE)
24611 +
24612 +#ifdef CONFIG_PAX_SEGMEXEC
24613 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24614 + pax_task_size = SEGMEXEC_TASK_SIZE;
24615 +#endif
24616 +
24617 + pax_task_size -= PAGE_SIZE;
24618 +
24619 + if (len > pax_task_size)
24620 return -ENOMEM;
24621
24622 if (flags & MAP_FIXED) {
24623 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24624 if (addr) {
24625 addr = ALIGN(addr, huge_page_size(h));
24626 vma = find_vma(mm, addr);
24627 - if (TASK_SIZE - len >= addr &&
24628 - (!vma || addr + len <= vma->vm_start))
24629 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24630 return addr;
24631 }
24632 if (mm->get_unmapped_area == arch_get_unmapped_area)
24633 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24634 index d7aea41..0fc945b 100644
24635 --- a/arch/x86/mm/init.c
24636 +++ b/arch/x86/mm/init.c
24637 @@ -4,6 +4,7 @@
24638 #include <linux/swap.h>
24639 #include <linux/memblock.h>
24640 #include <linux/bootmem.h> /* for max_low_pfn */
24641 +#include <linux/tboot.h>
24642
24643 #include <asm/cacheflush.h>
24644 #include <asm/e820.h>
24645 @@ -16,6 +17,8 @@
24646 #include <asm/tlb.h>
24647 #include <asm/proto.h>
24648 #include <asm/dma.h> /* for MAX_DMA_PFN */
24649 +#include <asm/desc.h>
24650 +#include <asm/bios_ebda.h>
24651
24652 unsigned long __initdata pgt_buf_start;
24653 unsigned long __meminitdata pgt_buf_end;
24654 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24655 {
24656 int i;
24657 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24658 - unsigned long start = 0, good_end;
24659 + unsigned long start = 0x100000, good_end;
24660 phys_addr_t base;
24661
24662 for (i = 0; i < nr_range; i++) {
24663 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24664 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24665 * mmio resources as well as potential bios/acpi data regions.
24666 */
24667 +
24668 +#ifdef CONFIG_GRKERNSEC_KMEM
24669 +static unsigned int ebda_start __read_only;
24670 +static unsigned int ebda_end __read_only;
24671 +#endif
24672 +
24673 int devmem_is_allowed(unsigned long pagenr)
24674 {
24675 - if (pagenr < 256)
24676 +#ifdef CONFIG_GRKERNSEC_KMEM
24677 + /* allow BDA */
24678 + if (!pagenr)
24679 return 1;
24680 + /* allow EBDA */
24681 + if (pagenr >= ebda_start && pagenr < ebda_end)
24682 + return 1;
24683 + /* if tboot is in use, allow access to its hardcoded serial log range */
24684 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24685 + return 1;
24686 +#else
24687 + if (!pagenr)
24688 + return 1;
24689 +#ifdef CONFIG_VM86
24690 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24691 + return 1;
24692 +#endif
24693 +#endif
24694 +
24695 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24696 + return 1;
24697 +#ifdef CONFIG_GRKERNSEC_KMEM
24698 + /* throw out everything else below 1MB */
24699 + if (pagenr <= 256)
24700 + return 0;
24701 +#endif
24702 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24703 return 0;
24704 if (!page_is_ram(pagenr))
24705 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24706 #endif
24707 }
24708
24709 +#ifdef CONFIG_GRKERNSEC_KMEM
24710 +static inline void gr_init_ebda(void)
24711 +{
24712 + unsigned int ebda_addr;
24713 + unsigned int ebda_size = 0;
24714 +
24715 + ebda_addr = get_bios_ebda();
24716 + if (ebda_addr) {
24717 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24718 + ebda_size <<= 10;
24719 + }
24720 + if (ebda_addr && ebda_size) {
24721 + ebda_start = ebda_addr >> PAGE_SHIFT;
24722 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24723 + } else {
24724 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24725 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24726 + }
24727 +}
24728 +#else
24729 +static inline void gr_init_ebda(void) { }
24730 +#endif
24731 +
24732 void free_initmem(void)
24733 {
24734 +#ifdef CONFIG_PAX_KERNEXEC
24735 +#ifdef CONFIG_X86_32
24736 + /* PaX: limit KERNEL_CS to actual size */
24737 + unsigned long addr, limit;
24738 + struct desc_struct d;
24739 + int cpu;
24740 +#else
24741 + pgd_t *pgd;
24742 + pud_t *pud;
24743 + pmd_t *pmd;
24744 + unsigned long addr, end;
24745 +#endif
24746 +#endif
24747 +
24748 + gr_init_ebda();
24749 +
24750 +#ifdef CONFIG_PAX_KERNEXEC
24751 +#ifdef CONFIG_X86_32
24752 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24753 + limit = (limit - 1UL) >> PAGE_SHIFT;
24754 +
24755 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24756 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24757 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24758 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24759 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24760 + }
24761 +
24762 + /* PaX: make KERNEL_CS read-only */
24763 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24764 + if (!paravirt_enabled())
24765 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24766 +/*
24767 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24768 + pgd = pgd_offset_k(addr);
24769 + pud = pud_offset(pgd, addr);
24770 + pmd = pmd_offset(pud, addr);
24771 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24772 + }
24773 +*/
24774 +#ifdef CONFIG_X86_PAE
24775 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24776 +/*
24777 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24778 + pgd = pgd_offset_k(addr);
24779 + pud = pud_offset(pgd, addr);
24780 + pmd = pmd_offset(pud, addr);
24781 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24782 + }
24783 +*/
24784 +#endif
24785 +
24786 +#ifdef CONFIG_MODULES
24787 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24788 +#endif
24789 +
24790 +#else
24791 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24792 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24793 + pgd = pgd_offset_k(addr);
24794 + pud = pud_offset(pgd, addr);
24795 + pmd = pmd_offset(pud, addr);
24796 + if (!pmd_present(*pmd))
24797 + continue;
24798 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24799 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24800 + else
24801 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24802 + }
24803 +
24804 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24805 + end = addr + KERNEL_IMAGE_SIZE;
24806 + for (; addr < end; addr += PMD_SIZE) {
24807 + pgd = pgd_offset_k(addr);
24808 + pud = pud_offset(pgd, addr);
24809 + pmd = pmd_offset(pud, addr);
24810 + if (!pmd_present(*pmd))
24811 + continue;
24812 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24813 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24814 + }
24815 +#endif
24816 +
24817 + flush_tlb_all();
24818 +#endif
24819 +
24820 free_init_pages("unused kernel memory",
24821 (unsigned long)(&__init_begin),
24822 (unsigned long)(&__init_end));
24823 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24824 index 575d86f..4987469 100644
24825 --- a/arch/x86/mm/init_32.c
24826 +++ b/arch/x86/mm/init_32.c
24827 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24828 }
24829
24830 /*
24831 - * Creates a middle page table and puts a pointer to it in the
24832 - * given global directory entry. This only returns the gd entry
24833 - * in non-PAE compilation mode, since the middle layer is folded.
24834 - */
24835 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24836 -{
24837 - pud_t *pud;
24838 - pmd_t *pmd_table;
24839 -
24840 -#ifdef CONFIG_X86_PAE
24841 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24842 - if (after_bootmem)
24843 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24844 - else
24845 - pmd_table = (pmd_t *)alloc_low_page();
24846 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24847 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24848 - pud = pud_offset(pgd, 0);
24849 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24850 -
24851 - return pmd_table;
24852 - }
24853 -#endif
24854 - pud = pud_offset(pgd, 0);
24855 - pmd_table = pmd_offset(pud, 0);
24856 -
24857 - return pmd_table;
24858 -}
24859 -
24860 -/*
24861 * Create a page table and place a pointer to it in a middle page
24862 * directory entry:
24863 */
24864 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24865 page_table = (pte_t *)alloc_low_page();
24866
24867 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24868 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24869 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24870 +#else
24871 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24872 +#endif
24873 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24874 }
24875
24876 return pte_offset_kernel(pmd, 0);
24877 }
24878
24879 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24880 +{
24881 + pud_t *pud;
24882 + pmd_t *pmd_table;
24883 +
24884 + pud = pud_offset(pgd, 0);
24885 + pmd_table = pmd_offset(pud, 0);
24886 +
24887 + return pmd_table;
24888 +}
24889 +
24890 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24891 {
24892 int pgd_idx = pgd_index(vaddr);
24893 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24894 int pgd_idx, pmd_idx;
24895 unsigned long vaddr;
24896 pgd_t *pgd;
24897 + pud_t *pud;
24898 pmd_t *pmd;
24899 pte_t *pte = NULL;
24900
24901 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24902 pgd = pgd_base + pgd_idx;
24903
24904 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24905 - pmd = one_md_table_init(pgd);
24906 - pmd = pmd + pmd_index(vaddr);
24907 + pud = pud_offset(pgd, vaddr);
24908 + pmd = pmd_offset(pud, vaddr);
24909 +
24910 +#ifdef CONFIG_X86_PAE
24911 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24912 +#endif
24913 +
24914 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24915 pmd++, pmd_idx++) {
24916 pte = page_table_kmap_check(one_page_table_init(pmd),
24917 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24918 }
24919 }
24920
24921 -static inline int is_kernel_text(unsigned long addr)
24922 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24923 {
24924 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24925 - return 1;
24926 - return 0;
24927 + if ((start > ktla_ktva((unsigned long)_etext) ||
24928 + end <= ktla_ktva((unsigned long)_stext)) &&
24929 + (start > ktla_ktva((unsigned long)_einittext) ||
24930 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24931 +
24932 +#ifdef CONFIG_ACPI_SLEEP
24933 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24934 +#endif
24935 +
24936 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24937 + return 0;
24938 + return 1;
24939 }
24940
24941 /*
24942 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24943 unsigned long last_map_addr = end;
24944 unsigned long start_pfn, end_pfn;
24945 pgd_t *pgd_base = swapper_pg_dir;
24946 - int pgd_idx, pmd_idx, pte_ofs;
24947 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24948 unsigned long pfn;
24949 pgd_t *pgd;
24950 + pud_t *pud;
24951 pmd_t *pmd;
24952 pte_t *pte;
24953 unsigned pages_2m, pages_4k;
24954 @@ -280,8 +281,13 @@ repeat:
24955 pfn = start_pfn;
24956 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24957 pgd = pgd_base + pgd_idx;
24958 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24959 - pmd = one_md_table_init(pgd);
24960 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24961 + pud = pud_offset(pgd, 0);
24962 + pmd = pmd_offset(pud, 0);
24963 +
24964 +#ifdef CONFIG_X86_PAE
24965 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24966 +#endif
24967
24968 if (pfn >= end_pfn)
24969 continue;
24970 @@ -293,14 +299,13 @@ repeat:
24971 #endif
24972 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24973 pmd++, pmd_idx++) {
24974 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24975 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24976
24977 /*
24978 * Map with big pages if possible, otherwise
24979 * create normal page tables:
24980 */
24981 if (use_pse) {
24982 - unsigned int addr2;
24983 pgprot_t prot = PAGE_KERNEL_LARGE;
24984 /*
24985 * first pass will use the same initial
24986 @@ -310,11 +315,7 @@ repeat:
24987 __pgprot(PTE_IDENT_ATTR |
24988 _PAGE_PSE);
24989
24990 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24991 - PAGE_OFFSET + PAGE_SIZE-1;
24992 -
24993 - if (is_kernel_text(addr) ||
24994 - is_kernel_text(addr2))
24995 + if (is_kernel_text(address, address + PMD_SIZE))
24996 prot = PAGE_KERNEL_LARGE_EXEC;
24997
24998 pages_2m++;
24999 @@ -331,7 +332,7 @@ repeat:
25000 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25001 pte += pte_ofs;
25002 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25003 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25004 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25005 pgprot_t prot = PAGE_KERNEL;
25006 /*
25007 * first pass will use the same initial
25008 @@ -339,7 +340,7 @@ repeat:
25009 */
25010 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25011
25012 - if (is_kernel_text(addr))
25013 + if (is_kernel_text(address, address + PAGE_SIZE))
25014 prot = PAGE_KERNEL_EXEC;
25015
25016 pages_4k++;
25017 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25018
25019 pud = pud_offset(pgd, va);
25020 pmd = pmd_offset(pud, va);
25021 - if (!pmd_present(*pmd))
25022 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25023 break;
25024
25025 pte = pte_offset_kernel(pmd, va);
25026 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25027
25028 static void __init pagetable_init(void)
25029 {
25030 - pgd_t *pgd_base = swapper_pg_dir;
25031 -
25032 - permanent_kmaps_init(pgd_base);
25033 + permanent_kmaps_init(swapper_pg_dir);
25034 }
25035
25036 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25037 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25038 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25039
25040 /* user-defined highmem size */
25041 @@ -734,6 +733,12 @@ void __init mem_init(void)
25042
25043 pci_iommu_alloc();
25044
25045 +#ifdef CONFIG_PAX_PER_CPU_PGD
25046 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25047 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25048 + KERNEL_PGD_PTRS);
25049 +#endif
25050 +
25051 #ifdef CONFIG_FLATMEM
25052 BUG_ON(!mem_map);
25053 #endif
25054 @@ -760,7 +765,7 @@ void __init mem_init(void)
25055 reservedpages++;
25056
25057 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25058 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25059 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25060 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25061
25062 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25063 @@ -801,10 +806,10 @@ void __init mem_init(void)
25064 ((unsigned long)&__init_end -
25065 (unsigned long)&__init_begin) >> 10,
25066
25067 - (unsigned long)&_etext, (unsigned long)&_edata,
25068 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25069 + (unsigned long)&_sdata, (unsigned long)&_edata,
25070 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25071
25072 - (unsigned long)&_text, (unsigned long)&_etext,
25073 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25074 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25075
25076 /*
25077 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25078 if (!kernel_set_to_readonly)
25079 return;
25080
25081 + start = ktla_ktva(start);
25082 pr_debug("Set kernel text: %lx - %lx for read write\n",
25083 start, start+size);
25084
25085 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25086 if (!kernel_set_to_readonly)
25087 return;
25088
25089 + start = ktla_ktva(start);
25090 pr_debug("Set kernel text: %lx - %lx for read only\n",
25091 start, start+size);
25092
25093 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25094 unsigned long start = PFN_ALIGN(_text);
25095 unsigned long size = PFN_ALIGN(_etext) - start;
25096
25097 + start = ktla_ktva(start);
25098 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25099 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25100 size >> 10);
25101 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25102 index 3baff25..8b37564 100644
25103 --- a/arch/x86/mm/init_64.c
25104 +++ b/arch/x86/mm/init_64.c
25105 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25106 * around without checking the pgd every time.
25107 */
25108
25109 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25110 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25111 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25112
25113 int force_personality32;
25114 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25115
25116 for (address = start; address <= end; address += PGDIR_SIZE) {
25117 const pgd_t *pgd_ref = pgd_offset_k(address);
25118 +
25119 +#ifdef CONFIG_PAX_PER_CPU_PGD
25120 + unsigned long cpu;
25121 +#else
25122 struct page *page;
25123 +#endif
25124
25125 if (pgd_none(*pgd_ref))
25126 continue;
25127
25128 spin_lock(&pgd_lock);
25129 +
25130 +#ifdef CONFIG_PAX_PER_CPU_PGD
25131 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25132 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25133 +#else
25134 list_for_each_entry(page, &pgd_list, lru) {
25135 pgd_t *pgd;
25136 spinlock_t *pgt_lock;
25137 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25138 /* the pgt_lock only for Xen */
25139 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25140 spin_lock(pgt_lock);
25141 +#endif
25142
25143 if (pgd_none(*pgd))
25144 set_pgd(pgd, *pgd_ref);
25145 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25146 BUG_ON(pgd_page_vaddr(*pgd)
25147 != pgd_page_vaddr(*pgd_ref));
25148
25149 +#ifndef CONFIG_PAX_PER_CPU_PGD
25150 spin_unlock(pgt_lock);
25151 +#endif
25152 +
25153 }
25154 spin_unlock(&pgd_lock);
25155 }
25156 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25157 {
25158 if (pgd_none(*pgd)) {
25159 pud_t *pud = (pud_t *)spp_getpage();
25160 - pgd_populate(&init_mm, pgd, pud);
25161 + pgd_populate_kernel(&init_mm, pgd, pud);
25162 if (pud != pud_offset(pgd, 0))
25163 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25164 pud, pud_offset(pgd, 0));
25165 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25166 {
25167 if (pud_none(*pud)) {
25168 pmd_t *pmd = (pmd_t *) spp_getpage();
25169 - pud_populate(&init_mm, pud, pmd);
25170 + pud_populate_kernel(&init_mm, pud, pmd);
25171 if (pmd != pmd_offset(pud, 0))
25172 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25173 pmd, pmd_offset(pud, 0));
25174 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25175 pmd = fill_pmd(pud, vaddr);
25176 pte = fill_pte(pmd, vaddr);
25177
25178 + pax_open_kernel();
25179 set_pte(pte, new_pte);
25180 + pax_close_kernel();
25181
25182 /*
25183 * It's enough to flush this one mapping.
25184 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25185 pgd = pgd_offset_k((unsigned long)__va(phys));
25186 if (pgd_none(*pgd)) {
25187 pud = (pud_t *) spp_getpage();
25188 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25189 - _PAGE_USER));
25190 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25191 }
25192 pud = pud_offset(pgd, (unsigned long)__va(phys));
25193 if (pud_none(*pud)) {
25194 pmd = (pmd_t *) spp_getpage();
25195 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25196 - _PAGE_USER));
25197 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25198 }
25199 pmd = pmd_offset(pud, phys);
25200 BUG_ON(!pmd_none(*pmd));
25201 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25202 if (pfn >= pgt_buf_top)
25203 panic("alloc_low_page: ran out of memory");
25204
25205 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25206 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25207 clear_page(adr);
25208 *phys = pfn * PAGE_SIZE;
25209 return adr;
25210 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25211
25212 phys = __pa(virt);
25213 left = phys & (PAGE_SIZE - 1);
25214 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25215 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25216 adr = (void *)(((unsigned long)adr) | left);
25217
25218 return adr;
25219 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25220 unmap_low_page(pmd);
25221
25222 spin_lock(&init_mm.page_table_lock);
25223 - pud_populate(&init_mm, pud, __va(pmd_phys));
25224 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25225 spin_unlock(&init_mm.page_table_lock);
25226 }
25227 __flush_tlb_all();
25228 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25229 unmap_low_page(pud);
25230
25231 spin_lock(&init_mm.page_table_lock);
25232 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25233 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25234 spin_unlock(&init_mm.page_table_lock);
25235 pgd_changed = true;
25236 }
25237 @@ -691,6 +705,12 @@ void __init mem_init(void)
25238
25239 pci_iommu_alloc();
25240
25241 +#ifdef CONFIG_PAX_PER_CPU_PGD
25242 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25243 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25244 + KERNEL_PGD_PTRS);
25245 +#endif
25246 +
25247 /* clear_bss() already clear the empty_zero_page */
25248
25249 reservedpages = 0;
25250 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25251 static struct vm_area_struct gate_vma = {
25252 .vm_start = VSYSCALL_START,
25253 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25254 - .vm_page_prot = PAGE_READONLY_EXEC,
25255 - .vm_flags = VM_READ | VM_EXEC
25256 + .vm_page_prot = PAGE_READONLY,
25257 + .vm_flags = VM_READ
25258 };
25259
25260 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25261 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25262
25263 const char *arch_vma_name(struct vm_area_struct *vma)
25264 {
25265 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25266 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25267 return "[vdso]";
25268 if (vma == &gate_vma)
25269 return "[vsyscall]";
25270 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25271 index 7b179b4..6bd1777 100644
25272 --- a/arch/x86/mm/iomap_32.c
25273 +++ b/arch/x86/mm/iomap_32.c
25274 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25275 type = kmap_atomic_idx_push();
25276 idx = type + KM_TYPE_NR * smp_processor_id();
25277 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25278 +
25279 + pax_open_kernel();
25280 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25281 + pax_close_kernel();
25282 +
25283 arch_flush_lazy_mmu_mode();
25284
25285 return (void *)vaddr;
25286 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25287 index 78fe3f1..8293b6f 100644
25288 --- a/arch/x86/mm/ioremap.c
25289 +++ b/arch/x86/mm/ioremap.c
25290 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25291 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25292 int is_ram = page_is_ram(pfn);
25293
25294 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25295 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25296 return NULL;
25297 WARN_ON_ONCE(is_ram);
25298 }
25299 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25300
25301 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25302 if (page_is_ram(start >> PAGE_SHIFT))
25303 +#ifdef CONFIG_HIGHMEM
25304 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25305 +#endif
25306 return __va(phys);
25307
25308 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25309 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25310 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25311
25312 static __initdata int after_paging_init;
25313 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25314 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25315
25316 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25317 {
25318 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25319 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25320
25321 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25322 - memset(bm_pte, 0, sizeof(bm_pte));
25323 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25324 + pmd_populate_user(&init_mm, pmd, bm_pte);
25325
25326 /*
25327 * The boot-ioremap range spans multiple pmds, for which
25328 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25329 index d87dd6d..bf3fa66 100644
25330 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25331 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25332 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25333 * memory (e.g. tracked pages)? For now, we need this to avoid
25334 * invoking kmemcheck for PnP BIOS calls.
25335 */
25336 - if (regs->flags & X86_VM_MASK)
25337 + if (v8086_mode(regs))
25338 return false;
25339 - if (regs->cs != __KERNEL_CS)
25340 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25341 return false;
25342
25343 pte = kmemcheck_pte_lookup(address);
25344 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25345 index 845df68..1d8d29f 100644
25346 --- a/arch/x86/mm/mmap.c
25347 +++ b/arch/x86/mm/mmap.c
25348 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25349 * Leave an at least ~128 MB hole with possible stack randomization.
25350 */
25351 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25352 -#define MAX_GAP (TASK_SIZE/6*5)
25353 +#define MAX_GAP (pax_task_size/6*5)
25354
25355 static int mmap_is_legacy(void)
25356 {
25357 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25358 return rnd << PAGE_SHIFT;
25359 }
25360
25361 -static unsigned long mmap_base(void)
25362 +static unsigned long mmap_base(struct mm_struct *mm)
25363 {
25364 unsigned long gap = rlimit(RLIMIT_STACK);
25365 + unsigned long pax_task_size = TASK_SIZE;
25366 +
25367 +#ifdef CONFIG_PAX_SEGMEXEC
25368 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25369 + pax_task_size = SEGMEXEC_TASK_SIZE;
25370 +#endif
25371
25372 if (gap < MIN_GAP)
25373 gap = MIN_GAP;
25374 else if (gap > MAX_GAP)
25375 gap = MAX_GAP;
25376
25377 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25378 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25379 }
25380
25381 /*
25382 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25383 * does, but not when emulating X86_32
25384 */
25385 -static unsigned long mmap_legacy_base(void)
25386 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25387 {
25388 - if (mmap_is_ia32())
25389 + if (mmap_is_ia32()) {
25390 +
25391 +#ifdef CONFIG_PAX_SEGMEXEC
25392 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25393 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25394 + else
25395 +#endif
25396 +
25397 return TASK_UNMAPPED_BASE;
25398 - else
25399 + } else
25400 return TASK_UNMAPPED_BASE + mmap_rnd();
25401 }
25402
25403 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25404 void arch_pick_mmap_layout(struct mm_struct *mm)
25405 {
25406 if (mmap_is_legacy()) {
25407 - mm->mmap_base = mmap_legacy_base();
25408 + mm->mmap_base = mmap_legacy_base(mm);
25409 +
25410 +#ifdef CONFIG_PAX_RANDMMAP
25411 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25412 + mm->mmap_base += mm->delta_mmap;
25413 +#endif
25414 +
25415 mm->get_unmapped_area = arch_get_unmapped_area;
25416 mm->unmap_area = arch_unmap_area;
25417 } else {
25418 - mm->mmap_base = mmap_base();
25419 + mm->mmap_base = mmap_base(mm);
25420 +
25421 +#ifdef CONFIG_PAX_RANDMMAP
25422 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25423 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25424 +#endif
25425 +
25426 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25427 mm->unmap_area = arch_unmap_area_topdown;
25428 }
25429 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25430 index dc0b727..dc9d71a 100644
25431 --- a/arch/x86/mm/mmio-mod.c
25432 +++ b/arch/x86/mm/mmio-mod.c
25433 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25434 break;
25435 default:
25436 {
25437 - unsigned char *ip = (unsigned char *)instptr;
25438 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25439 my_trace->opcode = MMIO_UNKNOWN_OP;
25440 my_trace->width = 0;
25441 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25442 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25443 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25444 void __iomem *addr)
25445 {
25446 - static atomic_t next_id;
25447 + static atomic_unchecked_t next_id;
25448 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25449 /* These are page-unaligned. */
25450 struct mmiotrace_map map = {
25451 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25452 .private = trace
25453 },
25454 .phys = offset,
25455 - .id = atomic_inc_return(&next_id)
25456 + .id = atomic_inc_return_unchecked(&next_id)
25457 };
25458 map.map_id = trace->id;
25459
25460 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25461 index b008656..773eac2 100644
25462 --- a/arch/x86/mm/pageattr-test.c
25463 +++ b/arch/x86/mm/pageattr-test.c
25464 @@ -36,7 +36,7 @@ enum {
25465
25466 static int pte_testbit(pte_t pte)
25467 {
25468 - return pte_flags(pte) & _PAGE_UNUSED1;
25469 + return pte_flags(pte) & _PAGE_CPA_TEST;
25470 }
25471
25472 struct split_state {
25473 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25474 index a718e0d..45efc32 100644
25475 --- a/arch/x86/mm/pageattr.c
25476 +++ b/arch/x86/mm/pageattr.c
25477 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25478 */
25479 #ifdef CONFIG_PCI_BIOS
25480 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25481 - pgprot_val(forbidden) |= _PAGE_NX;
25482 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25483 #endif
25484
25485 /*
25486 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25487 * Does not cover __inittext since that is gone later on. On
25488 * 64bit we do not enforce !NX on the low mapping
25489 */
25490 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25491 - pgprot_val(forbidden) |= _PAGE_NX;
25492 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25493 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25494
25495 +#ifdef CONFIG_DEBUG_RODATA
25496 /*
25497 * The .rodata section needs to be read-only. Using the pfn
25498 * catches all aliases.
25499 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25500 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25501 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25502 pgprot_val(forbidden) |= _PAGE_RW;
25503 +#endif
25504
25505 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25506 /*
25507 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25508 }
25509 #endif
25510
25511 +#ifdef CONFIG_PAX_KERNEXEC
25512 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25513 + pgprot_val(forbidden) |= _PAGE_RW;
25514 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25515 + }
25516 +#endif
25517 +
25518 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25519
25520 return prot;
25521 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25522 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25523 {
25524 /* change init_mm */
25525 + pax_open_kernel();
25526 set_pte_atomic(kpte, pte);
25527 +
25528 #ifdef CONFIG_X86_32
25529 if (!SHARED_KERNEL_PMD) {
25530 +
25531 +#ifdef CONFIG_PAX_PER_CPU_PGD
25532 + unsigned long cpu;
25533 +#else
25534 struct page *page;
25535 +#endif
25536
25537 +#ifdef CONFIG_PAX_PER_CPU_PGD
25538 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25539 + pgd_t *pgd = get_cpu_pgd(cpu);
25540 +#else
25541 list_for_each_entry(page, &pgd_list, lru) {
25542 - pgd_t *pgd;
25543 + pgd_t *pgd = (pgd_t *)page_address(page);
25544 +#endif
25545 +
25546 pud_t *pud;
25547 pmd_t *pmd;
25548
25549 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25550 + pgd += pgd_index(address);
25551 pud = pud_offset(pgd, address);
25552 pmd = pmd_offset(pud, address);
25553 set_pte_atomic((pte_t *)pmd, pte);
25554 }
25555 }
25556 #endif
25557 + pax_close_kernel();
25558 }
25559
25560 static int
25561 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25562 index 3d68ef6..7f69136 100644
25563 --- a/arch/x86/mm/pat.c
25564 +++ b/arch/x86/mm/pat.c
25565 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25566
25567 if (!entry) {
25568 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25569 - current->comm, current->pid, start, end - 1);
25570 + current->comm, task_pid_nr(current), start, end - 1);
25571 return -EINVAL;
25572 }
25573
25574 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25575
25576 while (cursor < to) {
25577 if (!devmem_is_allowed(pfn)) {
25578 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25579 - current->comm, from, to - 1);
25580 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25581 + current->comm, from, to - 1, cursor);
25582 return 0;
25583 }
25584 cursor += PAGE_SIZE;
25585 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25586 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25587 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25588 "for [mem %#010Lx-%#010Lx]\n",
25589 - current->comm, current->pid,
25590 + current->comm, task_pid_nr(current),
25591 cattr_name(flags),
25592 base, (unsigned long long)(base + size-1));
25593 return -EINVAL;
25594 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25595 flags = lookup_memtype(paddr);
25596 if (want_flags != flags) {
25597 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25598 - current->comm, current->pid,
25599 + current->comm, task_pid_nr(current),
25600 cattr_name(want_flags),
25601 (unsigned long long)paddr,
25602 (unsigned long long)(paddr + size - 1),
25603 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25604 free_memtype(paddr, paddr + size);
25605 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25606 " for [mem %#010Lx-%#010Lx], got %s\n",
25607 - current->comm, current->pid,
25608 + current->comm, task_pid_nr(current),
25609 cattr_name(want_flags),
25610 (unsigned long long)paddr,
25611 (unsigned long long)(paddr + size - 1),
25612 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25613 index 9f0614d..92ae64a 100644
25614 --- a/arch/x86/mm/pf_in.c
25615 +++ b/arch/x86/mm/pf_in.c
25616 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25617 int i;
25618 enum reason_type rv = OTHERS;
25619
25620 - p = (unsigned char *)ins_addr;
25621 + p = (unsigned char *)ktla_ktva(ins_addr);
25622 p += skip_prefix(p, &prf);
25623 p += get_opcode(p, &opcode);
25624
25625 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25626 struct prefix_bits prf;
25627 int i;
25628
25629 - p = (unsigned char *)ins_addr;
25630 + p = (unsigned char *)ktla_ktva(ins_addr);
25631 p += skip_prefix(p, &prf);
25632 p += get_opcode(p, &opcode);
25633
25634 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25635 struct prefix_bits prf;
25636 int i;
25637
25638 - p = (unsigned char *)ins_addr;
25639 + p = (unsigned char *)ktla_ktva(ins_addr);
25640 p += skip_prefix(p, &prf);
25641 p += get_opcode(p, &opcode);
25642
25643 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25644 struct prefix_bits prf;
25645 int i;
25646
25647 - p = (unsigned char *)ins_addr;
25648 + p = (unsigned char *)ktla_ktva(ins_addr);
25649 p += skip_prefix(p, &prf);
25650 p += get_opcode(p, &opcode);
25651 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25652 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25653 struct prefix_bits prf;
25654 int i;
25655
25656 - p = (unsigned char *)ins_addr;
25657 + p = (unsigned char *)ktla_ktva(ins_addr);
25658 p += skip_prefix(p, &prf);
25659 p += get_opcode(p, &opcode);
25660 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25661 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25662 index 8573b83..4f3ed7e 100644
25663 --- a/arch/x86/mm/pgtable.c
25664 +++ b/arch/x86/mm/pgtable.c
25665 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25666 list_del(&page->lru);
25667 }
25668
25669 -#define UNSHARED_PTRS_PER_PGD \
25670 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25672 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25673
25674 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25675 +{
25676 + unsigned int count = USER_PGD_PTRS;
25677
25678 + while (count--)
25679 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25680 +}
25681 +#endif
25682 +
25683 +#ifdef CONFIG_PAX_PER_CPU_PGD
25684 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25685 +{
25686 + unsigned int count = USER_PGD_PTRS;
25687 +
25688 + while (count--) {
25689 + pgd_t pgd;
25690 +
25691 +#ifdef CONFIG_X86_64
25692 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25693 +#else
25694 + pgd = *src++;
25695 +#endif
25696 +
25697 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25698 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25699 +#endif
25700 +
25701 + *dst++ = pgd;
25702 + }
25703 +
25704 +}
25705 +#endif
25706 +
25707 +#ifdef CONFIG_X86_64
25708 +#define pxd_t pud_t
25709 +#define pyd_t pgd_t
25710 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25711 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25712 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25713 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25714 +#define PYD_SIZE PGDIR_SIZE
25715 +#else
25716 +#define pxd_t pmd_t
25717 +#define pyd_t pud_t
25718 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25719 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25720 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25721 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25722 +#define PYD_SIZE PUD_SIZE
25723 +#endif
25724 +
25725 +#ifdef CONFIG_PAX_PER_CPU_PGD
25726 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25727 +static inline void pgd_dtor(pgd_t *pgd) {}
25728 +#else
25729 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25730 {
25731 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25732 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25733 pgd_list_del(pgd);
25734 spin_unlock(&pgd_lock);
25735 }
25736 +#endif
25737
25738 /*
25739 * List of all pgd's needed for non-PAE so it can invalidate entries
25740 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25741 * -- wli
25742 */
25743
25744 -#ifdef CONFIG_X86_PAE
25745 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25746 /*
25747 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25748 * updating the top-level pagetable entries to guarantee the
25749 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25750 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25751 * and initialize the kernel pmds here.
25752 */
25753 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25754 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25755
25756 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25757 {
25758 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25759 */
25760 flush_tlb_mm(mm);
25761 }
25762 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25763 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25764 #else /* !CONFIG_X86_PAE */
25765
25766 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25767 -#define PREALLOCATED_PMDS 0
25768 +#define PREALLOCATED_PXDS 0
25769
25770 #endif /* CONFIG_X86_PAE */
25771
25772 -static void free_pmds(pmd_t *pmds[])
25773 +static void free_pxds(pxd_t *pxds[])
25774 {
25775 int i;
25776
25777 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25778 - if (pmds[i])
25779 - free_page((unsigned long)pmds[i]);
25780 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25781 + if (pxds[i])
25782 + free_page((unsigned long)pxds[i]);
25783 }
25784
25785 -static int preallocate_pmds(pmd_t *pmds[])
25786 +static int preallocate_pxds(pxd_t *pxds[])
25787 {
25788 int i;
25789 bool failed = false;
25790
25791 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25792 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25793 - if (pmd == NULL)
25794 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25795 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25796 + if (pxd == NULL)
25797 failed = true;
25798 - pmds[i] = pmd;
25799 + pxds[i] = pxd;
25800 }
25801
25802 if (failed) {
25803 - free_pmds(pmds);
25804 + free_pxds(pxds);
25805 return -ENOMEM;
25806 }
25807
25808 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25809 * preallocate which never got a corresponding vma will need to be
25810 * freed manually.
25811 */
25812 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25813 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25814 {
25815 int i;
25816
25817 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25818 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25819 pgd_t pgd = pgdp[i];
25820
25821 if (pgd_val(pgd) != 0) {
25822 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25823 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25824
25825 - pgdp[i] = native_make_pgd(0);
25826 + set_pgd(pgdp + i, native_make_pgd(0));
25827
25828 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25829 - pmd_free(mm, pmd);
25830 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25831 + pxd_free(mm, pxd);
25832 }
25833 }
25834 }
25835
25836 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25837 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25838 {
25839 - pud_t *pud;
25840 + pyd_t *pyd;
25841 unsigned long addr;
25842 int i;
25843
25844 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25845 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25846 return;
25847
25848 - pud = pud_offset(pgd, 0);
25849 +#ifdef CONFIG_X86_64
25850 + pyd = pyd_offset(mm, 0L);
25851 +#else
25852 + pyd = pyd_offset(pgd, 0L);
25853 +#endif
25854
25855 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25856 - i++, pud++, addr += PUD_SIZE) {
25857 - pmd_t *pmd = pmds[i];
25858 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25859 + i++, pyd++, addr += PYD_SIZE) {
25860 + pxd_t *pxd = pxds[i];
25861
25862 if (i >= KERNEL_PGD_BOUNDARY)
25863 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25864 - sizeof(pmd_t) * PTRS_PER_PMD);
25865 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25866 + sizeof(pxd_t) * PTRS_PER_PMD);
25867
25868 - pud_populate(mm, pud, pmd);
25869 + pyd_populate(mm, pyd, pxd);
25870 }
25871 }
25872
25873 pgd_t *pgd_alloc(struct mm_struct *mm)
25874 {
25875 pgd_t *pgd;
25876 - pmd_t *pmds[PREALLOCATED_PMDS];
25877 + pxd_t *pxds[PREALLOCATED_PXDS];
25878
25879 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25880
25881 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25882
25883 mm->pgd = pgd;
25884
25885 - if (preallocate_pmds(pmds) != 0)
25886 + if (preallocate_pxds(pxds) != 0)
25887 goto out_free_pgd;
25888
25889 if (paravirt_pgd_alloc(mm) != 0)
25890 - goto out_free_pmds;
25891 + goto out_free_pxds;
25892
25893 /*
25894 * Make sure that pre-populating the pmds is atomic with
25895 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25896 spin_lock(&pgd_lock);
25897
25898 pgd_ctor(mm, pgd);
25899 - pgd_prepopulate_pmd(mm, pgd, pmds);
25900 + pgd_prepopulate_pxd(mm, pgd, pxds);
25901
25902 spin_unlock(&pgd_lock);
25903
25904 return pgd;
25905
25906 -out_free_pmds:
25907 - free_pmds(pmds);
25908 +out_free_pxds:
25909 + free_pxds(pxds);
25910 out_free_pgd:
25911 free_page((unsigned long)pgd);
25912 out:
25913 @@ -295,7 +356,7 @@ out:
25914
25915 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25916 {
25917 - pgd_mop_up_pmds(mm, pgd);
25918 + pgd_mop_up_pxds(mm, pgd);
25919 pgd_dtor(pgd);
25920 paravirt_pgd_free(mm, pgd);
25921 free_page((unsigned long)pgd);
25922 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25923 index a69bcb8..19068ab 100644
25924 --- a/arch/x86/mm/pgtable_32.c
25925 +++ b/arch/x86/mm/pgtable_32.c
25926 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25927 return;
25928 }
25929 pte = pte_offset_kernel(pmd, vaddr);
25930 +
25931 + pax_open_kernel();
25932 if (pte_val(pteval))
25933 set_pte_at(&init_mm, vaddr, pte, pteval);
25934 else
25935 pte_clear(&init_mm, vaddr, pte);
25936 + pax_close_kernel();
25937
25938 /*
25939 * It's enough to flush this one mapping.
25940 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25941 index 410531d..0f16030 100644
25942 --- a/arch/x86/mm/setup_nx.c
25943 +++ b/arch/x86/mm/setup_nx.c
25944 @@ -5,8 +5,10 @@
25945 #include <asm/pgtable.h>
25946 #include <asm/proto.h>
25947
25948 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25949 static int disable_nx __cpuinitdata;
25950
25951 +#ifndef CONFIG_PAX_PAGEEXEC
25952 /*
25953 * noexec = on|off
25954 *
25955 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25956 return 0;
25957 }
25958 early_param("noexec", noexec_setup);
25959 +#endif
25960 +
25961 +#endif
25962
25963 void __cpuinit x86_configure_nx(void)
25964 {
25965 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25966 if (cpu_has_nx && !disable_nx)
25967 __supported_pte_mask |= _PAGE_NX;
25968 else
25969 +#endif
25970 __supported_pte_mask &= ~_PAGE_NX;
25971 }
25972
25973 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25974 index 613cd83..3a21f1c 100644
25975 --- a/arch/x86/mm/tlb.c
25976 +++ b/arch/x86/mm/tlb.c
25977 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25978 BUG();
25979 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25980 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25981 +
25982 +#ifndef CONFIG_PAX_PER_CPU_PGD
25983 load_cr3(swapper_pg_dir);
25984 +#endif
25985 +
25986 }
25987 }
25988 EXPORT_SYMBOL_GPL(leave_mm);
25989 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25990 index 877b9a1..a8ecf42 100644
25991 --- a/arch/x86/net/bpf_jit.S
25992 +++ b/arch/x86/net/bpf_jit.S
25993 @@ -9,6 +9,7 @@
25994 */
25995 #include <linux/linkage.h>
25996 #include <asm/dwarf2.h>
25997 +#include <asm/alternative-asm.h>
25998
25999 /*
26000 * Calling convention :
26001 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26002 jle bpf_slow_path_word
26003 mov (SKBDATA,%rsi),%eax
26004 bswap %eax /* ntohl() */
26005 + pax_force_retaddr
26006 ret
26007
26008 sk_load_half:
26009 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26010 jle bpf_slow_path_half
26011 movzwl (SKBDATA,%rsi),%eax
26012 rol $8,%ax # ntohs()
26013 + pax_force_retaddr
26014 ret
26015
26016 sk_load_byte:
26017 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26018 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26019 jle bpf_slow_path_byte
26020 movzbl (SKBDATA,%rsi),%eax
26021 + pax_force_retaddr
26022 ret
26023
26024 /**
26025 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26026 movzbl (SKBDATA,%rsi),%ebx
26027 and $15,%bl
26028 shl $2,%bl
26029 + pax_force_retaddr
26030 ret
26031
26032 /* rsi contains offset and can be scratched */
26033 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26034 js bpf_error
26035 mov -12(%rbp),%eax
26036 bswap %eax
26037 + pax_force_retaddr
26038 ret
26039
26040 bpf_slow_path_half:
26041 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26042 mov -12(%rbp),%ax
26043 rol $8,%ax
26044 movzwl %ax,%eax
26045 + pax_force_retaddr
26046 ret
26047
26048 bpf_slow_path_byte:
26049 bpf_slow_path_common(1)
26050 js bpf_error
26051 movzbl -12(%rbp),%eax
26052 + pax_force_retaddr
26053 ret
26054
26055 bpf_slow_path_byte_msh:
26056 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26057 and $15,%al
26058 shl $2,%al
26059 xchg %eax,%ebx
26060 + pax_force_retaddr
26061 ret
26062
26063 #define sk_negative_common(SIZE) \
26064 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26065 sk_negative_common(4)
26066 mov (%rax), %eax
26067 bswap %eax
26068 + pax_force_retaddr
26069 ret
26070
26071 bpf_slow_path_half_neg:
26072 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26073 mov (%rax),%ax
26074 rol $8,%ax
26075 movzwl %ax,%eax
26076 + pax_force_retaddr
26077 ret
26078
26079 bpf_slow_path_byte_neg:
26080 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26081 .globl sk_load_byte_negative_offset
26082 sk_negative_common(1)
26083 movzbl (%rax), %eax
26084 + pax_force_retaddr
26085 ret
26086
26087 bpf_slow_path_byte_msh_neg:
26088 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26089 and $15,%al
26090 shl $2,%al
26091 xchg %eax,%ebx
26092 + pax_force_retaddr
26093 ret
26094
26095 bpf_error:
26096 @@ -197,4 +210,5 @@ bpf_error:
26097 xor %eax,%eax
26098 mov -8(%rbp),%rbx
26099 leaveq
26100 + pax_force_retaddr
26101 ret
26102 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26103 index 33643a8..8e44870 100644
26104 --- a/arch/x86/net/bpf_jit_comp.c
26105 +++ b/arch/x86/net/bpf_jit_comp.c
26106 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26107 set_fs(old_fs);
26108 }
26109
26110 +struct bpf_jit_work {
26111 + struct work_struct work;
26112 + void *image;
26113 +};
26114 +
26115 #define CHOOSE_LOAD_FUNC(K, func) \
26116 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26117
26118 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26119 if (addrs == NULL)
26120 return;
26121
26122 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26123 + if (!fp->work)
26124 + goto out;
26125 +
26126 /* Before first pass, make a rough estimation of addrs[]
26127 * each bpf instruction is translated to less than 64 bytes
26128 */
26129 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26130 break;
26131 default:
26132 /* hmm, too complex filter, give up with jit compiler */
26133 - goto out;
26134 + goto error;
26135 }
26136 ilen = prog - temp;
26137 if (image) {
26138 if (unlikely(proglen + ilen > oldproglen)) {
26139 pr_err("bpb_jit_compile fatal error\n");
26140 - kfree(addrs);
26141 - module_free(NULL, image);
26142 - return;
26143 + module_free_exec(NULL, image);
26144 + goto error;
26145 }
26146 + pax_open_kernel();
26147 memcpy(image + proglen, temp, ilen);
26148 + pax_close_kernel();
26149 }
26150 proglen += ilen;
26151 addrs[i] = proglen;
26152 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26153 break;
26154 }
26155 if (proglen == oldproglen) {
26156 - image = module_alloc(max_t(unsigned int,
26157 - proglen,
26158 - sizeof(struct work_struct)));
26159 + image = module_alloc_exec(proglen);
26160 if (!image)
26161 - goto out;
26162 + goto error;
26163 }
26164 oldproglen = proglen;
26165 }
26166 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26167 bpf_flush_icache(image, image + proglen);
26168
26169 fp->bpf_func = (void *)image;
26170 - }
26171 + } else
26172 +error:
26173 + kfree(fp->work);
26174 +
26175 out:
26176 kfree(addrs);
26177 return;
26178 @@ -652,18 +663,20 @@ out:
26179
26180 static void jit_free_defer(struct work_struct *arg)
26181 {
26182 - module_free(NULL, arg);
26183 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26184 + kfree(arg);
26185 }
26186
26187 /* run from softirq, we must use a work_struct to call
26188 - * module_free() from process context
26189 + * module_free_exec() from process context
26190 */
26191 void bpf_jit_free(struct sk_filter *fp)
26192 {
26193 if (fp->bpf_func != sk_run_filter) {
26194 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26195 + struct work_struct *work = &fp->work->work;
26196
26197 INIT_WORK(work, jit_free_defer);
26198 + fp->work->image = fp->bpf_func;
26199 schedule_work(work);
26200 }
26201 }
26202 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26203 index d6aa6e8..266395a 100644
26204 --- a/arch/x86/oprofile/backtrace.c
26205 +++ b/arch/x86/oprofile/backtrace.c
26206 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26207 struct stack_frame_ia32 *fp;
26208 unsigned long bytes;
26209
26210 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26211 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26212 if (bytes != sizeof(bufhead))
26213 return NULL;
26214
26215 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26216 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26217
26218 oprofile_add_trace(bufhead[0].return_address);
26219
26220 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26221 struct stack_frame bufhead[2];
26222 unsigned long bytes;
26223
26224 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26225 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26226 if (bytes != sizeof(bufhead))
26227 return NULL;
26228
26229 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26230 {
26231 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26232
26233 - if (!user_mode_vm(regs)) {
26234 + if (!user_mode(regs)) {
26235 unsigned long stack = kernel_stack_pointer(regs);
26236 if (depth)
26237 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26238 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26239 index e14a2ff..3fd6b58 100644
26240 --- a/arch/x86/pci/mrst.c
26241 +++ b/arch/x86/pci/mrst.c
26242 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26243 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26244 pci_mmcfg_late_init();
26245 pcibios_enable_irq = mrst_pci_irq_enable;
26246 - pci_root_ops = pci_mrst_ops;
26247 + pax_open_kernel();
26248 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26249 + pax_close_kernel();
26250 pci_soc_mode = 1;
26251 /* Continue with standard init */
26252 return 1;
26253 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26254 index da8fe05..7ee6704 100644
26255 --- a/arch/x86/pci/pcbios.c
26256 +++ b/arch/x86/pci/pcbios.c
26257 @@ -79,50 +79,93 @@ union bios32 {
26258 static struct {
26259 unsigned long address;
26260 unsigned short segment;
26261 -} bios32_indirect = { 0, __KERNEL_CS };
26262 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26263
26264 /*
26265 * Returns the entry point for the given service, NULL on error
26266 */
26267
26268 -static unsigned long bios32_service(unsigned long service)
26269 +static unsigned long __devinit bios32_service(unsigned long service)
26270 {
26271 unsigned char return_code; /* %al */
26272 unsigned long address; /* %ebx */
26273 unsigned long length; /* %ecx */
26274 unsigned long entry; /* %edx */
26275 unsigned long flags;
26276 + struct desc_struct d, *gdt;
26277
26278 local_irq_save(flags);
26279 - __asm__("lcall *(%%edi); cld"
26280 +
26281 + gdt = get_cpu_gdt_table(smp_processor_id());
26282 +
26283 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26284 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26285 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26286 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26287 +
26288 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26289 : "=a" (return_code),
26290 "=b" (address),
26291 "=c" (length),
26292 "=d" (entry)
26293 : "0" (service),
26294 "1" (0),
26295 - "D" (&bios32_indirect));
26296 + "D" (&bios32_indirect),
26297 + "r"(__PCIBIOS_DS)
26298 + : "memory");
26299 +
26300 + pax_open_kernel();
26301 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26302 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26303 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26304 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26305 + pax_close_kernel();
26306 +
26307 local_irq_restore(flags);
26308
26309 switch (return_code) {
26310 - case 0:
26311 - return address + entry;
26312 - case 0x80: /* Not present */
26313 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26314 - return 0;
26315 - default: /* Shouldn't happen */
26316 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26317 - service, return_code);
26318 + case 0: {
26319 + int cpu;
26320 + unsigned char flags;
26321 +
26322 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26323 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26324 + printk(KERN_WARNING "bios32_service: not valid\n");
26325 return 0;
26326 + }
26327 + address = address + PAGE_OFFSET;
26328 + length += 16UL; /* some BIOSs underreport this... */
26329 + flags = 4;
26330 + if (length >= 64*1024*1024) {
26331 + length >>= PAGE_SHIFT;
26332 + flags |= 8;
26333 + }
26334 +
26335 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26336 + gdt = get_cpu_gdt_table(cpu);
26337 + pack_descriptor(&d, address, length, 0x9b, flags);
26338 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26339 + pack_descriptor(&d, address, length, 0x93, flags);
26340 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26341 + }
26342 + return entry;
26343 + }
26344 + case 0x80: /* Not present */
26345 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26346 + return 0;
26347 + default: /* Shouldn't happen */
26348 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26349 + service, return_code);
26350 + return 0;
26351 }
26352 }
26353
26354 static struct {
26355 unsigned long address;
26356 unsigned short segment;
26357 -} pci_indirect = { 0, __KERNEL_CS };
26358 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26359
26360 -static int pci_bios_present;
26361 +static int pci_bios_present __read_only;
26362
26363 static int __devinit check_pcibios(void)
26364 {
26365 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26366 unsigned long flags, pcibios_entry;
26367
26368 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26369 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26370 + pci_indirect.address = pcibios_entry;
26371
26372 local_irq_save(flags);
26373 - __asm__(
26374 - "lcall *(%%edi); cld\n\t"
26375 + __asm__("movw %w6, %%ds\n\t"
26376 + "lcall *%%ss:(%%edi); cld\n\t"
26377 + "push %%ss\n\t"
26378 + "pop %%ds\n\t"
26379 "jc 1f\n\t"
26380 "xor %%ah, %%ah\n"
26381 "1:"
26382 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26383 "=b" (ebx),
26384 "=c" (ecx)
26385 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26386 - "D" (&pci_indirect)
26387 + "D" (&pci_indirect),
26388 + "r" (__PCIBIOS_DS)
26389 : "memory");
26390 local_irq_restore(flags);
26391
26392 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26393
26394 switch (len) {
26395 case 1:
26396 - __asm__("lcall *(%%esi); cld\n\t"
26397 + __asm__("movw %w6, %%ds\n\t"
26398 + "lcall *%%ss:(%%esi); cld\n\t"
26399 + "push %%ss\n\t"
26400 + "pop %%ds\n\t"
26401 "jc 1f\n\t"
26402 "xor %%ah, %%ah\n"
26403 "1:"
26404 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26405 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26406 "b" (bx),
26407 "D" ((long)reg),
26408 - "S" (&pci_indirect));
26409 + "S" (&pci_indirect),
26410 + "r" (__PCIBIOS_DS));
26411 /*
26412 * Zero-extend the result beyond 8 bits, do not trust the
26413 * BIOS having done it:
26414 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26415 *value &= 0xff;
26416 break;
26417 case 2:
26418 - __asm__("lcall *(%%esi); cld\n\t"
26419 + __asm__("movw %w6, %%ds\n\t"
26420 + "lcall *%%ss:(%%esi); cld\n\t"
26421 + "push %%ss\n\t"
26422 + "pop %%ds\n\t"
26423 "jc 1f\n\t"
26424 "xor %%ah, %%ah\n"
26425 "1:"
26426 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26427 : "1" (PCIBIOS_READ_CONFIG_WORD),
26428 "b" (bx),
26429 "D" ((long)reg),
26430 - "S" (&pci_indirect));
26431 + "S" (&pci_indirect),
26432 + "r" (__PCIBIOS_DS));
26433 /*
26434 * Zero-extend the result beyond 16 bits, do not trust the
26435 * BIOS having done it:
26436 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26437 *value &= 0xffff;
26438 break;
26439 case 4:
26440 - __asm__("lcall *(%%esi); cld\n\t"
26441 + __asm__("movw %w6, %%ds\n\t"
26442 + "lcall *%%ss:(%%esi); cld\n\t"
26443 + "push %%ss\n\t"
26444 + "pop %%ds\n\t"
26445 "jc 1f\n\t"
26446 "xor %%ah, %%ah\n"
26447 "1:"
26448 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26449 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26450 "b" (bx),
26451 "D" ((long)reg),
26452 - "S" (&pci_indirect));
26453 + "S" (&pci_indirect),
26454 + "r" (__PCIBIOS_DS));
26455 break;
26456 }
26457
26458 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26459
26460 switch (len) {
26461 case 1:
26462 - __asm__("lcall *(%%esi); cld\n\t"
26463 + __asm__("movw %w6, %%ds\n\t"
26464 + "lcall *%%ss:(%%esi); cld\n\t"
26465 + "push %%ss\n\t"
26466 + "pop %%ds\n\t"
26467 "jc 1f\n\t"
26468 "xor %%ah, %%ah\n"
26469 "1:"
26470 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26471 "c" (value),
26472 "b" (bx),
26473 "D" ((long)reg),
26474 - "S" (&pci_indirect));
26475 + "S" (&pci_indirect),
26476 + "r" (__PCIBIOS_DS));
26477 break;
26478 case 2:
26479 - __asm__("lcall *(%%esi); cld\n\t"
26480 + __asm__("movw %w6, %%ds\n\t"
26481 + "lcall *%%ss:(%%esi); cld\n\t"
26482 + "push %%ss\n\t"
26483 + "pop %%ds\n\t"
26484 "jc 1f\n\t"
26485 "xor %%ah, %%ah\n"
26486 "1:"
26487 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26488 "c" (value),
26489 "b" (bx),
26490 "D" ((long)reg),
26491 - "S" (&pci_indirect));
26492 + "S" (&pci_indirect),
26493 + "r" (__PCIBIOS_DS));
26494 break;
26495 case 4:
26496 - __asm__("lcall *(%%esi); cld\n\t"
26497 + __asm__("movw %w6, %%ds\n\t"
26498 + "lcall *%%ss:(%%esi); cld\n\t"
26499 + "push %%ss\n\t"
26500 + "pop %%ds\n\t"
26501 "jc 1f\n\t"
26502 "xor %%ah, %%ah\n"
26503 "1:"
26504 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26505 "c" (value),
26506 "b" (bx),
26507 "D" ((long)reg),
26508 - "S" (&pci_indirect));
26509 + "S" (&pci_indirect),
26510 + "r" (__PCIBIOS_DS));
26511 break;
26512 }
26513
26514 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26515
26516 DBG("PCI: Fetching IRQ routing table... ");
26517 __asm__("push %%es\n\t"
26518 + "movw %w8, %%ds\n\t"
26519 "push %%ds\n\t"
26520 "pop %%es\n\t"
26521 - "lcall *(%%esi); cld\n\t"
26522 + "lcall *%%ss:(%%esi); cld\n\t"
26523 "pop %%es\n\t"
26524 + "push %%ss\n\t"
26525 + "pop %%ds\n"
26526 "jc 1f\n\t"
26527 "xor %%ah, %%ah\n"
26528 "1:"
26529 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26530 "1" (0),
26531 "D" ((long) &opt),
26532 "S" (&pci_indirect),
26533 - "m" (opt)
26534 + "m" (opt),
26535 + "r" (__PCIBIOS_DS)
26536 : "memory");
26537 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26538 if (ret & 0xff00)
26539 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26540 {
26541 int ret;
26542
26543 - __asm__("lcall *(%%esi); cld\n\t"
26544 + __asm__("movw %w5, %%ds\n\t"
26545 + "lcall *%%ss:(%%esi); cld\n\t"
26546 + "push %%ss\n\t"
26547 + "pop %%ds\n"
26548 "jc 1f\n\t"
26549 "xor %%ah, %%ah\n"
26550 "1:"
26551 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26552 : "0" (PCIBIOS_SET_PCI_HW_INT),
26553 "b" ((dev->bus->number << 8) | dev->devfn),
26554 "c" ((irq << 8) | (pin + 10)),
26555 - "S" (&pci_indirect));
26556 + "S" (&pci_indirect),
26557 + "r" (__PCIBIOS_DS));
26558 return !(ret & 0xff00);
26559 }
26560 EXPORT_SYMBOL(pcibios_set_irq_routing);
26561 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26562 index 40e4469..1ab536e 100644
26563 --- a/arch/x86/platform/efi/efi_32.c
26564 +++ b/arch/x86/platform/efi/efi_32.c
26565 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26566 {
26567 struct desc_ptr gdt_descr;
26568
26569 +#ifdef CONFIG_PAX_KERNEXEC
26570 + struct desc_struct d;
26571 +#endif
26572 +
26573 local_irq_save(efi_rt_eflags);
26574
26575 load_cr3(initial_page_table);
26576 __flush_tlb_all();
26577
26578 +#ifdef CONFIG_PAX_KERNEXEC
26579 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26580 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26581 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26582 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26583 +#endif
26584 +
26585 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26586 gdt_descr.size = GDT_SIZE - 1;
26587 load_gdt(&gdt_descr);
26588 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26589 {
26590 struct desc_ptr gdt_descr;
26591
26592 +#ifdef CONFIG_PAX_KERNEXEC
26593 + struct desc_struct d;
26594 +
26595 + memset(&d, 0, sizeof d);
26596 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26597 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26598 +#endif
26599 +
26600 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26601 gdt_descr.size = GDT_SIZE - 1;
26602 load_gdt(&gdt_descr);
26603 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26604 index fbe66e6..eae5e38 100644
26605 --- a/arch/x86/platform/efi/efi_stub_32.S
26606 +++ b/arch/x86/platform/efi/efi_stub_32.S
26607 @@ -6,7 +6,9 @@
26608 */
26609
26610 #include <linux/linkage.h>
26611 +#include <linux/init.h>
26612 #include <asm/page_types.h>
26613 +#include <asm/segment.h>
26614
26615 /*
26616 * efi_call_phys(void *, ...) is a function with variable parameters.
26617 @@ -20,7 +22,7 @@
26618 * service functions will comply with gcc calling convention, too.
26619 */
26620
26621 -.text
26622 +__INIT
26623 ENTRY(efi_call_phys)
26624 /*
26625 * 0. The function can only be called in Linux kernel. So CS has been
26626 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26627 * The mapping of lower virtual memory has been created in prelog and
26628 * epilog.
26629 */
26630 - movl $1f, %edx
26631 - subl $__PAGE_OFFSET, %edx
26632 - jmp *%edx
26633 +#ifdef CONFIG_PAX_KERNEXEC
26634 + movl $(__KERNEXEC_EFI_DS), %edx
26635 + mov %edx, %ds
26636 + mov %edx, %es
26637 + mov %edx, %ss
26638 + addl $2f,(1f)
26639 + ljmp *(1f)
26640 +
26641 +__INITDATA
26642 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26643 +.previous
26644 +
26645 +2:
26646 + subl $2b,(1b)
26647 +#else
26648 + jmp 1f-__PAGE_OFFSET
26649 1:
26650 +#endif
26651
26652 /*
26653 * 2. Now on the top of stack is the return
26654 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26655 * parameter 2, ..., param n. To make things easy, we save the return
26656 * address of efi_call_phys in a global variable.
26657 */
26658 - popl %edx
26659 - movl %edx, saved_return_addr
26660 - /* get the function pointer into ECX*/
26661 - popl %ecx
26662 - movl %ecx, efi_rt_function_ptr
26663 - movl $2f, %edx
26664 - subl $__PAGE_OFFSET, %edx
26665 - pushl %edx
26666 + popl (saved_return_addr)
26667 + popl (efi_rt_function_ptr)
26668
26669 /*
26670 * 3. Clear PG bit in %CR0.
26671 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26672 /*
26673 * 5. Call the physical function.
26674 */
26675 - jmp *%ecx
26676 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26677
26678 -2:
26679 /*
26680 * 6. After EFI runtime service returns, control will return to
26681 * following instruction. We'd better readjust stack pointer first.
26682 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26683 movl %cr0, %edx
26684 orl $0x80000000, %edx
26685 movl %edx, %cr0
26686 - jmp 1f
26687 -1:
26688 +
26689 /*
26690 * 8. Now restore the virtual mode from flat mode by
26691 * adding EIP with PAGE_OFFSET.
26692 */
26693 - movl $1f, %edx
26694 - jmp *%edx
26695 +#ifdef CONFIG_PAX_KERNEXEC
26696 + movl $(__KERNEL_DS), %edx
26697 + mov %edx, %ds
26698 + mov %edx, %es
26699 + mov %edx, %ss
26700 + ljmp $(__KERNEL_CS),$1f
26701 +#else
26702 + jmp 1f+__PAGE_OFFSET
26703 +#endif
26704 1:
26705
26706 /*
26707 * 9. Balance the stack. And because EAX contain the return value,
26708 * we'd better not clobber it.
26709 */
26710 - leal efi_rt_function_ptr, %edx
26711 - movl (%edx), %ecx
26712 - pushl %ecx
26713 + pushl (efi_rt_function_ptr)
26714
26715 /*
26716 - * 10. Push the saved return address onto the stack and return.
26717 + * 10. Return to the saved return address.
26718 */
26719 - leal saved_return_addr, %edx
26720 - movl (%edx), %ecx
26721 - pushl %ecx
26722 - ret
26723 + jmpl *(saved_return_addr)
26724 ENDPROC(efi_call_phys)
26725 .previous
26726
26727 -.data
26728 +__INITDATA
26729 saved_return_addr:
26730 .long 0
26731 efi_rt_function_ptr:
26732 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26733 index 4c07cca..2c8427d 100644
26734 --- a/arch/x86/platform/efi/efi_stub_64.S
26735 +++ b/arch/x86/platform/efi/efi_stub_64.S
26736 @@ -7,6 +7,7 @@
26737 */
26738
26739 #include <linux/linkage.h>
26740 +#include <asm/alternative-asm.h>
26741
26742 #define SAVE_XMM \
26743 mov %rsp, %rax; \
26744 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26745 call *%rdi
26746 addq $32, %rsp
26747 RESTORE_XMM
26748 + pax_force_retaddr 0, 1
26749 ret
26750 ENDPROC(efi_call0)
26751
26752 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26753 call *%rdi
26754 addq $32, %rsp
26755 RESTORE_XMM
26756 + pax_force_retaddr 0, 1
26757 ret
26758 ENDPROC(efi_call1)
26759
26760 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26761 call *%rdi
26762 addq $32, %rsp
26763 RESTORE_XMM
26764 + pax_force_retaddr 0, 1
26765 ret
26766 ENDPROC(efi_call2)
26767
26768 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26769 call *%rdi
26770 addq $32, %rsp
26771 RESTORE_XMM
26772 + pax_force_retaddr 0, 1
26773 ret
26774 ENDPROC(efi_call3)
26775
26776 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26777 call *%rdi
26778 addq $32, %rsp
26779 RESTORE_XMM
26780 + pax_force_retaddr 0, 1
26781 ret
26782 ENDPROC(efi_call4)
26783
26784 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26785 call *%rdi
26786 addq $48, %rsp
26787 RESTORE_XMM
26788 + pax_force_retaddr 0, 1
26789 ret
26790 ENDPROC(efi_call5)
26791
26792 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26793 call *%rdi
26794 addq $48, %rsp
26795 RESTORE_XMM
26796 + pax_force_retaddr 0, 1
26797 ret
26798 ENDPROC(efi_call6)
26799 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26800 index fd41a92..9c33628 100644
26801 --- a/arch/x86/platform/mrst/mrst.c
26802 +++ b/arch/x86/platform/mrst/mrst.c
26803 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26804 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26805 int sfi_mrtc_num;
26806
26807 -static void mrst_power_off(void)
26808 +static __noreturn void mrst_power_off(void)
26809 {
26810 + BUG();
26811 }
26812
26813 -static void mrst_reboot(void)
26814 +static __noreturn void mrst_reboot(void)
26815 {
26816 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26817 + BUG();
26818 }
26819
26820 /* parse all the mtimer info to a static mtimer array */
26821 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26822 index 218cdb1..fd55c08 100644
26823 --- a/arch/x86/power/cpu.c
26824 +++ b/arch/x86/power/cpu.c
26825 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26826 static void fix_processor_context(void)
26827 {
26828 int cpu = smp_processor_id();
26829 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26830 + struct tss_struct *t = init_tss + cpu;
26831
26832 set_tss_desc(cpu, t); /*
26833 * This just modifies memory; should not be
26834 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26835 */
26836
26837 #ifdef CONFIG_X86_64
26838 + pax_open_kernel();
26839 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26840 + pax_close_kernel();
26841
26842 syscall_init(); /* This sets MSR_*STAR and related */
26843 #endif
26844 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26845 index cbca565..bae7133 100644
26846 --- a/arch/x86/realmode/init.c
26847 +++ b/arch/x86/realmode/init.c
26848 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26849 __va(real_mode_header->trampoline_header);
26850
26851 #ifdef CONFIG_X86_32
26852 - trampoline_header->start = __pa(startup_32_smp);
26853 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26854 +
26855 +#ifdef CONFIG_PAX_KERNEXEC
26856 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26857 +#endif
26858 +
26859 + trampoline_header->boot_cs = __BOOT_CS;
26860 trampoline_header->gdt_limit = __BOOT_DS + 7;
26861 trampoline_header->gdt_base = __pa(boot_gdt);
26862 #else
26863 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26864 index 8869287..d577672 100644
26865 --- a/arch/x86/realmode/rm/Makefile
26866 +++ b/arch/x86/realmode/rm/Makefile
26867 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26868 $(call cc-option, -fno-unit-at-a-time)) \
26869 $(call cc-option, -fno-stack-protector) \
26870 $(call cc-option, -mpreferred-stack-boundary=2)
26871 +ifdef CONSTIFY_PLUGIN
26872 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26873 +endif
26874 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26875 GCOV_PROFILE := n
26876 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26877 index a28221d..93c40f1 100644
26878 --- a/arch/x86/realmode/rm/header.S
26879 +++ b/arch/x86/realmode/rm/header.S
26880 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26881 #endif
26882 /* APM/BIOS reboot */
26883 .long pa_machine_real_restart_asm
26884 -#ifdef CONFIG_X86_64
26885 +#ifdef CONFIG_X86_32
26886 + .long __KERNEL_CS
26887 +#else
26888 .long __KERNEL32_CS
26889 #endif
26890 END(real_mode_header)
26891 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26892 index c1b2791..f9e31c7 100644
26893 --- a/arch/x86/realmode/rm/trampoline_32.S
26894 +++ b/arch/x86/realmode/rm/trampoline_32.S
26895 @@ -25,6 +25,12 @@
26896 #include <asm/page_types.h>
26897 #include "realmode.h"
26898
26899 +#ifdef CONFIG_PAX_KERNEXEC
26900 +#define ta(X) (X)
26901 +#else
26902 +#define ta(X) (pa_ ## X)
26903 +#endif
26904 +
26905 .text
26906 .code16
26907
26908 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26909
26910 cli # We should be safe anyway
26911
26912 - movl tr_start, %eax # where we need to go
26913 -
26914 movl $0xA5A5A5A5, trampoline_status
26915 # write marker for master knows we're running
26916
26917 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26918 movw $1, %dx # protected mode (PE) bit
26919 lmsw %dx # into protected mode
26920
26921 - ljmpl $__BOOT_CS, $pa_startup_32
26922 + ljmpl *(trampoline_header)
26923
26924 .section ".text32","ax"
26925 .code32
26926 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26927 .balign 8
26928 GLOBAL(trampoline_header)
26929 tr_start: .space 4
26930 - tr_gdt_pad: .space 2
26931 + tr_boot_cs: .space 2
26932 tr_gdt: .space 6
26933 END(trampoline_header)
26934
26935 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26936 index bb360dc..3e5945f 100644
26937 --- a/arch/x86/realmode/rm/trampoline_64.S
26938 +++ b/arch/x86/realmode/rm/trampoline_64.S
26939 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26940 wrmsr
26941
26942 # Enable paging and in turn activate Long Mode
26943 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26944 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26945 movl %eax, %cr0
26946
26947 /*
26948 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26949 index 5a1847d..deccb30 100644
26950 --- a/arch/x86/tools/relocs.c
26951 +++ b/arch/x86/tools/relocs.c
26952 @@ -12,10 +12,13 @@
26953 #include <regex.h>
26954 #include <tools/le_byteshift.h>
26955
26956 +#include "../../../include/generated/autoconf.h"
26957 +
26958 static void die(char *fmt, ...);
26959
26960 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26961 static Elf32_Ehdr ehdr;
26962 +static Elf32_Phdr *phdr;
26963 static unsigned long reloc_count, reloc_idx;
26964 static unsigned long *relocs;
26965 static unsigned long reloc16_count, reloc16_idx;
26966 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26967 }
26968 }
26969
26970 +static void read_phdrs(FILE *fp)
26971 +{
26972 + unsigned int i;
26973 +
26974 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26975 + if (!phdr) {
26976 + die("Unable to allocate %d program headers\n",
26977 + ehdr.e_phnum);
26978 + }
26979 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26980 + die("Seek to %d failed: %s\n",
26981 + ehdr.e_phoff, strerror(errno));
26982 + }
26983 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26984 + die("Cannot read ELF program headers: %s\n",
26985 + strerror(errno));
26986 + }
26987 + for(i = 0; i < ehdr.e_phnum; i++) {
26988 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26989 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26990 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26991 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26992 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26993 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26994 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26995 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26996 + }
26997 +
26998 +}
26999 +
27000 static void read_shdrs(FILE *fp)
27001 {
27002 - int i;
27003 + unsigned int i;
27004 Elf32_Shdr shdr;
27005
27006 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27007 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27008
27009 static void read_strtabs(FILE *fp)
27010 {
27011 - int i;
27012 + unsigned int i;
27013 for (i = 0; i < ehdr.e_shnum; i++) {
27014 struct section *sec = &secs[i];
27015 if (sec->shdr.sh_type != SHT_STRTAB) {
27016 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27017
27018 static void read_symtabs(FILE *fp)
27019 {
27020 - int i,j;
27021 + unsigned int i,j;
27022 for (i = 0; i < ehdr.e_shnum; i++) {
27023 struct section *sec = &secs[i];
27024 if (sec->shdr.sh_type != SHT_SYMTAB) {
27025 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27026 }
27027
27028
27029 -static void read_relocs(FILE *fp)
27030 +static void read_relocs(FILE *fp, int use_real_mode)
27031 {
27032 - int i,j;
27033 + unsigned int i,j;
27034 + uint32_t base;
27035 +
27036 for (i = 0; i < ehdr.e_shnum; i++) {
27037 struct section *sec = &secs[i];
27038 if (sec->shdr.sh_type != SHT_REL) {
27039 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27040 die("Cannot read symbol table: %s\n",
27041 strerror(errno));
27042 }
27043 + base = 0;
27044 +
27045 +#ifdef CONFIG_X86_32
27046 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27047 + if (phdr[j].p_type != PT_LOAD )
27048 + continue;
27049 + 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)
27050 + continue;
27051 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27052 + break;
27053 + }
27054 +#endif
27055 +
27056 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27057 Elf32_Rel *rel = &sec->reltab[j];
27058 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27059 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27060 rel->r_info = elf32_to_cpu(rel->r_info);
27061 }
27062 }
27063 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27064
27065 static void print_absolute_symbols(void)
27066 {
27067 - int i;
27068 + unsigned int i;
27069 printf("Absolute symbols\n");
27070 printf(" Num: Value Size Type Bind Visibility Name\n");
27071 for (i = 0; i < ehdr.e_shnum; i++) {
27072 struct section *sec = &secs[i];
27073 char *sym_strtab;
27074 - int j;
27075 + unsigned int j;
27076
27077 if (sec->shdr.sh_type != SHT_SYMTAB) {
27078 continue;
27079 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27080
27081 static void print_absolute_relocs(void)
27082 {
27083 - int i, printed = 0;
27084 + unsigned int i, printed = 0;
27085
27086 for (i = 0; i < ehdr.e_shnum; i++) {
27087 struct section *sec = &secs[i];
27088 struct section *sec_applies, *sec_symtab;
27089 char *sym_strtab;
27090 Elf32_Sym *sh_symtab;
27091 - int j;
27092 + unsigned int j;
27093 if (sec->shdr.sh_type != SHT_REL) {
27094 continue;
27095 }
27096 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27097 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27098 int use_real_mode)
27099 {
27100 - int i;
27101 + unsigned int i;
27102 /* Walk through the relocations */
27103 for (i = 0; i < ehdr.e_shnum; i++) {
27104 char *sym_strtab;
27105 Elf32_Sym *sh_symtab;
27106 struct section *sec_applies, *sec_symtab;
27107 - int j;
27108 + unsigned int j;
27109 struct section *sec = &secs[i];
27110
27111 if (sec->shdr.sh_type != SHT_REL) {
27112 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27113 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27114 r_type = ELF32_R_TYPE(rel->r_info);
27115
27116 + if (!use_real_mode) {
27117 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27118 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27119 + continue;
27120 +
27121 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27122 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27123 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27124 + continue;
27125 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27126 + continue;
27127 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27128 + continue;
27129 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27130 + continue;
27131 +#endif
27132 + }
27133 +
27134 shn_abs = sym->st_shndx == SHN_ABS;
27135
27136 switch (r_type) {
27137 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27138
27139 static void emit_relocs(int as_text, int use_real_mode)
27140 {
27141 - int i;
27142 + unsigned int i;
27143 /* Count how many relocations I have and allocate space for them. */
27144 reloc_count = 0;
27145 walk_relocs(count_reloc, use_real_mode);
27146 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27147 fname, strerror(errno));
27148 }
27149 read_ehdr(fp);
27150 + read_phdrs(fp);
27151 read_shdrs(fp);
27152 read_strtabs(fp);
27153 read_symtabs(fp);
27154 - read_relocs(fp);
27155 + read_relocs(fp, use_real_mode);
27156 if (show_absolute_syms) {
27157 print_absolute_symbols();
27158 return 0;
27159 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27160 index fd14be1..e3c79c0 100644
27161 --- a/arch/x86/vdso/Makefile
27162 +++ b/arch/x86/vdso/Makefile
27163 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27164 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27165 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27166
27167 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27168 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27169 GCOV_PROFILE := n
27170
27171 #
27172 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27173 index 0faad64..39ef157 100644
27174 --- a/arch/x86/vdso/vdso32-setup.c
27175 +++ b/arch/x86/vdso/vdso32-setup.c
27176 @@ -25,6 +25,7 @@
27177 #include <asm/tlbflush.h>
27178 #include <asm/vdso.h>
27179 #include <asm/proto.h>
27180 +#include <asm/mman.h>
27181
27182 enum {
27183 VDSO_DISABLED = 0,
27184 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27185 void enable_sep_cpu(void)
27186 {
27187 int cpu = get_cpu();
27188 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27189 + struct tss_struct *tss = init_tss + cpu;
27190
27191 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27192 put_cpu();
27193 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27194 gate_vma.vm_start = FIXADDR_USER_START;
27195 gate_vma.vm_end = FIXADDR_USER_END;
27196 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27197 - gate_vma.vm_page_prot = __P101;
27198 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27199
27200 return 0;
27201 }
27202 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27203 if (compat)
27204 addr = VDSO_HIGH_BASE;
27205 else {
27206 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27207 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27208 if (IS_ERR_VALUE(addr)) {
27209 ret = addr;
27210 goto up_fail;
27211 }
27212 }
27213
27214 - current->mm->context.vdso = (void *)addr;
27215 + current->mm->context.vdso = addr;
27216
27217 if (compat_uses_vma || !compat) {
27218 /*
27219 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27220 }
27221
27222 current_thread_info()->sysenter_return =
27223 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27224 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27225
27226 up_fail:
27227 if (ret)
27228 - current->mm->context.vdso = NULL;
27229 + current->mm->context.vdso = 0;
27230
27231 up_write(&mm->mmap_sem);
27232
27233 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27234
27235 const char *arch_vma_name(struct vm_area_struct *vma)
27236 {
27237 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27238 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27239 return "[vdso]";
27240 +
27241 +#ifdef CONFIG_PAX_SEGMEXEC
27242 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27243 + return "[vdso]";
27244 +#endif
27245 +
27246 return NULL;
27247 }
27248
27249 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27250 * Check to see if the corresponding task was created in compat vdso
27251 * mode.
27252 */
27253 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27254 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27255 return &gate_vma;
27256 return NULL;
27257 }
27258 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27259 index 00aaf04..4a26505 100644
27260 --- a/arch/x86/vdso/vma.c
27261 +++ b/arch/x86/vdso/vma.c
27262 @@ -16,8 +16,6 @@
27263 #include <asm/vdso.h>
27264 #include <asm/page.h>
27265
27266 -unsigned int __read_mostly vdso_enabled = 1;
27267 -
27268 extern char vdso_start[], vdso_end[];
27269 extern unsigned short vdso_sync_cpuid;
27270
27271 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27272 * unaligned here as a result of stack start randomization.
27273 */
27274 addr = PAGE_ALIGN(addr);
27275 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27276
27277 return addr;
27278 }
27279 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27280 unsigned size)
27281 {
27282 struct mm_struct *mm = current->mm;
27283 - unsigned long addr;
27284 + unsigned long addr = 0;
27285 int ret;
27286
27287 - if (!vdso_enabled)
27288 - return 0;
27289 -
27290 down_write(&mm->mmap_sem);
27291 +
27292 +#ifdef CONFIG_PAX_RANDMMAP
27293 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27294 +#endif
27295 +
27296 addr = vdso_addr(mm->start_stack, size);
27297 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27298 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27299 if (IS_ERR_VALUE(addr)) {
27300 ret = addr;
27301 goto up_fail;
27302 }
27303
27304 - current->mm->context.vdso = (void *)addr;
27305 + mm->context.vdso = addr;
27306
27307 ret = install_special_mapping(mm, addr, size,
27308 VM_READ|VM_EXEC|
27309 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27310 pages);
27311 - if (ret) {
27312 - current->mm->context.vdso = NULL;
27313 - goto up_fail;
27314 - }
27315 + if (ret)
27316 + mm->context.vdso = 0;
27317
27318 up_fail:
27319 up_write(&mm->mmap_sem);
27320 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27321 vdsox32_size);
27322 }
27323 #endif
27324 -
27325 -static __init int vdso_setup(char *s)
27326 -{
27327 - vdso_enabled = simple_strtoul(s, NULL, 0);
27328 - return 0;
27329 -}
27330 -__setup("vdso=", vdso_setup);
27331 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27332 index c1461de..355f120 100644
27333 --- a/arch/x86/xen/enlighten.c
27334 +++ b/arch/x86/xen/enlighten.c
27335 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27336
27337 struct shared_info xen_dummy_shared_info;
27338
27339 -void *xen_initial_gdt;
27340 -
27341 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27342 __read_mostly int xen_have_vector_callback;
27343 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27344 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27345
27346 static void set_xen_basic_apic_ops(void)
27347 {
27348 - apic->read = xen_apic_read;
27349 - apic->write = xen_apic_write;
27350 - apic->icr_read = xen_apic_icr_read;
27351 - apic->icr_write = xen_apic_icr_write;
27352 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27353 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27354 - apic->set_apic_id = xen_set_apic_id;
27355 - apic->get_apic_id = xen_get_apic_id;
27356 + *(void **)&apic->read = xen_apic_read;
27357 + *(void **)&apic->write = xen_apic_write;
27358 + *(void **)&apic->icr_read = xen_apic_icr_read;
27359 + *(void **)&apic->icr_write = xen_apic_icr_write;
27360 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27361 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27362 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27363 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27364
27365 #ifdef CONFIG_SMP
27366 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27367 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27368 - apic->send_IPI_mask = xen_send_IPI_mask;
27369 - apic->send_IPI_all = xen_send_IPI_all;
27370 - apic->send_IPI_self = xen_send_IPI_self;
27371 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27372 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27373 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27374 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27375 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27376 #endif
27377 }
27378
27379 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27380 #endif
27381 };
27382
27383 -static void xen_reboot(int reason)
27384 +static __noreturn void xen_reboot(int reason)
27385 {
27386 struct sched_shutdown r = { .reason = reason };
27387
27388 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27389 - BUG();
27390 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27391 + BUG();
27392 }
27393
27394 -static void xen_restart(char *msg)
27395 +static __noreturn void xen_restart(char *msg)
27396 {
27397 xen_reboot(SHUTDOWN_reboot);
27398 }
27399
27400 -static void xen_emergency_restart(void)
27401 +static __noreturn void xen_emergency_restart(void)
27402 {
27403 xen_reboot(SHUTDOWN_reboot);
27404 }
27405
27406 -static void xen_machine_halt(void)
27407 +static __noreturn void xen_machine_halt(void)
27408 {
27409 xen_reboot(SHUTDOWN_poweroff);
27410 }
27411
27412 -static void xen_machine_power_off(void)
27413 +static __noreturn void xen_machine_power_off(void)
27414 {
27415 if (pm_power_off)
27416 pm_power_off();
27417 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27418 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27419
27420 /* Work out if we support NX */
27421 - x86_configure_nx();
27422 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27423 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27424 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27425 + unsigned l, h;
27426 +
27427 + __supported_pte_mask |= _PAGE_NX;
27428 + rdmsr(MSR_EFER, l, h);
27429 + l |= EFER_NX;
27430 + wrmsr(MSR_EFER, l, h);
27431 + }
27432 +#endif
27433
27434 xen_setup_features();
27435
27436 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27437
27438 machine_ops = xen_machine_ops;
27439
27440 - /*
27441 - * The only reliable way to retain the initial address of the
27442 - * percpu gdt_page is to remember it here, so we can go and
27443 - * mark it RW later, when the initial percpu area is freed.
27444 - */
27445 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27446 -
27447 xen_smp_init();
27448
27449 #ifdef CONFIG_ACPI_NUMA
27450 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27451 index dde1a3f..6b663e6 100644
27452 --- a/arch/x86/xen/mmu.c
27453 +++ b/arch/x86/xen/mmu.c
27454 @@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27455 convert_pfn_mfn(init_level4_pgt);
27456 convert_pfn_mfn(level3_ident_pgt);
27457 convert_pfn_mfn(level3_kernel_pgt);
27458 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27459 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27460 + convert_pfn_mfn(level3_vmemmap_pgt);
27461
27462 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27463 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27464 @@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27465 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27466 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27467 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27468 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27469 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27470 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27471 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27472 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27473 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27474 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27475
27476 @@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27477 pv_mmu_ops.set_pud = xen_set_pud;
27478 #if PAGETABLE_LEVELS == 4
27479 pv_mmu_ops.set_pgd = xen_set_pgd;
27480 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27481 #endif
27482
27483 /* This will work as long as patching hasn't happened yet
27484 @@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27485 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27486 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27487 .set_pgd = xen_set_pgd_hyper,
27488 + .set_pgd_batched = xen_set_pgd_hyper,
27489
27490 .alloc_pud = xen_alloc_pmd_init,
27491 .release_pud = xen_release_pmd_init,
27492 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27493 index f58dca7..ad21f52 100644
27494 --- a/arch/x86/xen/smp.c
27495 +++ b/arch/x86/xen/smp.c
27496 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27497 {
27498 BUG_ON(smp_processor_id() != 0);
27499 native_smp_prepare_boot_cpu();
27500 -
27501 - /* We've switched to the "real" per-cpu gdt, so make sure the
27502 - old memory can be recycled */
27503 - make_lowmem_page_readwrite(xen_initial_gdt);
27504 -
27505 xen_filter_cpu_maps();
27506 xen_setup_vcpu_info_placement();
27507 }
27508 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27509 gdt = get_cpu_gdt_table(cpu);
27510
27511 ctxt->flags = VGCF_IN_KERNEL;
27512 - ctxt->user_regs.ds = __USER_DS;
27513 - ctxt->user_regs.es = __USER_DS;
27514 + ctxt->user_regs.ds = __KERNEL_DS;
27515 + ctxt->user_regs.es = __KERNEL_DS;
27516 ctxt->user_regs.ss = __KERNEL_DS;
27517 #ifdef CONFIG_X86_32
27518 ctxt->user_regs.fs = __KERNEL_PERCPU;
27519 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27520 + savesegment(gs, ctxt->user_regs.gs);
27521 #else
27522 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27523 #endif
27524 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27525 int rc;
27526
27527 per_cpu(current_task, cpu) = idle;
27528 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27529 #ifdef CONFIG_X86_32
27530 irq_ctx_init(cpu);
27531 #else
27532 clear_tsk_thread_flag(idle, TIF_FORK);
27533 - per_cpu(kernel_stack, cpu) =
27534 - (unsigned long)task_stack_page(idle) -
27535 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27536 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27537 #endif
27538 xen_setup_runstate_info(cpu);
27539 xen_setup_timer(cpu);
27540 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27541 index f9643fc..602e8af 100644
27542 --- a/arch/x86/xen/xen-asm_32.S
27543 +++ b/arch/x86/xen/xen-asm_32.S
27544 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27545 ESP_OFFSET=4 # bytes pushed onto stack
27546
27547 /*
27548 - * Store vcpu_info pointer for easy access. Do it this way to
27549 - * avoid having to reload %fs
27550 + * Store vcpu_info pointer for easy access.
27551 */
27552 #ifdef CONFIG_SMP
27553 - GET_THREAD_INFO(%eax)
27554 - movl TI_cpu(%eax), %eax
27555 - movl __per_cpu_offset(,%eax,4), %eax
27556 - mov xen_vcpu(%eax), %eax
27557 + push %fs
27558 + mov $(__KERNEL_PERCPU), %eax
27559 + mov %eax, %fs
27560 + mov PER_CPU_VAR(xen_vcpu), %eax
27561 + pop %fs
27562 #else
27563 movl xen_vcpu, %eax
27564 #endif
27565 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27566 index aaa7291..3f77960 100644
27567 --- a/arch/x86/xen/xen-head.S
27568 +++ b/arch/x86/xen/xen-head.S
27569 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27570 #ifdef CONFIG_X86_32
27571 mov %esi,xen_start_info
27572 mov $init_thread_union+THREAD_SIZE,%esp
27573 +#ifdef CONFIG_SMP
27574 + movl $cpu_gdt_table,%edi
27575 + movl $__per_cpu_load,%eax
27576 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27577 + rorl $16,%eax
27578 + movb %al,__KERNEL_PERCPU + 4(%edi)
27579 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27580 + movl $__per_cpu_end - 1,%eax
27581 + subl $__per_cpu_start,%eax
27582 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27583 +#endif
27584 #else
27585 mov %rsi,xen_start_info
27586 mov $init_thread_union+THREAD_SIZE,%rsp
27587 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27588 index 202d4c1..99b072a 100644
27589 --- a/arch/x86/xen/xen-ops.h
27590 +++ b/arch/x86/xen/xen-ops.h
27591 @@ -10,8 +10,6 @@
27592 extern const char xen_hypervisor_callback[];
27593 extern const char xen_failsafe_callback[];
27594
27595 -extern void *xen_initial_gdt;
27596 -
27597 struct trap_info;
27598 void xen_copy_trap_info(struct trap_info *traps);
27599
27600 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27601 index 525bd3d..ef888b1 100644
27602 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27603 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27604 @@ -119,9 +119,9 @@
27605 ----------------------------------------------------------------------*/
27606
27607 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27608 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27609 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27610 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27611 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27612
27613 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27614 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27615 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27616 index 2f33760..835e50a 100644
27617 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27618 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27619 @@ -11,6 +11,7 @@
27620 #ifndef _XTENSA_CORE_H
27621 #define _XTENSA_CORE_H
27622
27623 +#include <linux/const.h>
27624
27625 /****************************************************************************
27626 Parameters Useful for Any Code, USER or PRIVILEGED
27627 @@ -112,9 +113,9 @@
27628 ----------------------------------------------------------------------*/
27629
27630 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27631 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27632 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27633 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27634 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27635
27636 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27637 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27638 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27639 index af00795..2bb8105 100644
27640 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27641 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27642 @@ -11,6 +11,7 @@
27643 #ifndef _XTENSA_CORE_CONFIGURATION_H
27644 #define _XTENSA_CORE_CONFIGURATION_H
27645
27646 +#include <linux/const.h>
27647
27648 /****************************************************************************
27649 Parameters Useful for Any Code, USER or PRIVILEGED
27650 @@ -118,9 +119,9 @@
27651 ----------------------------------------------------------------------*/
27652
27653 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27654 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27655 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27656 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27657 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27658
27659 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27660 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27661 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27662 index 58916af..9cb880b 100644
27663 --- a/block/blk-iopoll.c
27664 +++ b/block/blk-iopoll.c
27665 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27666 }
27667 EXPORT_SYMBOL(blk_iopoll_complete);
27668
27669 -static void blk_iopoll_softirq(struct softirq_action *h)
27670 +static void blk_iopoll_softirq(void)
27671 {
27672 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27673 int rearm = 0, budget = blk_iopoll_budget;
27674 diff --git a/block/blk-map.c b/block/blk-map.c
27675 index 623e1cd..ca1e109 100644
27676 --- a/block/blk-map.c
27677 +++ b/block/blk-map.c
27678 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27679 if (!len || !kbuf)
27680 return -EINVAL;
27681
27682 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27683 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27684 if (do_copy)
27685 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27686 else
27687 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27688 index 467c8de..4bddc6d 100644
27689 --- a/block/blk-softirq.c
27690 +++ b/block/blk-softirq.c
27691 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27692 * Softirq action handler - move entries to local list and loop over them
27693 * while passing them to the queue registered handler.
27694 */
27695 -static void blk_done_softirq(struct softirq_action *h)
27696 +static void blk_done_softirq(void)
27697 {
27698 struct list_head *cpu_list, local_list;
27699
27700 diff --git a/block/bsg.c b/block/bsg.c
27701 index ff64ae3..593560c 100644
27702 --- a/block/bsg.c
27703 +++ b/block/bsg.c
27704 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27705 struct sg_io_v4 *hdr, struct bsg_device *bd,
27706 fmode_t has_write_perm)
27707 {
27708 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27709 + unsigned char *cmdptr;
27710 +
27711 if (hdr->request_len > BLK_MAX_CDB) {
27712 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27713 if (!rq->cmd)
27714 return -ENOMEM;
27715 - }
27716 + cmdptr = rq->cmd;
27717 + } else
27718 + cmdptr = tmpcmd;
27719
27720 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27721 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27722 hdr->request_len))
27723 return -EFAULT;
27724
27725 + if (cmdptr != rq->cmd)
27726 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27727 +
27728 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27729 if (blk_verify_command(rq->cmd, has_write_perm))
27730 return -EPERM;
27731 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27732 index 7c668c8..db3521c 100644
27733 --- a/block/compat_ioctl.c
27734 +++ b/block/compat_ioctl.c
27735 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27736 err |= __get_user(f->spec1, &uf->spec1);
27737 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27738 err |= __get_user(name, &uf->name);
27739 - f->name = compat_ptr(name);
27740 + f->name = (void __force_kernel *)compat_ptr(name);
27741 if (err) {
27742 err = -EFAULT;
27743 goto out;
27744 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27745 index 6296b40..417c00f 100644
27746 --- a/block/partitions/efi.c
27747 +++ b/block/partitions/efi.c
27748 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27749 if (!gpt)
27750 return NULL;
27751
27752 + if (!le32_to_cpu(gpt->num_partition_entries))
27753 + return NULL;
27754 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27755 + if (!pte)
27756 + return NULL;
27757 +
27758 count = le32_to_cpu(gpt->num_partition_entries) *
27759 le32_to_cpu(gpt->sizeof_partition_entry);
27760 - if (!count)
27761 - return NULL;
27762 - pte = kzalloc(count, GFP_KERNEL);
27763 - if (!pte)
27764 - return NULL;
27765 -
27766 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27767 (u8 *) pte,
27768 count) < count) {
27769 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27770 index 9a87daa..fb17486 100644
27771 --- a/block/scsi_ioctl.c
27772 +++ b/block/scsi_ioctl.c
27773 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27774 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27775 struct sg_io_hdr *hdr, fmode_t mode)
27776 {
27777 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27778 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27779 + unsigned char *cmdptr;
27780 +
27781 + if (rq->cmd != rq->__cmd)
27782 + cmdptr = rq->cmd;
27783 + else
27784 + cmdptr = tmpcmd;
27785 +
27786 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27787 return -EFAULT;
27788 +
27789 + if (cmdptr != rq->cmd)
27790 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27791 +
27792 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27793 return -EPERM;
27794
27795 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27796 int err;
27797 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27798 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27799 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27800 + unsigned char *cmdptr;
27801
27802 if (!sic)
27803 return -EINVAL;
27804 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27805 */
27806 err = -EFAULT;
27807 rq->cmd_len = cmdlen;
27808 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27809 +
27810 + if (rq->cmd != rq->__cmd)
27811 + cmdptr = rq->cmd;
27812 + else
27813 + cmdptr = tmpcmd;
27814 +
27815 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27816 goto error;
27817
27818 + if (rq->cmd != cmdptr)
27819 + memcpy(rq->cmd, cmdptr, cmdlen);
27820 +
27821 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27822 goto error;
27823
27824 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27825 index 671d4d6..afec999 100644
27826 --- a/crypto/cryptd.c
27827 +++ b/crypto/cryptd.c
27828 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27829
27830 struct cryptd_blkcipher_request_ctx {
27831 crypto_completion_t complete;
27832 -};
27833 +} __no_const;
27834
27835 struct cryptd_hash_ctx {
27836 struct crypto_shash *child;
27837 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27838
27839 struct cryptd_aead_request_ctx {
27840 crypto_completion_t complete;
27841 -};
27842 +} __no_const;
27843
27844 static void cryptd_queue_worker(struct work_struct *work);
27845
27846 @@ -137,13 +137,18 @@ static void cryptd_queue_worker(struct work_struct *work)
27847 struct crypto_async_request *req, *backlog;
27848
27849 cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
27850 - /* Only handle one request at a time to avoid hogging crypto
27851 - * workqueue. preempt_disable/enable is used to prevent
27852 - * being preempted by cryptd_enqueue_request() */
27853 + /*
27854 + * Only handle one request at a time to avoid hogging crypto workqueue.
27855 + * preempt_disable/enable is used to prevent being preempted by
27856 + * cryptd_enqueue_request(). local_bh_disable/enable is used to prevent
27857 + * cryptd_enqueue_request() being accessed from software interrupts.
27858 + */
27859 + local_bh_disable();
27860 preempt_disable();
27861 backlog = crypto_get_backlog(&cpu_queue->queue);
27862 req = crypto_dequeue_request(&cpu_queue->queue);
27863 preempt_enable();
27864 + local_bh_enable();
27865
27866 if (!req)
27867 return;
27868 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27869 index e6defd8..c26a225 100644
27870 --- a/drivers/acpi/apei/cper.c
27871 +++ b/drivers/acpi/apei/cper.c
27872 @@ -38,12 +38,12 @@
27873 */
27874 u64 cper_next_record_id(void)
27875 {
27876 - static atomic64_t seq;
27877 + static atomic64_unchecked_t seq;
27878
27879 - if (!atomic64_read(&seq))
27880 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27881 + if (!atomic64_read_unchecked(&seq))
27882 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27883
27884 - return atomic64_inc_return(&seq);
27885 + return atomic64_inc_return_unchecked(&seq);
27886 }
27887 EXPORT_SYMBOL_GPL(cper_next_record_id);
27888
27889 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27890 index 7586544..636a2f0 100644
27891 --- a/drivers/acpi/ec_sys.c
27892 +++ b/drivers/acpi/ec_sys.c
27893 @@ -12,6 +12,7 @@
27894 #include <linux/acpi.h>
27895 #include <linux/debugfs.h>
27896 #include <linux/module.h>
27897 +#include <linux/uaccess.h>
27898 #include "internal.h"
27899
27900 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27901 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27902 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27903 */
27904 unsigned int size = EC_SPACE_SIZE;
27905 - u8 *data = (u8 *) buf;
27906 + u8 data;
27907 loff_t init_off = *off;
27908 int err = 0;
27909
27910 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27911 size = count;
27912
27913 while (size) {
27914 - err = ec_read(*off, &data[*off - init_off]);
27915 + err = ec_read(*off, &data);
27916 if (err)
27917 return err;
27918 + if (put_user(data, &buf[*off - init_off]))
27919 + return -EFAULT;
27920 *off += 1;
27921 size--;
27922 }
27923 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27924
27925 unsigned int size = count;
27926 loff_t init_off = *off;
27927 - u8 *data = (u8 *) buf;
27928 int err = 0;
27929
27930 if (*off >= EC_SPACE_SIZE)
27931 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27932 }
27933
27934 while (size) {
27935 - u8 byte_write = data[*off - init_off];
27936 + u8 byte_write;
27937 + if (get_user(byte_write, &buf[*off - init_off]))
27938 + return -EFAULT;
27939 err = ec_write(*off, byte_write);
27940 if (err)
27941 return err;
27942 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27943 index 251c7b62..000462d 100644
27944 --- a/drivers/acpi/proc.c
27945 +++ b/drivers/acpi/proc.c
27946 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27947 size_t count, loff_t * ppos)
27948 {
27949 struct list_head *node, *next;
27950 - char strbuf[5];
27951 - char str[5] = "";
27952 - unsigned int len = count;
27953 + char strbuf[5] = {0};
27954
27955 - if (len > 4)
27956 - len = 4;
27957 - if (len < 0)
27958 + if (count > 4)
27959 + count = 4;
27960 + if (copy_from_user(strbuf, buffer, count))
27961 return -EFAULT;
27962 -
27963 - if (copy_from_user(strbuf, buffer, len))
27964 - return -EFAULT;
27965 - strbuf[len] = '\0';
27966 - sscanf(strbuf, "%s", str);
27967 + strbuf[count] = '\0';
27968
27969 mutex_lock(&acpi_device_lock);
27970 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27971 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27972 if (!dev->wakeup.flags.valid)
27973 continue;
27974
27975 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27976 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27977 if (device_can_wakeup(&dev->dev)) {
27978 bool enable = !device_may_wakeup(&dev->dev);
27979 device_set_wakeup_enable(&dev->dev, enable);
27980 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27981 index bfc31cb..8213ce1 100644
27982 --- a/drivers/acpi/processor_driver.c
27983 +++ b/drivers/acpi/processor_driver.c
27984 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27985 return 0;
27986 #endif
27987
27988 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27989 + BUG_ON(pr->id >= nr_cpu_ids);
27990
27991 /*
27992 * Buggy BIOS check
27993 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27994 index 8e1039c..ea9cbd4 100644
27995 --- a/drivers/ata/libata-core.c
27996 +++ b/drivers/ata/libata-core.c
27997 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27998 struct ata_port *ap;
27999 unsigned int tag;
28000
28001 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28002 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28003 ap = qc->ap;
28004
28005 qc->flags = 0;
28006 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28007 struct ata_port *ap;
28008 struct ata_link *link;
28009
28010 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28011 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28012 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28013 ap = qc->ap;
28014 link = qc->dev->link;
28015 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28016 return;
28017
28018 spin_lock(&lock);
28019 + pax_open_kernel();
28020
28021 for (cur = ops->inherits; cur; cur = cur->inherits) {
28022 void **inherit = (void **)cur;
28023 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28024 if (IS_ERR(*pp))
28025 *pp = NULL;
28026
28027 - ops->inherits = NULL;
28028 + *(struct ata_port_operations **)&ops->inherits = NULL;
28029
28030 + pax_close_kernel();
28031 spin_unlock(&lock);
28032 }
28033
28034 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28035 index bfaa5cb..3ba1cc3 100644
28036 --- a/drivers/ata/pata_arasan_cf.c
28037 +++ b/drivers/ata/pata_arasan_cf.c
28038 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28039 /* Handle platform specific quirks */
28040 if (pdata->quirk) {
28041 if (pdata->quirk & CF_BROKEN_PIO) {
28042 - ap->ops->set_piomode = NULL;
28043 + pax_open_kernel();
28044 + *(void **)&ap->ops->set_piomode = NULL;
28045 + pax_close_kernel();
28046 ap->pio_mask = 0;
28047 }
28048 if (pdata->quirk & CF_BROKEN_MWDMA)
28049 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28050 index f9b983a..887b9d8 100644
28051 --- a/drivers/atm/adummy.c
28052 +++ b/drivers/atm/adummy.c
28053 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28054 vcc->pop(vcc, skb);
28055 else
28056 dev_kfree_skb_any(skb);
28057 - atomic_inc(&vcc->stats->tx);
28058 + atomic_inc_unchecked(&vcc->stats->tx);
28059
28060 return 0;
28061 }
28062 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28063 index 89b30f3..7964211 100644
28064 --- a/drivers/atm/ambassador.c
28065 +++ b/drivers/atm/ambassador.c
28066 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28067 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28068
28069 // VC layer stats
28070 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28071 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28072
28073 // free the descriptor
28074 kfree (tx_descr);
28075 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28076 dump_skb ("<<<", vc, skb);
28077
28078 // VC layer stats
28079 - atomic_inc(&atm_vcc->stats->rx);
28080 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28081 __net_timestamp(skb);
28082 // end of our responsibility
28083 atm_vcc->push (atm_vcc, skb);
28084 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28085 } else {
28086 PRINTK (KERN_INFO, "dropped over-size frame");
28087 // should we count this?
28088 - atomic_inc(&atm_vcc->stats->rx_drop);
28089 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28090 }
28091
28092 } else {
28093 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28094 }
28095
28096 if (check_area (skb->data, skb->len)) {
28097 - atomic_inc(&atm_vcc->stats->tx_err);
28098 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28099 return -ENOMEM; // ?
28100 }
28101
28102 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28103 index b22d71c..d6e1049 100644
28104 --- a/drivers/atm/atmtcp.c
28105 +++ b/drivers/atm/atmtcp.c
28106 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28107 if (vcc->pop) vcc->pop(vcc,skb);
28108 else dev_kfree_skb(skb);
28109 if (dev_data) return 0;
28110 - atomic_inc(&vcc->stats->tx_err);
28111 + atomic_inc_unchecked(&vcc->stats->tx_err);
28112 return -ENOLINK;
28113 }
28114 size = skb->len+sizeof(struct atmtcp_hdr);
28115 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28116 if (!new_skb) {
28117 if (vcc->pop) vcc->pop(vcc,skb);
28118 else dev_kfree_skb(skb);
28119 - atomic_inc(&vcc->stats->tx_err);
28120 + atomic_inc_unchecked(&vcc->stats->tx_err);
28121 return -ENOBUFS;
28122 }
28123 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28124 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28125 if (vcc->pop) vcc->pop(vcc,skb);
28126 else dev_kfree_skb(skb);
28127 out_vcc->push(out_vcc,new_skb);
28128 - atomic_inc(&vcc->stats->tx);
28129 - atomic_inc(&out_vcc->stats->rx);
28130 + atomic_inc_unchecked(&vcc->stats->tx);
28131 + atomic_inc_unchecked(&out_vcc->stats->rx);
28132 return 0;
28133 }
28134
28135 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28136 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28137 read_unlock(&vcc_sklist_lock);
28138 if (!out_vcc) {
28139 - atomic_inc(&vcc->stats->tx_err);
28140 + atomic_inc_unchecked(&vcc->stats->tx_err);
28141 goto done;
28142 }
28143 skb_pull(skb,sizeof(struct atmtcp_hdr));
28144 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28145 __net_timestamp(new_skb);
28146 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28147 out_vcc->push(out_vcc,new_skb);
28148 - atomic_inc(&vcc->stats->tx);
28149 - atomic_inc(&out_vcc->stats->rx);
28150 + atomic_inc_unchecked(&vcc->stats->tx);
28151 + atomic_inc_unchecked(&out_vcc->stats->rx);
28152 done:
28153 if (vcc->pop) vcc->pop(vcc,skb);
28154 else dev_kfree_skb(skb);
28155 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28156 index 2059ee4..faf51c7 100644
28157 --- a/drivers/atm/eni.c
28158 +++ b/drivers/atm/eni.c
28159 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28160 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28161 vcc->dev->number);
28162 length = 0;
28163 - atomic_inc(&vcc->stats->rx_err);
28164 + atomic_inc_unchecked(&vcc->stats->rx_err);
28165 }
28166 else {
28167 length = ATM_CELL_SIZE-1; /* no HEC */
28168 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28169 size);
28170 }
28171 eff = length = 0;
28172 - atomic_inc(&vcc->stats->rx_err);
28173 + atomic_inc_unchecked(&vcc->stats->rx_err);
28174 }
28175 else {
28176 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28177 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28178 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28179 vcc->dev->number,vcc->vci,length,size << 2,descr);
28180 length = eff = 0;
28181 - atomic_inc(&vcc->stats->rx_err);
28182 + atomic_inc_unchecked(&vcc->stats->rx_err);
28183 }
28184 }
28185 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28186 @@ -767,7 +767,7 @@ rx_dequeued++;
28187 vcc->push(vcc,skb);
28188 pushed++;
28189 }
28190 - atomic_inc(&vcc->stats->rx);
28191 + atomic_inc_unchecked(&vcc->stats->rx);
28192 }
28193 wake_up(&eni_dev->rx_wait);
28194 }
28195 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28196 PCI_DMA_TODEVICE);
28197 if (vcc->pop) vcc->pop(vcc,skb);
28198 else dev_kfree_skb_irq(skb);
28199 - atomic_inc(&vcc->stats->tx);
28200 + atomic_inc_unchecked(&vcc->stats->tx);
28201 wake_up(&eni_dev->tx_wait);
28202 dma_complete++;
28203 }
28204 @@ -1567,7 +1567,7 @@ tx_complete++;
28205 /*--------------------------------- entries ---------------------------------*/
28206
28207
28208 -static const char *media_name[] __devinitdata = {
28209 +static const char *media_name[] __devinitconst = {
28210 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28211 "UTP", "05?", "06?", "07?", /* 4- 7 */
28212 "TAXI","09?", "10?", "11?", /* 8-11 */
28213 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28214 index 86fed1b..6dc4721 100644
28215 --- a/drivers/atm/firestream.c
28216 +++ b/drivers/atm/firestream.c
28217 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28218 }
28219 }
28220
28221 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28222 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28223
28224 fs_dprintk (FS_DEBUG_TXMEM, "i");
28225 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28226 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28227 #endif
28228 skb_put (skb, qe->p1 & 0xffff);
28229 ATM_SKB(skb)->vcc = atm_vcc;
28230 - atomic_inc(&atm_vcc->stats->rx);
28231 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28232 __net_timestamp(skb);
28233 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28234 atm_vcc->push (atm_vcc, skb);
28235 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28236 kfree (pe);
28237 }
28238 if (atm_vcc)
28239 - atomic_inc(&atm_vcc->stats->rx_drop);
28240 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28241 break;
28242 case 0x1f: /* Reassembly abort: no buffers. */
28243 /* Silently increment error counter. */
28244 if (atm_vcc)
28245 - atomic_inc(&atm_vcc->stats->rx_drop);
28246 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28247 break;
28248 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28249 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28250 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28251 index 361f5ae..7fc552d 100644
28252 --- a/drivers/atm/fore200e.c
28253 +++ b/drivers/atm/fore200e.c
28254 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28255 #endif
28256 /* check error condition */
28257 if (*entry->status & STATUS_ERROR)
28258 - atomic_inc(&vcc->stats->tx_err);
28259 + atomic_inc_unchecked(&vcc->stats->tx_err);
28260 else
28261 - atomic_inc(&vcc->stats->tx);
28262 + atomic_inc_unchecked(&vcc->stats->tx);
28263 }
28264 }
28265
28266 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28267 if (skb == NULL) {
28268 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28269
28270 - atomic_inc(&vcc->stats->rx_drop);
28271 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28272 return -ENOMEM;
28273 }
28274
28275 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28276
28277 dev_kfree_skb_any(skb);
28278
28279 - atomic_inc(&vcc->stats->rx_drop);
28280 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28281 return -ENOMEM;
28282 }
28283
28284 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28285
28286 vcc->push(vcc, skb);
28287 - atomic_inc(&vcc->stats->rx);
28288 + atomic_inc_unchecked(&vcc->stats->rx);
28289
28290 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28291
28292 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28293 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28294 fore200e->atm_dev->number,
28295 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28296 - atomic_inc(&vcc->stats->rx_err);
28297 + atomic_inc_unchecked(&vcc->stats->rx_err);
28298 }
28299 }
28300
28301 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28302 goto retry_here;
28303 }
28304
28305 - atomic_inc(&vcc->stats->tx_err);
28306 + atomic_inc_unchecked(&vcc->stats->tx_err);
28307
28308 fore200e->tx_sat++;
28309 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28310 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28311 index b182c2f..1c6fa8a 100644
28312 --- a/drivers/atm/he.c
28313 +++ b/drivers/atm/he.c
28314 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28315
28316 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28317 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28318 - atomic_inc(&vcc->stats->rx_drop);
28319 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28320 goto return_host_buffers;
28321 }
28322
28323 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28324 RBRQ_LEN_ERR(he_dev->rbrq_head)
28325 ? "LEN_ERR" : "",
28326 vcc->vpi, vcc->vci);
28327 - atomic_inc(&vcc->stats->rx_err);
28328 + atomic_inc_unchecked(&vcc->stats->rx_err);
28329 goto return_host_buffers;
28330 }
28331
28332 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28333 vcc->push(vcc, skb);
28334 spin_lock(&he_dev->global_lock);
28335
28336 - atomic_inc(&vcc->stats->rx);
28337 + atomic_inc_unchecked(&vcc->stats->rx);
28338
28339 return_host_buffers:
28340 ++pdus_assembled;
28341 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28342 tpd->vcc->pop(tpd->vcc, tpd->skb);
28343 else
28344 dev_kfree_skb_any(tpd->skb);
28345 - atomic_inc(&tpd->vcc->stats->tx_err);
28346 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28347 }
28348 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28349 return;
28350 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28351 vcc->pop(vcc, skb);
28352 else
28353 dev_kfree_skb_any(skb);
28354 - atomic_inc(&vcc->stats->tx_err);
28355 + atomic_inc_unchecked(&vcc->stats->tx_err);
28356 return -EINVAL;
28357 }
28358
28359 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28360 vcc->pop(vcc, skb);
28361 else
28362 dev_kfree_skb_any(skb);
28363 - atomic_inc(&vcc->stats->tx_err);
28364 + atomic_inc_unchecked(&vcc->stats->tx_err);
28365 return -EINVAL;
28366 }
28367 #endif
28368 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28369 vcc->pop(vcc, skb);
28370 else
28371 dev_kfree_skb_any(skb);
28372 - atomic_inc(&vcc->stats->tx_err);
28373 + atomic_inc_unchecked(&vcc->stats->tx_err);
28374 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28375 return -ENOMEM;
28376 }
28377 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28378 vcc->pop(vcc, skb);
28379 else
28380 dev_kfree_skb_any(skb);
28381 - atomic_inc(&vcc->stats->tx_err);
28382 + atomic_inc_unchecked(&vcc->stats->tx_err);
28383 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28384 return -ENOMEM;
28385 }
28386 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28387 __enqueue_tpd(he_dev, tpd, cid);
28388 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28389
28390 - atomic_inc(&vcc->stats->tx);
28391 + atomic_inc_unchecked(&vcc->stats->tx);
28392
28393 return 0;
28394 }
28395 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28396 index 7d01c2a..4e3ac01 100644
28397 --- a/drivers/atm/horizon.c
28398 +++ b/drivers/atm/horizon.c
28399 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28400 {
28401 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28402 // VC layer stats
28403 - atomic_inc(&vcc->stats->rx);
28404 + atomic_inc_unchecked(&vcc->stats->rx);
28405 __net_timestamp(skb);
28406 // end of our responsibility
28407 vcc->push (vcc, skb);
28408 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28409 dev->tx_iovec = NULL;
28410
28411 // VC layer stats
28412 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28413 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28414
28415 // free the skb
28416 hrz_kfree_skb (skb);
28417 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28418 index 8974bd2..b856f85 100644
28419 --- a/drivers/atm/idt77252.c
28420 +++ b/drivers/atm/idt77252.c
28421 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28422 else
28423 dev_kfree_skb(skb);
28424
28425 - atomic_inc(&vcc->stats->tx);
28426 + atomic_inc_unchecked(&vcc->stats->tx);
28427 }
28428
28429 atomic_dec(&scq->used);
28430 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28431 if ((sb = dev_alloc_skb(64)) == NULL) {
28432 printk("%s: Can't allocate buffers for aal0.\n",
28433 card->name);
28434 - atomic_add(i, &vcc->stats->rx_drop);
28435 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28436 break;
28437 }
28438 if (!atm_charge(vcc, sb->truesize)) {
28439 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28440 card->name);
28441 - atomic_add(i - 1, &vcc->stats->rx_drop);
28442 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28443 dev_kfree_skb(sb);
28444 break;
28445 }
28446 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28447 ATM_SKB(sb)->vcc = vcc;
28448 __net_timestamp(sb);
28449 vcc->push(vcc, sb);
28450 - atomic_inc(&vcc->stats->rx);
28451 + atomic_inc_unchecked(&vcc->stats->rx);
28452
28453 cell += ATM_CELL_PAYLOAD;
28454 }
28455 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28456 "(CDC: %08x)\n",
28457 card->name, len, rpp->len, readl(SAR_REG_CDC));
28458 recycle_rx_pool_skb(card, rpp);
28459 - atomic_inc(&vcc->stats->rx_err);
28460 + atomic_inc_unchecked(&vcc->stats->rx_err);
28461 return;
28462 }
28463 if (stat & SAR_RSQE_CRC) {
28464 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28465 recycle_rx_pool_skb(card, rpp);
28466 - atomic_inc(&vcc->stats->rx_err);
28467 + atomic_inc_unchecked(&vcc->stats->rx_err);
28468 return;
28469 }
28470 if (skb_queue_len(&rpp->queue) > 1) {
28471 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28472 RXPRINTK("%s: Can't alloc RX skb.\n",
28473 card->name);
28474 recycle_rx_pool_skb(card, rpp);
28475 - atomic_inc(&vcc->stats->rx_err);
28476 + atomic_inc_unchecked(&vcc->stats->rx_err);
28477 return;
28478 }
28479 if (!atm_charge(vcc, skb->truesize)) {
28480 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28481 __net_timestamp(skb);
28482
28483 vcc->push(vcc, skb);
28484 - atomic_inc(&vcc->stats->rx);
28485 + atomic_inc_unchecked(&vcc->stats->rx);
28486
28487 return;
28488 }
28489 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28490 __net_timestamp(skb);
28491
28492 vcc->push(vcc, skb);
28493 - atomic_inc(&vcc->stats->rx);
28494 + atomic_inc_unchecked(&vcc->stats->rx);
28495
28496 if (skb->truesize > SAR_FB_SIZE_3)
28497 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28498 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28499 if (vcc->qos.aal != ATM_AAL0) {
28500 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28501 card->name, vpi, vci);
28502 - atomic_inc(&vcc->stats->rx_drop);
28503 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28504 goto drop;
28505 }
28506
28507 if ((sb = dev_alloc_skb(64)) == NULL) {
28508 printk("%s: Can't allocate buffers for AAL0.\n",
28509 card->name);
28510 - atomic_inc(&vcc->stats->rx_err);
28511 + atomic_inc_unchecked(&vcc->stats->rx_err);
28512 goto drop;
28513 }
28514
28515 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28516 ATM_SKB(sb)->vcc = vcc;
28517 __net_timestamp(sb);
28518 vcc->push(vcc, sb);
28519 - atomic_inc(&vcc->stats->rx);
28520 + atomic_inc_unchecked(&vcc->stats->rx);
28521
28522 drop:
28523 skb_pull(queue, 64);
28524 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28525
28526 if (vc == NULL) {
28527 printk("%s: NULL connection in send().\n", card->name);
28528 - atomic_inc(&vcc->stats->tx_err);
28529 + atomic_inc_unchecked(&vcc->stats->tx_err);
28530 dev_kfree_skb(skb);
28531 return -EINVAL;
28532 }
28533 if (!test_bit(VCF_TX, &vc->flags)) {
28534 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28535 - atomic_inc(&vcc->stats->tx_err);
28536 + atomic_inc_unchecked(&vcc->stats->tx_err);
28537 dev_kfree_skb(skb);
28538 return -EINVAL;
28539 }
28540 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28541 break;
28542 default:
28543 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28544 - atomic_inc(&vcc->stats->tx_err);
28545 + atomic_inc_unchecked(&vcc->stats->tx_err);
28546 dev_kfree_skb(skb);
28547 return -EINVAL;
28548 }
28549
28550 if (skb_shinfo(skb)->nr_frags != 0) {
28551 printk("%s: No scatter-gather yet.\n", card->name);
28552 - atomic_inc(&vcc->stats->tx_err);
28553 + atomic_inc_unchecked(&vcc->stats->tx_err);
28554 dev_kfree_skb(skb);
28555 return -EINVAL;
28556 }
28557 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28558
28559 err = queue_skb(card, vc, skb, oam);
28560 if (err) {
28561 - atomic_inc(&vcc->stats->tx_err);
28562 + atomic_inc_unchecked(&vcc->stats->tx_err);
28563 dev_kfree_skb(skb);
28564 return err;
28565 }
28566 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28567 skb = dev_alloc_skb(64);
28568 if (!skb) {
28569 printk("%s: Out of memory in send_oam().\n", card->name);
28570 - atomic_inc(&vcc->stats->tx_err);
28571 + atomic_inc_unchecked(&vcc->stats->tx_err);
28572 return -ENOMEM;
28573 }
28574 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28575 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28576 index 96cce6d..62c3ec5 100644
28577 --- a/drivers/atm/iphase.c
28578 +++ b/drivers/atm/iphase.c
28579 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28580 status = (u_short) (buf_desc_ptr->desc_mode);
28581 if (status & (RX_CER | RX_PTE | RX_OFL))
28582 {
28583 - atomic_inc(&vcc->stats->rx_err);
28584 + atomic_inc_unchecked(&vcc->stats->rx_err);
28585 IF_ERR(printk("IA: bad packet, dropping it");)
28586 if (status & RX_CER) {
28587 IF_ERR(printk(" cause: packet CRC error\n");)
28588 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28589 len = dma_addr - buf_addr;
28590 if (len > iadev->rx_buf_sz) {
28591 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28592 - atomic_inc(&vcc->stats->rx_err);
28593 + atomic_inc_unchecked(&vcc->stats->rx_err);
28594 goto out_free_desc;
28595 }
28596
28597 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28598 ia_vcc = INPH_IA_VCC(vcc);
28599 if (ia_vcc == NULL)
28600 {
28601 - atomic_inc(&vcc->stats->rx_err);
28602 + atomic_inc_unchecked(&vcc->stats->rx_err);
28603 atm_return(vcc, skb->truesize);
28604 dev_kfree_skb_any(skb);
28605 goto INCR_DLE;
28606 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28607 if ((length > iadev->rx_buf_sz) || (length >
28608 (skb->len - sizeof(struct cpcs_trailer))))
28609 {
28610 - atomic_inc(&vcc->stats->rx_err);
28611 + atomic_inc_unchecked(&vcc->stats->rx_err);
28612 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28613 length, skb->len);)
28614 atm_return(vcc, skb->truesize);
28615 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28616
28617 IF_RX(printk("rx_dle_intr: skb push");)
28618 vcc->push(vcc,skb);
28619 - atomic_inc(&vcc->stats->rx);
28620 + atomic_inc_unchecked(&vcc->stats->rx);
28621 iadev->rx_pkt_cnt++;
28622 }
28623 INCR_DLE:
28624 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28625 {
28626 struct k_sonet_stats *stats;
28627 stats = &PRIV(_ia_dev[board])->sonet_stats;
28628 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28629 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28630 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28631 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28632 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28633 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28634 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28635 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28636 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28637 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28638 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28639 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28640 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28641 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28642 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28643 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28644 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28645 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28646 }
28647 ia_cmds.status = 0;
28648 break;
28649 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28650 if ((desc == 0) || (desc > iadev->num_tx_desc))
28651 {
28652 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28653 - atomic_inc(&vcc->stats->tx);
28654 + atomic_inc_unchecked(&vcc->stats->tx);
28655 if (vcc->pop)
28656 vcc->pop(vcc, skb);
28657 else
28658 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28659 ATM_DESC(skb) = vcc->vci;
28660 skb_queue_tail(&iadev->tx_dma_q, skb);
28661
28662 - atomic_inc(&vcc->stats->tx);
28663 + atomic_inc_unchecked(&vcc->stats->tx);
28664 iadev->tx_pkt_cnt++;
28665 /* Increment transaction counter */
28666 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28667
28668 #if 0
28669 /* add flow control logic */
28670 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28671 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28672 if (iavcc->vc_desc_cnt > 10) {
28673 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28674 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28675 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28676 index 68c7588..7036683 100644
28677 --- a/drivers/atm/lanai.c
28678 +++ b/drivers/atm/lanai.c
28679 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28680 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28681 lanai_endtx(lanai, lvcc);
28682 lanai_free_skb(lvcc->tx.atmvcc, skb);
28683 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28684 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28685 }
28686
28687 /* Try to fill the buffer - don't call unless there is backlog */
28688 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28689 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28690 __net_timestamp(skb);
28691 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28692 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28693 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28694 out:
28695 lvcc->rx.buf.ptr = end;
28696 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28697 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28698 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28699 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28700 lanai->stats.service_rxnotaal5++;
28701 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28702 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28703 return 0;
28704 }
28705 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28706 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28707 int bytes;
28708 read_unlock(&vcc_sklist_lock);
28709 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28710 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28711 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28712 lvcc->stats.x.aal5.service_trash++;
28713 bytes = (SERVICE_GET_END(s) * 16) -
28714 (((unsigned long) lvcc->rx.buf.ptr) -
28715 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28716 }
28717 if (s & SERVICE_STREAM) {
28718 read_unlock(&vcc_sklist_lock);
28719 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28720 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28721 lvcc->stats.x.aal5.service_stream++;
28722 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28723 "PDU on VCI %d!\n", lanai->number, vci);
28724 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28725 return 0;
28726 }
28727 DPRINTK("got rx crc error on vci %d\n", vci);
28728 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28729 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28730 lvcc->stats.x.aal5.service_rxcrc++;
28731 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28732 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28733 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28734 index 1c70c45..300718d 100644
28735 --- a/drivers/atm/nicstar.c
28736 +++ b/drivers/atm/nicstar.c
28737 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28738 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28739 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28740 card->index);
28741 - atomic_inc(&vcc->stats->tx_err);
28742 + atomic_inc_unchecked(&vcc->stats->tx_err);
28743 dev_kfree_skb_any(skb);
28744 return -EINVAL;
28745 }
28746 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28747 if (!vc->tx) {
28748 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28749 card->index);
28750 - atomic_inc(&vcc->stats->tx_err);
28751 + atomic_inc_unchecked(&vcc->stats->tx_err);
28752 dev_kfree_skb_any(skb);
28753 return -EINVAL;
28754 }
28755 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28756 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28757 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28758 card->index);
28759 - atomic_inc(&vcc->stats->tx_err);
28760 + atomic_inc_unchecked(&vcc->stats->tx_err);
28761 dev_kfree_skb_any(skb);
28762 return -EINVAL;
28763 }
28764
28765 if (skb_shinfo(skb)->nr_frags != 0) {
28766 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28767 - atomic_inc(&vcc->stats->tx_err);
28768 + atomic_inc_unchecked(&vcc->stats->tx_err);
28769 dev_kfree_skb_any(skb);
28770 return -EINVAL;
28771 }
28772 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28773 }
28774
28775 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28776 - atomic_inc(&vcc->stats->tx_err);
28777 + atomic_inc_unchecked(&vcc->stats->tx_err);
28778 dev_kfree_skb_any(skb);
28779 return -EIO;
28780 }
28781 - atomic_inc(&vcc->stats->tx);
28782 + atomic_inc_unchecked(&vcc->stats->tx);
28783
28784 return 0;
28785 }
28786 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28787 printk
28788 ("nicstar%d: Can't allocate buffers for aal0.\n",
28789 card->index);
28790 - atomic_add(i, &vcc->stats->rx_drop);
28791 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28792 break;
28793 }
28794 if (!atm_charge(vcc, sb->truesize)) {
28795 RXPRINTK
28796 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28797 card->index);
28798 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28799 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28800 dev_kfree_skb_any(sb);
28801 break;
28802 }
28803 @@ -2068,7 +2068,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 cell += ATM_CELL_PAYLOAD;
28810 }
28811
28812 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813 if (iovb == NULL) {
28814 printk("nicstar%d: Out of iovec buffers.\n",
28815 card->index);
28816 - atomic_inc(&vcc->stats->rx_drop);
28817 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28818 recycle_rx_buf(card, skb);
28819 return;
28820 }
28821 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 small or large buffer itself. */
28823 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28824 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28825 - atomic_inc(&vcc->stats->rx_err);
28826 + atomic_inc_unchecked(&vcc->stats->rx_err);
28827 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28828 NS_MAX_IOVECS);
28829 NS_PRV_IOVCNT(iovb) = 0;
28830 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28832 card->index);
28833 which_list(card, skb);
28834 - atomic_inc(&vcc->stats->rx_err);
28835 + atomic_inc_unchecked(&vcc->stats->rx_err);
28836 recycle_rx_buf(card, skb);
28837 vc->rx_iov = NULL;
28838 recycle_iov_buf(card, iovb);
28839 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28841 card->index);
28842 which_list(card, skb);
28843 - atomic_inc(&vcc->stats->rx_err);
28844 + atomic_inc_unchecked(&vcc->stats->rx_err);
28845 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28846 NS_PRV_IOVCNT(iovb));
28847 vc->rx_iov = NULL;
28848 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28849 printk(" - PDU size mismatch.\n");
28850 else
28851 printk(".\n");
28852 - atomic_inc(&vcc->stats->rx_err);
28853 + atomic_inc_unchecked(&vcc->stats->rx_err);
28854 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28855 NS_PRV_IOVCNT(iovb));
28856 vc->rx_iov = NULL;
28857 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28858 /* skb points to a small buffer */
28859 if (!atm_charge(vcc, skb->truesize)) {
28860 push_rxbufs(card, skb);
28861 - atomic_inc(&vcc->stats->rx_drop);
28862 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28863 } else {
28864 skb_put(skb, len);
28865 dequeue_sm_buf(card, skb);
28866 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28867 ATM_SKB(skb)->vcc = vcc;
28868 __net_timestamp(skb);
28869 vcc->push(vcc, skb);
28870 - atomic_inc(&vcc->stats->rx);
28871 + atomic_inc_unchecked(&vcc->stats->rx);
28872 }
28873 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28874 struct sk_buff *sb;
28875 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28876 if (len <= NS_SMBUFSIZE) {
28877 if (!atm_charge(vcc, sb->truesize)) {
28878 push_rxbufs(card, sb);
28879 - atomic_inc(&vcc->stats->rx_drop);
28880 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28881 } else {
28882 skb_put(sb, len);
28883 dequeue_sm_buf(card, sb);
28884 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28885 ATM_SKB(sb)->vcc = vcc;
28886 __net_timestamp(sb);
28887 vcc->push(vcc, sb);
28888 - atomic_inc(&vcc->stats->rx);
28889 + atomic_inc_unchecked(&vcc->stats->rx);
28890 }
28891
28892 push_rxbufs(card, skb);
28893 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28894
28895 if (!atm_charge(vcc, skb->truesize)) {
28896 push_rxbufs(card, skb);
28897 - atomic_inc(&vcc->stats->rx_drop);
28898 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28899 } else {
28900 dequeue_lg_buf(card, skb);
28901 #ifdef NS_USE_DESTRUCTORS
28902 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28903 ATM_SKB(skb)->vcc = vcc;
28904 __net_timestamp(skb);
28905 vcc->push(vcc, skb);
28906 - atomic_inc(&vcc->stats->rx);
28907 + atomic_inc_unchecked(&vcc->stats->rx);
28908 }
28909
28910 push_rxbufs(card, sb);
28911 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28912 printk
28913 ("nicstar%d: Out of huge buffers.\n",
28914 card->index);
28915 - atomic_inc(&vcc->stats->rx_drop);
28916 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28917 recycle_iovec_rx_bufs(card,
28918 (struct iovec *)
28919 iovb->data,
28920 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28921 card->hbpool.count++;
28922 } else
28923 dev_kfree_skb_any(hb);
28924 - atomic_inc(&vcc->stats->rx_drop);
28925 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28926 } else {
28927 /* Copy the small buffer to the huge buffer */
28928 sb = (struct sk_buff *)iov->iov_base;
28929 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28930 #endif /* NS_USE_DESTRUCTORS */
28931 __net_timestamp(hb);
28932 vcc->push(vcc, hb);
28933 - atomic_inc(&vcc->stats->rx);
28934 + atomic_inc_unchecked(&vcc->stats->rx);
28935 }
28936 }
28937
28938 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28939 index 9851093..adb2b1e 100644
28940 --- a/drivers/atm/solos-pci.c
28941 +++ b/drivers/atm/solos-pci.c
28942 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28943 }
28944 atm_charge(vcc, skb->truesize);
28945 vcc->push(vcc, skb);
28946 - atomic_inc(&vcc->stats->rx);
28947 + atomic_inc_unchecked(&vcc->stats->rx);
28948 break;
28949
28950 case PKT_STATUS:
28951 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28952 vcc = SKB_CB(oldskb)->vcc;
28953
28954 if (vcc) {
28955 - atomic_inc(&vcc->stats->tx);
28956 + atomic_inc_unchecked(&vcc->stats->tx);
28957 solos_pop(vcc, oldskb);
28958 } else
28959 dev_kfree_skb_irq(oldskb);
28960 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28961 index 0215934..ce9f5b1 100644
28962 --- a/drivers/atm/suni.c
28963 +++ b/drivers/atm/suni.c
28964 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28965
28966
28967 #define ADD_LIMITED(s,v) \
28968 - atomic_add((v),&stats->s); \
28969 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28970 + atomic_add_unchecked((v),&stats->s); \
28971 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28972
28973
28974 static void suni_hz(unsigned long from_timer)
28975 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28976 index 5120a96..e2572bd 100644
28977 --- a/drivers/atm/uPD98402.c
28978 +++ b/drivers/atm/uPD98402.c
28979 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28980 struct sonet_stats tmp;
28981 int error = 0;
28982
28983 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28984 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28985 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28986 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28987 if (zero && !error) {
28988 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28989
28990
28991 #define ADD_LIMITED(s,v) \
28992 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28993 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28994 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28995 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28996 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28997 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28998
28999
29000 static void stat_event(struct atm_dev *dev)
29001 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29002 if (reason & uPD98402_INT_PFM) stat_event(dev);
29003 if (reason & uPD98402_INT_PCO) {
29004 (void) GET(PCOCR); /* clear interrupt cause */
29005 - atomic_add(GET(HECCT),
29006 + atomic_add_unchecked(GET(HECCT),
29007 &PRIV(dev)->sonet_stats.uncorr_hcs);
29008 }
29009 if ((reason & uPD98402_INT_RFO) &&
29010 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29011 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29012 uPD98402_INT_LOS),PIMR); /* enable them */
29013 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29014 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29015 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29016 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29017 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29018 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29019 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29020 return 0;
29021 }
29022
29023 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29024 index abe4e20..83c4727 100644
29025 --- a/drivers/atm/zatm.c
29026 +++ b/drivers/atm/zatm.c
29027 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29028 }
29029 if (!size) {
29030 dev_kfree_skb_irq(skb);
29031 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29032 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29033 continue;
29034 }
29035 if (!atm_charge(vcc,skb->truesize)) {
29036 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29037 skb->len = size;
29038 ATM_SKB(skb)->vcc = vcc;
29039 vcc->push(vcc,skb);
29040 - atomic_inc(&vcc->stats->rx);
29041 + atomic_inc_unchecked(&vcc->stats->rx);
29042 }
29043 zout(pos & 0xffff,MTA(mbx));
29044 #if 0 /* probably a stupid idea */
29045 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29046 skb_queue_head(&zatm_vcc->backlog,skb);
29047 break;
29048 }
29049 - atomic_inc(&vcc->stats->tx);
29050 + atomic_inc_unchecked(&vcc->stats->tx);
29051 wake_up(&zatm_vcc->tx_wait);
29052 }
29053
29054 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29055 index deb4a45..211eff2 100644
29056 --- a/drivers/base/devtmpfs.c
29057 +++ b/drivers/base/devtmpfs.c
29058 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29059 if (!thread)
29060 return 0;
29061
29062 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29063 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29064 if (err)
29065 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29066 else
29067 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29068 index cbb463b..babe2cf 100644
29069 --- a/drivers/base/power/wakeup.c
29070 +++ b/drivers/base/power/wakeup.c
29071 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29072 * They need to be modified together atomically, so it's better to use one
29073 * atomic variable to hold them both.
29074 */
29075 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29076 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29077
29078 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29079 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29080
29081 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29082 {
29083 - unsigned int comb = atomic_read(&combined_event_count);
29084 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29085
29086 *cnt = (comb >> IN_PROGRESS_BITS);
29087 *inpr = comb & MAX_IN_PROGRESS;
29088 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29089 ws->start_prevent_time = ws->last_time;
29090
29091 /* Increment the counter of events in progress. */
29092 - cec = atomic_inc_return(&combined_event_count);
29093 + cec = atomic_inc_return_unchecked(&combined_event_count);
29094
29095 trace_wakeup_source_activate(ws->name, cec);
29096 }
29097 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29098 * Increment the counter of registered wakeup events and decrement the
29099 * couter of wakeup events in progress simultaneously.
29100 */
29101 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29102 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29103 trace_wakeup_source_deactivate(ws->name, cec);
29104
29105 split_counters(&cnt, &inpr);
29106 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29107 index b0f553b..77b928b 100644
29108 --- a/drivers/block/cciss.c
29109 +++ b/drivers/block/cciss.c
29110 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29111 int err;
29112 u32 cp;
29113
29114 + memset(&arg64, 0, sizeof(arg64));
29115 +
29116 err = 0;
29117 err |=
29118 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29119 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29120 while (!list_empty(&h->reqQ)) {
29121 c = list_entry(h->reqQ.next, CommandList_struct, list);
29122 /* can't do anything if fifo is full */
29123 - if ((h->access.fifo_full(h))) {
29124 + if ((h->access->fifo_full(h))) {
29125 dev_warn(&h->pdev->dev, "fifo full\n");
29126 break;
29127 }
29128 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29129 h->Qdepth--;
29130
29131 /* Tell the controller execute command */
29132 - h->access.submit_command(h, c);
29133 + h->access->submit_command(h, c);
29134
29135 /* Put job onto the completed Q */
29136 addQ(&h->cmpQ, c);
29137 @@ -3443,17 +3445,17 @@ startio:
29138
29139 static inline unsigned long get_next_completion(ctlr_info_t *h)
29140 {
29141 - return h->access.command_completed(h);
29142 + return h->access->command_completed(h);
29143 }
29144
29145 static inline int interrupt_pending(ctlr_info_t *h)
29146 {
29147 - return h->access.intr_pending(h);
29148 + return h->access->intr_pending(h);
29149 }
29150
29151 static inline long interrupt_not_for_us(ctlr_info_t *h)
29152 {
29153 - return ((h->access.intr_pending(h) == 0) ||
29154 + return ((h->access->intr_pending(h) == 0) ||
29155 (h->interrupts_enabled == 0));
29156 }
29157
29158 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29159 u32 a;
29160
29161 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29162 - return h->access.command_completed(h);
29163 + return h->access->command_completed(h);
29164
29165 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29166 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29167 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29168 trans_support & CFGTBL_Trans_use_short_tags);
29169
29170 /* Change the access methods to the performant access methods */
29171 - h->access = SA5_performant_access;
29172 + h->access = &SA5_performant_access;
29173 h->transMethod = CFGTBL_Trans_Performant;
29174
29175 return;
29176 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29177 if (prod_index < 0)
29178 return -ENODEV;
29179 h->product_name = products[prod_index].product_name;
29180 - h->access = *(products[prod_index].access);
29181 + h->access = products[prod_index].access;
29182
29183 if (cciss_board_disabled(h)) {
29184 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29185 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29186 }
29187
29188 /* make sure the board interrupts are off */
29189 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29190 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29191 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29192 if (rc)
29193 goto clean2;
29194 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29195 * fake ones to scoop up any residual completions.
29196 */
29197 spin_lock_irqsave(&h->lock, flags);
29198 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29199 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29200 spin_unlock_irqrestore(&h->lock, flags);
29201 free_irq(h->intr[h->intr_mode], h);
29202 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29203 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29204 dev_info(&h->pdev->dev, "Board READY.\n");
29205 dev_info(&h->pdev->dev,
29206 "Waiting for stale completions to drain.\n");
29207 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29208 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29209 msleep(10000);
29210 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29211 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29212
29213 rc = controller_reset_failed(h->cfgtable);
29214 if (rc)
29215 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29216 cciss_scsi_setup(h);
29217
29218 /* Turn the interrupts on so we can service requests */
29219 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29220 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29221
29222 /* Get the firmware version */
29223 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29224 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29225 kfree(flush_buf);
29226 if (return_code != IO_OK)
29227 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29228 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29229 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29230 free_irq(h->intr[h->intr_mode], h);
29231 }
29232
29233 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29234 index 7fda30e..eb5dfe0 100644
29235 --- a/drivers/block/cciss.h
29236 +++ b/drivers/block/cciss.h
29237 @@ -101,7 +101,7 @@ struct ctlr_info
29238 /* information about each logical volume */
29239 drive_info_struct *drv[CISS_MAX_LUN];
29240
29241 - struct access_method access;
29242 + struct access_method *access;
29243
29244 /* queue and queue Info */
29245 struct list_head reqQ;
29246 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29247 index 9125bbe..eede5c8 100644
29248 --- a/drivers/block/cpqarray.c
29249 +++ b/drivers/block/cpqarray.c
29250 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29251 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29252 goto Enomem4;
29253 }
29254 - hba[i]->access.set_intr_mask(hba[i], 0);
29255 + hba[i]->access->set_intr_mask(hba[i], 0);
29256 if (request_irq(hba[i]->intr, do_ida_intr,
29257 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29258 {
29259 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29260 add_timer(&hba[i]->timer);
29261
29262 /* Enable IRQ now that spinlock and rate limit timer are set up */
29263 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29264 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29265
29266 for(j=0; j<NWD; j++) {
29267 struct gendisk *disk = ida_gendisk[i][j];
29268 @@ -694,7 +694,7 @@ DBGINFO(
29269 for(i=0; i<NR_PRODUCTS; i++) {
29270 if (board_id == products[i].board_id) {
29271 c->product_name = products[i].product_name;
29272 - c->access = *(products[i].access);
29273 + c->access = products[i].access;
29274 break;
29275 }
29276 }
29277 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29278 hba[ctlr]->intr = intr;
29279 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29280 hba[ctlr]->product_name = products[j].product_name;
29281 - hba[ctlr]->access = *(products[j].access);
29282 + hba[ctlr]->access = products[j].access;
29283 hba[ctlr]->ctlr = ctlr;
29284 hba[ctlr]->board_id = board_id;
29285 hba[ctlr]->pci_dev = NULL; /* not PCI */
29286 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29287
29288 while((c = h->reqQ) != NULL) {
29289 /* Can't do anything if we're busy */
29290 - if (h->access.fifo_full(h) == 0)
29291 + if (h->access->fifo_full(h) == 0)
29292 return;
29293
29294 /* Get the first entry from the request Q */
29295 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29296 h->Qdepth--;
29297
29298 /* Tell the controller to do our bidding */
29299 - h->access.submit_command(h, c);
29300 + h->access->submit_command(h, c);
29301
29302 /* Get onto the completion Q */
29303 addQ(&h->cmpQ, c);
29304 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29305 unsigned long flags;
29306 __u32 a,a1;
29307
29308 - istat = h->access.intr_pending(h);
29309 + istat = h->access->intr_pending(h);
29310 /* Is this interrupt for us? */
29311 if (istat == 0)
29312 return IRQ_NONE;
29313 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29314 */
29315 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29316 if (istat & FIFO_NOT_EMPTY) {
29317 - while((a = h->access.command_completed(h))) {
29318 + while((a = h->access->command_completed(h))) {
29319 a1 = a; a &= ~3;
29320 if ((c = h->cmpQ) == NULL)
29321 {
29322 @@ -1449,11 +1449,11 @@ static int sendcmd(
29323 /*
29324 * Disable interrupt
29325 */
29326 - info_p->access.set_intr_mask(info_p, 0);
29327 + info_p->access->set_intr_mask(info_p, 0);
29328 /* Make sure there is room in the command FIFO */
29329 /* Actually it should be completely empty at this time. */
29330 for (i = 200000; i > 0; i--) {
29331 - temp = info_p->access.fifo_full(info_p);
29332 + temp = info_p->access->fifo_full(info_p);
29333 if (temp != 0) {
29334 break;
29335 }
29336 @@ -1466,7 +1466,7 @@ DBG(
29337 /*
29338 * Send the cmd
29339 */
29340 - info_p->access.submit_command(info_p, c);
29341 + info_p->access->submit_command(info_p, c);
29342 complete = pollcomplete(ctlr);
29343
29344 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29345 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29346 * we check the new geometry. Then turn interrupts back on when
29347 * we're done.
29348 */
29349 - host->access.set_intr_mask(host, 0);
29350 + host->access->set_intr_mask(host, 0);
29351 getgeometry(ctlr);
29352 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29353 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29354
29355 for(i=0; i<NWD; i++) {
29356 struct gendisk *disk = ida_gendisk[ctlr][i];
29357 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29358 /* Wait (up to 2 seconds) for a command to complete */
29359
29360 for (i = 200000; i > 0; i--) {
29361 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29362 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29363 if (done == 0) {
29364 udelay(10); /* a short fixed delay */
29365 } else
29366 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29367 index be73e9d..7fbf140 100644
29368 --- a/drivers/block/cpqarray.h
29369 +++ b/drivers/block/cpqarray.h
29370 @@ -99,7 +99,7 @@ struct ctlr_info {
29371 drv_info_t drv[NWD];
29372 struct proc_dir_entry *proc;
29373
29374 - struct access_method access;
29375 + struct access_method *access;
29376
29377 cmdlist_t *reqQ;
29378 cmdlist_t *cmpQ;
29379 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29380 index b953cc7..e3dc580 100644
29381 --- a/drivers/block/drbd/drbd_int.h
29382 +++ b/drivers/block/drbd/drbd_int.h
29383 @@ -735,7 +735,7 @@ struct drbd_request;
29384 struct drbd_epoch {
29385 struct list_head list;
29386 unsigned int barrier_nr;
29387 - atomic_t epoch_size; /* increased on every request added. */
29388 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29389 atomic_t active; /* increased on every req. added, and dec on every finished. */
29390 unsigned long flags;
29391 };
29392 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29393 void *int_dig_in;
29394 void *int_dig_vv;
29395 wait_queue_head_t seq_wait;
29396 - atomic_t packet_seq;
29397 + atomic_unchecked_t packet_seq;
29398 unsigned int peer_seq;
29399 spinlock_t peer_seq_lock;
29400 unsigned int minor;
29401 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29402
29403 static inline void drbd_tcp_cork(struct socket *sock)
29404 {
29405 - int __user val = 1;
29406 + int val = 1;
29407 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29408 - (char __user *)&val, sizeof(val));
29409 + (char __force_user *)&val, sizeof(val));
29410 }
29411
29412 static inline void drbd_tcp_uncork(struct socket *sock)
29413 {
29414 - int __user val = 0;
29415 + int val = 0;
29416 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29417 - (char __user *)&val, sizeof(val));
29418 + (char __force_user *)&val, sizeof(val));
29419 }
29420
29421 static inline void drbd_tcp_nodelay(struct socket *sock)
29422 {
29423 - int __user val = 1;
29424 + int val = 1;
29425 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29426 - (char __user *)&val, sizeof(val));
29427 + (char __force_user *)&val, sizeof(val));
29428 }
29429
29430 static inline void drbd_tcp_quickack(struct socket *sock)
29431 {
29432 - int __user val = 2;
29433 + int val = 2;
29434 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29435 - (char __user *)&val, sizeof(val));
29436 + (char __force_user *)&val, sizeof(val));
29437 }
29438
29439 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29440 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29441 index f93a032..71c87bf 100644
29442 --- a/drivers/block/drbd/drbd_main.c
29443 +++ b/drivers/block/drbd/drbd_main.c
29444 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29445 p.sector = sector;
29446 p.block_id = block_id;
29447 p.blksize = blksize;
29448 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29449 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29450
29451 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29452 return false;
29453 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29454
29455 p.sector = cpu_to_be64(req->sector);
29456 p.block_id = (unsigned long)req;
29457 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29458 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29459
29460 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29461
29462 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29463 atomic_set(&mdev->unacked_cnt, 0);
29464 atomic_set(&mdev->local_cnt, 0);
29465 atomic_set(&mdev->net_cnt, 0);
29466 - atomic_set(&mdev->packet_seq, 0);
29467 + atomic_set_unchecked(&mdev->packet_seq, 0);
29468 atomic_set(&mdev->pp_in_use, 0);
29469 atomic_set(&mdev->pp_in_use_by_net, 0);
29470 atomic_set(&mdev->rs_sect_in, 0);
29471 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29472 mdev->receiver.t_state);
29473
29474 /* no need to lock it, I'm the only thread alive */
29475 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29476 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29477 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29478 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29479 mdev->al_writ_cnt =
29480 mdev->bm_writ_cnt =
29481 mdev->read_cnt =
29482 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29483 index edb490a..ecd69da 100644
29484 --- a/drivers/block/drbd/drbd_nl.c
29485 +++ b/drivers/block/drbd/drbd_nl.c
29486 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29487 module_put(THIS_MODULE);
29488 }
29489
29490 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29491 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29492
29493 static unsigned short *
29494 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29495 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29496 cn_reply->id.idx = CN_IDX_DRBD;
29497 cn_reply->id.val = CN_VAL_DRBD;
29498
29499 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29500 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29501 cn_reply->ack = 0; /* not used here. */
29502 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29503 (int)((char *)tl - (char *)reply->tag_list);
29504 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29505 cn_reply->id.idx = CN_IDX_DRBD;
29506 cn_reply->id.val = CN_VAL_DRBD;
29507
29508 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29509 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29510 cn_reply->ack = 0; /* not used here. */
29511 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29512 (int)((char *)tl - (char *)reply->tag_list);
29513 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29514 cn_reply->id.idx = CN_IDX_DRBD;
29515 cn_reply->id.val = CN_VAL_DRBD;
29516
29517 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29518 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29519 cn_reply->ack = 0; // not used here.
29520 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29521 (int)((char*)tl - (char*)reply->tag_list);
29522 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29523 cn_reply->id.idx = CN_IDX_DRBD;
29524 cn_reply->id.val = CN_VAL_DRBD;
29525
29526 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29527 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29528 cn_reply->ack = 0; /* not used here. */
29529 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29530 (int)((char *)tl - (char *)reply->tag_list);
29531 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29532 index c74ca2d..860c819 100644
29533 --- a/drivers/block/drbd/drbd_receiver.c
29534 +++ b/drivers/block/drbd/drbd_receiver.c
29535 @@ -898,7 +898,7 @@ retry:
29536 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29537 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29538
29539 - atomic_set(&mdev->packet_seq, 0);
29540 + atomic_set_unchecked(&mdev->packet_seq, 0);
29541 mdev->peer_seq = 0;
29542
29543 if (drbd_send_protocol(mdev) == -1)
29544 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29545 do {
29546 next_epoch = NULL;
29547
29548 - epoch_size = atomic_read(&epoch->epoch_size);
29549 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29550
29551 switch (ev & ~EV_CLEANUP) {
29552 case EV_PUT:
29553 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29554 rv = FE_DESTROYED;
29555 } else {
29556 epoch->flags = 0;
29557 - atomic_set(&epoch->epoch_size, 0);
29558 + atomic_set_unchecked(&epoch->epoch_size, 0);
29559 /* atomic_set(&epoch->active, 0); is already zero */
29560 if (rv == FE_STILL_LIVE)
29561 rv = FE_RECYCLED;
29562 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29563 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29564 drbd_flush(mdev);
29565
29566 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29567 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29568 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29569 if (epoch)
29570 break;
29571 }
29572
29573 epoch = mdev->current_epoch;
29574 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29575 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29576
29577 D_ASSERT(atomic_read(&epoch->active) == 0);
29578 D_ASSERT(epoch->flags == 0);
29579 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29580 }
29581
29582 epoch->flags = 0;
29583 - atomic_set(&epoch->epoch_size, 0);
29584 + atomic_set_unchecked(&epoch->epoch_size, 0);
29585 atomic_set(&epoch->active, 0);
29586
29587 spin_lock(&mdev->epoch_lock);
29588 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29589 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29590 list_add(&epoch->list, &mdev->current_epoch->list);
29591 mdev->current_epoch = epoch;
29592 mdev->epochs++;
29593 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29594 spin_unlock(&mdev->peer_seq_lock);
29595
29596 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29597 - atomic_inc(&mdev->current_epoch->epoch_size);
29598 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29599 return drbd_drain_block(mdev, data_size);
29600 }
29601
29602 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29603
29604 spin_lock(&mdev->epoch_lock);
29605 e->epoch = mdev->current_epoch;
29606 - atomic_inc(&e->epoch->epoch_size);
29607 + atomic_inc_unchecked(&e->epoch->epoch_size);
29608 atomic_inc(&e->epoch->active);
29609 spin_unlock(&mdev->epoch_lock);
29610
29611 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29612 D_ASSERT(list_empty(&mdev->done_ee));
29613
29614 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29615 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29616 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29617 D_ASSERT(list_empty(&mdev->current_epoch->list));
29618 }
29619
29620 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29621 index 3bba655..6151b66 100644
29622 --- a/drivers/block/loop.c
29623 +++ b/drivers/block/loop.c
29624 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29625 mm_segment_t old_fs = get_fs();
29626
29627 set_fs(get_ds());
29628 - bw = file->f_op->write(file, buf, len, &pos);
29629 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29630 set_fs(old_fs);
29631 if (likely(bw == len))
29632 return 0;
29633 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29634 index ea6f632..eafb192 100644
29635 --- a/drivers/char/Kconfig
29636 +++ b/drivers/char/Kconfig
29637 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29638
29639 config DEVKMEM
29640 bool "/dev/kmem virtual device support"
29641 - default y
29642 + default n
29643 + depends on !GRKERNSEC_KMEM
29644 help
29645 Say Y here if you want to support the /dev/kmem device. The
29646 /dev/kmem device is rarely used, but can be used for certain
29647 @@ -581,6 +582,7 @@ config DEVPORT
29648 bool
29649 depends on !M68K
29650 depends on ISA || PCI
29651 + depends on !GRKERNSEC_KMEM
29652 default y
29653
29654 source "drivers/s390/char/Kconfig"
29655 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29656 index 2e04433..22afc64 100644
29657 --- a/drivers/char/agp/frontend.c
29658 +++ b/drivers/char/agp/frontend.c
29659 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29660 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29661 return -EFAULT;
29662
29663 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29664 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29665 return -EFAULT;
29666
29667 client = agp_find_client_by_pid(reserve.pid);
29668 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29669 index 21cb980..f15107c 100644
29670 --- a/drivers/char/genrtc.c
29671 +++ b/drivers/char/genrtc.c
29672 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29673 switch (cmd) {
29674
29675 case RTC_PLL_GET:
29676 + memset(&pll, 0, sizeof(pll));
29677 if (get_rtc_pll(&pll))
29678 return -EINVAL;
29679 else
29680 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29681 index dfd7876..c0b0885 100644
29682 --- a/drivers/char/hpet.c
29683 +++ b/drivers/char/hpet.c
29684 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29685 }
29686
29687 static int
29688 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29689 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29690 struct hpet_info *info)
29691 {
29692 struct hpet_timer __iomem *timer;
29693 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29694 index 2c29942..604c5ba 100644
29695 --- a/drivers/char/ipmi/ipmi_msghandler.c
29696 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29697 @@ -420,7 +420,7 @@ struct ipmi_smi {
29698 struct proc_dir_entry *proc_dir;
29699 char proc_dir_name[10];
29700
29701 - atomic_t stats[IPMI_NUM_STATS];
29702 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29703
29704 /*
29705 * run_to_completion duplicate of smb_info, smi_info
29706 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29707
29708
29709 #define ipmi_inc_stat(intf, stat) \
29710 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29711 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29712 #define ipmi_get_stat(intf, stat) \
29713 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29714 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29715
29716 static int is_lan_addr(struct ipmi_addr *addr)
29717 {
29718 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29719 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29720 init_waitqueue_head(&intf->waitq);
29721 for (i = 0; i < IPMI_NUM_STATS; i++)
29722 - atomic_set(&intf->stats[i], 0);
29723 + atomic_set_unchecked(&intf->stats[i], 0);
29724
29725 intf->proc_dir = NULL;
29726
29727 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29728 index 83f85cf..279e63f 100644
29729 --- a/drivers/char/ipmi/ipmi_si_intf.c
29730 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29731 @@ -275,7 +275,7 @@ struct smi_info {
29732 unsigned char slave_addr;
29733
29734 /* Counters and things for the proc filesystem. */
29735 - atomic_t stats[SI_NUM_STATS];
29736 + atomic_unchecked_t stats[SI_NUM_STATS];
29737
29738 struct task_struct *thread;
29739
29740 @@ -284,9 +284,9 @@ struct smi_info {
29741 };
29742
29743 #define smi_inc_stat(smi, stat) \
29744 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29745 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29746 #define smi_get_stat(smi, stat) \
29747 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29748 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29749
29750 #define SI_MAX_PARMS 4
29751
29752 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29753 atomic_set(&new_smi->req_events, 0);
29754 new_smi->run_to_completion = 0;
29755 for (i = 0; i < SI_NUM_STATS; i++)
29756 - atomic_set(&new_smi->stats[i], 0);
29757 + atomic_set_unchecked(&new_smi->stats[i], 0);
29758
29759 new_smi->interrupt_disabled = 1;
29760 atomic_set(&new_smi->stop_operation, 0);
29761 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29762 index 47ff7e4..0c7d340 100644
29763 --- a/drivers/char/mbcs.c
29764 +++ b/drivers/char/mbcs.c
29765 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29766 return 0;
29767 }
29768
29769 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29770 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29771 {
29772 .part_num = MBCS_PART_NUM,
29773 .mfg_num = MBCS_MFG_NUM,
29774 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29775 index e5eedfa..fcab50ea 100644
29776 --- a/drivers/char/mem.c
29777 +++ b/drivers/char/mem.c
29778 @@ -18,6 +18,7 @@
29779 #include <linux/raw.h>
29780 #include <linux/tty.h>
29781 #include <linux/capability.h>
29782 +#include <linux/security.h>
29783 #include <linux/ptrace.h>
29784 #include <linux/device.h>
29785 #include <linux/highmem.h>
29786 @@ -37,6 +38,10 @@
29787
29788 #define DEVPORT_MINOR 4
29789
29790 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29791 +extern const struct file_operations grsec_fops;
29792 +#endif
29793 +
29794 static inline unsigned long size_inside_page(unsigned long start,
29795 unsigned long size)
29796 {
29797 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29798
29799 while (cursor < to) {
29800 if (!devmem_is_allowed(pfn)) {
29801 +#ifdef CONFIG_GRKERNSEC_KMEM
29802 + gr_handle_mem_readwrite(from, to);
29803 +#else
29804 printk(KERN_INFO
29805 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29806 current->comm, from, to);
29807 +#endif
29808 return 0;
29809 }
29810 cursor += PAGE_SIZE;
29811 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29812 }
29813 return 1;
29814 }
29815 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29816 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29817 +{
29818 + return 0;
29819 +}
29820 #else
29821 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29822 {
29823 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29824
29825 while (count > 0) {
29826 unsigned long remaining;
29827 + char *temp;
29828
29829 sz = size_inside_page(p, count);
29830
29831 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29832 if (!ptr)
29833 return -EFAULT;
29834
29835 - remaining = copy_to_user(buf, ptr, sz);
29836 +#ifdef CONFIG_PAX_USERCOPY
29837 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29838 + if (!temp) {
29839 + unxlate_dev_mem_ptr(p, ptr);
29840 + return -ENOMEM;
29841 + }
29842 + memcpy(temp, ptr, sz);
29843 +#else
29844 + temp = ptr;
29845 +#endif
29846 +
29847 + remaining = copy_to_user(buf, temp, sz);
29848 +
29849 +#ifdef CONFIG_PAX_USERCOPY
29850 + kfree(temp);
29851 +#endif
29852 +
29853 unxlate_dev_mem_ptr(p, ptr);
29854 if (remaining)
29855 return -EFAULT;
29856 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29857 size_t count, loff_t *ppos)
29858 {
29859 unsigned long p = *ppos;
29860 - ssize_t low_count, read, sz;
29861 + ssize_t low_count, read, sz, err = 0;
29862 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29863 - int err = 0;
29864
29865 read = 0;
29866 if (p < (unsigned long) high_memory) {
29867 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29868 }
29869 #endif
29870 while (low_count > 0) {
29871 + char *temp;
29872 +
29873 sz = size_inside_page(p, low_count);
29874
29875 /*
29876 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29877 */
29878 kbuf = xlate_dev_kmem_ptr((char *)p);
29879
29880 - if (copy_to_user(buf, kbuf, sz))
29881 +#ifdef CONFIG_PAX_USERCOPY
29882 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29883 + if (!temp)
29884 + return -ENOMEM;
29885 + memcpy(temp, kbuf, sz);
29886 +#else
29887 + temp = kbuf;
29888 +#endif
29889 +
29890 + err = copy_to_user(buf, temp, sz);
29891 +
29892 +#ifdef CONFIG_PAX_USERCOPY
29893 + kfree(temp);
29894 +#endif
29895 +
29896 + if (err)
29897 return -EFAULT;
29898 buf += sz;
29899 p += sz;
29900 @@ -833,6 +880,9 @@ static const struct memdev {
29901 #ifdef CONFIG_CRASH_DUMP
29902 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29903 #endif
29904 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29905 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29906 +#endif
29907 };
29908
29909 static int memory_open(struct inode *inode, struct file *filp)
29910 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29911 index 9df78e2..01ba9ae 100644
29912 --- a/drivers/char/nvram.c
29913 +++ b/drivers/char/nvram.c
29914 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29915
29916 spin_unlock_irq(&rtc_lock);
29917
29918 - if (copy_to_user(buf, contents, tmp - contents))
29919 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29920 return -EFAULT;
29921
29922 *ppos = i;
29923 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29924 index 0a484b4..f48ccd1 100644
29925 --- a/drivers/char/pcmcia/synclink_cs.c
29926 +++ b/drivers/char/pcmcia/synclink_cs.c
29927 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29928
29929 if (debug_level >= DEBUG_LEVEL_INFO)
29930 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29931 - __FILE__,__LINE__, info->device_name, port->count);
29932 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29933
29934 - WARN_ON(!port->count);
29935 + WARN_ON(!atomic_read(&port->count));
29936
29937 if (tty_port_close_start(port, tty, filp) == 0)
29938 goto cleanup;
29939 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29940 cleanup:
29941 if (debug_level >= DEBUG_LEVEL_INFO)
29942 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29943 - tty->driver->name, port->count);
29944 + tty->driver->name, atomic_read(&port->count));
29945 }
29946
29947 /* Wait until the transmitter is empty.
29948 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29949
29950 if (debug_level >= DEBUG_LEVEL_INFO)
29951 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29952 - __FILE__,__LINE__,tty->driver->name, port->count);
29953 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29954
29955 /* If port is closing, signal caller to try again */
29956 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29957 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29958 goto cleanup;
29959 }
29960 spin_lock(&port->lock);
29961 - port->count++;
29962 + atomic_inc(&port->count);
29963 spin_unlock(&port->lock);
29964 spin_unlock_irqrestore(&info->netlock, flags);
29965
29966 - if (port->count == 1) {
29967 + if (atomic_read(&port->count) == 1) {
29968 /* 1st open on this device, init hardware */
29969 retval = startup(info, tty);
29970 if (retval < 0)
29971 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29972 unsigned short new_crctype;
29973
29974 /* return error if TTY interface open */
29975 - if (info->port.count)
29976 + if (atomic_read(&info->port.count))
29977 return -EBUSY;
29978
29979 switch (encoding)
29980 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29981
29982 /* arbitrate between network and tty opens */
29983 spin_lock_irqsave(&info->netlock, flags);
29984 - if (info->port.count != 0 || info->netcount != 0) {
29985 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29986 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29987 spin_unlock_irqrestore(&info->netlock, flags);
29988 return -EBUSY;
29989 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29990 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29991
29992 /* return error if TTY interface open */
29993 - if (info->port.count)
29994 + if (atomic_read(&info->port.count))
29995 return -EBUSY;
29996
29997 if (cmd != SIOCWANDEV)
29998 diff --git a/drivers/char/random.c b/drivers/char/random.c
29999 index b86eae9..4192a7a 100644
30000 --- a/drivers/char/random.c
30001 +++ b/drivers/char/random.c
30002 @@ -272,8 +272,13 @@
30003 /*
30004 * Configuration information
30005 */
30006 +#ifdef CONFIG_GRKERNSEC_RANDNET
30007 +#define INPUT_POOL_WORDS 512
30008 +#define OUTPUT_POOL_WORDS 128
30009 +#else
30010 #define INPUT_POOL_WORDS 128
30011 #define OUTPUT_POOL_WORDS 32
30012 +#endif
30013 #define SEC_XFER_SIZE 512
30014 #define EXTRACT_SIZE 10
30015
30016 @@ -313,10 +318,17 @@ static struct poolinfo {
30017 int poolwords;
30018 int tap1, tap2, tap3, tap4, tap5;
30019 } poolinfo_table[] = {
30020 +#ifdef CONFIG_GRKERNSEC_RANDNET
30021 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30022 + { 512, 411, 308, 208, 104, 1 },
30023 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30024 + { 128, 103, 76, 51, 25, 1 },
30025 +#else
30026 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30027 { 128, 103, 76, 51, 25, 1 },
30028 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30029 { 32, 26, 20, 14, 7, 1 },
30030 +#endif
30031 #if 0
30032 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30033 { 2048, 1638, 1231, 819, 411, 1 },
30034 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30035 input_rotate += i ? 7 : 14;
30036 }
30037
30038 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30039 - ACCESS_ONCE(r->add_ptr) = i;
30040 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30041 + ACCESS_ONCE_RW(r->add_ptr) = i;
30042 smp_wmb();
30043
30044 if (out)
30045 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30046 }
30047 #endif
30048
30049 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30050 +u64 latent_entropy;
30051 +
30052 +__init void transfer_latent_entropy(void)
30053 +{
30054 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30055 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30056 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30057 +}
30058 +#endif
30059 +
30060 /*********************************************************************
30061 *
30062 * Entropy extraction routines
30063 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30064
30065 extract_buf(r, tmp);
30066 i = min_t(int, nbytes, EXTRACT_SIZE);
30067 - if (copy_to_user(buf, tmp, i)) {
30068 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30069 ret = -EFAULT;
30070 break;
30071 }
30072 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30073 #include <linux/sysctl.h>
30074
30075 static int min_read_thresh = 8, min_write_thresh;
30076 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30077 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30078 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30079 static char sysctl_bootid[16];
30080
30081 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30082 index f877805..403375a 100644
30083 --- a/drivers/char/sonypi.c
30084 +++ b/drivers/char/sonypi.c
30085 @@ -54,6 +54,7 @@
30086
30087 #include <asm/uaccess.h>
30088 #include <asm/io.h>
30089 +#include <asm/local.h>
30090
30091 #include <linux/sonypi.h>
30092
30093 @@ -490,7 +491,7 @@ static struct sonypi_device {
30094 spinlock_t fifo_lock;
30095 wait_queue_head_t fifo_proc_list;
30096 struct fasync_struct *fifo_async;
30097 - int open_count;
30098 + local_t open_count;
30099 int model;
30100 struct input_dev *input_jog_dev;
30101 struct input_dev *input_key_dev;
30102 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30103 static int sonypi_misc_release(struct inode *inode, struct file *file)
30104 {
30105 mutex_lock(&sonypi_device.lock);
30106 - sonypi_device.open_count--;
30107 + local_dec(&sonypi_device.open_count);
30108 mutex_unlock(&sonypi_device.lock);
30109 return 0;
30110 }
30111 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30112 {
30113 mutex_lock(&sonypi_device.lock);
30114 /* Flush input queue on first open */
30115 - if (!sonypi_device.open_count)
30116 + if (!local_read(&sonypi_device.open_count))
30117 kfifo_reset(&sonypi_device.fifo);
30118 - sonypi_device.open_count++;
30119 + local_inc(&sonypi_device.open_count);
30120 mutex_unlock(&sonypi_device.lock);
30121
30122 return 0;
30123 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30124 index 4dc8024..90108d1 100644
30125 --- a/drivers/char/tpm/tpm.c
30126 +++ b/drivers/char/tpm/tpm.c
30127 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30128 chip->vendor.req_complete_val)
30129 goto out_recv;
30130
30131 - if ((status == chip->vendor.req_canceled)) {
30132 + if (status == chip->vendor.req_canceled) {
30133 dev_err(chip->dev, "Operation Canceled\n");
30134 rc = -ECANCELED;
30135 goto out;
30136 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30137 index 0636520..169c1d0 100644
30138 --- a/drivers/char/tpm/tpm_bios.c
30139 +++ b/drivers/char/tpm/tpm_bios.c
30140 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30141 event = addr;
30142
30143 if ((event->event_type == 0 && event->event_size == 0) ||
30144 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30145 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30146 return NULL;
30147
30148 return addr;
30149 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30150 return NULL;
30151
30152 if ((event->event_type == 0 && event->event_size == 0) ||
30153 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30154 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30155 return NULL;
30156
30157 (*pos)++;
30158 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30159 int i;
30160
30161 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30162 - seq_putc(m, data[i]);
30163 + if (!seq_putc(m, data[i]))
30164 + return -EFAULT;
30165
30166 return 0;
30167 }
30168 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30169 log->bios_event_log_end = log->bios_event_log + len;
30170
30171 virt = acpi_os_map_memory(start, len);
30172 + if (!virt) {
30173 + kfree(log->bios_event_log);
30174 + log->bios_event_log = NULL;
30175 + return -EFAULT;
30176 + }
30177
30178 - memcpy(log->bios_event_log, virt, len);
30179 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30180
30181 acpi_os_unmap_memory(virt, len);
30182 return 0;
30183 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30184 index cdf2f54..e55c197 100644
30185 --- a/drivers/char/virtio_console.c
30186 +++ b/drivers/char/virtio_console.c
30187 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30188 if (to_user) {
30189 ssize_t ret;
30190
30191 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30192 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30193 if (ret)
30194 return -EFAULT;
30195 } else {
30196 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30197 if (!port_has_data(port) && !port->host_connected)
30198 return 0;
30199
30200 - return fill_readbuf(port, ubuf, count, true);
30201 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30202 }
30203
30204 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30205 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30206 index e164c55..3aabb50 100644
30207 --- a/drivers/edac/edac_pci_sysfs.c
30208 +++ b/drivers/edac/edac_pci_sysfs.c
30209 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30210 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30211 static int edac_pci_poll_msec = 1000; /* one second workq period */
30212
30213 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30214 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30215 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30216 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30217
30218 static struct kobject *edac_pci_top_main_kobj;
30219 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30220 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30221 edac_printk(KERN_CRIT, EDAC_PCI,
30222 "Signaled System Error on %s\n",
30223 pci_name(dev));
30224 - atomic_inc(&pci_nonparity_count);
30225 + atomic_inc_unchecked(&pci_nonparity_count);
30226 }
30227
30228 if (status & (PCI_STATUS_PARITY)) {
30229 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30230 "Master Data Parity Error on %s\n",
30231 pci_name(dev));
30232
30233 - atomic_inc(&pci_parity_count);
30234 + atomic_inc_unchecked(&pci_parity_count);
30235 }
30236
30237 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30238 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30239 "Detected Parity Error on %s\n",
30240 pci_name(dev));
30241
30242 - atomic_inc(&pci_parity_count);
30243 + atomic_inc_unchecked(&pci_parity_count);
30244 }
30245 }
30246
30247 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30248 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30249 "Signaled System Error on %s\n",
30250 pci_name(dev));
30251 - atomic_inc(&pci_nonparity_count);
30252 + atomic_inc_unchecked(&pci_nonparity_count);
30253 }
30254
30255 if (status & (PCI_STATUS_PARITY)) {
30256 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30257 "Master Data Parity Error on "
30258 "%s\n", pci_name(dev));
30259
30260 - atomic_inc(&pci_parity_count);
30261 + atomic_inc_unchecked(&pci_parity_count);
30262 }
30263
30264 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30265 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30266 "Detected Parity Error on %s\n",
30267 pci_name(dev));
30268
30269 - atomic_inc(&pci_parity_count);
30270 + atomic_inc_unchecked(&pci_parity_count);
30271 }
30272 }
30273 }
30274 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30275 if (!check_pci_errors)
30276 return;
30277
30278 - before_count = atomic_read(&pci_parity_count);
30279 + before_count = atomic_read_unchecked(&pci_parity_count);
30280
30281 /* scan all PCI devices looking for a Parity Error on devices and
30282 * bridges.
30283 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30284 /* Only if operator has selected panic on PCI Error */
30285 if (edac_pci_get_panic_on_pe()) {
30286 /* If the count is different 'after' from 'before' */
30287 - if (before_count != atomic_read(&pci_parity_count))
30288 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30289 panic("EDAC: PCI Parity Error");
30290 }
30291 }
30292 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30293 index 8c87a5e..a19cbd7 100644
30294 --- a/drivers/edac/mce_amd.h
30295 +++ b/drivers/edac/mce_amd.h
30296 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30297 struct amd_decoder_ops {
30298 bool (*dc_mce)(u16, u8);
30299 bool (*ic_mce)(u16, u8);
30300 -};
30301 +} __no_const;
30302
30303 void amd_report_gart_errors(bool);
30304 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30305 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30306 index 57ea7f4..789e3c3 100644
30307 --- a/drivers/firewire/core-card.c
30308 +++ b/drivers/firewire/core-card.c
30309 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30310
30311 void fw_core_remove_card(struct fw_card *card)
30312 {
30313 - struct fw_card_driver dummy_driver = dummy_driver_template;
30314 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30315
30316 card->driver->update_phy_reg(card, 4,
30317 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30318 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30319 index f8d2287..5aaf4db 100644
30320 --- a/drivers/firewire/core-cdev.c
30321 +++ b/drivers/firewire/core-cdev.c
30322 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30323 int ret;
30324
30325 if ((request->channels == 0 && request->bandwidth == 0) ||
30326 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30327 - request->bandwidth < 0)
30328 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30329 return -EINVAL;
30330
30331 r = kmalloc(sizeof(*r), GFP_KERNEL);
30332 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30333 index 87d6f2d..5bf9d90 100644
30334 --- a/drivers/firewire/core-transaction.c
30335 +++ b/drivers/firewire/core-transaction.c
30336 @@ -37,6 +37,7 @@
30337 #include <linux/timer.h>
30338 #include <linux/types.h>
30339 #include <linux/workqueue.h>
30340 +#include <linux/sched.h>
30341
30342 #include <asm/byteorder.h>
30343
30344 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30345 index 515a42c..5ecf3ba 100644
30346 --- a/drivers/firewire/core.h
30347 +++ b/drivers/firewire/core.h
30348 @@ -111,6 +111,7 @@ struct fw_card_driver {
30349
30350 int (*stop_iso)(struct fw_iso_context *ctx);
30351 };
30352 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30353
30354 void fw_card_initialize(struct fw_card *card,
30355 const struct fw_card_driver *driver, struct device *device);
30356 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30357 index b298158..7ed8432 100644
30358 --- a/drivers/firmware/dmi_scan.c
30359 +++ b/drivers/firmware/dmi_scan.c
30360 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30361 }
30362 }
30363 else {
30364 - /*
30365 - * no iounmap() for that ioremap(); it would be a no-op, but
30366 - * it's so early in setup that sucker gets confused into doing
30367 - * what it shouldn't if we actually call it.
30368 - */
30369 p = dmi_ioremap(0xF0000, 0x10000);
30370 if (p == NULL)
30371 goto error;
30372 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30373 if (buf == NULL)
30374 return -1;
30375
30376 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30377 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30378
30379 iounmap(buf);
30380 return 0;
30381 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30382 index 82d5c20..44a7177 100644
30383 --- a/drivers/gpio/gpio-vr41xx.c
30384 +++ b/drivers/gpio/gpio-vr41xx.c
30385 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30386 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30387 maskl, pendl, maskh, pendh);
30388
30389 - atomic_inc(&irq_err_count);
30390 + atomic_inc_unchecked(&irq_err_count);
30391
30392 return -EINVAL;
30393 }
30394 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30395 index 3252e70..b5314ace 100644
30396 --- a/drivers/gpu/drm/drm_crtc_helper.c
30397 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30398 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30399 struct drm_crtc *tmp;
30400 int crtc_mask = 1;
30401
30402 - WARN(!crtc, "checking null crtc?\n");
30403 + BUG_ON(!crtc);
30404
30405 dev = crtc->dev;
30406
30407 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30408 index 9238de4..a27c72a 100644
30409 --- a/drivers/gpu/drm/drm_drv.c
30410 +++ b/drivers/gpu/drm/drm_drv.c
30411 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30412 /**
30413 * Copy and IOCTL return string to user space
30414 */
30415 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30416 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30417 {
30418 int len;
30419
30420 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30421 return -ENODEV;
30422
30423 atomic_inc(&dev->ioctl_count);
30424 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30425 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30426 ++file_priv->ioctl_count;
30427
30428 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30429 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30430 index 7aff5c7..bee6c27 100644
30431 --- a/drivers/gpu/drm/drm_fops.c
30432 +++ b/drivers/gpu/drm/drm_fops.c
30433 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30434 }
30435
30436 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30437 - atomic_set(&dev->counts[i], 0);
30438 + atomic_set_unchecked(&dev->counts[i], 0);
30439
30440 dev->sigdata.lock = NULL;
30441
30442 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30443 if (drm_device_is_unplugged(dev))
30444 return -ENODEV;
30445
30446 - if (!dev->open_count++)
30447 + if (local_inc_return(&dev->open_count) == 1)
30448 need_setup = 1;
30449 mutex_lock(&dev->struct_mutex);
30450 old_mapping = dev->dev_mapping;
30451 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30452 retcode = drm_open_helper(inode, filp, dev);
30453 if (retcode)
30454 goto err_undo;
30455 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30456 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30457 if (need_setup) {
30458 retcode = drm_setup(dev);
30459 if (retcode)
30460 @@ -164,7 +164,7 @@ err_undo:
30461 iput(container_of(dev->dev_mapping, struct inode, i_data));
30462 dev->dev_mapping = old_mapping;
30463 mutex_unlock(&dev->struct_mutex);
30464 - dev->open_count--;
30465 + local_dec(&dev->open_count);
30466 return retcode;
30467 }
30468 EXPORT_SYMBOL(drm_open);
30469 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30470
30471 mutex_lock(&drm_global_mutex);
30472
30473 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30474 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30475
30476 if (dev->driver->preclose)
30477 dev->driver->preclose(dev, file_priv);
30478 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30479 * Begin inline drm_release
30480 */
30481
30482 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30483 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30484 task_pid_nr(current),
30485 (long)old_encode_dev(file_priv->minor->device),
30486 - dev->open_count);
30487 + local_read(&dev->open_count));
30488
30489 /* Release any auth tokens that might point to this file_priv,
30490 (do that under the drm_global_mutex) */
30491 @@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30492 * End inline drm_release
30493 */
30494
30495 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30496 - if (!--dev->open_count) {
30497 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30498 + if (local_dec_and_test(&dev->open_count)) {
30499 if (atomic_read(&dev->ioctl_count)) {
30500 DRM_ERROR("Device busy: %d\n",
30501 atomic_read(&dev->ioctl_count));
30502 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30503 index c87dc96..326055d 100644
30504 --- a/drivers/gpu/drm/drm_global.c
30505 +++ b/drivers/gpu/drm/drm_global.c
30506 @@ -36,7 +36,7 @@
30507 struct drm_global_item {
30508 struct mutex mutex;
30509 void *object;
30510 - int refcount;
30511 + atomic_t refcount;
30512 };
30513
30514 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30515 @@ -49,7 +49,7 @@ void drm_global_init(void)
30516 struct drm_global_item *item = &glob[i];
30517 mutex_init(&item->mutex);
30518 item->object = NULL;
30519 - item->refcount = 0;
30520 + atomic_set(&item->refcount, 0);
30521 }
30522 }
30523
30524 @@ -59,7 +59,7 @@ void drm_global_release(void)
30525 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30526 struct drm_global_item *item = &glob[i];
30527 BUG_ON(item->object != NULL);
30528 - BUG_ON(item->refcount != 0);
30529 + BUG_ON(atomic_read(&item->refcount) != 0);
30530 }
30531 }
30532
30533 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30534 void *object;
30535
30536 mutex_lock(&item->mutex);
30537 - if (item->refcount == 0) {
30538 + if (atomic_read(&item->refcount) == 0) {
30539 item->object = kzalloc(ref->size, GFP_KERNEL);
30540 if (unlikely(item->object == NULL)) {
30541 ret = -ENOMEM;
30542 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30543 goto out_err;
30544
30545 }
30546 - ++item->refcount;
30547 + atomic_inc(&item->refcount);
30548 ref->object = item->object;
30549 object = item->object;
30550 mutex_unlock(&item->mutex);
30551 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30552 struct drm_global_item *item = &glob[ref->global_type];
30553
30554 mutex_lock(&item->mutex);
30555 - BUG_ON(item->refcount == 0);
30556 + BUG_ON(atomic_read(&item->refcount) == 0);
30557 BUG_ON(ref->object != item->object);
30558 - if (--item->refcount == 0) {
30559 + if (atomic_dec_and_test(&item->refcount)) {
30560 ref->release(ref);
30561 item->object = NULL;
30562 }
30563 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30564 index 8928edb..0c79258 100644
30565 --- a/drivers/gpu/drm/drm_info.c
30566 +++ b/drivers/gpu/drm/drm_info.c
30567 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30568 struct drm_local_map *map;
30569 struct drm_map_list *r_list;
30570
30571 - /* Hardcoded from _DRM_FRAME_BUFFER,
30572 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30573 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30574 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30575 + static const char * const types[] = {
30576 + [_DRM_FRAME_BUFFER] = "FB",
30577 + [_DRM_REGISTERS] = "REG",
30578 + [_DRM_SHM] = "SHM",
30579 + [_DRM_AGP] = "AGP",
30580 + [_DRM_SCATTER_GATHER] = "SG",
30581 + [_DRM_CONSISTENT] = "PCI",
30582 + [_DRM_GEM] = "GEM" };
30583 const char *type;
30584 int i;
30585
30586 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30587 map = r_list->map;
30588 if (!map)
30589 continue;
30590 - if (map->type < 0 || map->type > 5)
30591 + if (map->type >= ARRAY_SIZE(types))
30592 type = "??";
30593 else
30594 type = types[map->type];
30595 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30596 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30597 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30598 vma->vm_flags & VM_IO ? 'i' : '-',
30599 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30600 + 0);
30601 +#else
30602 vma->vm_pgoff);
30603 +#endif
30604
30605 #if defined(__i386__)
30606 pgprot = pgprot_val(vma->vm_page_prot);
30607 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30608 index 637fcc3..e890b33 100644
30609 --- a/drivers/gpu/drm/drm_ioc32.c
30610 +++ b/drivers/gpu/drm/drm_ioc32.c
30611 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30612 request = compat_alloc_user_space(nbytes);
30613 if (!access_ok(VERIFY_WRITE, request, nbytes))
30614 return -EFAULT;
30615 - list = (struct drm_buf_desc *) (request + 1);
30616 + list = (struct drm_buf_desc __user *) (request + 1);
30617
30618 if (__put_user(count, &request->count)
30619 || __put_user(list, &request->list))
30620 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30621 request = compat_alloc_user_space(nbytes);
30622 if (!access_ok(VERIFY_WRITE, request, nbytes))
30623 return -EFAULT;
30624 - list = (struct drm_buf_pub *) (request + 1);
30625 + list = (struct drm_buf_pub __user *) (request + 1);
30626
30627 if (__put_user(count, &request->count)
30628 || __put_user(list, &request->list))
30629 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30630 index 64a62c6..ceab35e 100644
30631 --- a/drivers/gpu/drm/drm_ioctl.c
30632 +++ b/drivers/gpu/drm/drm_ioctl.c
30633 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30634 stats->data[i].value =
30635 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30636 else
30637 - stats->data[i].value = atomic_read(&dev->counts[i]);
30638 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30639 stats->data[i].type = dev->types[i];
30640 }
30641
30642 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30643 index 3203955..c8090af 100644
30644 --- a/drivers/gpu/drm/drm_lock.c
30645 +++ b/drivers/gpu/drm/drm_lock.c
30646 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30647 if (drm_lock_take(&master->lock, lock->context)) {
30648 master->lock.file_priv = file_priv;
30649 master->lock.lock_time = jiffies;
30650 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30651 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30652 break; /* Got lock */
30653 }
30654
30655 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30656 return -EINVAL;
30657 }
30658
30659 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30660 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30661
30662 if (drm_lock_free(&master->lock, lock->context)) {
30663 /* FIXME: Should really bail out here. */
30664 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30665 index 21bcd4a..8e074e0 100644
30666 --- a/drivers/gpu/drm/drm_stub.c
30667 +++ b/drivers/gpu/drm/drm_stub.c
30668 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30669
30670 drm_device_set_unplugged(dev);
30671
30672 - if (dev->open_count == 0) {
30673 + if (local_read(&dev->open_count) == 0) {
30674 drm_put_dev(dev);
30675 }
30676 mutex_unlock(&drm_global_mutex);
30677 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30678 index 463ec68..f5bd2b5 100644
30679 --- a/drivers/gpu/drm/i810/i810_dma.c
30680 +++ b/drivers/gpu/drm/i810/i810_dma.c
30681 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30682 dma->buflist[vertex->idx],
30683 vertex->discard, vertex->used);
30684
30685 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30686 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30687 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30688 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30689 sarea_priv->last_enqueue = dev_priv->counter - 1;
30690 sarea_priv->last_dispatch = (int)hw_status[5];
30691
30692 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30693 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30694 mc->last_render);
30695
30696 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30697 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30698 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30699 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30700 sarea_priv->last_enqueue = dev_priv->counter - 1;
30701 sarea_priv->last_dispatch = (int)hw_status[5];
30702
30703 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30704 index 6e0acad..93c8289 100644
30705 --- a/drivers/gpu/drm/i810/i810_drv.h
30706 +++ b/drivers/gpu/drm/i810/i810_drv.h
30707 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30708 int page_flipping;
30709
30710 wait_queue_head_t irq_queue;
30711 - atomic_t irq_received;
30712 - atomic_t irq_emitted;
30713 + atomic_unchecked_t irq_received;
30714 + atomic_unchecked_t irq_emitted;
30715
30716 int front_offset;
30717 } drm_i810_private_t;
30718 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30719 index 359f6e8..ada68fd 100644
30720 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30721 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30722 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30723 I915_READ(GTIMR));
30724 }
30725 seq_printf(m, "Interrupts received: %d\n",
30726 - atomic_read(&dev_priv->irq_received));
30727 + atomic_read_unchecked(&dev_priv->irq_received));
30728 for (i = 0; i < I915_NUM_RINGS; i++) {
30729 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30730 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30731 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30732 index 0969a7c..b9ffa45 100644
30733 --- a/drivers/gpu/drm/i915/i915_dma.c
30734 +++ b/drivers/gpu/drm/i915/i915_dma.c
30735 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30736 bool can_switch;
30737
30738 spin_lock(&dev->count_lock);
30739 - can_switch = (dev->open_count == 0);
30740 + can_switch = (local_read(&dev->open_count) == 0);
30741 spin_unlock(&dev->count_lock);
30742 return can_switch;
30743 }
30744 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30745 index 627fe35..c9a7346 100644
30746 --- a/drivers/gpu/drm/i915/i915_drv.h
30747 +++ b/drivers/gpu/drm/i915/i915_drv.h
30748 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30749 /* render clock increase/decrease */
30750 /* display clock increase/decrease */
30751 /* pll clock increase/decrease */
30752 -};
30753 +} __no_const;
30754
30755 struct drm_i915_gt_funcs {
30756 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30757 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30758 -};
30759 +} __no_const;
30760
30761 struct intel_device_info {
30762 u8 gen;
30763 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30764 int current_page;
30765 int page_flipping;
30766
30767 - atomic_t irq_received;
30768 + atomic_unchecked_t irq_received;
30769
30770 /* protects the irq masks */
30771 spinlock_t irq_lock;
30772 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30773 * will be page flipped away on the next vblank. When it
30774 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30775 */
30776 - atomic_t pending_flip;
30777 + atomic_unchecked_t pending_flip;
30778 };
30779
30780 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30781 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30782 struct drm_i915_private *dev_priv, unsigned port);
30783 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30784 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30785 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30786 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30787 {
30788 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30789 }
30790 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30791 index cdf46b5..e785624 100644
30792 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30793 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30794 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30795 i915_gem_clflush_object(obj);
30796
30797 if (obj->base.pending_write_domain)
30798 - cd->flips |= atomic_read(&obj->pending_flip);
30799 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30800
30801 /* The actual obj->write_domain will be updated with
30802 * pending_write_domain after we emit the accumulated flush for all
30803 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30804
30805 static int
30806 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30807 - int count)
30808 + unsigned int count)
30809 {
30810 - int i;
30811 + unsigned int i;
30812
30813 for (i = 0; i < count; i++) {
30814 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30815 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30816 index 73fa3e1..ab2e9b9 100644
30817 --- a/drivers/gpu/drm/i915/i915_irq.c
30818 +++ b/drivers/gpu/drm/i915/i915_irq.c
30819 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30820 u32 pipe_stats[I915_MAX_PIPES];
30821 bool blc_event;
30822
30823 - atomic_inc(&dev_priv->irq_received);
30824 + atomic_inc_unchecked(&dev_priv->irq_received);
30825
30826 while (true) {
30827 iir = I915_READ(VLV_IIR);
30828 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30829 irqreturn_t ret = IRQ_NONE;
30830 int i;
30831
30832 - atomic_inc(&dev_priv->irq_received);
30833 + atomic_inc_unchecked(&dev_priv->irq_received);
30834
30835 /* disable master interrupt before clearing iir */
30836 de_ier = I915_READ(DEIER);
30837 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30838 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30839 u32 hotplug_mask;
30840
30841 - atomic_inc(&dev_priv->irq_received);
30842 + atomic_inc_unchecked(&dev_priv->irq_received);
30843
30844 /* disable master interrupt before clearing iir */
30845 de_ier = I915_READ(DEIER);
30846 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30847 {
30848 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30849
30850 - atomic_set(&dev_priv->irq_received, 0);
30851 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30852
30853 I915_WRITE(HWSTAM, 0xeffe);
30854
30855 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30856 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30857 int pipe;
30858
30859 - atomic_set(&dev_priv->irq_received, 0);
30860 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30861
30862 /* VLV magic */
30863 I915_WRITE(VLV_IMR, 0);
30864 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30865 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30866 int pipe;
30867
30868 - atomic_set(&dev_priv->irq_received, 0);
30869 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30870
30871 for_each_pipe(pipe)
30872 I915_WRITE(PIPESTAT(pipe), 0);
30873 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30874 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30875 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30876
30877 - atomic_inc(&dev_priv->irq_received);
30878 + atomic_inc_unchecked(&dev_priv->irq_received);
30879
30880 iir = I915_READ16(IIR);
30881 if (iir == 0)
30882 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30883 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30884 int pipe;
30885
30886 - atomic_set(&dev_priv->irq_received, 0);
30887 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30888
30889 if (I915_HAS_HOTPLUG(dev)) {
30890 I915_WRITE(PORT_HOTPLUG_EN, 0);
30891 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30892 };
30893 int pipe, ret = IRQ_NONE;
30894
30895 - atomic_inc(&dev_priv->irq_received);
30896 + atomic_inc_unchecked(&dev_priv->irq_received);
30897
30898 iir = I915_READ(IIR);
30899 do {
30900 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30901 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30902 int pipe;
30903
30904 - atomic_set(&dev_priv->irq_received, 0);
30905 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30906
30907 I915_WRITE(PORT_HOTPLUG_EN, 0);
30908 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30909 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30910 int irq_received;
30911 int ret = IRQ_NONE, pipe;
30912
30913 - atomic_inc(&dev_priv->irq_received);
30914 + atomic_inc_unchecked(&dev_priv->irq_received);
30915
30916 iir = I915_READ(IIR);
30917
30918 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30919 index b634f6f..43c62f5 100644
30920 --- a/drivers/gpu/drm/i915/intel_display.c
30921 +++ b/drivers/gpu/drm/i915/intel_display.c
30922 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30923
30924 wait_event(dev_priv->pending_flip_queue,
30925 atomic_read(&dev_priv->mm.wedged) ||
30926 - atomic_read(&obj->pending_flip) == 0);
30927 + atomic_read_unchecked(&obj->pending_flip) == 0);
30928
30929 /* Big Hammer, we also need to ensure that any pending
30930 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30931 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30932
30933 obj = work->old_fb_obj;
30934
30935 - atomic_clear_mask(1 << intel_crtc->plane,
30936 - &obj->pending_flip.counter);
30937 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30938
30939 wake_up(&dev_priv->pending_flip_queue);
30940 schedule_work(&work->work);
30941 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30942 /* Block clients from rendering to the new back buffer until
30943 * the flip occurs and the object is no longer visible.
30944 */
30945 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30946 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30947
30948 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30949 if (ret)
30950 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30951 return 0;
30952
30953 cleanup_pending:
30954 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30955 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30956 drm_gem_object_unreference(&work->old_fb_obj->base);
30957 drm_gem_object_unreference(&obj->base);
30958 mutex_unlock(&dev->struct_mutex);
30959 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30960 index 54558a0..2d97005 100644
30961 --- a/drivers/gpu/drm/mga/mga_drv.h
30962 +++ b/drivers/gpu/drm/mga/mga_drv.h
30963 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30964 u32 clear_cmd;
30965 u32 maccess;
30966
30967 - atomic_t vbl_received; /**< Number of vblanks received. */
30968 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30969 wait_queue_head_t fence_queue;
30970 - atomic_t last_fence_retired;
30971 + atomic_unchecked_t last_fence_retired;
30972 u32 next_fence_to_post;
30973
30974 unsigned int fb_cpp;
30975 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30976 index 2581202..f230a8d9 100644
30977 --- a/drivers/gpu/drm/mga/mga_irq.c
30978 +++ b/drivers/gpu/drm/mga/mga_irq.c
30979 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30980 if (crtc != 0)
30981 return 0;
30982
30983 - return atomic_read(&dev_priv->vbl_received);
30984 + return atomic_read_unchecked(&dev_priv->vbl_received);
30985 }
30986
30987
30988 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30989 /* VBLANK interrupt */
30990 if (status & MGA_VLINEPEN) {
30991 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30992 - atomic_inc(&dev_priv->vbl_received);
30993 + atomic_inc_unchecked(&dev_priv->vbl_received);
30994 drm_handle_vblank(dev, 0);
30995 handled = 1;
30996 }
30997 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30998 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30999 MGA_WRITE(MGA_PRIMEND, prim_end);
31000
31001 - atomic_inc(&dev_priv->last_fence_retired);
31002 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31003 DRM_WAKEUP(&dev_priv->fence_queue);
31004 handled = 1;
31005 }
31006 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31007 * using fences.
31008 */
31009 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31010 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31011 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31012 - *sequence) <= (1 << 23)));
31013
31014 *sequence = cur_fence;
31015 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31016 index a0a3fe3..209bf10 100644
31017 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31018 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31019 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31020 struct bit_table {
31021 const char id;
31022 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31023 -};
31024 +} __no_const;
31025
31026 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31027
31028 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31029 index 4f2cc95..9c6c510 100644
31030 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31031 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31032 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31033 u32 handle, u16 class);
31034 void (*set_tile_region)(struct drm_device *dev, int i);
31035 void (*tlb_flush)(struct drm_device *, int engine);
31036 -};
31037 +} __no_const;
31038
31039 struct nouveau_instmem_engine {
31040 void *priv;
31041 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31042 struct nouveau_mc_engine {
31043 int (*init)(struct drm_device *dev);
31044 void (*takedown)(struct drm_device *dev);
31045 -};
31046 +} __no_const;
31047
31048 struct nouveau_timer_engine {
31049 int (*init)(struct drm_device *dev);
31050 void (*takedown)(struct drm_device *dev);
31051 uint64_t (*read)(struct drm_device *dev);
31052 -};
31053 +} __no_const;
31054
31055 struct nouveau_fb_engine {
31056 int num_tiles;
31057 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31058 void (*put)(struct drm_device *, struct nouveau_mem **);
31059
31060 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31061 -};
31062 +} __no_const;
31063
31064 struct nouveau_engine {
31065 struct nouveau_instmem_engine instmem;
31066 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
31067 struct drm_global_reference mem_global_ref;
31068 struct ttm_bo_global_ref bo_global_ref;
31069 struct ttm_bo_device bdev;
31070 - atomic_t validate_sequence;
31071 + atomic_unchecked_t validate_sequence;
31072 int (*move)(struct nouveau_channel *,
31073 struct ttm_buffer_object *,
31074 struct ttm_mem_reg *, struct ttm_mem_reg *);
31075 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31076 index af7cfb8..aadc2a3 100644
31077 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31078 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31079 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31080 int trycnt = 0;
31081 int ret, i;
31082
31083 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31084 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31085 retry:
31086 if (++trycnt > 100000) {
31087 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31088 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31089 index f5e9584..05934ba 100644
31090 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31091 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31092 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31093 bool can_switch;
31094
31095 spin_lock(&dev->count_lock);
31096 - can_switch = (dev->open_count == 0);
31097 + can_switch = (local_read(&dev->open_count) == 0);
31098 spin_unlock(&dev->count_lock);
31099 return can_switch;
31100 }
31101 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31102 index 93240bd..c490f60 100644
31103 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31104 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31105 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31106 }
31107
31108 if (nv_encoder->dcb->type == OUTPUT_DP) {
31109 - struct dp_train_func func = {
31110 + static struct dp_train_func func = {
31111 .link_set = nv50_sor_dp_link_set,
31112 .train_set = nv50_sor_dp_train_set,
31113 .train_adj = nv50_sor_dp_train_adj
31114 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31115 index 8a2fc89..3a5cf40 100644
31116 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31117 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31118 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31119 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31120
31121 if (nv_encoder->dcb->type == OUTPUT_DP) {
31122 - struct dp_train_func func = {
31123 + static struct dp_train_func func = {
31124 .link_set = nvd0_sor_dp_link_set,
31125 .train_set = nvd0_sor_dp_train_set,
31126 .train_adj = nvd0_sor_dp_train_adj
31127 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31128 index bcac90b..53bfc76 100644
31129 --- a/drivers/gpu/drm/r128/r128_cce.c
31130 +++ b/drivers/gpu/drm/r128/r128_cce.c
31131 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31132
31133 /* GH: Simple idle check.
31134 */
31135 - atomic_set(&dev_priv->idle_count, 0);
31136 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31137
31138 /* We don't support anything other than bus-mastering ring mode,
31139 * but the ring can be in either AGP or PCI space for the ring
31140 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31141 index 930c71b..499aded 100644
31142 --- a/drivers/gpu/drm/r128/r128_drv.h
31143 +++ b/drivers/gpu/drm/r128/r128_drv.h
31144 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31145 int is_pci;
31146 unsigned long cce_buffers_offset;
31147
31148 - atomic_t idle_count;
31149 + atomic_unchecked_t idle_count;
31150
31151 int page_flipping;
31152 int current_page;
31153 u32 crtc_offset;
31154 u32 crtc_offset_cntl;
31155
31156 - atomic_t vbl_received;
31157 + atomic_unchecked_t vbl_received;
31158
31159 u32 color_fmt;
31160 unsigned int front_offset;
31161 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31162 index 429d5a0..7e899ed 100644
31163 --- a/drivers/gpu/drm/r128/r128_irq.c
31164 +++ b/drivers/gpu/drm/r128/r128_irq.c
31165 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31166 if (crtc != 0)
31167 return 0;
31168
31169 - return atomic_read(&dev_priv->vbl_received);
31170 + return atomic_read_unchecked(&dev_priv->vbl_received);
31171 }
31172
31173 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31174 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31175 /* VBLANK interrupt */
31176 if (status & R128_CRTC_VBLANK_INT) {
31177 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31178 - atomic_inc(&dev_priv->vbl_received);
31179 + atomic_inc_unchecked(&dev_priv->vbl_received);
31180 drm_handle_vblank(dev, 0);
31181 return IRQ_HANDLED;
31182 }
31183 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31184 index a9e33ce..09edd4b 100644
31185 --- a/drivers/gpu/drm/r128/r128_state.c
31186 +++ b/drivers/gpu/drm/r128/r128_state.c
31187 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31188
31189 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31190 {
31191 - if (atomic_read(&dev_priv->idle_count) == 0)
31192 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31193 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31194 else
31195 - atomic_set(&dev_priv->idle_count, 0);
31196 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31197 }
31198
31199 #endif
31200 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31201 index 5a82b6b..9e69c73 100644
31202 --- a/drivers/gpu/drm/radeon/mkregtable.c
31203 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31204 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31205 regex_t mask_rex;
31206 regmatch_t match[4];
31207 char buf[1024];
31208 - size_t end;
31209 + long end;
31210 int len;
31211 int done = 0;
31212 int r;
31213 unsigned o;
31214 struct offset *offset;
31215 char last_reg_s[10];
31216 - int last_reg;
31217 + unsigned long last_reg;
31218
31219 if (regcomp
31220 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31221 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31222 index 59a1531..3bab49b 100644
31223 --- a/drivers/gpu/drm/radeon/radeon.h
31224 +++ b/drivers/gpu/drm/radeon/radeon.h
31225 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31226 int x2, int y2);
31227 void (*draw_auto)(struct radeon_device *rdev);
31228 void (*set_default_state)(struct radeon_device *rdev);
31229 -};
31230 +} __no_const;
31231
31232 struct r600_blit {
31233 struct radeon_bo *shader_obj;
31234 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31235 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31236 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31237 } pflip;
31238 -};
31239 +} __no_const;
31240
31241 /*
31242 * Asic structures
31243 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31244 index 7a3daeb..5016171 100644
31245 --- a/drivers/gpu/drm/radeon/radeon_device.c
31246 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31247 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31248 bool can_switch;
31249
31250 spin_lock(&dev->count_lock);
31251 - can_switch = (dev->open_count == 0);
31252 + can_switch = (local_read(&dev->open_count) == 0);
31253 spin_unlock(&dev->count_lock);
31254 return can_switch;
31255 }
31256 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31257 index a1b59ca..86f2d44 100644
31258 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31259 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31260 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31261
31262 /* SW interrupt */
31263 wait_queue_head_t swi_queue;
31264 - atomic_t swi_emitted;
31265 + atomic_unchecked_t swi_emitted;
31266 int vblank_crtc;
31267 uint32_t irq_enable_reg;
31268 uint32_t r500_disp_irq_reg;
31269 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31270 index 48b7cea..342236f 100644
31271 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31272 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31273 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31274 request = compat_alloc_user_space(sizeof(*request));
31275 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31276 || __put_user(req32.param, &request->param)
31277 - || __put_user((void __user *)(unsigned long)req32.value,
31278 + || __put_user((unsigned long)req32.value,
31279 &request->value))
31280 return -EFAULT;
31281
31282 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31283 index 00da384..32f972d 100644
31284 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31285 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31286 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31287 unsigned int ret;
31288 RING_LOCALS;
31289
31290 - atomic_inc(&dev_priv->swi_emitted);
31291 - ret = atomic_read(&dev_priv->swi_emitted);
31292 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31293 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31294
31295 BEGIN_RING(4);
31296 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31297 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31298 drm_radeon_private_t *dev_priv =
31299 (drm_radeon_private_t *) dev->dev_private;
31300
31301 - atomic_set(&dev_priv->swi_emitted, 0);
31302 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31303 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31304
31305 dev->max_vblank_count = 0x001fffff;
31306 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31307 index e8422ae..d22d4a8 100644
31308 --- a/drivers/gpu/drm/radeon/radeon_state.c
31309 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31310 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31311 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31312 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31313
31314 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31315 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31316 sarea_priv->nbox * sizeof(depth_boxes[0])))
31317 return -EFAULT;
31318
31319 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31320 {
31321 drm_radeon_private_t *dev_priv = dev->dev_private;
31322 drm_radeon_getparam_t *param = data;
31323 - int value;
31324 + int value = 0;
31325
31326 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31327
31328 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31329 index 5b71c71..650f9e4 100644
31330 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31331 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31332 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31333 }
31334 if (unlikely(ttm_vm_ops == NULL)) {
31335 ttm_vm_ops = vma->vm_ops;
31336 - radeon_ttm_vm_ops = *ttm_vm_ops;
31337 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31338 + pax_open_kernel();
31339 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31340 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31341 + pax_close_kernel();
31342 }
31343 vma->vm_ops = &radeon_ttm_vm_ops;
31344 return 0;
31345 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31346 index 3b663fc..57850f4 100644
31347 --- a/drivers/gpu/drm/radeon/rs690.c
31348 +++ b/drivers/gpu/drm/radeon/rs690.c
31349 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31350 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31351 rdev->pm.sideport_bandwidth.full)
31352 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31353 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31354 + read_delay_latency.full = dfixed_const(800 * 1000);
31355 read_delay_latency.full = dfixed_div(read_delay_latency,
31356 rdev->pm.igp_sideport_mclk);
31357 + a.full = dfixed_const(370);
31358 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31359 } else {
31360 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31361 rdev->pm.k8_bandwidth.full)
31362 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31363 index ebc6fac..a8313ed 100644
31364 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31365 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31366 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31367 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31368 struct shrink_control *sc)
31369 {
31370 - static atomic_t start_pool = ATOMIC_INIT(0);
31371 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31372 unsigned i;
31373 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31374 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31375 struct ttm_page_pool *pool;
31376 int shrink_pages = sc->nr_to_scan;
31377
31378 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31379 index 88edacc..1e5412b 100644
31380 --- a/drivers/gpu/drm/via/via_drv.h
31381 +++ b/drivers/gpu/drm/via/via_drv.h
31382 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31383 typedef uint32_t maskarray_t[5];
31384
31385 typedef struct drm_via_irq {
31386 - atomic_t irq_received;
31387 + atomic_unchecked_t irq_received;
31388 uint32_t pending_mask;
31389 uint32_t enable_mask;
31390 wait_queue_head_t irq_queue;
31391 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31392 struct timeval last_vblank;
31393 int last_vblank_valid;
31394 unsigned usec_per_vblank;
31395 - atomic_t vbl_received;
31396 + atomic_unchecked_t vbl_received;
31397 drm_via_state_t hc_state;
31398 char pci_buf[VIA_PCI_BUF_SIZE];
31399 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31400 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31401 index d391f48..10c8ca3 100644
31402 --- a/drivers/gpu/drm/via/via_irq.c
31403 +++ b/drivers/gpu/drm/via/via_irq.c
31404 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31405 if (crtc != 0)
31406 return 0;
31407
31408 - return atomic_read(&dev_priv->vbl_received);
31409 + return atomic_read_unchecked(&dev_priv->vbl_received);
31410 }
31411
31412 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31413 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31414
31415 status = VIA_READ(VIA_REG_INTERRUPT);
31416 if (status & VIA_IRQ_VBLANK_PENDING) {
31417 - atomic_inc(&dev_priv->vbl_received);
31418 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31419 + atomic_inc_unchecked(&dev_priv->vbl_received);
31420 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31421 do_gettimeofday(&cur_vblank);
31422 if (dev_priv->last_vblank_valid) {
31423 dev_priv->usec_per_vblank =
31424 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31425 dev_priv->last_vblank = cur_vblank;
31426 dev_priv->last_vblank_valid = 1;
31427 }
31428 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31429 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31430 DRM_DEBUG("US per vblank is: %u\n",
31431 dev_priv->usec_per_vblank);
31432 }
31433 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31434
31435 for (i = 0; i < dev_priv->num_irqs; ++i) {
31436 if (status & cur_irq->pending_mask) {
31437 - atomic_inc(&cur_irq->irq_received);
31438 + atomic_inc_unchecked(&cur_irq->irq_received);
31439 DRM_WAKEUP(&cur_irq->irq_queue);
31440 handled = 1;
31441 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31442 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31443 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31444 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31445 masks[irq][4]));
31446 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31447 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31448 } else {
31449 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31450 (((cur_irq_sequence =
31451 - atomic_read(&cur_irq->irq_received)) -
31452 + atomic_read_unchecked(&cur_irq->irq_received)) -
31453 *sequence) <= (1 << 23)));
31454 }
31455 *sequence = cur_irq_sequence;
31456 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31457 }
31458
31459 for (i = 0; i < dev_priv->num_irqs; ++i) {
31460 - atomic_set(&cur_irq->irq_received, 0);
31461 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31462 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31463 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31464 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31465 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31466 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31467 case VIA_IRQ_RELATIVE:
31468 irqwait->request.sequence +=
31469 - atomic_read(&cur_irq->irq_received);
31470 + atomic_read_unchecked(&cur_irq->irq_received);
31471 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31472 case VIA_IRQ_ABSOLUTE:
31473 break;
31474 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31475 index 29c984f..4084f1a 100644
31476 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31477 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31478 @@ -263,7 +263,7 @@ struct vmw_private {
31479 * Fencing and IRQs.
31480 */
31481
31482 - atomic_t marker_seq;
31483 + atomic_unchecked_t marker_seq;
31484 wait_queue_head_t fence_queue;
31485 wait_queue_head_t fifo_queue;
31486 int fence_queue_waiters; /* Protected by hw_mutex */
31487 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31488 index a0c2f12..68ae6cb 100644
31489 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31490 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31491 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31492 (unsigned int) min,
31493 (unsigned int) fifo->capabilities);
31494
31495 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31496 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31497 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31498 vmw_marker_queue_init(&fifo->marker_queue);
31499 return vmw_fifo_send_fence(dev_priv, &dummy);
31500 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31501 if (reserveable)
31502 iowrite32(bytes, fifo_mem +
31503 SVGA_FIFO_RESERVED);
31504 - return fifo_mem + (next_cmd >> 2);
31505 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31506 } else {
31507 need_bounce = true;
31508 }
31509 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31510
31511 fm = vmw_fifo_reserve(dev_priv, bytes);
31512 if (unlikely(fm == NULL)) {
31513 - *seqno = atomic_read(&dev_priv->marker_seq);
31514 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31515 ret = -ENOMEM;
31516 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31517 false, 3*HZ);
31518 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31519 }
31520
31521 do {
31522 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31523 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31524 } while (*seqno == 0);
31525
31526 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31527 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31528 index cabc95f..14b3d77 100644
31529 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31530 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31531 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31532 * emitted. Then the fence is stale and signaled.
31533 */
31534
31535 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31536 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31537 > VMW_FENCE_WRAP);
31538
31539 return ret;
31540 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31541
31542 if (fifo_idle)
31543 down_read(&fifo_state->rwsem);
31544 - signal_seq = atomic_read(&dev_priv->marker_seq);
31545 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31546 ret = 0;
31547
31548 for (;;) {
31549 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31550 index 8a8725c..afed796 100644
31551 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31552 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31553 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31554 while (!vmw_lag_lt(queue, us)) {
31555 spin_lock(&queue->lock);
31556 if (list_empty(&queue->head))
31557 - seqno = atomic_read(&dev_priv->marker_seq);
31558 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31559 else {
31560 marker = list_first_entry(&queue->head,
31561 struct vmw_marker, head);
31562 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31563 index 5de3bb3..08e5063 100644
31564 --- a/drivers/hid/hid-core.c
31565 +++ b/drivers/hid/hid-core.c
31566 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31567
31568 int hid_add_device(struct hid_device *hdev)
31569 {
31570 - static atomic_t id = ATOMIC_INIT(0);
31571 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31572 int ret;
31573
31574 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31575 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31576 /* XXX hack, any other cleaner solution after the driver core
31577 * is converted to allow more than 20 bytes as the device name? */
31578 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31579 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31580 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31581
31582 hid_debug_register(hdev, dev_name(&hdev->dev));
31583 ret = device_add(&hdev->dev);
31584 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31585 index eec3291..8ed706b 100644
31586 --- a/drivers/hid/hid-wiimote-debug.c
31587 +++ b/drivers/hid/hid-wiimote-debug.c
31588 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31589 else if (size == 0)
31590 return -EIO;
31591
31592 - if (copy_to_user(u, buf, size))
31593 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31594 return -EFAULT;
31595
31596 *off += size;
31597 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31598 index 14599e2..711c965 100644
31599 --- a/drivers/hid/usbhid/hiddev.c
31600 +++ b/drivers/hid/usbhid/hiddev.c
31601 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31602 break;
31603
31604 case HIDIOCAPPLICATION:
31605 - if (arg < 0 || arg >= hid->maxapplication)
31606 + if (arg >= hid->maxapplication)
31607 break;
31608
31609 for (i = 0; i < hid->maxcollection; i++)
31610 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31611 index f4c3d28..82f45a9 100644
31612 --- a/drivers/hv/channel.c
31613 +++ b/drivers/hv/channel.c
31614 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31615 int ret = 0;
31616 int t;
31617
31618 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31619 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31620 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31621 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31622
31623 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31624 if (ret)
31625 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31626 index 86f8885..ab9cb2b 100644
31627 --- a/drivers/hv/hv.c
31628 +++ b/drivers/hv/hv.c
31629 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31630 u64 output_address = (output) ? virt_to_phys(output) : 0;
31631 u32 output_address_hi = output_address >> 32;
31632 u32 output_address_lo = output_address & 0xFFFFFFFF;
31633 - void *hypercall_page = hv_context.hypercall_page;
31634 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31635
31636 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31637 "=a"(hv_status_lo) : "d" (control_hi),
31638 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31639 index 0614ff3..f0b2b5c 100644
31640 --- a/drivers/hv/hyperv_vmbus.h
31641 +++ b/drivers/hv/hyperv_vmbus.h
31642 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31643 struct vmbus_connection {
31644 enum vmbus_connect_state conn_state;
31645
31646 - atomic_t next_gpadl_handle;
31647 + atomic_unchecked_t next_gpadl_handle;
31648
31649 /*
31650 * Represents channel interrupts. Each bit position represents a
31651 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31652 index 4748086..3abf845 100644
31653 --- a/drivers/hv/vmbus_drv.c
31654 +++ b/drivers/hv/vmbus_drv.c
31655 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31656 {
31657 int ret = 0;
31658
31659 - static atomic_t device_num = ATOMIC_INIT(0);
31660 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31661
31662 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31663 - atomic_inc_return(&device_num));
31664 + atomic_inc_return_unchecked(&device_num));
31665
31666 child_device_obj->device.bus = &hv_bus;
31667 child_device_obj->device.parent = &hv_acpi_dev->dev;
31668 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31669 index 8b011d0..3de24a1 100644
31670 --- a/drivers/hwmon/sht15.c
31671 +++ b/drivers/hwmon/sht15.c
31672 @@ -166,7 +166,7 @@ struct sht15_data {
31673 int supply_uV;
31674 bool supply_uV_valid;
31675 struct work_struct update_supply_work;
31676 - atomic_t interrupt_handled;
31677 + atomic_unchecked_t interrupt_handled;
31678 };
31679
31680 /**
31681 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31682 return ret;
31683
31684 gpio_direction_input(data->pdata->gpio_data);
31685 - atomic_set(&data->interrupt_handled, 0);
31686 + atomic_set_unchecked(&data->interrupt_handled, 0);
31687
31688 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31689 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31690 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31691 /* Only relevant if the interrupt hasn't occurred. */
31692 - if (!atomic_read(&data->interrupt_handled))
31693 + if (!atomic_read_unchecked(&data->interrupt_handled))
31694 schedule_work(&data->read_work);
31695 }
31696 ret = wait_event_timeout(data->wait_queue,
31697 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31698
31699 /* First disable the interrupt */
31700 disable_irq_nosync(irq);
31701 - atomic_inc(&data->interrupt_handled);
31702 + atomic_inc_unchecked(&data->interrupt_handled);
31703 /* Then schedule a reading work struct */
31704 if (data->state != SHT15_READING_NOTHING)
31705 schedule_work(&data->read_work);
31706 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31707 * If not, then start the interrupt again - care here as could
31708 * have gone low in meantime so verify it hasn't!
31709 */
31710 - atomic_set(&data->interrupt_handled, 0);
31711 + atomic_set_unchecked(&data->interrupt_handled, 0);
31712 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31713 /* If still not occurred or another handler was scheduled */
31714 if (gpio_get_value(data->pdata->gpio_data)
31715 - || atomic_read(&data->interrupt_handled))
31716 + || atomic_read_unchecked(&data->interrupt_handled))
31717 return;
31718 }
31719
31720 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31721 index 378fcb5..5e91fa8 100644
31722 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31723 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31724 @@ -43,7 +43,7 @@
31725 extern struct i2c_adapter amd756_smbus;
31726
31727 static struct i2c_adapter *s4882_adapter;
31728 -static struct i2c_algorithm *s4882_algo;
31729 +static i2c_algorithm_no_const *s4882_algo;
31730
31731 /* Wrapper access functions for multiplexed SMBus */
31732 static DEFINE_MUTEX(amd756_lock);
31733 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31734 index 29015eb..af2d8e9 100644
31735 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31736 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31737 @@ -41,7 +41,7 @@
31738 extern struct i2c_adapter *nforce2_smbus;
31739
31740 static struct i2c_adapter *s4985_adapter;
31741 -static struct i2c_algorithm *s4985_algo;
31742 +static i2c_algorithm_no_const *s4985_algo;
31743
31744 /* Wrapper access functions for multiplexed SMBus */
31745 static DEFINE_MUTEX(nforce2_lock);
31746 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31747 index 1038c38..eb92f51 100644
31748 --- a/drivers/i2c/i2c-mux.c
31749 +++ b/drivers/i2c/i2c-mux.c
31750 @@ -30,7 +30,7 @@
31751 /* multiplexer per channel data */
31752 struct i2c_mux_priv {
31753 struct i2c_adapter adap;
31754 - struct i2c_algorithm algo;
31755 + i2c_algorithm_no_const algo;
31756
31757 struct i2c_adapter *parent;
31758 void *mux_priv; /* the mux chip/device */
31759 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31760 index 57d00ca..0145194 100644
31761 --- a/drivers/ide/aec62xx.c
31762 +++ b/drivers/ide/aec62xx.c
31763 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31764 .cable_detect = atp86x_cable_detect,
31765 };
31766
31767 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31768 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31769 { /* 0: AEC6210 */
31770 .name = DRV_NAME,
31771 .init_chipset = init_chipset_aec62xx,
31772 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31773 index 2c8016a..911a27c 100644
31774 --- a/drivers/ide/alim15x3.c
31775 +++ b/drivers/ide/alim15x3.c
31776 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31777 .dma_sff_read_status = ide_dma_sff_read_status,
31778 };
31779
31780 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31781 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31782 .name = DRV_NAME,
31783 .init_chipset = init_chipset_ali15x3,
31784 .init_hwif = init_hwif_ali15x3,
31785 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31786 index 3747b25..56fc995 100644
31787 --- a/drivers/ide/amd74xx.c
31788 +++ b/drivers/ide/amd74xx.c
31789 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31790 .udma_mask = udma, \
31791 }
31792
31793 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31794 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31795 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31796 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31797 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31798 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31799 index 15f0ead..cb43480 100644
31800 --- a/drivers/ide/atiixp.c
31801 +++ b/drivers/ide/atiixp.c
31802 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31803 .cable_detect = atiixp_cable_detect,
31804 };
31805
31806 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31807 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31808 { /* 0: IXP200/300/400/700 */
31809 .name = DRV_NAME,
31810 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31811 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31812 index 5f80312..d1fc438 100644
31813 --- a/drivers/ide/cmd64x.c
31814 +++ b/drivers/ide/cmd64x.c
31815 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31816 .dma_sff_read_status = ide_dma_sff_read_status,
31817 };
31818
31819 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31820 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31821 { /* 0: CMD643 */
31822 .name = DRV_NAME,
31823 .init_chipset = init_chipset_cmd64x,
31824 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31825 index 2c1e5f7..1444762 100644
31826 --- a/drivers/ide/cs5520.c
31827 +++ b/drivers/ide/cs5520.c
31828 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31829 .set_dma_mode = cs5520_set_dma_mode,
31830 };
31831
31832 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31833 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31834 .name = DRV_NAME,
31835 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31836 .port_ops = &cs5520_port_ops,
31837 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31838 index 4dc4eb9..49b40ad 100644
31839 --- a/drivers/ide/cs5530.c
31840 +++ b/drivers/ide/cs5530.c
31841 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31842 .udma_filter = cs5530_udma_filter,
31843 };
31844
31845 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31846 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31847 .name = DRV_NAME,
31848 .init_chipset = init_chipset_cs5530,
31849 .init_hwif = init_hwif_cs5530,
31850 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31851 index 5059faf..18d4c85 100644
31852 --- a/drivers/ide/cs5535.c
31853 +++ b/drivers/ide/cs5535.c
31854 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31855 .cable_detect = cs5535_cable_detect,
31856 };
31857
31858 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31859 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31860 .name = DRV_NAME,
31861 .port_ops = &cs5535_port_ops,
31862 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31863 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31864 index 847553f..3ffb49d 100644
31865 --- a/drivers/ide/cy82c693.c
31866 +++ b/drivers/ide/cy82c693.c
31867 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31868 .set_dma_mode = cy82c693_set_dma_mode,
31869 };
31870
31871 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31872 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31873 .name = DRV_NAME,
31874 .init_iops = init_iops_cy82c693,
31875 .port_ops = &cy82c693_port_ops,
31876 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31877 index 58c51cd..4aec3b8 100644
31878 --- a/drivers/ide/hpt366.c
31879 +++ b/drivers/ide/hpt366.c
31880 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31881 }
31882 };
31883
31884 -static const struct hpt_info hpt36x __devinitdata = {
31885 +static const struct hpt_info hpt36x __devinitconst = {
31886 .chip_name = "HPT36x",
31887 .chip_type = HPT36x,
31888 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31889 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31890 .timings = &hpt36x_timings
31891 };
31892
31893 -static const struct hpt_info hpt370 __devinitdata = {
31894 +static const struct hpt_info hpt370 __devinitconst = {
31895 .chip_name = "HPT370",
31896 .chip_type = HPT370,
31897 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31898 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31899 .timings = &hpt37x_timings
31900 };
31901
31902 -static const struct hpt_info hpt370a __devinitdata = {
31903 +static const struct hpt_info hpt370a __devinitconst = {
31904 .chip_name = "HPT370A",
31905 .chip_type = HPT370A,
31906 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31907 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31908 .timings = &hpt37x_timings
31909 };
31910
31911 -static const struct hpt_info hpt374 __devinitdata = {
31912 +static const struct hpt_info hpt374 __devinitconst = {
31913 .chip_name = "HPT374",
31914 .chip_type = HPT374,
31915 .udma_mask = ATA_UDMA5,
31916 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31917 .timings = &hpt37x_timings
31918 };
31919
31920 -static const struct hpt_info hpt372 __devinitdata = {
31921 +static const struct hpt_info hpt372 __devinitconst = {
31922 .chip_name = "HPT372",
31923 .chip_type = HPT372,
31924 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31925 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31926 .timings = &hpt37x_timings
31927 };
31928
31929 -static const struct hpt_info hpt372a __devinitdata = {
31930 +static const struct hpt_info hpt372a __devinitconst = {
31931 .chip_name = "HPT372A",
31932 .chip_type = HPT372A,
31933 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31934 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31935 .timings = &hpt37x_timings
31936 };
31937
31938 -static const struct hpt_info hpt302 __devinitdata = {
31939 +static const struct hpt_info hpt302 __devinitconst = {
31940 .chip_name = "HPT302",
31941 .chip_type = HPT302,
31942 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31943 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31944 .timings = &hpt37x_timings
31945 };
31946
31947 -static const struct hpt_info hpt371 __devinitdata = {
31948 +static const struct hpt_info hpt371 __devinitconst = {
31949 .chip_name = "HPT371",
31950 .chip_type = HPT371,
31951 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31952 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31953 .timings = &hpt37x_timings
31954 };
31955
31956 -static const struct hpt_info hpt372n __devinitdata = {
31957 +static const struct hpt_info hpt372n __devinitconst = {
31958 .chip_name = "HPT372N",
31959 .chip_type = HPT372N,
31960 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31961 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31962 .timings = &hpt37x_timings
31963 };
31964
31965 -static const struct hpt_info hpt302n __devinitdata = {
31966 +static const struct hpt_info hpt302n __devinitconst = {
31967 .chip_name = "HPT302N",
31968 .chip_type = HPT302N,
31969 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31970 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31971 .timings = &hpt37x_timings
31972 };
31973
31974 -static const struct hpt_info hpt371n __devinitdata = {
31975 +static const struct hpt_info hpt371n __devinitconst = {
31976 .chip_name = "HPT371N",
31977 .chip_type = HPT371N,
31978 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31979 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31980 .dma_sff_read_status = ide_dma_sff_read_status,
31981 };
31982
31983 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31984 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31985 { /* 0: HPT36x */
31986 .name = DRV_NAME,
31987 .init_chipset = init_chipset_hpt366,
31988 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31989 index 8126824..55a2798 100644
31990 --- a/drivers/ide/ide-cd.c
31991 +++ b/drivers/ide/ide-cd.c
31992 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31993 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31994 if ((unsigned long)buf & alignment
31995 || blk_rq_bytes(rq) & q->dma_pad_mask
31996 - || object_is_on_stack(buf))
31997 + || object_starts_on_stack(buf))
31998 drive->dma = 0;
31999 }
32000 }
32001 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32002 index 7f56b73..dab5b67 100644
32003 --- a/drivers/ide/ide-pci-generic.c
32004 +++ b/drivers/ide/ide-pci-generic.c
32005 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32006 .udma_mask = ATA_UDMA6, \
32007 }
32008
32009 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32010 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32011 /* 0: Unknown */
32012 DECLARE_GENERIC_PCI_DEV(0),
32013
32014 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32015 index 560e66d..d5dd180 100644
32016 --- a/drivers/ide/it8172.c
32017 +++ b/drivers/ide/it8172.c
32018 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32019 .set_dma_mode = it8172_set_dma_mode,
32020 };
32021
32022 -static const struct ide_port_info it8172_port_info __devinitdata = {
32023 +static const struct ide_port_info it8172_port_info __devinitconst = {
32024 .name = DRV_NAME,
32025 .port_ops = &it8172_port_ops,
32026 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32027 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32028 index 46816ba..1847aeb 100644
32029 --- a/drivers/ide/it8213.c
32030 +++ b/drivers/ide/it8213.c
32031 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32032 .cable_detect = it8213_cable_detect,
32033 };
32034
32035 -static const struct ide_port_info it8213_chipset __devinitdata = {
32036 +static const struct ide_port_info it8213_chipset __devinitconst = {
32037 .name = DRV_NAME,
32038 .enablebits = { {0x41, 0x80, 0x80} },
32039 .port_ops = &it8213_port_ops,
32040 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32041 index 2e3169f..c5611db 100644
32042 --- a/drivers/ide/it821x.c
32043 +++ b/drivers/ide/it821x.c
32044 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32045 .cable_detect = it821x_cable_detect,
32046 };
32047
32048 -static const struct ide_port_info it821x_chipset __devinitdata = {
32049 +static const struct ide_port_info it821x_chipset __devinitconst = {
32050 .name = DRV_NAME,
32051 .init_chipset = init_chipset_it821x,
32052 .init_hwif = init_hwif_it821x,
32053 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32054 index 74c2c4a..efddd7d 100644
32055 --- a/drivers/ide/jmicron.c
32056 +++ b/drivers/ide/jmicron.c
32057 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32058 .cable_detect = jmicron_cable_detect,
32059 };
32060
32061 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32062 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32063 .name = DRV_NAME,
32064 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32065 .port_ops = &jmicron_port_ops,
32066 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32067 index 95327a2..73f78d8 100644
32068 --- a/drivers/ide/ns87415.c
32069 +++ b/drivers/ide/ns87415.c
32070 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32071 .dma_sff_read_status = superio_dma_sff_read_status,
32072 };
32073
32074 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32075 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32076 .name = DRV_NAME,
32077 .init_hwif = init_hwif_ns87415,
32078 .tp_ops = &ns87415_tp_ops,
32079 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32080 index 1a53a4c..39edc66 100644
32081 --- a/drivers/ide/opti621.c
32082 +++ b/drivers/ide/opti621.c
32083 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32084 .set_pio_mode = opti621_set_pio_mode,
32085 };
32086
32087 -static const struct ide_port_info opti621_chipset __devinitdata = {
32088 +static const struct ide_port_info opti621_chipset __devinitconst = {
32089 .name = DRV_NAME,
32090 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32091 .port_ops = &opti621_port_ops,
32092 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32093 index 9546fe2..2e5ceb6 100644
32094 --- a/drivers/ide/pdc202xx_new.c
32095 +++ b/drivers/ide/pdc202xx_new.c
32096 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32097 .udma_mask = udma, \
32098 }
32099
32100 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32101 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32102 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32103 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32104 };
32105 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32106 index 3a35ec6..5634510 100644
32107 --- a/drivers/ide/pdc202xx_old.c
32108 +++ b/drivers/ide/pdc202xx_old.c
32109 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32110 .max_sectors = sectors, \
32111 }
32112
32113 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32114 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32115 { /* 0: PDC20246 */
32116 .name = DRV_NAME,
32117 .init_chipset = init_chipset_pdc202xx,
32118 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32119 index 1892e81..fe0fd60 100644
32120 --- a/drivers/ide/piix.c
32121 +++ b/drivers/ide/piix.c
32122 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32123 .udma_mask = udma, \
32124 }
32125
32126 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32127 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32128 /* 0: MPIIX */
32129 { /*
32130 * MPIIX actually has only a single IDE channel mapped to
32131 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32132 index a6414a8..c04173e 100644
32133 --- a/drivers/ide/rz1000.c
32134 +++ b/drivers/ide/rz1000.c
32135 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32136 }
32137 }
32138
32139 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32140 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32141 .name = DRV_NAME,
32142 .host_flags = IDE_HFLAG_NO_DMA,
32143 };
32144 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32145 index 356b9b5..d4758eb 100644
32146 --- a/drivers/ide/sc1200.c
32147 +++ b/drivers/ide/sc1200.c
32148 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32149 .dma_sff_read_status = ide_dma_sff_read_status,
32150 };
32151
32152 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32153 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32154 .name = DRV_NAME,
32155 .port_ops = &sc1200_port_ops,
32156 .dma_ops = &sc1200_dma_ops,
32157 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32158 index b7f5b0c..9701038 100644
32159 --- a/drivers/ide/scc_pata.c
32160 +++ b/drivers/ide/scc_pata.c
32161 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32162 .dma_sff_read_status = scc_dma_sff_read_status,
32163 };
32164
32165 -static const struct ide_port_info scc_chipset __devinitdata = {
32166 +static const struct ide_port_info scc_chipset __devinitconst = {
32167 .name = "sccIDE",
32168 .init_iops = init_iops_scc,
32169 .init_dma = scc_init_dma,
32170 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32171 index 35fb8da..24d72ef 100644
32172 --- a/drivers/ide/serverworks.c
32173 +++ b/drivers/ide/serverworks.c
32174 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32175 .cable_detect = svwks_cable_detect,
32176 };
32177
32178 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32179 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32180 { /* 0: OSB4 */
32181 .name = DRV_NAME,
32182 .init_chipset = init_chipset_svwks,
32183 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32184 index ddeda44..46f7e30 100644
32185 --- a/drivers/ide/siimage.c
32186 +++ b/drivers/ide/siimage.c
32187 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32188 .udma_mask = ATA_UDMA6, \
32189 }
32190
32191 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32192 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32193 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32194 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32195 };
32196 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32197 index 4a00225..09e61b4 100644
32198 --- a/drivers/ide/sis5513.c
32199 +++ b/drivers/ide/sis5513.c
32200 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32201 .cable_detect = sis_cable_detect,
32202 };
32203
32204 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32205 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32206 .name = DRV_NAME,
32207 .init_chipset = init_chipset_sis5513,
32208 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32209 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32210 index f21dc2a..d051cd2 100644
32211 --- a/drivers/ide/sl82c105.c
32212 +++ b/drivers/ide/sl82c105.c
32213 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32214 .dma_sff_read_status = ide_dma_sff_read_status,
32215 };
32216
32217 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32218 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32219 .name = DRV_NAME,
32220 .init_chipset = init_chipset_sl82c105,
32221 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32222 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32223 index 864ffe0..863a5e9 100644
32224 --- a/drivers/ide/slc90e66.c
32225 +++ b/drivers/ide/slc90e66.c
32226 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32227 .cable_detect = slc90e66_cable_detect,
32228 };
32229
32230 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32231 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32232 .name = DRV_NAME,
32233 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32234 .port_ops = &slc90e66_port_ops,
32235 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32236 index 4799d5c..1794678 100644
32237 --- a/drivers/ide/tc86c001.c
32238 +++ b/drivers/ide/tc86c001.c
32239 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32240 .dma_sff_read_status = ide_dma_sff_read_status,
32241 };
32242
32243 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32244 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32245 .name = DRV_NAME,
32246 .init_hwif = init_hwif_tc86c001,
32247 .port_ops = &tc86c001_port_ops,
32248 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32249 index 281c914..55ce1b8 100644
32250 --- a/drivers/ide/triflex.c
32251 +++ b/drivers/ide/triflex.c
32252 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32253 .set_dma_mode = triflex_set_mode,
32254 };
32255
32256 -static const struct ide_port_info triflex_device __devinitdata = {
32257 +static const struct ide_port_info triflex_device __devinitconst = {
32258 .name = DRV_NAME,
32259 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32260 .port_ops = &triflex_port_ops,
32261 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32262 index 4b42ca0..e494a98 100644
32263 --- a/drivers/ide/trm290.c
32264 +++ b/drivers/ide/trm290.c
32265 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32266 .dma_check = trm290_dma_check,
32267 };
32268
32269 -static const struct ide_port_info trm290_chipset __devinitdata = {
32270 +static const struct ide_port_info trm290_chipset __devinitconst = {
32271 .name = DRV_NAME,
32272 .init_hwif = init_hwif_trm290,
32273 .tp_ops = &trm290_tp_ops,
32274 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32275 index f46f49c..eb77678 100644
32276 --- a/drivers/ide/via82cxxx.c
32277 +++ b/drivers/ide/via82cxxx.c
32278 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32279 .cable_detect = via82cxxx_cable_detect,
32280 };
32281
32282 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32283 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32284 .name = DRV_NAME,
32285 .init_chipset = init_chipset_via82cxxx,
32286 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32287 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32288 index 73d4531..c90cd2d 100644
32289 --- a/drivers/ieee802154/fakehard.c
32290 +++ b/drivers/ieee802154/fakehard.c
32291 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32292 phy->transmit_power = 0xbf;
32293
32294 dev->netdev_ops = &fake_ops;
32295 - dev->ml_priv = &fake_mlme;
32296 + dev->ml_priv = (void *)&fake_mlme;
32297
32298 priv = netdev_priv(dev);
32299 priv->phy = phy;
32300 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32301 index d67999f..4c5d083 100644
32302 --- a/drivers/infiniband/core/cm.c
32303 +++ b/drivers/infiniband/core/cm.c
32304 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32305
32306 struct cm_counter_group {
32307 struct kobject obj;
32308 - atomic_long_t counter[CM_ATTR_COUNT];
32309 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32310 };
32311
32312 struct cm_counter_attribute {
32313 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32314 struct ib_mad_send_buf *msg = NULL;
32315 int ret;
32316
32317 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32318 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32319 counter[CM_REQ_COUNTER]);
32320
32321 /* Quick state check to discard duplicate REQs. */
32322 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32323 if (!cm_id_priv)
32324 return;
32325
32326 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32327 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32328 counter[CM_REP_COUNTER]);
32329 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32330 if (ret)
32331 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32332 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32333 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32334 spin_unlock_irq(&cm_id_priv->lock);
32335 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32336 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32337 counter[CM_RTU_COUNTER]);
32338 goto out;
32339 }
32340 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32341 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32342 dreq_msg->local_comm_id);
32343 if (!cm_id_priv) {
32344 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32345 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32346 counter[CM_DREQ_COUNTER]);
32347 cm_issue_drep(work->port, work->mad_recv_wc);
32348 return -EINVAL;
32349 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32350 case IB_CM_MRA_REP_RCVD:
32351 break;
32352 case IB_CM_TIMEWAIT:
32353 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32354 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32355 counter[CM_DREQ_COUNTER]);
32356 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32357 goto unlock;
32358 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32359 cm_free_msg(msg);
32360 goto deref;
32361 case IB_CM_DREQ_RCVD:
32362 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32363 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32364 counter[CM_DREQ_COUNTER]);
32365 goto unlock;
32366 default:
32367 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32368 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32369 cm_id_priv->msg, timeout)) {
32370 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32371 - atomic_long_inc(&work->port->
32372 + atomic_long_inc_unchecked(&work->port->
32373 counter_group[CM_RECV_DUPLICATES].
32374 counter[CM_MRA_COUNTER]);
32375 goto out;
32376 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32377 break;
32378 case IB_CM_MRA_REQ_RCVD:
32379 case IB_CM_MRA_REP_RCVD:
32380 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32381 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32382 counter[CM_MRA_COUNTER]);
32383 /* fall through */
32384 default:
32385 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32386 case IB_CM_LAP_IDLE:
32387 break;
32388 case IB_CM_MRA_LAP_SENT:
32389 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32390 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32391 counter[CM_LAP_COUNTER]);
32392 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32393 goto unlock;
32394 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32395 cm_free_msg(msg);
32396 goto deref;
32397 case IB_CM_LAP_RCVD:
32398 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32399 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32400 counter[CM_LAP_COUNTER]);
32401 goto unlock;
32402 default:
32403 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32404 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32405 if (cur_cm_id_priv) {
32406 spin_unlock_irq(&cm.lock);
32407 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32408 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32409 counter[CM_SIDR_REQ_COUNTER]);
32410 goto out; /* Duplicate message. */
32411 }
32412 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32413 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32414 msg->retries = 1;
32415
32416 - atomic_long_add(1 + msg->retries,
32417 + atomic_long_add_unchecked(1 + msg->retries,
32418 &port->counter_group[CM_XMIT].counter[attr_index]);
32419 if (msg->retries)
32420 - atomic_long_add(msg->retries,
32421 + atomic_long_add_unchecked(msg->retries,
32422 &port->counter_group[CM_XMIT_RETRIES].
32423 counter[attr_index]);
32424
32425 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32426 }
32427
32428 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32429 - atomic_long_inc(&port->counter_group[CM_RECV].
32430 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32431 counter[attr_id - CM_ATTR_ID_OFFSET]);
32432
32433 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32434 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32435 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32436
32437 return sprintf(buf, "%ld\n",
32438 - atomic_long_read(&group->counter[cm_attr->index]));
32439 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32440 }
32441
32442 static const struct sysfs_ops cm_counter_ops = {
32443 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32444 index 176c8f9..2627b62 100644
32445 --- a/drivers/infiniband/core/fmr_pool.c
32446 +++ b/drivers/infiniband/core/fmr_pool.c
32447 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32448
32449 struct task_struct *thread;
32450
32451 - atomic_t req_ser;
32452 - atomic_t flush_ser;
32453 + atomic_unchecked_t req_ser;
32454 + atomic_unchecked_t flush_ser;
32455
32456 wait_queue_head_t force_wait;
32457 };
32458 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32459 struct ib_fmr_pool *pool = pool_ptr;
32460
32461 do {
32462 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32463 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32464 ib_fmr_batch_release(pool);
32465
32466 - atomic_inc(&pool->flush_ser);
32467 + atomic_inc_unchecked(&pool->flush_ser);
32468 wake_up_interruptible(&pool->force_wait);
32469
32470 if (pool->flush_function)
32471 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32472 }
32473
32474 set_current_state(TASK_INTERRUPTIBLE);
32475 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32476 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32477 !kthread_should_stop())
32478 schedule();
32479 __set_current_state(TASK_RUNNING);
32480 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32481 pool->dirty_watermark = params->dirty_watermark;
32482 pool->dirty_len = 0;
32483 spin_lock_init(&pool->pool_lock);
32484 - atomic_set(&pool->req_ser, 0);
32485 - atomic_set(&pool->flush_ser, 0);
32486 + atomic_set_unchecked(&pool->req_ser, 0);
32487 + atomic_set_unchecked(&pool->flush_ser, 0);
32488 init_waitqueue_head(&pool->force_wait);
32489
32490 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32491 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32492 }
32493 spin_unlock_irq(&pool->pool_lock);
32494
32495 - serial = atomic_inc_return(&pool->req_ser);
32496 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32497 wake_up_process(pool->thread);
32498
32499 if (wait_event_interruptible(pool->force_wait,
32500 - atomic_read(&pool->flush_ser) - serial >= 0))
32501 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32502 return -EINTR;
32503
32504 return 0;
32505 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32506 } else {
32507 list_add_tail(&fmr->list, &pool->dirty_list);
32508 if (++pool->dirty_len >= pool->dirty_watermark) {
32509 - atomic_inc(&pool->req_ser);
32510 + atomic_inc_unchecked(&pool->req_ser);
32511 wake_up_process(pool->thread);
32512 }
32513 }
32514 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32515 index 57e07c6..56d09d4 100644
32516 --- a/drivers/infiniband/hw/cxgb4/mem.c
32517 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32518 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32519 int err;
32520 struct fw_ri_tpte tpt;
32521 u32 stag_idx;
32522 - static atomic_t key;
32523 + static atomic_unchecked_t key;
32524
32525 if (c4iw_fatal_error(rdev))
32526 return -EIO;
32527 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32528 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32529 rdev->stats.stag.max = rdev->stats.stag.cur;
32530 mutex_unlock(&rdev->stats.lock);
32531 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32532 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32533 }
32534 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32535 __func__, stag_state, type, pdid, stag_idx);
32536 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32537 index 79b3dbc..96e5fcc 100644
32538 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32539 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32540 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32541 struct ib_atomic_eth *ateth;
32542 struct ipath_ack_entry *e;
32543 u64 vaddr;
32544 - atomic64_t *maddr;
32545 + atomic64_unchecked_t *maddr;
32546 u64 sdata;
32547 u32 rkey;
32548 u8 next;
32549 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32550 IB_ACCESS_REMOTE_ATOMIC)))
32551 goto nack_acc_unlck;
32552 /* Perform atomic OP and save result. */
32553 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32554 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32555 sdata = be64_to_cpu(ateth->swap_data);
32556 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32557 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32558 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32559 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32560 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32561 be64_to_cpu(ateth->compare_data),
32562 sdata);
32563 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32564 index 1f95bba..9530f87 100644
32565 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32566 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32567 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32568 unsigned long flags;
32569 struct ib_wc wc;
32570 u64 sdata;
32571 - atomic64_t *maddr;
32572 + atomic64_unchecked_t *maddr;
32573 enum ib_wc_status send_status;
32574
32575 /*
32576 @@ -382,11 +382,11 @@ again:
32577 IB_ACCESS_REMOTE_ATOMIC)))
32578 goto acc_err;
32579 /* Perform atomic OP and save result. */
32580 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32581 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32582 sdata = wqe->wr.wr.atomic.compare_add;
32583 *(u64 *) sqp->s_sge.sge.vaddr =
32584 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32585 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32586 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32587 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32588 sdata, wqe->wr.wr.atomic.swap);
32589 goto send_comp;
32590 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32591 index 7140199..da60063 100644
32592 --- a/drivers/infiniband/hw/nes/nes.c
32593 +++ b/drivers/infiniband/hw/nes/nes.c
32594 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32595 LIST_HEAD(nes_adapter_list);
32596 static LIST_HEAD(nes_dev_list);
32597
32598 -atomic_t qps_destroyed;
32599 +atomic_unchecked_t qps_destroyed;
32600
32601 static unsigned int ee_flsh_adapter;
32602 static unsigned int sysfs_nonidx_addr;
32603 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32604 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32605 struct nes_adapter *nesadapter = nesdev->nesadapter;
32606
32607 - atomic_inc(&qps_destroyed);
32608 + atomic_inc_unchecked(&qps_destroyed);
32609
32610 /* Free the control structures */
32611
32612 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32613 index c438e46..ca30356 100644
32614 --- a/drivers/infiniband/hw/nes/nes.h
32615 +++ b/drivers/infiniband/hw/nes/nes.h
32616 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32617 extern unsigned int wqm_quanta;
32618 extern struct list_head nes_adapter_list;
32619
32620 -extern atomic_t cm_connects;
32621 -extern atomic_t cm_accepts;
32622 -extern atomic_t cm_disconnects;
32623 -extern atomic_t cm_closes;
32624 -extern atomic_t cm_connecteds;
32625 -extern atomic_t cm_connect_reqs;
32626 -extern atomic_t cm_rejects;
32627 -extern atomic_t mod_qp_timouts;
32628 -extern atomic_t qps_created;
32629 -extern atomic_t qps_destroyed;
32630 -extern atomic_t sw_qps_destroyed;
32631 +extern atomic_unchecked_t cm_connects;
32632 +extern atomic_unchecked_t cm_accepts;
32633 +extern atomic_unchecked_t cm_disconnects;
32634 +extern atomic_unchecked_t cm_closes;
32635 +extern atomic_unchecked_t cm_connecteds;
32636 +extern atomic_unchecked_t cm_connect_reqs;
32637 +extern atomic_unchecked_t cm_rejects;
32638 +extern atomic_unchecked_t mod_qp_timouts;
32639 +extern atomic_unchecked_t qps_created;
32640 +extern atomic_unchecked_t qps_destroyed;
32641 +extern atomic_unchecked_t sw_qps_destroyed;
32642 extern u32 mh_detected;
32643 extern u32 mh_pauses_sent;
32644 extern u32 cm_packets_sent;
32645 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32646 extern u32 cm_packets_received;
32647 extern u32 cm_packets_dropped;
32648 extern u32 cm_packets_retrans;
32649 -extern atomic_t cm_listens_created;
32650 -extern atomic_t cm_listens_destroyed;
32651 +extern atomic_unchecked_t cm_listens_created;
32652 +extern atomic_unchecked_t cm_listens_destroyed;
32653 extern u32 cm_backlog_drops;
32654 -extern atomic_t cm_loopbacks;
32655 -extern atomic_t cm_nodes_created;
32656 -extern atomic_t cm_nodes_destroyed;
32657 -extern atomic_t cm_accel_dropped_pkts;
32658 -extern atomic_t cm_resets_recvd;
32659 -extern atomic_t pau_qps_created;
32660 -extern atomic_t pau_qps_destroyed;
32661 +extern atomic_unchecked_t cm_loopbacks;
32662 +extern atomic_unchecked_t cm_nodes_created;
32663 +extern atomic_unchecked_t cm_nodes_destroyed;
32664 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32665 +extern atomic_unchecked_t cm_resets_recvd;
32666 +extern atomic_unchecked_t pau_qps_created;
32667 +extern atomic_unchecked_t pau_qps_destroyed;
32668
32669 extern u32 int_mod_timer_init;
32670 extern u32 int_mod_cq_depth_256;
32671 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32672 index 020e95c..fbb3450 100644
32673 --- a/drivers/infiniband/hw/nes/nes_cm.c
32674 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32675 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32676 u32 cm_packets_retrans;
32677 u32 cm_packets_created;
32678 u32 cm_packets_received;
32679 -atomic_t cm_listens_created;
32680 -atomic_t cm_listens_destroyed;
32681 +atomic_unchecked_t cm_listens_created;
32682 +atomic_unchecked_t cm_listens_destroyed;
32683 u32 cm_backlog_drops;
32684 -atomic_t cm_loopbacks;
32685 -atomic_t cm_nodes_created;
32686 -atomic_t cm_nodes_destroyed;
32687 -atomic_t cm_accel_dropped_pkts;
32688 -atomic_t cm_resets_recvd;
32689 +atomic_unchecked_t cm_loopbacks;
32690 +atomic_unchecked_t cm_nodes_created;
32691 +atomic_unchecked_t cm_nodes_destroyed;
32692 +atomic_unchecked_t cm_accel_dropped_pkts;
32693 +atomic_unchecked_t cm_resets_recvd;
32694
32695 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32696 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32697 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32698
32699 static struct nes_cm_core *g_cm_core;
32700
32701 -atomic_t cm_connects;
32702 -atomic_t cm_accepts;
32703 -atomic_t cm_disconnects;
32704 -atomic_t cm_closes;
32705 -atomic_t cm_connecteds;
32706 -atomic_t cm_connect_reqs;
32707 -atomic_t cm_rejects;
32708 +atomic_unchecked_t cm_connects;
32709 +atomic_unchecked_t cm_accepts;
32710 +atomic_unchecked_t cm_disconnects;
32711 +atomic_unchecked_t cm_closes;
32712 +atomic_unchecked_t cm_connecteds;
32713 +atomic_unchecked_t cm_connect_reqs;
32714 +atomic_unchecked_t cm_rejects;
32715
32716 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32717 {
32718 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32719 kfree(listener);
32720 listener = NULL;
32721 ret = 0;
32722 - atomic_inc(&cm_listens_destroyed);
32723 + atomic_inc_unchecked(&cm_listens_destroyed);
32724 } else {
32725 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32726 }
32727 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32728 cm_node->rem_mac);
32729
32730 add_hte_node(cm_core, cm_node);
32731 - atomic_inc(&cm_nodes_created);
32732 + atomic_inc_unchecked(&cm_nodes_created);
32733
32734 return cm_node;
32735 }
32736 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32737 }
32738
32739 atomic_dec(&cm_core->node_cnt);
32740 - atomic_inc(&cm_nodes_destroyed);
32741 + atomic_inc_unchecked(&cm_nodes_destroyed);
32742 nesqp = cm_node->nesqp;
32743 if (nesqp) {
32744 nesqp->cm_node = NULL;
32745 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32746
32747 static void drop_packet(struct sk_buff *skb)
32748 {
32749 - atomic_inc(&cm_accel_dropped_pkts);
32750 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32751 dev_kfree_skb_any(skb);
32752 }
32753
32754 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32755 {
32756
32757 int reset = 0; /* whether to send reset in case of err.. */
32758 - atomic_inc(&cm_resets_recvd);
32759 + atomic_inc_unchecked(&cm_resets_recvd);
32760 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32761 " refcnt=%d\n", cm_node, cm_node->state,
32762 atomic_read(&cm_node->ref_count));
32763 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32764 rem_ref_cm_node(cm_node->cm_core, cm_node);
32765 return NULL;
32766 }
32767 - atomic_inc(&cm_loopbacks);
32768 + atomic_inc_unchecked(&cm_loopbacks);
32769 loopbackremotenode->loopbackpartner = cm_node;
32770 loopbackremotenode->tcp_cntxt.rcv_wscale =
32771 NES_CM_DEFAULT_RCV_WND_SCALE;
32772 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32773 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32774 else {
32775 rem_ref_cm_node(cm_core, cm_node);
32776 - atomic_inc(&cm_accel_dropped_pkts);
32777 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32778 dev_kfree_skb_any(skb);
32779 }
32780 break;
32781 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32782
32783 if ((cm_id) && (cm_id->event_handler)) {
32784 if (issue_disconn) {
32785 - atomic_inc(&cm_disconnects);
32786 + atomic_inc_unchecked(&cm_disconnects);
32787 cm_event.event = IW_CM_EVENT_DISCONNECT;
32788 cm_event.status = disconn_status;
32789 cm_event.local_addr = cm_id->local_addr;
32790 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32791 }
32792
32793 if (issue_close) {
32794 - atomic_inc(&cm_closes);
32795 + atomic_inc_unchecked(&cm_closes);
32796 nes_disconnect(nesqp, 1);
32797
32798 cm_id->provider_data = nesqp;
32799 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32800
32801 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32802 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32803 - atomic_inc(&cm_accepts);
32804 + atomic_inc_unchecked(&cm_accepts);
32805
32806 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32807 netdev_refcnt_read(nesvnic->netdev));
32808 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32809 struct nes_cm_core *cm_core;
32810 u8 *start_buff;
32811
32812 - atomic_inc(&cm_rejects);
32813 + atomic_inc_unchecked(&cm_rejects);
32814 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32815 loopback = cm_node->loopbackpartner;
32816 cm_core = cm_node->cm_core;
32817 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32818 ntohl(cm_id->local_addr.sin_addr.s_addr),
32819 ntohs(cm_id->local_addr.sin_port));
32820
32821 - atomic_inc(&cm_connects);
32822 + atomic_inc_unchecked(&cm_connects);
32823 nesqp->active_conn = 1;
32824
32825 /* cache the cm_id in the qp */
32826 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32827 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32828 return err;
32829 }
32830 - atomic_inc(&cm_listens_created);
32831 + atomic_inc_unchecked(&cm_listens_created);
32832 }
32833
32834 cm_id->add_ref(cm_id);
32835 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32836
32837 if (nesqp->destroyed)
32838 return;
32839 - atomic_inc(&cm_connecteds);
32840 + atomic_inc_unchecked(&cm_connecteds);
32841 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32842 " local port 0x%04X. jiffies = %lu.\n",
32843 nesqp->hwqp.qp_id,
32844 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32845
32846 cm_id->add_ref(cm_id);
32847 ret = cm_id->event_handler(cm_id, &cm_event);
32848 - atomic_inc(&cm_closes);
32849 + atomic_inc_unchecked(&cm_closes);
32850 cm_event.event = IW_CM_EVENT_CLOSE;
32851 cm_event.status = 0;
32852 cm_event.provider_data = cm_id->provider_data;
32853 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32854 return;
32855 cm_id = cm_node->cm_id;
32856
32857 - atomic_inc(&cm_connect_reqs);
32858 + atomic_inc_unchecked(&cm_connect_reqs);
32859 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32860 cm_node, cm_id, jiffies);
32861
32862 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32863 return;
32864 cm_id = cm_node->cm_id;
32865
32866 - atomic_inc(&cm_connect_reqs);
32867 + atomic_inc_unchecked(&cm_connect_reqs);
32868 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32869 cm_node, cm_id, jiffies);
32870
32871 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32872 index 3ba7be3..c81f6ff 100644
32873 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32874 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32875 @@ -40,8 +40,8 @@
32876 #include "nes.h"
32877 #include "nes_mgt.h"
32878
32879 -atomic_t pau_qps_created;
32880 -atomic_t pau_qps_destroyed;
32881 +atomic_unchecked_t pau_qps_created;
32882 +atomic_unchecked_t pau_qps_destroyed;
32883
32884 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32885 {
32886 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32887 {
32888 struct sk_buff *skb;
32889 unsigned long flags;
32890 - atomic_inc(&pau_qps_destroyed);
32891 + atomic_inc_unchecked(&pau_qps_destroyed);
32892
32893 /* Free packets that have not yet been forwarded */
32894 /* Lock is acquired by skb_dequeue when removing the skb */
32895 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32896 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32897 skb_queue_head_init(&nesqp->pau_list);
32898 spin_lock_init(&nesqp->pau_lock);
32899 - atomic_inc(&pau_qps_created);
32900 + atomic_inc_unchecked(&pau_qps_created);
32901 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32902 }
32903
32904 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32905 index f3a3ecf..57d311d 100644
32906 --- a/drivers/infiniband/hw/nes/nes_nic.c
32907 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32908 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32909 target_stat_values[++index] = mh_detected;
32910 target_stat_values[++index] = mh_pauses_sent;
32911 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32912 - target_stat_values[++index] = atomic_read(&cm_connects);
32913 - target_stat_values[++index] = atomic_read(&cm_accepts);
32914 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32915 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32916 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32917 - target_stat_values[++index] = atomic_read(&cm_rejects);
32918 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32919 - target_stat_values[++index] = atomic_read(&qps_created);
32920 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32921 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32922 - target_stat_values[++index] = atomic_read(&cm_closes);
32923 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32924 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32925 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32926 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32927 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32928 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32929 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32930 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32931 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32932 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32933 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32934 target_stat_values[++index] = cm_packets_sent;
32935 target_stat_values[++index] = cm_packets_bounced;
32936 target_stat_values[++index] = cm_packets_created;
32937 target_stat_values[++index] = cm_packets_received;
32938 target_stat_values[++index] = cm_packets_dropped;
32939 target_stat_values[++index] = cm_packets_retrans;
32940 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32941 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32942 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32943 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32944 target_stat_values[++index] = cm_backlog_drops;
32945 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32946 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32947 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32948 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32949 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32950 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32951 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32952 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32953 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32954 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32955 target_stat_values[++index] = nesadapter->free_4kpbl;
32956 target_stat_values[++index] = nesadapter->free_256pbl;
32957 target_stat_values[++index] = int_mod_timer_init;
32958 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32959 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32960 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32961 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32962 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32963 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32964 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32965 }
32966
32967 /**
32968 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32969 index 8b8812d..a5e1133 100644
32970 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32971 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32972 @@ -46,9 +46,9 @@
32973
32974 #include <rdma/ib_umem.h>
32975
32976 -atomic_t mod_qp_timouts;
32977 -atomic_t qps_created;
32978 -atomic_t sw_qps_destroyed;
32979 +atomic_unchecked_t mod_qp_timouts;
32980 +atomic_unchecked_t qps_created;
32981 +atomic_unchecked_t sw_qps_destroyed;
32982
32983 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32984
32985 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32986 if (init_attr->create_flags)
32987 return ERR_PTR(-EINVAL);
32988
32989 - atomic_inc(&qps_created);
32990 + atomic_inc_unchecked(&qps_created);
32991 switch (init_attr->qp_type) {
32992 case IB_QPT_RC:
32993 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32994 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32995 struct iw_cm_event cm_event;
32996 int ret = 0;
32997
32998 - atomic_inc(&sw_qps_destroyed);
32999 + atomic_inc_unchecked(&sw_qps_destroyed);
33000 nesqp->destroyed = 1;
33001
33002 /* Blow away the connection if it exists. */
33003 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33004 index 7b1b8669..4b69f85 100644
33005 --- a/drivers/infiniband/hw/qib/qib.h
33006 +++ b/drivers/infiniband/hw/qib/qib.h
33007 @@ -51,6 +51,7 @@
33008 #include <linux/completion.h>
33009 #include <linux/kref.h>
33010 #include <linux/sched.h>
33011 +#include <linux/slab.h>
33012
33013 #include "qib_common.h"
33014 #include "qib_verbs.h"
33015 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33016 index da739d9..da1c7f4 100644
33017 --- a/drivers/input/gameport/gameport.c
33018 +++ b/drivers/input/gameport/gameport.c
33019 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33020 */
33021 static void gameport_init_port(struct gameport *gameport)
33022 {
33023 - static atomic_t gameport_no = ATOMIC_INIT(0);
33024 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33025
33026 __module_get(THIS_MODULE);
33027
33028 mutex_init(&gameport->drv_mutex);
33029 device_initialize(&gameport->dev);
33030 dev_set_name(&gameport->dev, "gameport%lu",
33031 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33032 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33033 gameport->dev.bus = &gameport_bus;
33034 gameport->dev.release = gameport_release_port;
33035 if (gameport->parent)
33036 diff --git a/drivers/input/input.c b/drivers/input/input.c
33037 index 8921c61..f5cd63d 100644
33038 --- a/drivers/input/input.c
33039 +++ b/drivers/input/input.c
33040 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33041 */
33042 int input_register_device(struct input_dev *dev)
33043 {
33044 - static atomic_t input_no = ATOMIC_INIT(0);
33045 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33046 struct input_handler *handler;
33047 const char *path;
33048 int error;
33049 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33050 dev->setkeycode = input_default_setkeycode;
33051
33052 dev_set_name(&dev->dev, "input%ld",
33053 - (unsigned long) atomic_inc_return(&input_no) - 1);
33054 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33055
33056 error = device_add(&dev->dev);
33057 if (error)
33058 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33059 index 04c69af..5f92d00 100644
33060 --- a/drivers/input/joystick/sidewinder.c
33061 +++ b/drivers/input/joystick/sidewinder.c
33062 @@ -30,6 +30,7 @@
33063 #include <linux/kernel.h>
33064 #include <linux/module.h>
33065 #include <linux/slab.h>
33066 +#include <linux/sched.h>
33067 #include <linux/init.h>
33068 #include <linux/input.h>
33069 #include <linux/gameport.h>
33070 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33071 index 83811e4..0822b90 100644
33072 --- a/drivers/input/joystick/xpad.c
33073 +++ b/drivers/input/joystick/xpad.c
33074 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33075
33076 static int xpad_led_probe(struct usb_xpad *xpad)
33077 {
33078 - static atomic_t led_seq = ATOMIC_INIT(0);
33079 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33080 long led_no;
33081 struct xpad_led *led;
33082 struct led_classdev *led_cdev;
33083 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33084 if (!led)
33085 return -ENOMEM;
33086
33087 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33088 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33089
33090 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33091 led->xpad = xpad;
33092 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33093 index 0110b5a..d3ad144 100644
33094 --- a/drivers/input/mousedev.c
33095 +++ b/drivers/input/mousedev.c
33096 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33097
33098 spin_unlock_irq(&client->packet_lock);
33099
33100 - if (copy_to_user(buffer, data, count))
33101 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33102 return -EFAULT;
33103
33104 return count;
33105 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33106 index d0f7533..fb8215b 100644
33107 --- a/drivers/input/serio/serio.c
33108 +++ b/drivers/input/serio/serio.c
33109 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33110 */
33111 static void serio_init_port(struct serio *serio)
33112 {
33113 - static atomic_t serio_no = ATOMIC_INIT(0);
33114 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33115
33116 __module_get(THIS_MODULE);
33117
33118 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33119 mutex_init(&serio->drv_mutex);
33120 device_initialize(&serio->dev);
33121 dev_set_name(&serio->dev, "serio%ld",
33122 - (long)atomic_inc_return(&serio_no) - 1);
33123 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33124 serio->dev.bus = &serio_bus;
33125 serio->dev.release = serio_release_port;
33126 serio->dev.groups = serio_device_attr_groups;
33127 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33128 index 38c4bd8..58965d9 100644
33129 --- a/drivers/isdn/capi/capi.c
33130 +++ b/drivers/isdn/capi/capi.c
33131 @@ -83,8 +83,8 @@ struct capiminor {
33132
33133 struct capi20_appl *ap;
33134 u32 ncci;
33135 - atomic_t datahandle;
33136 - atomic_t msgid;
33137 + atomic_unchecked_t datahandle;
33138 + atomic_unchecked_t msgid;
33139
33140 struct tty_port port;
33141 int ttyinstop;
33142 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33143 capimsg_setu16(s, 2, mp->ap->applid);
33144 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33145 capimsg_setu8 (s, 5, CAPI_RESP);
33146 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33147 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33148 capimsg_setu32(s, 8, mp->ncci);
33149 capimsg_setu16(s, 12, datahandle);
33150 }
33151 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33152 mp->outbytes -= len;
33153 spin_unlock_bh(&mp->outlock);
33154
33155 - datahandle = atomic_inc_return(&mp->datahandle);
33156 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33157 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33158 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33159 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33160 capimsg_setu16(skb->data, 2, mp->ap->applid);
33161 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33162 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33163 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33164 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33165 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33166 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33167 capimsg_setu16(skb->data, 16, len); /* Data length */
33168 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33169 index a6d9fd2..afdb8a3 100644
33170 --- a/drivers/isdn/gigaset/interface.c
33171 +++ b/drivers/isdn/gigaset/interface.c
33172 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33173 }
33174 tty->driver_data = cs;
33175
33176 - ++cs->port.count;
33177 + atomic_inc(&cs->port.count);
33178
33179 - if (cs->port.count == 1) {
33180 + if (atomic_read(&cs->port.count) == 1) {
33181 tty_port_tty_set(&cs->port, tty);
33182 tty->low_latency = 1;
33183 }
33184 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33185
33186 if (!cs->connected)
33187 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33188 - else if (!cs->port.count)
33189 + else if (!atomic_read(&cs->port.count))
33190 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33191 - else if (!--cs->port.count)
33192 + else if (!atomic_dec_return(&cs->port.count))
33193 tty_port_tty_set(&cs->port, NULL);
33194
33195 mutex_unlock(&cs->mutex);
33196 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33197 index 821f7ac..28d4030 100644
33198 --- a/drivers/isdn/hardware/avm/b1.c
33199 +++ b/drivers/isdn/hardware/avm/b1.c
33200 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33201 }
33202 if (left) {
33203 if (t4file->user) {
33204 - if (copy_from_user(buf, dp, left))
33205 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33206 return -EFAULT;
33207 } else {
33208 memcpy(buf, dp, left);
33209 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33210 }
33211 if (left) {
33212 if (config->user) {
33213 - if (copy_from_user(buf, dp, left))
33214 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33215 return -EFAULT;
33216 } else {
33217 memcpy(buf, dp, left);
33218 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33219 index dd6b53a..19d9ee6 100644
33220 --- a/drivers/isdn/hardware/eicon/divasync.h
33221 +++ b/drivers/isdn/hardware/eicon/divasync.h
33222 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33223 } diva_didd_add_adapter_t;
33224 typedef struct _diva_didd_remove_adapter {
33225 IDI_CALL p_request;
33226 -} diva_didd_remove_adapter_t;
33227 +} __no_const diva_didd_remove_adapter_t;
33228 typedef struct _diva_didd_read_adapter_array {
33229 void *buffer;
33230 dword length;
33231 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33232 index d303e65..28bcb7b 100644
33233 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33234 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33235 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33236 typedef struct _diva_os_idi_adapter_interface {
33237 diva_init_card_proc_t cleanup_adapter_proc;
33238 diva_cmd_card_proc_t cmd_proc;
33239 -} diva_os_idi_adapter_interface_t;
33240 +} __no_const diva_os_idi_adapter_interface_t;
33241
33242 typedef struct _diva_os_xdi_adapter {
33243 struct list_head link;
33244 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33245 index 7bc5067..fd36232 100644
33246 --- a/drivers/isdn/i4l/isdn_tty.c
33247 +++ b/drivers/isdn/i4l/isdn_tty.c
33248 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33249 port = &info->port;
33250 #ifdef ISDN_DEBUG_MODEM_OPEN
33251 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33252 - port->count);
33253 + atomic_read(&port->count))
33254 #endif
33255 - port->count++;
33256 + atomic_inc(&port->count);
33257 tty->driver_data = info;
33258 port->tty = tty;
33259 tty->port = port;
33260 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33261 #endif
33262 return;
33263 }
33264 - if ((tty->count == 1) && (port->count != 1)) {
33265 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33266 /*
33267 * Uh, oh. tty->count is 1, which means that the tty
33268 * structure will be freed. Info->count should always
33269 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33270 * serial port won't be shutdown.
33271 */
33272 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33273 - "info->count is %d\n", port->count);
33274 - port->count = 1;
33275 + "info->count is %d\n", atomic_read(&port->count));
33276 + atomic_set(&port->count, 1);
33277 }
33278 - if (--port->count < 0) {
33279 + if (atomic_dec_return(&port->count) < 0) {
33280 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33281 - info->line, port->count);
33282 - port->count = 0;
33283 + info->line, atomic_read(&port->count));
33284 + atomic_set(&port->count, 0);
33285 }
33286 - if (port->count) {
33287 + if (atomic_read(&port->count)) {
33288 #ifdef ISDN_DEBUG_MODEM_OPEN
33289 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33290 #endif
33291 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33292 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33293 return;
33294 isdn_tty_shutdown(info);
33295 - port->count = 0;
33296 + atomic_set(&port->count, 0);
33297 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33298 port->tty = NULL;
33299 wake_up_interruptible(&port->open_wait);
33300 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33301 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33302 modem_info *info = &dev->mdm.info[i];
33303
33304 - if (info->port.count == 0)
33305 + if (atomic_read(&info->port.count) == 0)
33306 continue;
33307 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33308 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33309 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33310 index e74df7c..03a03ba 100644
33311 --- a/drivers/isdn/icn/icn.c
33312 +++ b/drivers/isdn/icn/icn.c
33313 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33314 if (count > len)
33315 count = len;
33316 if (user) {
33317 - if (copy_from_user(msg, buf, count))
33318 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33319 return -EFAULT;
33320 } else
33321 memcpy(msg, buf, count);
33322 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33323 index b5fdcb7..5b6c59f 100644
33324 --- a/drivers/lguest/core.c
33325 +++ b/drivers/lguest/core.c
33326 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33327 * it's worked so far. The end address needs +1 because __get_vm_area
33328 * allocates an extra guard page, so we need space for that.
33329 */
33330 +
33331 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33332 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33333 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33334 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33335 +#else
33336 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33337 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33338 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33339 +#endif
33340 +
33341 if (!switcher_vma) {
33342 err = -ENOMEM;
33343 printk("lguest: could not map switcher pages high\n");
33344 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33345 * Now the Switcher is mapped at the right address, we can't fail!
33346 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33347 */
33348 - memcpy(switcher_vma->addr, start_switcher_text,
33349 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33350 end_switcher_text - start_switcher_text);
33351
33352 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33353 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33354 index 39809035..ce25c5e 100644
33355 --- a/drivers/lguest/x86/core.c
33356 +++ b/drivers/lguest/x86/core.c
33357 @@ -59,7 +59,7 @@ static struct {
33358 /* Offset from where switcher.S was compiled to where we've copied it */
33359 static unsigned long switcher_offset(void)
33360 {
33361 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33362 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33363 }
33364
33365 /* This cpu's struct lguest_pages. */
33366 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33367 * These copies are pretty cheap, so we do them unconditionally: */
33368 /* Save the current Host top-level page directory.
33369 */
33370 +
33371 +#ifdef CONFIG_PAX_PER_CPU_PGD
33372 + pages->state.host_cr3 = read_cr3();
33373 +#else
33374 pages->state.host_cr3 = __pa(current->mm->pgd);
33375 +#endif
33376 +
33377 /*
33378 * Set up the Guest's page tables to see this CPU's pages (and no
33379 * other CPU's pages).
33380 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33381 * compiled-in switcher code and the high-mapped copy we just made.
33382 */
33383 for (i = 0; i < IDT_ENTRIES; i++)
33384 - default_idt_entries[i] += switcher_offset();
33385 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33386
33387 /*
33388 * Set up the Switcher's per-cpu areas.
33389 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33390 * it will be undisturbed when we switch. To change %cs and jump we
33391 * need this structure to feed to Intel's "lcall" instruction.
33392 */
33393 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33394 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33395 lguest_entry.segment = LGUEST_CS;
33396
33397 /*
33398 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33399 index 40634b0..4f5855e 100644
33400 --- a/drivers/lguest/x86/switcher_32.S
33401 +++ b/drivers/lguest/x86/switcher_32.S
33402 @@ -87,6 +87,7 @@
33403 #include <asm/page.h>
33404 #include <asm/segment.h>
33405 #include <asm/lguest.h>
33406 +#include <asm/processor-flags.h>
33407
33408 // We mark the start of the code to copy
33409 // It's placed in .text tho it's never run here
33410 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33411 // Changes type when we load it: damn Intel!
33412 // For after we switch over our page tables
33413 // That entry will be read-only: we'd crash.
33414 +
33415 +#ifdef CONFIG_PAX_KERNEXEC
33416 + mov %cr0, %edx
33417 + xor $X86_CR0_WP, %edx
33418 + mov %edx, %cr0
33419 +#endif
33420 +
33421 movl $(GDT_ENTRY_TSS*8), %edx
33422 ltr %dx
33423
33424 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33425 // Let's clear it again for our return.
33426 // The GDT descriptor of the Host
33427 // Points to the table after two "size" bytes
33428 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33429 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33430 // Clear "used" from type field (byte 5, bit 2)
33431 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33432 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33433 +
33434 +#ifdef CONFIG_PAX_KERNEXEC
33435 + mov %cr0, %eax
33436 + xor $X86_CR0_WP, %eax
33437 + mov %eax, %cr0
33438 +#endif
33439
33440 // Once our page table's switched, the Guest is live!
33441 // The Host fades as we run this final step.
33442 @@ -295,13 +309,12 @@ deliver_to_host:
33443 // I consulted gcc, and it gave
33444 // These instructions, which I gladly credit:
33445 leal (%edx,%ebx,8), %eax
33446 - movzwl (%eax),%edx
33447 - movl 4(%eax), %eax
33448 - xorw %ax, %ax
33449 - orl %eax, %edx
33450 + movl 4(%eax), %edx
33451 + movw (%eax), %dx
33452 // Now the address of the handler's in %edx
33453 // We call it now: its "iret" drops us home.
33454 - jmp *%edx
33455 + ljmp $__KERNEL_CS, $1f
33456 +1: jmp *%edx
33457
33458 // Every interrupt can come to us here
33459 // But we must truly tell each apart.
33460 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33461 index 20e5c2c..9e849a9 100644
33462 --- a/drivers/macintosh/macio_asic.c
33463 +++ b/drivers/macintosh/macio_asic.c
33464 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33465 * MacIO is matched against any Apple ID, it's probe() function
33466 * will then decide wether it applies or not
33467 */
33468 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33469 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33470 .vendor = PCI_VENDOR_ID_APPLE,
33471 .device = PCI_ANY_ID,
33472 .subvendor = PCI_ANY_ID,
33473 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33474 index 94e7f6b..2f4a0d8 100644
33475 --- a/drivers/md/bitmap.c
33476 +++ b/drivers/md/bitmap.c
33477 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33478 chunk_kb ? "KB" : "B");
33479 if (bitmap->storage.file) {
33480 seq_printf(seq, ", file: ");
33481 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33482 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33483 }
33484
33485 seq_printf(seq, "\n");
33486 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33487 index afd9598..528d8f9 100644
33488 --- a/drivers/md/dm-ioctl.c
33489 +++ b/drivers/md/dm-ioctl.c
33490 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33491 cmd == DM_LIST_VERSIONS_CMD)
33492 return 0;
33493
33494 - if ((cmd == DM_DEV_CREATE_CMD)) {
33495 + if (cmd == DM_DEV_CREATE_CMD) {
33496 if (!*param->name) {
33497 DMWARN("name not supplied when creating device");
33498 return -EINVAL;
33499 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33500 index bc5ddba8..b961159 100644
33501 --- a/drivers/md/dm-raid1.c
33502 +++ b/drivers/md/dm-raid1.c
33503 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33504
33505 struct mirror {
33506 struct mirror_set *ms;
33507 - atomic_t error_count;
33508 + atomic_unchecked_t error_count;
33509 unsigned long error_type;
33510 struct dm_dev *dev;
33511 sector_t offset;
33512 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33513 struct mirror *m;
33514
33515 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33516 - if (!atomic_read(&m->error_count))
33517 + if (!atomic_read_unchecked(&m->error_count))
33518 return m;
33519
33520 return NULL;
33521 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33522 * simple way to tell if a device has encountered
33523 * errors.
33524 */
33525 - atomic_inc(&m->error_count);
33526 + atomic_inc_unchecked(&m->error_count);
33527
33528 if (test_and_set_bit(error_type, &m->error_type))
33529 return;
33530 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33531 struct mirror *m = get_default_mirror(ms);
33532
33533 do {
33534 - if (likely(!atomic_read(&m->error_count)))
33535 + if (likely(!atomic_read_unchecked(&m->error_count)))
33536 return m;
33537
33538 if (m-- == ms->mirror)
33539 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33540 {
33541 struct mirror *default_mirror = get_default_mirror(m->ms);
33542
33543 - return !atomic_read(&default_mirror->error_count);
33544 + return !atomic_read_unchecked(&default_mirror->error_count);
33545 }
33546
33547 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33548 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33549 */
33550 if (likely(region_in_sync(ms, region, 1)))
33551 m = choose_mirror(ms, bio->bi_sector);
33552 - else if (m && atomic_read(&m->error_count))
33553 + else if (m && atomic_read_unchecked(&m->error_count))
33554 m = NULL;
33555
33556 if (likely(m))
33557 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33558 }
33559
33560 ms->mirror[mirror].ms = ms;
33561 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33562 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33563 ms->mirror[mirror].error_type = 0;
33564 ms->mirror[mirror].offset = offset;
33565
33566 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33567 */
33568 static char device_status_char(struct mirror *m)
33569 {
33570 - if (!atomic_read(&(m->error_count)))
33571 + if (!atomic_read_unchecked(&(m->error_count)))
33572 return 'A';
33573
33574 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33575 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33576 index a087bf2..4c94786 100644
33577 --- a/drivers/md/dm-stripe.c
33578 +++ b/drivers/md/dm-stripe.c
33579 @@ -20,7 +20,7 @@ struct stripe {
33580 struct dm_dev *dev;
33581 sector_t physical_start;
33582
33583 - atomic_t error_count;
33584 + atomic_unchecked_t error_count;
33585 };
33586
33587 struct stripe_c {
33588 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33589 kfree(sc);
33590 return r;
33591 }
33592 - atomic_set(&(sc->stripe[i].error_count), 0);
33593 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33594 }
33595
33596 ti->private = sc;
33597 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33598 DMEMIT("%d ", sc->stripes);
33599 for (i = 0; i < sc->stripes; i++) {
33600 DMEMIT("%s ", sc->stripe[i].dev->name);
33601 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33602 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33603 'D' : 'A';
33604 }
33605 buffer[i] = '\0';
33606 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33607 */
33608 for (i = 0; i < sc->stripes; i++)
33609 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33610 - atomic_inc(&(sc->stripe[i].error_count));
33611 - if (atomic_read(&(sc->stripe[i].error_count)) <
33612 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33613 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33614 DM_IO_ERROR_THRESHOLD)
33615 schedule_work(&sc->trigger_event);
33616 }
33617 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33618 index 100368e..64262ce 100644
33619 --- a/drivers/md/dm-table.c
33620 +++ b/drivers/md/dm-table.c
33621 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33622 if (!dev_size)
33623 return 0;
33624
33625 - if ((start >= dev_size) || (start + len > dev_size)) {
33626 + if ((start >= dev_size) || (len > dev_size - start)) {
33627 DMWARN("%s: %s too small for target: "
33628 "start=%llu, len=%llu, dev_size=%llu",
33629 dm_device_name(ti->table->md), bdevname(bdev, b),
33630 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33631 index 693e149..b7e0fde 100644
33632 --- a/drivers/md/dm-thin-metadata.c
33633 +++ b/drivers/md/dm-thin-metadata.c
33634 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33635 {
33636 pmd->info.tm = pmd->tm;
33637 pmd->info.levels = 2;
33638 - pmd->info.value_type.context = pmd->data_sm;
33639 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33640 pmd->info.value_type.size = sizeof(__le64);
33641 pmd->info.value_type.inc = data_block_inc;
33642 pmd->info.value_type.dec = data_block_dec;
33643 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33644
33645 pmd->bl_info.tm = pmd->tm;
33646 pmd->bl_info.levels = 1;
33647 - pmd->bl_info.value_type.context = pmd->data_sm;
33648 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33649 pmd->bl_info.value_type.size = sizeof(__le64);
33650 pmd->bl_info.value_type.inc = data_block_inc;
33651 pmd->bl_info.value_type.dec = data_block_dec;
33652 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33653 index 67ffa39..cb3b1dd 100644
33654 --- a/drivers/md/dm.c
33655 +++ b/drivers/md/dm.c
33656 @@ -176,9 +176,9 @@ struct mapped_device {
33657 /*
33658 * Event handling.
33659 */
33660 - atomic_t event_nr;
33661 + atomic_unchecked_t event_nr;
33662 wait_queue_head_t eventq;
33663 - atomic_t uevent_seq;
33664 + atomic_unchecked_t uevent_seq;
33665 struct list_head uevent_list;
33666 spinlock_t uevent_lock; /* Protect access to uevent_list */
33667
33668 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33669 rwlock_init(&md->map_lock);
33670 atomic_set(&md->holders, 1);
33671 atomic_set(&md->open_count, 0);
33672 - atomic_set(&md->event_nr, 0);
33673 - atomic_set(&md->uevent_seq, 0);
33674 + atomic_set_unchecked(&md->event_nr, 0);
33675 + atomic_set_unchecked(&md->uevent_seq, 0);
33676 INIT_LIST_HEAD(&md->uevent_list);
33677 spin_lock_init(&md->uevent_lock);
33678
33679 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33680
33681 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33682
33683 - atomic_inc(&md->event_nr);
33684 + atomic_inc_unchecked(&md->event_nr);
33685 wake_up(&md->eventq);
33686 }
33687
33688 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33689
33690 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33691 {
33692 - return atomic_add_return(1, &md->uevent_seq);
33693 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33694 }
33695
33696 uint32_t dm_get_event_nr(struct mapped_device *md)
33697 {
33698 - return atomic_read(&md->event_nr);
33699 + return atomic_read_unchecked(&md->event_nr);
33700 }
33701
33702 int dm_wait_event(struct mapped_device *md, int event_nr)
33703 {
33704 return wait_event_interruptible(md->eventq,
33705 - (event_nr != atomic_read(&md->event_nr)));
33706 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33707 }
33708
33709 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33710 diff --git a/drivers/md/md.c b/drivers/md/md.c
33711 index 308e87b..7f365d6 100644
33712 --- a/drivers/md/md.c
33713 +++ b/drivers/md/md.c
33714 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33715 * start build, activate spare
33716 */
33717 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33718 -static atomic_t md_event_count;
33719 +static atomic_unchecked_t md_event_count;
33720 void md_new_event(struct mddev *mddev)
33721 {
33722 - atomic_inc(&md_event_count);
33723 + atomic_inc_unchecked(&md_event_count);
33724 wake_up(&md_event_waiters);
33725 }
33726 EXPORT_SYMBOL_GPL(md_new_event);
33727 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33728 */
33729 static void md_new_event_inintr(struct mddev *mddev)
33730 {
33731 - atomic_inc(&md_event_count);
33732 + atomic_inc_unchecked(&md_event_count);
33733 wake_up(&md_event_waiters);
33734 }
33735
33736 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33737 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33738 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33739 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33740 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33741 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33742
33743 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33744 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33745 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33746 else
33747 sb->resync_offset = cpu_to_le64(0);
33748
33749 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33750 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33751
33752 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33753 sb->size = cpu_to_le64(mddev->dev_sectors);
33754 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33755 static ssize_t
33756 errors_show(struct md_rdev *rdev, char *page)
33757 {
33758 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33759 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33760 }
33761
33762 static ssize_t
33763 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33764 char *e;
33765 unsigned long n = simple_strtoul(buf, &e, 10);
33766 if (*buf && (*e == 0 || *e == '\n')) {
33767 - atomic_set(&rdev->corrected_errors, n);
33768 + atomic_set_unchecked(&rdev->corrected_errors, n);
33769 return len;
33770 }
33771 return -EINVAL;
33772 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33773 rdev->sb_loaded = 0;
33774 rdev->bb_page = NULL;
33775 atomic_set(&rdev->nr_pending, 0);
33776 - atomic_set(&rdev->read_errors, 0);
33777 - atomic_set(&rdev->corrected_errors, 0);
33778 + atomic_set_unchecked(&rdev->read_errors, 0);
33779 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33780
33781 INIT_LIST_HEAD(&rdev->same_set);
33782 init_waitqueue_head(&rdev->blocked_wait);
33783 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33784
33785 spin_unlock(&pers_lock);
33786 seq_printf(seq, "\n");
33787 - seq->poll_event = atomic_read(&md_event_count);
33788 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33789 return 0;
33790 }
33791 if (v == (void*)2) {
33792 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33793 return error;
33794
33795 seq = file->private_data;
33796 - seq->poll_event = atomic_read(&md_event_count);
33797 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33798 return error;
33799 }
33800
33801 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33802 /* always allow read */
33803 mask = POLLIN | POLLRDNORM;
33804
33805 - if (seq->poll_event != atomic_read(&md_event_count))
33806 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33807 mask |= POLLERR | POLLPRI;
33808 return mask;
33809 }
33810 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33811 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33812 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33813 (int)part_stat_read(&disk->part0, sectors[1]) -
33814 - atomic_read(&disk->sync_io);
33815 + atomic_read_unchecked(&disk->sync_io);
33816 /* sync IO will cause sync_io to increase before the disk_stats
33817 * as sync_io is counted when a request starts, and
33818 * disk_stats is counted when it completes.
33819 diff --git a/drivers/md/md.h b/drivers/md/md.h
33820 index f385b03..b600be8 100644
33821 --- a/drivers/md/md.h
33822 +++ b/drivers/md/md.h
33823 @@ -94,13 +94,13 @@ struct md_rdev {
33824 * only maintained for arrays that
33825 * support hot removal
33826 */
33827 - atomic_t read_errors; /* number of consecutive read errors that
33828 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33829 * we have tried to ignore.
33830 */
33831 struct timespec last_read_error; /* monotonic time since our
33832 * last read error
33833 */
33834 - atomic_t corrected_errors; /* number of corrected read errors,
33835 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33836 * for reporting to userspace and storing
33837 * in superblock.
33838 */
33839 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33840
33841 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33842 {
33843 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33844 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33845 }
33846
33847 struct md_personality
33848 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33849 index f6d29e6..7917f5e 100644
33850 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33851 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33852 @@ -22,7 +22,7 @@
33853 * Space map interface.
33854 */
33855 struct sm_disk {
33856 - struct dm_space_map sm;
33857 + dm_space_map_no_const sm;
33858
33859 struct ll_disk ll;
33860 struct ll_disk old_ll;
33861 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33862 index e89ae5e..062e4c2 100644
33863 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33864 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33865 @@ -43,7 +43,7 @@ struct block_op {
33866 };
33867
33868 struct sm_metadata {
33869 - struct dm_space_map sm;
33870 + dm_space_map_no_const sm;
33871
33872 struct ll_disk ll;
33873 struct ll_disk old_ll;
33874 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33875 index 1cbfc6b..56e1dbb 100644
33876 --- a/drivers/md/persistent-data/dm-space-map.h
33877 +++ b/drivers/md/persistent-data/dm-space-map.h
33878 @@ -60,6 +60,7 @@ struct dm_space_map {
33879 int (*root_size)(struct dm_space_map *sm, size_t *result);
33880 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33881 };
33882 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33883
33884 /*----------------------------------------------------------------*/
33885
33886 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33887 index 05bb49e..84d7ce6 100644
33888 --- a/drivers/md/raid1.c
33889 +++ b/drivers/md/raid1.c
33890 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33891 if (r1_sync_page_io(rdev, sect, s,
33892 bio->bi_io_vec[idx].bv_page,
33893 READ) != 0)
33894 - atomic_add(s, &rdev->corrected_errors);
33895 + atomic_add_unchecked(s, &rdev->corrected_errors);
33896 }
33897 sectors -= s;
33898 sect += s;
33899 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33900 test_bit(In_sync, &rdev->flags)) {
33901 if (r1_sync_page_io(rdev, sect, s,
33902 conf->tmppage, READ)) {
33903 - atomic_add(s, &rdev->corrected_errors);
33904 + atomic_add_unchecked(s, &rdev->corrected_errors);
33905 printk(KERN_INFO
33906 "md/raid1:%s: read error corrected "
33907 "(%d sectors at %llu on %s)\n",
33908 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33909 index a48c215..6bda6f4 100644
33910 --- a/drivers/md/raid10.c
33911 +++ b/drivers/md/raid10.c
33912 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33913 /* The write handler will notice the lack of
33914 * R10BIO_Uptodate and record any errors etc
33915 */
33916 - atomic_add(r10_bio->sectors,
33917 + atomic_add_unchecked(r10_bio->sectors,
33918 &conf->mirrors[d].rdev->corrected_errors);
33919
33920 /* for reconstruct, we always reschedule after a read.
33921 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33922 {
33923 struct timespec cur_time_mon;
33924 unsigned long hours_since_last;
33925 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33926 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33927
33928 ktime_get_ts(&cur_time_mon);
33929
33930 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33931 * overflowing the shift of read_errors by hours_since_last.
33932 */
33933 if (hours_since_last >= 8 * sizeof(read_errors))
33934 - atomic_set(&rdev->read_errors, 0);
33935 + atomic_set_unchecked(&rdev->read_errors, 0);
33936 else
33937 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33938 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33939 }
33940
33941 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33942 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33943 return;
33944
33945 check_decay_read_errors(mddev, rdev);
33946 - atomic_inc(&rdev->read_errors);
33947 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33948 + atomic_inc_unchecked(&rdev->read_errors);
33949 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33950 char b[BDEVNAME_SIZE];
33951 bdevname(rdev->bdev, b);
33952
33953 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33954 "md/raid10:%s: %s: Raid device exceeded "
33955 "read_error threshold [cur %d:max %d]\n",
33956 mdname(mddev), b,
33957 - atomic_read(&rdev->read_errors), max_read_errors);
33958 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33959 printk(KERN_NOTICE
33960 "md/raid10:%s: %s: Failing raid device\n",
33961 mdname(mddev), b);
33962 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33963 sect +
33964 choose_data_offset(r10_bio, rdev)),
33965 bdevname(rdev->bdev, b));
33966 - atomic_add(s, &rdev->corrected_errors);
33967 + atomic_add_unchecked(s, &rdev->corrected_errors);
33968 }
33969
33970 rdev_dec_pending(rdev, mddev);
33971 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33972 index 0689173..35df76c 100644
33973 --- a/drivers/md/raid5.c
33974 +++ b/drivers/md/raid5.c
33975 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33976 mdname(conf->mddev), STRIPE_SECTORS,
33977 (unsigned long long)s,
33978 bdevname(rdev->bdev, b));
33979 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33980 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33981 clear_bit(R5_ReadError, &sh->dev[i].flags);
33982 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33983 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33984 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33985
33986 - if (atomic_read(&rdev->read_errors))
33987 - atomic_set(&rdev->read_errors, 0);
33988 + if (atomic_read_unchecked(&rdev->read_errors))
33989 + atomic_set_unchecked(&rdev->read_errors, 0);
33990 } else {
33991 const char *bdn = bdevname(rdev->bdev, b);
33992 int retry = 0;
33993 int set_bad = 0;
33994
33995 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33996 - atomic_inc(&rdev->read_errors);
33997 + atomic_inc_unchecked(&rdev->read_errors);
33998 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33999 printk_ratelimited(
34000 KERN_WARNING
34001 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34002 mdname(conf->mddev),
34003 (unsigned long long)s,
34004 bdn);
34005 - } else if (atomic_read(&rdev->read_errors)
34006 + } else if (atomic_read_unchecked(&rdev->read_errors)
34007 > conf->max_nr_stripes)
34008 printk(KERN_WARNING
34009 "md/raid:%s: Too many read errors, failing device %s.\n",
34010 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34011 index ebf3f05..b1f3e77 100644
34012 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34013 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34014 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34015 .subvendor = _subvend, .subdevice = _subdev, \
34016 .driver_data = (unsigned long)&_driverdata }
34017
34018 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34019 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34020 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34021 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34022 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34023 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34024 index fa7188a..04a045e 100644
34025 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34026 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34027 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34028 union {
34029 dmx_ts_cb ts;
34030 dmx_section_cb sec;
34031 - } cb;
34032 + } __no_const cb;
34033
34034 struct dvb_demux *demux;
34035 void *priv;
34036 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34037 index 39eab73..60033e7 100644
34038 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34039 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34040 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34041 const struct dvb_device *template, void *priv, int type)
34042 {
34043 struct dvb_device *dvbdev;
34044 - struct file_operations *dvbdevfops;
34045 + file_operations_no_const *dvbdevfops;
34046 struct device *clsdev;
34047 int minor;
34048 int id;
34049 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34050 index 3940bb0..fb3952a 100644
34051 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34052 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34053 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34054
34055 struct dib0700_adapter_state {
34056 int (*set_param_save) (struct dvb_frontend *);
34057 -};
34058 +} __no_const;
34059
34060 static int dib7070_set_param_override(struct dvb_frontend *fe)
34061 {
34062 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34063 index 9382895..ac8093c 100644
34064 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34065 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34066 @@ -95,7 +95,7 @@ struct su3000_state {
34067
34068 struct s6x0_state {
34069 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34070 -};
34071 +} __no_const;
34072
34073 /* debug */
34074 static int dvb_usb_dw2102_debug;
34075 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34076 index 404f63a..4796533 100644
34077 --- a/drivers/media/dvb/frontends/dib3000.h
34078 +++ b/drivers/media/dvb/frontends/dib3000.h
34079 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34080 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34081 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34082 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34083 -};
34084 +} __no_const;
34085
34086 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34087 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34088 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34089 index 72ee8de..eae0c80 100644
34090 --- a/drivers/media/dvb/ngene/ngene-cards.c
34091 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34092 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34093
34094 /****************************************************************************/
34095
34096 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34097 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34098 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34099 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34100 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34101 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34102 index 697a421..16c5a5f 100644
34103 --- a/drivers/media/radio/radio-cadet.c
34104 +++ b/drivers/media/radio/radio-cadet.c
34105 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34106 unsigned char readbuf[RDS_BUFFER];
34107 int i = 0;
34108
34109 + if (count > RDS_BUFFER)
34110 + return -EFAULT;
34111 mutex_lock(&dev->lock);
34112 if (dev->rdsstat == 0)
34113 cadet_start_rds(dev);
34114 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34115 while (i < count && dev->rdsin != dev->rdsout)
34116 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34117
34118 - if (i && copy_to_user(data, readbuf, i))
34119 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34120 i = -EFAULT;
34121 unlock:
34122 mutex_unlock(&dev->lock);
34123 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34124 index 55cbd78..428b0da 100644
34125 --- a/drivers/media/radio/radio-tea5777.h
34126 +++ b/drivers/media/radio/radio-tea5777.h
34127 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34128
34129 struct radio_tea5777 {
34130 struct v4l2_device *v4l2_dev;
34131 - struct v4l2_file_operations fops;
34132 + v4l2_file_operations_no_const fops;
34133 struct video_device vd; /* video device */
34134 bool has_am; /* Device can tune to AM freqs */
34135 bool write_before_read; /* must write before read quirk */
34136 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34137 index 9cde353..8c6a1c3 100644
34138 --- a/drivers/media/video/au0828/au0828.h
34139 +++ b/drivers/media/video/au0828/au0828.h
34140 @@ -191,7 +191,7 @@ struct au0828_dev {
34141
34142 /* I2C */
34143 struct i2c_adapter i2c_adap;
34144 - struct i2c_algorithm i2c_algo;
34145 + i2c_algorithm_no_const i2c_algo;
34146 struct i2c_client i2c_client;
34147 u32 i2c_rc;
34148
34149 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34150 index dfac6e3..c26de31 100644
34151 --- a/drivers/media/video/cx88/cx88-alsa.c
34152 +++ b/drivers/media/video/cx88/cx88-alsa.c
34153 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34154 * Only boards with eeprom and byte 1 at eeprom=1 have it
34155 */
34156
34157 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34158 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34159 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34160 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34161 {0, }
34162 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34163 index 88cf9d9..bbc4b2c 100644
34164 --- a/drivers/media/video/omap/omap_vout.c
34165 +++ b/drivers/media/video/omap/omap_vout.c
34166 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34167 OMAP_VIDEO2,
34168 };
34169
34170 -static struct videobuf_queue_ops video_vbq_ops;
34171 /* Variables configurable through module params*/
34172 static u32 video1_numbuffers = 3;
34173 static u32 video2_numbuffers = 3;
34174 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34175 {
34176 struct videobuf_queue *q;
34177 struct omap_vout_device *vout = NULL;
34178 + static struct videobuf_queue_ops video_vbq_ops = {
34179 + .buf_setup = omap_vout_buffer_setup,
34180 + .buf_prepare = omap_vout_buffer_prepare,
34181 + .buf_release = omap_vout_buffer_release,
34182 + .buf_queue = omap_vout_buffer_queue,
34183 + };
34184
34185 vout = video_drvdata(file);
34186 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34187 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34188 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34189
34190 q = &vout->vbq;
34191 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34192 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34193 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34194 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34195 spin_lock_init(&vout->vbq_lock);
34196
34197 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34198 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34199 index 036952f..80d356d 100644
34200 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34201 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34202 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34203
34204 /* I2C stuff */
34205 struct i2c_adapter i2c_adap;
34206 - struct i2c_algorithm i2c_algo;
34207 + i2c_algorithm_no_const i2c_algo;
34208 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34209 int i2c_cx25840_hack_state;
34210 int i2c_linked;
34211 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34212 index 02194c0..091733b 100644
34213 --- a/drivers/media/video/timblogiw.c
34214 +++ b/drivers/media/video/timblogiw.c
34215 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34216
34217 /* Platform device functions */
34218
34219 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34220 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34221 .vidioc_querycap = timblogiw_querycap,
34222 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34223 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34224 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34225 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34226 };
34227
34228 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34229 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34230 .owner = THIS_MODULE,
34231 .open = timblogiw_open,
34232 .release = timblogiw_close,
34233 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34234 index d99db56..a16b959 100644
34235 --- a/drivers/message/fusion/mptbase.c
34236 +++ b/drivers/message/fusion/mptbase.c
34237 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34238 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34239 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34240
34241 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34242 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34243 +#else
34244 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34245 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34246 +#endif
34247 +
34248 /*
34249 * Rounding UP to nearest 4-kB boundary here...
34250 */
34251 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34252 index 551262e..7551198 100644
34253 --- a/drivers/message/fusion/mptsas.c
34254 +++ b/drivers/message/fusion/mptsas.c
34255 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34256 return 0;
34257 }
34258
34259 +static inline void
34260 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34261 +{
34262 + if (phy_info->port_details) {
34263 + phy_info->port_details->rphy = rphy;
34264 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34265 + ioc->name, rphy));
34266 + }
34267 +
34268 + if (rphy) {
34269 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34270 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34271 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34272 + ioc->name, rphy, rphy->dev.release));
34273 + }
34274 +}
34275 +
34276 /* no mutex */
34277 static void
34278 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34279 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34280 return NULL;
34281 }
34282
34283 -static inline void
34284 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34285 -{
34286 - if (phy_info->port_details) {
34287 - phy_info->port_details->rphy = rphy;
34288 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34289 - ioc->name, rphy));
34290 - }
34291 -
34292 - if (rphy) {
34293 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34294 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34295 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34296 - ioc->name, rphy, rphy->dev.release));
34297 - }
34298 -}
34299 -
34300 static inline struct sas_port *
34301 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34302 {
34303 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34304 index 0c3ced7..1fe34ec 100644
34305 --- a/drivers/message/fusion/mptscsih.c
34306 +++ b/drivers/message/fusion/mptscsih.c
34307 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34308
34309 h = shost_priv(SChost);
34310
34311 - if (h) {
34312 - if (h->info_kbuf == NULL)
34313 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34314 - return h->info_kbuf;
34315 - h->info_kbuf[0] = '\0';
34316 + if (!h)
34317 + return NULL;
34318
34319 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34320 - h->info_kbuf[size-1] = '\0';
34321 - }
34322 + if (h->info_kbuf == NULL)
34323 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34324 + return h->info_kbuf;
34325 + h->info_kbuf[0] = '\0';
34326 +
34327 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34328 + h->info_kbuf[size-1] = '\0';
34329
34330 return h->info_kbuf;
34331 }
34332 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34333 index 8001aa6..b137580 100644
34334 --- a/drivers/message/i2o/i2o_proc.c
34335 +++ b/drivers/message/i2o/i2o_proc.c
34336 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34337 "Array Controller Device"
34338 };
34339
34340 -static char *chtostr(char *tmp, u8 *chars, int n)
34341 -{
34342 - tmp[0] = 0;
34343 - return strncat(tmp, (char *)chars, n);
34344 -}
34345 -
34346 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34347 char *group)
34348 {
34349 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34350 } *result;
34351
34352 i2o_exec_execute_ddm_table ddm_table;
34353 - char tmp[28 + 1];
34354
34355 result = kmalloc(sizeof(*result), GFP_KERNEL);
34356 if (!result)
34357 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34358
34359 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34360 seq_printf(seq, "%-#8x", ddm_table.module_id);
34361 - seq_printf(seq, "%-29s",
34362 - chtostr(tmp, ddm_table.module_name_version, 28));
34363 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34364 seq_printf(seq, "%9d ", ddm_table.data_size);
34365 seq_printf(seq, "%8d", ddm_table.code_size);
34366
34367 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34368
34369 i2o_driver_result_table *result;
34370 i2o_driver_store_table *dst;
34371 - char tmp[28 + 1];
34372
34373 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34374 if (result == NULL)
34375 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34376
34377 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34378 seq_printf(seq, "%-#8x", dst->module_id);
34379 - seq_printf(seq, "%-29s",
34380 - chtostr(tmp, dst->module_name_version, 28));
34381 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34382 + seq_printf(seq, "%-.28s", dst->module_name_version);
34383 + seq_printf(seq, "%-.8s", dst->date);
34384 seq_printf(seq, "%8d ", dst->module_size);
34385 seq_printf(seq, "%8d ", dst->mpb_size);
34386 seq_printf(seq, "0x%04x", dst->module_flags);
34387 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34388 // == (allow) 512d bytes (max)
34389 static u16 *work16 = (u16 *) work32;
34390 int token;
34391 - char tmp[16 + 1];
34392
34393 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34394
34395 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34396 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34397 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34398 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34399 - seq_printf(seq, "Vendor info : %s\n",
34400 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34401 - seq_printf(seq, "Product info : %s\n",
34402 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34403 - seq_printf(seq, "Description : %s\n",
34404 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34405 - seq_printf(seq, "Product rev. : %s\n",
34406 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34407 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34408 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34409 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34410 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34411
34412 seq_printf(seq, "Serial number : ");
34413 print_serial_number(seq, (u8 *) (work32 + 16),
34414 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34415 u8 pad[256]; // allow up to 256 byte (max) serial number
34416 } result;
34417
34418 - char tmp[24 + 1];
34419 -
34420 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34421
34422 if (token < 0) {
34423 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34424 }
34425
34426 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34427 - seq_printf(seq, "Module name : %s\n",
34428 - chtostr(tmp, result.module_name, 24));
34429 - seq_printf(seq, "Module revision : %s\n",
34430 - chtostr(tmp, result.module_rev, 8));
34431 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34432 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34433
34434 seq_printf(seq, "Serial number : ");
34435 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34436 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34437 u8 instance_number[4];
34438 } result;
34439
34440 - char tmp[64 + 1];
34441 -
34442 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34443
34444 if (token < 0) {
34445 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34446 return 0;
34447 }
34448
34449 - seq_printf(seq, "Device name : %s\n",
34450 - chtostr(tmp, result.device_name, 64));
34451 - seq_printf(seq, "Service name : %s\n",
34452 - chtostr(tmp, result.service_name, 64));
34453 - seq_printf(seq, "Physical name : %s\n",
34454 - chtostr(tmp, result.physical_location, 64));
34455 - seq_printf(seq, "Instance number : %s\n",
34456 - chtostr(tmp, result.instance_number, 4));
34457 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34458 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34459 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34460 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34461
34462 return 0;
34463 }
34464 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34465 index a8c08f3..155fe3d 100644
34466 --- a/drivers/message/i2o/iop.c
34467 +++ b/drivers/message/i2o/iop.c
34468 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34469
34470 spin_lock_irqsave(&c->context_list_lock, flags);
34471
34472 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34473 - atomic_inc(&c->context_list_counter);
34474 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34475 + atomic_inc_unchecked(&c->context_list_counter);
34476
34477 - entry->context = atomic_read(&c->context_list_counter);
34478 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34479
34480 list_add(&entry->list, &c->context_list);
34481
34482 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34483
34484 #if BITS_PER_LONG == 64
34485 spin_lock_init(&c->context_list_lock);
34486 - atomic_set(&c->context_list_counter, 0);
34487 + atomic_set_unchecked(&c->context_list_counter, 0);
34488 INIT_LIST_HEAD(&c->context_list);
34489 #endif
34490
34491 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34492 index 7ce65f4..e66e9bc 100644
34493 --- a/drivers/mfd/abx500-core.c
34494 +++ b/drivers/mfd/abx500-core.c
34495 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34496
34497 struct abx500_device_entry {
34498 struct list_head list;
34499 - struct abx500_ops ops;
34500 + abx500_ops_no_const ops;
34501 struct device *dev;
34502 };
34503
34504 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34505 index 965c480..71f2db9 100644
34506 --- a/drivers/mfd/janz-cmodio.c
34507 +++ b/drivers/mfd/janz-cmodio.c
34508 @@ -13,6 +13,7 @@
34509
34510 #include <linux/kernel.h>
34511 #include <linux/module.h>
34512 +#include <linux/slab.h>
34513 #include <linux/init.h>
34514 #include <linux/pci.h>
34515 #include <linux/interrupt.h>
34516 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34517 index a981e2a..5ca0c8b 100644
34518 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34519 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34520 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34521 * the lid is closed. This leads to interrupts as soon as a little move
34522 * is done.
34523 */
34524 - atomic_inc(&lis3->count);
34525 + atomic_inc_unchecked(&lis3->count);
34526
34527 wake_up_interruptible(&lis3->misc_wait);
34528 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34529 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34530 if (lis3->pm_dev)
34531 pm_runtime_get_sync(lis3->pm_dev);
34532
34533 - atomic_set(&lis3->count, 0);
34534 + atomic_set_unchecked(&lis3->count, 0);
34535 return 0;
34536 }
34537
34538 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34539 add_wait_queue(&lis3->misc_wait, &wait);
34540 while (true) {
34541 set_current_state(TASK_INTERRUPTIBLE);
34542 - data = atomic_xchg(&lis3->count, 0);
34543 + data = atomic_xchg_unchecked(&lis3->count, 0);
34544 if (data)
34545 break;
34546
34547 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34548 struct lis3lv02d, miscdev);
34549
34550 poll_wait(file, &lis3->misc_wait, wait);
34551 - if (atomic_read(&lis3->count))
34552 + if (atomic_read_unchecked(&lis3->count))
34553 return POLLIN | POLLRDNORM;
34554 return 0;
34555 }
34556 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34557 index 2b1482a..5d33616 100644
34558 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34559 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34560 @@ -266,7 +266,7 @@ struct lis3lv02d {
34561 struct input_polled_dev *idev; /* input device */
34562 struct platform_device *pdev; /* platform device */
34563 struct regulator_bulk_data regulators[2];
34564 - atomic_t count; /* interrupt count after last read */
34565 + atomic_unchecked_t count; /* interrupt count after last read */
34566 union axis_conversion ac; /* hw -> logical axis */
34567 int mapped_btns[3];
34568
34569 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34570 index 2f30bad..c4c13d0 100644
34571 --- a/drivers/misc/sgi-gru/gruhandles.c
34572 +++ b/drivers/misc/sgi-gru/gruhandles.c
34573 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34574 unsigned long nsec;
34575
34576 nsec = CLKS2NSEC(clks);
34577 - atomic_long_inc(&mcs_op_statistics[op].count);
34578 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34579 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34580 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34581 if (mcs_op_statistics[op].max < nsec)
34582 mcs_op_statistics[op].max = nsec;
34583 }
34584 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34585 index 950dbe9..eeef0f8 100644
34586 --- a/drivers/misc/sgi-gru/gruprocfs.c
34587 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34588 @@ -32,9 +32,9 @@
34589
34590 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34591
34592 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34593 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34594 {
34595 - unsigned long val = atomic_long_read(v);
34596 + unsigned long val = atomic_long_read_unchecked(v);
34597
34598 seq_printf(s, "%16lu %s\n", val, id);
34599 }
34600 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34601
34602 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34603 for (op = 0; op < mcsop_last; op++) {
34604 - count = atomic_long_read(&mcs_op_statistics[op].count);
34605 - total = atomic_long_read(&mcs_op_statistics[op].total);
34606 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34607 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34608 max = mcs_op_statistics[op].max;
34609 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34610 count ? total / count : 0, max);
34611 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34612 index 5c3ce24..4915ccb 100644
34613 --- a/drivers/misc/sgi-gru/grutables.h
34614 +++ b/drivers/misc/sgi-gru/grutables.h
34615 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34616 * GRU statistics.
34617 */
34618 struct gru_stats_s {
34619 - atomic_long_t vdata_alloc;
34620 - atomic_long_t vdata_free;
34621 - atomic_long_t gts_alloc;
34622 - atomic_long_t gts_free;
34623 - atomic_long_t gms_alloc;
34624 - atomic_long_t gms_free;
34625 - atomic_long_t gts_double_allocate;
34626 - atomic_long_t assign_context;
34627 - atomic_long_t assign_context_failed;
34628 - atomic_long_t free_context;
34629 - atomic_long_t load_user_context;
34630 - atomic_long_t load_kernel_context;
34631 - atomic_long_t lock_kernel_context;
34632 - atomic_long_t unlock_kernel_context;
34633 - atomic_long_t steal_user_context;
34634 - atomic_long_t steal_kernel_context;
34635 - atomic_long_t steal_context_failed;
34636 - atomic_long_t nopfn;
34637 - atomic_long_t asid_new;
34638 - atomic_long_t asid_next;
34639 - atomic_long_t asid_wrap;
34640 - atomic_long_t asid_reuse;
34641 - atomic_long_t intr;
34642 - atomic_long_t intr_cbr;
34643 - atomic_long_t intr_tfh;
34644 - atomic_long_t intr_spurious;
34645 - atomic_long_t intr_mm_lock_failed;
34646 - atomic_long_t call_os;
34647 - atomic_long_t call_os_wait_queue;
34648 - atomic_long_t user_flush_tlb;
34649 - atomic_long_t user_unload_context;
34650 - atomic_long_t user_exception;
34651 - atomic_long_t set_context_option;
34652 - atomic_long_t check_context_retarget_intr;
34653 - atomic_long_t check_context_unload;
34654 - atomic_long_t tlb_dropin;
34655 - atomic_long_t tlb_preload_page;
34656 - atomic_long_t tlb_dropin_fail_no_asid;
34657 - atomic_long_t tlb_dropin_fail_upm;
34658 - atomic_long_t tlb_dropin_fail_invalid;
34659 - atomic_long_t tlb_dropin_fail_range_active;
34660 - atomic_long_t tlb_dropin_fail_idle;
34661 - atomic_long_t tlb_dropin_fail_fmm;
34662 - atomic_long_t tlb_dropin_fail_no_exception;
34663 - atomic_long_t tfh_stale_on_fault;
34664 - atomic_long_t mmu_invalidate_range;
34665 - atomic_long_t mmu_invalidate_page;
34666 - atomic_long_t flush_tlb;
34667 - atomic_long_t flush_tlb_gru;
34668 - atomic_long_t flush_tlb_gru_tgh;
34669 - atomic_long_t flush_tlb_gru_zero_asid;
34670 + atomic_long_unchecked_t vdata_alloc;
34671 + atomic_long_unchecked_t vdata_free;
34672 + atomic_long_unchecked_t gts_alloc;
34673 + atomic_long_unchecked_t gts_free;
34674 + atomic_long_unchecked_t gms_alloc;
34675 + atomic_long_unchecked_t gms_free;
34676 + atomic_long_unchecked_t gts_double_allocate;
34677 + atomic_long_unchecked_t assign_context;
34678 + atomic_long_unchecked_t assign_context_failed;
34679 + atomic_long_unchecked_t free_context;
34680 + atomic_long_unchecked_t load_user_context;
34681 + atomic_long_unchecked_t load_kernel_context;
34682 + atomic_long_unchecked_t lock_kernel_context;
34683 + atomic_long_unchecked_t unlock_kernel_context;
34684 + atomic_long_unchecked_t steal_user_context;
34685 + atomic_long_unchecked_t steal_kernel_context;
34686 + atomic_long_unchecked_t steal_context_failed;
34687 + atomic_long_unchecked_t nopfn;
34688 + atomic_long_unchecked_t asid_new;
34689 + atomic_long_unchecked_t asid_next;
34690 + atomic_long_unchecked_t asid_wrap;
34691 + atomic_long_unchecked_t asid_reuse;
34692 + atomic_long_unchecked_t intr;
34693 + atomic_long_unchecked_t intr_cbr;
34694 + atomic_long_unchecked_t intr_tfh;
34695 + atomic_long_unchecked_t intr_spurious;
34696 + atomic_long_unchecked_t intr_mm_lock_failed;
34697 + atomic_long_unchecked_t call_os;
34698 + atomic_long_unchecked_t call_os_wait_queue;
34699 + atomic_long_unchecked_t user_flush_tlb;
34700 + atomic_long_unchecked_t user_unload_context;
34701 + atomic_long_unchecked_t user_exception;
34702 + atomic_long_unchecked_t set_context_option;
34703 + atomic_long_unchecked_t check_context_retarget_intr;
34704 + atomic_long_unchecked_t check_context_unload;
34705 + atomic_long_unchecked_t tlb_dropin;
34706 + atomic_long_unchecked_t tlb_preload_page;
34707 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34708 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34709 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34710 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34711 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34712 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34713 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34714 + atomic_long_unchecked_t tfh_stale_on_fault;
34715 + atomic_long_unchecked_t mmu_invalidate_range;
34716 + atomic_long_unchecked_t mmu_invalidate_page;
34717 + atomic_long_unchecked_t flush_tlb;
34718 + atomic_long_unchecked_t flush_tlb_gru;
34719 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34720 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34721
34722 - atomic_long_t copy_gpa;
34723 - atomic_long_t read_gpa;
34724 + atomic_long_unchecked_t copy_gpa;
34725 + atomic_long_unchecked_t read_gpa;
34726
34727 - atomic_long_t mesq_receive;
34728 - atomic_long_t mesq_receive_none;
34729 - atomic_long_t mesq_send;
34730 - atomic_long_t mesq_send_failed;
34731 - atomic_long_t mesq_noop;
34732 - atomic_long_t mesq_send_unexpected_error;
34733 - atomic_long_t mesq_send_lb_overflow;
34734 - atomic_long_t mesq_send_qlimit_reached;
34735 - atomic_long_t mesq_send_amo_nacked;
34736 - atomic_long_t mesq_send_put_nacked;
34737 - atomic_long_t mesq_page_overflow;
34738 - atomic_long_t mesq_qf_locked;
34739 - atomic_long_t mesq_qf_noop_not_full;
34740 - atomic_long_t mesq_qf_switch_head_failed;
34741 - atomic_long_t mesq_qf_unexpected_error;
34742 - atomic_long_t mesq_noop_unexpected_error;
34743 - atomic_long_t mesq_noop_lb_overflow;
34744 - atomic_long_t mesq_noop_qlimit_reached;
34745 - atomic_long_t mesq_noop_amo_nacked;
34746 - atomic_long_t mesq_noop_put_nacked;
34747 - atomic_long_t mesq_noop_page_overflow;
34748 + atomic_long_unchecked_t mesq_receive;
34749 + atomic_long_unchecked_t mesq_receive_none;
34750 + atomic_long_unchecked_t mesq_send;
34751 + atomic_long_unchecked_t mesq_send_failed;
34752 + atomic_long_unchecked_t mesq_noop;
34753 + atomic_long_unchecked_t mesq_send_unexpected_error;
34754 + atomic_long_unchecked_t mesq_send_lb_overflow;
34755 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34756 + atomic_long_unchecked_t mesq_send_amo_nacked;
34757 + atomic_long_unchecked_t mesq_send_put_nacked;
34758 + atomic_long_unchecked_t mesq_page_overflow;
34759 + atomic_long_unchecked_t mesq_qf_locked;
34760 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34761 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34762 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34763 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34764 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34765 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34766 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34767 + atomic_long_unchecked_t mesq_noop_put_nacked;
34768 + atomic_long_unchecked_t mesq_noop_page_overflow;
34769
34770 };
34771
34772 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34773 tghop_invalidate, mcsop_last};
34774
34775 struct mcs_op_statistic {
34776 - atomic_long_t count;
34777 - atomic_long_t total;
34778 + atomic_long_unchecked_t count;
34779 + atomic_long_unchecked_t total;
34780 unsigned long max;
34781 };
34782
34783 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34784
34785 #define STAT(id) do { \
34786 if (gru_options & OPT_STATS) \
34787 - atomic_long_inc(&gru_stats.id); \
34788 + atomic_long_inc_unchecked(&gru_stats.id); \
34789 } while (0)
34790
34791 #ifdef CONFIG_SGI_GRU_DEBUG
34792 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34793 index c862cd4..0d176fe 100644
34794 --- a/drivers/misc/sgi-xp/xp.h
34795 +++ b/drivers/misc/sgi-xp/xp.h
34796 @@ -288,7 +288,7 @@ struct xpc_interface {
34797 xpc_notify_func, void *);
34798 void (*received) (short, int, void *);
34799 enum xp_retval (*partid_to_nasids) (short, void *);
34800 -};
34801 +} __no_const;
34802
34803 extern struct xpc_interface xpc_interface;
34804
34805 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34806 index b94d5f7..7f494c5 100644
34807 --- a/drivers/misc/sgi-xp/xpc.h
34808 +++ b/drivers/misc/sgi-xp/xpc.h
34809 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34810 void (*received_payload) (struct xpc_channel *, void *);
34811 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34812 };
34813 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34814
34815 /* struct xpc_partition act_state values (for XPC HB) */
34816
34817 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34818 /* found in xpc_main.c */
34819 extern struct device *xpc_part;
34820 extern struct device *xpc_chan;
34821 -extern struct xpc_arch_operations xpc_arch_ops;
34822 +extern xpc_arch_operations_no_const xpc_arch_ops;
34823 extern int xpc_disengage_timelimit;
34824 extern int xpc_disengage_timedout;
34825 extern int xpc_activate_IRQ_rcvd;
34826 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34827 index 8d082b4..aa749ae 100644
34828 --- a/drivers/misc/sgi-xp/xpc_main.c
34829 +++ b/drivers/misc/sgi-xp/xpc_main.c
34830 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34831 .notifier_call = xpc_system_die,
34832 };
34833
34834 -struct xpc_arch_operations xpc_arch_ops;
34835 +xpc_arch_operations_no_const xpc_arch_ops;
34836
34837 /*
34838 * Timer function to enforce the timelimit on the partition disengage.
34839 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34840 index 504da71..9722d43 100644
34841 --- a/drivers/mmc/host/sdhci-pci.c
34842 +++ b/drivers/mmc/host/sdhci-pci.c
34843 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34844 .probe = via_probe,
34845 };
34846
34847 -static const struct pci_device_id pci_ids[] __devinitdata = {
34848 +static const struct pci_device_id pci_ids[] __devinitconst = {
34849 {
34850 .vendor = PCI_VENDOR_ID_RICOH,
34851 .device = PCI_DEVICE_ID_RICOH_R5C822,
34852 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34853 index a4eb8b5..8c0628f 100644
34854 --- a/drivers/mtd/devices/doc2000.c
34855 +++ b/drivers/mtd/devices/doc2000.c
34856 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34857
34858 /* The ECC will not be calculated correctly if less than 512 is written */
34859 /* DBB-
34860 - if (len != 0x200 && eccbuf)
34861 + if (len != 0x200)
34862 printk(KERN_WARNING
34863 "ECC needs a full sector write (adr: %lx size %lx)\n",
34864 (long) to, (long) len);
34865 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34866 index 0650aaf..7718762 100644
34867 --- a/drivers/mtd/nand/denali.c
34868 +++ b/drivers/mtd/nand/denali.c
34869 @@ -26,6 +26,7 @@
34870 #include <linux/pci.h>
34871 #include <linux/mtd/mtd.h>
34872 #include <linux/module.h>
34873 +#include <linux/slab.h>
34874
34875 #include "denali.h"
34876
34877 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34878 index 51b9d6a..52af9a7 100644
34879 --- a/drivers/mtd/nftlmount.c
34880 +++ b/drivers/mtd/nftlmount.c
34881 @@ -24,6 +24,7 @@
34882 #include <asm/errno.h>
34883 #include <linux/delay.h>
34884 #include <linux/slab.h>
34885 +#include <linux/sched.h>
34886 #include <linux/mtd/mtd.h>
34887 #include <linux/mtd/nand.h>
34888 #include <linux/mtd/nftl.h>
34889 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
34890 index dc15d24..ef8d2a0 100644
34891 --- a/drivers/net/bonding/bond_sysfs.c
34892 +++ b/drivers/net/bonding/bond_sysfs.c
34893 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
34894 goto out;
34895 }
34896
34897 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34898 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34899
34900 /* check to see if we are clearing primary */
34901 if (!strlen(ifname) || buf[0] == '\n') {
34902 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
34903 goto out;
34904 }
34905
34906 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34907 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34908
34909 /* check to see if we are clearing active */
34910 if (!strlen(ifname) || buf[0] == '\n') {
34911 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34912 index 57d64b8..623dd86 100644
34913 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34914 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34915 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34916 */
34917
34918 #define ATL2_PARAM(X, desc) \
34919 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34920 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34921 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34922 MODULE_PARM_DESC(X, desc);
34923 #else
34924 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34925 index 0875ecf..794cdf3 100644
34926 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34927 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34928 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
34929 struct eth_stats_info *ether_stat =
34930 &bp->slowpath->drv_info_to_mcp.ether_stat;
34931
34932 - /* leave last char as NULL */
34933 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
34934 - ETH_STAT_INFO_VERSION_LEN - 1);
34935 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
34936 + ETH_STAT_INFO_VERSION_LEN);
34937
34938 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
34939 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
34940 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34941 index f83e033..8b4f43a 100644
34942 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34943 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34944 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34945
34946 int (*wait_comp)(struct bnx2x *bp,
34947 struct bnx2x_rx_mode_ramrod_params *p);
34948 -};
34949 +} __no_const;
34950
34951 /********************** Set multicast group ***********************************/
34952
34953 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34954 index 6d52cb2..bc95640 100644
34955 --- a/drivers/net/ethernet/broadcom/tg3.h
34956 +++ b/drivers/net/ethernet/broadcom/tg3.h
34957 @@ -140,6 +140,7 @@
34958 #define CHIPREV_ID_5750_A0 0x4000
34959 #define CHIPREV_ID_5750_A1 0x4001
34960 #define CHIPREV_ID_5750_A3 0x4003
34961 +#define CHIPREV_ID_5750_C1 0x4201
34962 #define CHIPREV_ID_5750_C2 0x4202
34963 #define CHIPREV_ID_5752_A0_HW 0x5000
34964 #define CHIPREV_ID_5752_A0 0x6000
34965 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34966 index 8cffcdf..aadf043 100644
34967 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34968 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34969 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34970 */
34971 struct l2t_skb_cb {
34972 arp_failure_handler_func arp_failure_handler;
34973 -};
34974 +} __no_const;
34975
34976 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34977
34978 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34979 index f879e92..726f20f 100644
34980 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34981 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34982 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34983 for (i=0; i<ETH_ALEN; i++) {
34984 tmp.addr[i] = dev->dev_addr[i];
34985 }
34986 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34987 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34988 break;
34989
34990 case DE4X5_SET_HWADDR: /* Set the hardware address */
34991 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34992 spin_lock_irqsave(&lp->lock, flags);
34993 memcpy(&statbuf, &lp->pktStats, ioc->len);
34994 spin_unlock_irqrestore(&lp->lock, flags);
34995 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34996 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34997 return -EFAULT;
34998 break;
34999 }
35000 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35001 index ed7d1dc..d426748 100644
35002 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35003 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35004 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35005 {NULL}};
35006
35007
35008 -static const char *block_name[] __devinitdata = {
35009 +static const char *block_name[] __devinitconst = {
35010 "21140 non-MII",
35011 "21140 MII PHY",
35012 "21142 Serial PHY",
35013 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35014 index 75d45f8..3d9c55b 100644
35015 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
35016 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35017 @@ -129,7 +129,7 @@ struct uli526x_board_info {
35018 struct uli_phy_ops {
35019 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35020 u16 (*read)(struct uli526x_board_info *, u8, u8);
35021 - } phy;
35022 + } __no_const phy;
35023 struct net_device *next_dev; /* next device */
35024 struct pci_dev *pdev; /* PCI device */
35025 spinlock_t lock;
35026 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35027 index 4d1ffca..7c1ec4d 100644
35028 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35029 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35030 @@ -236,7 +236,7 @@ struct pci_id_info {
35031 int drv_flags; /* Driver use, intended as capability flags. */
35032 };
35033
35034 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35035 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35036 { /* Sometime a Level-One switch card. */
35037 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35038 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35039 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35040 index d7bb52a..3b83588 100644
35041 --- a/drivers/net/ethernet/dlink/sundance.c
35042 +++ b/drivers/net/ethernet/dlink/sundance.c
35043 @@ -218,7 +218,7 @@ enum {
35044 struct pci_id_info {
35045 const char *name;
35046 };
35047 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35048 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35049 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35050 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35051 {"D-Link DFE-580TX 4 port Server Adapter"},
35052 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35053 index 78b8aa8..dd6323a 100644
35054 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35055 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35056 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35057
35058 if (wrapped)
35059 newacc += 65536;
35060 - ACCESS_ONCE(*acc) = newacc;
35061 + ACCESS_ONCE_RW(*acc) = newacc;
35062 }
35063
35064 void be_parse_stats(struct be_adapter *adapter)
35065 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35066 index 74d749e..eefb1bd 100644
35067 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35068 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35069 @@ -31,6 +31,8 @@
35070 #include <linux/netdevice.h>
35071 #include <linux/phy.h>
35072 #include <linux/platform_device.h>
35073 +#include <linux/interrupt.h>
35074 +#include <linux/irqreturn.h>
35075 #include <net/ip.h>
35076
35077 #include "ftgmac100.h"
35078 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35079 index b901a01..1ff32ee 100644
35080 --- a/drivers/net/ethernet/faraday/ftmac100.c
35081 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35082 @@ -31,6 +31,8 @@
35083 #include <linux/module.h>
35084 #include <linux/netdevice.h>
35085 #include <linux/platform_device.h>
35086 +#include <linux/interrupt.h>
35087 +#include <linux/irqreturn.h>
35088
35089 #include "ftmac100.h"
35090
35091 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35092 index 9d71c9c..0e4a0ac 100644
35093 --- a/drivers/net/ethernet/fealnx.c
35094 +++ b/drivers/net/ethernet/fealnx.c
35095 @@ -150,7 +150,7 @@ struct chip_info {
35096 int flags;
35097 };
35098
35099 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35100 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35101 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35102 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35103 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35104 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35105 index ed5b409..ec37828 100644
35106 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35107 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35108 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35109 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35110 s32 (*read_mac_addr)(struct e1000_hw *);
35111 };
35112 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35113
35114 /*
35115 * When to use various PHY register access functions:
35116 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35117 void (*power_up)(struct e1000_hw *);
35118 void (*power_down)(struct e1000_hw *);
35119 };
35120 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35121
35122 /* Function pointers for the NVM. */
35123 struct e1000_nvm_operations {
35124 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35125 s32 (*validate)(struct e1000_hw *);
35126 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35127 };
35128 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35129
35130 struct e1000_mac_info {
35131 - struct e1000_mac_operations ops;
35132 + e1000_mac_operations_no_const ops;
35133 u8 addr[ETH_ALEN];
35134 u8 perm_addr[ETH_ALEN];
35135
35136 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35137 };
35138
35139 struct e1000_phy_info {
35140 - struct e1000_phy_operations ops;
35141 + e1000_phy_operations_no_const ops;
35142
35143 enum e1000_phy_type type;
35144
35145 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35146 };
35147
35148 struct e1000_nvm_info {
35149 - struct e1000_nvm_operations ops;
35150 + e1000_nvm_operations_no_const ops;
35151
35152 enum e1000_nvm_type type;
35153 enum e1000_nvm_override override;
35154 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35155 index c2a51dc..c2bd262 100644
35156 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35157 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35158 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35159 void (*release_swfw_sync)(struct e1000_hw *, u16);
35160
35161 };
35162 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35163
35164 struct e1000_phy_operations {
35165 s32 (*acquire)(struct e1000_hw *);
35166 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35167 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35168 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35169 };
35170 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35171
35172 struct e1000_nvm_operations {
35173 s32 (*acquire)(struct e1000_hw *);
35174 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35175 s32 (*validate)(struct e1000_hw *);
35176 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35177 };
35178 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35179
35180 struct e1000_info {
35181 s32 (*get_invariants)(struct e1000_hw *);
35182 @@ -364,7 +367,7 @@ struct e1000_info {
35183 extern const struct e1000_info e1000_82575_info;
35184
35185 struct e1000_mac_info {
35186 - struct e1000_mac_operations ops;
35187 + e1000_mac_operations_no_const ops;
35188
35189 u8 addr[6];
35190 u8 perm_addr[6];
35191 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35192 };
35193
35194 struct e1000_phy_info {
35195 - struct e1000_phy_operations ops;
35196 + e1000_phy_operations_no_const ops;
35197
35198 enum e1000_phy_type type;
35199
35200 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35201 };
35202
35203 struct e1000_nvm_info {
35204 - struct e1000_nvm_operations ops;
35205 + e1000_nvm_operations_no_const ops;
35206 enum e1000_nvm_type type;
35207 enum e1000_nvm_override override;
35208
35209 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35210 s32 (*check_for_ack)(struct e1000_hw *, u16);
35211 s32 (*check_for_rst)(struct e1000_hw *, u16);
35212 };
35213 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35214
35215 struct e1000_mbx_stats {
35216 u32 msgs_tx;
35217 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35218 };
35219
35220 struct e1000_mbx_info {
35221 - struct e1000_mbx_operations ops;
35222 + e1000_mbx_operations_no_const ops;
35223 struct e1000_mbx_stats stats;
35224 u32 timeout;
35225 u32 usec_delay;
35226 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35227 index 57db3c6..aa825fc 100644
35228 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35229 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35230 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35231 s32 (*read_mac_addr)(struct e1000_hw *);
35232 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35233 };
35234 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35235
35236 struct e1000_mac_info {
35237 - struct e1000_mac_operations ops;
35238 + e1000_mac_operations_no_const ops;
35239 u8 addr[6];
35240 u8 perm_addr[6];
35241
35242 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35243 s32 (*check_for_ack)(struct e1000_hw *);
35244 s32 (*check_for_rst)(struct e1000_hw *);
35245 };
35246 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35247
35248 struct e1000_mbx_stats {
35249 u32 msgs_tx;
35250 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35251 };
35252
35253 struct e1000_mbx_info {
35254 - struct e1000_mbx_operations ops;
35255 + e1000_mbx_operations_no_const ops;
35256 struct e1000_mbx_stats stats;
35257 u32 timeout;
35258 u32 usec_delay;
35259 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35260 index 3456d56..b688d81 100644
35261 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35262 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35263 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35264 /* store the new cycle speed */
35265 adapter->cycle_speed = cycle_speed;
35266
35267 - ACCESS_ONCE(adapter->base_incval) = incval;
35268 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35269 smp_mb();
35270
35271 /* grab the ptp lock */
35272 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35273 index 400f86a..7f2e062 100644
35274 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35275 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35276 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35277 s32 (*update_checksum)(struct ixgbe_hw *);
35278 u16 (*calc_checksum)(struct ixgbe_hw *);
35279 };
35280 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35281
35282 struct ixgbe_mac_operations {
35283 s32 (*init_hw)(struct ixgbe_hw *);
35284 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35285 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35286 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35287 };
35288 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35289
35290 struct ixgbe_phy_operations {
35291 s32 (*identify)(struct ixgbe_hw *);
35292 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35293 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35294 s32 (*check_overtemp)(struct ixgbe_hw *);
35295 };
35296 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35297
35298 struct ixgbe_eeprom_info {
35299 - struct ixgbe_eeprom_operations ops;
35300 + ixgbe_eeprom_operations_no_const ops;
35301 enum ixgbe_eeprom_type type;
35302 u32 semaphore_delay;
35303 u16 word_size;
35304 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35305
35306 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35307 struct ixgbe_mac_info {
35308 - struct ixgbe_mac_operations ops;
35309 + ixgbe_mac_operations_no_const ops;
35310 enum ixgbe_mac_type type;
35311 u8 addr[ETH_ALEN];
35312 u8 perm_addr[ETH_ALEN];
35313 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35314 };
35315
35316 struct ixgbe_phy_info {
35317 - struct ixgbe_phy_operations ops;
35318 + ixgbe_phy_operations_no_const ops;
35319 struct mdio_if_info mdio;
35320 enum ixgbe_phy_type type;
35321 u32 id;
35322 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35323 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35324 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35325 };
35326 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35327
35328 struct ixgbe_mbx_stats {
35329 u32 msgs_tx;
35330 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35331 };
35332
35333 struct ixgbe_mbx_info {
35334 - struct ixgbe_mbx_operations ops;
35335 + ixgbe_mbx_operations_no_const ops;
35336 struct ixgbe_mbx_stats stats;
35337 u32 timeout;
35338 u32 usec_delay;
35339 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35340 index 25c951d..cc7cf33 100644
35341 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35342 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35343 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35344 s32 (*clear_vfta)(struct ixgbe_hw *);
35345 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35346 };
35347 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35348
35349 enum ixgbe_mac_type {
35350 ixgbe_mac_unknown = 0,
35351 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35352 };
35353
35354 struct ixgbe_mac_info {
35355 - struct ixgbe_mac_operations ops;
35356 + ixgbe_mac_operations_no_const ops;
35357 u8 addr[6];
35358 u8 perm_addr[6];
35359
35360 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35361 s32 (*check_for_ack)(struct ixgbe_hw *);
35362 s32 (*check_for_rst)(struct ixgbe_hw *);
35363 };
35364 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35365
35366 struct ixgbe_mbx_stats {
35367 u32 msgs_tx;
35368 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35369 };
35370
35371 struct ixgbe_mbx_info {
35372 - struct ixgbe_mbx_operations ops;
35373 + ixgbe_mbx_operations_no_const ops;
35374 struct ixgbe_mbx_stats stats;
35375 u32 timeout;
35376 u32 udelay;
35377 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35378 index 9e0c1ee..8471f77 100644
35379 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35380 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35381 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35382 void (*link_down)(struct __vxge_hw_device *devh);
35383 void (*crit_err)(struct __vxge_hw_device *devh,
35384 enum vxge_hw_event type, u64 ext_data);
35385 -};
35386 +} __no_const;
35387
35388 /*
35389 * struct __vxge_hw_blockpool_entry - Block private data structure
35390 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35391 index 4a518a3..936b334 100644
35392 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35393 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35394 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35395 struct vxge_hw_mempool_dma *dma_object,
35396 u32 index,
35397 u32 is_last);
35398 -};
35399 +} __no_const;
35400
35401 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35402 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35403 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35404 index b47d5b3..273a516 100644
35405 --- a/drivers/net/ethernet/realtek/r8169.c
35406 +++ b/drivers/net/ethernet/realtek/r8169.c
35407 @@ -745,22 +745,22 @@ struct rtl8169_private {
35408 struct mdio_ops {
35409 void (*write)(struct rtl8169_private *, int, int);
35410 int (*read)(struct rtl8169_private *, int);
35411 - } mdio_ops;
35412 + } __no_const mdio_ops;
35413
35414 struct pll_power_ops {
35415 void (*down)(struct rtl8169_private *);
35416 void (*up)(struct rtl8169_private *);
35417 - } pll_power_ops;
35418 + } __no_const pll_power_ops;
35419
35420 struct jumbo_ops {
35421 void (*enable)(struct rtl8169_private *);
35422 void (*disable)(struct rtl8169_private *);
35423 - } jumbo_ops;
35424 + } __no_const jumbo_ops;
35425
35426 struct csi_ops {
35427 void (*write)(struct rtl8169_private *, int, int);
35428 u32 (*read)(struct rtl8169_private *, int);
35429 - } csi_ops;
35430 + } __no_const csi_ops;
35431
35432 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35433 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35434 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35435 index 4613591..d816601 100644
35436 --- a/drivers/net/ethernet/sis/sis190.c
35437 +++ b/drivers/net/ethernet/sis/sis190.c
35438 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35439 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35440 struct net_device *dev)
35441 {
35442 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35443 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35444 struct sis190_private *tp = netdev_priv(dev);
35445 struct pci_dev *isa_bridge;
35446 u8 reg, tmp8;
35447 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35448 index 0c74a70..3bc6f68 100644
35449 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35450 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35451 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35452
35453 writel(value, ioaddr + MMC_CNTRL);
35454
35455 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35456 - MMC_CNTRL, value);
35457 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35458 +// MMC_CNTRL, value);
35459 }
35460
35461 /* To mask all all interrupts.*/
35462 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35463 index 95ceb35..318fc12 100644
35464 --- a/drivers/net/hyperv/hyperv_net.h
35465 +++ b/drivers/net/hyperv/hyperv_net.h
35466 @@ -99,7 +99,7 @@ struct rndis_device {
35467
35468 enum rndis_device_state state;
35469 bool link_state;
35470 - atomic_t new_req_id;
35471 + atomic_unchecked_t new_req_id;
35472
35473 spinlock_t request_lock;
35474 struct list_head req_list;
35475 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35476 index 1e88a10..1b01736 100644
35477 --- a/drivers/net/hyperv/rndis_filter.c
35478 +++ b/drivers/net/hyperv/rndis_filter.c
35479 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35480 * template
35481 */
35482 set = &rndis_msg->msg.set_req;
35483 - set->req_id = atomic_inc_return(&dev->new_req_id);
35484 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35485
35486 /* Add to the request list */
35487 spin_lock_irqsave(&dev->request_lock, flags);
35488 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35489
35490 /* Setup the rndis set */
35491 halt = &request->request_msg.msg.halt_req;
35492 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35493 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35494
35495 /* Ignore return since this msg is optional. */
35496 rndis_filter_send_request(dev, request);
35497 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35498 index daec9b0..6428fcb 100644
35499 --- a/drivers/net/phy/mdio-bitbang.c
35500 +++ b/drivers/net/phy/mdio-bitbang.c
35501 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35502 struct mdiobb_ctrl *ctrl = bus->priv;
35503
35504 module_put(ctrl->ops->owner);
35505 + mdiobus_unregister(bus);
35506 mdiobus_free(bus);
35507 }
35508 EXPORT_SYMBOL(free_mdio_bitbang);
35509 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35510 index 5c05572..389610b 100644
35511 --- a/drivers/net/ppp/ppp_generic.c
35512 +++ b/drivers/net/ppp/ppp_generic.c
35513 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35514 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35515 struct ppp_stats stats;
35516 struct ppp_comp_stats cstats;
35517 - char *vers;
35518
35519 switch (cmd) {
35520 case SIOCGPPPSTATS:
35521 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35522 break;
35523
35524 case SIOCGPPPVER:
35525 - vers = PPP_VERSION;
35526 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35527 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35528 break;
35529 err = 0;
35530 break;
35531 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35532 index 3a16d4f..a311cec 100644
35533 --- a/drivers/net/tun.c
35534 +++ b/drivers/net/tun.c
35535 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35536 }
35537
35538 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35539 - unsigned long arg, int ifreq_len)
35540 + unsigned long arg, size_t ifreq_len)
35541 {
35542 struct tun_file *tfile = file->private_data;
35543 struct tun_struct *tun;
35544 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35545 int vnet_hdr_sz;
35546 int ret;
35547
35548 + if (ifreq_len > sizeof ifr)
35549 + return -EFAULT;
35550 +
35551 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35552 if (copy_from_user(&ifr, argp, ifreq_len))
35553 return -EFAULT;
35554 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35555 index 62f30b4..ff99dfd 100644
35556 --- a/drivers/net/usb/hso.c
35557 +++ b/drivers/net/usb/hso.c
35558 @@ -71,7 +71,7 @@
35559 #include <asm/byteorder.h>
35560 #include <linux/serial_core.h>
35561 #include <linux/serial.h>
35562 -
35563 +#include <asm/local.h>
35564
35565 #define MOD_AUTHOR "Option Wireless"
35566 #define MOD_DESCRIPTION "USB High Speed Option driver"
35567 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35568 struct urb *urb;
35569
35570 urb = serial->rx_urb[0];
35571 - if (serial->port.count > 0) {
35572 + if (atomic_read(&serial->port.count) > 0) {
35573 count = put_rxbuf_data(urb, serial);
35574 if (count == -1)
35575 return;
35576 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35577 DUMP1(urb->transfer_buffer, urb->actual_length);
35578
35579 /* Anyone listening? */
35580 - if (serial->port.count == 0)
35581 + if (atomic_read(&serial->port.count) == 0)
35582 return;
35583
35584 if (status == 0) {
35585 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35586 tty_port_tty_set(&serial->port, tty);
35587
35588 /* check for port already opened, if not set the termios */
35589 - serial->port.count++;
35590 - if (serial->port.count == 1) {
35591 + if (atomic_inc_return(&serial->port.count) == 1) {
35592 serial->rx_state = RX_IDLE;
35593 /* Force default termio settings */
35594 _hso_serial_set_termios(tty, NULL);
35595 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35596 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35597 if (result) {
35598 hso_stop_serial_device(serial->parent);
35599 - serial->port.count--;
35600 + atomic_dec(&serial->port.count);
35601 kref_put(&serial->parent->ref, hso_serial_ref_free);
35602 }
35603 } else {
35604 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35605
35606 /* reset the rts and dtr */
35607 /* do the actual close */
35608 - serial->port.count--;
35609 + atomic_dec(&serial->port.count);
35610
35611 - if (serial->port.count <= 0) {
35612 - serial->port.count = 0;
35613 + if (atomic_read(&serial->port.count) <= 0) {
35614 + atomic_set(&serial->port.count, 0);
35615 tty_port_tty_set(&serial->port, NULL);
35616 if (!usb_gone)
35617 hso_stop_serial_device(serial->parent);
35618 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35619
35620 /* the actual setup */
35621 spin_lock_irqsave(&serial->serial_lock, flags);
35622 - if (serial->port.count)
35623 + if (atomic_read(&serial->port.count))
35624 _hso_serial_set_termios(tty, old);
35625 else
35626 tty->termios = old;
35627 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35628 D1("Pending read interrupt on port %d\n", i);
35629 spin_lock(&serial->serial_lock);
35630 if (serial->rx_state == RX_IDLE &&
35631 - serial->port.count > 0) {
35632 + atomic_read(&serial->port.count) > 0) {
35633 /* Setup and send a ctrl req read on
35634 * port i */
35635 if (!serial->rx_urb_filled[0]) {
35636 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35637 /* Start all serial ports */
35638 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35639 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35640 - if (dev2ser(serial_table[i])->port.count) {
35641 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35642 result =
35643 hso_start_serial_device(serial_table[i], GFP_NOIO);
35644 hso_kick_transmit(dev2ser(serial_table[i]));
35645 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35646 index 6169fbd..40e8422 100644
35647 --- a/drivers/net/wireless/ath/ath.h
35648 +++ b/drivers/net/wireless/ath/ath.h
35649 @@ -119,6 +119,7 @@ struct ath_ops {
35650 void (*write_flush) (void *);
35651 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35652 };
35653 +typedef struct ath_ops __no_const ath_ops_no_const;
35654
35655 struct ath_common;
35656 struct ath_bus_ops;
35657 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35658 index 2aab20e..b761ef8 100644
35659 --- a/drivers/net/wireless/ath/ath5k/base.c
35660 +++ b/drivers/net/wireless/ath/ath5k/base.c
35661 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35662 {
35663 int ret;
35664 struct ath5k_hw *ah = hw->priv;
35665 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35666 + struct ath5k_vif *avf;
35667 struct sk_buff *skb;
35668
35669 if (WARN_ON(!vif)) {
35670 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35671 goto out;
35672 }
35673
35674 + avf = (void *)vif->drv_priv;
35675 ath5k_txbuf_free_skb(ah, avf->bbuf);
35676 avf->bbuf->skb = skb;
35677 ret = ath5k_beacon_setup(ah, avf->bbuf);
35678 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35679 index 8d78253..bebbb68 100644
35680 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35681 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35682 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35683 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35684 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35685
35686 - ACCESS_ONCE(ads->ds_link) = i->link;
35687 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35688 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35689 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35690
35691 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35692 ctl6 = SM(i->keytype, AR_EncrType);
35693 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35694
35695 if ((i->is_first || i->is_last) &&
35696 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35697 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35698 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35699 | set11nTries(i->rates, 1)
35700 | set11nTries(i->rates, 2)
35701 | set11nTries(i->rates, 3)
35702 | (i->dur_update ? AR_DurUpdateEna : 0)
35703 | SM(0, AR_BurstDur);
35704
35705 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35706 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35707 | set11nRate(i->rates, 1)
35708 | set11nRate(i->rates, 2)
35709 | set11nRate(i->rates, 3);
35710 } else {
35711 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35712 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35713 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35714 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35715 }
35716
35717 if (!i->is_first) {
35718 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35719 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35720 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35721 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35722 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35723 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35724 return;
35725 }
35726
35727 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35728 break;
35729 }
35730
35731 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35732 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35733 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35734 | SM(i->txpower, AR_XmitPower)
35735 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35736 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35737 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35738 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35739
35740 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35741 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35742 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35743 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35744
35745 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35746 return;
35747
35748 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35749 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35750 | set11nPktDurRTSCTS(i->rates, 1);
35751
35752 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35753 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35754 | set11nPktDurRTSCTS(i->rates, 3);
35755
35756 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35757 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35758 | set11nRateFlags(i->rates, 1)
35759 | set11nRateFlags(i->rates, 2)
35760 | set11nRateFlags(i->rates, 3)
35761 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35762 index 78816b8..1fcdfae 100644
35763 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35764 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35765 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35766 (i->qcu << AR_TxQcuNum_S) | desc_len;
35767
35768 checksum += val;
35769 - ACCESS_ONCE(ads->info) = val;
35770 + ACCESS_ONCE_RW(ads->info) = val;
35771
35772 checksum += i->link;
35773 - ACCESS_ONCE(ads->link) = i->link;
35774 + ACCESS_ONCE_RW(ads->link) = i->link;
35775
35776 checksum += i->buf_addr[0];
35777 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35778 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35779 checksum += i->buf_addr[1];
35780 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35781 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35782 checksum += i->buf_addr[2];
35783 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35784 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35785 checksum += i->buf_addr[3];
35786 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35787 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35788
35789 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35790 - ACCESS_ONCE(ads->ctl3) = val;
35791 + ACCESS_ONCE_RW(ads->ctl3) = val;
35792 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35793 - ACCESS_ONCE(ads->ctl5) = val;
35794 + ACCESS_ONCE_RW(ads->ctl5) = val;
35795 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35796 - ACCESS_ONCE(ads->ctl7) = val;
35797 + ACCESS_ONCE_RW(ads->ctl7) = val;
35798 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35799 - ACCESS_ONCE(ads->ctl9) = val;
35800 + ACCESS_ONCE_RW(ads->ctl9) = val;
35801
35802 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35803 - ACCESS_ONCE(ads->ctl10) = checksum;
35804 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35805
35806 if (i->is_first || i->is_last) {
35807 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35808 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35809 | set11nTries(i->rates, 1)
35810 | set11nTries(i->rates, 2)
35811 | set11nTries(i->rates, 3)
35812 | (i->dur_update ? AR_DurUpdateEna : 0)
35813 | SM(0, AR_BurstDur);
35814
35815 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35816 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35817 | set11nRate(i->rates, 1)
35818 | set11nRate(i->rates, 2)
35819 | set11nRate(i->rates, 3);
35820 } else {
35821 - ACCESS_ONCE(ads->ctl13) = 0;
35822 - ACCESS_ONCE(ads->ctl14) = 0;
35823 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35824 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35825 }
35826
35827 ads->ctl20 = 0;
35828 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35829
35830 ctl17 = SM(i->keytype, AR_EncrType);
35831 if (!i->is_first) {
35832 - ACCESS_ONCE(ads->ctl11) = 0;
35833 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35834 - ACCESS_ONCE(ads->ctl15) = 0;
35835 - ACCESS_ONCE(ads->ctl16) = 0;
35836 - ACCESS_ONCE(ads->ctl17) = ctl17;
35837 - ACCESS_ONCE(ads->ctl18) = 0;
35838 - ACCESS_ONCE(ads->ctl19) = 0;
35839 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35840 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35841 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35842 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35843 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35844 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35845 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35846 return;
35847 }
35848
35849 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35850 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35851 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35852 | SM(i->txpower, AR_XmitPower)
35853 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35854 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35855 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35856 ctl12 |= SM(val, AR_PAPRDChainMask);
35857
35858 - ACCESS_ONCE(ads->ctl12) = ctl12;
35859 - ACCESS_ONCE(ads->ctl17) = ctl17;
35860 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35861 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35862
35863 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35864 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35865 | set11nPktDurRTSCTS(i->rates, 1);
35866
35867 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35868 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35869 | set11nPktDurRTSCTS(i->rates, 3);
35870
35871 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35872 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35873 | set11nRateFlags(i->rates, 1)
35874 | set11nRateFlags(i->rates, 2)
35875 | set11nRateFlags(i->rates, 3)
35876 | SM(i->rtscts_rate, AR_RTSCTSRate);
35877
35878 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35879 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35880 }
35881
35882 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35883 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35884 index de6968f..29ac4c1 100644
35885 --- a/drivers/net/wireless/ath/ath9k/hw.h
35886 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35887 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35888
35889 /* ANI */
35890 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35891 -};
35892 +} __no_const;
35893
35894 /**
35895 * struct ath_hw_ops - callbacks used by hardware code and driver code
35896 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35897 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35898 struct ath_hw_antcomb_conf *antconf);
35899
35900 -};
35901 +} __no_const;
35902
35903 struct ath_nf_limits {
35904 s16 max;
35905 @@ -706,7 +706,7 @@ enum ath_cal_list {
35906 #define AH_FASTCC 0x4
35907
35908 struct ath_hw {
35909 - struct ath_ops reg_ops;
35910 + ath_ops_no_const reg_ops;
35911
35912 struct ieee80211_hw *hw;
35913 struct ath_common common;
35914 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35915 index af00e2c..ab04d34 100644
35916 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35917 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35918 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35919 void (*carrsuppr)(struct brcms_phy *);
35920 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35921 void (*detach)(struct brcms_phy *);
35922 -};
35923 +} __no_const;
35924
35925 struct brcms_phy {
35926 struct brcms_phy_pub pubpi_ro;
35927 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35928 index faec404..a5277f1 100644
35929 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35930 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35931 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35932 */
35933 if (il3945_mod_params.disable_hw_scan) {
35934 D_INFO("Disabling hw_scan\n");
35935 - il3945_mac_ops.hw_scan = NULL;
35936 + pax_open_kernel();
35937 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35938 + pax_close_kernel();
35939 }
35940
35941 D_INFO("*** LOAD DRIVER ***\n");
35942 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35943 index a47b306..297daf2 100644
35944 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35945 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35946 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35947 {
35948 struct iwl_priv *priv = file->private_data;
35949 char buf[64];
35950 - int buf_size;
35951 + size_t buf_size;
35952 u32 offset, len;
35953
35954 memset(buf, 0, sizeof(buf));
35955 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35956 struct iwl_priv *priv = file->private_data;
35957
35958 char buf[8];
35959 - int buf_size;
35960 + size_t buf_size;
35961 u32 reset_flag;
35962
35963 memset(buf, 0, sizeof(buf));
35964 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35965 {
35966 struct iwl_priv *priv = file->private_data;
35967 char buf[8];
35968 - int buf_size;
35969 + size_t buf_size;
35970 int ht40;
35971
35972 memset(buf, 0, sizeof(buf));
35973 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35974 {
35975 struct iwl_priv *priv = file->private_data;
35976 char buf[8];
35977 - int buf_size;
35978 + size_t buf_size;
35979 int value;
35980
35981 memset(buf, 0, sizeof(buf));
35982 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35983 {
35984 struct iwl_priv *priv = file->private_data;
35985 char buf[8];
35986 - int buf_size;
35987 + size_t buf_size;
35988 int clear;
35989
35990 memset(buf, 0, sizeof(buf));
35991 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35992 {
35993 struct iwl_priv *priv = file->private_data;
35994 char buf[8];
35995 - int buf_size;
35996 + size_t buf_size;
35997 int trace;
35998
35999 memset(buf, 0, sizeof(buf));
36000 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36001 {
36002 struct iwl_priv *priv = file->private_data;
36003 char buf[8];
36004 - int buf_size;
36005 + size_t buf_size;
36006 int missed;
36007
36008 memset(buf, 0, sizeof(buf));
36009 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36010
36011 struct iwl_priv *priv = file->private_data;
36012 char buf[8];
36013 - int buf_size;
36014 + size_t buf_size;
36015 int plcp;
36016
36017 memset(buf, 0, sizeof(buf));
36018 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36019
36020 struct iwl_priv *priv = file->private_data;
36021 char buf[8];
36022 - int buf_size;
36023 + size_t buf_size;
36024 int flush;
36025
36026 memset(buf, 0, sizeof(buf));
36027 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36028
36029 struct iwl_priv *priv = file->private_data;
36030 char buf[8];
36031 - int buf_size;
36032 + size_t buf_size;
36033 int rts;
36034
36035 if (!priv->cfg->ht_params)
36036 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36037 {
36038 struct iwl_priv *priv = file->private_data;
36039 char buf[8];
36040 - int buf_size;
36041 + size_t buf_size;
36042
36043 memset(buf, 0, sizeof(buf));
36044 buf_size = min(count, sizeof(buf) - 1);
36045 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36046 struct iwl_priv *priv = file->private_data;
36047 u32 event_log_flag;
36048 char buf[8];
36049 - int buf_size;
36050 + size_t buf_size;
36051
36052 /* check that the interface is up */
36053 if (!iwl_is_ready(priv))
36054 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36055 struct iwl_priv *priv = file->private_data;
36056 char buf[8];
36057 u32 calib_disabled;
36058 - int buf_size;
36059 + size_t buf_size;
36060
36061 memset(buf, 0, sizeof(buf));
36062 buf_size = min(count, sizeof(buf) - 1);
36063 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36064 index dbeebef..b45a152 100644
36065 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36066 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36067 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36068 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36069
36070 char buf[8];
36071 - int buf_size;
36072 + size_t buf_size;
36073 u32 reset_flag;
36074
36075 memset(buf, 0, sizeof(buf));
36076 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36077 {
36078 struct iwl_trans *trans = file->private_data;
36079 char buf[8];
36080 - int buf_size;
36081 + size_t buf_size;
36082 int csr;
36083
36084 memset(buf, 0, sizeof(buf));
36085 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36086 index 0083839..fcb7225 100644
36087 --- a/drivers/net/wireless/mac80211_hwsim.c
36088 +++ b/drivers/net/wireless/mac80211_hwsim.c
36089 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36090 return -EINVAL;
36091
36092 if (fake_hw_scan) {
36093 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36094 - mac80211_hwsim_ops.sw_scan_start = NULL;
36095 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36096 + pax_open_kernel();
36097 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36098 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36099 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36100 + pax_close_kernel();
36101 }
36102
36103 spin_lock_init(&hwsim_radio_lock);
36104 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36105 index e7c2a82..582e228 100644
36106 --- a/drivers/net/wireless/mwifiex/main.h
36107 +++ b/drivers/net/wireless/mwifiex/main.h
36108 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36109 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36110 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36111 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36112 -};
36113 +} __no_const;
36114
36115 struct mwifiex_adapter {
36116 u8 iface_type;
36117 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36118 index 7a4ae9e..56e00bd 100644
36119 --- a/drivers/net/wireless/rndis_wlan.c
36120 +++ b/drivers/net/wireless/rndis_wlan.c
36121 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36122
36123 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36124
36125 - if (rts_threshold < 0 || rts_threshold > 2347)
36126 + if (rts_threshold > 2347)
36127 rts_threshold = 2347;
36128
36129 tmp = cpu_to_le32(rts_threshold);
36130 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36131 index 8afb546..0c0dc5c 100644
36132 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36133 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36134 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36135 * for hardware which doesn't support hardware
36136 * sequence counting.
36137 */
36138 - atomic_t seqno;
36139 + atomic_unchecked_t seqno;
36140 };
36141
36142 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36143 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36144 index f7e74a0..da71431 100644
36145 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36146 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36147 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36148 * sequence counter given by mac80211.
36149 */
36150 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36151 - seqno = atomic_add_return(0x10, &intf->seqno);
36152 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36153 else
36154 - seqno = atomic_read(&intf->seqno);
36155 + seqno = atomic_read_unchecked(&intf->seqno);
36156
36157 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36158 hdr->seq_ctrl |= cpu_to_le16(seqno);
36159 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36160 index fd02060..74ee481 100644
36161 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36162 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36163 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36164 void (*reset)(struct wl1251 *wl);
36165 void (*enable_irq)(struct wl1251 *wl);
36166 void (*disable_irq)(struct wl1251 *wl);
36167 -};
36168 +} __no_const;
36169
36170 struct wl1251 {
36171 struct ieee80211_hw *hw;
36172 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36173 index 0ce7a8e..56a0ccf 100644
36174 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36175 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36176 @@ -81,7 +81,7 @@ struct wlcore_ops {
36177 struct ieee80211_sta *sta,
36178 struct ieee80211_key_conf *key_conf);
36179 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36180 -};
36181 +} __no_const;
36182
36183 enum wlcore_partitions {
36184 PART_DOWN,
36185 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36186 index f34b5b2..b5abb9f 100644
36187 --- a/drivers/oprofile/buffer_sync.c
36188 +++ b/drivers/oprofile/buffer_sync.c
36189 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36190 if (cookie == NO_COOKIE)
36191 offset = pc;
36192 if (cookie == INVALID_COOKIE) {
36193 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36194 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36195 offset = pc;
36196 }
36197 if (cookie != last_cookie) {
36198 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36199 /* add userspace sample */
36200
36201 if (!mm) {
36202 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36203 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36204 return 0;
36205 }
36206
36207 cookie = lookup_dcookie(mm, s->eip, &offset);
36208
36209 if (cookie == INVALID_COOKIE) {
36210 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36211 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36212 return 0;
36213 }
36214
36215 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36216 /* ignore backtraces if failed to add a sample */
36217 if (state == sb_bt_start) {
36218 state = sb_bt_ignore;
36219 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36220 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36221 }
36222 }
36223 release_mm(mm);
36224 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36225 index c0cc4e7..44d4e54 100644
36226 --- a/drivers/oprofile/event_buffer.c
36227 +++ b/drivers/oprofile/event_buffer.c
36228 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36229 }
36230
36231 if (buffer_pos == buffer_size) {
36232 - atomic_inc(&oprofile_stats.event_lost_overflow);
36233 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36234 return;
36235 }
36236
36237 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36238 index ed2c3ec..deda85a 100644
36239 --- a/drivers/oprofile/oprof.c
36240 +++ b/drivers/oprofile/oprof.c
36241 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36242 if (oprofile_ops.switch_events())
36243 return;
36244
36245 - atomic_inc(&oprofile_stats.multiplex_counter);
36246 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36247 start_switch_worker();
36248 }
36249
36250 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36251 index 917d28e..d62d981 100644
36252 --- a/drivers/oprofile/oprofile_stats.c
36253 +++ b/drivers/oprofile/oprofile_stats.c
36254 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36255 cpu_buf->sample_invalid_eip = 0;
36256 }
36257
36258 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36259 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36260 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36261 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36262 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36263 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36264 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36265 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36266 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36267 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36268 }
36269
36270
36271 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36272 index 38b6fc0..b5cbfce 100644
36273 --- a/drivers/oprofile/oprofile_stats.h
36274 +++ b/drivers/oprofile/oprofile_stats.h
36275 @@ -13,11 +13,11 @@
36276 #include <linux/atomic.h>
36277
36278 struct oprofile_stat_struct {
36279 - atomic_t sample_lost_no_mm;
36280 - atomic_t sample_lost_no_mapping;
36281 - atomic_t bt_lost_no_mapping;
36282 - atomic_t event_lost_overflow;
36283 - atomic_t multiplex_counter;
36284 + atomic_unchecked_t sample_lost_no_mm;
36285 + atomic_unchecked_t sample_lost_no_mapping;
36286 + atomic_unchecked_t bt_lost_no_mapping;
36287 + atomic_unchecked_t event_lost_overflow;
36288 + atomic_unchecked_t multiplex_counter;
36289 };
36290
36291 extern struct oprofile_stat_struct oprofile_stats;
36292 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36293 index 849357c..b83c1e0 100644
36294 --- a/drivers/oprofile/oprofilefs.c
36295 +++ b/drivers/oprofile/oprofilefs.c
36296 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36297
36298
36299 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36300 - char const *name, atomic_t *val)
36301 + char const *name, atomic_unchecked_t *val)
36302 {
36303 return __oprofilefs_create_file(sb, root, name,
36304 &atomic_ro_fops, 0444, val);
36305 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36306 index 3f56bc0..707d642 100644
36307 --- a/drivers/parport/procfs.c
36308 +++ b/drivers/parport/procfs.c
36309 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36310
36311 *ppos += len;
36312
36313 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36314 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36315 }
36316
36317 #ifdef CONFIG_PARPORT_1284
36318 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36319
36320 *ppos += len;
36321
36322 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36323 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36324 }
36325 #endif /* IEEE1284.3 support. */
36326
36327 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36328 index 9fff878..ad0ad53 100644
36329 --- a/drivers/pci/hotplug/cpci_hotplug.h
36330 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36331 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36332 int (*hardware_test) (struct slot* slot, u32 value);
36333 u8 (*get_power) (struct slot* slot);
36334 int (*set_power) (struct slot* slot, int value);
36335 -};
36336 +} __no_const;
36337
36338 struct cpci_hp_controller {
36339 unsigned int irq;
36340 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36341 index 76ba8a1..20ca857 100644
36342 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36343 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36344 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36345
36346 void compaq_nvram_init (void __iomem *rom_start)
36347 {
36348 +
36349 +#ifndef CONFIG_PAX_KERNEXEC
36350 if (rom_start) {
36351 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36352 }
36353 +#endif
36354 +
36355 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36356
36357 /* initialize our int15 lock */
36358 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36359 index b500840..d7159d3 100644
36360 --- a/drivers/pci/pcie/aspm.c
36361 +++ b/drivers/pci/pcie/aspm.c
36362 @@ -27,9 +27,9 @@
36363 #define MODULE_PARAM_PREFIX "pcie_aspm."
36364
36365 /* Note: those are not register definitions */
36366 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36367 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36368 -#define ASPM_STATE_L1 (4) /* L1 state */
36369 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36370 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36371 +#define ASPM_STATE_L1 (4U) /* L1 state */
36372 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36373 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36374
36375 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36376 index 61859d0..124539e 100644
36377 --- a/drivers/pci/probe.c
36378 +++ b/drivers/pci/probe.c
36379 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36380 struct pci_bus_region region;
36381 bool bar_too_big = false, bar_disabled = false;
36382
36383 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36384 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36385
36386 /* No printks while decoding is disabled! */
36387 if (!dev->mmio_always_on) {
36388 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36389 index 27911b5..5b6db88 100644
36390 --- a/drivers/pci/proc.c
36391 +++ b/drivers/pci/proc.c
36392 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36393 static int __init pci_proc_init(void)
36394 {
36395 struct pci_dev *dev = NULL;
36396 +
36397 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36398 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36399 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36400 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36401 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36402 +#endif
36403 +#else
36404 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36405 +#endif
36406 proc_create("devices", 0, proc_bus_pci_dir,
36407 &proc_bus_pci_dev_operations);
36408 proc_initialized = 1;
36409 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36410 index 52daaa8..d6b81eb 100644
36411 --- a/drivers/platform/x86/thinkpad_acpi.c
36412 +++ b/drivers/platform/x86/thinkpad_acpi.c
36413 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36414 return 0;
36415 }
36416
36417 -void static hotkey_mask_warn_incomplete_mask(void)
36418 +static void hotkey_mask_warn_incomplete_mask(void)
36419 {
36420 /* log only what the user can fix... */
36421 const u32 wantedmask = hotkey_driver_mask &
36422 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36423 }
36424 }
36425
36426 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36427 - struct tp_nvram_state *newn,
36428 - const u32 event_mask)
36429 -{
36430 -
36431 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36432 do { \
36433 if ((event_mask & (1 << __scancode)) && \
36434 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36435 tpacpi_hotkey_send_key(__scancode); \
36436 } while (0)
36437
36438 - void issue_volchange(const unsigned int oldvol,
36439 - const unsigned int newvol)
36440 - {
36441 - unsigned int i = oldvol;
36442 +static void issue_volchange(const unsigned int oldvol,
36443 + const unsigned int newvol,
36444 + const u32 event_mask)
36445 +{
36446 + unsigned int i = oldvol;
36447
36448 - while (i > newvol) {
36449 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36450 - i--;
36451 - }
36452 - while (i < newvol) {
36453 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36454 - i++;
36455 - }
36456 + while (i > newvol) {
36457 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36458 + i--;
36459 }
36460 + while (i < newvol) {
36461 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36462 + i++;
36463 + }
36464 +}
36465
36466 - void issue_brightnesschange(const unsigned int oldbrt,
36467 - const unsigned int newbrt)
36468 - {
36469 - unsigned int i = oldbrt;
36470 +static void issue_brightnesschange(const unsigned int oldbrt,
36471 + const unsigned int newbrt,
36472 + const u32 event_mask)
36473 +{
36474 + unsigned int i = oldbrt;
36475
36476 - while (i > newbrt) {
36477 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36478 - i--;
36479 - }
36480 - while (i < newbrt) {
36481 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36482 - i++;
36483 - }
36484 + while (i > newbrt) {
36485 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36486 + i--;
36487 + }
36488 + while (i < newbrt) {
36489 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36490 + i++;
36491 }
36492 +}
36493
36494 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36495 + struct tp_nvram_state *newn,
36496 + const u32 event_mask)
36497 +{
36498 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36499 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36500 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36501 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36502 oldn->volume_level != newn->volume_level) {
36503 /* recently muted, or repeated mute keypress, or
36504 * multiple presses ending in mute */
36505 - issue_volchange(oldn->volume_level, newn->volume_level);
36506 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36507 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36508 }
36509 } else {
36510 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36511 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36512 }
36513 if (oldn->volume_level != newn->volume_level) {
36514 - issue_volchange(oldn->volume_level, newn->volume_level);
36515 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36516 } else if (oldn->volume_toggle != newn->volume_toggle) {
36517 /* repeated vol up/down keypress at end of scale ? */
36518 if (newn->volume_level == 0)
36519 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36520 /* handle brightness */
36521 if (oldn->brightness_level != newn->brightness_level) {
36522 issue_brightnesschange(oldn->brightness_level,
36523 - newn->brightness_level);
36524 + newn->brightness_level,
36525 + event_mask);
36526 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36527 /* repeated key presses that didn't change state */
36528 if (newn->brightness_level == 0)
36529 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36530 && !tp_features.bright_unkfw)
36531 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36532 }
36533 +}
36534
36535 #undef TPACPI_COMPARE_KEY
36536 #undef TPACPI_MAY_SEND_KEY
36537 -}
36538
36539 /*
36540 * Polling driver
36541 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36542 index 769d265..a3a05ca 100644
36543 --- a/drivers/pnp/pnpbios/bioscalls.c
36544 +++ b/drivers/pnp/pnpbios/bioscalls.c
36545 @@ -58,7 +58,7 @@ do { \
36546 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36547 } while(0)
36548
36549 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36550 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36551 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36552
36553 /*
36554 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36555
36556 cpu = get_cpu();
36557 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36558 +
36559 + pax_open_kernel();
36560 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36561 + pax_close_kernel();
36562
36563 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36564 spin_lock_irqsave(&pnp_bios_lock, flags);
36565 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36566 :"memory");
36567 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36568
36569 + pax_open_kernel();
36570 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36571 + pax_close_kernel();
36572 +
36573 put_cpu();
36574
36575 /* If we get here and this is set then the PnP BIOS faulted on us. */
36576 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36577 return status;
36578 }
36579
36580 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36581 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36582 {
36583 int i;
36584
36585 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36586 pnp_bios_callpoint.offset = header->fields.pm16offset;
36587 pnp_bios_callpoint.segment = PNP_CS16;
36588
36589 + pax_open_kernel();
36590 +
36591 for_each_possible_cpu(i) {
36592 struct desc_struct *gdt = get_cpu_gdt_table(i);
36593 if (!gdt)
36594 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36595 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36596 (unsigned long)__va(header->fields.pm16dseg));
36597 }
36598 +
36599 + pax_close_kernel();
36600 }
36601 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36602 index b0ecacb..7c9da2e 100644
36603 --- a/drivers/pnp/resource.c
36604 +++ b/drivers/pnp/resource.c
36605 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36606 return 1;
36607
36608 /* check if the resource is valid */
36609 - if (*irq < 0 || *irq > 15)
36610 + if (*irq > 15)
36611 return 0;
36612
36613 /* check if the resource is reserved */
36614 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36615 return 1;
36616
36617 /* check if the resource is valid */
36618 - if (*dma < 0 || *dma == 4 || *dma > 7)
36619 + if (*dma == 4 || *dma > 7)
36620 return 0;
36621
36622 /* check if the resource is reserved */
36623 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36624 index 181ddec..774b6da 100644
36625 --- a/drivers/power/bq27x00_battery.c
36626 +++ b/drivers/power/bq27x00_battery.c
36627 @@ -80,7 +80,7 @@
36628 struct bq27x00_device_info;
36629 struct bq27x00_access_methods {
36630 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36631 -};
36632 +} __no_const;
36633
36634 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36635
36636 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36637 index 8d53174..04c65de 100644
36638 --- a/drivers/regulator/max8660.c
36639 +++ b/drivers/regulator/max8660.c
36640 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36641 max8660->shadow_regs[MAX8660_OVER1] = 5;
36642 } else {
36643 /* Otherwise devices can be toggled via software */
36644 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36645 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36646 + pax_open_kernel();
36647 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36648 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36649 + pax_close_kernel();
36650 }
36651
36652 /*
36653 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36654 index b388b74..ed82573 100644
36655 --- a/drivers/regulator/mc13892-regulator.c
36656 +++ b/drivers/regulator/mc13892-regulator.c
36657 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36658 }
36659 mc13xxx_unlock(mc13892);
36660
36661 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36662 + pax_open_kernel();
36663 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36664 = mc13892_vcam_set_mode;
36665 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36666 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36667 = mc13892_vcam_get_mode;
36668 + pax_close_kernel();
36669
36670 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36671 ARRAY_SIZE(mc13892_regulators));
36672 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36673 index cace6d3..f623fda 100644
36674 --- a/drivers/rtc/rtc-dev.c
36675 +++ b/drivers/rtc/rtc-dev.c
36676 @@ -14,6 +14,7 @@
36677 #include <linux/module.h>
36678 #include <linux/rtc.h>
36679 #include <linux/sched.h>
36680 +#include <linux/grsecurity.h>
36681 #include "rtc-core.h"
36682
36683 static dev_t rtc_devt;
36684 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36685 if (copy_from_user(&tm, uarg, sizeof(tm)))
36686 return -EFAULT;
36687
36688 + gr_log_timechange();
36689 +
36690 return rtc_set_time(rtc, &tm);
36691
36692 case RTC_PIE_ON:
36693 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36694 index 9e933a8..4f969f7 100644
36695 --- a/drivers/scsi/aacraid/aacraid.h
36696 +++ b/drivers/scsi/aacraid/aacraid.h
36697 @@ -503,7 +503,7 @@ struct adapter_ops
36698 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36699 /* Administrative operations */
36700 int (*adapter_comm)(struct aac_dev * dev, int comm);
36701 -};
36702 +} __no_const;
36703
36704 /*
36705 * Define which interrupt handler needs to be installed
36706 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36707 index 7199534..cb7f158 100644
36708 --- a/drivers/scsi/aacraid/linit.c
36709 +++ b/drivers/scsi/aacraid/linit.c
36710 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36711 #elif defined(__devinitconst)
36712 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36713 #else
36714 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36715 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36716 #endif
36717 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36718 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36719 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36720 index ff80552..1c4120c 100644
36721 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36722 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36723 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36724 .lldd_ata_set_dmamode = asd_set_dmamode,
36725 };
36726
36727 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36728 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36729 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36730 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36731 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36732 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36733 index 4ad7e36..d004679 100644
36734 --- a/drivers/scsi/bfa/bfa.h
36735 +++ b/drivers/scsi/bfa/bfa.h
36736 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36737 u32 *end);
36738 int cpe_vec_q0;
36739 int rme_vec_q0;
36740 -};
36741 +} __no_const;
36742 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36743
36744 struct bfa_faa_cbfn_s {
36745 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36746 index f0f80e2..8ec946b 100644
36747 --- a/drivers/scsi/bfa/bfa_fcpim.c
36748 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36749 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36750
36751 bfa_iotag_attach(fcp);
36752
36753 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36754 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36755 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36756 (fcp->num_itns * sizeof(struct bfa_itn_s));
36757 memset(fcp->itn_arr, 0,
36758 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36759 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36760 {
36761 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36762 - struct bfa_itn_s *itn;
36763 + bfa_itn_s_no_const *itn;
36764
36765 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36766 itn->isr = isr;
36767 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36768 index 36f26da..38a34a8 100644
36769 --- a/drivers/scsi/bfa/bfa_fcpim.h
36770 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36771 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36772 struct bfa_itn_s {
36773 bfa_isr_func_t isr;
36774 };
36775 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36776
36777 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36778 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36779 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36780 struct list_head iotag_tio_free_q; /* free IO resources */
36781 struct list_head iotag_unused_q; /* unused IO resources*/
36782 struct bfa_iotag_s *iotag_arr;
36783 - struct bfa_itn_s *itn_arr;
36784 + bfa_itn_s_no_const *itn_arr;
36785 int num_ioim_reqs;
36786 int num_fwtio_reqs;
36787 int num_itns;
36788 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36789 index 1a99d4b..e85d64b 100644
36790 --- a/drivers/scsi/bfa/bfa_ioc.h
36791 +++ b/drivers/scsi/bfa/bfa_ioc.h
36792 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36793 bfa_ioc_disable_cbfn_t disable_cbfn;
36794 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36795 bfa_ioc_reset_cbfn_t reset_cbfn;
36796 -};
36797 +} __no_const;
36798
36799 /*
36800 * IOC event notification mechanism.
36801 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36802 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36803 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36804 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36805 -};
36806 +} __no_const;
36807
36808 /*
36809 * Queue element to wait for room in request queue. FIFO order is
36810 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36811 index 593085a..47aa999 100644
36812 --- a/drivers/scsi/hosts.c
36813 +++ b/drivers/scsi/hosts.c
36814 @@ -42,7 +42,7 @@
36815 #include "scsi_logging.h"
36816
36817
36818 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36819 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36820
36821
36822 static void scsi_host_cls_release(struct device *dev)
36823 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36824 * subtract one because we increment first then return, but we need to
36825 * know what the next host number was before increment
36826 */
36827 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36828 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36829 shost->dma_channel = 0xff;
36830
36831 /* These three are default values which can be overridden */
36832 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36833 index f9823f2..7bc3e81 100644
36834 --- a/drivers/scsi/hpsa.c
36835 +++ b/drivers/scsi/hpsa.c
36836 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36837 unsigned long flags;
36838
36839 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36840 - return h->access.command_completed(h, q);
36841 + return h->access->command_completed(h, q);
36842
36843 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36844 a = rq->head[rq->current_entry];
36845 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36846 while (!list_empty(&h->reqQ)) {
36847 c = list_entry(h->reqQ.next, struct CommandList, list);
36848 /* can't do anything if fifo is full */
36849 - if ((h->access.fifo_full(h))) {
36850 + if ((h->access->fifo_full(h))) {
36851 dev_warn(&h->pdev->dev, "fifo full\n");
36852 break;
36853 }
36854 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36855
36856 /* Tell the controller execute command */
36857 spin_unlock_irqrestore(&h->lock, flags);
36858 - h->access.submit_command(h, c);
36859 + h->access->submit_command(h, c);
36860 spin_lock_irqsave(&h->lock, flags);
36861 }
36862 spin_unlock_irqrestore(&h->lock, flags);
36863 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36864
36865 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36866 {
36867 - return h->access.command_completed(h, q);
36868 + return h->access->command_completed(h, q);
36869 }
36870
36871 static inline bool interrupt_pending(struct ctlr_info *h)
36872 {
36873 - return h->access.intr_pending(h);
36874 + return h->access->intr_pending(h);
36875 }
36876
36877 static inline long interrupt_not_for_us(struct ctlr_info *h)
36878 {
36879 - return (h->access.intr_pending(h) == 0) ||
36880 + return (h->access->intr_pending(h) == 0) ||
36881 (h->interrupts_enabled == 0);
36882 }
36883
36884 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36885 if (prod_index < 0)
36886 return -ENODEV;
36887 h->product_name = products[prod_index].product_name;
36888 - h->access = *(products[prod_index].access);
36889 + h->access = products[prod_index].access;
36890
36891 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36892 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36893 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36894
36895 assert_spin_locked(&lockup_detector_lock);
36896 remove_ctlr_from_lockup_detector_list(h);
36897 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36898 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36899 spin_lock_irqsave(&h->lock, flags);
36900 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36901 spin_unlock_irqrestore(&h->lock, flags);
36902 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36903 }
36904
36905 /* make sure the board interrupts are off */
36906 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36907 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36908
36909 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36910 goto clean2;
36911 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36912 * fake ones to scoop up any residual completions.
36913 */
36914 spin_lock_irqsave(&h->lock, flags);
36915 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36916 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36917 spin_unlock_irqrestore(&h->lock, flags);
36918 free_irqs(h);
36919 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36920 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36921 dev_info(&h->pdev->dev, "Board READY.\n");
36922 dev_info(&h->pdev->dev,
36923 "Waiting for stale completions to drain.\n");
36924 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36925 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36926 msleep(10000);
36927 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36928 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36929
36930 rc = controller_reset_failed(h->cfgtable);
36931 if (rc)
36932 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36933 }
36934
36935 /* Turn the interrupts on so we can service requests */
36936 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36937 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36938
36939 hpsa_hba_inquiry(h);
36940 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36941 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36942 * To write all data in the battery backed cache to disks
36943 */
36944 hpsa_flush_cache(h);
36945 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36946 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36947 hpsa_free_irqs_and_disable_msix(h);
36948 }
36949
36950 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36951 return;
36952 }
36953 /* Change the access methods to the performant access methods */
36954 - h->access = SA5_performant_access;
36955 + h->access = &SA5_performant_access;
36956 h->transMethod = CFGTBL_Trans_Performant;
36957 }
36958
36959 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36960 index 9816479..c5d4e97 100644
36961 --- a/drivers/scsi/hpsa.h
36962 +++ b/drivers/scsi/hpsa.h
36963 @@ -79,7 +79,7 @@ struct ctlr_info {
36964 unsigned int msix_vector;
36965 unsigned int msi_vector;
36966 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36967 - struct access_method access;
36968 + struct access_method *access;
36969
36970 /* queue and queue Info */
36971 struct list_head reqQ;
36972 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36973 index f2df059..a3a9930 100644
36974 --- a/drivers/scsi/ips.h
36975 +++ b/drivers/scsi/ips.h
36976 @@ -1027,7 +1027,7 @@ typedef struct {
36977 int (*intr)(struct ips_ha *);
36978 void (*enableint)(struct ips_ha *);
36979 uint32_t (*statupd)(struct ips_ha *);
36980 -} ips_hw_func_t;
36981 +} __no_const ips_hw_func_t;
36982
36983 typedef struct ips_ha {
36984 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36985 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36986 index c772d8d..35c362c 100644
36987 --- a/drivers/scsi/libfc/fc_exch.c
36988 +++ b/drivers/scsi/libfc/fc_exch.c
36989 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36990 u16 pool_max_index;
36991
36992 struct {
36993 - atomic_t no_free_exch;
36994 - atomic_t no_free_exch_xid;
36995 - atomic_t xid_not_found;
36996 - atomic_t xid_busy;
36997 - atomic_t seq_not_found;
36998 - atomic_t non_bls_resp;
36999 + atomic_unchecked_t no_free_exch;
37000 + atomic_unchecked_t no_free_exch_xid;
37001 + atomic_unchecked_t xid_not_found;
37002 + atomic_unchecked_t xid_busy;
37003 + atomic_unchecked_t seq_not_found;
37004 + atomic_unchecked_t non_bls_resp;
37005 } stats;
37006 };
37007
37008 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37009 /* allocate memory for exchange */
37010 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37011 if (!ep) {
37012 - atomic_inc(&mp->stats.no_free_exch);
37013 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37014 goto out;
37015 }
37016 memset(ep, 0, sizeof(*ep));
37017 @@ -786,7 +786,7 @@ out:
37018 return ep;
37019 err:
37020 spin_unlock_bh(&pool->lock);
37021 - atomic_inc(&mp->stats.no_free_exch_xid);
37022 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37023 mempool_free(ep, mp->ep_pool);
37024 return NULL;
37025 }
37026 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37027 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37028 ep = fc_exch_find(mp, xid);
37029 if (!ep) {
37030 - atomic_inc(&mp->stats.xid_not_found);
37031 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37032 reject = FC_RJT_OX_ID;
37033 goto out;
37034 }
37035 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37036 ep = fc_exch_find(mp, xid);
37037 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37038 if (ep) {
37039 - atomic_inc(&mp->stats.xid_busy);
37040 + atomic_inc_unchecked(&mp->stats.xid_busy);
37041 reject = FC_RJT_RX_ID;
37042 goto rel;
37043 }
37044 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37045 }
37046 xid = ep->xid; /* get our XID */
37047 } else if (!ep) {
37048 - atomic_inc(&mp->stats.xid_not_found);
37049 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37050 reject = FC_RJT_RX_ID; /* XID not found */
37051 goto out;
37052 }
37053 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37054 } else {
37055 sp = &ep->seq;
37056 if (sp->id != fh->fh_seq_id) {
37057 - atomic_inc(&mp->stats.seq_not_found);
37058 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37059 if (f_ctl & FC_FC_END_SEQ) {
37060 /*
37061 * Update sequence_id based on incoming last
37062 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37063
37064 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37065 if (!ep) {
37066 - atomic_inc(&mp->stats.xid_not_found);
37067 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37068 goto out;
37069 }
37070 if (ep->esb_stat & ESB_ST_COMPLETE) {
37071 - atomic_inc(&mp->stats.xid_not_found);
37072 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37073 goto rel;
37074 }
37075 if (ep->rxid == FC_XID_UNKNOWN)
37076 ep->rxid = ntohs(fh->fh_rx_id);
37077 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37078 - atomic_inc(&mp->stats.xid_not_found);
37079 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37080 goto rel;
37081 }
37082 if (ep->did != ntoh24(fh->fh_s_id) &&
37083 ep->did != FC_FID_FLOGI) {
37084 - atomic_inc(&mp->stats.xid_not_found);
37085 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37086 goto rel;
37087 }
37088 sof = fr_sof(fp);
37089 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37090 sp->ssb_stat |= SSB_ST_RESP;
37091 sp->id = fh->fh_seq_id;
37092 } else if (sp->id != fh->fh_seq_id) {
37093 - atomic_inc(&mp->stats.seq_not_found);
37094 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37095 goto rel;
37096 }
37097
37098 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37099 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37100
37101 if (!sp)
37102 - atomic_inc(&mp->stats.xid_not_found);
37103 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37104 else
37105 - atomic_inc(&mp->stats.non_bls_resp);
37106 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37107
37108 fc_frame_free(fp);
37109 }
37110 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37111
37112 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37113 mp = ema->mp;
37114 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37115 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37116 st->fc_no_free_exch_xid +=
37117 - atomic_read(&mp->stats.no_free_exch_xid);
37118 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37119 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37120 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37121 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37122 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37123 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37124 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37125 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37126 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37127 }
37128 }
37129 EXPORT_SYMBOL(fc_exch_update_stats);
37130 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37131 index a59fcdc..abe55f3 100644
37132 --- a/drivers/scsi/libsas/sas_ata.c
37133 +++ b/drivers/scsi/libsas/sas_ata.c
37134 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37135 .postreset = ata_std_postreset,
37136 .error_handler = ata_std_error_handler,
37137 .post_internal_cmd = sas_ata_post_internal,
37138 - .qc_defer = ata_std_qc_defer,
37139 + .qc_defer = ata_std_qc_defer,
37140 .qc_prep = ata_noop_qc_prep,
37141 .qc_issue = sas_ata_qc_issue,
37142 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37143 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37144 index a65c05a..a39e402 100644
37145 --- a/drivers/scsi/lpfc/lpfc.h
37146 +++ b/drivers/scsi/lpfc/lpfc.h
37147 @@ -420,7 +420,7 @@ struct lpfc_vport {
37148 struct dentry *debug_nodelist;
37149 struct dentry *vport_debugfs_root;
37150 struct lpfc_debugfs_trc *disc_trc;
37151 - atomic_t disc_trc_cnt;
37152 + atomic_unchecked_t disc_trc_cnt;
37153 #endif
37154 uint8_t stat_data_enabled;
37155 uint8_t stat_data_blocked;
37156 @@ -834,8 +834,8 @@ struct lpfc_hba {
37157 struct timer_list fabric_block_timer;
37158 unsigned long bit_flags;
37159 #define FABRIC_COMANDS_BLOCKED 0
37160 - atomic_t num_rsrc_err;
37161 - atomic_t num_cmd_success;
37162 + atomic_unchecked_t num_rsrc_err;
37163 + atomic_unchecked_t num_cmd_success;
37164 unsigned long last_rsrc_error_time;
37165 unsigned long last_ramp_down_time;
37166 unsigned long last_ramp_up_time;
37167 @@ -871,7 +871,7 @@ struct lpfc_hba {
37168
37169 struct dentry *debug_slow_ring_trc;
37170 struct lpfc_debugfs_trc *slow_ring_trc;
37171 - atomic_t slow_ring_trc_cnt;
37172 + atomic_unchecked_t slow_ring_trc_cnt;
37173 /* iDiag debugfs sub-directory */
37174 struct dentry *idiag_root;
37175 struct dentry *idiag_pci_cfg;
37176 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37177 index 3217d63..c417981 100644
37178 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37179 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37180 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37181
37182 #include <linux/debugfs.h>
37183
37184 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37185 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37186 static unsigned long lpfc_debugfs_start_time = 0L;
37187
37188 /* iDiag */
37189 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37190 lpfc_debugfs_enable = 0;
37191
37192 len = 0;
37193 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37194 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37195 (lpfc_debugfs_max_disc_trc - 1);
37196 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37197 dtp = vport->disc_trc + i;
37198 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37199 lpfc_debugfs_enable = 0;
37200
37201 len = 0;
37202 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37203 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37204 (lpfc_debugfs_max_slow_ring_trc - 1);
37205 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37206 dtp = phba->slow_ring_trc + i;
37207 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37208 !vport || !vport->disc_trc)
37209 return;
37210
37211 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37212 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37213 (lpfc_debugfs_max_disc_trc - 1);
37214 dtp = vport->disc_trc + index;
37215 dtp->fmt = fmt;
37216 dtp->data1 = data1;
37217 dtp->data2 = data2;
37218 dtp->data3 = data3;
37219 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37220 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37221 dtp->jif = jiffies;
37222 #endif
37223 return;
37224 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37225 !phba || !phba->slow_ring_trc)
37226 return;
37227
37228 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37229 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37230 (lpfc_debugfs_max_slow_ring_trc - 1);
37231 dtp = phba->slow_ring_trc + index;
37232 dtp->fmt = fmt;
37233 dtp->data1 = data1;
37234 dtp->data2 = data2;
37235 dtp->data3 = data3;
37236 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37237 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37238 dtp->jif = jiffies;
37239 #endif
37240 return;
37241 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37242 "slow_ring buffer\n");
37243 goto debug_failed;
37244 }
37245 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37246 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37247 memset(phba->slow_ring_trc, 0,
37248 (sizeof(struct lpfc_debugfs_trc) *
37249 lpfc_debugfs_max_slow_ring_trc));
37250 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37251 "buffer\n");
37252 goto debug_failed;
37253 }
37254 - atomic_set(&vport->disc_trc_cnt, 0);
37255 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37256
37257 snprintf(name, sizeof(name), "discovery_trace");
37258 vport->debug_disc_trc =
37259 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37260 index 45c1520..35ba744 100644
37261 --- a/drivers/scsi/lpfc/lpfc_init.c
37262 +++ b/drivers/scsi/lpfc/lpfc_init.c
37263 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37264 "misc_register returned with status %d", error);
37265
37266 if (lpfc_enable_npiv) {
37267 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37268 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37269 + pax_open_kernel();
37270 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37271 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37272 + pax_close_kernel();
37273 }
37274 lpfc_transport_template =
37275 fc_attach_transport(&lpfc_transport_functions);
37276 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37277 index 925975d..0f1fc07 100644
37278 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37279 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37280 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37281 uint32_t evt_posted;
37282
37283 spin_lock_irqsave(&phba->hbalock, flags);
37284 - atomic_inc(&phba->num_rsrc_err);
37285 + atomic_inc_unchecked(&phba->num_rsrc_err);
37286 phba->last_rsrc_error_time = jiffies;
37287
37288 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37289 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37290 unsigned long flags;
37291 struct lpfc_hba *phba = vport->phba;
37292 uint32_t evt_posted;
37293 - atomic_inc(&phba->num_cmd_success);
37294 + atomic_inc_unchecked(&phba->num_cmd_success);
37295
37296 if (vport->cfg_lun_queue_depth <= queue_depth)
37297 return;
37298 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37299 unsigned long num_rsrc_err, num_cmd_success;
37300 int i;
37301
37302 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37303 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37304 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37305 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37306
37307 /*
37308 * The error and success command counters are global per
37309 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37310 }
37311 }
37312 lpfc_destroy_vport_work_array(phba, vports);
37313 - atomic_set(&phba->num_rsrc_err, 0);
37314 - atomic_set(&phba->num_cmd_success, 0);
37315 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37316 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37317 }
37318
37319 /**
37320 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37321 }
37322 }
37323 lpfc_destroy_vport_work_array(phba, vports);
37324 - atomic_set(&phba->num_rsrc_err, 0);
37325 - atomic_set(&phba->num_cmd_success, 0);
37326 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37327 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37328 }
37329
37330 /**
37331 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37332 index ea8a0b4..812a124 100644
37333 --- a/drivers/scsi/pmcraid.c
37334 +++ b/drivers/scsi/pmcraid.c
37335 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37336 res->scsi_dev = scsi_dev;
37337 scsi_dev->hostdata = res;
37338 res->change_detected = 0;
37339 - atomic_set(&res->read_failures, 0);
37340 - atomic_set(&res->write_failures, 0);
37341 + atomic_set_unchecked(&res->read_failures, 0);
37342 + atomic_set_unchecked(&res->write_failures, 0);
37343 rc = 0;
37344 }
37345 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37346 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37347
37348 /* If this was a SCSI read/write command keep count of errors */
37349 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37350 - atomic_inc(&res->read_failures);
37351 + atomic_inc_unchecked(&res->read_failures);
37352 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37353 - atomic_inc(&res->write_failures);
37354 + atomic_inc_unchecked(&res->write_failures);
37355
37356 if (!RES_IS_GSCSI(res->cfg_entry) &&
37357 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37358 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37359 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37360 * hrrq_id assigned here in queuecommand
37361 */
37362 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37363 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37364 pinstance->num_hrrq;
37365 cmd->cmd_done = pmcraid_io_done;
37366
37367 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37368 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37369 * hrrq_id assigned here in queuecommand
37370 */
37371 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37372 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37373 pinstance->num_hrrq;
37374
37375 if (request_size) {
37376 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37377
37378 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37379 /* add resources only after host is added into system */
37380 - if (!atomic_read(&pinstance->expose_resources))
37381 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37382 return;
37383
37384 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37385 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37386 init_waitqueue_head(&pinstance->reset_wait_q);
37387
37388 atomic_set(&pinstance->outstanding_cmds, 0);
37389 - atomic_set(&pinstance->last_message_id, 0);
37390 - atomic_set(&pinstance->expose_resources, 0);
37391 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37392 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37393
37394 INIT_LIST_HEAD(&pinstance->free_res_q);
37395 INIT_LIST_HEAD(&pinstance->used_res_q);
37396 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37397 /* Schedule worker thread to handle CCN and take care of adding and
37398 * removing devices to OS
37399 */
37400 - atomic_set(&pinstance->expose_resources, 1);
37401 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37402 schedule_work(&pinstance->worker_q);
37403 return rc;
37404
37405 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37406 index e1d150f..6c6df44 100644
37407 --- a/drivers/scsi/pmcraid.h
37408 +++ b/drivers/scsi/pmcraid.h
37409 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37410 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37411
37412 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37413 - atomic_t last_message_id;
37414 + atomic_unchecked_t last_message_id;
37415
37416 /* configuration table */
37417 struct pmcraid_config_table *cfg_table;
37418 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37419 atomic_t outstanding_cmds;
37420
37421 /* should add/delete resources to mid-layer now ?*/
37422 - atomic_t expose_resources;
37423 + atomic_unchecked_t expose_resources;
37424
37425
37426
37427 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37428 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37429 };
37430 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37431 - atomic_t read_failures; /* count of failed READ commands */
37432 - atomic_t write_failures; /* count of failed WRITE commands */
37433 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37434 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37435
37436 /* To indicate add/delete/modify during CCN */
37437 u8 change_detected;
37438 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37439 index 5ab9530..2dd80f7 100644
37440 --- a/drivers/scsi/qla2xxx/qla_attr.c
37441 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37442 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37443 return 0;
37444 }
37445
37446 -struct fc_function_template qla2xxx_transport_functions = {
37447 +fc_function_template_no_const qla2xxx_transport_functions = {
37448
37449 .show_host_node_name = 1,
37450 .show_host_port_name = 1,
37451 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37452 .bsg_timeout = qla24xx_bsg_timeout,
37453 };
37454
37455 -struct fc_function_template qla2xxx_transport_vport_functions = {
37456 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37457
37458 .show_host_node_name = 1,
37459 .show_host_port_name = 1,
37460 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37461 index 39007f5..7fafc64 100644
37462 --- a/drivers/scsi/qla2xxx/qla_def.h
37463 +++ b/drivers/scsi/qla2xxx/qla_def.h
37464 @@ -2284,7 +2284,7 @@ struct isp_operations {
37465 int (*start_scsi) (srb_t *);
37466 int (*abort_isp) (struct scsi_qla_host *);
37467 int (*iospace_config)(struct qla_hw_data*);
37468 -};
37469 +} __no_const;
37470
37471 /* MSI-X Support *************************************************************/
37472
37473 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37474 index 9eacd2d..d79629c 100644
37475 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37476 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37477 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37478 struct device_attribute;
37479 extern struct device_attribute *qla2x00_host_attrs[];
37480 struct fc_function_template;
37481 -extern struct fc_function_template qla2xxx_transport_functions;
37482 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37483 +extern fc_function_template_no_const qla2xxx_transport_functions;
37484 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37485 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37486 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37487 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37488 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37489 index 7fdba7f..1b4b2c2 100644
37490 --- a/drivers/scsi/qla4xxx/ql4_def.h
37491 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37492 @@ -268,7 +268,7 @@ struct ddb_entry {
37493 * (4000 only) */
37494 atomic_t relogin_timer; /* Max Time to wait for
37495 * relogin to complete */
37496 - atomic_t relogin_retry_count; /* Num of times relogin has been
37497 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37498 * retried */
37499 uint32_t default_time2wait; /* Default Min time between
37500 * relogins (+aens) */
37501 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37502 index 9da4266..377b3b6 100644
37503 --- a/drivers/scsi/qla4xxx/ql4_os.c
37504 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37505 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37506 */
37507 if (!iscsi_is_session_online(cls_sess)) {
37508 /* Reset retry relogin timer */
37509 - atomic_inc(&ddb_entry->relogin_retry_count);
37510 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37511 DEBUG2(ql4_printk(KERN_INFO, ha,
37512 "%s: index[%d] relogin timed out-retrying"
37513 " relogin (%d), retry (%d)\n", __func__,
37514 ddb_entry->fw_ddb_index,
37515 - atomic_read(&ddb_entry->relogin_retry_count),
37516 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37517 ddb_entry->default_time2wait + 4));
37518 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37519 atomic_set(&ddb_entry->retry_relogin_timer,
37520 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37521
37522 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37523 atomic_set(&ddb_entry->relogin_timer, 0);
37524 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37525 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37526 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37527 ddb_entry->default_relogin_timeout =
37528 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37529 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37530 index 2936b44..546ecdb 100644
37531 --- a/drivers/scsi/scsi.c
37532 +++ b/drivers/scsi/scsi.c
37533 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37534 unsigned long timeout;
37535 int rtn = 0;
37536
37537 - atomic_inc(&cmd->device->iorequest_cnt);
37538 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37539
37540 /* check if the device is still usable */
37541 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37542 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37543 index faa790f..7e351ddd 100644
37544 --- a/drivers/scsi/scsi_lib.c
37545 +++ b/drivers/scsi/scsi_lib.c
37546 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37547 shost = sdev->host;
37548 scsi_init_cmd_errh(cmd);
37549 cmd->result = DID_NO_CONNECT << 16;
37550 - atomic_inc(&cmd->device->iorequest_cnt);
37551 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37552
37553 /*
37554 * SCSI request completion path will do scsi_device_unbusy(),
37555 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37556
37557 INIT_LIST_HEAD(&cmd->eh_entry);
37558
37559 - atomic_inc(&cmd->device->iodone_cnt);
37560 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37561 if (cmd->result)
37562 - atomic_inc(&cmd->device->ioerr_cnt);
37563 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37564
37565 disposition = scsi_decide_disposition(cmd);
37566 if (disposition != SUCCESS &&
37567 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37568 index ce5224c..8c6d071 100644
37569 --- a/drivers/scsi/scsi_sysfs.c
37570 +++ b/drivers/scsi/scsi_sysfs.c
37571 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37572 char *buf) \
37573 { \
37574 struct scsi_device *sdev = to_scsi_device(dev); \
37575 - unsigned long long count = atomic_read(&sdev->field); \
37576 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37577 return snprintf(buf, 20, "0x%llx\n", count); \
37578 } \
37579 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37580 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37581 index 84a1fdf..693b0d6 100644
37582 --- a/drivers/scsi/scsi_tgt_lib.c
37583 +++ b/drivers/scsi/scsi_tgt_lib.c
37584 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37585 int err;
37586
37587 dprintk("%lx %u\n", uaddr, len);
37588 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37589 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37590 if (err) {
37591 /*
37592 * TODO: need to fixup sg_tablesize, max_segment_size,
37593 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37594 index e894ca7..de9d7660 100644
37595 --- a/drivers/scsi/scsi_transport_fc.c
37596 +++ b/drivers/scsi/scsi_transport_fc.c
37597 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37598 * Netlink Infrastructure
37599 */
37600
37601 -static atomic_t fc_event_seq;
37602 +static atomic_unchecked_t fc_event_seq;
37603
37604 /**
37605 * fc_get_event_number - Obtain the next sequential FC event number
37606 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37607 u32
37608 fc_get_event_number(void)
37609 {
37610 - return atomic_add_return(1, &fc_event_seq);
37611 + return atomic_add_return_unchecked(1, &fc_event_seq);
37612 }
37613 EXPORT_SYMBOL(fc_get_event_number);
37614
37615 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37616 {
37617 int error;
37618
37619 - atomic_set(&fc_event_seq, 0);
37620 + atomic_set_unchecked(&fc_event_seq, 0);
37621
37622 error = transport_class_register(&fc_host_class);
37623 if (error)
37624 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37625 char *cp;
37626
37627 *val = simple_strtoul(buf, &cp, 0);
37628 - if ((*cp && (*cp != '\n')) || (*val < 0))
37629 + if (*cp && (*cp != '\n'))
37630 return -EINVAL;
37631 /*
37632 * Check for overflow; dev_loss_tmo is u32
37633 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37634 index fa1dfaa..4bb620c 100644
37635 --- a/drivers/scsi/scsi_transport_iscsi.c
37636 +++ b/drivers/scsi/scsi_transport_iscsi.c
37637 @@ -79,7 +79,7 @@ struct iscsi_internal {
37638 struct transport_container session_cont;
37639 };
37640
37641 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37642 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37643 static struct workqueue_struct *iscsi_eh_timer_workq;
37644
37645 static DEFINE_IDA(iscsi_sess_ida);
37646 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37647 int err;
37648
37649 ihost = shost->shost_data;
37650 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37651 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37652
37653 if (target_id == ISCSI_MAX_TARGET) {
37654 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37655 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37656 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37657 ISCSI_TRANSPORT_VERSION);
37658
37659 - atomic_set(&iscsi_session_nr, 0);
37660 + atomic_set_unchecked(&iscsi_session_nr, 0);
37661
37662 err = class_register(&iscsi_transport_class);
37663 if (err)
37664 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37665 index 21a045e..ec89e03 100644
37666 --- a/drivers/scsi/scsi_transport_srp.c
37667 +++ b/drivers/scsi/scsi_transport_srp.c
37668 @@ -33,7 +33,7 @@
37669 #include "scsi_transport_srp_internal.h"
37670
37671 struct srp_host_attrs {
37672 - atomic_t next_port_id;
37673 + atomic_unchecked_t next_port_id;
37674 };
37675 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37676
37677 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37678 struct Scsi_Host *shost = dev_to_shost(dev);
37679 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37680
37681 - atomic_set(&srp_host->next_port_id, 0);
37682 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37683 return 0;
37684 }
37685
37686 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37687 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37688 rport->roles = ids->roles;
37689
37690 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37691 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37692 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37693
37694 transport_setup_device(&rport->dev);
37695 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37696 index 4df73e5..b691c58 100644
37697 --- a/drivers/scsi/sd.c
37698 +++ b/drivers/scsi/sd.c
37699 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37700 sdkp->disk = gd;
37701 sdkp->index = index;
37702 atomic_set(&sdkp->openers, 0);
37703 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37704 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37705
37706 if (!sdp->request_queue->rq_timeout) {
37707 if (sdp->type != TYPE_MOD)
37708 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37709 index 9c5c5f2..8414557 100644
37710 --- a/drivers/scsi/sg.c
37711 +++ b/drivers/scsi/sg.c
37712 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37713 sdp->disk->disk_name,
37714 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37715 NULL,
37716 - (char *)arg);
37717 + (char __user *)arg);
37718 case BLKTRACESTART:
37719 return blk_trace_startstop(sdp->device->request_queue, 1);
37720 case BLKTRACESTOP:
37721 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37722 index 84c2861..ece0a31 100644
37723 --- a/drivers/spi/spi.c
37724 +++ b/drivers/spi/spi.c
37725 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37726 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37727
37728 /* portable code must never pass more than 32 bytes */
37729 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37730 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37731
37732 static u8 *buf;
37733
37734 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37735 index 34afc16..ffe44dd 100644
37736 --- a/drivers/staging/octeon/ethernet-rx.c
37737 +++ b/drivers/staging/octeon/ethernet-rx.c
37738 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37739 /* Increment RX stats for virtual ports */
37740 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37741 #ifdef CONFIG_64BIT
37742 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37743 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37744 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37745 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37746 #else
37747 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37748 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37749 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37750 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37751 #endif
37752 }
37753 netif_receive_skb(skb);
37754 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37755 dev->name);
37756 */
37757 #ifdef CONFIG_64BIT
37758 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37759 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37760 #else
37761 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37762 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37763 #endif
37764 dev_kfree_skb_irq(skb);
37765 }
37766 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37767 index 683bedc..86dba9a 100644
37768 --- a/drivers/staging/octeon/ethernet.c
37769 +++ b/drivers/staging/octeon/ethernet.c
37770 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37771 * since the RX tasklet also increments it.
37772 */
37773 #ifdef CONFIG_64BIT
37774 - atomic64_add(rx_status.dropped_packets,
37775 - (atomic64_t *)&priv->stats.rx_dropped);
37776 + atomic64_add_unchecked(rx_status.dropped_packets,
37777 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37778 #else
37779 - atomic_add(rx_status.dropped_packets,
37780 - (atomic_t *)&priv->stats.rx_dropped);
37781 + atomic_add_unchecked(rx_status.dropped_packets,
37782 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37783 #endif
37784 }
37785
37786 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37787 index 4beab94..44149ee 100644
37788 --- a/drivers/staging/omapdrm/omap_drv.c
37789 +++ b/drivers/staging/omapdrm/omap_drv.c
37790 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37791 .irq_postinstall = dev_irq_postinstall,
37792 .irq_uninstall = dev_irq_uninstall,
37793 .irq_handler = dev_irq_handler,
37794 - .reclaim_buffers = drm_core_reclaim_buffers,
37795 #ifdef CONFIG_DEBUG_FS
37796 .debugfs_init = omap_debugfs_init,
37797 .debugfs_cleanup = omap_debugfs_cleanup,
37798 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37799 index dc23395..cf7e9b1 100644
37800 --- a/drivers/staging/rtl8712/rtl871x_io.h
37801 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37802 @@ -108,7 +108,7 @@ struct _io_ops {
37803 u8 *pmem);
37804 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37805 u8 *pmem);
37806 -};
37807 +} __no_const;
37808
37809 struct io_req {
37810 struct list_head list;
37811 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37812 index c7b5e8b..783d6cb 100644
37813 --- a/drivers/staging/sbe-2t3e3/netdev.c
37814 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37815 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37816 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37817
37818 if (rlen)
37819 - if (copy_to_user(data, &resp, rlen))
37820 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37821 return -EFAULT;
37822
37823 return 0;
37824 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37825 index 5d89c0f..9261317 100644
37826 --- a/drivers/staging/usbip/usbip_common.h
37827 +++ b/drivers/staging/usbip/usbip_common.h
37828 @@ -289,7 +289,7 @@ struct usbip_device {
37829 void (*shutdown)(struct usbip_device *);
37830 void (*reset)(struct usbip_device *);
37831 void (*unusable)(struct usbip_device *);
37832 - } eh_ops;
37833 + } __no_const eh_ops;
37834 };
37835
37836 #define kthread_get_run(threadfn, data, namefmt, ...) \
37837 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37838 index c66b8b3..a4a035b 100644
37839 --- a/drivers/staging/usbip/vhci.h
37840 +++ b/drivers/staging/usbip/vhci.h
37841 @@ -83,7 +83,7 @@ struct vhci_hcd {
37842 unsigned resuming:1;
37843 unsigned long re_timeout;
37844
37845 - atomic_t seqnum;
37846 + atomic_unchecked_t seqnum;
37847
37848 /*
37849 * NOTE:
37850 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37851 index 12a9a5f..afd8295 100644
37852 --- a/drivers/staging/usbip/vhci_hcd.c
37853 +++ b/drivers/staging/usbip/vhci_hcd.c
37854 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37855 return;
37856 }
37857
37858 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37859 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37860 if (priv->seqnum == 0xffff)
37861 dev_info(&urb->dev->dev, "seqnum max\n");
37862
37863 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37864 return -ENOMEM;
37865 }
37866
37867 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37868 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37869 if (unlink->seqnum == 0xffff)
37870 pr_info("seqnum max\n");
37871
37872 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37873 vdev->rhport = rhport;
37874 }
37875
37876 - atomic_set(&vhci->seqnum, 0);
37877 + atomic_set_unchecked(&vhci->seqnum, 0);
37878 spin_lock_init(&vhci->lock);
37879
37880 hcd->power_budget = 0; /* no limit */
37881 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37882 index f0eaf04..5a82e06 100644
37883 --- a/drivers/staging/usbip/vhci_rx.c
37884 +++ b/drivers/staging/usbip/vhci_rx.c
37885 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37886 if (!urb) {
37887 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37888 pr_info("max seqnum %d\n",
37889 - atomic_read(&the_controller->seqnum));
37890 + atomic_read_unchecked(&the_controller->seqnum));
37891 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37892 return;
37893 }
37894 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37895 index 6ac6f45..1b208ba 100644
37896 --- a/drivers/staging/vt6655/hostap.c
37897 +++ b/drivers/staging/vt6655/hostap.c
37898 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37899 *
37900 */
37901
37902 +static net_device_ops_no_const apdev_netdev_ops;
37903 +
37904 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37905 {
37906 PSDevice apdev_priv;
37907 struct net_device *dev = pDevice->dev;
37908 int ret;
37909 - const struct net_device_ops apdev_netdev_ops = {
37910 - .ndo_start_xmit = pDevice->tx_80211,
37911 - };
37912
37913 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37914
37915 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37916 *apdev_priv = *pDevice;
37917 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37918
37919 + /* only half broken now */
37920 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37921 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37922
37923 pDevice->apdev->type = ARPHRD_IEEE80211;
37924 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37925 index 682002a..35ed5cf 100644
37926 --- a/drivers/staging/vt6656/hostap.c
37927 +++ b/drivers/staging/vt6656/hostap.c
37928 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37929 *
37930 */
37931
37932 +static net_device_ops_no_const apdev_netdev_ops;
37933 +
37934 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37935 {
37936 PSDevice apdev_priv;
37937 struct net_device *dev = pDevice->dev;
37938 int ret;
37939 - const struct net_device_ops apdev_netdev_ops = {
37940 - .ndo_start_xmit = pDevice->tx_80211,
37941 - };
37942
37943 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37944
37945 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37946 *apdev_priv = *pDevice;
37947 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37948
37949 + /* only half broken now */
37950 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37951 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37952
37953 pDevice->apdev->type = ARPHRD_IEEE80211;
37954 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37955 index 7843dfd..3db105f 100644
37956 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37957 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37958 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37959
37960 struct usbctlx_completor {
37961 int (*complete) (struct usbctlx_completor *);
37962 -};
37963 +} __no_const;
37964
37965 static int
37966 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37967 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37968 index eaa9021..43f023b 100644
37969 --- a/drivers/staging/zcache/tmem.c
37970 +++ b/drivers/staging/zcache/tmem.c
37971 @@ -39,7 +39,7 @@
37972 * A tmem host implementation must use this function to register callbacks
37973 * for memory allocation.
37974 */
37975 -static struct tmem_hostops tmem_hostops;
37976 +static tmem_hostops_no_const tmem_hostops;
37977
37978 static void tmem_objnode_tree_init(void);
37979
37980 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37981 * A tmem host implementation must use this function to register
37982 * callbacks for a page-accessible memory (PAM) implementation
37983 */
37984 -static struct tmem_pamops tmem_pamops;
37985 +static tmem_pamops_no_const tmem_pamops;
37986
37987 void tmem_register_pamops(struct tmem_pamops *m)
37988 {
37989 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37990 index 0d4aa82..f7832d4 100644
37991 --- a/drivers/staging/zcache/tmem.h
37992 +++ b/drivers/staging/zcache/tmem.h
37993 @@ -180,6 +180,7 @@ struct tmem_pamops {
37994 void (*new_obj)(struct tmem_obj *);
37995 int (*replace_in_obj)(void *, struct tmem_obj *);
37996 };
37997 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37998 extern void tmem_register_pamops(struct tmem_pamops *m);
37999
38000 /* memory allocation methods provided by the host implementation */
38001 @@ -189,6 +190,7 @@ struct tmem_hostops {
38002 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38003 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38004 };
38005 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38006 extern void tmem_register_hostops(struct tmem_hostops *m);
38007
38008 /* core tmem accessor functions */
38009 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38010 index 7502660..f214d9f 100644
38011 --- a/drivers/target/target_core_transport.c
38012 +++ b/drivers/target/target_core_transport.c
38013 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38014 spin_lock_init(&dev->se_port_lock);
38015 spin_lock_init(&dev->se_tmr_lock);
38016 spin_lock_init(&dev->qf_cmd_lock);
38017 - atomic_set(&dev->dev_ordered_id, 0);
38018 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38019
38020 se_dev_set_default_attribs(dev, dev_limits);
38021
38022 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38023 * Used to determine when ORDERED commands should go from
38024 * Dormant to Active status.
38025 */
38026 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38027 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38028 smp_mb__after_atomic_inc();
38029 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38030 cmd->se_ordered_id, cmd->sam_task_attr,
38031 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38032 index e61cabd..7617d26 100644
38033 --- a/drivers/tty/cyclades.c
38034 +++ b/drivers/tty/cyclades.c
38035 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38036 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38037 info->port.count);
38038 #endif
38039 - info->port.count++;
38040 + atomic_inc(&info->port.count);
38041 #ifdef CY_DEBUG_COUNT
38042 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38043 - current->pid, info->port.count);
38044 + current->pid, atomic_read(&info->port.count));
38045 #endif
38046
38047 /*
38048 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38049 for (j = 0; j < cy_card[i].nports; j++) {
38050 info = &cy_card[i].ports[j];
38051
38052 - if (info->port.count) {
38053 + if (atomic_read(&info->port.count)) {
38054 /* XXX is the ldisc num worth this? */
38055 struct tty_struct *tty;
38056 struct tty_ldisc *ld;
38057 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38058 index 2d691eb..be02ebd 100644
38059 --- a/drivers/tty/hvc/hvc_console.c
38060 +++ b/drivers/tty/hvc/hvc_console.c
38061 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38062
38063 spin_lock_irqsave(&hp->port.lock, flags);
38064 /* Check and then increment for fast path open. */
38065 - if (hp->port.count++ > 0) {
38066 + if (atomic_inc_return(&hp->port.count) > 1) {
38067 spin_unlock_irqrestore(&hp->port.lock, flags);
38068 hvc_kick();
38069 return 0;
38070 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38071
38072 spin_lock_irqsave(&hp->port.lock, flags);
38073
38074 - if (--hp->port.count == 0) {
38075 + if (atomic_dec_return(&hp->port.count) == 0) {
38076 spin_unlock_irqrestore(&hp->port.lock, flags);
38077 /* We are done with the tty pointer now. */
38078 tty_port_tty_set(&hp->port, NULL);
38079 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38080 */
38081 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38082 } else {
38083 - if (hp->port.count < 0)
38084 + if (atomic_read(&hp->port.count) < 0)
38085 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38086 - hp->vtermno, hp->port.count);
38087 + hp->vtermno, atomic_read(&hp->port.count));
38088 spin_unlock_irqrestore(&hp->port.lock, flags);
38089 }
38090
38091 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38092 * open->hangup case this can be called after the final close so prevent
38093 * that from happening for now.
38094 */
38095 - if (hp->port.count <= 0) {
38096 + if (atomic_read(&hp->port.count) <= 0) {
38097 spin_unlock_irqrestore(&hp->port.lock, flags);
38098 return;
38099 }
38100
38101 - temp_open_count = hp->port.count;
38102 - hp->port.count = 0;
38103 + temp_open_count = atomic_read(&hp->port.count);
38104 + atomic_set(&hp->port.count, 0);
38105 spin_unlock_irqrestore(&hp->port.lock, flags);
38106 tty_port_tty_set(&hp->port, NULL);
38107
38108 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38109 return -EPIPE;
38110
38111 /* FIXME what's this (unprotected) check for? */
38112 - if (hp->port.count <= 0)
38113 + if (atomic_read(&hp->port.count) <= 0)
38114 return -EIO;
38115
38116 spin_lock_irqsave(&hp->lock, flags);
38117 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38118 index d56788c..12d8f85 100644
38119 --- a/drivers/tty/hvc/hvcs.c
38120 +++ b/drivers/tty/hvc/hvcs.c
38121 @@ -83,6 +83,7 @@
38122 #include <asm/hvcserver.h>
38123 #include <asm/uaccess.h>
38124 #include <asm/vio.h>
38125 +#include <asm/local.h>
38126
38127 /*
38128 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38129 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38130
38131 spin_lock_irqsave(&hvcsd->lock, flags);
38132
38133 - if (hvcsd->port.count > 0) {
38134 + if (atomic_read(&hvcsd->port.count) > 0) {
38135 spin_unlock_irqrestore(&hvcsd->lock, flags);
38136 printk(KERN_INFO "HVCS: vterm state unchanged. "
38137 "The hvcs device node is still in use.\n");
38138 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38139 if ((retval = hvcs_partner_connect(hvcsd)))
38140 goto error_release;
38141
38142 - hvcsd->port.count = 1;
38143 + atomic_set(&hvcsd->port.count, 1);
38144 hvcsd->port.tty = tty;
38145 tty->driver_data = hvcsd;
38146
38147 @@ -1168,7 +1169,7 @@ fast_open:
38148
38149 spin_lock_irqsave(&hvcsd->lock, flags);
38150 tty_port_get(&hvcsd->port);
38151 - hvcsd->port.count++;
38152 + atomic_inc(&hvcsd->port.count);
38153 hvcsd->todo_mask |= HVCS_SCHED_READ;
38154 spin_unlock_irqrestore(&hvcsd->lock, flags);
38155
38156 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38157 hvcsd = tty->driver_data;
38158
38159 spin_lock_irqsave(&hvcsd->lock, flags);
38160 - if (--hvcsd->port.count == 0) {
38161 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38162
38163 vio_disable_interrupts(hvcsd->vdev);
38164
38165 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38166 free_irq(irq, hvcsd);
38167 tty_port_put(&hvcsd->port);
38168 return;
38169 - } else if (hvcsd->port.count < 0) {
38170 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38171 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38172 " is missmanaged.\n",
38173 - hvcsd->vdev->unit_address, hvcsd->port.count);
38174 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38175 }
38176
38177 spin_unlock_irqrestore(&hvcsd->lock, flags);
38178 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38179
38180 spin_lock_irqsave(&hvcsd->lock, flags);
38181 /* Preserve this so that we know how many kref refs to put */
38182 - temp_open_count = hvcsd->port.count;
38183 + temp_open_count = atomic_read(&hvcsd->port.count);
38184
38185 /*
38186 * Don't kref put inside the spinlock because the destruction
38187 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38188 tty->driver_data = NULL;
38189 hvcsd->port.tty = NULL;
38190
38191 - hvcsd->port.count = 0;
38192 + atomic_set(&hvcsd->port.count, 0);
38193
38194 /* This will drop any buffered data on the floor which is OK in a hangup
38195 * scenario. */
38196 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38197 * the middle of a write operation? This is a crummy place to do this
38198 * but we want to keep it all in the spinlock.
38199 */
38200 - if (hvcsd->port.count <= 0) {
38201 + if (atomic_read(&hvcsd->port.count) <= 0) {
38202 spin_unlock_irqrestore(&hvcsd->lock, flags);
38203 return -ENODEV;
38204 }
38205 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38206 {
38207 struct hvcs_struct *hvcsd = tty->driver_data;
38208
38209 - if (!hvcsd || hvcsd->port.count <= 0)
38210 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38211 return 0;
38212
38213 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38214 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38215 index f8b5fa0..4ba9f89 100644
38216 --- a/drivers/tty/ipwireless/tty.c
38217 +++ b/drivers/tty/ipwireless/tty.c
38218 @@ -29,6 +29,7 @@
38219 #include <linux/tty_driver.h>
38220 #include <linux/tty_flip.h>
38221 #include <linux/uaccess.h>
38222 +#include <asm/local.h>
38223
38224 #include "tty.h"
38225 #include "network.h"
38226 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38227 mutex_unlock(&tty->ipw_tty_mutex);
38228 return -ENODEV;
38229 }
38230 - if (tty->port.count == 0)
38231 + if (atomic_read(&tty->port.count) == 0)
38232 tty->tx_bytes_queued = 0;
38233
38234 - tty->port.count++;
38235 + atomic_inc(&tty->port.count);
38236
38237 tty->port.tty = linux_tty;
38238 linux_tty->driver_data = tty;
38239 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38240
38241 static void do_ipw_close(struct ipw_tty *tty)
38242 {
38243 - tty->port.count--;
38244 -
38245 - if (tty->port.count == 0) {
38246 + if (atomic_dec_return(&tty->port.count) == 0) {
38247 struct tty_struct *linux_tty = tty->port.tty;
38248
38249 if (linux_tty != NULL) {
38250 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38251 return;
38252
38253 mutex_lock(&tty->ipw_tty_mutex);
38254 - if (tty->port.count == 0) {
38255 + if (atomic_read(&tty->port.count) == 0) {
38256 mutex_unlock(&tty->ipw_tty_mutex);
38257 return;
38258 }
38259 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38260 return;
38261 }
38262
38263 - if (!tty->port.count) {
38264 + if (!atomic_read(&tty->port.count)) {
38265 mutex_unlock(&tty->ipw_tty_mutex);
38266 return;
38267 }
38268 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38269 return -ENODEV;
38270
38271 mutex_lock(&tty->ipw_tty_mutex);
38272 - if (!tty->port.count) {
38273 + if (!atomic_read(&tty->port.count)) {
38274 mutex_unlock(&tty->ipw_tty_mutex);
38275 return -EINVAL;
38276 }
38277 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38278 if (!tty)
38279 return -ENODEV;
38280
38281 - if (!tty->port.count)
38282 + if (!atomic_read(&tty->port.count))
38283 return -EINVAL;
38284
38285 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38286 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38287 if (!tty)
38288 return 0;
38289
38290 - if (!tty->port.count)
38291 + if (!atomic_read(&tty->port.count))
38292 return 0;
38293
38294 return tty->tx_bytes_queued;
38295 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38296 if (!tty)
38297 return -ENODEV;
38298
38299 - if (!tty->port.count)
38300 + if (!atomic_read(&tty->port.count))
38301 return -EINVAL;
38302
38303 return get_control_lines(tty);
38304 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38305 if (!tty)
38306 return -ENODEV;
38307
38308 - if (!tty->port.count)
38309 + if (!atomic_read(&tty->port.count))
38310 return -EINVAL;
38311
38312 return set_control_lines(tty, set, clear);
38313 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38314 if (!tty)
38315 return -ENODEV;
38316
38317 - if (!tty->port.count)
38318 + if (!atomic_read(&tty->port.count))
38319 return -EINVAL;
38320
38321 /* FIXME: Exactly how is the tty object locked here .. */
38322 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38323 * are gone */
38324 mutex_lock(&ttyj->ipw_tty_mutex);
38325 }
38326 - while (ttyj->port.count)
38327 + while (atomic_read(&ttyj->port.count))
38328 do_ipw_close(ttyj);
38329 ipwireless_disassociate_network_ttys(network,
38330 ttyj->channel_idx);
38331 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38332 index 324467d..504cc25 100644
38333 --- a/drivers/tty/moxa.c
38334 +++ b/drivers/tty/moxa.c
38335 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38336 }
38337
38338 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38339 - ch->port.count++;
38340 + atomic_inc(&ch->port.count);
38341 tty->driver_data = ch;
38342 tty_port_tty_set(&ch->port, tty);
38343 mutex_lock(&ch->port.mutex);
38344 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38345 index 90dff82..08119c3 100644
38346 --- a/drivers/tty/n_gsm.c
38347 +++ b/drivers/tty/n_gsm.c
38348 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38349 kref_init(&dlci->ref);
38350 mutex_init(&dlci->mutex);
38351 dlci->fifo = &dlci->_fifo;
38352 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38353 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38354 kfree(dlci);
38355 return NULL;
38356 }
38357 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38358 if (dlci == NULL)
38359 return -ENOMEM;
38360 port = &dlci->port;
38361 - port->count++;
38362 + atomic_inc(&port->count);
38363 tty->driver_data = dlci;
38364 dlci_get(dlci);
38365 dlci_get(dlci->gsm->dlci[0]);
38366 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38367 index 26f0d0e..b7c4273 100644
38368 --- a/drivers/tty/n_tty.c
38369 +++ b/drivers/tty/n_tty.c
38370 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38371 {
38372 *ops = tty_ldisc_N_TTY;
38373 ops->owner = NULL;
38374 - ops->refcount = ops->flags = 0;
38375 + atomic_set(&ops->refcount, 0);
38376 + ops->flags = 0;
38377 }
38378 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38379 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38380 index 5505ffc..7affff9 100644
38381 --- a/drivers/tty/pty.c
38382 +++ b/drivers/tty/pty.c
38383 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38384 panic("Couldn't register Unix98 pts driver");
38385
38386 /* Now create the /dev/ptmx special device */
38387 + pax_open_kernel();
38388 tty_default_fops(&ptmx_fops);
38389 - ptmx_fops.open = ptmx_open;
38390 + *(void **)&ptmx_fops.open = ptmx_open;
38391 + pax_close_kernel();
38392
38393 cdev_init(&ptmx_cdev, &ptmx_fops);
38394 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38395 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38396 index 777d5f9..56d67ca 100644
38397 --- a/drivers/tty/rocket.c
38398 +++ b/drivers/tty/rocket.c
38399 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38400 tty->driver_data = info;
38401 tty_port_tty_set(port, tty);
38402
38403 - if (port->count++ == 0) {
38404 + if (atomic_inc_return(&port->count) == 1) {
38405 atomic_inc(&rp_num_ports_open);
38406
38407 #ifdef ROCKET_DEBUG_OPEN
38408 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38409 #endif
38410 }
38411 #ifdef ROCKET_DEBUG_OPEN
38412 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38413 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38414 #endif
38415
38416 /*
38417 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38418 spin_unlock_irqrestore(&info->port.lock, flags);
38419 return;
38420 }
38421 - if (info->port.count)
38422 + if (atomic_read(&info->port.count))
38423 atomic_dec(&rp_num_ports_open);
38424 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38425 spin_unlock_irqrestore(&info->port.lock, flags);
38426 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38427 index 2b42a01..32a2ed3 100644
38428 --- a/drivers/tty/serial/kgdboc.c
38429 +++ b/drivers/tty/serial/kgdboc.c
38430 @@ -24,8 +24,9 @@
38431 #define MAX_CONFIG_LEN 40
38432
38433 static struct kgdb_io kgdboc_io_ops;
38434 +static struct kgdb_io kgdboc_io_ops_console;
38435
38436 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38437 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38438 static int configured = -1;
38439
38440 static char config[MAX_CONFIG_LEN];
38441 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38442 kgdboc_unregister_kbd();
38443 if (configured == 1)
38444 kgdb_unregister_io_module(&kgdboc_io_ops);
38445 + else if (configured == 2)
38446 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38447 }
38448
38449 static int configure_kgdboc(void)
38450 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38451 int err;
38452 char *cptr = config;
38453 struct console *cons;
38454 + int is_console = 0;
38455
38456 err = kgdboc_option_setup(config);
38457 if (err || !strlen(config) || isspace(config[0]))
38458 goto noconfig;
38459
38460 err = -ENODEV;
38461 - kgdboc_io_ops.is_console = 0;
38462 kgdb_tty_driver = NULL;
38463
38464 kgdboc_use_kms = 0;
38465 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38466 int idx;
38467 if (cons->device && cons->device(cons, &idx) == p &&
38468 idx == tty_line) {
38469 - kgdboc_io_ops.is_console = 1;
38470 + is_console = 1;
38471 break;
38472 }
38473 cons = cons->next;
38474 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38475 kgdb_tty_line = tty_line;
38476
38477 do_register:
38478 - err = kgdb_register_io_module(&kgdboc_io_ops);
38479 + if (is_console) {
38480 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38481 + configured = 2;
38482 + } else {
38483 + err = kgdb_register_io_module(&kgdboc_io_ops);
38484 + configured = 1;
38485 + }
38486 if (err)
38487 goto noconfig;
38488
38489 - configured = 1;
38490 -
38491 return 0;
38492
38493 noconfig:
38494 @@ -213,7 +220,7 @@ noconfig:
38495 static int __init init_kgdboc(void)
38496 {
38497 /* Already configured? */
38498 - if (configured == 1)
38499 + if (configured >= 1)
38500 return 0;
38501
38502 return configure_kgdboc();
38503 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38504 if (config[len - 1] == '\n')
38505 config[len - 1] = '\0';
38506
38507 - if (configured == 1)
38508 + if (configured >= 1)
38509 cleanup_kgdboc();
38510
38511 /* Go and configure with the new params. */
38512 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38513 .post_exception = kgdboc_post_exp_handler,
38514 };
38515
38516 +static struct kgdb_io kgdboc_io_ops_console = {
38517 + .name = "kgdboc",
38518 + .read_char = kgdboc_get_char,
38519 + .write_char = kgdboc_put_char,
38520 + .pre_exception = kgdboc_pre_exp_handler,
38521 + .post_exception = kgdboc_post_exp_handler,
38522 + .is_console = 1
38523 +};
38524 +
38525 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38526 /* This is only available if kgdboc is a built in for early debugging */
38527 static int __init kgdboc_early_init(char *opt)
38528 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38529 index a21dc8e..fe43e9e 100644
38530 --- a/drivers/tty/serial/serial_core.c
38531 +++ b/drivers/tty/serial/serial_core.c
38532 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38533 uart_flush_buffer(tty);
38534 uart_shutdown(tty, state);
38535 spin_lock_irqsave(&port->lock, flags);
38536 - port->count = 0;
38537 + atomic_set(&port->count, 0);
38538 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38539 spin_unlock_irqrestore(&port->lock, flags);
38540 tty_port_tty_set(port, NULL);
38541 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38542 goto end;
38543 }
38544
38545 - port->count++;
38546 + atomic_inc(&port->count);
38547 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38548 retval = -ENXIO;
38549 goto err_dec_count;
38550 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38551 /*
38552 * Make sure the device is in D0 state.
38553 */
38554 - if (port->count == 1)
38555 + if (atomic_read(&port->count) == 1)
38556 uart_change_pm(state, 0);
38557
38558 /*
38559 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38560 end:
38561 return retval;
38562 err_dec_count:
38563 - port->count--;
38564 + atomic_inc(&port->count);
38565 mutex_unlock(&port->mutex);
38566 goto end;
38567 }
38568 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38569 index 593d40a..bdc61f3 100644
38570 --- a/drivers/tty/synclink.c
38571 +++ b/drivers/tty/synclink.c
38572 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38573
38574 if (debug_level >= DEBUG_LEVEL_INFO)
38575 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38576 - __FILE__,__LINE__, info->device_name, info->port.count);
38577 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38578
38579 if (tty_port_close_start(&info->port, tty, filp) == 0)
38580 goto cleanup;
38581 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38582 cleanup:
38583 if (debug_level >= DEBUG_LEVEL_INFO)
38584 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38585 - tty->driver->name, info->port.count);
38586 + tty->driver->name, atomic_read(&info->port.count));
38587
38588 } /* end of mgsl_close() */
38589
38590 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38591
38592 mgsl_flush_buffer(tty);
38593 shutdown(info);
38594 -
38595 - info->port.count = 0;
38596 +
38597 + atomic_set(&info->port.count, 0);
38598 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38599 info->port.tty = NULL;
38600
38601 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38602
38603 if (debug_level >= DEBUG_LEVEL_INFO)
38604 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38605 - __FILE__,__LINE__, tty->driver->name, port->count );
38606 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38607
38608 spin_lock_irqsave(&info->irq_spinlock, flags);
38609 if (!tty_hung_up_p(filp)) {
38610 extra_count = true;
38611 - port->count--;
38612 + atomic_dec(&port->count);
38613 }
38614 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38615 port->blocked_open++;
38616 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38617
38618 if (debug_level >= DEBUG_LEVEL_INFO)
38619 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38620 - __FILE__,__LINE__, tty->driver->name, port->count );
38621 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38622
38623 tty_unlock();
38624 schedule();
38625 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38626
38627 /* FIXME: Racy on hangup during close wait */
38628 if (extra_count)
38629 - port->count++;
38630 + atomic_inc(&port->count);
38631 port->blocked_open--;
38632
38633 if (debug_level >= DEBUG_LEVEL_INFO)
38634 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38635 - __FILE__,__LINE__, tty->driver->name, port->count );
38636 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38637
38638 if (!retval)
38639 port->flags |= ASYNC_NORMAL_ACTIVE;
38640 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38641
38642 if (debug_level >= DEBUG_LEVEL_INFO)
38643 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38644 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38645 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38646
38647 /* If port is closing, signal caller to try again */
38648 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38649 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38650 spin_unlock_irqrestore(&info->netlock, flags);
38651 goto cleanup;
38652 }
38653 - info->port.count++;
38654 + atomic_inc(&info->port.count);
38655 spin_unlock_irqrestore(&info->netlock, flags);
38656
38657 - if (info->port.count == 1) {
38658 + if (atomic_read(&info->port.count) == 1) {
38659 /* 1st open on this device, init hardware */
38660 retval = startup(info);
38661 if (retval < 0)
38662 @@ -3444,8 +3444,8 @@ cleanup:
38663 if (retval) {
38664 if (tty->count == 1)
38665 info->port.tty = NULL; /* tty layer will release tty struct */
38666 - if(info->port.count)
38667 - info->port.count--;
38668 + if (atomic_read(&info->port.count))
38669 + atomic_dec(&info->port.count);
38670 }
38671
38672 return retval;
38673 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38674 unsigned short new_crctype;
38675
38676 /* return error if TTY interface open */
38677 - if (info->port.count)
38678 + if (atomic_read(&info->port.count))
38679 return -EBUSY;
38680
38681 switch (encoding)
38682 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38683
38684 /* arbitrate between network and tty opens */
38685 spin_lock_irqsave(&info->netlock, flags);
38686 - if (info->port.count != 0 || info->netcount != 0) {
38687 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38688 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38689 spin_unlock_irqrestore(&info->netlock, flags);
38690 return -EBUSY;
38691 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38692 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38693
38694 /* return error if TTY interface open */
38695 - if (info->port.count)
38696 + if (atomic_read(&info->port.count))
38697 return -EBUSY;
38698
38699 if (cmd != SIOCWANDEV)
38700 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38701 index aa1debf..9297a16 100644
38702 --- a/drivers/tty/synclink_gt.c
38703 +++ b/drivers/tty/synclink_gt.c
38704 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38705 tty->driver_data = info;
38706 info->port.tty = tty;
38707
38708 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38709 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38710
38711 /* If port is closing, signal caller to try again */
38712 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38713 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38714 mutex_unlock(&info->port.mutex);
38715 goto cleanup;
38716 }
38717 - info->port.count++;
38718 + atomic_inc(&info->port.count);
38719 spin_unlock_irqrestore(&info->netlock, flags);
38720
38721 - if (info->port.count == 1) {
38722 + if (atomic_read(&info->port.count) == 1) {
38723 /* 1st open on this device, init hardware */
38724 retval = startup(info);
38725 if (retval < 0) {
38726 @@ -716,8 +716,8 @@ cleanup:
38727 if (retval) {
38728 if (tty->count == 1)
38729 info->port.tty = NULL; /* tty layer will release tty struct */
38730 - if(info->port.count)
38731 - info->port.count--;
38732 + if(atomic_read(&info->port.count))
38733 + atomic_dec(&info->port.count);
38734 }
38735
38736 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38737 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38738
38739 if (sanity_check(info, tty->name, "close"))
38740 return;
38741 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38742 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38743
38744 if (tty_port_close_start(&info->port, tty, filp) == 0)
38745 goto cleanup;
38746 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38747 tty_port_close_end(&info->port, tty);
38748 info->port.tty = NULL;
38749 cleanup:
38750 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38751 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38752 }
38753
38754 static void hangup(struct tty_struct *tty)
38755 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38756 shutdown(info);
38757
38758 spin_lock_irqsave(&info->port.lock, flags);
38759 - info->port.count = 0;
38760 + atomic_set(&info->port.count, 0);
38761 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38762 info->port.tty = NULL;
38763 spin_unlock_irqrestore(&info->port.lock, flags);
38764 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38765 unsigned short new_crctype;
38766
38767 /* return error if TTY interface open */
38768 - if (info->port.count)
38769 + if (atomic_read(&info->port.count))
38770 return -EBUSY;
38771
38772 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38773 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38774
38775 /* arbitrate between network and tty opens */
38776 spin_lock_irqsave(&info->netlock, flags);
38777 - if (info->port.count != 0 || info->netcount != 0) {
38778 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38779 DBGINFO(("%s hdlc_open busy\n", dev->name));
38780 spin_unlock_irqrestore(&info->netlock, flags);
38781 return -EBUSY;
38782 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38783 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38784
38785 /* return error if TTY interface open */
38786 - if (info->port.count)
38787 + if (atomic_read(&info->port.count))
38788 return -EBUSY;
38789
38790 if (cmd != SIOCWANDEV)
38791 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38792 if (port == NULL)
38793 continue;
38794 spin_lock(&port->lock);
38795 - if ((port->port.count || port->netcount) &&
38796 + if ((atomic_read(&port->port.count) || port->netcount) &&
38797 port->pending_bh && !port->bh_running &&
38798 !port->bh_requested) {
38799 DBGISR(("%s bh queued\n", port->device_name));
38800 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38801 spin_lock_irqsave(&info->lock, flags);
38802 if (!tty_hung_up_p(filp)) {
38803 extra_count = true;
38804 - port->count--;
38805 + atomic_dec(&port->count);
38806 }
38807 spin_unlock_irqrestore(&info->lock, flags);
38808 port->blocked_open++;
38809 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38810 remove_wait_queue(&port->open_wait, &wait);
38811
38812 if (extra_count)
38813 - port->count++;
38814 + atomic_inc(&port->count);
38815 port->blocked_open--;
38816
38817 if (!retval)
38818 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38819 index a3dddc1..8905ab2 100644
38820 --- a/drivers/tty/synclinkmp.c
38821 +++ b/drivers/tty/synclinkmp.c
38822 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38823
38824 if (debug_level >= DEBUG_LEVEL_INFO)
38825 printk("%s(%d):%s open(), old ref count = %d\n",
38826 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38827 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38828
38829 /* If port is closing, signal caller to try again */
38830 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38831 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38832 spin_unlock_irqrestore(&info->netlock, flags);
38833 goto cleanup;
38834 }
38835 - info->port.count++;
38836 + atomic_inc(&info->port.count);
38837 spin_unlock_irqrestore(&info->netlock, flags);
38838
38839 - if (info->port.count == 1) {
38840 + if (atomic_read(&info->port.count) == 1) {
38841 /* 1st open on this device, init hardware */
38842 retval = startup(info);
38843 if (retval < 0)
38844 @@ -788,8 +788,8 @@ cleanup:
38845 if (retval) {
38846 if (tty->count == 1)
38847 info->port.tty = NULL; /* tty layer will release tty struct */
38848 - if(info->port.count)
38849 - info->port.count--;
38850 + if(atomic_read(&info->port.count))
38851 + atomic_dec(&info->port.count);
38852 }
38853
38854 return retval;
38855 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38856
38857 if (debug_level >= DEBUG_LEVEL_INFO)
38858 printk("%s(%d):%s close() entry, count=%d\n",
38859 - __FILE__,__LINE__, info->device_name, info->port.count);
38860 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38861
38862 if (tty_port_close_start(&info->port, tty, filp) == 0)
38863 goto cleanup;
38864 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38865 cleanup:
38866 if (debug_level >= DEBUG_LEVEL_INFO)
38867 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38868 - tty->driver->name, info->port.count);
38869 + tty->driver->name, atomic_read(&info->port.count));
38870 }
38871
38872 /* Called by tty_hangup() when a hangup is signaled.
38873 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38874 shutdown(info);
38875
38876 spin_lock_irqsave(&info->port.lock, flags);
38877 - info->port.count = 0;
38878 + atomic_set(&info->port.count, 0);
38879 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38880 info->port.tty = NULL;
38881 spin_unlock_irqrestore(&info->port.lock, flags);
38882 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38883 unsigned short new_crctype;
38884
38885 /* return error if TTY interface open */
38886 - if (info->port.count)
38887 + if (atomic_read(&info->port.count))
38888 return -EBUSY;
38889
38890 switch (encoding)
38891 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38892
38893 /* arbitrate between network and tty opens */
38894 spin_lock_irqsave(&info->netlock, flags);
38895 - if (info->port.count != 0 || info->netcount != 0) {
38896 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38897 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38898 spin_unlock_irqrestore(&info->netlock, flags);
38899 return -EBUSY;
38900 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38901 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38902
38903 /* return error if TTY interface open */
38904 - if (info->port.count)
38905 + if (atomic_read(&info->port.count))
38906 return -EBUSY;
38907
38908 if (cmd != SIOCWANDEV)
38909 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38910 * do not request bottom half processing if the
38911 * device is not open in a normal mode.
38912 */
38913 - if ( port && (port->port.count || port->netcount) &&
38914 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38915 port->pending_bh && !port->bh_running &&
38916 !port->bh_requested ) {
38917 if ( debug_level >= DEBUG_LEVEL_ISR )
38918 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38919
38920 if (debug_level >= DEBUG_LEVEL_INFO)
38921 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38922 - __FILE__,__LINE__, tty->driver->name, port->count );
38923 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38924
38925 spin_lock_irqsave(&info->lock, flags);
38926 if (!tty_hung_up_p(filp)) {
38927 extra_count = true;
38928 - port->count--;
38929 + atomic_dec(&port->count);
38930 }
38931 spin_unlock_irqrestore(&info->lock, flags);
38932 port->blocked_open++;
38933 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38934
38935 if (debug_level >= DEBUG_LEVEL_INFO)
38936 printk("%s(%d):%s block_til_ready() count=%d\n",
38937 - __FILE__,__LINE__, tty->driver->name, port->count );
38938 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38939
38940 tty_unlock();
38941 schedule();
38942 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38943 remove_wait_queue(&port->open_wait, &wait);
38944
38945 if (extra_count)
38946 - port->count++;
38947 + atomic_inc(&port->count);
38948 port->blocked_open--;
38949
38950 if (debug_level >= DEBUG_LEVEL_INFO)
38951 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38952 - __FILE__,__LINE__, tty->driver->name, port->count );
38953 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38954
38955 if (!retval)
38956 port->flags |= ASYNC_NORMAL_ACTIVE;
38957 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38958 index 05728894..b9d44c6 100644
38959 --- a/drivers/tty/sysrq.c
38960 +++ b/drivers/tty/sysrq.c
38961 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38962 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38963 size_t count, loff_t *ppos)
38964 {
38965 - if (count) {
38966 + if (count && capable(CAP_SYS_ADMIN)) {
38967 char c;
38968
38969 if (get_user(c, buf))
38970 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38971 index b425c79..08a3f06 100644
38972 --- a/drivers/tty/tty_io.c
38973 +++ b/drivers/tty/tty_io.c
38974 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38975
38976 void tty_default_fops(struct file_operations *fops)
38977 {
38978 - *fops = tty_fops;
38979 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38980 }
38981
38982 /*
38983 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38984 index 6f99c99..8947bc4 100644
38985 --- a/drivers/tty/tty_ldisc.c
38986 +++ b/drivers/tty/tty_ldisc.c
38987 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38988 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38989 struct tty_ldisc_ops *ldo = ld->ops;
38990
38991 - ldo->refcount--;
38992 + atomic_dec(&ldo->refcount);
38993 module_put(ldo->owner);
38994 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38995
38996 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38997 spin_lock_irqsave(&tty_ldisc_lock, flags);
38998 tty_ldiscs[disc] = new_ldisc;
38999 new_ldisc->num = disc;
39000 - new_ldisc->refcount = 0;
39001 + atomic_set(&new_ldisc->refcount, 0);
39002 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39003
39004 return ret;
39005 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39006 return -EINVAL;
39007
39008 spin_lock_irqsave(&tty_ldisc_lock, flags);
39009 - if (tty_ldiscs[disc]->refcount)
39010 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39011 ret = -EBUSY;
39012 else
39013 tty_ldiscs[disc] = NULL;
39014 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39015 if (ldops) {
39016 ret = ERR_PTR(-EAGAIN);
39017 if (try_module_get(ldops->owner)) {
39018 - ldops->refcount++;
39019 + atomic_inc(&ldops->refcount);
39020 ret = ldops;
39021 }
39022 }
39023 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39024 unsigned long flags;
39025
39026 spin_lock_irqsave(&tty_ldisc_lock, flags);
39027 - ldops->refcount--;
39028 + atomic_dec(&ldops->refcount);
39029 module_put(ldops->owner);
39030 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39031 }
39032 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39033 index bf6e238..d401c04 100644
39034 --- a/drivers/tty/tty_port.c
39035 +++ b/drivers/tty/tty_port.c
39036 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39037 unsigned long flags;
39038
39039 spin_lock_irqsave(&port->lock, flags);
39040 - port->count = 0;
39041 + atomic_set(&port->count, 0);
39042 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39043 if (port->tty) {
39044 set_bit(TTY_IO_ERROR, &port->tty->flags);
39045 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39046 /* The port lock protects the port counts */
39047 spin_lock_irqsave(&port->lock, flags);
39048 if (!tty_hung_up_p(filp))
39049 - port->count--;
39050 + atomic_dec(&port->count);
39051 port->blocked_open++;
39052 spin_unlock_irqrestore(&port->lock, flags);
39053
39054 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39055 we must not mess that up further */
39056 spin_lock_irqsave(&port->lock, flags);
39057 if (!tty_hung_up_p(filp))
39058 - port->count++;
39059 + atomic_inc(&port->count);
39060 port->blocked_open--;
39061 if (retval == 0)
39062 port->flags |= ASYNC_NORMAL_ACTIVE;
39063 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39064 return 0;
39065 }
39066
39067 - if (tty->count == 1 && port->count != 1) {
39068 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39069 printk(KERN_WARNING
39070 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39071 - port->count);
39072 - port->count = 1;
39073 + atomic_read(&port->count));
39074 + atomic_set(&port->count, 1);
39075 }
39076 - if (--port->count < 0) {
39077 + if (atomic_dec_return(&port->count) < 0) {
39078 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39079 - port->count);
39080 - port->count = 0;
39081 + atomic_read(&port->count));
39082 + atomic_set(&port->count, 0);
39083 }
39084
39085 - if (port->count) {
39086 + if (atomic_read(&port->count)) {
39087 spin_unlock_irqrestore(&port->lock, flags);
39088 if (port->ops->drop)
39089 port->ops->drop(port);
39090 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39091 {
39092 spin_lock_irq(&port->lock);
39093 if (!tty_hung_up_p(filp))
39094 - ++port->count;
39095 + atomic_inc(&port->count);
39096 spin_unlock_irq(&port->lock);
39097 tty_port_tty_set(port, tty);
39098
39099 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39100 index 770a854..e5d3db3 100644
39101 --- a/drivers/tty/vt/keyboard.c
39102 +++ b/drivers/tty/vt/keyboard.c
39103 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39104 kbd->kbdmode == VC_OFF) &&
39105 value != KVAL(K_SAK))
39106 return; /* SAK is allowed even in raw mode */
39107 +
39108 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39109 + {
39110 + void *func = fn_handler[value];
39111 + if (func == fn_show_state || func == fn_show_ptregs ||
39112 + func == fn_show_mem)
39113 + return;
39114 + }
39115 +#endif
39116 +
39117 fn_handler[value](vc);
39118 }
39119
39120 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39121 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39122 return -EFAULT;
39123
39124 - if (!capable(CAP_SYS_TTY_CONFIG))
39125 - perm = 0;
39126 -
39127 switch (cmd) {
39128 case KDGKBENT:
39129 /* Ensure another thread doesn't free it under us */
39130 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39131 spin_unlock_irqrestore(&kbd_event_lock, flags);
39132 return put_user(val, &user_kbe->kb_value);
39133 case KDSKBENT:
39134 + if (!capable(CAP_SYS_TTY_CONFIG))
39135 + perm = 0;
39136 +
39137 if (!perm)
39138 return -EPERM;
39139 if (!i && v == K_NOSUCHMAP) {
39140 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39141 int i, j, k;
39142 int ret;
39143
39144 - if (!capable(CAP_SYS_TTY_CONFIG))
39145 - perm = 0;
39146 -
39147 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39148 if (!kbs) {
39149 ret = -ENOMEM;
39150 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39151 kfree(kbs);
39152 return ((p && *p) ? -EOVERFLOW : 0);
39153 case KDSKBSENT:
39154 + if (!capable(CAP_SYS_TTY_CONFIG))
39155 + perm = 0;
39156 +
39157 if (!perm) {
39158 ret = -EPERM;
39159 goto reterr;
39160 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39161 index a783d53..cb30d94 100644
39162 --- a/drivers/uio/uio.c
39163 +++ b/drivers/uio/uio.c
39164 @@ -25,6 +25,7 @@
39165 #include <linux/kobject.h>
39166 #include <linux/cdev.h>
39167 #include <linux/uio_driver.h>
39168 +#include <asm/local.h>
39169
39170 #define UIO_MAX_DEVICES (1U << MINORBITS)
39171
39172 @@ -32,10 +33,10 @@ struct uio_device {
39173 struct module *owner;
39174 struct device *dev;
39175 int minor;
39176 - atomic_t event;
39177 + atomic_unchecked_t event;
39178 struct fasync_struct *async_queue;
39179 wait_queue_head_t wait;
39180 - int vma_count;
39181 + local_t vma_count;
39182 struct uio_info *info;
39183 struct kobject *map_dir;
39184 struct kobject *portio_dir;
39185 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39186 struct device_attribute *attr, char *buf)
39187 {
39188 struct uio_device *idev = dev_get_drvdata(dev);
39189 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39190 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39191 }
39192
39193 static struct device_attribute uio_class_attributes[] = {
39194 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39195 {
39196 struct uio_device *idev = info->uio_dev;
39197
39198 - atomic_inc(&idev->event);
39199 + atomic_inc_unchecked(&idev->event);
39200 wake_up_interruptible(&idev->wait);
39201 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39202 }
39203 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39204 }
39205
39206 listener->dev = idev;
39207 - listener->event_count = atomic_read(&idev->event);
39208 + listener->event_count = atomic_read_unchecked(&idev->event);
39209 filep->private_data = listener;
39210
39211 if (idev->info->open) {
39212 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39213 return -EIO;
39214
39215 poll_wait(filep, &idev->wait, wait);
39216 - if (listener->event_count != atomic_read(&idev->event))
39217 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39218 return POLLIN | POLLRDNORM;
39219 return 0;
39220 }
39221 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39222 do {
39223 set_current_state(TASK_INTERRUPTIBLE);
39224
39225 - event_count = atomic_read(&idev->event);
39226 + event_count = atomic_read_unchecked(&idev->event);
39227 if (event_count != listener->event_count) {
39228 if (copy_to_user(buf, &event_count, count))
39229 retval = -EFAULT;
39230 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39231 static void uio_vma_open(struct vm_area_struct *vma)
39232 {
39233 struct uio_device *idev = vma->vm_private_data;
39234 - idev->vma_count++;
39235 + local_inc(&idev->vma_count);
39236 }
39237
39238 static void uio_vma_close(struct vm_area_struct *vma)
39239 {
39240 struct uio_device *idev = vma->vm_private_data;
39241 - idev->vma_count--;
39242 + local_dec(&idev->vma_count);
39243 }
39244
39245 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39246 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39247 idev->owner = owner;
39248 idev->info = info;
39249 init_waitqueue_head(&idev->wait);
39250 - atomic_set(&idev->event, 0);
39251 + atomic_set_unchecked(&idev->event, 0);
39252
39253 ret = uio_get_minor(idev);
39254 if (ret)
39255 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39256 index b7eb86a..36d28af 100644
39257 --- a/drivers/usb/atm/cxacru.c
39258 +++ b/drivers/usb/atm/cxacru.c
39259 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39260 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39261 if (ret < 2)
39262 return -EINVAL;
39263 - if (index < 0 || index > 0x7f)
39264 + if (index > 0x7f)
39265 return -EINVAL;
39266 pos += tmp;
39267
39268 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39269 index ee62b35..b663594 100644
39270 --- a/drivers/usb/atm/usbatm.c
39271 +++ b/drivers/usb/atm/usbatm.c
39272 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39273 if (printk_ratelimit())
39274 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39275 __func__, vpi, vci);
39276 - atomic_inc(&vcc->stats->rx_err);
39277 + atomic_inc_unchecked(&vcc->stats->rx_err);
39278 return;
39279 }
39280
39281 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39282 if (length > ATM_MAX_AAL5_PDU) {
39283 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39284 __func__, length, vcc);
39285 - atomic_inc(&vcc->stats->rx_err);
39286 + atomic_inc_unchecked(&vcc->stats->rx_err);
39287 goto out;
39288 }
39289
39290 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39291 if (sarb->len < pdu_length) {
39292 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39293 __func__, pdu_length, sarb->len, vcc);
39294 - atomic_inc(&vcc->stats->rx_err);
39295 + atomic_inc_unchecked(&vcc->stats->rx_err);
39296 goto out;
39297 }
39298
39299 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39300 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39301 __func__, vcc);
39302 - atomic_inc(&vcc->stats->rx_err);
39303 + atomic_inc_unchecked(&vcc->stats->rx_err);
39304 goto out;
39305 }
39306
39307 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39308 if (printk_ratelimit())
39309 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39310 __func__, length);
39311 - atomic_inc(&vcc->stats->rx_drop);
39312 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39313 goto out;
39314 }
39315
39316 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39317
39318 vcc->push(vcc, skb);
39319
39320 - atomic_inc(&vcc->stats->rx);
39321 + atomic_inc_unchecked(&vcc->stats->rx);
39322 out:
39323 skb_trim(sarb, 0);
39324 }
39325 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39326 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39327
39328 usbatm_pop(vcc, skb);
39329 - atomic_inc(&vcc->stats->tx);
39330 + atomic_inc_unchecked(&vcc->stats->tx);
39331
39332 skb = skb_dequeue(&instance->sndqueue);
39333 }
39334 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39335 if (!left--)
39336 return sprintf(page,
39337 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39338 - atomic_read(&atm_dev->stats.aal5.tx),
39339 - atomic_read(&atm_dev->stats.aal5.tx_err),
39340 - atomic_read(&atm_dev->stats.aal5.rx),
39341 - atomic_read(&atm_dev->stats.aal5.rx_err),
39342 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39343 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39344 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39345 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39346 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39347 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39348
39349 if (!left--) {
39350 if (instance->disconnected)
39351 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39352 index 3440812..2a4ef1f 100644
39353 --- a/drivers/usb/core/devices.c
39354 +++ b/drivers/usb/core/devices.c
39355 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39356 * time it gets called.
39357 */
39358 static struct device_connect_event {
39359 - atomic_t count;
39360 + atomic_unchecked_t count;
39361 wait_queue_head_t wait;
39362 } device_event = {
39363 .count = ATOMIC_INIT(1),
39364 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39365
39366 void usbfs_conn_disc_event(void)
39367 {
39368 - atomic_add(2, &device_event.count);
39369 + atomic_add_unchecked(2, &device_event.count);
39370 wake_up(&device_event.wait);
39371 }
39372
39373 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39374
39375 poll_wait(file, &device_event.wait, wait);
39376
39377 - event_count = atomic_read(&device_event.count);
39378 + event_count = atomic_read_unchecked(&device_event.count);
39379 if (file->f_version != event_count) {
39380 file->f_version = event_count;
39381 return POLLIN | POLLRDNORM;
39382 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39383 index 89dcf15..481800b 100644
39384 --- a/drivers/usb/early/ehci-dbgp.c
39385 +++ b/drivers/usb/early/ehci-dbgp.c
39386 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39387
39388 #ifdef CONFIG_KGDB
39389 static struct kgdb_io kgdbdbgp_io_ops;
39390 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39391 +static struct kgdb_io kgdbdbgp_io_ops_console;
39392 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39393 #else
39394 #define dbgp_kgdb_mode (0)
39395 #endif
39396 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39397 .write_char = kgdbdbgp_write_char,
39398 };
39399
39400 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39401 + .name = "kgdbdbgp",
39402 + .read_char = kgdbdbgp_read_char,
39403 + .write_char = kgdbdbgp_write_char,
39404 + .is_console = 1
39405 +};
39406 +
39407 static int kgdbdbgp_wait_time;
39408
39409 static int __init kgdbdbgp_parse_config(char *str)
39410 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39411 ptr++;
39412 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39413 }
39414 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39415 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39416 + if (early_dbgp_console.index != -1)
39417 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39418 + else
39419 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39420
39421 return 0;
39422 }
39423 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39424 index da6d479..80ed10b 100644
39425 --- a/drivers/usb/gadget/u_serial.c
39426 +++ b/drivers/usb/gadget/u_serial.c
39427 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39428 spin_lock_irq(&port->port_lock);
39429
39430 /* already open? Great. */
39431 - if (port->port.count) {
39432 + if (atomic_read(&port->port.count)) {
39433 status = 0;
39434 - port->port.count++;
39435 + atomic_inc(&port->port.count);
39436
39437 /* currently opening/closing? wait ... */
39438 } else if (port->openclose) {
39439 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39440 tty->driver_data = port;
39441 port->port.tty = tty;
39442
39443 - port->port.count = 1;
39444 + atomic_set(&port->port.count, 1);
39445 port->openclose = false;
39446
39447 /* if connected, start the I/O stream */
39448 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39449
39450 spin_lock_irq(&port->port_lock);
39451
39452 - if (port->port.count != 1) {
39453 - if (port->port.count == 0)
39454 + if (atomic_read(&port->port.count) != 1) {
39455 + if (atomic_read(&port->port.count) == 0)
39456 WARN_ON(1);
39457 else
39458 - --port->port.count;
39459 + atomic_dec(&port->port.count);
39460 goto exit;
39461 }
39462
39463 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39464 * and sleep if necessary
39465 */
39466 port->openclose = true;
39467 - port->port.count = 0;
39468 + atomic_set(&port->port.count, 0);
39469
39470 gser = port->port_usb;
39471 if (gser && gser->disconnect)
39472 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39473 int cond;
39474
39475 spin_lock_irq(&port->port_lock);
39476 - cond = (port->port.count == 0) && !port->openclose;
39477 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39478 spin_unlock_irq(&port->port_lock);
39479 return cond;
39480 }
39481 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39482 /* if it's already open, start I/O ... and notify the serial
39483 * protocol about open/close status (connect/disconnect).
39484 */
39485 - if (port->port.count) {
39486 + if (atomic_read(&port->port.count)) {
39487 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39488 gs_start_io(port);
39489 if (gser->connect)
39490 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39491
39492 port->port_usb = NULL;
39493 gser->ioport = NULL;
39494 - if (port->port.count > 0 || port->openclose) {
39495 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39496 wake_up_interruptible(&port->drain_wait);
39497 if (port->port.tty)
39498 tty_hangup(port->port.tty);
39499 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39500
39501 /* finally, free any unused/unusable I/O buffers */
39502 spin_lock_irqsave(&port->port_lock, flags);
39503 - if (port->port.count == 0 && !port->openclose)
39504 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39505 gs_buf_free(&port->port_write_buf);
39506 gs_free_requests(gser->out, &port->read_pool, NULL);
39507 gs_free_requests(gser->out, &port->read_queue, NULL);
39508 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39509 index b9cca6d..75c75df 100644
39510 --- a/drivers/usb/serial/console.c
39511 +++ b/drivers/usb/serial/console.c
39512 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39513
39514 info->port = port;
39515
39516 - ++port->port.count;
39517 + atomic_inc(&port->port.count);
39518 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39519 if (serial->type->set_termios) {
39520 /*
39521 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39522 }
39523 /* Now that any required fake tty operations are completed restore
39524 * the tty port count */
39525 - --port->port.count;
39526 + atomic_dec(&port->port.count);
39527 /* The console is special in terms of closing the device so
39528 * indicate this port is now acting as a system console. */
39529 port->port.console = 1;
39530 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39531 free_tty:
39532 kfree(tty);
39533 reset_open_count:
39534 - port->port.count = 0;
39535 + atomic_set(&port->port.count, 0);
39536 usb_autopm_put_interface(serial->interface);
39537 error_get_interface:
39538 usb_serial_put(serial);
39539 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39540 index d6bea3e..60b250e 100644
39541 --- a/drivers/usb/wusbcore/wa-hc.h
39542 +++ b/drivers/usb/wusbcore/wa-hc.h
39543 @@ -192,7 +192,7 @@ struct wahc {
39544 struct list_head xfer_delayed_list;
39545 spinlock_t xfer_list_lock;
39546 struct work_struct xfer_work;
39547 - atomic_t xfer_id_count;
39548 + atomic_unchecked_t xfer_id_count;
39549 };
39550
39551
39552 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39553 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39554 spin_lock_init(&wa->xfer_list_lock);
39555 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39556 - atomic_set(&wa->xfer_id_count, 1);
39557 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39558 }
39559
39560 /**
39561 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39562 index 57c01ab..8a05959 100644
39563 --- a/drivers/usb/wusbcore/wa-xfer.c
39564 +++ b/drivers/usb/wusbcore/wa-xfer.c
39565 @@ -296,7 +296,7 @@ out:
39566 */
39567 static void wa_xfer_id_init(struct wa_xfer *xfer)
39568 {
39569 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39570 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39571 }
39572
39573 /*
39574 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39575 index ef82a0d..da8a0b3 100644
39576 --- a/drivers/vhost/vhost.c
39577 +++ b/drivers/vhost/vhost.c
39578 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39579 return 0;
39580 }
39581
39582 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39583 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39584 {
39585 struct file *eventfp, *filep = NULL,
39586 *pollstart = NULL, *pollstop = NULL;
39587 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39588 index 747442d..7c0c434 100644
39589 --- a/drivers/video/aty/aty128fb.c
39590 +++ b/drivers/video/aty/aty128fb.c
39591 @@ -149,7 +149,7 @@ enum {
39592 };
39593
39594 /* Must match above enum */
39595 -static const char *r128_family[] __devinitdata = {
39596 +static const char *r128_family[] __devinitconst = {
39597 "AGP",
39598 "PCI",
39599 "PRO AGP",
39600 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39601 index 5c3960d..15cf8fc 100644
39602 --- a/drivers/video/fbcmap.c
39603 +++ b/drivers/video/fbcmap.c
39604 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39605 rc = -ENODEV;
39606 goto out;
39607 }
39608 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39609 - !info->fbops->fb_setcmap)) {
39610 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39611 rc = -EINVAL;
39612 goto out1;
39613 }
39614 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39615 index 0dff12a..2ef47b3 100644
39616 --- a/drivers/video/fbmem.c
39617 +++ b/drivers/video/fbmem.c
39618 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39619 image->dx += image->width + 8;
39620 }
39621 } else if (rotate == FB_ROTATE_UD) {
39622 - for (x = 0; x < num && image->dx >= 0; x++) {
39623 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39624 info->fbops->fb_imageblit(info, image);
39625 image->dx -= image->width + 8;
39626 }
39627 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39628 image->dy += image->height + 8;
39629 }
39630 } else if (rotate == FB_ROTATE_CCW) {
39631 - for (x = 0; x < num && image->dy >= 0; x++) {
39632 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39633 info->fbops->fb_imageblit(info, image);
39634 image->dy -= image->height + 8;
39635 }
39636 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39637 return -EFAULT;
39638 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39639 return -EINVAL;
39640 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39641 + if (con2fb.framebuffer >= FB_MAX)
39642 return -EINVAL;
39643 if (!registered_fb[con2fb.framebuffer])
39644 request_module("fb%d", con2fb.framebuffer);
39645 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39646 index 5a5d092..265c5ed 100644
39647 --- a/drivers/video/geode/gx1fb_core.c
39648 +++ b/drivers/video/geode/gx1fb_core.c
39649 @@ -29,7 +29,7 @@ static int crt_option = 1;
39650 static char panel_option[32] = "";
39651
39652 /* Modes relevant to the GX1 (taken from modedb.c) */
39653 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39654 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39655 /* 640x480-60 VESA */
39656 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39657 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39658 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39659 index 0fad23f..0e9afa4 100644
39660 --- a/drivers/video/gxt4500.c
39661 +++ b/drivers/video/gxt4500.c
39662 @@ -156,7 +156,7 @@ struct gxt4500_par {
39663 static char *mode_option;
39664
39665 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39666 -static const struct fb_videomode defaultmode __devinitdata = {
39667 +static const struct fb_videomode defaultmode __devinitconst = {
39668 .refresh = 60,
39669 .xres = 1280,
39670 .yres = 1024,
39671 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39672 return 0;
39673 }
39674
39675 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39676 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39677 .id = "IBM GXT4500P",
39678 .type = FB_TYPE_PACKED_PIXELS,
39679 .visual = FB_VISUAL_PSEUDOCOLOR,
39680 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39681 index 7672d2e..b56437f 100644
39682 --- a/drivers/video/i810/i810_accel.c
39683 +++ b/drivers/video/i810/i810_accel.c
39684 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39685 }
39686 }
39687 printk("ringbuffer lockup!!!\n");
39688 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39689 i810_report_error(mmio);
39690 par->dev_flags |= LOCKUP;
39691 info->pixmap.scan_align = 1;
39692 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39693 index b83f361..2b05a91 100644
39694 --- a/drivers/video/i810/i810_main.c
39695 +++ b/drivers/video/i810/i810_main.c
39696 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39697 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39698
39699 /* PCI */
39700 -static const char *i810_pci_list[] __devinitdata = {
39701 +static const char *i810_pci_list[] __devinitconst = {
39702 "Intel(R) 810 Framebuffer Device" ,
39703 "Intel(R) 810-DC100 Framebuffer Device" ,
39704 "Intel(R) 810E Framebuffer Device" ,
39705 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39706 index de36693..3c63fc2 100644
39707 --- a/drivers/video/jz4740_fb.c
39708 +++ b/drivers/video/jz4740_fb.c
39709 @@ -136,7 +136,7 @@ struct jzfb {
39710 uint32_t pseudo_palette[16];
39711 };
39712
39713 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39714 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39715 .id = "JZ4740 FB",
39716 .type = FB_TYPE_PACKED_PIXELS,
39717 .visual = FB_VISUAL_TRUECOLOR,
39718 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39719 index 3c14e43..eafa544 100644
39720 --- a/drivers/video/logo/logo_linux_clut224.ppm
39721 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39722 @@ -1,1604 +1,1123 @@
39723 P3
39724 -# Standard 224-color Linux logo
39725 80 80
39726 255
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 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 6 6 6 6 6 6 10 10 10 10 10 10
39737 - 10 10 10 6 6 6 6 6 6 6 6 6
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 6 6 6 10 10 10 14 14 14
39756 - 22 22 22 26 26 26 30 30 30 34 34 34
39757 - 30 30 30 30 30 30 26 26 26 18 18 18
39758 - 14 14 14 10 10 10 6 6 6 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 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 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 1 0 0 1 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 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 6 6 6 14 14 14 26 26 26 42 42 42
39776 - 54 54 54 66 66 66 78 78 78 78 78 78
39777 - 78 78 78 74 74 74 66 66 66 54 54 54
39778 - 42 42 42 26 26 26 18 18 18 10 10 10
39779 - 6 6 6 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 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 0 0 0 0 0 0 0
39788 - 0 0 1 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 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 10 10 10
39795 - 22 22 22 42 42 42 66 66 66 86 86 86
39796 - 66 66 66 38 38 38 38 38 38 22 22 22
39797 - 26 26 26 34 34 34 54 54 54 66 66 66
39798 - 86 86 86 70 70 70 46 46 46 26 26 26
39799 - 14 14 14 6 6 6 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 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 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 10 10 10 26 26 26
39815 - 50 50 50 82 82 82 58 58 58 6 6 6
39816 - 2 2 6 2 2 6 2 2 6 2 2 6
39817 - 2 2 6 2 2 6 2 2 6 2 2 6
39818 - 6 6 6 54 54 54 86 86 86 66 66 66
39819 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 6 6 6 22 22 22 50 50 50
39835 - 78 78 78 34 34 34 2 2 6 2 2 6
39836 - 2 2 6 2 2 6 2 2 6 2 2 6
39837 - 2 2 6 2 2 6 2 2 6 2 2 6
39838 - 2 2 6 2 2 6 6 6 6 70 70 70
39839 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 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 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 6 6 6 18 18 18 42 42 42 82 82 82
39855 - 26 26 26 2 2 6 2 2 6 2 2 6
39856 - 2 2 6 2 2 6 2 2 6 2 2 6
39857 - 2 2 6 2 2 6 2 2 6 14 14 14
39858 - 46 46 46 34 34 34 6 6 6 2 2 6
39859 - 42 42 42 78 78 78 42 42 42 18 18 18
39860 - 6 6 6 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 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 10 10 10 30 30 30 66 66 66 58 58 58
39875 - 2 2 6 2 2 6 2 2 6 2 2 6
39876 - 2 2 6 2 2 6 2 2 6 2 2 6
39877 - 2 2 6 2 2 6 2 2 6 26 26 26
39878 - 86 86 86 101 101 101 46 46 46 10 10 10
39879 - 2 2 6 58 58 58 70 70 70 34 34 34
39880 - 10 10 10 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 1 0 0 1 0 0 1 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 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 14 14 14 42 42 42 86 86 86 10 10 10
39895 - 2 2 6 2 2 6 2 2 6 2 2 6
39896 - 2 2 6 2 2 6 2 2 6 2 2 6
39897 - 2 2 6 2 2 6 2 2 6 30 30 30
39898 - 94 94 94 94 94 94 58 58 58 26 26 26
39899 - 2 2 6 6 6 6 78 78 78 54 54 54
39900 - 22 22 22 6 6 6 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 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 6 6 6
39914 - 22 22 22 62 62 62 62 62 62 2 2 6
39915 - 2 2 6 2 2 6 2 2 6 2 2 6
39916 - 2 2 6 2 2 6 2 2 6 2 2 6
39917 - 2 2 6 2 2 6 2 2 6 26 26 26
39918 - 54 54 54 38 38 38 18 18 18 10 10 10
39919 - 2 2 6 2 2 6 34 34 34 82 82 82
39920 - 38 38 38 14 14 14 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 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 1 0 0 1 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 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 6 6 6
39934 - 30 30 30 78 78 78 30 30 30 2 2 6
39935 - 2 2 6 2 2 6 2 2 6 2 2 6
39936 - 2 2 6 2 2 6 2 2 6 2 2 6
39937 - 2 2 6 2 2 6 2 2 6 10 10 10
39938 - 10 10 10 2 2 6 2 2 6 2 2 6
39939 - 2 2 6 2 2 6 2 2 6 78 78 78
39940 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 1 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 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 10 10 10
39954 - 38 38 38 86 86 86 14 14 14 2 2 6
39955 - 2 2 6 2 2 6 2 2 6 2 2 6
39956 - 2 2 6 2 2 6 2 2 6 2 2 6
39957 - 2 2 6 2 2 6 2 2 6 2 2 6
39958 - 2 2 6 2 2 6 2 2 6 2 2 6
39959 - 2 2 6 2 2 6 2 2 6 54 54 54
39960 - 66 66 66 26 26 26 6 6 6 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 1 0 0 1 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 14 14 14
39974 - 42 42 42 82 82 82 2 2 6 2 2 6
39975 - 2 2 6 6 6 6 10 10 10 2 2 6
39976 - 2 2 6 2 2 6 2 2 6 2 2 6
39977 - 2 2 6 2 2 6 2 2 6 6 6 6
39978 - 14 14 14 10 10 10 2 2 6 2 2 6
39979 - 2 2 6 2 2 6 2 2 6 18 18 18
39980 - 82 82 82 34 34 34 10 10 10 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 1 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 14 14 14
39994 - 46 46 46 86 86 86 2 2 6 2 2 6
39995 - 6 6 6 6 6 6 22 22 22 34 34 34
39996 - 6 6 6 2 2 6 2 2 6 2 2 6
39997 - 2 2 6 2 2 6 18 18 18 34 34 34
39998 - 10 10 10 50 50 50 22 22 22 2 2 6
39999 - 2 2 6 2 2 6 2 2 6 10 10 10
40000 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 14 14 14
40014 - 46 46 46 86 86 86 2 2 6 2 2 6
40015 - 38 38 38 116 116 116 94 94 94 22 22 22
40016 - 22 22 22 2 2 6 2 2 6 2 2 6
40017 - 14 14 14 86 86 86 138 138 138 162 162 162
40018 -154 154 154 38 38 38 26 26 26 6 6 6
40019 - 2 2 6 2 2 6 2 2 6 2 2 6
40020 - 86 86 86 46 46 46 14 14 14 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 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 14 14 14
40034 - 46 46 46 86 86 86 2 2 6 14 14 14
40035 -134 134 134 198 198 198 195 195 195 116 116 116
40036 - 10 10 10 2 2 6 2 2 6 6 6 6
40037 -101 98 89 187 187 187 210 210 210 218 218 218
40038 -214 214 214 134 134 134 14 14 14 6 6 6
40039 - 2 2 6 2 2 6 2 2 6 2 2 6
40040 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
40048 - 0 0 1 0 0 1 0 0 1 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 14 14 14
40054 - 46 46 46 86 86 86 2 2 6 54 54 54
40055 -218 218 218 195 195 195 226 226 226 246 246 246
40056 - 58 58 58 2 2 6 2 2 6 30 30 30
40057 -210 210 210 253 253 253 174 174 174 123 123 123
40058 -221 221 221 234 234 234 74 74 74 2 2 6
40059 - 2 2 6 2 2 6 2 2 6 2 2 6
40060 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 14 14 14
40074 - 46 46 46 82 82 82 2 2 6 106 106 106
40075 -170 170 170 26 26 26 86 86 86 226 226 226
40076 -123 123 123 10 10 10 14 14 14 46 46 46
40077 -231 231 231 190 190 190 6 6 6 70 70 70
40078 - 90 90 90 238 238 238 158 158 158 2 2 6
40079 - 2 2 6 2 2 6 2 2 6 2 2 6
40080 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
40088 - 0 0 1 0 0 1 0 0 1 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 14 14 14
40094 - 42 42 42 86 86 86 6 6 6 116 116 116
40095 -106 106 106 6 6 6 70 70 70 149 149 149
40096 -128 128 128 18 18 18 38 38 38 54 54 54
40097 -221 221 221 106 106 106 2 2 6 14 14 14
40098 - 46 46 46 190 190 190 198 198 198 2 2 6
40099 - 2 2 6 2 2 6 2 2 6 2 2 6
40100 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
40108 - 0 0 1 0 0 0 0 0 1 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 14 14 14
40114 - 42 42 42 94 94 94 14 14 14 101 101 101
40115 -128 128 128 2 2 6 18 18 18 116 116 116
40116 -118 98 46 121 92 8 121 92 8 98 78 10
40117 -162 162 162 106 106 106 2 2 6 2 2 6
40118 - 2 2 6 195 195 195 195 195 195 6 6 6
40119 - 2 2 6 2 2 6 2 2 6 2 2 6
40120 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
40128 - 0 0 1 0 0 0 0 0 1 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 10 10 10
40134 - 38 38 38 90 90 90 14 14 14 58 58 58
40135 -210 210 210 26 26 26 54 38 6 154 114 10
40136 -226 170 11 236 186 11 225 175 15 184 144 12
40137 -215 174 15 175 146 61 37 26 9 2 2 6
40138 - 70 70 70 246 246 246 138 138 138 2 2 6
40139 - 2 2 6 2 2 6 2 2 6 2 2 6
40140 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 10 10 10
40154 - 38 38 38 86 86 86 14 14 14 10 10 10
40155 -195 195 195 188 164 115 192 133 9 225 175 15
40156 -239 182 13 234 190 10 232 195 16 232 200 30
40157 -245 207 45 241 208 19 232 195 16 184 144 12
40158 -218 194 134 211 206 186 42 42 42 2 2 6
40159 - 2 2 6 2 2 6 2 2 6 2 2 6
40160 - 50 50 50 74 74 74 30 30 30 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 10 10 10
40174 - 34 34 34 86 86 86 14 14 14 2 2 6
40175 -121 87 25 192 133 9 219 162 10 239 182 13
40176 -236 186 11 232 195 16 241 208 19 244 214 54
40177 -246 218 60 246 218 38 246 215 20 241 208 19
40178 -241 208 19 226 184 13 121 87 25 2 2 6
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 50 50 50 82 82 82 34 34 34 10 10 10
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 10 10 10
40194 - 34 34 34 82 82 82 30 30 30 61 42 6
40195 -180 123 7 206 145 10 230 174 11 239 182 13
40196 -234 190 10 238 202 15 241 208 19 246 218 74
40197 -246 218 38 246 215 20 246 215 20 246 215 20
40198 -226 184 13 215 174 15 184 144 12 6 6 6
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 26 26 26 94 94 94 42 42 42 14 14 14
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 10 10 10
40214 - 30 30 30 78 78 78 50 50 50 104 69 6
40215 -192 133 9 216 158 10 236 178 12 236 186 11
40216 -232 195 16 241 208 19 244 214 54 245 215 43
40217 -246 215 20 246 215 20 241 208 19 198 155 10
40218 -200 144 11 216 158 10 156 118 10 2 2 6
40219 - 2 2 6 2 2 6 2 2 6 2 2 6
40220 - 6 6 6 90 90 90 54 54 54 18 18 18
40221 - 6 6 6 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 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 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 10 10 10
40234 - 30 30 30 78 78 78 46 46 46 22 22 22
40235 -137 92 6 210 162 10 239 182 13 238 190 10
40236 -238 202 15 241 208 19 246 215 20 246 215 20
40237 -241 208 19 203 166 17 185 133 11 210 150 10
40238 -216 158 10 210 150 10 102 78 10 2 2 6
40239 - 6 6 6 54 54 54 14 14 14 2 2 6
40240 - 2 2 6 62 62 62 74 74 74 30 30 30
40241 - 10 10 10 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 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 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 10 10 10
40254 - 34 34 34 78 78 78 50 50 50 6 6 6
40255 - 94 70 30 139 102 15 190 146 13 226 184 13
40256 -232 200 30 232 195 16 215 174 15 190 146 13
40257 -168 122 10 192 133 9 210 150 10 213 154 11
40258 -202 150 34 182 157 106 101 98 89 2 2 6
40259 - 2 2 6 78 78 78 116 116 116 58 58 58
40260 - 2 2 6 22 22 22 90 90 90 46 46 46
40261 - 18 18 18 6 6 6 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 10 10 10
40274 - 38 38 38 86 86 86 50 50 50 6 6 6
40275 -128 128 128 174 154 114 156 107 11 168 122 10
40276 -198 155 10 184 144 12 197 138 11 200 144 11
40277 -206 145 10 206 145 10 197 138 11 188 164 115
40278 -195 195 195 198 198 198 174 174 174 14 14 14
40279 - 2 2 6 22 22 22 116 116 116 116 116 116
40280 - 22 22 22 2 2 6 74 74 74 70 70 70
40281 - 30 30 30 10 10 10 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 6 6 6 18 18 18
40294 - 50 50 50 101 101 101 26 26 26 10 10 10
40295 -138 138 138 190 190 190 174 154 114 156 107 11
40296 -197 138 11 200 144 11 197 138 11 192 133 9
40297 -180 123 7 190 142 34 190 178 144 187 187 187
40298 -202 202 202 221 221 221 214 214 214 66 66 66
40299 - 2 2 6 2 2 6 50 50 50 62 62 62
40300 - 6 6 6 2 2 6 10 10 10 90 90 90
40301 - 50 50 50 18 18 18 6 6 6 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 10 10 10 34 34 34
40314 - 74 74 74 74 74 74 2 2 6 6 6 6
40315 -144 144 144 198 198 198 190 190 190 178 166 146
40316 -154 121 60 156 107 11 156 107 11 168 124 44
40317 -174 154 114 187 187 187 190 190 190 210 210 210
40318 -246 246 246 253 253 253 253 253 253 182 182 182
40319 - 6 6 6 2 2 6 2 2 6 2 2 6
40320 - 2 2 6 2 2 6 2 2 6 62 62 62
40321 - 74 74 74 34 34 34 14 14 14 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 10 10 10 22 22 22 54 54 54
40334 - 94 94 94 18 18 18 2 2 6 46 46 46
40335 -234 234 234 221 221 221 190 190 190 190 190 190
40336 -190 190 190 187 187 187 187 187 187 190 190 190
40337 -190 190 190 195 195 195 214 214 214 242 242 242
40338 -253 253 253 253 253 253 253 253 253 253 253 253
40339 - 82 82 82 2 2 6 2 2 6 2 2 6
40340 - 2 2 6 2 2 6 2 2 6 14 14 14
40341 - 86 86 86 54 54 54 22 22 22 6 6 6
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 6 6 6 18 18 18 46 46 46 90 90 90
40354 - 46 46 46 18 18 18 6 6 6 182 182 182
40355 -253 253 253 246 246 246 206 206 206 190 190 190
40356 -190 190 190 190 190 190 190 190 190 190 190 190
40357 -206 206 206 231 231 231 250 250 250 253 253 253
40358 -253 253 253 253 253 253 253 253 253 253 253 253
40359 -202 202 202 14 14 14 2 2 6 2 2 6
40360 - 2 2 6 2 2 6 2 2 6 2 2 6
40361 - 42 42 42 86 86 86 42 42 42 18 18 18
40362 - 6 6 6 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 6 6 6
40373 - 14 14 14 38 38 38 74 74 74 66 66 66
40374 - 2 2 6 6 6 6 90 90 90 250 250 250
40375 -253 253 253 253 253 253 238 238 238 198 198 198
40376 -190 190 190 190 190 190 195 195 195 221 221 221
40377 -246 246 246 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 253 253 253 253 253 253
40379 -253 253 253 82 82 82 2 2 6 2 2 6
40380 - 2 2 6 2 2 6 2 2 6 2 2 6
40381 - 2 2 6 78 78 78 70 70 70 34 34 34
40382 - 14 14 14 6 6 6 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 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 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 14 14 14
40393 - 34 34 34 66 66 66 78 78 78 6 6 6
40394 - 2 2 6 18 18 18 218 218 218 253 253 253
40395 -253 253 253 253 253 253 253 253 253 246 246 246
40396 -226 226 226 231 231 231 246 246 246 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 253 253 253
40399 -253 253 253 178 178 178 2 2 6 2 2 6
40400 - 2 2 6 2 2 6 2 2 6 2 2 6
40401 - 2 2 6 18 18 18 90 90 90 62 62 62
40402 - 30 30 30 10 10 10 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 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 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 10 10 10 26 26 26
40413 - 58 58 58 90 90 90 18 18 18 2 2 6
40414 - 2 2 6 110 110 110 253 253 253 253 253 253
40415 -253 253 253 253 253 253 253 253 253 253 253 253
40416 -250 250 250 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 231 231 231 18 18 18 2 2 6
40420 - 2 2 6 2 2 6 2 2 6 2 2 6
40421 - 2 2 6 2 2 6 18 18 18 94 94 94
40422 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 6 6 6 22 22 22 50 50 50
40433 - 90 90 90 26 26 26 2 2 6 2 2 6
40434 - 14 14 14 195 195 195 250 250 250 253 253 253
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 -250 250 250 242 242 242 54 54 54 2 2 6
40440 - 2 2 6 2 2 6 2 2 6 2 2 6
40441 - 2 2 6 2 2 6 2 2 6 38 38 38
40442 - 86 86 86 50 50 50 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 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 6 6 6 14 14 14 38 38 38 82 82 82
40453 - 34 34 34 2 2 6 2 2 6 2 2 6
40454 - 42 42 42 195 195 195 246 246 246 253 253 253
40455 -253 253 253 253 253 253 253 253 253 250 250 250
40456 -242 242 242 242 242 242 250 250 250 253 253 253
40457 -253 253 253 253 253 253 253 253 253 253 253 253
40458 -253 253 253 250 250 250 246 246 246 238 238 238
40459 -226 226 226 231 231 231 101 101 101 6 6 6
40460 - 2 2 6 2 2 6 2 2 6 2 2 6
40461 - 2 2 6 2 2 6 2 2 6 2 2 6
40462 - 38 38 38 82 82 82 42 42 42 14 14 14
40463 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 10 10 10 26 26 26 62 62 62 66 66 66
40473 - 2 2 6 2 2 6 2 2 6 6 6 6
40474 - 70 70 70 170 170 170 206 206 206 234 234 234
40475 -246 246 246 250 250 250 250 250 250 238 238 238
40476 -226 226 226 231 231 231 238 238 238 250 250 250
40477 -250 250 250 250 250 250 246 246 246 231 231 231
40478 -214 214 214 206 206 206 202 202 202 202 202 202
40479 -198 198 198 202 202 202 182 182 182 18 18 18
40480 - 2 2 6 2 2 6 2 2 6 2 2 6
40481 - 2 2 6 2 2 6 2 2 6 2 2 6
40482 - 2 2 6 62 62 62 66 66 66 30 30 30
40483 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 14 14 14 42 42 42 82 82 82 18 18 18
40493 - 2 2 6 2 2 6 2 2 6 10 10 10
40494 - 94 94 94 182 182 182 218 218 218 242 242 242
40495 -250 250 250 253 253 253 253 253 253 250 250 250
40496 -234 234 234 253 253 253 253 253 253 253 253 253
40497 -253 253 253 253 253 253 253 253 253 246 246 246
40498 -238 238 238 226 226 226 210 210 210 202 202 202
40499 -195 195 195 195 195 195 210 210 210 158 158 158
40500 - 6 6 6 14 14 14 50 50 50 14 14 14
40501 - 2 2 6 2 2 6 2 2 6 2 2 6
40502 - 2 2 6 6 6 6 86 86 86 46 46 46
40503 - 18 18 18 6 6 6 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 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 6 6 6
40512 - 22 22 22 54 54 54 70 70 70 2 2 6
40513 - 2 2 6 10 10 10 2 2 6 22 22 22
40514 -166 166 166 231 231 231 250 250 250 253 253 253
40515 -253 253 253 253 253 253 253 253 253 250 250 250
40516 -242 242 242 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 246 246 246
40519 -231 231 231 206 206 206 198 198 198 226 226 226
40520 - 94 94 94 2 2 6 6 6 6 38 38 38
40521 - 30 30 30 2 2 6 2 2 6 2 2 6
40522 - 2 2 6 2 2 6 62 62 62 66 66 66
40523 - 26 26 26 10 10 10 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 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 10 10 10
40532 - 30 30 30 74 74 74 50 50 50 2 2 6
40533 - 26 26 26 26 26 26 2 2 6 106 106 106
40534 -238 238 238 253 253 253 253 253 253 253 253 253
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 246 246 246 218 218 218 202 202 202
40540 -210 210 210 14 14 14 2 2 6 2 2 6
40541 - 30 30 30 22 22 22 2 2 6 2 2 6
40542 - 2 2 6 2 2 6 18 18 18 86 86 86
40543 - 42 42 42 14 14 14 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 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 14 14 14
40552 - 42 42 42 90 90 90 22 22 22 2 2 6
40553 - 42 42 42 2 2 6 18 18 18 218 218 218
40554 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
40560 -218 218 218 101 101 101 2 2 6 14 14 14
40561 - 18 18 18 38 38 38 10 10 10 2 2 6
40562 - 2 2 6 2 2 6 2 2 6 78 78 78
40563 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 6 6 6 18 18 18
40572 - 54 54 54 82 82 82 2 2 6 26 26 26
40573 - 22 22 22 2 2 6 123 123 123 253 253 253
40574 -253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 250 250 250
40580 -238 238 238 198 198 198 6 6 6 38 38 38
40581 - 58 58 58 26 26 26 38 38 38 2 2 6
40582 - 2 2 6 2 2 6 2 2 6 46 46 46
40583 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 10 10 10 30 30 30
40592 - 74 74 74 58 58 58 2 2 6 42 42 42
40593 - 2 2 6 22 22 22 231 231 231 253 253 253
40594 -253 253 253 253 253 253 253 253 253 253 253 253
40595 -253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253 253 253 253
40600 -253 253 253 246 246 246 46 46 46 38 38 38
40601 - 42 42 42 14 14 14 38 38 38 14 14 14
40602 - 2 2 6 2 2 6 2 2 6 6 6 6
40603 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 6 6 6 14 14 14 42 42 42
40612 - 90 90 90 18 18 18 18 18 18 26 26 26
40613 - 2 2 6 116 116 116 253 253 253 253 253 253
40614 -253 253 253 253 253 253 253 253 253 253 253 253
40615 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 253 253 253
40620 -253 253 253 253 253 253 94 94 94 6 6 6
40621 - 2 2 6 2 2 6 10 10 10 34 34 34
40622 - 2 2 6 2 2 6 2 2 6 2 2 6
40623 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 10 10 10 26 26 26 66 66 66
40632 - 82 82 82 2 2 6 38 38 38 6 6 6
40633 - 14 14 14 210 210 210 253 253 253 253 253 253
40634 -253 253 253 253 253 253 253 253 253 253 253 253
40635 -253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253
40640 -253 253 253 253 253 253 144 144 144 2 2 6
40641 - 2 2 6 2 2 6 2 2 6 46 46 46
40642 - 2 2 6 2 2 6 2 2 6 2 2 6
40643 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 0 0 0
40651 - 6 6 6 14 14 14 42 42 42 90 90 90
40652 - 26 26 26 6 6 6 42 42 42 2 2 6
40653 - 74 74 74 250 250 250 253 253 253 253 253 253
40654 -253 253 253 253 253 253 253 253 253 253 253 253
40655 -253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253
40659 -253 253 253 253 253 253 253 253 253 253 253 253
40660 -253 253 253 253 253 253 182 182 182 2 2 6
40661 - 2 2 6 2 2 6 2 2 6 46 46 46
40662 - 2 2 6 2 2 6 2 2 6 2 2 6
40663 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0 0 0 0
40669 - 0 0 0 0 0 0 0 0 0 0 0 0
40670 - 0 0 0 0 0 0 0 0 0 0 0 0
40671 - 10 10 10 26 26 26 66 66 66 82 82 82
40672 - 2 2 6 22 22 22 18 18 18 2 2 6
40673 -149 149 149 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 253 253 253 253 253 253
40675 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253
40679 -253 253 253 253 253 253 253 253 253 253 253 253
40680 -253 253 253 253 253 253 206 206 206 2 2 6
40681 - 2 2 6 2 2 6 2 2 6 38 38 38
40682 - 2 2 6 2 2 6 2 2 6 2 2 6
40683 - 6 6 6 86 86 86 46 46 46 14 14 14
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40689 - 0 0 0 0 0 0 0 0 0 0 0 0
40690 - 0 0 0 0 0 0 0 0 0 6 6 6
40691 - 18 18 18 46 46 46 86 86 86 18 18 18
40692 - 2 2 6 34 34 34 10 10 10 6 6 6
40693 -210 210 210 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 253 253 253 253 253 253
40695 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253
40699 -253 253 253 253 253 253 253 253 253 253 253 253
40700 -253 253 253 253 253 253 221 221 221 6 6 6
40701 - 2 2 6 2 2 6 6 6 6 30 30 30
40702 - 2 2 6 2 2 6 2 2 6 2 2 6
40703 - 2 2 6 82 82 82 54 54 54 18 18 18
40704 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40709 - 0 0 0 0 0 0 0 0 0 0 0 0
40710 - 0 0 0 0 0 0 0 0 0 10 10 10
40711 - 26 26 26 66 66 66 62 62 62 2 2 6
40712 - 2 2 6 38 38 38 10 10 10 26 26 26
40713 -238 238 238 253 253 253 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 231 231 231 238 238 238
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 253 253 253 253 253 253 253 253 253
40719 -253 253 253 253 253 253 253 253 253 253 253 253
40720 -253 253 253 253 253 253 231 231 231 6 6 6
40721 - 2 2 6 2 2 6 10 10 10 30 30 30
40722 - 2 2 6 2 2 6 2 2 6 2 2 6
40723 - 2 2 6 66 66 66 58 58 58 22 22 22
40724 - 6 6 6 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 0 0 0
40728 - 0 0 0 0 0 0 0 0 0 0 0 0
40729 - 0 0 0 0 0 0 0 0 0 0 0 0
40730 - 0 0 0 0 0 0 0 0 0 10 10 10
40731 - 38 38 38 78 78 78 6 6 6 2 2 6
40732 - 2 2 6 46 46 46 14 14 14 42 42 42
40733 -246 246 246 253 253 253 253 253 253 253 253 253
40734 -253 253 253 253 253 253 253 253 253 253 253 253
40735 -253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253 253 253 253
40739 -253 253 253 253 253 253 253 253 253 253 253 253
40740 -253 253 253 253 253 253 234 234 234 10 10 10
40741 - 2 2 6 2 2 6 22 22 22 14 14 14
40742 - 2 2 6 2 2 6 2 2 6 2 2 6
40743 - 2 2 6 66 66 66 62 62 62 22 22 22
40744 - 6 6 6 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 0 0 0
40748 - 0 0 0 0 0 0 0 0 0 0 0 0
40749 - 0 0 0 0 0 0 0 0 0 0 0 0
40750 - 0 0 0 0 0 0 6 6 6 18 18 18
40751 - 50 50 50 74 74 74 2 2 6 2 2 6
40752 - 14 14 14 70 70 70 34 34 34 62 62 62
40753 -250 250 250 253 253 253 253 253 253 253 253 253
40754 -253 253 253 253 253 253 253 253 253 253 253 253
40755 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
40759 -253 253 253 253 253 253 253 253 253 253 253 253
40760 -253 253 253 253 253 253 234 234 234 14 14 14
40761 - 2 2 6 2 2 6 30 30 30 2 2 6
40762 - 2 2 6 2 2 6 2 2 6 2 2 6
40763 - 2 2 6 66 66 66 62 62 62 22 22 22
40764 - 6 6 6 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 0 0 0
40768 - 0 0 0 0 0 0 0 0 0 0 0 0
40769 - 0 0 0 0 0 0 0 0 0 0 0 0
40770 - 0 0 0 0 0 0 6 6 6 18 18 18
40771 - 54 54 54 62 62 62 2 2 6 2 2 6
40772 - 2 2 6 30 30 30 46 46 46 70 70 70
40773 -250 250 250 253 253 253 253 253 253 253 253 253
40774 -253 253 253 253 253 253 253 253 253 253 253 253
40775 -253 253 253 253 253 253 231 231 231 246 246 246
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 -253 253 253 253 253 253 253 253 253 253 253 253
40779 -253 253 253 253 253 253 253 253 253 253 253 253
40780 -253 253 253 253 253 253 226 226 226 10 10 10
40781 - 2 2 6 6 6 6 30 30 30 2 2 6
40782 - 2 2 6 2 2 6 2 2 6 2 2 6
40783 - 2 2 6 66 66 66 58 58 58 22 22 22
40784 - 6 6 6 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 0 0 0
40788 - 0 0 0 0 0 0 0 0 0 0 0 0
40789 - 0 0 0 0 0 0 0 0 0 0 0 0
40790 - 0 0 0 0 0 0 6 6 6 22 22 22
40791 - 58 58 58 62 62 62 2 2 6 2 2 6
40792 - 2 2 6 2 2 6 30 30 30 78 78 78
40793 -250 250 250 253 253 253 253 253 253 253 253 253
40794 -253 253 253 253 253 253 253 253 253 253 253 253
40795 -253 253 253 253 253 253 231 231 231 246 246 246
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 -253 253 253 253 253 253 253 253 253 253 253 253
40799 -253 253 253 253 253 253 253 253 253 253 253 253
40800 -253 253 253 253 253 253 206 206 206 2 2 6
40801 - 22 22 22 34 34 34 18 14 6 22 22 22
40802 - 26 26 26 18 18 18 6 6 6 2 2 6
40803 - 2 2 6 82 82 82 54 54 54 18 18 18
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 0 0 0
40808 - 0 0 0 0 0 0 0 0 0 0 0 0
40809 - 0 0 0 0 0 0 0 0 0 0 0 0
40810 - 0 0 0 0 0 0 6 6 6 26 26 26
40811 - 62 62 62 106 106 106 74 54 14 185 133 11
40812 -210 162 10 121 92 8 6 6 6 62 62 62
40813 -238 238 238 253 253 253 253 253 253 253 253 253
40814 -253 253 253 253 253 253 253 253 253 253 253 253
40815 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
40819 -253 253 253 253 253 253 253 253 253 253 253 253
40820 -253 253 253 253 253 253 158 158 158 18 18 18
40821 - 14 14 14 2 2 6 2 2 6 2 2 6
40822 - 6 6 6 18 18 18 66 66 66 38 38 38
40823 - 6 6 6 94 94 94 50 50 50 18 18 18
40824 - 6 6 6 0 0 0 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 0 0 0
40828 - 0 0 0 0 0 0 0 0 0 0 0 0
40829 - 0 0 0 0 0 0 0 0 0 6 6 6
40830 - 10 10 10 10 10 10 18 18 18 38 38 38
40831 - 78 78 78 142 134 106 216 158 10 242 186 14
40832 -246 190 14 246 190 14 156 118 10 10 10 10
40833 - 90 90 90 238 238 238 253 253 253 253 253 253
40834 -253 253 253 253 253 253 253 253 253 253 253 253
40835 -253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
40839 -253 253 253 253 253 253 253 253 253 246 230 190
40840 -238 204 91 238 204 91 181 142 44 37 26 9
40841 - 2 2 6 2 2 6 2 2 6 2 2 6
40842 - 2 2 6 2 2 6 38 38 38 46 46 46
40843 - 26 26 26 106 106 106 54 54 54 18 18 18
40844 - 6 6 6 0 0 0 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 0 0 0
40848 - 0 0 0 0 0 0 0 0 0 0 0 0
40849 - 0 0 0 6 6 6 14 14 14 22 22 22
40850 - 30 30 30 38 38 38 50 50 50 70 70 70
40851 -106 106 106 190 142 34 226 170 11 242 186 14
40852 -246 190 14 246 190 14 246 190 14 154 114 10
40853 - 6 6 6 74 74 74 226 226 226 253 253 253
40854 -253 253 253 253 253 253 253 253 253 253 253 253
40855 -253 253 253 253 253 253 231 231 231 250 250 250
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 -253 253 253 253 253 253 253 253 253 253 253 253
40859 -253 253 253 253 253 253 253 253 253 228 184 62
40860 -241 196 14 241 208 19 232 195 16 38 30 10
40861 - 2 2 6 2 2 6 2 2 6 2 2 6
40862 - 2 2 6 6 6 6 30 30 30 26 26 26
40863 -203 166 17 154 142 90 66 66 66 26 26 26
40864 - 6 6 6 0 0 0 0 0 0 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 0 0 0
40868 - 0 0 0 0 0 0 0 0 0 0 0 0
40869 - 6 6 6 18 18 18 38 38 38 58 58 58
40870 - 78 78 78 86 86 86 101 101 101 123 123 123
40871 -175 146 61 210 150 10 234 174 13 246 186 14
40872 -246 190 14 246 190 14 246 190 14 238 190 10
40873 -102 78 10 2 2 6 46 46 46 198 198 198
40874 -253 253 253 253 253 253 253 253 253 253 253 253
40875 -253 253 253 253 253 253 234 234 234 242 242 242
40876 -253 253 253 253 253 253 253 253 253 253 253 253
40877 -253 253 253 253 253 253 253 253 253 253 253 253
40878 -253 253 253 253 253 253 253 253 253 253 253 253
40879 -253 253 253 253 253 253 253 253 253 224 178 62
40880 -242 186 14 241 196 14 210 166 10 22 18 6
40881 - 2 2 6 2 2 6 2 2 6 2 2 6
40882 - 2 2 6 2 2 6 6 6 6 121 92 8
40883 -238 202 15 232 195 16 82 82 82 34 34 34
40884 - 10 10 10 0 0 0 0 0 0 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 0 0 0
40888 - 0 0 0 0 0 0 0 0 0 0 0 0
40889 - 14 14 14 38 38 38 70 70 70 154 122 46
40890 -190 142 34 200 144 11 197 138 11 197 138 11
40891 -213 154 11 226 170 11 242 186 14 246 190 14
40892 -246 190 14 246 190 14 246 190 14 246 190 14
40893 -225 175 15 46 32 6 2 2 6 22 22 22
40894 -158 158 158 250 250 250 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 253 253 253 253 253 253 253 253 253
40898 -253 253 253 253 253 253 253 253 253 253 253 253
40899 -253 253 253 250 250 250 242 242 242 224 178 62
40900 -239 182 13 236 186 11 213 154 11 46 32 6
40901 - 2 2 6 2 2 6 2 2 6 2 2 6
40902 - 2 2 6 2 2 6 61 42 6 225 175 15
40903 -238 190 10 236 186 11 112 100 78 42 42 42
40904 - 14 14 14 0 0 0 0 0 0 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 0 0 0 0 0 0
40908 - 0 0 0 0 0 0 0 0 0 6 6 6
40909 - 22 22 22 54 54 54 154 122 46 213 154 11
40910 -226 170 11 230 174 11 226 170 11 226 170 11
40911 -236 178 12 242 186 14 246 190 14 246 190 14
40912 -246 190 14 246 190 14 246 190 14 246 190 14
40913 -241 196 14 184 144 12 10 10 10 2 2 6
40914 - 6 6 6 116 116 116 242 242 242 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 -253 253 253 253 253 253 253 253 253 253 253 253
40918 -253 253 253 253 253 253 253 253 253 253 253 253
40919 -253 253 253 231 231 231 198 198 198 214 170 54
40920 -236 178 12 236 178 12 210 150 10 137 92 6
40921 - 18 14 6 2 2 6 2 2 6 2 2 6
40922 - 6 6 6 70 47 6 200 144 11 236 178 12
40923 -239 182 13 239 182 13 124 112 88 58 58 58
40924 - 22 22 22 6 6 6 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 0 0 0 0 0 0
40928 - 0 0 0 0 0 0 0 0 0 10 10 10
40929 - 30 30 30 70 70 70 180 133 36 226 170 11
40930 -239 182 13 242 186 14 242 186 14 246 186 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 190 14 232 195 16 98 70 6 2 2 6
40934 - 2 2 6 2 2 6 66 66 66 221 221 221
40935 -253 253 253 253 253 253 253 253 253 253 253 253
40936 -253 253 253 253 253 253 253 253 253 253 253 253
40937 -253 253 253 253 253 253 253 253 253 253 253 253
40938 -253 253 253 253 253 253 253 253 253 253 253 253
40939 -253 253 253 206 206 206 198 198 198 214 166 58
40940 -230 174 11 230 174 11 216 158 10 192 133 9
40941 -163 110 8 116 81 8 102 78 10 116 81 8
40942 -167 114 7 197 138 11 226 170 11 239 182 13
40943 -242 186 14 242 186 14 162 146 94 78 78 78
40944 - 34 34 34 14 14 14 6 6 6 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 0 0 0 0 0 0
40948 - 0 0 0 0 0 0 0 0 0 6 6 6
40949 - 30 30 30 78 78 78 190 142 34 226 170 11
40950 -239 182 13 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 241 196 14 203 166 17 22 18 6
40954 - 2 2 6 2 2 6 2 2 6 38 38 38
40955 -218 218 218 253 253 253 253 253 253 253 253 253
40956 -253 253 253 253 253 253 253 253 253 253 253 253
40957 -253 253 253 253 253 253 253 253 253 253 253 253
40958 -253 253 253 253 253 253 253 253 253 253 253 253
40959 -250 250 250 206 206 206 198 198 198 202 162 69
40960 -226 170 11 236 178 12 224 166 10 210 150 10
40961 -200 144 11 197 138 11 192 133 9 197 138 11
40962 -210 150 10 226 170 11 242 186 14 246 190 14
40963 -246 190 14 246 186 14 225 175 15 124 112 88
40964 - 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
40968 - 0 0 0 0 0 0 0 0 0 10 10 10
40969 - 30 30 30 78 78 78 174 135 50 224 166 10
40970 -239 182 13 246 190 14 246 190 14 246 190 14
40971 -246 190 14 246 190 14 246 190 14 246 190 14
40972 -246 190 14 246 190 14 246 190 14 246 190 14
40973 -246 190 14 246 190 14 241 196 14 139 102 15
40974 - 2 2 6 2 2 6 2 2 6 2 2 6
40975 - 78 78 78 250 250 250 253 253 253 253 253 253
40976 -253 253 253 253 253 253 253 253 253 253 253 253
40977 -253 253 253 253 253 253 253 253 253 253 253 253
40978 -253 253 253 253 253 253 253 253 253 253 253 253
40979 -250 250 250 214 214 214 198 198 198 190 150 46
40980 -219 162 10 236 178 12 234 174 13 224 166 10
40981 -216 158 10 213 154 11 213 154 11 216 158 10
40982 -226 170 11 239 182 13 246 190 14 246 190 14
40983 -246 190 14 246 190 14 242 186 14 206 162 42
40984 -101 101 101 58 58 58 30 30 30 14 14 14
40985 - 6 6 6 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 0 0 0
40988 - 0 0 0 0 0 0 0 0 0 10 10 10
40989 - 30 30 30 74 74 74 174 135 50 216 158 10
40990 -236 178 12 246 190 14 246 190 14 246 190 14
40991 -246 190 14 246 190 14 246 190 14 246 190 14
40992 -246 190 14 246 190 14 246 190 14 246 190 14
40993 -246 190 14 246 190 14 241 196 14 226 184 13
40994 - 61 42 6 2 2 6 2 2 6 2 2 6
40995 - 22 22 22 238 238 238 253 253 253 253 253 253
40996 -253 253 253 253 253 253 253 253 253 253 253 253
40997 -253 253 253 253 253 253 253 253 253 253 253 253
40998 -253 253 253 253 253 253 253 253 253 253 253 253
40999 -253 253 253 226 226 226 187 187 187 180 133 36
41000 -216 158 10 236 178 12 239 182 13 236 178 12
41001 -230 174 11 226 170 11 226 170 11 230 174 11
41002 -236 178 12 242 186 14 246 190 14 246 190 14
41003 -246 190 14 246 190 14 246 186 14 239 182 13
41004 -206 162 42 106 106 106 66 66 66 34 34 34
41005 - 14 14 14 6 6 6 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 0 0 0
41008 - 0 0 0 0 0 0 0 0 0 6 6 6
41009 - 26 26 26 70 70 70 163 133 67 213 154 11
41010 -236 178 12 246 190 14 246 190 14 246 190 14
41011 -246 190 14 246 190 14 246 190 14 246 190 14
41012 -246 190 14 246 190 14 246 190 14 246 190 14
41013 -246 190 14 246 190 14 246 190 14 241 196 14
41014 -190 146 13 18 14 6 2 2 6 2 2 6
41015 - 46 46 46 246 246 246 253 253 253 253 253 253
41016 -253 253 253 253 253 253 253 253 253 253 253 253
41017 -253 253 253 253 253 253 253 253 253 253 253 253
41018 -253 253 253 253 253 253 253 253 253 253 253 253
41019 -253 253 253 221 221 221 86 86 86 156 107 11
41020 -216 158 10 236 178 12 242 186 14 246 186 14
41021 -242 186 14 239 182 13 239 182 13 242 186 14
41022 -242 186 14 246 186 14 246 190 14 246 190 14
41023 -246 190 14 246 190 14 246 190 14 246 190 14
41024 -242 186 14 225 175 15 142 122 72 66 66 66
41025 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 6 6 6
41029 - 26 26 26 70 70 70 163 133 67 210 150 10
41030 -236 178 12 246 190 14 246 190 14 246 190 14
41031 -246 190 14 246 190 14 246 190 14 246 190 14
41032 -246 190 14 246 190 14 246 190 14 246 190 14
41033 -246 190 14 246 190 14 246 190 14 246 190 14
41034 -232 195 16 121 92 8 34 34 34 106 106 106
41035 -221 221 221 253 253 253 253 253 253 253 253 253
41036 -253 253 253 253 253 253 253 253 253 253 253 253
41037 -253 253 253 253 253 253 253 253 253 253 253 253
41038 -253 253 253 253 253 253 253 253 253 253 253 253
41039 -242 242 242 82 82 82 18 14 6 163 110 8
41040 -216 158 10 236 178 12 242 186 14 246 190 14
41041 -246 190 14 246 190 14 246 190 14 246 190 14
41042 -246 190 14 246 190 14 246 190 14 246 190 14
41043 -246 190 14 246 190 14 246 190 14 246 190 14
41044 -246 190 14 246 190 14 242 186 14 163 133 67
41045 - 46 46 46 18 18 18 6 6 6 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 0 0 0 10 10 10
41049 - 30 30 30 78 78 78 163 133 67 210 150 10
41050 -236 178 12 246 186 14 246 190 14 246 190 14
41051 -246 190 14 246 190 14 246 190 14 246 190 14
41052 -246 190 14 246 190 14 246 190 14 246 190 14
41053 -246 190 14 246 190 14 246 190 14 246 190 14
41054 -241 196 14 215 174 15 190 178 144 253 253 253
41055 -253 253 253 253 253 253 253 253 253 253 253 253
41056 -253 253 253 253 253 253 253 253 253 253 253 253
41057 -253 253 253 253 253 253 253 253 253 253 253 253
41058 -253 253 253 253 253 253 253 253 253 218 218 218
41059 - 58 58 58 2 2 6 22 18 6 167 114 7
41060 -216 158 10 236 178 12 246 186 14 246 190 14
41061 -246 190 14 246 190 14 246 190 14 246 190 14
41062 -246 190 14 246 190 14 246 190 14 246 190 14
41063 -246 190 14 246 190 14 246 190 14 246 190 14
41064 -246 190 14 246 186 14 242 186 14 190 150 46
41065 - 54 54 54 22 22 22 6 6 6 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 14 14 14
41069 - 38 38 38 86 86 86 180 133 36 213 154 11
41070 -236 178 12 246 186 14 246 190 14 246 190 14
41071 -246 190 14 246 190 14 246 190 14 246 190 14
41072 -246 190 14 246 190 14 246 190 14 246 190 14
41073 -246 190 14 246 190 14 246 190 14 246 190 14
41074 -246 190 14 232 195 16 190 146 13 214 214 214
41075 -253 253 253 253 253 253 253 253 253 253 253 253
41076 -253 253 253 253 253 253 253 253 253 253 253 253
41077 -253 253 253 253 253 253 253 253 253 253 253 253
41078 -253 253 253 250 250 250 170 170 170 26 26 26
41079 - 2 2 6 2 2 6 37 26 9 163 110 8
41080 -219 162 10 239 182 13 246 186 14 246 190 14
41081 -246 190 14 246 190 14 246 190 14 246 190 14
41082 -246 190 14 246 190 14 246 190 14 246 190 14
41083 -246 190 14 246 190 14 246 190 14 246 190 14
41084 -246 186 14 236 178 12 224 166 10 142 122 72
41085 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
41089 - 50 50 50 109 106 95 192 133 9 224 166 10
41090 -242 186 14 246 190 14 246 190 14 246 190 14
41091 -246 190 14 246 190 14 246 190 14 246 190 14
41092 -246 190 14 246 190 14 246 190 14 246 190 14
41093 -246 190 14 246 190 14 246 190 14 246 190 14
41094 -242 186 14 226 184 13 210 162 10 142 110 46
41095 -226 226 226 253 253 253 253 253 253 253 253 253
41096 -253 253 253 253 253 253 253 253 253 253 253 253
41097 -253 253 253 253 253 253 253 253 253 253 253 253
41098 -198 198 198 66 66 66 2 2 6 2 2 6
41099 - 2 2 6 2 2 6 50 34 6 156 107 11
41100 -219 162 10 239 182 13 246 186 14 246 190 14
41101 -246 190 14 246 190 14 246 190 14 246 190 14
41102 -246 190 14 246 190 14 246 190 14 246 190 14
41103 -246 190 14 246 190 14 246 190 14 242 186 14
41104 -234 174 13 213 154 11 154 122 46 66 66 66
41105 - 30 30 30 10 10 10 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 6 6 6 22 22 22
41109 - 58 58 58 154 121 60 206 145 10 234 174 13
41110 -242 186 14 246 186 14 246 190 14 246 190 14
41111 -246 190 14 246 190 14 246 190 14 246 190 14
41112 -246 190 14 246 190 14 246 190 14 246 190 14
41113 -246 190 14 246 190 14 246 190 14 246 190 14
41114 -246 186 14 236 178 12 210 162 10 163 110 8
41115 - 61 42 6 138 138 138 218 218 218 250 250 250
41116 -253 253 253 253 253 253 253 253 253 250 250 250
41117 -242 242 242 210 210 210 144 144 144 66 66 66
41118 - 6 6 6 2 2 6 2 2 6 2 2 6
41119 - 2 2 6 2 2 6 61 42 6 163 110 8
41120 -216 158 10 236 178 12 246 190 14 246 190 14
41121 -246 190 14 246 190 14 246 190 14 246 190 14
41122 -246 190 14 246 190 14 246 190 14 246 190 14
41123 -246 190 14 239 182 13 230 174 11 216 158 10
41124 -190 142 34 124 112 88 70 70 70 38 38 38
41125 - 18 18 18 6 6 6 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 6 6 6 22 22 22
41129 - 62 62 62 168 124 44 206 145 10 224 166 10
41130 -236 178 12 239 182 13 242 186 14 242 186 14
41131 -246 186 14 246 190 14 246 190 14 246 190 14
41132 -246 190 14 246 190 14 246 190 14 246 190 14
41133 -246 190 14 246 190 14 246 190 14 246 190 14
41134 -246 190 14 236 178 12 216 158 10 175 118 6
41135 - 80 54 7 2 2 6 6 6 6 30 30 30
41136 - 54 54 54 62 62 62 50 50 50 38 38 38
41137 - 14 14 14 2 2 6 2 2 6 2 2 6
41138 - 2 2 6 2 2 6 2 2 6 2 2 6
41139 - 2 2 6 6 6 6 80 54 7 167 114 7
41140 -213 154 11 236 178 12 246 190 14 246 190 14
41141 -246 190 14 246 190 14 246 190 14 246 190 14
41142 -246 190 14 242 186 14 239 182 13 239 182 13
41143 -230 174 11 210 150 10 174 135 50 124 112 88
41144 - 82 82 82 54 54 54 34 34 34 18 18 18
41145 - 6 6 6 0 0 0 0 0 0 0 0 0
41146 - 0 0 0 0 0 0 0 0 0 0 0 0
41147 - 0 0 0 0 0 0 0 0 0 0 0 0
41148 - 0 0 0 0 0 0 6 6 6 18 18 18
41149 - 50 50 50 158 118 36 192 133 9 200 144 11
41150 -216 158 10 219 162 10 224 166 10 226 170 11
41151 -230 174 11 236 178 12 239 182 13 239 182 13
41152 -242 186 14 246 186 14 246 190 14 246 190 14
41153 -246 190 14 246 190 14 246 190 14 246 190 14
41154 -246 186 14 230 174 11 210 150 10 163 110 8
41155 -104 69 6 10 10 10 2 2 6 2 2 6
41156 - 2 2 6 2 2 6 2 2 6 2 2 6
41157 - 2 2 6 2 2 6 2 2 6 2 2 6
41158 - 2 2 6 2 2 6 2 2 6 2 2 6
41159 - 2 2 6 6 6 6 91 60 6 167 114 7
41160 -206 145 10 230 174 11 242 186 14 246 190 14
41161 -246 190 14 246 190 14 246 186 14 242 186 14
41162 -239 182 13 230 174 11 224 166 10 213 154 11
41163 -180 133 36 124 112 88 86 86 86 58 58 58
41164 - 38 38 38 22 22 22 10 10 10 6 6 6
41165 - 0 0 0 0 0 0 0 0 0 0 0 0
41166 - 0 0 0 0 0 0 0 0 0 0 0 0
41167 - 0 0 0 0 0 0 0 0 0 0 0 0
41168 - 0 0 0 0 0 0 0 0 0 14 14 14
41169 - 34 34 34 70 70 70 138 110 50 158 118 36
41170 -167 114 7 180 123 7 192 133 9 197 138 11
41171 -200 144 11 206 145 10 213 154 11 219 162 10
41172 -224 166 10 230 174 11 239 182 13 242 186 14
41173 -246 186 14 246 186 14 246 186 14 246 186 14
41174 -239 182 13 216 158 10 185 133 11 152 99 6
41175 -104 69 6 18 14 6 2 2 6 2 2 6
41176 - 2 2 6 2 2 6 2 2 6 2 2 6
41177 - 2 2 6 2 2 6 2 2 6 2 2 6
41178 - 2 2 6 2 2 6 2 2 6 2 2 6
41179 - 2 2 6 6 6 6 80 54 7 152 99 6
41180 -192 133 9 219 162 10 236 178 12 239 182 13
41181 -246 186 14 242 186 14 239 182 13 236 178 12
41182 -224 166 10 206 145 10 192 133 9 154 121 60
41183 - 94 94 94 62 62 62 42 42 42 22 22 22
41184 - 14 14 14 6 6 6 0 0 0 0 0 0
41185 - 0 0 0 0 0 0 0 0 0 0 0 0
41186 - 0 0 0 0 0 0 0 0 0 0 0 0
41187 - 0 0 0 0 0 0 0 0 0 0 0 0
41188 - 0 0 0 0 0 0 0 0 0 6 6 6
41189 - 18 18 18 34 34 34 58 58 58 78 78 78
41190 -101 98 89 124 112 88 142 110 46 156 107 11
41191 -163 110 8 167 114 7 175 118 6 180 123 7
41192 -185 133 11 197 138 11 210 150 10 219 162 10
41193 -226 170 11 236 178 12 236 178 12 234 174 13
41194 -219 162 10 197 138 11 163 110 8 130 83 6
41195 - 91 60 6 10 10 10 2 2 6 2 2 6
41196 - 18 18 18 38 38 38 38 38 38 38 38 38
41197 - 38 38 38 38 38 38 38 38 38 38 38 38
41198 - 38 38 38 38 38 38 26 26 26 2 2 6
41199 - 2 2 6 6 6 6 70 47 6 137 92 6
41200 -175 118 6 200 144 11 219 162 10 230 174 11
41201 -234 174 13 230 174 11 219 162 10 210 150 10
41202 -192 133 9 163 110 8 124 112 88 82 82 82
41203 - 50 50 50 30 30 30 14 14 14 6 6 6
41204 - 0 0 0 0 0 0 0 0 0 0 0 0
41205 - 0 0 0 0 0 0 0 0 0 0 0 0
41206 - 0 0 0 0 0 0 0 0 0 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 0 0 0 0 0 0 0 0 0
41209 - 6 6 6 14 14 14 22 22 22 34 34 34
41210 - 42 42 42 58 58 58 74 74 74 86 86 86
41211 -101 98 89 122 102 70 130 98 46 121 87 25
41212 -137 92 6 152 99 6 163 110 8 180 123 7
41213 -185 133 11 197 138 11 206 145 10 200 144 11
41214 -180 123 7 156 107 11 130 83 6 104 69 6
41215 - 50 34 6 54 54 54 110 110 110 101 98 89
41216 - 86 86 86 82 82 82 78 78 78 78 78 78
41217 - 78 78 78 78 78 78 78 78 78 78 78 78
41218 - 78 78 78 82 82 82 86 86 86 94 94 94
41219 -106 106 106 101 101 101 86 66 34 124 80 6
41220 -156 107 11 180 123 7 192 133 9 200 144 11
41221 -206 145 10 200 144 11 192 133 9 175 118 6
41222 -139 102 15 109 106 95 70 70 70 42 42 42
41223 - 22 22 22 10 10 10 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
41228 - 0 0 0 0 0 0 0 0 0 0 0 0
41229 - 0 0 0 0 0 0 6 6 6 10 10 10
41230 - 14 14 14 22 22 22 30 30 30 38 38 38
41231 - 50 50 50 62 62 62 74 74 74 90 90 90
41232 -101 98 89 112 100 78 121 87 25 124 80 6
41233 -137 92 6 152 99 6 152 99 6 152 99 6
41234 -138 86 6 124 80 6 98 70 6 86 66 30
41235 -101 98 89 82 82 82 58 58 58 46 46 46
41236 - 38 38 38 34 34 34 34 34 34 34 34 34
41237 - 34 34 34 34 34 34 34 34 34 34 34 34
41238 - 34 34 34 34 34 34 38 38 38 42 42 42
41239 - 54 54 54 82 82 82 94 86 76 91 60 6
41240 -134 86 6 156 107 11 167 114 7 175 118 6
41241 -175 118 6 167 114 7 152 99 6 121 87 25
41242 -101 98 89 62 62 62 34 34 34 18 18 18
41243 - 6 6 6 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 0 0 0 0 0 0 0 0 0 0 0 0
41249 - 0 0 0 0 0 0 0 0 0 0 0 0
41250 - 0 0 0 6 6 6 6 6 6 10 10 10
41251 - 18 18 18 22 22 22 30 30 30 42 42 42
41252 - 50 50 50 66 66 66 86 86 86 101 98 89
41253 -106 86 58 98 70 6 104 69 6 104 69 6
41254 -104 69 6 91 60 6 82 62 34 90 90 90
41255 - 62 62 62 38 38 38 22 22 22 14 14 14
41256 - 10 10 10 10 10 10 10 10 10 10 10 10
41257 - 10 10 10 10 10 10 6 6 6 10 10 10
41258 - 10 10 10 10 10 10 10 10 10 14 14 14
41259 - 22 22 22 42 42 42 70 70 70 89 81 66
41260 - 80 54 7 104 69 6 124 80 6 137 92 6
41261 -134 86 6 116 81 8 100 82 52 86 86 86
41262 - 58 58 58 30 30 30 14 14 14 6 6 6
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 0 0 0
41268 - 0 0 0 0 0 0 0 0 0 0 0 0
41269 - 0 0 0 0 0 0 0 0 0 0 0 0
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 6 6 6 10 10 10 14 14 14
41272 - 18 18 18 26 26 26 38 38 38 54 54 54
41273 - 70 70 70 86 86 86 94 86 76 89 81 66
41274 - 89 81 66 86 86 86 74 74 74 50 50 50
41275 - 30 30 30 14 14 14 6 6 6 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 6 6 6 18 18 18 34 34 34 58 58 58
41280 - 82 82 82 89 81 66 89 81 66 89 81 66
41281 - 94 86 66 94 86 76 74 74 74 50 50 50
41282 - 26 26 26 14 14 14 6 6 6 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 - 0 0 0 0 0 0 0 0 0 0 0 0
41288 - 0 0 0 0 0 0 0 0 0 0 0 0
41289 - 0 0 0 0 0 0 0 0 0 0 0 0
41290 - 0 0 0 0 0 0 0 0 0 0 0 0
41291 - 0 0 0 0 0 0 0 0 0 0 0 0
41292 - 6 6 6 6 6 6 14 14 14 18 18 18
41293 - 30 30 30 38 38 38 46 46 46 54 54 54
41294 - 50 50 50 42 42 42 30 30 30 18 18 18
41295 - 10 10 10 0 0 0 0 0 0 0 0 0
41296 - 0 0 0 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 0 0 0
41299 - 0 0 0 6 6 6 14 14 14 26 26 26
41300 - 38 38 38 50 50 50 58 58 58 58 58 58
41301 - 54 54 54 42 42 42 30 30 30 18 18 18
41302 - 10 10 10 0 0 0 0 0 0 0 0 0
41303 - 0 0 0 0 0 0 0 0 0 0 0 0
41304 - 0 0 0 0 0 0 0 0 0 0 0 0
41305 - 0 0 0 0 0 0 0 0 0 0 0 0
41306 - 0 0 0 0 0 0 0 0 0 0 0 0
41307 - 0 0 0 0 0 0 0 0 0 0 0 0
41308 - 0 0 0 0 0 0 0 0 0 0 0 0
41309 - 0 0 0 0 0 0 0 0 0 0 0 0
41310 - 0 0 0 0 0 0 0 0 0 0 0 0
41311 - 0 0 0 0 0 0 0 0 0 0 0 0
41312 - 0 0 0 0 0 0 0 0 0 6 6 6
41313 - 6 6 6 10 10 10 14 14 14 18 18 18
41314 - 18 18 18 14 14 14 10 10 10 6 6 6
41315 - 0 0 0 0 0 0 0 0 0 0 0 0
41316 - 0 0 0 0 0 0 0 0 0 0 0 0
41317 - 0 0 0 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 0 0 0 0 0 0
41319 - 0 0 0 0 0 0 0 0 0 6 6 6
41320 - 14 14 14 18 18 18 22 22 22 22 22 22
41321 - 18 18 18 14 14 14 10 10 10 6 6 6
41322 - 0 0 0 0 0 0 0 0 0 0 0 0
41323 - 0 0 0 0 0 0 0 0 0 0 0 0
41324 - 0 0 0 0 0 0 0 0 0 0 0 0
41325 - 0 0 0 0 0 0 0 0 0 0 0 0
41326 - 0 0 0 0 0 0 0 0 0 0 0 0
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410 +4 4 4 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41416 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41421 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424 +4 4 4 4 4 4
41425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41430 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41431 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41435 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41436 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41437 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438 +4 4 4 4 4 4
41439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41444 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41445 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41449 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41450 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41451 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41452 +4 4 4 4 4 4
41453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41457 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41458 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41459 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41462 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41463 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41464 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41465 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41466 +4 4 4 4 4 4
41467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41471 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41472 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41473 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41474 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41476 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41477 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41478 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41479 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41480 +4 4 4 4 4 4
41481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41484 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41485 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41486 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41487 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41488 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41489 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41490 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41491 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41492 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41493 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41494 +4 4 4 4 4 4
41495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41498 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41499 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41500 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41501 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41502 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41503 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41504 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41505 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41506 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41507 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41508 +4 4 4 4 4 4
41509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41512 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41513 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41514 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41515 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41516 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41517 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41518 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41519 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41520 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41521 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41522 +4 4 4 4 4 4
41523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41526 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41527 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41528 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41529 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41530 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41531 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41532 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41533 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41534 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41535 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41536 +4 4 4 4 4 4
41537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41539 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41540 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41541 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41542 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41543 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41544 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41545 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41546 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41547 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41548 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41549 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41550 +4 4 4 4 4 4
41551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41552 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41553 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41554 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41555 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41556 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41557 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41558 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41559 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41560 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41561 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41562 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41563 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41564 +4 4 4 4 4 4
41565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41566 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41567 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41568 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41569 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41570 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41571 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41572 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41573 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41574 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41575 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41576 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41577 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41578 +0 0 0 4 4 4
41579 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41580 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41581 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41582 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41583 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41584 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41585 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41586 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41587 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41588 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41589 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41590 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41591 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41592 +2 0 0 0 0 0
41593 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41594 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41595 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41596 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41597 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41598 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41599 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41600 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41601 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41602 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41603 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41604 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41605 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41606 +37 38 37 0 0 0
41607 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41608 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41609 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41610 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41611 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41612 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41613 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41614 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41615 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41616 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41617 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41618 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41619 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41620 +85 115 134 4 0 0
41621 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41622 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41623 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41624 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41625 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41626 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41627 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41628 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41629 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41630 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41631 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41632 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41633 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41634 +60 73 81 4 0 0
41635 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41636 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41637 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41638 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41639 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41640 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41641 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41642 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41643 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41644 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41645 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41646 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41647 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41648 +16 19 21 4 0 0
41649 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41650 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41651 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41652 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41653 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41654 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41655 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41656 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41657 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41658 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41659 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41660 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41661 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41662 +4 0 0 4 3 3
41663 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41664 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41665 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41667 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41668 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41669 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41670 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41671 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41672 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41673 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41674 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41675 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41676 +3 2 2 4 4 4
41677 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41678 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41679 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41680 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41681 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41682 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41683 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41684 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41685 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41686 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41687 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41688 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41689 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41690 +4 4 4 4 4 4
41691 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41692 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41693 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41694 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41695 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41696 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41697 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41698 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41699 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41700 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41701 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41702 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41703 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41704 +4 4 4 4 4 4
41705 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41706 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41707 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41708 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41709 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41710 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41711 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41712 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41713 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41714 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41715 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41716 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41717 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41718 +5 5 5 5 5 5
41719 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41720 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41721 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41722 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41723 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41724 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41725 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41726 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41727 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41728 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41729 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41730 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41731 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41732 +5 5 5 4 4 4
41733 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41734 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41735 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41736 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41737 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41738 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41739 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41740 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41741 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41742 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41743 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41744 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4
41747 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41748 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41749 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41750 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41751 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41752 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41753 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41754 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41755 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41756 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41757 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41758 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4
41761 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41762 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41763 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41764 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41765 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41766 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41767 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41768 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41769 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41770 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41771 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4
41775 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41776 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41777 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41778 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41779 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41780 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41781 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41782 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41783 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41784 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41785 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4
41789 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41790 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41791 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41792 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41793 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41794 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41795 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41796 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41797 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41798 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41799 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4
41803 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41804 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41805 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41806 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41807 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41808 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41809 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41810 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41811 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41812 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41813 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4
41817 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41818 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41819 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41820 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41821 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41822 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41823 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41824 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41825 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41826 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41827 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4
41831 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41832 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41833 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41834 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41835 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41836 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41837 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41838 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41839 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41840 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41841 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4
41845 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41846 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41847 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41848 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41849 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41850 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41851 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41852 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41853 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41854 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41855 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4
41859 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41860 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41861 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41862 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41863 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41864 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41865 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41866 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41867 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41868 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41869 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4
41873 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41874 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41875 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41876 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41877 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41878 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41879 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41880 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41881 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41882 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41883 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4
41887 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41888 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41889 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41890 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41891 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41892 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41893 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41894 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41895 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41896 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41897 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4
41901 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41902 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41903 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41904 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41905 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41906 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41907 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41908 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41909 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41910 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41911 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4
41915 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41916 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41917 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41918 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41919 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41920 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41921 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41922 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41923 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41924 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41925 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4
41929 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41930 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41931 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41932 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41933 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41934 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41935 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41936 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41937 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41938 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41939 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4
41943 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41944 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41945 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41946 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41947 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41948 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41949 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41950 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41951 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41952 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41953 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4
41957 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41958 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41959 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41960 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41961 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41962 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41963 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41964 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41965 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41966 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41967 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4
41971 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41972 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41973 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41974 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41975 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41976 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41977 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41978 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41979 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41980 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41981 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4
41985 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41986 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41987 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41988 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41989 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41990 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41991 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41992 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41993 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41994 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41995 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4
41999 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42000 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42001 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42002 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42003 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42004 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42005 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42006 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42007 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42008 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42009 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4
42013 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42014 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42015 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42016 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42017 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42018 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42019 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42020 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42021 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42022 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42023 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4
42027 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42028 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42029 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42030 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42031 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42032 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42033 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42034 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42035 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42036 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42037 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4
42041 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42042 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42043 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42044 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42045 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42046 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42047 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42048 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42049 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42050 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42051 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4
42055 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42056 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42057 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42058 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42059 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42060 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42061 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42062 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42063 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42064 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42065 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4
42069 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42070 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42071 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42072 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42073 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42074 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42075 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42076 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42077 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42078 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42079 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4
42083 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42084 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42085 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42086 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42087 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42088 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42089 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42090 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42091 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42092 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42093 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4
42097 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42098 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42099 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42100 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42101 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42102 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42103 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42104 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42105 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42106 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42107 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4
42111 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42112 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42113 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42114 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42115 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42116 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42117 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42119 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42120 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42121 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4
42125 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42126 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42127 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42128 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42129 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42130 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42131 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42132 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42133 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42134 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42135 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4
42139 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42140 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42141 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42142 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42143 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42144 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42145 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42146 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42147 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42148 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4
42153 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42154 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42155 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42156 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42157 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42158 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42159 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42160 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42161 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42162 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4
42167 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42168 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42169 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42170 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42171 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42172 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42173 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42174 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42175 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42176 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4
42181 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42182 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42183 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42184 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42185 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42186 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42187 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42188 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42189 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42190 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4
42195 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42196 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42197 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42198 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42199 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42200 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42201 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42202 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42203 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4
42209 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42210 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42211 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42212 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42213 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42214 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42215 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42216 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42217 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4
42223 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42224 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42225 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42226 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42227 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42228 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42229 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42230 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42231 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4
42237 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42238 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42239 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42240 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42241 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42242 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42243 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42244 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4
42251 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42252 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42253 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42254 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42255 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42256 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42257 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42258 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4
42265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42266 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42267 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42268 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42269 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42270 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42271 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42272 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278 +4 4 4 4 4 4
42279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42280 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42281 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42282 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42283 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42284 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42285 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42286 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292 +4 4 4 4 4 4
42293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42294 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42295 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42296 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42297 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42298 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42299 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42300 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306 +4 4 4 4 4 4
42307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42309 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42310 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42311 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42312 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42313 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42314 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 4 4
42321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42324 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42325 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42326 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42327 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334 +4 4 4 4 4 4
42335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42339 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42340 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42341 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +4 4 4 4 4 4
42349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42353 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42354 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42355 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362 +4 4 4 4 4 4
42363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42367 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42368 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42369 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376 +4 4 4 4 4 4
42377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42381 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42382 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42383 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42390 +4 4 4 4 4 4
42391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42395 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42396 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42397 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42404 +4 4 4 4 4 4
42405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42409 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42410 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42411 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42418 +4 4 4 4 4 4
42419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42423 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42424 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42432 +4 4 4 4 4 4
42433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42437 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42438 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42446 +4 4 4 4 4 4
42447 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42448 index 38fcfff..0072dcd 100644
42449 --- a/drivers/video/udlfb.c
42450 +++ b/drivers/video/udlfb.c
42451 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42452 dlfb_urb_completion(urb);
42453
42454 error:
42455 - atomic_add(bytes_sent, &dev->bytes_sent);
42456 - atomic_add(bytes_identical, &dev->bytes_identical);
42457 - atomic_add(width*height*2, &dev->bytes_rendered);
42458 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42459 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42460 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42461 end_cycles = get_cycles();
42462 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42463 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42464 >> 10)), /* Kcycles */
42465 &dev->cpu_kcycles_used);
42466
42467 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42468 dlfb_urb_completion(urb);
42469
42470 error:
42471 - atomic_add(bytes_sent, &dev->bytes_sent);
42472 - atomic_add(bytes_identical, &dev->bytes_identical);
42473 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42474 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42475 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42476 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42477 end_cycles = get_cycles();
42478 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42479 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42480 >> 10)), /* Kcycles */
42481 &dev->cpu_kcycles_used);
42482 }
42483 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42484 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42485 struct dlfb_data *dev = fb_info->par;
42486 return snprintf(buf, PAGE_SIZE, "%u\n",
42487 - atomic_read(&dev->bytes_rendered));
42488 + atomic_read_unchecked(&dev->bytes_rendered));
42489 }
42490
42491 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42492 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42493 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42494 struct dlfb_data *dev = fb_info->par;
42495 return snprintf(buf, PAGE_SIZE, "%u\n",
42496 - atomic_read(&dev->bytes_identical));
42497 + atomic_read_unchecked(&dev->bytes_identical));
42498 }
42499
42500 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42501 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42502 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42503 struct dlfb_data *dev = fb_info->par;
42504 return snprintf(buf, PAGE_SIZE, "%u\n",
42505 - atomic_read(&dev->bytes_sent));
42506 + atomic_read_unchecked(&dev->bytes_sent));
42507 }
42508
42509 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42510 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42511 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42512 struct dlfb_data *dev = fb_info->par;
42513 return snprintf(buf, PAGE_SIZE, "%u\n",
42514 - atomic_read(&dev->cpu_kcycles_used));
42515 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42516 }
42517
42518 static ssize_t edid_show(
42519 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42520 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42521 struct dlfb_data *dev = fb_info->par;
42522
42523 - atomic_set(&dev->bytes_rendered, 0);
42524 - atomic_set(&dev->bytes_identical, 0);
42525 - atomic_set(&dev->bytes_sent, 0);
42526 - atomic_set(&dev->cpu_kcycles_used, 0);
42527 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42528 + atomic_set_unchecked(&dev->bytes_identical, 0);
42529 + atomic_set_unchecked(&dev->bytes_sent, 0);
42530 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42531
42532 return count;
42533 }
42534 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42535 index b0e2a42..e2df3ad 100644
42536 --- a/drivers/video/uvesafb.c
42537 +++ b/drivers/video/uvesafb.c
42538 @@ -19,6 +19,7 @@
42539 #include <linux/io.h>
42540 #include <linux/mutex.h>
42541 #include <linux/slab.h>
42542 +#include <linux/moduleloader.h>
42543 #include <video/edid.h>
42544 #include <video/uvesafb.h>
42545 #ifdef CONFIG_X86
42546 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42547 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42548 par->pmi_setpal = par->ypan = 0;
42549 } else {
42550 +
42551 +#ifdef CONFIG_PAX_KERNEXEC
42552 +#ifdef CONFIG_MODULES
42553 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42554 +#endif
42555 + if (!par->pmi_code) {
42556 + par->pmi_setpal = par->ypan = 0;
42557 + return 0;
42558 + }
42559 +#endif
42560 +
42561 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42562 + task->t.regs.edi);
42563 +
42564 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42565 + pax_open_kernel();
42566 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42567 + pax_close_kernel();
42568 +
42569 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42570 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42571 +#else
42572 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42573 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42574 +#endif
42575 +
42576 printk(KERN_INFO "uvesafb: protected mode interface info at "
42577 "%04x:%04x\n",
42578 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42579 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42580 par->ypan = ypan;
42581
42582 if (par->pmi_setpal || par->ypan) {
42583 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42584 if (__supported_pte_mask & _PAGE_NX) {
42585 par->pmi_setpal = par->ypan = 0;
42586 printk(KERN_WARNING "uvesafb: NX protection is actively."
42587 "We have better not to use the PMI.\n");
42588 - } else {
42589 + } else
42590 +#endif
42591 uvesafb_vbe_getpmi(task, par);
42592 - }
42593 }
42594 #else
42595 /* The protected mode interface is not available on non-x86. */
42596 @@ -1836,6 +1860,11 @@ out:
42597 if (par->vbe_modes)
42598 kfree(par->vbe_modes);
42599
42600 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42601 + if (par->pmi_code)
42602 + module_free_exec(NULL, par->pmi_code);
42603 +#endif
42604 +
42605 framebuffer_release(info);
42606 return err;
42607 }
42608 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42609 kfree(par->vbe_state_orig);
42610 if (par->vbe_state_saved)
42611 kfree(par->vbe_state_saved);
42612 +
42613 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42614 + if (par->pmi_code)
42615 + module_free_exec(NULL, par->pmi_code);
42616 +#endif
42617 +
42618 }
42619
42620 framebuffer_release(info);
42621 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42622 index 501b340..86bd4cf 100644
42623 --- a/drivers/video/vesafb.c
42624 +++ b/drivers/video/vesafb.c
42625 @@ -9,6 +9,7 @@
42626 */
42627
42628 #include <linux/module.h>
42629 +#include <linux/moduleloader.h>
42630 #include <linux/kernel.h>
42631 #include <linux/errno.h>
42632 #include <linux/string.h>
42633 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42634 static int vram_total __initdata; /* Set total amount of memory */
42635 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42636 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42637 -static void (*pmi_start)(void) __read_mostly;
42638 -static void (*pmi_pal) (void) __read_mostly;
42639 +static void (*pmi_start)(void) __read_only;
42640 +static void (*pmi_pal) (void) __read_only;
42641 static int depth __read_mostly;
42642 static int vga_compat __read_mostly;
42643 /* --------------------------------------------------------------------- */
42644 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42645 unsigned int size_vmode;
42646 unsigned int size_remap;
42647 unsigned int size_total;
42648 + void *pmi_code = NULL;
42649
42650 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42651 return -ENODEV;
42652 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42653 size_remap = size_total;
42654 vesafb_fix.smem_len = size_remap;
42655
42656 -#ifndef __i386__
42657 - screen_info.vesapm_seg = 0;
42658 -#endif
42659 -
42660 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42661 printk(KERN_WARNING
42662 "vesafb: cannot reserve video memory at 0x%lx\n",
42663 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42664 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42665 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42666
42667 +#ifdef __i386__
42668 +
42669 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42670 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42671 + if (!pmi_code)
42672 +#elif !defined(CONFIG_PAX_KERNEXEC)
42673 + if (0)
42674 +#endif
42675 +
42676 +#endif
42677 + screen_info.vesapm_seg = 0;
42678 +
42679 if (screen_info.vesapm_seg) {
42680 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42681 - screen_info.vesapm_seg,screen_info.vesapm_off);
42682 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42683 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42684 }
42685
42686 if (screen_info.vesapm_seg < 0xc000)
42687 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42688
42689 if (ypan || pmi_setpal) {
42690 unsigned short *pmi_base;
42691 +
42692 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42693 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42694 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42695 +
42696 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42697 + pax_open_kernel();
42698 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42699 +#else
42700 + pmi_code = pmi_base;
42701 +#endif
42702 +
42703 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42704 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42705 +
42706 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42707 + pmi_start = ktva_ktla(pmi_start);
42708 + pmi_pal = ktva_ktla(pmi_pal);
42709 + pax_close_kernel();
42710 +#endif
42711 +
42712 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42713 if (pmi_base[3]) {
42714 printk(KERN_INFO "vesafb: pmi: ports = ");
42715 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42716 info->node, info->fix.id);
42717 return 0;
42718 err:
42719 +
42720 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42721 + module_free_exec(NULL, pmi_code);
42722 +#endif
42723 +
42724 if (info->screen_base)
42725 iounmap(info->screen_base);
42726 framebuffer_release(info);
42727 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42728 index 88714ae..16c2e11 100644
42729 --- a/drivers/video/via/via_clock.h
42730 +++ b/drivers/video/via/via_clock.h
42731 @@ -56,7 +56,7 @@ struct via_clock {
42732
42733 void (*set_engine_pll_state)(u8 state);
42734 void (*set_engine_pll)(struct via_pll_config config);
42735 -};
42736 +} __no_const;
42737
42738
42739 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42740 diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
42741 index c3b3f7f..abd47c7 100644
42742 --- a/drivers/virtio/virtio.c
42743 +++ b/drivers/virtio/virtio.c
42744 @@ -225,8 +225,10 @@ EXPORT_SYMBOL_GPL(register_virtio_device);
42745
42746 void unregister_virtio_device(struct virtio_device *dev)
42747 {
42748 + int index = dev->index; /* save for after device release */
42749 +
42750 device_unregister(&dev->dev);
42751 - ida_simple_remove(&virtio_index_ida, dev->index);
42752 + ida_simple_remove(&virtio_index_ida, index);
42753 }
42754 EXPORT_SYMBOL_GPL(unregister_virtio_device);
42755
42756 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42757 index 453db0c..604973e 100644
42758 --- a/drivers/virtio/virtio_mmio.c
42759 +++ b/drivers/virtio/virtio_mmio.c
42760 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42761
42762 resources[0].end = memparse(device, &str) - 1;
42763
42764 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42765 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42766 &base, &resources[1].start, &consumed,
42767 &vm_cmdline_id, &consumed);
42768
42769 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42770 index e56c934..fc22f4b 100644
42771 --- a/drivers/xen/xen-pciback/conf_space.h
42772 +++ b/drivers/xen/xen-pciback/conf_space.h
42773 @@ -44,15 +44,15 @@ struct config_field {
42774 struct {
42775 conf_dword_write write;
42776 conf_dword_read read;
42777 - } dw;
42778 + } __no_const dw;
42779 struct {
42780 conf_word_write write;
42781 conf_word_read read;
42782 - } w;
42783 + } __no_const w;
42784 struct {
42785 conf_byte_write write;
42786 conf_byte_read read;
42787 - } b;
42788 + } __no_const b;
42789 } u;
42790 struct list_head list;
42791 };
42792 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42793 index 89f7625..ac72702 100644
42794 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42795 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42796 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42797 goto out;
42798
42799 /* Can't write a xenbus message larger we can buffer */
42800 - if ((len + u->len) > sizeof(u->u.buffer)) {
42801 + if (len > sizeof(u->u.buffer) - u->len) {
42802 /* On error, dump existing buffer */
42803 u->len = 0;
42804 rc = -EINVAL;
42805 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42806 index fef20db..d28b1ab 100644
42807 --- a/drivers/xen/xenfs/xenstored.c
42808 +++ b/drivers/xen/xenfs/xenstored.c
42809 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42810 static int xsd_kva_open(struct inode *inode, struct file *file)
42811 {
42812 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42813 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42814 + NULL);
42815 +#else
42816 xen_store_interface);
42817 +#endif
42818 +
42819 if (!file->private_data)
42820 return -ENOMEM;
42821 return 0;
42822 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42823 index cbf9dbb..35c3af7 100644
42824 --- a/fs/9p/vfs_inode.c
42825 +++ b/fs/9p/vfs_inode.c
42826 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42827 void
42828 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42829 {
42830 - char *s = nd_get_link(nd);
42831 + const char *s = nd_get_link(nd);
42832
42833 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42834 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42835 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42836 index 0225742..1cd4732 100644
42837 --- a/fs/Kconfig.binfmt
42838 +++ b/fs/Kconfig.binfmt
42839 @@ -89,7 +89,7 @@ config HAVE_AOUT
42840
42841 config BINFMT_AOUT
42842 tristate "Kernel support for a.out and ECOFF binaries"
42843 - depends on HAVE_AOUT
42844 + depends on HAVE_AOUT && BROKEN
42845 ---help---
42846 A.out (Assembler.OUTput) is a set of formats for libraries and
42847 executables used in the earliest versions of UNIX. Linux used
42848 diff --git a/fs/aio.c b/fs/aio.c
42849 index 71f613c..9d01f1f 100644
42850 --- a/fs/aio.c
42851 +++ b/fs/aio.c
42852 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42853 size += sizeof(struct io_event) * nr_events;
42854 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42855
42856 - if (nr_pages < 0)
42857 + if (nr_pages <= 0)
42858 return -EINVAL;
42859
42860 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42861 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42862 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42863 {
42864 ssize_t ret;
42865 + struct iovec iovstack;
42866
42867 #ifdef CONFIG_COMPAT
42868 if (compat)
42869 ret = compat_rw_copy_check_uvector(type,
42870 (struct compat_iovec __user *)kiocb->ki_buf,
42871 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42872 + kiocb->ki_nbytes, 1, &iovstack,
42873 &kiocb->ki_iovec);
42874 else
42875 #endif
42876 ret = rw_copy_check_uvector(type,
42877 (struct iovec __user *)kiocb->ki_buf,
42878 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42879 + kiocb->ki_nbytes, 1, &iovstack,
42880 &kiocb->ki_iovec);
42881 if (ret < 0)
42882 goto out;
42883 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42884 if (ret < 0)
42885 goto out;
42886
42887 + if (kiocb->ki_iovec == &iovstack) {
42888 + kiocb->ki_inline_vec = iovstack;
42889 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42890 + }
42891 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42892 kiocb->ki_cur_seg = 0;
42893 /* ki_nbytes/left now reflect bytes instead of segs */
42894 diff --git a/fs/attr.c b/fs/attr.c
42895 index 29e38a1..2bc037b 100644
42896 --- a/fs/attr.c
42897 +++ b/fs/attr.c
42898 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42899 unsigned long limit;
42900
42901 limit = rlimit(RLIMIT_FSIZE);
42902 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42903 if (limit != RLIM_INFINITY && offset > limit)
42904 goto out_sig;
42905 if (offset > inode->i_sb->s_maxbytes)
42906 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42907 index da8876d..4456166 100644
42908 --- a/fs/autofs4/waitq.c
42909 +++ b/fs/autofs4/waitq.c
42910 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42911 {
42912 unsigned long sigpipe, flags;
42913 mm_segment_t fs;
42914 - const char *data = (const char *)addr;
42915 + const char __user *data = (const char __force_user *)addr;
42916 ssize_t wr = 0;
42917
42918 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42919 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42920 return 1;
42921 }
42922
42923 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42924 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42925 +#endif
42926 +
42927 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42928 enum autofs_notify notify)
42929 {
42930 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42931
42932 /* If this is a direct mount request create a dummy name */
42933 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42934 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42935 + /* this name does get written to userland via autofs4_write() */
42936 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42937 +#else
42938 qstr.len = sprintf(name, "%p", dentry);
42939 +#endif
42940 else {
42941 qstr.len = autofs4_getpath(sbi, dentry, &name);
42942 if (!qstr.len) {
42943 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42944 index cf7f3c6..f61080d 100644
42945 --- a/fs/befs/linuxvfs.c
42946 +++ b/fs/befs/linuxvfs.c
42947 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42948 {
42949 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42950 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42951 - char *link = nd_get_link(nd);
42952 + const char *link = nd_get_link(nd);
42953 if (!IS_ERR(link))
42954 kfree(link);
42955 }
42956 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42957 index d146e18..12d1bd1 100644
42958 --- a/fs/binfmt_aout.c
42959 +++ b/fs/binfmt_aout.c
42960 @@ -16,6 +16,7 @@
42961 #include <linux/string.h>
42962 #include <linux/fs.h>
42963 #include <linux/file.h>
42964 +#include <linux/security.h>
42965 #include <linux/stat.h>
42966 #include <linux/fcntl.h>
42967 #include <linux/ptrace.h>
42968 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42969 #endif
42970 # define START_STACK(u) ((void __user *)u.start_stack)
42971
42972 + memset(&dump, 0, sizeof(dump));
42973 +
42974 fs = get_fs();
42975 set_fs(KERNEL_DS);
42976 has_dumped = 1;
42977 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42978
42979 /* If the size of the dump file exceeds the rlimit, then see what would happen
42980 if we wrote the stack, but not the data area. */
42981 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42982 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42983 dump.u_dsize = 0;
42984
42985 /* Make sure we have enough room to write the stack and data areas. */
42986 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42987 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42988 dump.u_ssize = 0;
42989
42990 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42991 rlim = rlimit(RLIMIT_DATA);
42992 if (rlim >= RLIM_INFINITY)
42993 rlim = ~0;
42994 +
42995 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42996 if (ex.a_data + ex.a_bss > rlim)
42997 return -ENOMEM;
42998
42999 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43000
43001 install_exec_creds(bprm);
43002
43003 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43004 + current->mm->pax_flags = 0UL;
43005 +#endif
43006 +
43007 +#ifdef CONFIG_PAX_PAGEEXEC
43008 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43009 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43010 +
43011 +#ifdef CONFIG_PAX_EMUTRAMP
43012 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43013 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43014 +#endif
43015 +
43016 +#ifdef CONFIG_PAX_MPROTECT
43017 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43018 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43019 +#endif
43020 +
43021 + }
43022 +#endif
43023 +
43024 if (N_MAGIC(ex) == OMAGIC) {
43025 unsigned long text_addr, map_size;
43026 loff_t pos;
43027 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43028 }
43029
43030 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43031 - PROT_READ | PROT_WRITE | PROT_EXEC,
43032 + PROT_READ | PROT_WRITE,
43033 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43034 fd_offset + ex.a_text);
43035 if (error != N_DATADDR(ex)) {
43036 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43037 index 0225fdd..0c0d35d 100644
43038 --- a/fs/binfmt_elf.c
43039 +++ b/fs/binfmt_elf.c
43040 @@ -32,6 +32,7 @@
43041 #include <linux/elf.h>
43042 #include <linux/utsname.h>
43043 #include <linux/coredump.h>
43044 +#include <linux/xattr.h>
43045 #include <asm/uaccess.h>
43046 #include <asm/param.h>
43047 #include <asm/page.h>
43048 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43049 #define elf_core_dump NULL
43050 #endif
43051
43052 +#ifdef CONFIG_PAX_MPROTECT
43053 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43054 +#endif
43055 +
43056 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43057 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43058 #else
43059 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43060 .load_binary = load_elf_binary,
43061 .load_shlib = load_elf_library,
43062 .core_dump = elf_core_dump,
43063 +
43064 +#ifdef CONFIG_PAX_MPROTECT
43065 + .handle_mprotect= elf_handle_mprotect,
43066 +#endif
43067 +
43068 .min_coredump = ELF_EXEC_PAGESIZE,
43069 };
43070
43071 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43072
43073 static int set_brk(unsigned long start, unsigned long end)
43074 {
43075 + unsigned long e = end;
43076 +
43077 start = ELF_PAGEALIGN(start);
43078 end = ELF_PAGEALIGN(end);
43079 if (end > start) {
43080 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43081 if (BAD_ADDR(addr))
43082 return addr;
43083 }
43084 - current->mm->start_brk = current->mm->brk = end;
43085 + current->mm->start_brk = current->mm->brk = e;
43086 return 0;
43087 }
43088
43089 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43090 elf_addr_t __user *u_rand_bytes;
43091 const char *k_platform = ELF_PLATFORM;
43092 const char *k_base_platform = ELF_BASE_PLATFORM;
43093 - unsigned char k_rand_bytes[16];
43094 + u32 k_rand_bytes[4];
43095 int items;
43096 elf_addr_t *elf_info;
43097 int ei_index = 0;
43098 const struct cred *cred = current_cred();
43099 struct vm_area_struct *vma;
43100 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43101
43102 /*
43103 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43104 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43105 * Generate 16 random bytes for userspace PRNG seeding.
43106 */
43107 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43108 - u_rand_bytes = (elf_addr_t __user *)
43109 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43110 + srandom32(k_rand_bytes[0] ^ random32());
43111 + srandom32(k_rand_bytes[1] ^ random32());
43112 + srandom32(k_rand_bytes[2] ^ random32());
43113 + srandom32(k_rand_bytes[3] ^ random32());
43114 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43115 + u_rand_bytes = (elf_addr_t __user *) p;
43116 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43117 return -EFAULT;
43118
43119 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43120 return -EFAULT;
43121 current->mm->env_end = p;
43122
43123 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43124 +
43125 /* Put the elf_info on the stack in the right place. */
43126 sp = (elf_addr_t __user *)envp + 1;
43127 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43128 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43129 return -EFAULT;
43130 return 0;
43131 }
43132 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43133 an ELF header */
43134
43135 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43136 - struct file *interpreter, unsigned long *interp_map_addr,
43137 - unsigned long no_base)
43138 + struct file *interpreter, unsigned long no_base)
43139 {
43140 struct elf_phdr *elf_phdata;
43141 struct elf_phdr *eppnt;
43142 - unsigned long load_addr = 0;
43143 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43144 int load_addr_set = 0;
43145 unsigned long last_bss = 0, elf_bss = 0;
43146 - unsigned long error = ~0UL;
43147 + unsigned long error = -EINVAL;
43148 unsigned long total_size;
43149 int retval, i, size;
43150
43151 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43152 goto out_close;
43153 }
43154
43155 +#ifdef CONFIG_PAX_SEGMEXEC
43156 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43157 + pax_task_size = SEGMEXEC_TASK_SIZE;
43158 +#endif
43159 +
43160 eppnt = elf_phdata;
43161 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43162 if (eppnt->p_type == PT_LOAD) {
43163 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43164 map_addr = elf_map(interpreter, load_addr + vaddr,
43165 eppnt, elf_prot, elf_type, total_size);
43166 total_size = 0;
43167 - if (!*interp_map_addr)
43168 - *interp_map_addr = map_addr;
43169 error = map_addr;
43170 if (BAD_ADDR(map_addr))
43171 goto out_close;
43172 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43173 k = load_addr + eppnt->p_vaddr;
43174 if (BAD_ADDR(k) ||
43175 eppnt->p_filesz > eppnt->p_memsz ||
43176 - eppnt->p_memsz > TASK_SIZE ||
43177 - TASK_SIZE - eppnt->p_memsz < k) {
43178 + eppnt->p_memsz > pax_task_size ||
43179 + pax_task_size - eppnt->p_memsz < k) {
43180 error = -ENOMEM;
43181 goto out_close;
43182 }
43183 @@ -523,6 +544,315 @@ out:
43184 return error;
43185 }
43186
43187 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43188 +#ifdef CONFIG_PAX_SOFTMODE
43189 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43190 +{
43191 + unsigned long pax_flags = 0UL;
43192 +
43193 +#ifdef CONFIG_PAX_PAGEEXEC
43194 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43195 + pax_flags |= MF_PAX_PAGEEXEC;
43196 +#endif
43197 +
43198 +#ifdef CONFIG_PAX_SEGMEXEC
43199 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43200 + pax_flags |= MF_PAX_SEGMEXEC;
43201 +#endif
43202 +
43203 +#ifdef CONFIG_PAX_EMUTRAMP
43204 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43205 + pax_flags |= MF_PAX_EMUTRAMP;
43206 +#endif
43207 +
43208 +#ifdef CONFIG_PAX_MPROTECT
43209 + if (elf_phdata->p_flags & PF_MPROTECT)
43210 + pax_flags |= MF_PAX_MPROTECT;
43211 +#endif
43212 +
43213 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43214 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43215 + pax_flags |= MF_PAX_RANDMMAP;
43216 +#endif
43217 +
43218 + return pax_flags;
43219 +}
43220 +#endif
43221 +
43222 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43223 +{
43224 + unsigned long pax_flags = 0UL;
43225 +
43226 +#ifdef CONFIG_PAX_PAGEEXEC
43227 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43228 + pax_flags |= MF_PAX_PAGEEXEC;
43229 +#endif
43230 +
43231 +#ifdef CONFIG_PAX_SEGMEXEC
43232 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43233 + pax_flags |= MF_PAX_SEGMEXEC;
43234 +#endif
43235 +
43236 +#ifdef CONFIG_PAX_EMUTRAMP
43237 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43238 + pax_flags |= MF_PAX_EMUTRAMP;
43239 +#endif
43240 +
43241 +#ifdef CONFIG_PAX_MPROTECT
43242 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43243 + pax_flags |= MF_PAX_MPROTECT;
43244 +#endif
43245 +
43246 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43247 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43248 + pax_flags |= MF_PAX_RANDMMAP;
43249 +#endif
43250 +
43251 + return pax_flags;
43252 +}
43253 +#endif
43254 +
43255 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43256 +#ifdef CONFIG_PAX_SOFTMODE
43257 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43258 +{
43259 + unsigned long pax_flags = 0UL;
43260 +
43261 +#ifdef CONFIG_PAX_PAGEEXEC
43262 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43263 + pax_flags |= MF_PAX_PAGEEXEC;
43264 +#endif
43265 +
43266 +#ifdef CONFIG_PAX_SEGMEXEC
43267 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43268 + pax_flags |= MF_PAX_SEGMEXEC;
43269 +#endif
43270 +
43271 +#ifdef CONFIG_PAX_EMUTRAMP
43272 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43273 + pax_flags |= MF_PAX_EMUTRAMP;
43274 +#endif
43275 +
43276 +#ifdef CONFIG_PAX_MPROTECT
43277 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43278 + pax_flags |= MF_PAX_MPROTECT;
43279 +#endif
43280 +
43281 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43282 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43283 + pax_flags |= MF_PAX_RANDMMAP;
43284 +#endif
43285 +
43286 + return pax_flags;
43287 +}
43288 +#endif
43289 +
43290 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43291 +{
43292 + unsigned long pax_flags = 0UL;
43293 +
43294 +#ifdef CONFIG_PAX_PAGEEXEC
43295 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43296 + pax_flags |= MF_PAX_PAGEEXEC;
43297 +#endif
43298 +
43299 +#ifdef CONFIG_PAX_SEGMEXEC
43300 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43301 + pax_flags |= MF_PAX_SEGMEXEC;
43302 +#endif
43303 +
43304 +#ifdef CONFIG_PAX_EMUTRAMP
43305 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43306 + pax_flags |= MF_PAX_EMUTRAMP;
43307 +#endif
43308 +
43309 +#ifdef CONFIG_PAX_MPROTECT
43310 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43311 + pax_flags |= MF_PAX_MPROTECT;
43312 +#endif
43313 +
43314 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43315 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43316 + pax_flags |= MF_PAX_RANDMMAP;
43317 +#endif
43318 +
43319 + return pax_flags;
43320 +}
43321 +#endif
43322 +
43323 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43324 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43325 +{
43326 + unsigned long pax_flags = 0UL;
43327 +
43328 +#ifdef CONFIG_PAX_EI_PAX
43329 +
43330 +#ifdef CONFIG_PAX_PAGEEXEC
43331 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43332 + pax_flags |= MF_PAX_PAGEEXEC;
43333 +#endif
43334 +
43335 +#ifdef CONFIG_PAX_SEGMEXEC
43336 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43337 + pax_flags |= MF_PAX_SEGMEXEC;
43338 +#endif
43339 +
43340 +#ifdef CONFIG_PAX_EMUTRAMP
43341 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43342 + pax_flags |= MF_PAX_EMUTRAMP;
43343 +#endif
43344 +
43345 +#ifdef CONFIG_PAX_MPROTECT
43346 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43347 + pax_flags |= MF_PAX_MPROTECT;
43348 +#endif
43349 +
43350 +#ifdef CONFIG_PAX_ASLR
43351 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43352 + pax_flags |= MF_PAX_RANDMMAP;
43353 +#endif
43354 +
43355 +#else
43356 +
43357 +#ifdef CONFIG_PAX_PAGEEXEC
43358 + pax_flags |= MF_PAX_PAGEEXEC;
43359 +#endif
43360 +
43361 +#ifdef CONFIG_PAX_SEGMEXEC
43362 + pax_flags |= MF_PAX_SEGMEXEC;
43363 +#endif
43364 +
43365 +#ifdef CONFIG_PAX_MPROTECT
43366 + pax_flags |= MF_PAX_MPROTECT;
43367 +#endif
43368 +
43369 +#ifdef CONFIG_PAX_RANDMMAP
43370 + if (randomize_va_space)
43371 + pax_flags |= MF_PAX_RANDMMAP;
43372 +#endif
43373 +
43374 +#endif
43375 +
43376 + return pax_flags;
43377 +}
43378 +
43379 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43380 +{
43381 +
43382 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43383 + unsigned long i;
43384 +
43385 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43386 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43387 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43388 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43389 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43390 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43391 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43392 + return ~0UL;
43393 +
43394 +#ifdef CONFIG_PAX_SOFTMODE
43395 + if (pax_softmode)
43396 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43397 + else
43398 +#endif
43399 +
43400 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43401 + break;
43402 + }
43403 +#endif
43404 +
43405 + return ~0UL;
43406 +}
43407 +
43408 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43409 +{
43410 +
43411 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43412 + ssize_t xattr_size, i;
43413 + unsigned char xattr_value[5];
43414 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43415 +
43416 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43417 + if (xattr_size <= 0 || xattr_size > 5)
43418 + return ~0UL;
43419 +
43420 + for (i = 0; i < xattr_size; i++)
43421 + switch (xattr_value[i]) {
43422 + default:
43423 + return ~0UL;
43424 +
43425 +#define parse_flag(option1, option2, flag) \
43426 + case option1: \
43427 + if (pax_flags_hardmode & MF_PAX_##flag) \
43428 + return ~0UL; \
43429 + pax_flags_hardmode |= MF_PAX_##flag; \
43430 + break; \
43431 + case option2: \
43432 + if (pax_flags_softmode & MF_PAX_##flag) \
43433 + return ~0UL; \
43434 + pax_flags_softmode |= MF_PAX_##flag; \
43435 + break;
43436 +
43437 + parse_flag('p', 'P', PAGEEXEC);
43438 + parse_flag('e', 'E', EMUTRAMP);
43439 + parse_flag('m', 'M', MPROTECT);
43440 + parse_flag('r', 'R', RANDMMAP);
43441 + parse_flag('s', 'S', SEGMEXEC);
43442 +
43443 +#undef parse_flag
43444 + }
43445 +
43446 + if (pax_flags_hardmode & pax_flags_softmode)
43447 + return ~0UL;
43448 +
43449 +#ifdef CONFIG_PAX_SOFTMODE
43450 + if (pax_softmode)
43451 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43452 + else
43453 +#endif
43454 +
43455 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43456 +#else
43457 + return ~0UL;
43458 +#endif
43459 +
43460 +}
43461 +
43462 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43463 +{
43464 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43465 +
43466 + pax_flags = pax_parse_ei_pax(elf_ex);
43467 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43468 + xattr_pax_flags = pax_parse_xattr_pax(file);
43469 +
43470 + if (pt_pax_flags == ~0UL)
43471 + pt_pax_flags = xattr_pax_flags;
43472 + else if (xattr_pax_flags == ~0UL)
43473 + xattr_pax_flags = pt_pax_flags;
43474 + if (pt_pax_flags != xattr_pax_flags)
43475 + return -EINVAL;
43476 + if (pt_pax_flags != ~0UL)
43477 + pax_flags = pt_pax_flags;
43478 +
43479 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43480 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43481 + if ((__supported_pte_mask & _PAGE_NX))
43482 + pax_flags &= ~MF_PAX_SEGMEXEC;
43483 + else
43484 + pax_flags &= ~MF_PAX_PAGEEXEC;
43485 + }
43486 +#endif
43487 +
43488 + if (0 > pax_check_flags(&pax_flags))
43489 + return -EINVAL;
43490 +
43491 + current->mm->pax_flags = pax_flags;
43492 + return 0;
43493 +}
43494 +#endif
43495 +
43496 /*
43497 * These are the functions used to load ELF style executables and shared
43498 * libraries. There is no binary dependent code anywhere else.
43499 @@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43500 {
43501 unsigned int random_variable = 0;
43502
43503 +#ifdef CONFIG_PAX_RANDUSTACK
43504 + if (randomize_va_space)
43505 + return stack_top - current->mm->delta_stack;
43506 +#endif
43507 +
43508 if ((current->flags & PF_RANDOMIZE) &&
43509 !(current->personality & ADDR_NO_RANDOMIZE)) {
43510 random_variable = get_random_int() & STACK_RND_MASK;
43511 @@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43512 unsigned long load_addr = 0, load_bias = 0;
43513 int load_addr_set = 0;
43514 char * elf_interpreter = NULL;
43515 - unsigned long error;
43516 + unsigned long error = 0;
43517 struct elf_phdr *elf_ppnt, *elf_phdata;
43518 unsigned long elf_bss, elf_brk;
43519 int retval, i;
43520 @@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43521 unsigned long start_code, end_code, start_data, end_data;
43522 unsigned long reloc_func_desc __maybe_unused = 0;
43523 int executable_stack = EXSTACK_DEFAULT;
43524 - unsigned long def_flags = 0;
43525 struct {
43526 struct elfhdr elf_ex;
43527 struct elfhdr interp_elf_ex;
43528 } *loc;
43529 + unsigned long pax_task_size = TASK_SIZE;
43530
43531 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43532 if (!loc) {
43533 @@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43534 goto out_free_dentry;
43535
43536 /* OK, This is the point of no return */
43537 - current->mm->def_flags = def_flags;
43538 +
43539 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43540 + current->mm->pax_flags = 0UL;
43541 +#endif
43542 +
43543 +#ifdef CONFIG_PAX_DLRESOLVE
43544 + current->mm->call_dl_resolve = 0UL;
43545 +#endif
43546 +
43547 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43548 + current->mm->call_syscall = 0UL;
43549 +#endif
43550 +
43551 +#ifdef CONFIG_PAX_ASLR
43552 + current->mm->delta_mmap = 0UL;
43553 + current->mm->delta_stack = 0UL;
43554 +#endif
43555 +
43556 + current->mm->def_flags = 0;
43557 +
43558 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43559 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43560 + send_sig(SIGKILL, current, 0);
43561 + goto out_free_dentry;
43562 + }
43563 +#endif
43564 +
43565 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43566 + pax_set_initial_flags(bprm);
43567 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43568 + if (pax_set_initial_flags_func)
43569 + (pax_set_initial_flags_func)(bprm);
43570 +#endif
43571 +
43572 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43573 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43574 + current->mm->context.user_cs_limit = PAGE_SIZE;
43575 + current->mm->def_flags |= VM_PAGEEXEC;
43576 + }
43577 +#endif
43578 +
43579 +#ifdef CONFIG_PAX_SEGMEXEC
43580 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43581 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43582 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43583 + pax_task_size = SEGMEXEC_TASK_SIZE;
43584 + current->mm->def_flags |= VM_NOHUGEPAGE;
43585 + }
43586 +#endif
43587 +
43588 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43589 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43590 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43591 + put_cpu();
43592 + }
43593 +#endif
43594
43595 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43596 may depend on the personality. */
43597 SET_PERSONALITY(loc->elf_ex);
43598 +
43599 +#ifdef CONFIG_PAX_ASLR
43600 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43601 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43602 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43603 + }
43604 +#endif
43605 +
43606 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43607 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43608 + executable_stack = EXSTACK_DISABLE_X;
43609 + current->personality &= ~READ_IMPLIES_EXEC;
43610 + } else
43611 +#endif
43612 +
43613 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43614 current->personality |= READ_IMPLIES_EXEC;
43615
43616 @@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43617 #else
43618 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43619 #endif
43620 +
43621 +#ifdef CONFIG_PAX_RANDMMAP
43622 + /* PaX: randomize base address at the default exe base if requested */
43623 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43624 +#ifdef CONFIG_SPARC64
43625 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43626 +#else
43627 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43628 +#endif
43629 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43630 + elf_flags |= MAP_FIXED;
43631 + }
43632 +#endif
43633 +
43634 }
43635
43636 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43637 @@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43638 * allowed task size. Note that p_filesz must always be
43639 * <= p_memsz so it is only necessary to check p_memsz.
43640 */
43641 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43642 - elf_ppnt->p_memsz > TASK_SIZE ||
43643 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43644 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43645 + elf_ppnt->p_memsz > pax_task_size ||
43646 + pax_task_size - elf_ppnt->p_memsz < k) {
43647 /* set_brk can never work. Avoid overflows. */
43648 send_sig(SIGKILL, current, 0);
43649 retval = -EINVAL;
43650 @@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43651 goto out_free_dentry;
43652 }
43653 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43654 - send_sig(SIGSEGV, current, 0);
43655 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43656 - goto out_free_dentry;
43657 + /*
43658 + * This bss-zeroing can fail if the ELF
43659 + * file specifies odd protections. So
43660 + * we don't check the return value
43661 + */
43662 }
43663
43664 +#ifdef CONFIG_PAX_RANDMMAP
43665 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43666 + unsigned long start, size;
43667 +
43668 + start = ELF_PAGEALIGN(elf_brk);
43669 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43670 + down_read(&current->mm->mmap_sem);
43671 + retval = -ENOMEM;
43672 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43673 + unsigned long prot = PROT_NONE;
43674 +
43675 + up_read(&current->mm->mmap_sem);
43676 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43677 +// if (current->personality & ADDR_NO_RANDOMIZE)
43678 +// prot = PROT_READ;
43679 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43680 + retval = IS_ERR_VALUE(start) ? start : 0;
43681 + } else
43682 + up_read(&current->mm->mmap_sem);
43683 + if (retval == 0)
43684 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43685 + if (retval < 0) {
43686 + send_sig(SIGKILL, current, 0);
43687 + goto out_free_dentry;
43688 + }
43689 + }
43690 +#endif
43691 +
43692 if (elf_interpreter) {
43693 - unsigned long uninitialized_var(interp_map_addr);
43694 -
43695 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43696 interpreter,
43697 - &interp_map_addr,
43698 load_bias);
43699 if (!IS_ERR((void *)elf_entry)) {
43700 /*
43701 @@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43702 * Decide what to dump of a segment, part, all or none.
43703 */
43704 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43705 - unsigned long mm_flags)
43706 + unsigned long mm_flags, long signr)
43707 {
43708 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43709
43710 @@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43711 if (vma->vm_file == NULL)
43712 return 0;
43713
43714 - if (FILTER(MAPPED_PRIVATE))
43715 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43716 goto whole;
43717
43718 /*
43719 @@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43720 {
43721 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43722 int i = 0;
43723 - do
43724 + do {
43725 i += 2;
43726 - while (auxv[i - 2] != AT_NULL);
43727 + } while (auxv[i - 2] != AT_NULL);
43728 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43729 }
43730
43731 @@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43732 }
43733
43734 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43735 - unsigned long mm_flags)
43736 + struct coredump_params *cprm)
43737 {
43738 struct vm_area_struct *vma;
43739 size_t size = 0;
43740
43741 for (vma = first_vma(current, gate_vma); vma != NULL;
43742 vma = next_vma(vma, gate_vma))
43743 - size += vma_dump_size(vma, mm_flags);
43744 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43745 return size;
43746 }
43747
43748 @@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43749
43750 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43751
43752 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43753 + offset += elf_core_vma_data_size(gate_vma, cprm);
43754 offset += elf_core_extra_data_size();
43755 e_shoff = offset;
43756
43757 @@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43758 offset = dataoff;
43759
43760 size += sizeof(*elf);
43761 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43762 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43763 goto end_coredump;
43764
43765 size += sizeof(*phdr4note);
43766 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43767 if (size > cprm->limit
43768 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43769 goto end_coredump;
43770 @@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43771 phdr.p_offset = offset;
43772 phdr.p_vaddr = vma->vm_start;
43773 phdr.p_paddr = 0;
43774 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43775 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43776 phdr.p_memsz = vma->vm_end - vma->vm_start;
43777 offset += phdr.p_filesz;
43778 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43779 @@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43780 phdr.p_align = ELF_EXEC_PAGESIZE;
43781
43782 size += sizeof(phdr);
43783 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43784 if (size > cprm->limit
43785 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43786 goto end_coredump;
43787 @@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43788 unsigned long addr;
43789 unsigned long end;
43790
43791 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43792 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43793
43794 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43795 struct page *page;
43796 @@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43797 page = get_dump_page(addr);
43798 if (page) {
43799 void *kaddr = kmap(page);
43800 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43801 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43802 !dump_write(cprm->file, kaddr,
43803 PAGE_SIZE);
43804 @@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43805
43806 if (e_phnum == PN_XNUM) {
43807 size += sizeof(*shdr4extnum);
43808 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43809 if (size > cprm->limit
43810 || !dump_write(cprm->file, shdr4extnum,
43811 sizeof(*shdr4extnum)))
43812 @@ -2092,6 +2543,97 @@ out:
43813
43814 #endif /* CONFIG_ELF_CORE */
43815
43816 +#ifdef CONFIG_PAX_MPROTECT
43817 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43818 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43819 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43820 + *
43821 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43822 + * basis because we want to allow the common case and not the special ones.
43823 + */
43824 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43825 +{
43826 + struct elfhdr elf_h;
43827 + struct elf_phdr elf_p;
43828 + unsigned long i;
43829 + unsigned long oldflags;
43830 + bool is_textrel_rw, is_textrel_rx, is_relro;
43831 +
43832 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43833 + return;
43834 +
43835 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43836 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43837 +
43838 +#ifdef CONFIG_PAX_ELFRELOCS
43839 + /* possible TEXTREL */
43840 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43841 + 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);
43842 +#else
43843 + is_textrel_rw = false;
43844 + is_textrel_rx = false;
43845 +#endif
43846 +
43847 + /* possible RELRO */
43848 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43849 +
43850 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43851 + return;
43852 +
43853 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43854 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43855 +
43856 +#ifdef CONFIG_PAX_ETEXECRELOCS
43857 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43858 +#else
43859 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43860 +#endif
43861 +
43862 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43863 + !elf_check_arch(&elf_h) ||
43864 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43865 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43866 + return;
43867 +
43868 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43869 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43870 + return;
43871 + switch (elf_p.p_type) {
43872 + case PT_DYNAMIC:
43873 + if (!is_textrel_rw && !is_textrel_rx)
43874 + continue;
43875 + i = 0UL;
43876 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43877 + elf_dyn dyn;
43878 +
43879 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43880 + return;
43881 + if (dyn.d_tag == DT_NULL)
43882 + return;
43883 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43884 + gr_log_textrel(vma);
43885 + if (is_textrel_rw)
43886 + vma->vm_flags |= VM_MAYWRITE;
43887 + else
43888 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43889 + vma->vm_flags &= ~VM_MAYWRITE;
43890 + return;
43891 + }
43892 + i++;
43893 + }
43894 + return;
43895 +
43896 + case PT_GNU_RELRO:
43897 + if (!is_relro)
43898 + continue;
43899 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43900 + vma->vm_flags &= ~VM_MAYWRITE;
43901 + return;
43902 + }
43903 + }
43904 +}
43905 +#endif
43906 +
43907 static int __init init_elf_binfmt(void)
43908 {
43909 register_binfmt(&elf_format);
43910 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43911 index 178cb70..8972997 100644
43912 --- a/fs/binfmt_flat.c
43913 +++ b/fs/binfmt_flat.c
43914 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43915 realdatastart = (unsigned long) -ENOMEM;
43916 printk("Unable to allocate RAM for process data, errno %d\n",
43917 (int)-realdatastart);
43918 + down_write(&current->mm->mmap_sem);
43919 vm_munmap(textpos, text_len);
43920 + up_write(&current->mm->mmap_sem);
43921 ret = realdatastart;
43922 goto err;
43923 }
43924 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43925 }
43926 if (IS_ERR_VALUE(result)) {
43927 printk("Unable to read data+bss, errno %d\n", (int)-result);
43928 + down_write(&current->mm->mmap_sem);
43929 vm_munmap(textpos, text_len);
43930 vm_munmap(realdatastart, len);
43931 + up_write(&current->mm->mmap_sem);
43932 ret = result;
43933 goto err;
43934 }
43935 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43936 }
43937 if (IS_ERR_VALUE(result)) {
43938 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43939 + down_write(&current->mm->mmap_sem);
43940 vm_munmap(textpos, text_len + data_len + extra +
43941 MAX_SHARED_LIBS * sizeof(unsigned long));
43942 + up_write(&current->mm->mmap_sem);
43943 ret = result;
43944 goto err;
43945 }
43946 diff --git a/fs/bio.c b/fs/bio.c
43947 index 71072ab..439851b 100644
43948 --- a/fs/bio.c
43949 +++ b/fs/bio.c
43950 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43951 /*
43952 * Overflow, abort
43953 */
43954 - if (end < start)
43955 + if (end < start || end - start > INT_MAX - nr_pages)
43956 return ERR_PTR(-EINVAL);
43957
43958 nr_pages += end - start;
43959 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43960 /*
43961 * Overflow, abort
43962 */
43963 - if (end < start)
43964 + if (end < start || end - start > INT_MAX - nr_pages)
43965 return ERR_PTR(-EINVAL);
43966
43967 nr_pages += end - start;
43968 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43969 const int read = bio_data_dir(bio) == READ;
43970 struct bio_map_data *bmd = bio->bi_private;
43971 int i;
43972 - char *p = bmd->sgvecs[0].iov_base;
43973 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43974
43975 __bio_for_each_segment(bvec, bio, i, 0) {
43976 char *addr = page_address(bvec->bv_page);
43977 diff --git a/fs/block_dev.c b/fs/block_dev.c
43978 index 38e721b..7a9c5bc 100644
43979 --- a/fs/block_dev.c
43980 +++ b/fs/block_dev.c
43981 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43982 else if (bdev->bd_contains == bdev)
43983 return true; /* is a whole device which isn't held */
43984
43985 - else if (whole->bd_holder == bd_may_claim)
43986 + else if (whole->bd_holder == (void *)bd_may_claim)
43987 return true; /* is a partition of a device that is being partitioned */
43988 else if (whole->bd_holder != NULL)
43989 return false; /* is a partition of a held device */
43990 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43991 index 9197e2e..7f731f8 100644
43992 --- a/fs/btrfs/check-integrity.c
43993 +++ b/fs/btrfs/check-integrity.c
43994 @@ -155,7 +155,7 @@ struct btrfsic_block {
43995 union {
43996 bio_end_io_t *bio;
43997 bh_end_io_t *bh;
43998 - } orig_bio_bh_end_io;
43999 + } __no_const orig_bio_bh_end_io;
44000 int submit_bio_bh_rw;
44001 u64 flush_gen; /* only valid if !never_written */
44002 };
44003 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44004 index 6d183f6..f47cc7a 100644
44005 --- a/fs/btrfs/ctree.c
44006 +++ b/fs/btrfs/ctree.c
44007 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44008 free_extent_buffer(buf);
44009 add_root_to_dirty_list(root);
44010 } else {
44011 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44012 - parent_start = parent->start;
44013 - else
44014 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44015 + if (parent)
44016 + parent_start = parent->start;
44017 + else
44018 + parent_start = 0;
44019 + } else
44020 parent_start = 0;
44021
44022 WARN_ON(trans->transid != btrfs_header_generation(parent));
44023 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44024 index ec154f9..bf617a7 100644
44025 --- a/fs/btrfs/inode.c
44026 +++ b/fs/btrfs/inode.c
44027 @@ -7126,7 +7126,7 @@ fail:
44028 return -ENOMEM;
44029 }
44030
44031 -static int btrfs_getattr(struct vfsmount *mnt,
44032 +int btrfs_getattr(struct vfsmount *mnt,
44033 struct dentry *dentry, struct kstat *stat)
44034 {
44035 struct inode *inode = dentry->d_inode;
44036 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44037 return 0;
44038 }
44039
44040 +EXPORT_SYMBOL(btrfs_getattr);
44041 +
44042 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44043 +{
44044 + return BTRFS_I(inode)->root->anon_dev;
44045 +}
44046 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44047 +
44048 /*
44049 * If a file is moved, it will inherit the cow and compression flags of the new
44050 * directory.
44051 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44052 index 9df50fa..6cd20d0 100644
44053 --- a/fs/btrfs/ioctl.c
44054 +++ b/fs/btrfs/ioctl.c
44055 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44056 for (i = 0; i < num_types; i++) {
44057 struct btrfs_space_info *tmp;
44058
44059 + /* Don't copy in more than we allocated */
44060 if (!slot_count)
44061 break;
44062
44063 + slot_count--;
44064 +
44065 info = NULL;
44066 rcu_read_lock();
44067 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44068 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44069 memcpy(dest, &space, sizeof(space));
44070 dest++;
44071 space_args.total_spaces++;
44072 - slot_count--;
44073 }
44074 - if (!slot_count)
44075 - break;
44076 }
44077 up_read(&info->groups_sem);
44078 }
44079 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44080 index 4da0865..01c4778 100644
44081 --- a/fs/btrfs/relocation.c
44082 +++ b/fs/btrfs/relocation.c
44083 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44084 }
44085 spin_unlock(&rc->reloc_root_tree.lock);
44086
44087 - BUG_ON((struct btrfs_root *)node->data != root);
44088 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44089
44090 if (!del) {
44091 spin_lock(&rc->reloc_root_tree.lock);
44092 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44093 index 622f469..e8d2d55 100644
44094 --- a/fs/cachefiles/bind.c
44095 +++ b/fs/cachefiles/bind.c
44096 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44097 args);
44098
44099 /* start by checking things over */
44100 - ASSERT(cache->fstop_percent >= 0 &&
44101 - cache->fstop_percent < cache->fcull_percent &&
44102 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44103 cache->fcull_percent < cache->frun_percent &&
44104 cache->frun_percent < 100);
44105
44106 - ASSERT(cache->bstop_percent >= 0 &&
44107 - cache->bstop_percent < cache->bcull_percent &&
44108 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44109 cache->bcull_percent < cache->brun_percent &&
44110 cache->brun_percent < 100);
44111
44112 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44113 index 0a1467b..6a53245 100644
44114 --- a/fs/cachefiles/daemon.c
44115 +++ b/fs/cachefiles/daemon.c
44116 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44117 if (n > buflen)
44118 return -EMSGSIZE;
44119
44120 - if (copy_to_user(_buffer, buffer, n) != 0)
44121 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44122 return -EFAULT;
44123
44124 return n;
44125 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44126 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44127 return -EIO;
44128
44129 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44130 + if (datalen > PAGE_SIZE - 1)
44131 return -EOPNOTSUPP;
44132
44133 /* drag the command string into the kernel so we can parse it */
44134 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44135 if (args[0] != '%' || args[1] != '\0')
44136 return -EINVAL;
44137
44138 - if (fstop < 0 || fstop >= cache->fcull_percent)
44139 + if (fstop >= cache->fcull_percent)
44140 return cachefiles_daemon_range_error(cache, args);
44141
44142 cache->fstop_percent = fstop;
44143 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44144 if (args[0] != '%' || args[1] != '\0')
44145 return -EINVAL;
44146
44147 - if (bstop < 0 || bstop >= cache->bcull_percent)
44148 + if (bstop >= cache->bcull_percent)
44149 return cachefiles_daemon_range_error(cache, args);
44150
44151 cache->bstop_percent = bstop;
44152 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44153 index bd6bc1b..b627b53 100644
44154 --- a/fs/cachefiles/internal.h
44155 +++ b/fs/cachefiles/internal.h
44156 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44157 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44158 struct rb_root active_nodes; /* active nodes (can't be culled) */
44159 rwlock_t active_lock; /* lock for active_nodes */
44160 - atomic_t gravecounter; /* graveyard uniquifier */
44161 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44162 unsigned frun_percent; /* when to stop culling (% files) */
44163 unsigned fcull_percent; /* when to start culling (% files) */
44164 unsigned fstop_percent; /* when to stop allocating (% files) */
44165 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44166 * proc.c
44167 */
44168 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44169 -extern atomic_t cachefiles_lookup_histogram[HZ];
44170 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44171 -extern atomic_t cachefiles_create_histogram[HZ];
44172 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44173 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44174 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44175
44176 extern int __init cachefiles_proc_init(void);
44177 extern void cachefiles_proc_cleanup(void);
44178 static inline
44179 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44180 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44181 {
44182 unsigned long jif = jiffies - start_jif;
44183 if (jif >= HZ)
44184 jif = HZ - 1;
44185 - atomic_inc(&histogram[jif]);
44186 + atomic_inc_unchecked(&histogram[jif]);
44187 }
44188
44189 #else
44190 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44191 index b0b5f7c..039bb26 100644
44192 --- a/fs/cachefiles/namei.c
44193 +++ b/fs/cachefiles/namei.c
44194 @@ -318,7 +318,7 @@ try_again:
44195 /* first step is to make up a grave dentry in the graveyard */
44196 sprintf(nbuffer, "%08x%08x",
44197 (uint32_t) get_seconds(),
44198 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44199 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44200
44201 /* do the multiway lock magic */
44202 trap = lock_rename(cache->graveyard, dir);
44203 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44204 index eccd339..4c1d995 100644
44205 --- a/fs/cachefiles/proc.c
44206 +++ b/fs/cachefiles/proc.c
44207 @@ -14,9 +14,9 @@
44208 #include <linux/seq_file.h>
44209 #include "internal.h"
44210
44211 -atomic_t cachefiles_lookup_histogram[HZ];
44212 -atomic_t cachefiles_mkdir_histogram[HZ];
44213 -atomic_t cachefiles_create_histogram[HZ];
44214 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44215 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44216 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44217
44218 /*
44219 * display the latency histogram
44220 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44221 return 0;
44222 default:
44223 index = (unsigned long) v - 3;
44224 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44225 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44226 - z = atomic_read(&cachefiles_create_histogram[index]);
44227 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44228 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44229 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44230 if (x == 0 && y == 0 && z == 0)
44231 return 0;
44232
44233 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44234 index c994691..2a1537f 100644
44235 --- a/fs/cachefiles/rdwr.c
44236 +++ b/fs/cachefiles/rdwr.c
44237 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44238 old_fs = get_fs();
44239 set_fs(KERNEL_DS);
44240 ret = file->f_op->write(
44241 - file, (const void __user *) data, len, &pos);
44242 + file, (const void __force_user *) data, len, &pos);
44243 set_fs(old_fs);
44244 kunmap(page);
44245 if (ret != len)
44246 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44247 index e5b7731..b9c59fb 100644
44248 --- a/fs/ceph/dir.c
44249 +++ b/fs/ceph/dir.c
44250 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44251 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44252 struct ceph_mds_client *mdsc = fsc->mdsc;
44253 unsigned frag = fpos_frag(filp->f_pos);
44254 - int off = fpos_off(filp->f_pos);
44255 + unsigned int off = fpos_off(filp->f_pos);
44256 int err;
44257 u32 ftype;
44258 struct ceph_mds_reply_info_parsed *rinfo;
44259 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44260 index d9ea6ed..1e6c8ac 100644
44261 --- a/fs/cifs/cifs_debug.c
44262 +++ b/fs/cifs/cifs_debug.c
44263 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44264
44265 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44266 #ifdef CONFIG_CIFS_STATS2
44267 - atomic_set(&totBufAllocCount, 0);
44268 - atomic_set(&totSmBufAllocCount, 0);
44269 + atomic_set_unchecked(&totBufAllocCount, 0);
44270 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44271 #endif /* CONFIG_CIFS_STATS2 */
44272 spin_lock(&cifs_tcp_ses_lock);
44273 list_for_each(tmp1, &cifs_tcp_ses_list) {
44274 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44275 tcon = list_entry(tmp3,
44276 struct cifs_tcon,
44277 tcon_list);
44278 - atomic_set(&tcon->num_smbs_sent, 0);
44279 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44280 if (server->ops->clear_stats)
44281 server->ops->clear_stats(tcon);
44282 }
44283 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44284 smBufAllocCount.counter, cifs_min_small);
44285 #ifdef CONFIG_CIFS_STATS2
44286 seq_printf(m, "Total Large %d Small %d Allocations\n",
44287 - atomic_read(&totBufAllocCount),
44288 - atomic_read(&totSmBufAllocCount));
44289 + atomic_read_unchecked(&totBufAllocCount),
44290 + atomic_read_unchecked(&totSmBufAllocCount));
44291 #endif /* CONFIG_CIFS_STATS2 */
44292
44293 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44294 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44295 if (tcon->need_reconnect)
44296 seq_puts(m, "\tDISCONNECTED ");
44297 seq_printf(m, "\nSMBs: %d",
44298 - atomic_read(&tcon->num_smbs_sent));
44299 + atomic_read_unchecked(&tcon->num_smbs_sent));
44300 if (server->ops->print_stats)
44301 server->ops->print_stats(m, tcon);
44302 }
44303 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44304 index db8a404..c712e2e 100644
44305 --- a/fs/cifs/cifsfs.c
44306 +++ b/fs/cifs/cifsfs.c
44307 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44308 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44309 cifs_req_cachep = kmem_cache_create("cifs_request",
44310 CIFSMaxBufSize + max_hdr_size, 0,
44311 - SLAB_HWCACHE_ALIGN, NULL);
44312 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44313 if (cifs_req_cachep == NULL)
44314 return -ENOMEM;
44315
44316 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44317 efficient to alloc 1 per page off the slab compared to 17K (5page)
44318 alloc of large cifs buffers even when page debugging is on */
44319 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44320 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44321 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44322 NULL);
44323 if (cifs_sm_req_cachep == NULL) {
44324 mempool_destroy(cifs_req_poolp);
44325 @@ -1115,8 +1115,8 @@ init_cifs(void)
44326 atomic_set(&bufAllocCount, 0);
44327 atomic_set(&smBufAllocCount, 0);
44328 #ifdef CONFIG_CIFS_STATS2
44329 - atomic_set(&totBufAllocCount, 0);
44330 - atomic_set(&totSmBufAllocCount, 0);
44331 + atomic_set_unchecked(&totBufAllocCount, 0);
44332 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44333 #endif /* CONFIG_CIFS_STATS2 */
44334
44335 atomic_set(&midCount, 0);
44336 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44337 index 977dc0e..ba48ab9 100644
44338 --- a/fs/cifs/cifsglob.h
44339 +++ b/fs/cifs/cifsglob.h
44340 @@ -590,35 +590,35 @@ struct cifs_tcon {
44341 __u16 Flags; /* optional support bits */
44342 enum statusEnum tidStatus;
44343 #ifdef CONFIG_CIFS_STATS
44344 - atomic_t num_smbs_sent;
44345 + atomic_unchecked_t num_smbs_sent;
44346 union {
44347 struct {
44348 - atomic_t num_writes;
44349 - atomic_t num_reads;
44350 - atomic_t num_flushes;
44351 - atomic_t num_oplock_brks;
44352 - atomic_t num_opens;
44353 - atomic_t num_closes;
44354 - atomic_t num_deletes;
44355 - atomic_t num_mkdirs;
44356 - atomic_t num_posixopens;
44357 - atomic_t num_posixmkdirs;
44358 - atomic_t num_rmdirs;
44359 - atomic_t num_renames;
44360 - atomic_t num_t2renames;
44361 - atomic_t num_ffirst;
44362 - atomic_t num_fnext;
44363 - atomic_t num_fclose;
44364 - atomic_t num_hardlinks;
44365 - atomic_t num_symlinks;
44366 - atomic_t num_locks;
44367 - atomic_t num_acl_get;
44368 - atomic_t num_acl_set;
44369 + atomic_unchecked_t num_writes;
44370 + atomic_unchecked_t num_reads;
44371 + atomic_unchecked_t num_flushes;
44372 + atomic_unchecked_t num_oplock_brks;
44373 + atomic_unchecked_t num_opens;
44374 + atomic_unchecked_t num_closes;
44375 + atomic_unchecked_t num_deletes;
44376 + atomic_unchecked_t num_mkdirs;
44377 + atomic_unchecked_t num_posixopens;
44378 + atomic_unchecked_t num_posixmkdirs;
44379 + atomic_unchecked_t num_rmdirs;
44380 + atomic_unchecked_t num_renames;
44381 + atomic_unchecked_t num_t2renames;
44382 + atomic_unchecked_t num_ffirst;
44383 + atomic_unchecked_t num_fnext;
44384 + atomic_unchecked_t num_fclose;
44385 + atomic_unchecked_t num_hardlinks;
44386 + atomic_unchecked_t num_symlinks;
44387 + atomic_unchecked_t num_locks;
44388 + atomic_unchecked_t num_acl_get;
44389 + atomic_unchecked_t num_acl_set;
44390 } cifs_stats;
44391 #ifdef CONFIG_CIFS_SMB2
44392 struct {
44393 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44394 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44395 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44396 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44397 } smb2_stats;
44398 #endif /* CONFIG_CIFS_SMB2 */
44399 } stats;
44400 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44401 }
44402
44403 #ifdef CONFIG_CIFS_STATS
44404 -#define cifs_stats_inc atomic_inc
44405 +#define cifs_stats_inc atomic_inc_unchecked
44406
44407 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44408 unsigned int bytes)
44409 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44410 /* Various Debug counters */
44411 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44412 #ifdef CONFIG_CIFS_STATS2
44413 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44414 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44415 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44416 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44417 #endif
44418 GLOBAL_EXTERN atomic_t smBufAllocCount;
44419 GLOBAL_EXTERN atomic_t midCount;
44420 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44421 index e6ce3b1..adc21fd 100644
44422 --- a/fs/cifs/link.c
44423 +++ b/fs/cifs/link.c
44424 @@ -602,7 +602,7 @@ symlink_exit:
44425
44426 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44427 {
44428 - char *p = nd_get_link(nd);
44429 + const char *p = nd_get_link(nd);
44430 if (!IS_ERR(p))
44431 kfree(p);
44432 }
44433 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44434 index ce41fee..ac0d27a 100644
44435 --- a/fs/cifs/misc.c
44436 +++ b/fs/cifs/misc.c
44437 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44438 memset(ret_buf, 0, buf_size + 3);
44439 atomic_inc(&bufAllocCount);
44440 #ifdef CONFIG_CIFS_STATS2
44441 - atomic_inc(&totBufAllocCount);
44442 + atomic_inc_unchecked(&totBufAllocCount);
44443 #endif /* CONFIG_CIFS_STATS2 */
44444 }
44445
44446 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44447 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44448 atomic_inc(&smBufAllocCount);
44449 #ifdef CONFIG_CIFS_STATS2
44450 - atomic_inc(&totSmBufAllocCount);
44451 + atomic_inc_unchecked(&totSmBufAllocCount);
44452 #endif /* CONFIG_CIFS_STATS2 */
44453
44454 }
44455 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44456 index 3129ac7..cc4a948 100644
44457 --- a/fs/cifs/smb1ops.c
44458 +++ b/fs/cifs/smb1ops.c
44459 @@ -524,27 +524,27 @@ static void
44460 cifs_clear_stats(struct cifs_tcon *tcon)
44461 {
44462 #ifdef CONFIG_CIFS_STATS
44463 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44464 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44465 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44466 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44467 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44468 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44469 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44470 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44471 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44472 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44473 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44474 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44475 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44476 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44477 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44478 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44479 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44480 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44481 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44482 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44483 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44484 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44485 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44486 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44487 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44488 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44489 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44490 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44491 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44492 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44493 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44494 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44495 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44496 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44497 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44498 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44499 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44500 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44501 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44502 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44503 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44504 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44505 #endif
44506 }
44507
44508 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44509 {
44510 #ifdef CONFIG_CIFS_STATS
44511 seq_printf(m, " Oplocks breaks: %d",
44512 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44513 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44514 seq_printf(m, "\nReads: %d Bytes: %llu",
44515 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44516 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44517 (long long)(tcon->bytes_read));
44518 seq_printf(m, "\nWrites: %d Bytes: %llu",
44519 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44520 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44521 (long long)(tcon->bytes_written));
44522 seq_printf(m, "\nFlushes: %d",
44523 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44524 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44525 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44526 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44527 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44528 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44529 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44530 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44531 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44532 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44533 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44534 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44535 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44536 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44537 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44538 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44539 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44540 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44541 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44542 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44543 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44544 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44545 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44546 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44547 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44548 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44549 seq_printf(m, "\nRenames: %d T2 Renames %d",
44550 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44551 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44552 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44553 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44554 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44555 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44556 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44557 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44558 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44559 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44560 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44561 #endif
44562 }
44563
44564 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44565 index 826209b..fa460f4 100644
44566 --- a/fs/cifs/smb2ops.c
44567 +++ b/fs/cifs/smb2ops.c
44568 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44569 #ifdef CONFIG_CIFS_STATS
44570 int i;
44571 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44572 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44573 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44574 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44575 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44576 }
44577 #endif
44578 }
44579 @@ -229,66 +229,66 @@ static void
44580 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44581 {
44582 #ifdef CONFIG_CIFS_STATS
44583 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44584 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44585 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44586 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44587 seq_printf(m, "\nNegotiates: %d sent %d failed",
44588 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44589 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44590 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44591 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44592 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44593 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44594 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44595 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44596 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44597 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44598 seq_printf(m, "\nLogoffs: %d sent %d failed",
44599 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44600 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44601 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44602 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44603 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44604 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44605 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44606 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44607 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44608 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44609 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44610 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44611 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44612 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44613 seq_printf(m, "\nCreates: %d sent %d failed",
44614 - atomic_read(&sent[SMB2_CREATE_HE]),
44615 - atomic_read(&failed[SMB2_CREATE_HE]));
44616 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44617 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44618 seq_printf(m, "\nCloses: %d sent %d failed",
44619 - atomic_read(&sent[SMB2_CLOSE_HE]),
44620 - atomic_read(&failed[SMB2_CLOSE_HE]));
44621 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44622 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44623 seq_printf(m, "\nFlushes: %d sent %d failed",
44624 - atomic_read(&sent[SMB2_FLUSH_HE]),
44625 - atomic_read(&failed[SMB2_FLUSH_HE]));
44626 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44627 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44628 seq_printf(m, "\nReads: %d sent %d failed",
44629 - atomic_read(&sent[SMB2_READ_HE]),
44630 - atomic_read(&failed[SMB2_READ_HE]));
44631 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44632 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44633 seq_printf(m, "\nWrites: %d sent %d failed",
44634 - atomic_read(&sent[SMB2_WRITE_HE]),
44635 - atomic_read(&failed[SMB2_WRITE_HE]));
44636 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44637 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44638 seq_printf(m, "\nLocks: %d sent %d failed",
44639 - atomic_read(&sent[SMB2_LOCK_HE]),
44640 - atomic_read(&failed[SMB2_LOCK_HE]));
44641 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44642 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44643 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44644 - atomic_read(&sent[SMB2_IOCTL_HE]),
44645 - atomic_read(&failed[SMB2_IOCTL_HE]));
44646 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44647 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44648 seq_printf(m, "\nCancels: %d sent %d failed",
44649 - atomic_read(&sent[SMB2_CANCEL_HE]),
44650 - atomic_read(&failed[SMB2_CANCEL_HE]));
44651 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44652 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44653 seq_printf(m, "\nEchos: %d sent %d failed",
44654 - atomic_read(&sent[SMB2_ECHO_HE]),
44655 - atomic_read(&failed[SMB2_ECHO_HE]));
44656 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44657 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44658 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44659 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44660 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44661 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44662 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44663 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44664 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44665 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44666 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44667 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44668 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44669 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44670 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44671 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44672 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44673 seq_printf(m, "\nSetInfos: %d sent %d failed",
44674 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44675 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44676 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44677 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44678 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44679 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44680 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44681 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44682 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44683 #endif
44684 }
44685
44686 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44687 index 958ae0e..505c9d0 100644
44688 --- a/fs/coda/cache.c
44689 +++ b/fs/coda/cache.c
44690 @@ -24,7 +24,7 @@
44691 #include "coda_linux.h"
44692 #include "coda_cache.h"
44693
44694 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44695 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44696
44697 /* replace or extend an acl cache hit */
44698 void coda_cache_enter(struct inode *inode, int mask)
44699 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44700 struct coda_inode_info *cii = ITOC(inode);
44701
44702 spin_lock(&cii->c_lock);
44703 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44704 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44705 if (cii->c_uid != current_fsuid()) {
44706 cii->c_uid = current_fsuid();
44707 cii->c_cached_perm = mask;
44708 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44709 {
44710 struct coda_inode_info *cii = ITOC(inode);
44711 spin_lock(&cii->c_lock);
44712 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44713 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44714 spin_unlock(&cii->c_lock);
44715 }
44716
44717 /* remove all acl caches */
44718 void coda_cache_clear_all(struct super_block *sb)
44719 {
44720 - atomic_inc(&permission_epoch);
44721 + atomic_inc_unchecked(&permission_epoch);
44722 }
44723
44724
44725 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44726 spin_lock(&cii->c_lock);
44727 hit = (mask & cii->c_cached_perm) == mask &&
44728 cii->c_uid == current_fsuid() &&
44729 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44730 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44731 spin_unlock(&cii->c_lock);
44732
44733 return hit;
44734 diff --git a/fs/compat.c b/fs/compat.c
44735 index 1bdb350..9f28287 100644
44736 --- a/fs/compat.c
44737 +++ b/fs/compat.c
44738 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44739
44740 set_fs(KERNEL_DS);
44741 /* The __user pointer cast is valid because of the set_fs() */
44742 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44743 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44744 set_fs(oldfs);
44745 /* truncating is ok because it's a user address */
44746 if (!ret)
44747 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44748 goto out;
44749
44750 ret = -EINVAL;
44751 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44752 + if (nr_segs > UIO_MAXIOV)
44753 goto out;
44754 if (nr_segs > fast_segs) {
44755 ret = -ENOMEM;
44756 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44757
44758 struct compat_readdir_callback {
44759 struct compat_old_linux_dirent __user *dirent;
44760 + struct file * file;
44761 int result;
44762 };
44763
44764 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44765 buf->result = -EOVERFLOW;
44766 return -EOVERFLOW;
44767 }
44768 +
44769 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44770 + return 0;
44771 +
44772 buf->result++;
44773 dirent = buf->dirent;
44774 if (!access_ok(VERIFY_WRITE, dirent,
44775 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44776
44777 buf.result = 0;
44778 buf.dirent = dirent;
44779 + buf.file = file;
44780
44781 error = vfs_readdir(file, compat_fillonedir, &buf);
44782 if (buf.result)
44783 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44784 struct compat_getdents_callback {
44785 struct compat_linux_dirent __user *current_dir;
44786 struct compat_linux_dirent __user *previous;
44787 + struct file * file;
44788 int count;
44789 int error;
44790 };
44791 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44792 buf->error = -EOVERFLOW;
44793 return -EOVERFLOW;
44794 }
44795 +
44796 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44797 + return 0;
44798 +
44799 dirent = buf->previous;
44800 if (dirent) {
44801 if (__put_user(offset, &dirent->d_off))
44802 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44803 buf.previous = NULL;
44804 buf.count = count;
44805 buf.error = 0;
44806 + buf.file = file;
44807
44808 error = vfs_readdir(file, compat_filldir, &buf);
44809 if (error >= 0)
44810 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44811 struct compat_getdents_callback64 {
44812 struct linux_dirent64 __user *current_dir;
44813 struct linux_dirent64 __user *previous;
44814 + struct file * file;
44815 int count;
44816 int error;
44817 };
44818 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44819 buf->error = -EINVAL; /* only used if we fail.. */
44820 if (reclen > buf->count)
44821 return -EINVAL;
44822 +
44823 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44824 + return 0;
44825 +
44826 dirent = buf->previous;
44827
44828 if (dirent) {
44829 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44830 buf.previous = NULL;
44831 buf.count = count;
44832 buf.error = 0;
44833 + buf.file = file;
44834
44835 error = vfs_readdir(file, compat_filldir64, &buf);
44836 if (error >= 0)
44837 error = buf.error;
44838 lastdirent = buf.previous;
44839 if (lastdirent) {
44840 - typeof(lastdirent->d_off) d_off = file->f_pos;
44841 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44842 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44843 error = -EFAULT;
44844 else
44845 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44846 index 112e45a..b59845b 100644
44847 --- a/fs/compat_binfmt_elf.c
44848 +++ b/fs/compat_binfmt_elf.c
44849 @@ -30,11 +30,13 @@
44850 #undef elf_phdr
44851 #undef elf_shdr
44852 #undef elf_note
44853 +#undef elf_dyn
44854 #undef elf_addr_t
44855 #define elfhdr elf32_hdr
44856 #define elf_phdr elf32_phdr
44857 #define elf_shdr elf32_shdr
44858 #define elf_note elf32_note
44859 +#define elf_dyn Elf32_Dyn
44860 #define elf_addr_t Elf32_Addr
44861
44862 /*
44863 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44864 index 5d2069f..75d31d4 100644
44865 --- a/fs/compat_ioctl.c
44866 +++ b/fs/compat_ioctl.c
44867 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44868 return -EFAULT;
44869 if (__get_user(udata, &ss32->iomem_base))
44870 return -EFAULT;
44871 - ss.iomem_base = compat_ptr(udata);
44872 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44873 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44874 __get_user(ss.port_high, &ss32->port_high))
44875 return -EFAULT;
44876 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44877 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44878 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44879 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44880 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44881 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44882 return -EFAULT;
44883
44884 return ioctl_preallocate(file, p);
44885 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44886 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44887 {
44888 unsigned int a, b;
44889 - a = *(unsigned int *)p;
44890 - b = *(unsigned int *)q;
44891 + a = *(const unsigned int *)p;
44892 + b = *(const unsigned int *)q;
44893 if (a > b)
44894 return 1;
44895 if (a < b)
44896 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44897 index 7414ae2..d98ad6d 100644
44898 --- a/fs/configfs/dir.c
44899 +++ b/fs/configfs/dir.c
44900 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44901 }
44902 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44903 struct configfs_dirent *next;
44904 - const char * name;
44905 + const unsigned char * name;
44906 + char d_name[sizeof(next->s_dentry->d_iname)];
44907 int len;
44908 struct inode *inode = NULL;
44909
44910 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44911 continue;
44912
44913 name = configfs_get_name(next);
44914 - len = strlen(name);
44915 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44916 + len = next->s_dentry->d_name.len;
44917 + memcpy(d_name, name, len);
44918 + name = d_name;
44919 + } else
44920 + len = strlen(name);
44921
44922 /*
44923 * We'll have a dentry and an inode for
44924 diff --git a/fs/dcache.c b/fs/dcache.c
44925 index 693f95b..95f1223 100644
44926 --- a/fs/dcache.c
44927 +++ b/fs/dcache.c
44928 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44929 mempages -= reserve;
44930
44931 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44932 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44933 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44934
44935 dcache_init();
44936 inode_init();
44937 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44938 index 4733eab..71ef6fa 100644
44939 --- a/fs/debugfs/inode.c
44940 +++ b/fs/debugfs/inode.c
44941 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44942 */
44943 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44944 {
44945 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44946 + return __create_file(name, S_IFDIR | S_IRWXU,
44947 +#else
44948 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44949 +#endif
44950 parent, NULL, NULL);
44951 }
44952 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44953 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44954 index cc7709e..7e7211f 100644
44955 --- a/fs/ecryptfs/inode.c
44956 +++ b/fs/ecryptfs/inode.c
44957 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44958 old_fs = get_fs();
44959 set_fs(get_ds());
44960 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44961 - (char __user *)lower_buf,
44962 + (char __force_user *)lower_buf,
44963 PATH_MAX);
44964 set_fs(old_fs);
44965 if (rc < 0)
44966 @@ -706,7 +706,7 @@ out:
44967 static void
44968 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44969 {
44970 - char *buf = nd_get_link(nd);
44971 + const char *buf = nd_get_link(nd);
44972 if (!IS_ERR(buf)) {
44973 /* Free the char* */
44974 kfree(buf);
44975 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44976 index 412e6ed..4292d22 100644
44977 --- a/fs/ecryptfs/miscdev.c
44978 +++ b/fs/ecryptfs/miscdev.c
44979 @@ -315,7 +315,7 @@ check_list:
44980 goto out_unlock_msg_ctx;
44981 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44982 if (msg_ctx->msg) {
44983 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44984 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44985 goto out_unlock_msg_ctx;
44986 i += packet_length_size;
44987 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44988 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44989 index b2a34a1..162fa69 100644
44990 --- a/fs/ecryptfs/read_write.c
44991 +++ b/fs/ecryptfs/read_write.c
44992 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44993 return -EIO;
44994 fs_save = get_fs();
44995 set_fs(get_ds());
44996 - rc = vfs_write(lower_file, data, size, &offset);
44997 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44998 set_fs(fs_save);
44999 mark_inode_dirty_sync(ecryptfs_inode);
45000 return rc;
45001 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45002 return -EIO;
45003 fs_save = get_fs();
45004 set_fs(get_ds());
45005 - rc = vfs_read(lower_file, data, size, &offset);
45006 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45007 set_fs(fs_save);
45008 return rc;
45009 }
45010 diff --git a/fs/exec.c b/fs/exec.c
45011 index fab2c6d..4fa20c0 100644
45012 --- a/fs/exec.c
45013 +++ b/fs/exec.c
45014 @@ -55,6 +55,15 @@
45015 #include <linux/pipe_fs_i.h>
45016 #include <linux/oom.h>
45017 #include <linux/compat.h>
45018 +#include <linux/random.h>
45019 +#include <linux/seq_file.h>
45020 +
45021 +#ifdef CONFIG_PAX_REFCOUNT
45022 +#include <linux/kallsyms.h>
45023 +#include <linux/kdebug.h>
45024 +#endif
45025 +
45026 +#include <trace/events/fs.h>
45027
45028 #include <asm/uaccess.h>
45029 #include <asm/mmu_context.h>
45030 @@ -66,6 +75,18 @@
45031
45032 #include <trace/events/sched.h>
45033
45034 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45035 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45036 +{
45037 + 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");
45038 +}
45039 +#endif
45040 +
45041 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45042 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45043 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45044 +#endif
45045 +
45046 int core_uses_pid;
45047 char core_pattern[CORENAME_MAX_SIZE] = "core";
45048 unsigned int core_pipe_limit;
45049 @@ -75,7 +96,7 @@ struct core_name {
45050 char *corename;
45051 int used, size;
45052 };
45053 -static atomic_t call_count = ATOMIC_INIT(1);
45054 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45055
45056 /* The maximal length of core_pattern is also specified in sysctl.c */
45057
45058 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45059 int write)
45060 {
45061 struct page *page;
45062 - int ret;
45063
45064 -#ifdef CONFIG_STACK_GROWSUP
45065 - if (write) {
45066 - ret = expand_downwards(bprm->vma, pos);
45067 - if (ret < 0)
45068 - return NULL;
45069 - }
45070 -#endif
45071 - ret = get_user_pages(current, bprm->mm, pos,
45072 - 1, write, 1, &page, NULL);
45073 - if (ret <= 0)
45074 + if (0 > expand_downwards(bprm->vma, pos))
45075 + return NULL;
45076 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45077 return NULL;
45078
45079 if (write) {
45080 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45081 if (size <= ARG_MAX)
45082 return page;
45083
45084 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45085 + // only allow 512KB for argv+env on suid/sgid binaries
45086 + // to prevent easy ASLR exhaustion
45087 + if (((bprm->cred->euid != current_euid()) ||
45088 + (bprm->cred->egid != current_egid())) &&
45089 + (size > (512 * 1024))) {
45090 + put_page(page);
45091 + return NULL;
45092 + }
45093 +#endif
45094 +
45095 /*
45096 * Limit to 1/4-th the stack size for the argv+env strings.
45097 * This ensures that:
45098 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45099 vma->vm_end = STACK_TOP_MAX;
45100 vma->vm_start = vma->vm_end - PAGE_SIZE;
45101 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45102 +
45103 +#ifdef CONFIG_PAX_SEGMEXEC
45104 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45105 +#endif
45106 +
45107 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45108 INIT_LIST_HEAD(&vma->anon_vma_chain);
45109
45110 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45111 mm->stack_vm = mm->total_vm = 1;
45112 up_write(&mm->mmap_sem);
45113 bprm->p = vma->vm_end - sizeof(void *);
45114 +
45115 +#ifdef CONFIG_PAX_RANDUSTACK
45116 + if (randomize_va_space)
45117 + bprm->p ^= random32() & ~PAGE_MASK;
45118 +#endif
45119 +
45120 return 0;
45121 err:
45122 up_write(&mm->mmap_sem);
45123 @@ -395,19 +430,7 @@ err:
45124 return err;
45125 }
45126
45127 -struct user_arg_ptr {
45128 -#ifdef CONFIG_COMPAT
45129 - bool is_compat;
45130 -#endif
45131 - union {
45132 - const char __user *const __user *native;
45133 -#ifdef CONFIG_COMPAT
45134 - compat_uptr_t __user *compat;
45135 -#endif
45136 - } ptr;
45137 -};
45138 -
45139 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45140 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45141 {
45142 const char __user *native;
45143
45144 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45145 compat_uptr_t compat;
45146
45147 if (get_user(compat, argv.ptr.compat + nr))
45148 - return ERR_PTR(-EFAULT);
45149 + return (const char __force_user *)ERR_PTR(-EFAULT);
45150
45151 return compat_ptr(compat);
45152 }
45153 #endif
45154
45155 if (get_user(native, argv.ptr.native + nr))
45156 - return ERR_PTR(-EFAULT);
45157 + return (const char __force_user *)ERR_PTR(-EFAULT);
45158
45159 return native;
45160 }
45161 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45162 if (!p)
45163 break;
45164
45165 - if (IS_ERR(p))
45166 + if (IS_ERR((const char __force_kernel *)p))
45167 return -EFAULT;
45168
45169 if (i++ >= max)
45170 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45171
45172 ret = -EFAULT;
45173 str = get_user_arg_ptr(argv, argc);
45174 - if (IS_ERR(str))
45175 + if (IS_ERR((const char __force_kernel *)str))
45176 goto out;
45177
45178 len = strnlen_user(str, MAX_ARG_STRLEN);
45179 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45180 int r;
45181 mm_segment_t oldfs = get_fs();
45182 struct user_arg_ptr argv = {
45183 - .ptr.native = (const char __user *const __user *)__argv,
45184 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45185 };
45186
45187 set_fs(KERNEL_DS);
45188 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45189 unsigned long new_end = old_end - shift;
45190 struct mmu_gather tlb;
45191
45192 - BUG_ON(new_start > new_end);
45193 + if (new_start >= new_end || new_start < mmap_min_addr)
45194 + return -ENOMEM;
45195
45196 /*
45197 * ensure there are no vmas between where we want to go
45198 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45199 if (vma != find_vma(mm, new_start))
45200 return -EFAULT;
45201
45202 +#ifdef CONFIG_PAX_SEGMEXEC
45203 + BUG_ON(pax_find_mirror_vma(vma));
45204 +#endif
45205 +
45206 /*
45207 * cover the whole range: [new_start, old_end)
45208 */
45209 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45210 stack_top = arch_align_stack(stack_top);
45211 stack_top = PAGE_ALIGN(stack_top);
45212
45213 - if (unlikely(stack_top < mmap_min_addr) ||
45214 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45215 - return -ENOMEM;
45216 -
45217 stack_shift = vma->vm_end - stack_top;
45218
45219 bprm->p -= stack_shift;
45220 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45221 bprm->exec -= stack_shift;
45222
45223 down_write(&mm->mmap_sem);
45224 +
45225 + /* Move stack pages down in memory. */
45226 + if (stack_shift) {
45227 + ret = shift_arg_pages(vma, stack_shift);
45228 + if (ret)
45229 + goto out_unlock;
45230 + }
45231 +
45232 vm_flags = VM_STACK_FLAGS;
45233
45234 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45235 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45236 + vm_flags &= ~VM_EXEC;
45237 +
45238 +#ifdef CONFIG_PAX_MPROTECT
45239 + if (mm->pax_flags & MF_PAX_MPROTECT)
45240 + vm_flags &= ~VM_MAYEXEC;
45241 +#endif
45242 +
45243 + }
45244 +#endif
45245 +
45246 /*
45247 * Adjust stack execute permissions; explicitly enable for
45248 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45249 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45250 goto out_unlock;
45251 BUG_ON(prev != vma);
45252
45253 - /* Move stack pages down in memory. */
45254 - if (stack_shift) {
45255 - ret = shift_arg_pages(vma, stack_shift);
45256 - if (ret)
45257 - goto out_unlock;
45258 - }
45259 -
45260 /* mprotect_fixup is overkill to remove the temporary stack flags */
45261 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45262
45263 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45264
45265 fsnotify_open(file);
45266
45267 + trace_open_exec(name);
45268 +
45269 err = deny_write_access(file);
45270 if (err)
45271 goto exit;
45272 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45273 old_fs = get_fs();
45274 set_fs(get_ds());
45275 /* The cast to a user pointer is valid due to the set_fs() */
45276 - result = vfs_read(file, (void __user *)addr, count, &pos);
45277 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45278 set_fs(old_fs);
45279 return result;
45280 }
45281 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45282 }
45283 rcu_read_unlock();
45284
45285 - if (p->fs->users > n_fs) {
45286 + if (atomic_read(&p->fs->users) > n_fs) {
45287 bprm->unsafe |= LSM_UNSAFE_SHARE;
45288 } else {
45289 res = -EAGAIN;
45290 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45291
45292 EXPORT_SYMBOL(search_binary_handler);
45293
45294 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45295 +static DEFINE_PER_CPU(u64, exec_counter);
45296 +static int __init init_exec_counters(void)
45297 +{
45298 + unsigned int cpu;
45299 +
45300 + for_each_possible_cpu(cpu) {
45301 + per_cpu(exec_counter, cpu) = (u64)cpu;
45302 + }
45303 +
45304 + return 0;
45305 +}
45306 +early_initcall(init_exec_counters);
45307 +static inline void increment_exec_counter(void)
45308 +{
45309 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45310 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45311 +}
45312 +#else
45313 +static inline void increment_exec_counter(void) {}
45314 +#endif
45315 +
45316 /*
45317 * sys_execve() executes a new program.
45318 */
45319 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45320 struct user_arg_ptr envp,
45321 struct pt_regs *regs)
45322 {
45323 +#ifdef CONFIG_GRKERNSEC
45324 + struct file *old_exec_file;
45325 + struct acl_subject_label *old_acl;
45326 + struct rlimit old_rlim[RLIM_NLIMITS];
45327 +#endif
45328 struct linux_binprm *bprm;
45329 struct file *file;
45330 struct files_struct *displaced;
45331 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45332 int retval;
45333 const struct cred *cred = current_cred();
45334
45335 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45336 +
45337 /*
45338 * We move the actual failure in case of RLIMIT_NPROC excess from
45339 * set*uid() to execve() because too many poorly written programs
45340 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45341 if (IS_ERR(file))
45342 goto out_unmark;
45343
45344 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45345 + retval = -EPERM;
45346 + goto out_file;
45347 + }
45348 +
45349 sched_exec();
45350
45351 bprm->file = file;
45352 bprm->filename = filename;
45353 bprm->interp = filename;
45354
45355 + if (gr_process_user_ban()) {
45356 + retval = -EPERM;
45357 + goto out_file;
45358 + }
45359 +
45360 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45361 + retval = -EACCES;
45362 + goto out_file;
45363 + }
45364 +
45365 retval = bprm_mm_init(bprm);
45366 if (retval)
45367 goto out_file;
45368 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45369 if (retval < 0)
45370 goto out;
45371
45372 +#ifdef CONFIG_GRKERNSEC
45373 + old_acl = current->acl;
45374 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45375 + old_exec_file = current->exec_file;
45376 + get_file(file);
45377 + current->exec_file = file;
45378 +#endif
45379 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45380 + /* limit suid stack to 8MB
45381 + we saved the old limits above and will restore them if this exec fails
45382 + */
45383 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45384 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45385 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45386 +#endif
45387 +
45388 + if (!gr_tpe_allow(file)) {
45389 + retval = -EACCES;
45390 + goto out_fail;
45391 + }
45392 +
45393 + if (gr_check_crash_exec(file)) {
45394 + retval = -EACCES;
45395 + goto out_fail;
45396 + }
45397 +
45398 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45399 + bprm->unsafe);
45400 + if (retval < 0)
45401 + goto out_fail;
45402 +
45403 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45404 if (retval < 0)
45405 - goto out;
45406 + goto out_fail;
45407
45408 bprm->exec = bprm->p;
45409 retval = copy_strings(bprm->envc, envp, bprm);
45410 if (retval < 0)
45411 - goto out;
45412 + goto out_fail;
45413
45414 retval = copy_strings(bprm->argc, argv, bprm);
45415 if (retval < 0)
45416 - goto out;
45417 + goto out_fail;
45418 +
45419 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45420 +
45421 + gr_handle_exec_args(bprm, argv);
45422
45423 retval = search_binary_handler(bprm,regs);
45424 if (retval < 0)
45425 - goto out;
45426 + goto out_fail;
45427 +#ifdef CONFIG_GRKERNSEC
45428 + if (old_exec_file)
45429 + fput(old_exec_file);
45430 +#endif
45431
45432 /* execve succeeded */
45433 +
45434 + increment_exec_counter();
45435 current->fs->in_exec = 0;
45436 current->in_execve = 0;
45437 acct_update_integrals(current);
45438 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45439 put_files_struct(displaced);
45440 return retval;
45441
45442 +out_fail:
45443 +#ifdef CONFIG_GRKERNSEC
45444 + current->acl = old_acl;
45445 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45446 + fput(current->exec_file);
45447 + current->exec_file = old_exec_file;
45448 +#endif
45449 +
45450 out:
45451 if (bprm->mm) {
45452 acct_arg_size(bprm, 0);
45453 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45454 {
45455 char *old_corename = cn->corename;
45456
45457 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45458 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45459 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45460
45461 if (!cn->corename) {
45462 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45463 int pid_in_pattern = 0;
45464 int err = 0;
45465
45466 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45467 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45468 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45469 cn->used = 0;
45470
45471 @@ -1831,6 +1963,250 @@ out:
45472 return ispipe;
45473 }
45474
45475 +int pax_check_flags(unsigned long *flags)
45476 +{
45477 + int retval = 0;
45478 +
45479 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45480 + if (*flags & MF_PAX_SEGMEXEC)
45481 + {
45482 + *flags &= ~MF_PAX_SEGMEXEC;
45483 + retval = -EINVAL;
45484 + }
45485 +#endif
45486 +
45487 + if ((*flags & MF_PAX_PAGEEXEC)
45488 +
45489 +#ifdef CONFIG_PAX_PAGEEXEC
45490 + && (*flags & MF_PAX_SEGMEXEC)
45491 +#endif
45492 +
45493 + )
45494 + {
45495 + *flags &= ~MF_PAX_PAGEEXEC;
45496 + retval = -EINVAL;
45497 + }
45498 +
45499 + if ((*flags & MF_PAX_MPROTECT)
45500 +
45501 +#ifdef CONFIG_PAX_MPROTECT
45502 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45503 +#endif
45504 +
45505 + )
45506 + {
45507 + *flags &= ~MF_PAX_MPROTECT;
45508 + retval = -EINVAL;
45509 + }
45510 +
45511 + if ((*flags & MF_PAX_EMUTRAMP)
45512 +
45513 +#ifdef CONFIG_PAX_EMUTRAMP
45514 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45515 +#endif
45516 +
45517 + )
45518 + {
45519 + *flags &= ~MF_PAX_EMUTRAMP;
45520 + retval = -EINVAL;
45521 + }
45522 +
45523 + return retval;
45524 +}
45525 +
45526 +EXPORT_SYMBOL(pax_check_flags);
45527 +
45528 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45529 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45530 +{
45531 + struct task_struct *tsk = current;
45532 + struct mm_struct *mm = current->mm;
45533 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45534 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45535 + char *path_exec = NULL;
45536 + char *path_fault = NULL;
45537 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45538 +
45539 + if (buffer_exec && buffer_fault) {
45540 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45541 +
45542 + down_read(&mm->mmap_sem);
45543 + vma = mm->mmap;
45544 + while (vma && (!vma_exec || !vma_fault)) {
45545 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45546 + vma_exec = vma;
45547 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45548 + vma_fault = vma;
45549 + vma = vma->vm_next;
45550 + }
45551 + if (vma_exec) {
45552 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45553 + if (IS_ERR(path_exec))
45554 + path_exec = "<path too long>";
45555 + else {
45556 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45557 + if (path_exec) {
45558 + *path_exec = 0;
45559 + path_exec = buffer_exec;
45560 + } else
45561 + path_exec = "<path too long>";
45562 + }
45563 + }
45564 + if (vma_fault) {
45565 + start = vma_fault->vm_start;
45566 + end = vma_fault->vm_end;
45567 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45568 + if (vma_fault->vm_file) {
45569 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45570 + if (IS_ERR(path_fault))
45571 + path_fault = "<path too long>";
45572 + else {
45573 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45574 + if (path_fault) {
45575 + *path_fault = 0;
45576 + path_fault = buffer_fault;
45577 + } else
45578 + path_fault = "<path too long>";
45579 + }
45580 + } else
45581 + path_fault = "<anonymous mapping>";
45582 + }
45583 + up_read(&mm->mmap_sem);
45584 + }
45585 + if (tsk->signal->curr_ip)
45586 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45587 + else
45588 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45589 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45590 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45591 + task_uid(tsk), task_euid(tsk), pc, sp);
45592 + free_page((unsigned long)buffer_exec);
45593 + free_page((unsigned long)buffer_fault);
45594 + pax_report_insns(regs, pc, sp);
45595 + do_coredump(SIGKILL, SIGKILL, regs);
45596 +}
45597 +#endif
45598 +
45599 +#ifdef CONFIG_PAX_REFCOUNT
45600 +void pax_report_refcount_overflow(struct pt_regs *regs)
45601 +{
45602 + if (current->signal->curr_ip)
45603 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45604 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45605 + else
45606 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45607 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45608 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45609 + show_regs(regs);
45610 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45611 +}
45612 +#endif
45613 +
45614 +#ifdef CONFIG_PAX_USERCOPY
45615 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45616 +static noinline int check_stack_object(const void *obj, unsigned long len)
45617 +{
45618 + const void * const stack = task_stack_page(current);
45619 + const void * const stackend = stack + THREAD_SIZE;
45620 +
45621 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45622 + const void *frame = NULL;
45623 + const void *oldframe;
45624 +#endif
45625 +
45626 + if (obj + len < obj)
45627 + return -1;
45628 +
45629 + if (obj + len <= stack || stackend <= obj)
45630 + return 0;
45631 +
45632 + if (obj < stack || stackend < obj + len)
45633 + return -1;
45634 +
45635 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45636 + oldframe = __builtin_frame_address(1);
45637 + if (oldframe)
45638 + frame = __builtin_frame_address(2);
45639 + /*
45640 + low ----------------------------------------------> high
45641 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45642 + ^----------------^
45643 + allow copies only within here
45644 + */
45645 + while (stack <= frame && frame < stackend) {
45646 + /* if obj + len extends past the last frame, this
45647 + check won't pass and the next frame will be 0,
45648 + causing us to bail out and correctly report
45649 + the copy as invalid
45650 + */
45651 + if (obj + len <= frame)
45652 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45653 + oldframe = frame;
45654 + frame = *(const void * const *)frame;
45655 + }
45656 + return -1;
45657 +#else
45658 + return 1;
45659 +#endif
45660 +}
45661 +
45662 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45663 +{
45664 + if (current->signal->curr_ip)
45665 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45666 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45667 + else
45668 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45669 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45670 + dump_stack();
45671 + gr_handle_kernel_exploit();
45672 + do_group_exit(SIGKILL);
45673 +}
45674 +#endif
45675 +
45676 +void check_object_size(const void *ptr, unsigned long n, bool to)
45677 +{
45678 +
45679 +#ifdef CONFIG_PAX_USERCOPY
45680 + const char *type;
45681 +
45682 + if (!n)
45683 + return;
45684 +
45685 + type = check_heap_object(ptr, n, to);
45686 + if (!type) {
45687 + if (check_stack_object(ptr, n) != -1)
45688 + return;
45689 + type = "<process stack>";
45690 + }
45691 +
45692 + pax_report_usercopy(ptr, n, to, type);
45693 +#endif
45694 +
45695 +}
45696 +EXPORT_SYMBOL(check_object_size);
45697 +
45698 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45699 +void pax_track_stack(void)
45700 +{
45701 + unsigned long sp = (unsigned long)&sp;
45702 + if (sp < current_thread_info()->lowest_stack &&
45703 + sp > (unsigned long)task_stack_page(current))
45704 + current_thread_info()->lowest_stack = sp;
45705 +}
45706 +EXPORT_SYMBOL(pax_track_stack);
45707 +#endif
45708 +
45709 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45710 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45711 +{
45712 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45713 + dump_stack();
45714 + do_group_exit(SIGKILL);
45715 +}
45716 +EXPORT_SYMBOL(report_size_overflow);
45717 +#endif
45718 +
45719 static int zap_process(struct task_struct *start, int exit_code)
45720 {
45721 struct task_struct *t;
45722 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45723 pipe = file->f_path.dentry->d_inode->i_pipe;
45724
45725 pipe_lock(pipe);
45726 - pipe->readers++;
45727 - pipe->writers--;
45728 + atomic_inc(&pipe->readers);
45729 + atomic_dec(&pipe->writers);
45730
45731 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45732 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45733 wake_up_interruptible_sync(&pipe->wait);
45734 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45735 pipe_wait(pipe);
45736 }
45737
45738 - pipe->readers--;
45739 - pipe->writers++;
45740 + atomic_dec(&pipe->readers);
45741 + atomic_inc(&pipe->writers);
45742 pipe_unlock(pipe);
45743
45744 }
45745 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45746 int flag = 0;
45747 int ispipe;
45748 bool need_nonrelative = false;
45749 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45750 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45751 struct coredump_params cprm = {
45752 .signr = signr,
45753 .regs = regs,
45754 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45755
45756 audit_core_dumps(signr);
45757
45758 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45759 + gr_handle_brute_attach(current, cprm.mm_flags);
45760 +
45761 binfmt = mm->binfmt;
45762 if (!binfmt || !binfmt->core_dump)
45763 goto fail;
45764 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45765 }
45766 cprm.limit = RLIM_INFINITY;
45767
45768 - dump_count = atomic_inc_return(&core_dump_count);
45769 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45770 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45771 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45772 task_tgid_vnr(current), current->comm);
45773 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45774 } else {
45775 struct inode *inode;
45776
45777 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45778 +
45779 if (cprm.limit < binfmt->min_coredump)
45780 goto fail_unlock;
45781
45782 @@ -2269,7 +2650,7 @@ close_fail:
45783 filp_close(cprm.file, NULL);
45784 fail_dropcount:
45785 if (ispipe)
45786 - atomic_dec(&core_dump_count);
45787 + atomic_dec_unchecked(&core_dump_count);
45788 fail_unlock:
45789 kfree(cn.corename);
45790 fail_corename:
45791 @@ -2288,7 +2669,7 @@ fail:
45792 */
45793 int dump_write(struct file *file, const void *addr, int nr)
45794 {
45795 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45796 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45797 }
45798 EXPORT_SYMBOL(dump_write);
45799
45800 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45801 index 376aa77..59a129c 100644
45802 --- a/fs/ext2/balloc.c
45803 +++ b/fs/ext2/balloc.c
45804 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45805
45806 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45807 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45808 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45809 + if (free_blocks < root_blocks + 1 &&
45810 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45811 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45812 - !in_group_p (sbi->s_resgid))) {
45813 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45814 return 0;
45815 }
45816 return 1;
45817 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45818 index 90d901f..159975f 100644
45819 --- a/fs/ext3/balloc.c
45820 +++ b/fs/ext3/balloc.c
45821 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45822
45823 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45824 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45825 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45826 + if (free_blocks < root_blocks + 1 &&
45827 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45828 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45829 - !in_group_p (sbi->s_resgid))) {
45830 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45831 return 0;
45832 }
45833 return 1;
45834 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45835 index cf18217..8f6b9c3 100644
45836 --- a/fs/ext4/balloc.c
45837 +++ b/fs/ext4/balloc.c
45838 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45839 /* Hm, nope. Are (enough) root reserved clusters available? */
45840 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45841 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45842 - capable(CAP_SYS_RESOURCE) ||
45843 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45844 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45845 + capable_nolog(CAP_SYS_RESOURCE)) {
45846
45847 if (free_clusters >= (nclusters + dirty_clusters))
45848 return 1;
45849 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45850 index 5c69f2b..05dec7f 100644
45851 --- a/fs/ext4/ext4.h
45852 +++ b/fs/ext4/ext4.h
45853 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45854 unsigned long s_mb_last_start;
45855
45856 /* stats for buddy allocator */
45857 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45858 - atomic_t s_bal_success; /* we found long enough chunks */
45859 - atomic_t s_bal_allocated; /* in blocks */
45860 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45861 - atomic_t s_bal_goals; /* goal hits */
45862 - atomic_t s_bal_breaks; /* too long searches */
45863 - atomic_t s_bal_2orders; /* 2^order hits */
45864 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45865 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45866 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45867 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45868 + atomic_unchecked_t s_bal_goals; /* goal hits */
45869 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45870 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45871 spinlock_t s_bal_lock;
45872 unsigned long s_mb_buddies_generated;
45873 unsigned long long s_mb_generation_time;
45874 - atomic_t s_mb_lost_chunks;
45875 - atomic_t s_mb_preallocated;
45876 - atomic_t s_mb_discarded;
45877 + atomic_unchecked_t s_mb_lost_chunks;
45878 + atomic_unchecked_t s_mb_preallocated;
45879 + atomic_unchecked_t s_mb_discarded;
45880 atomic_t s_lock_busy;
45881
45882 /* locality groups */
45883 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45884 index b26410c..7383d90 100644
45885 --- a/fs/ext4/mballoc.c
45886 +++ b/fs/ext4/mballoc.c
45887 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45888 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45889
45890 if (EXT4_SB(sb)->s_mb_stats)
45891 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45892 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45893
45894 break;
45895 }
45896 @@ -2040,7 +2040,7 @@ repeat:
45897 ac->ac_status = AC_STATUS_CONTINUE;
45898 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45899 cr = 3;
45900 - atomic_inc(&sbi->s_mb_lost_chunks);
45901 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45902 goto repeat;
45903 }
45904 }
45905 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45906 if (sbi->s_mb_stats) {
45907 ext4_msg(sb, KERN_INFO,
45908 "mballoc: %u blocks %u reqs (%u success)",
45909 - atomic_read(&sbi->s_bal_allocated),
45910 - atomic_read(&sbi->s_bal_reqs),
45911 - atomic_read(&sbi->s_bal_success));
45912 + atomic_read_unchecked(&sbi->s_bal_allocated),
45913 + atomic_read_unchecked(&sbi->s_bal_reqs),
45914 + atomic_read_unchecked(&sbi->s_bal_success));
45915 ext4_msg(sb, KERN_INFO,
45916 "mballoc: %u extents scanned, %u goal hits, "
45917 "%u 2^N hits, %u breaks, %u lost",
45918 - atomic_read(&sbi->s_bal_ex_scanned),
45919 - atomic_read(&sbi->s_bal_goals),
45920 - atomic_read(&sbi->s_bal_2orders),
45921 - atomic_read(&sbi->s_bal_breaks),
45922 - atomic_read(&sbi->s_mb_lost_chunks));
45923 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45924 + atomic_read_unchecked(&sbi->s_bal_goals),
45925 + atomic_read_unchecked(&sbi->s_bal_2orders),
45926 + atomic_read_unchecked(&sbi->s_bal_breaks),
45927 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45928 ext4_msg(sb, KERN_INFO,
45929 "mballoc: %lu generated and it took %Lu",
45930 sbi->s_mb_buddies_generated,
45931 sbi->s_mb_generation_time);
45932 ext4_msg(sb, KERN_INFO,
45933 "mballoc: %u preallocated, %u discarded",
45934 - atomic_read(&sbi->s_mb_preallocated),
45935 - atomic_read(&sbi->s_mb_discarded));
45936 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45937 + atomic_read_unchecked(&sbi->s_mb_discarded));
45938 }
45939
45940 free_percpu(sbi->s_locality_groups);
45941 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45942 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45943
45944 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45945 - atomic_inc(&sbi->s_bal_reqs);
45946 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45947 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45948 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45949 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45950 - atomic_inc(&sbi->s_bal_success);
45951 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45952 + atomic_inc_unchecked(&sbi->s_bal_success);
45953 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45954 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45955 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45956 - atomic_inc(&sbi->s_bal_goals);
45957 + atomic_inc_unchecked(&sbi->s_bal_goals);
45958 if (ac->ac_found > sbi->s_mb_max_to_scan)
45959 - atomic_inc(&sbi->s_bal_breaks);
45960 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45961 }
45962
45963 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45964 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45965 trace_ext4_mb_new_inode_pa(ac, pa);
45966
45967 ext4_mb_use_inode_pa(ac, pa);
45968 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45969 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45970
45971 ei = EXT4_I(ac->ac_inode);
45972 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45973 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45974 trace_ext4_mb_new_group_pa(ac, pa);
45975
45976 ext4_mb_use_group_pa(ac, pa);
45977 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45978 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45979
45980 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45981 lg = ac->ac_lg;
45982 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45983 * from the bitmap and continue.
45984 */
45985 }
45986 - atomic_add(free, &sbi->s_mb_discarded);
45987 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45988
45989 return err;
45990 }
45991 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45992 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45993 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45994 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45995 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45996 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45997 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45998
45999 return 0;
46000 diff --git a/fs/fcntl.c b/fs/fcntl.c
46001 index 887b5ba..0e3f2c3 100644
46002 --- a/fs/fcntl.c
46003 +++ b/fs/fcntl.c
46004 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46005 if (err)
46006 return err;
46007
46008 + if (gr_handle_chroot_fowner(pid, type))
46009 + return -ENOENT;
46010 + if (gr_check_protected_task_fowner(pid, type))
46011 + return -EACCES;
46012 +
46013 f_modown(filp, pid, type, force);
46014 return 0;
46015 }
46016 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46017
46018 static int f_setown_ex(struct file *filp, unsigned long arg)
46019 {
46020 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46021 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46022 struct f_owner_ex owner;
46023 struct pid *pid;
46024 int type;
46025 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46026
46027 static int f_getown_ex(struct file *filp, unsigned long arg)
46028 {
46029 - struct f_owner_ex * __user owner_p = (void * __user)arg;
46030 + struct f_owner_ex __user *owner_p = (void __user *)arg;
46031 struct f_owner_ex owner;
46032 int ret = 0;
46033
46034 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46035 switch (cmd) {
46036 case F_DUPFD:
46037 case F_DUPFD_CLOEXEC:
46038 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46039 if (arg >= rlimit(RLIMIT_NOFILE))
46040 break;
46041 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46042 diff --git a/fs/fifo.c b/fs/fifo.c
46043 index cf6f434..3d7942c 100644
46044 --- a/fs/fifo.c
46045 +++ b/fs/fifo.c
46046 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46047 */
46048 filp->f_op = &read_pipefifo_fops;
46049 pipe->r_counter++;
46050 - if (pipe->readers++ == 0)
46051 + if (atomic_inc_return(&pipe->readers) == 1)
46052 wake_up_partner(inode);
46053
46054 - if (!pipe->writers) {
46055 + if (!atomic_read(&pipe->writers)) {
46056 if ((filp->f_flags & O_NONBLOCK)) {
46057 /* suppress POLLHUP until we have
46058 * seen a writer */
46059 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46060 * errno=ENXIO when there is no process reading the FIFO.
46061 */
46062 ret = -ENXIO;
46063 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46064 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46065 goto err;
46066
46067 filp->f_op = &write_pipefifo_fops;
46068 pipe->w_counter++;
46069 - if (!pipe->writers++)
46070 + if (atomic_inc_return(&pipe->writers) == 1)
46071 wake_up_partner(inode);
46072
46073 - if (!pipe->readers) {
46074 + if (!atomic_read(&pipe->readers)) {
46075 if (wait_for_partner(inode, &pipe->r_counter))
46076 goto err_wr;
46077 }
46078 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46079 */
46080 filp->f_op = &rdwr_pipefifo_fops;
46081
46082 - pipe->readers++;
46083 - pipe->writers++;
46084 + atomic_inc(&pipe->readers);
46085 + atomic_inc(&pipe->writers);
46086 pipe->r_counter++;
46087 pipe->w_counter++;
46088 - if (pipe->readers == 1 || pipe->writers == 1)
46089 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46090 wake_up_partner(inode);
46091 break;
46092
46093 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46094 return 0;
46095
46096 err_rd:
46097 - if (!--pipe->readers)
46098 + if (atomic_dec_and_test(&pipe->readers))
46099 wake_up_interruptible(&pipe->wait);
46100 ret = -ERESTARTSYS;
46101 goto err;
46102
46103 err_wr:
46104 - if (!--pipe->writers)
46105 + if (atomic_dec_and_test(&pipe->writers))
46106 wake_up_interruptible(&pipe->wait);
46107 ret = -ERESTARTSYS;
46108 goto err;
46109
46110 err:
46111 - if (!pipe->readers && !pipe->writers)
46112 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46113 free_pipe_info(inode);
46114
46115 err_nocleanup:
46116 diff --git a/fs/file.c b/fs/file.c
46117 index ba3f605..fade102 100644
46118 --- a/fs/file.c
46119 +++ b/fs/file.c
46120 @@ -15,6 +15,7 @@
46121 #include <linux/slab.h>
46122 #include <linux/vmalloc.h>
46123 #include <linux/file.h>
46124 +#include <linux/security.h>
46125 #include <linux/fdtable.h>
46126 #include <linux/bitops.h>
46127 #include <linux/interrupt.h>
46128 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46129 * N.B. For clone tasks sharing a files structure, this test
46130 * will limit the total number of files that can be opened.
46131 */
46132 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46133 if (nr >= rlimit(RLIMIT_NOFILE))
46134 return -EMFILE;
46135
46136 diff --git a/fs/filesystems.c b/fs/filesystems.c
46137 index 96f2428..f5eeb8e 100644
46138 --- a/fs/filesystems.c
46139 +++ b/fs/filesystems.c
46140 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46141 int len = dot ? dot - name : strlen(name);
46142
46143 fs = __get_fs_type(name, len);
46144 +
46145 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46146 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46147 +#else
46148 if (!fs && (request_module("%.*s", len, name) == 0))
46149 +#endif
46150 fs = __get_fs_type(name, len);
46151
46152 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46153 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46154 index 5df4775..9d9336f 100644
46155 --- a/fs/fs_struct.c
46156 +++ b/fs/fs_struct.c
46157 @@ -4,6 +4,7 @@
46158 #include <linux/path.h>
46159 #include <linux/slab.h>
46160 #include <linux/fs_struct.h>
46161 +#include <linux/grsecurity.h>
46162 #include "internal.h"
46163
46164 /*
46165 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46166 write_seqcount_begin(&fs->seq);
46167 old_root = fs->root;
46168 fs->root = *path;
46169 + gr_set_chroot_entries(current, path);
46170 write_seqcount_end(&fs->seq);
46171 spin_unlock(&fs->lock);
46172 if (old_root.dentry)
46173 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46174 return 1;
46175 }
46176
46177 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46178 +{
46179 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46180 + return 0;
46181 + *p = *new;
46182 +
46183 + /* This function is only called from pivot_root(). Leave our
46184 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46185 + pivoted root isn't treated as a chroot
46186 + */
46187 + //gr_set_chroot_entries(task, new);
46188 +
46189 + return 1;
46190 +}
46191 +
46192 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46193 {
46194 struct task_struct *g, *p;
46195 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46196 int hits = 0;
46197 spin_lock(&fs->lock);
46198 write_seqcount_begin(&fs->seq);
46199 - hits += replace_path(&fs->root, old_root, new_root);
46200 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46201 hits += replace_path(&fs->pwd, old_root, new_root);
46202 write_seqcount_end(&fs->seq);
46203 while (hits--) {
46204 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
46205 task_lock(tsk);
46206 spin_lock(&fs->lock);
46207 tsk->fs = NULL;
46208 - kill = !--fs->users;
46209 + gr_clear_chroot_entries(tsk);
46210 + kill = !atomic_dec_return(&fs->users);
46211 spin_unlock(&fs->lock);
46212 task_unlock(tsk);
46213 if (kill)
46214 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46215 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46216 /* We don't need to lock fs - think why ;-) */
46217 if (fs) {
46218 - fs->users = 1;
46219 + atomic_set(&fs->users, 1);
46220 fs->in_exec = 0;
46221 spin_lock_init(&fs->lock);
46222 seqcount_init(&fs->seq);
46223 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46224 spin_lock(&old->lock);
46225 fs->root = old->root;
46226 path_get(&fs->root);
46227 + /* instead of calling gr_set_chroot_entries here,
46228 + we call it from every caller of this function
46229 + */
46230 fs->pwd = old->pwd;
46231 path_get(&fs->pwd);
46232 spin_unlock(&old->lock);
46233 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46234
46235 task_lock(current);
46236 spin_lock(&fs->lock);
46237 - kill = !--fs->users;
46238 + kill = !atomic_dec_return(&fs->users);
46239 current->fs = new_fs;
46240 + gr_set_chroot_entries(current, &new_fs->root);
46241 spin_unlock(&fs->lock);
46242 task_unlock(current);
46243
46244 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46245
46246 int current_umask(void)
46247 {
46248 - return current->fs->umask;
46249 + return current->fs->umask | gr_acl_umask();
46250 }
46251 EXPORT_SYMBOL(current_umask);
46252
46253 /* to be mentioned only in INIT_TASK */
46254 struct fs_struct init_fs = {
46255 - .users = 1,
46256 + .users = ATOMIC_INIT(1),
46257 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46258 .seq = SEQCNT_ZERO,
46259 .umask = 0022,
46260 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46261 task_lock(current);
46262
46263 spin_lock(&init_fs.lock);
46264 - init_fs.users++;
46265 + atomic_inc(&init_fs.users);
46266 spin_unlock(&init_fs.lock);
46267
46268 spin_lock(&fs->lock);
46269 current->fs = &init_fs;
46270 - kill = !--fs->users;
46271 + gr_set_chroot_entries(current, &current->fs->root);
46272 + kill = !atomic_dec_return(&fs->users);
46273 spin_unlock(&fs->lock);
46274
46275 task_unlock(current);
46276 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46277 index 9905350..02eaec4 100644
46278 --- a/fs/fscache/cookie.c
46279 +++ b/fs/fscache/cookie.c
46280 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46281 parent ? (char *) parent->def->name : "<no-parent>",
46282 def->name, netfs_data);
46283
46284 - fscache_stat(&fscache_n_acquires);
46285 + fscache_stat_unchecked(&fscache_n_acquires);
46286
46287 /* if there's no parent cookie, then we don't create one here either */
46288 if (!parent) {
46289 - fscache_stat(&fscache_n_acquires_null);
46290 + fscache_stat_unchecked(&fscache_n_acquires_null);
46291 _leave(" [no parent]");
46292 return NULL;
46293 }
46294 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46295 /* allocate and initialise a cookie */
46296 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46297 if (!cookie) {
46298 - fscache_stat(&fscache_n_acquires_oom);
46299 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46300 _leave(" [ENOMEM]");
46301 return NULL;
46302 }
46303 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46304
46305 switch (cookie->def->type) {
46306 case FSCACHE_COOKIE_TYPE_INDEX:
46307 - fscache_stat(&fscache_n_cookie_index);
46308 + fscache_stat_unchecked(&fscache_n_cookie_index);
46309 break;
46310 case FSCACHE_COOKIE_TYPE_DATAFILE:
46311 - fscache_stat(&fscache_n_cookie_data);
46312 + fscache_stat_unchecked(&fscache_n_cookie_data);
46313 break;
46314 default:
46315 - fscache_stat(&fscache_n_cookie_special);
46316 + fscache_stat_unchecked(&fscache_n_cookie_special);
46317 break;
46318 }
46319
46320 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46321 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46322 atomic_dec(&parent->n_children);
46323 __fscache_cookie_put(cookie);
46324 - fscache_stat(&fscache_n_acquires_nobufs);
46325 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46326 _leave(" = NULL");
46327 return NULL;
46328 }
46329 }
46330
46331 - fscache_stat(&fscache_n_acquires_ok);
46332 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46333 _leave(" = %p", cookie);
46334 return cookie;
46335 }
46336 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46337 cache = fscache_select_cache_for_object(cookie->parent);
46338 if (!cache) {
46339 up_read(&fscache_addremove_sem);
46340 - fscache_stat(&fscache_n_acquires_no_cache);
46341 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46342 _leave(" = -ENOMEDIUM [no cache]");
46343 return -ENOMEDIUM;
46344 }
46345 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46346 object = cache->ops->alloc_object(cache, cookie);
46347 fscache_stat_d(&fscache_n_cop_alloc_object);
46348 if (IS_ERR(object)) {
46349 - fscache_stat(&fscache_n_object_no_alloc);
46350 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46351 ret = PTR_ERR(object);
46352 goto error;
46353 }
46354
46355 - fscache_stat(&fscache_n_object_alloc);
46356 + fscache_stat_unchecked(&fscache_n_object_alloc);
46357
46358 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46359
46360 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46361 struct fscache_object *object;
46362 struct hlist_node *_p;
46363
46364 - fscache_stat(&fscache_n_updates);
46365 + fscache_stat_unchecked(&fscache_n_updates);
46366
46367 if (!cookie) {
46368 - fscache_stat(&fscache_n_updates_null);
46369 + fscache_stat_unchecked(&fscache_n_updates_null);
46370 _leave(" [no cookie]");
46371 return;
46372 }
46373 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46374 struct fscache_object *object;
46375 unsigned long event;
46376
46377 - fscache_stat(&fscache_n_relinquishes);
46378 + fscache_stat_unchecked(&fscache_n_relinquishes);
46379 if (retire)
46380 - fscache_stat(&fscache_n_relinquishes_retire);
46381 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46382
46383 if (!cookie) {
46384 - fscache_stat(&fscache_n_relinquishes_null);
46385 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46386 _leave(" [no cookie]");
46387 return;
46388 }
46389 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46390
46391 /* wait for the cookie to finish being instantiated (or to fail) */
46392 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46393 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46394 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46395 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46396 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46397 }
46398 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46399 index f6aad48..88dcf26 100644
46400 --- a/fs/fscache/internal.h
46401 +++ b/fs/fscache/internal.h
46402 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46403 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46404 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46405
46406 -extern atomic_t fscache_n_op_pend;
46407 -extern atomic_t fscache_n_op_run;
46408 -extern atomic_t fscache_n_op_enqueue;
46409 -extern atomic_t fscache_n_op_deferred_release;
46410 -extern atomic_t fscache_n_op_release;
46411 -extern atomic_t fscache_n_op_gc;
46412 -extern atomic_t fscache_n_op_cancelled;
46413 -extern atomic_t fscache_n_op_rejected;
46414 +extern atomic_unchecked_t fscache_n_op_pend;
46415 +extern atomic_unchecked_t fscache_n_op_run;
46416 +extern atomic_unchecked_t fscache_n_op_enqueue;
46417 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46418 +extern atomic_unchecked_t fscache_n_op_release;
46419 +extern atomic_unchecked_t fscache_n_op_gc;
46420 +extern atomic_unchecked_t fscache_n_op_cancelled;
46421 +extern atomic_unchecked_t fscache_n_op_rejected;
46422
46423 -extern atomic_t fscache_n_attr_changed;
46424 -extern atomic_t fscache_n_attr_changed_ok;
46425 -extern atomic_t fscache_n_attr_changed_nobufs;
46426 -extern atomic_t fscache_n_attr_changed_nomem;
46427 -extern atomic_t fscache_n_attr_changed_calls;
46428 +extern atomic_unchecked_t fscache_n_attr_changed;
46429 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46430 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46431 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46432 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46433
46434 -extern atomic_t fscache_n_allocs;
46435 -extern atomic_t fscache_n_allocs_ok;
46436 -extern atomic_t fscache_n_allocs_wait;
46437 -extern atomic_t fscache_n_allocs_nobufs;
46438 -extern atomic_t fscache_n_allocs_intr;
46439 -extern atomic_t fscache_n_allocs_object_dead;
46440 -extern atomic_t fscache_n_alloc_ops;
46441 -extern atomic_t fscache_n_alloc_op_waits;
46442 +extern atomic_unchecked_t fscache_n_allocs;
46443 +extern atomic_unchecked_t fscache_n_allocs_ok;
46444 +extern atomic_unchecked_t fscache_n_allocs_wait;
46445 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46446 +extern atomic_unchecked_t fscache_n_allocs_intr;
46447 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46448 +extern atomic_unchecked_t fscache_n_alloc_ops;
46449 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46450
46451 -extern atomic_t fscache_n_retrievals;
46452 -extern atomic_t fscache_n_retrievals_ok;
46453 -extern atomic_t fscache_n_retrievals_wait;
46454 -extern atomic_t fscache_n_retrievals_nodata;
46455 -extern atomic_t fscache_n_retrievals_nobufs;
46456 -extern atomic_t fscache_n_retrievals_intr;
46457 -extern atomic_t fscache_n_retrievals_nomem;
46458 -extern atomic_t fscache_n_retrievals_object_dead;
46459 -extern atomic_t fscache_n_retrieval_ops;
46460 -extern atomic_t fscache_n_retrieval_op_waits;
46461 +extern atomic_unchecked_t fscache_n_retrievals;
46462 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46463 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46464 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46465 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46466 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46467 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46468 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46469 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46470 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46471
46472 -extern atomic_t fscache_n_stores;
46473 -extern atomic_t fscache_n_stores_ok;
46474 -extern atomic_t fscache_n_stores_again;
46475 -extern atomic_t fscache_n_stores_nobufs;
46476 -extern atomic_t fscache_n_stores_oom;
46477 -extern atomic_t fscache_n_store_ops;
46478 -extern atomic_t fscache_n_store_calls;
46479 -extern atomic_t fscache_n_store_pages;
46480 -extern atomic_t fscache_n_store_radix_deletes;
46481 -extern atomic_t fscache_n_store_pages_over_limit;
46482 +extern atomic_unchecked_t fscache_n_stores;
46483 +extern atomic_unchecked_t fscache_n_stores_ok;
46484 +extern atomic_unchecked_t fscache_n_stores_again;
46485 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46486 +extern atomic_unchecked_t fscache_n_stores_oom;
46487 +extern atomic_unchecked_t fscache_n_store_ops;
46488 +extern atomic_unchecked_t fscache_n_store_calls;
46489 +extern atomic_unchecked_t fscache_n_store_pages;
46490 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46491 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46492
46493 -extern atomic_t fscache_n_store_vmscan_not_storing;
46494 -extern atomic_t fscache_n_store_vmscan_gone;
46495 -extern atomic_t fscache_n_store_vmscan_busy;
46496 -extern atomic_t fscache_n_store_vmscan_cancelled;
46497 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46498 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46499 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46500 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46501
46502 -extern atomic_t fscache_n_marks;
46503 -extern atomic_t fscache_n_uncaches;
46504 +extern atomic_unchecked_t fscache_n_marks;
46505 +extern atomic_unchecked_t fscache_n_uncaches;
46506
46507 -extern atomic_t fscache_n_acquires;
46508 -extern atomic_t fscache_n_acquires_null;
46509 -extern atomic_t fscache_n_acquires_no_cache;
46510 -extern atomic_t fscache_n_acquires_ok;
46511 -extern atomic_t fscache_n_acquires_nobufs;
46512 -extern atomic_t fscache_n_acquires_oom;
46513 +extern atomic_unchecked_t fscache_n_acquires;
46514 +extern atomic_unchecked_t fscache_n_acquires_null;
46515 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46516 +extern atomic_unchecked_t fscache_n_acquires_ok;
46517 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46518 +extern atomic_unchecked_t fscache_n_acquires_oom;
46519
46520 -extern atomic_t fscache_n_updates;
46521 -extern atomic_t fscache_n_updates_null;
46522 -extern atomic_t fscache_n_updates_run;
46523 +extern atomic_unchecked_t fscache_n_updates;
46524 +extern atomic_unchecked_t fscache_n_updates_null;
46525 +extern atomic_unchecked_t fscache_n_updates_run;
46526
46527 -extern atomic_t fscache_n_relinquishes;
46528 -extern atomic_t fscache_n_relinquishes_null;
46529 -extern atomic_t fscache_n_relinquishes_waitcrt;
46530 -extern atomic_t fscache_n_relinquishes_retire;
46531 +extern atomic_unchecked_t fscache_n_relinquishes;
46532 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46533 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46534 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46535
46536 -extern atomic_t fscache_n_cookie_index;
46537 -extern atomic_t fscache_n_cookie_data;
46538 -extern atomic_t fscache_n_cookie_special;
46539 +extern atomic_unchecked_t fscache_n_cookie_index;
46540 +extern atomic_unchecked_t fscache_n_cookie_data;
46541 +extern atomic_unchecked_t fscache_n_cookie_special;
46542
46543 -extern atomic_t fscache_n_object_alloc;
46544 -extern atomic_t fscache_n_object_no_alloc;
46545 -extern atomic_t fscache_n_object_lookups;
46546 -extern atomic_t fscache_n_object_lookups_negative;
46547 -extern atomic_t fscache_n_object_lookups_positive;
46548 -extern atomic_t fscache_n_object_lookups_timed_out;
46549 -extern atomic_t fscache_n_object_created;
46550 -extern atomic_t fscache_n_object_avail;
46551 -extern atomic_t fscache_n_object_dead;
46552 +extern atomic_unchecked_t fscache_n_object_alloc;
46553 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46554 +extern atomic_unchecked_t fscache_n_object_lookups;
46555 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46556 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46557 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46558 +extern atomic_unchecked_t fscache_n_object_created;
46559 +extern atomic_unchecked_t fscache_n_object_avail;
46560 +extern atomic_unchecked_t fscache_n_object_dead;
46561
46562 -extern atomic_t fscache_n_checkaux_none;
46563 -extern atomic_t fscache_n_checkaux_okay;
46564 -extern atomic_t fscache_n_checkaux_update;
46565 -extern atomic_t fscache_n_checkaux_obsolete;
46566 +extern atomic_unchecked_t fscache_n_checkaux_none;
46567 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46568 +extern atomic_unchecked_t fscache_n_checkaux_update;
46569 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46570
46571 extern atomic_t fscache_n_cop_alloc_object;
46572 extern atomic_t fscache_n_cop_lookup_object;
46573 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46574 atomic_inc(stat);
46575 }
46576
46577 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46578 +{
46579 + atomic_inc_unchecked(stat);
46580 +}
46581 +
46582 static inline void fscache_stat_d(atomic_t *stat)
46583 {
46584 atomic_dec(stat);
46585 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46586
46587 #define __fscache_stat(stat) (NULL)
46588 #define fscache_stat(stat) do {} while (0)
46589 +#define fscache_stat_unchecked(stat) do {} while (0)
46590 #define fscache_stat_d(stat) do {} while (0)
46591 #endif
46592
46593 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46594 index b6b897c..0ffff9c 100644
46595 --- a/fs/fscache/object.c
46596 +++ b/fs/fscache/object.c
46597 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46598 /* update the object metadata on disk */
46599 case FSCACHE_OBJECT_UPDATING:
46600 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46601 - fscache_stat(&fscache_n_updates_run);
46602 + fscache_stat_unchecked(&fscache_n_updates_run);
46603 fscache_stat(&fscache_n_cop_update_object);
46604 object->cache->ops->update_object(object);
46605 fscache_stat_d(&fscache_n_cop_update_object);
46606 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46607 spin_lock(&object->lock);
46608 object->state = FSCACHE_OBJECT_DEAD;
46609 spin_unlock(&object->lock);
46610 - fscache_stat(&fscache_n_object_dead);
46611 + fscache_stat_unchecked(&fscache_n_object_dead);
46612 goto terminal_transit;
46613
46614 /* handle the parent cache of this object being withdrawn from
46615 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46616 spin_lock(&object->lock);
46617 object->state = FSCACHE_OBJECT_DEAD;
46618 spin_unlock(&object->lock);
46619 - fscache_stat(&fscache_n_object_dead);
46620 + fscache_stat_unchecked(&fscache_n_object_dead);
46621 goto terminal_transit;
46622
46623 /* complain about the object being woken up once it is
46624 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46625 parent->cookie->def->name, cookie->def->name,
46626 object->cache->tag->name);
46627
46628 - fscache_stat(&fscache_n_object_lookups);
46629 + fscache_stat_unchecked(&fscache_n_object_lookups);
46630 fscache_stat(&fscache_n_cop_lookup_object);
46631 ret = object->cache->ops->lookup_object(object);
46632 fscache_stat_d(&fscache_n_cop_lookup_object);
46633 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46634 if (ret == -ETIMEDOUT) {
46635 /* probably stuck behind another object, so move this one to
46636 * the back of the queue */
46637 - fscache_stat(&fscache_n_object_lookups_timed_out);
46638 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46639 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46640 }
46641
46642 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46643
46644 spin_lock(&object->lock);
46645 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46646 - fscache_stat(&fscache_n_object_lookups_negative);
46647 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46648
46649 /* transit here to allow write requests to begin stacking up
46650 * and read requests to begin returning ENODATA */
46651 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46652 * result, in which case there may be data available */
46653 spin_lock(&object->lock);
46654 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46655 - fscache_stat(&fscache_n_object_lookups_positive);
46656 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46657
46658 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46659
46660 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46661 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46662 } else {
46663 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46664 - fscache_stat(&fscache_n_object_created);
46665 + fscache_stat_unchecked(&fscache_n_object_created);
46666
46667 object->state = FSCACHE_OBJECT_AVAILABLE;
46668 spin_unlock(&object->lock);
46669 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46670 fscache_enqueue_dependents(object);
46671
46672 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46673 - fscache_stat(&fscache_n_object_avail);
46674 + fscache_stat_unchecked(&fscache_n_object_avail);
46675
46676 _leave("");
46677 }
46678 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46679 enum fscache_checkaux result;
46680
46681 if (!object->cookie->def->check_aux) {
46682 - fscache_stat(&fscache_n_checkaux_none);
46683 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46684 return FSCACHE_CHECKAUX_OKAY;
46685 }
46686
46687 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46688 switch (result) {
46689 /* entry okay as is */
46690 case FSCACHE_CHECKAUX_OKAY:
46691 - fscache_stat(&fscache_n_checkaux_okay);
46692 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46693 break;
46694
46695 /* entry requires update */
46696 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46697 - fscache_stat(&fscache_n_checkaux_update);
46698 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46699 break;
46700
46701 /* entry requires deletion */
46702 case FSCACHE_CHECKAUX_OBSOLETE:
46703 - fscache_stat(&fscache_n_checkaux_obsolete);
46704 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46705 break;
46706
46707 default:
46708 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46709 index 30afdfa..2256596 100644
46710 --- a/fs/fscache/operation.c
46711 +++ b/fs/fscache/operation.c
46712 @@ -17,7 +17,7 @@
46713 #include <linux/slab.h>
46714 #include "internal.h"
46715
46716 -atomic_t fscache_op_debug_id;
46717 +atomic_unchecked_t fscache_op_debug_id;
46718 EXPORT_SYMBOL(fscache_op_debug_id);
46719
46720 /**
46721 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46722 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46723 ASSERTCMP(atomic_read(&op->usage), >, 0);
46724
46725 - fscache_stat(&fscache_n_op_enqueue);
46726 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46727 switch (op->flags & FSCACHE_OP_TYPE) {
46728 case FSCACHE_OP_ASYNC:
46729 _debug("queue async");
46730 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46731 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46732 if (op->processor)
46733 fscache_enqueue_operation(op);
46734 - fscache_stat(&fscache_n_op_run);
46735 + fscache_stat_unchecked(&fscache_n_op_run);
46736 }
46737
46738 /*
46739 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46740 if (object->n_ops > 1) {
46741 atomic_inc(&op->usage);
46742 list_add_tail(&op->pend_link, &object->pending_ops);
46743 - fscache_stat(&fscache_n_op_pend);
46744 + fscache_stat_unchecked(&fscache_n_op_pend);
46745 } else if (!list_empty(&object->pending_ops)) {
46746 atomic_inc(&op->usage);
46747 list_add_tail(&op->pend_link, &object->pending_ops);
46748 - fscache_stat(&fscache_n_op_pend);
46749 + fscache_stat_unchecked(&fscache_n_op_pend);
46750 fscache_start_operations(object);
46751 } else {
46752 ASSERTCMP(object->n_in_progress, ==, 0);
46753 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46754 object->n_exclusive++; /* reads and writes must wait */
46755 atomic_inc(&op->usage);
46756 list_add_tail(&op->pend_link, &object->pending_ops);
46757 - fscache_stat(&fscache_n_op_pend);
46758 + fscache_stat_unchecked(&fscache_n_op_pend);
46759 ret = 0;
46760 } else {
46761 /* not allowed to submit ops in any other state */
46762 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46763 if (object->n_exclusive > 0) {
46764 atomic_inc(&op->usage);
46765 list_add_tail(&op->pend_link, &object->pending_ops);
46766 - fscache_stat(&fscache_n_op_pend);
46767 + fscache_stat_unchecked(&fscache_n_op_pend);
46768 } else if (!list_empty(&object->pending_ops)) {
46769 atomic_inc(&op->usage);
46770 list_add_tail(&op->pend_link, &object->pending_ops);
46771 - fscache_stat(&fscache_n_op_pend);
46772 + fscache_stat_unchecked(&fscache_n_op_pend);
46773 fscache_start_operations(object);
46774 } else {
46775 ASSERTCMP(object->n_exclusive, ==, 0);
46776 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46777 object->n_ops++;
46778 atomic_inc(&op->usage);
46779 list_add_tail(&op->pend_link, &object->pending_ops);
46780 - fscache_stat(&fscache_n_op_pend);
46781 + fscache_stat_unchecked(&fscache_n_op_pend);
46782 ret = 0;
46783 } else if (object->state == FSCACHE_OBJECT_DYING ||
46784 object->state == FSCACHE_OBJECT_LC_DYING ||
46785 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46786 - fscache_stat(&fscache_n_op_rejected);
46787 + fscache_stat_unchecked(&fscache_n_op_rejected);
46788 ret = -ENOBUFS;
46789 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46790 fscache_report_unexpected_submission(object, op, ostate);
46791 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46792
46793 ret = -EBUSY;
46794 if (!list_empty(&op->pend_link)) {
46795 - fscache_stat(&fscache_n_op_cancelled);
46796 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46797 list_del_init(&op->pend_link);
46798 object->n_ops--;
46799 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46800 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46801 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46802 BUG();
46803
46804 - fscache_stat(&fscache_n_op_release);
46805 + fscache_stat_unchecked(&fscache_n_op_release);
46806
46807 if (op->release) {
46808 op->release(op);
46809 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46810 * lock, and defer it otherwise */
46811 if (!spin_trylock(&object->lock)) {
46812 _debug("defer put");
46813 - fscache_stat(&fscache_n_op_deferred_release);
46814 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46815
46816 cache = object->cache;
46817 spin_lock(&cache->op_gc_list_lock);
46818 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46819
46820 _debug("GC DEFERRED REL OBJ%x OP%x",
46821 object->debug_id, op->debug_id);
46822 - fscache_stat(&fscache_n_op_gc);
46823 + fscache_stat_unchecked(&fscache_n_op_gc);
46824
46825 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46826
46827 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46828 index 3f7a59b..cf196cc 100644
46829 --- a/fs/fscache/page.c
46830 +++ b/fs/fscache/page.c
46831 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46832 val = radix_tree_lookup(&cookie->stores, page->index);
46833 if (!val) {
46834 rcu_read_unlock();
46835 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46836 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46837 __fscache_uncache_page(cookie, page);
46838 return true;
46839 }
46840 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46841 spin_unlock(&cookie->stores_lock);
46842
46843 if (xpage) {
46844 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46845 - fscache_stat(&fscache_n_store_radix_deletes);
46846 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46847 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46848 ASSERTCMP(xpage, ==, page);
46849 } else {
46850 - fscache_stat(&fscache_n_store_vmscan_gone);
46851 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46852 }
46853
46854 wake_up_bit(&cookie->flags, 0);
46855 @@ -107,7 +107,7 @@ page_busy:
46856 /* we might want to wait here, but that could deadlock the allocator as
46857 * the work threads writing to the cache may all end up sleeping
46858 * on memory allocation */
46859 - fscache_stat(&fscache_n_store_vmscan_busy);
46860 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46861 return false;
46862 }
46863 EXPORT_SYMBOL(__fscache_maybe_release_page);
46864 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46865 FSCACHE_COOKIE_STORING_TAG);
46866 if (!radix_tree_tag_get(&cookie->stores, page->index,
46867 FSCACHE_COOKIE_PENDING_TAG)) {
46868 - fscache_stat(&fscache_n_store_radix_deletes);
46869 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46870 xpage = radix_tree_delete(&cookie->stores, page->index);
46871 }
46872 spin_unlock(&cookie->stores_lock);
46873 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46874
46875 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46876
46877 - fscache_stat(&fscache_n_attr_changed_calls);
46878 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46879
46880 if (fscache_object_is_active(object)) {
46881 fscache_stat(&fscache_n_cop_attr_changed);
46882 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46883
46884 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46885
46886 - fscache_stat(&fscache_n_attr_changed);
46887 + fscache_stat_unchecked(&fscache_n_attr_changed);
46888
46889 op = kzalloc(sizeof(*op), GFP_KERNEL);
46890 if (!op) {
46891 - fscache_stat(&fscache_n_attr_changed_nomem);
46892 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46893 _leave(" = -ENOMEM");
46894 return -ENOMEM;
46895 }
46896 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46897 if (fscache_submit_exclusive_op(object, op) < 0)
46898 goto nobufs;
46899 spin_unlock(&cookie->lock);
46900 - fscache_stat(&fscache_n_attr_changed_ok);
46901 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46902 fscache_put_operation(op);
46903 _leave(" = 0");
46904 return 0;
46905 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46906 nobufs:
46907 spin_unlock(&cookie->lock);
46908 kfree(op);
46909 - fscache_stat(&fscache_n_attr_changed_nobufs);
46910 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46911 _leave(" = %d", -ENOBUFS);
46912 return -ENOBUFS;
46913 }
46914 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46915 /* allocate a retrieval operation and attempt to submit it */
46916 op = kzalloc(sizeof(*op), GFP_NOIO);
46917 if (!op) {
46918 - fscache_stat(&fscache_n_retrievals_nomem);
46919 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46920 return NULL;
46921 }
46922
46923 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46924 return 0;
46925 }
46926
46927 - fscache_stat(&fscache_n_retrievals_wait);
46928 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46929
46930 jif = jiffies;
46931 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46932 fscache_wait_bit_interruptible,
46933 TASK_INTERRUPTIBLE) != 0) {
46934 - fscache_stat(&fscache_n_retrievals_intr);
46935 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46936 _leave(" = -ERESTARTSYS");
46937 return -ERESTARTSYS;
46938 }
46939 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46940 */
46941 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46942 struct fscache_retrieval *op,
46943 - atomic_t *stat_op_waits,
46944 - atomic_t *stat_object_dead)
46945 + atomic_unchecked_t *stat_op_waits,
46946 + atomic_unchecked_t *stat_object_dead)
46947 {
46948 int ret;
46949
46950 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46951 goto check_if_dead;
46952
46953 _debug(">>> WT");
46954 - fscache_stat(stat_op_waits);
46955 + fscache_stat_unchecked(stat_op_waits);
46956 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46957 fscache_wait_bit_interruptible,
46958 TASK_INTERRUPTIBLE) < 0) {
46959 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46960
46961 check_if_dead:
46962 if (unlikely(fscache_object_is_dead(object))) {
46963 - fscache_stat(stat_object_dead);
46964 + fscache_stat_unchecked(stat_object_dead);
46965 return -ENOBUFS;
46966 }
46967 return 0;
46968 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46969
46970 _enter("%p,%p,,,", cookie, page);
46971
46972 - fscache_stat(&fscache_n_retrievals);
46973 + fscache_stat_unchecked(&fscache_n_retrievals);
46974
46975 if (hlist_empty(&cookie->backing_objects))
46976 goto nobufs;
46977 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46978 goto nobufs_unlock;
46979 spin_unlock(&cookie->lock);
46980
46981 - fscache_stat(&fscache_n_retrieval_ops);
46982 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46983
46984 /* pin the netfs read context in case we need to do the actual netfs
46985 * read because we've encountered a cache read failure */
46986 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46987
46988 error:
46989 if (ret == -ENOMEM)
46990 - fscache_stat(&fscache_n_retrievals_nomem);
46991 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46992 else if (ret == -ERESTARTSYS)
46993 - fscache_stat(&fscache_n_retrievals_intr);
46994 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46995 else if (ret == -ENODATA)
46996 - fscache_stat(&fscache_n_retrievals_nodata);
46997 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46998 else if (ret < 0)
46999 - fscache_stat(&fscache_n_retrievals_nobufs);
47000 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47001 else
47002 - fscache_stat(&fscache_n_retrievals_ok);
47003 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47004
47005 fscache_put_retrieval(op);
47006 _leave(" = %d", ret);
47007 @@ -429,7 +429,7 @@ nobufs_unlock:
47008 spin_unlock(&cookie->lock);
47009 kfree(op);
47010 nobufs:
47011 - fscache_stat(&fscache_n_retrievals_nobufs);
47012 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47013 _leave(" = -ENOBUFS");
47014 return -ENOBUFS;
47015 }
47016 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47017
47018 _enter("%p,,%d,,,", cookie, *nr_pages);
47019
47020 - fscache_stat(&fscache_n_retrievals);
47021 + fscache_stat_unchecked(&fscache_n_retrievals);
47022
47023 if (hlist_empty(&cookie->backing_objects))
47024 goto nobufs;
47025 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47026 goto nobufs_unlock;
47027 spin_unlock(&cookie->lock);
47028
47029 - fscache_stat(&fscache_n_retrieval_ops);
47030 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
47031
47032 /* pin the netfs read context in case we need to do the actual netfs
47033 * read because we've encountered a cache read failure */
47034 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47035
47036 error:
47037 if (ret == -ENOMEM)
47038 - fscache_stat(&fscache_n_retrievals_nomem);
47039 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47040 else if (ret == -ERESTARTSYS)
47041 - fscache_stat(&fscache_n_retrievals_intr);
47042 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47043 else if (ret == -ENODATA)
47044 - fscache_stat(&fscache_n_retrievals_nodata);
47045 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47046 else if (ret < 0)
47047 - fscache_stat(&fscache_n_retrievals_nobufs);
47048 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47049 else
47050 - fscache_stat(&fscache_n_retrievals_ok);
47051 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47052
47053 fscache_put_retrieval(op);
47054 _leave(" = %d", ret);
47055 @@ -545,7 +545,7 @@ nobufs_unlock:
47056 spin_unlock(&cookie->lock);
47057 kfree(op);
47058 nobufs:
47059 - fscache_stat(&fscache_n_retrievals_nobufs);
47060 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47061 _leave(" = -ENOBUFS");
47062 return -ENOBUFS;
47063 }
47064 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47065
47066 _enter("%p,%p,,,", cookie, page);
47067
47068 - fscache_stat(&fscache_n_allocs);
47069 + fscache_stat_unchecked(&fscache_n_allocs);
47070
47071 if (hlist_empty(&cookie->backing_objects))
47072 goto nobufs;
47073 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47074 goto nobufs_unlock;
47075 spin_unlock(&cookie->lock);
47076
47077 - fscache_stat(&fscache_n_alloc_ops);
47078 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47079
47080 ret = fscache_wait_for_retrieval_activation(
47081 object, op,
47082 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47083
47084 error:
47085 if (ret == -ERESTARTSYS)
47086 - fscache_stat(&fscache_n_allocs_intr);
47087 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47088 else if (ret < 0)
47089 - fscache_stat(&fscache_n_allocs_nobufs);
47090 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47091 else
47092 - fscache_stat(&fscache_n_allocs_ok);
47093 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47094
47095 fscache_put_retrieval(op);
47096 _leave(" = %d", ret);
47097 @@ -625,7 +625,7 @@ nobufs_unlock:
47098 spin_unlock(&cookie->lock);
47099 kfree(op);
47100 nobufs:
47101 - fscache_stat(&fscache_n_allocs_nobufs);
47102 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47103 _leave(" = -ENOBUFS");
47104 return -ENOBUFS;
47105 }
47106 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47107
47108 spin_lock(&cookie->stores_lock);
47109
47110 - fscache_stat(&fscache_n_store_calls);
47111 + fscache_stat_unchecked(&fscache_n_store_calls);
47112
47113 /* find a page to store */
47114 page = NULL;
47115 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47116 page = results[0];
47117 _debug("gang %d [%lx]", n, page->index);
47118 if (page->index > op->store_limit) {
47119 - fscache_stat(&fscache_n_store_pages_over_limit);
47120 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47121 goto superseded;
47122 }
47123
47124 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47125 spin_unlock(&cookie->stores_lock);
47126 spin_unlock(&object->lock);
47127
47128 - fscache_stat(&fscache_n_store_pages);
47129 + fscache_stat_unchecked(&fscache_n_store_pages);
47130 fscache_stat(&fscache_n_cop_write_page);
47131 ret = object->cache->ops->write_page(op, page);
47132 fscache_stat_d(&fscache_n_cop_write_page);
47133 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47134 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47135 ASSERT(PageFsCache(page));
47136
47137 - fscache_stat(&fscache_n_stores);
47138 + fscache_stat_unchecked(&fscache_n_stores);
47139
47140 op = kzalloc(sizeof(*op), GFP_NOIO);
47141 if (!op)
47142 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47143 spin_unlock(&cookie->stores_lock);
47144 spin_unlock(&object->lock);
47145
47146 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47147 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47148 op->store_limit = object->store_limit;
47149
47150 if (fscache_submit_op(object, &op->op) < 0)
47151 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47152
47153 spin_unlock(&cookie->lock);
47154 radix_tree_preload_end();
47155 - fscache_stat(&fscache_n_store_ops);
47156 - fscache_stat(&fscache_n_stores_ok);
47157 + fscache_stat_unchecked(&fscache_n_store_ops);
47158 + fscache_stat_unchecked(&fscache_n_stores_ok);
47159
47160 /* the work queue now carries its own ref on the object */
47161 fscache_put_operation(&op->op);
47162 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47163 return 0;
47164
47165 already_queued:
47166 - fscache_stat(&fscache_n_stores_again);
47167 + fscache_stat_unchecked(&fscache_n_stores_again);
47168 already_pending:
47169 spin_unlock(&cookie->stores_lock);
47170 spin_unlock(&object->lock);
47171 spin_unlock(&cookie->lock);
47172 radix_tree_preload_end();
47173 kfree(op);
47174 - fscache_stat(&fscache_n_stores_ok);
47175 + fscache_stat_unchecked(&fscache_n_stores_ok);
47176 _leave(" = 0");
47177 return 0;
47178
47179 @@ -851,14 +851,14 @@ nobufs:
47180 spin_unlock(&cookie->lock);
47181 radix_tree_preload_end();
47182 kfree(op);
47183 - fscache_stat(&fscache_n_stores_nobufs);
47184 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47185 _leave(" = -ENOBUFS");
47186 return -ENOBUFS;
47187
47188 nomem_free:
47189 kfree(op);
47190 nomem:
47191 - fscache_stat(&fscache_n_stores_oom);
47192 + fscache_stat_unchecked(&fscache_n_stores_oom);
47193 _leave(" = -ENOMEM");
47194 return -ENOMEM;
47195 }
47196 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47197 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47198 ASSERTCMP(page, !=, NULL);
47199
47200 - fscache_stat(&fscache_n_uncaches);
47201 + fscache_stat_unchecked(&fscache_n_uncaches);
47202
47203 /* cache withdrawal may beat us to it */
47204 if (!PageFsCache(page))
47205 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47206 unsigned long loop;
47207
47208 #ifdef CONFIG_FSCACHE_STATS
47209 - atomic_add(pagevec->nr, &fscache_n_marks);
47210 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47211 #endif
47212
47213 for (loop = 0; loop < pagevec->nr; loop++) {
47214 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47215 index 4765190..2a067f2 100644
47216 --- a/fs/fscache/stats.c
47217 +++ b/fs/fscache/stats.c
47218 @@ -18,95 +18,95 @@
47219 /*
47220 * operation counters
47221 */
47222 -atomic_t fscache_n_op_pend;
47223 -atomic_t fscache_n_op_run;
47224 -atomic_t fscache_n_op_enqueue;
47225 -atomic_t fscache_n_op_requeue;
47226 -atomic_t fscache_n_op_deferred_release;
47227 -atomic_t fscache_n_op_release;
47228 -atomic_t fscache_n_op_gc;
47229 -atomic_t fscache_n_op_cancelled;
47230 -atomic_t fscache_n_op_rejected;
47231 +atomic_unchecked_t fscache_n_op_pend;
47232 +atomic_unchecked_t fscache_n_op_run;
47233 +atomic_unchecked_t fscache_n_op_enqueue;
47234 +atomic_unchecked_t fscache_n_op_requeue;
47235 +atomic_unchecked_t fscache_n_op_deferred_release;
47236 +atomic_unchecked_t fscache_n_op_release;
47237 +atomic_unchecked_t fscache_n_op_gc;
47238 +atomic_unchecked_t fscache_n_op_cancelled;
47239 +atomic_unchecked_t fscache_n_op_rejected;
47240
47241 -atomic_t fscache_n_attr_changed;
47242 -atomic_t fscache_n_attr_changed_ok;
47243 -atomic_t fscache_n_attr_changed_nobufs;
47244 -atomic_t fscache_n_attr_changed_nomem;
47245 -atomic_t fscache_n_attr_changed_calls;
47246 +atomic_unchecked_t fscache_n_attr_changed;
47247 +atomic_unchecked_t fscache_n_attr_changed_ok;
47248 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47249 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47250 +atomic_unchecked_t fscache_n_attr_changed_calls;
47251
47252 -atomic_t fscache_n_allocs;
47253 -atomic_t fscache_n_allocs_ok;
47254 -atomic_t fscache_n_allocs_wait;
47255 -atomic_t fscache_n_allocs_nobufs;
47256 -atomic_t fscache_n_allocs_intr;
47257 -atomic_t fscache_n_allocs_object_dead;
47258 -atomic_t fscache_n_alloc_ops;
47259 -atomic_t fscache_n_alloc_op_waits;
47260 +atomic_unchecked_t fscache_n_allocs;
47261 +atomic_unchecked_t fscache_n_allocs_ok;
47262 +atomic_unchecked_t fscache_n_allocs_wait;
47263 +atomic_unchecked_t fscache_n_allocs_nobufs;
47264 +atomic_unchecked_t fscache_n_allocs_intr;
47265 +atomic_unchecked_t fscache_n_allocs_object_dead;
47266 +atomic_unchecked_t fscache_n_alloc_ops;
47267 +atomic_unchecked_t fscache_n_alloc_op_waits;
47268
47269 -atomic_t fscache_n_retrievals;
47270 -atomic_t fscache_n_retrievals_ok;
47271 -atomic_t fscache_n_retrievals_wait;
47272 -atomic_t fscache_n_retrievals_nodata;
47273 -atomic_t fscache_n_retrievals_nobufs;
47274 -atomic_t fscache_n_retrievals_intr;
47275 -atomic_t fscache_n_retrievals_nomem;
47276 -atomic_t fscache_n_retrievals_object_dead;
47277 -atomic_t fscache_n_retrieval_ops;
47278 -atomic_t fscache_n_retrieval_op_waits;
47279 +atomic_unchecked_t fscache_n_retrievals;
47280 +atomic_unchecked_t fscache_n_retrievals_ok;
47281 +atomic_unchecked_t fscache_n_retrievals_wait;
47282 +atomic_unchecked_t fscache_n_retrievals_nodata;
47283 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47284 +atomic_unchecked_t fscache_n_retrievals_intr;
47285 +atomic_unchecked_t fscache_n_retrievals_nomem;
47286 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47287 +atomic_unchecked_t fscache_n_retrieval_ops;
47288 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47289
47290 -atomic_t fscache_n_stores;
47291 -atomic_t fscache_n_stores_ok;
47292 -atomic_t fscache_n_stores_again;
47293 -atomic_t fscache_n_stores_nobufs;
47294 -atomic_t fscache_n_stores_oom;
47295 -atomic_t fscache_n_store_ops;
47296 -atomic_t fscache_n_store_calls;
47297 -atomic_t fscache_n_store_pages;
47298 -atomic_t fscache_n_store_radix_deletes;
47299 -atomic_t fscache_n_store_pages_over_limit;
47300 +atomic_unchecked_t fscache_n_stores;
47301 +atomic_unchecked_t fscache_n_stores_ok;
47302 +atomic_unchecked_t fscache_n_stores_again;
47303 +atomic_unchecked_t fscache_n_stores_nobufs;
47304 +atomic_unchecked_t fscache_n_stores_oom;
47305 +atomic_unchecked_t fscache_n_store_ops;
47306 +atomic_unchecked_t fscache_n_store_calls;
47307 +atomic_unchecked_t fscache_n_store_pages;
47308 +atomic_unchecked_t fscache_n_store_radix_deletes;
47309 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47310
47311 -atomic_t fscache_n_store_vmscan_not_storing;
47312 -atomic_t fscache_n_store_vmscan_gone;
47313 -atomic_t fscache_n_store_vmscan_busy;
47314 -atomic_t fscache_n_store_vmscan_cancelled;
47315 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47316 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47317 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47318 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47319
47320 -atomic_t fscache_n_marks;
47321 -atomic_t fscache_n_uncaches;
47322 +atomic_unchecked_t fscache_n_marks;
47323 +atomic_unchecked_t fscache_n_uncaches;
47324
47325 -atomic_t fscache_n_acquires;
47326 -atomic_t fscache_n_acquires_null;
47327 -atomic_t fscache_n_acquires_no_cache;
47328 -atomic_t fscache_n_acquires_ok;
47329 -atomic_t fscache_n_acquires_nobufs;
47330 -atomic_t fscache_n_acquires_oom;
47331 +atomic_unchecked_t fscache_n_acquires;
47332 +atomic_unchecked_t fscache_n_acquires_null;
47333 +atomic_unchecked_t fscache_n_acquires_no_cache;
47334 +atomic_unchecked_t fscache_n_acquires_ok;
47335 +atomic_unchecked_t fscache_n_acquires_nobufs;
47336 +atomic_unchecked_t fscache_n_acquires_oom;
47337
47338 -atomic_t fscache_n_updates;
47339 -atomic_t fscache_n_updates_null;
47340 -atomic_t fscache_n_updates_run;
47341 +atomic_unchecked_t fscache_n_updates;
47342 +atomic_unchecked_t fscache_n_updates_null;
47343 +atomic_unchecked_t fscache_n_updates_run;
47344
47345 -atomic_t fscache_n_relinquishes;
47346 -atomic_t fscache_n_relinquishes_null;
47347 -atomic_t fscache_n_relinquishes_waitcrt;
47348 -atomic_t fscache_n_relinquishes_retire;
47349 +atomic_unchecked_t fscache_n_relinquishes;
47350 +atomic_unchecked_t fscache_n_relinquishes_null;
47351 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47352 +atomic_unchecked_t fscache_n_relinquishes_retire;
47353
47354 -atomic_t fscache_n_cookie_index;
47355 -atomic_t fscache_n_cookie_data;
47356 -atomic_t fscache_n_cookie_special;
47357 +atomic_unchecked_t fscache_n_cookie_index;
47358 +atomic_unchecked_t fscache_n_cookie_data;
47359 +atomic_unchecked_t fscache_n_cookie_special;
47360
47361 -atomic_t fscache_n_object_alloc;
47362 -atomic_t fscache_n_object_no_alloc;
47363 -atomic_t fscache_n_object_lookups;
47364 -atomic_t fscache_n_object_lookups_negative;
47365 -atomic_t fscache_n_object_lookups_positive;
47366 -atomic_t fscache_n_object_lookups_timed_out;
47367 -atomic_t fscache_n_object_created;
47368 -atomic_t fscache_n_object_avail;
47369 -atomic_t fscache_n_object_dead;
47370 +atomic_unchecked_t fscache_n_object_alloc;
47371 +atomic_unchecked_t fscache_n_object_no_alloc;
47372 +atomic_unchecked_t fscache_n_object_lookups;
47373 +atomic_unchecked_t fscache_n_object_lookups_negative;
47374 +atomic_unchecked_t fscache_n_object_lookups_positive;
47375 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47376 +atomic_unchecked_t fscache_n_object_created;
47377 +atomic_unchecked_t fscache_n_object_avail;
47378 +atomic_unchecked_t fscache_n_object_dead;
47379
47380 -atomic_t fscache_n_checkaux_none;
47381 -atomic_t fscache_n_checkaux_okay;
47382 -atomic_t fscache_n_checkaux_update;
47383 -atomic_t fscache_n_checkaux_obsolete;
47384 +atomic_unchecked_t fscache_n_checkaux_none;
47385 +atomic_unchecked_t fscache_n_checkaux_okay;
47386 +atomic_unchecked_t fscache_n_checkaux_update;
47387 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47388
47389 atomic_t fscache_n_cop_alloc_object;
47390 atomic_t fscache_n_cop_lookup_object;
47391 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47392 seq_puts(m, "FS-Cache statistics\n");
47393
47394 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47395 - atomic_read(&fscache_n_cookie_index),
47396 - atomic_read(&fscache_n_cookie_data),
47397 - atomic_read(&fscache_n_cookie_special));
47398 + atomic_read_unchecked(&fscache_n_cookie_index),
47399 + atomic_read_unchecked(&fscache_n_cookie_data),
47400 + atomic_read_unchecked(&fscache_n_cookie_special));
47401
47402 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47403 - atomic_read(&fscache_n_object_alloc),
47404 - atomic_read(&fscache_n_object_no_alloc),
47405 - atomic_read(&fscache_n_object_avail),
47406 - atomic_read(&fscache_n_object_dead));
47407 + atomic_read_unchecked(&fscache_n_object_alloc),
47408 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47409 + atomic_read_unchecked(&fscache_n_object_avail),
47410 + atomic_read_unchecked(&fscache_n_object_dead));
47411 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47412 - atomic_read(&fscache_n_checkaux_none),
47413 - atomic_read(&fscache_n_checkaux_okay),
47414 - atomic_read(&fscache_n_checkaux_update),
47415 - atomic_read(&fscache_n_checkaux_obsolete));
47416 + atomic_read_unchecked(&fscache_n_checkaux_none),
47417 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47418 + atomic_read_unchecked(&fscache_n_checkaux_update),
47419 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47420
47421 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47422 - atomic_read(&fscache_n_marks),
47423 - atomic_read(&fscache_n_uncaches));
47424 + atomic_read_unchecked(&fscache_n_marks),
47425 + atomic_read_unchecked(&fscache_n_uncaches));
47426
47427 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47428 " oom=%u\n",
47429 - atomic_read(&fscache_n_acquires),
47430 - atomic_read(&fscache_n_acquires_null),
47431 - atomic_read(&fscache_n_acquires_no_cache),
47432 - atomic_read(&fscache_n_acquires_ok),
47433 - atomic_read(&fscache_n_acquires_nobufs),
47434 - atomic_read(&fscache_n_acquires_oom));
47435 + atomic_read_unchecked(&fscache_n_acquires),
47436 + atomic_read_unchecked(&fscache_n_acquires_null),
47437 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47438 + atomic_read_unchecked(&fscache_n_acquires_ok),
47439 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47440 + atomic_read_unchecked(&fscache_n_acquires_oom));
47441
47442 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47443 - atomic_read(&fscache_n_object_lookups),
47444 - atomic_read(&fscache_n_object_lookups_negative),
47445 - atomic_read(&fscache_n_object_lookups_positive),
47446 - atomic_read(&fscache_n_object_created),
47447 - atomic_read(&fscache_n_object_lookups_timed_out));
47448 + atomic_read_unchecked(&fscache_n_object_lookups),
47449 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47450 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47451 + atomic_read_unchecked(&fscache_n_object_created),
47452 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47453
47454 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47455 - atomic_read(&fscache_n_updates),
47456 - atomic_read(&fscache_n_updates_null),
47457 - atomic_read(&fscache_n_updates_run));
47458 + atomic_read_unchecked(&fscache_n_updates),
47459 + atomic_read_unchecked(&fscache_n_updates_null),
47460 + atomic_read_unchecked(&fscache_n_updates_run));
47461
47462 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47463 - atomic_read(&fscache_n_relinquishes),
47464 - atomic_read(&fscache_n_relinquishes_null),
47465 - atomic_read(&fscache_n_relinquishes_waitcrt),
47466 - atomic_read(&fscache_n_relinquishes_retire));
47467 + atomic_read_unchecked(&fscache_n_relinquishes),
47468 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47469 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47470 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47471
47472 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47473 - atomic_read(&fscache_n_attr_changed),
47474 - atomic_read(&fscache_n_attr_changed_ok),
47475 - atomic_read(&fscache_n_attr_changed_nobufs),
47476 - atomic_read(&fscache_n_attr_changed_nomem),
47477 - atomic_read(&fscache_n_attr_changed_calls));
47478 + atomic_read_unchecked(&fscache_n_attr_changed),
47479 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47480 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47481 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47482 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47483
47484 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47485 - atomic_read(&fscache_n_allocs),
47486 - atomic_read(&fscache_n_allocs_ok),
47487 - atomic_read(&fscache_n_allocs_wait),
47488 - atomic_read(&fscache_n_allocs_nobufs),
47489 - atomic_read(&fscache_n_allocs_intr));
47490 + atomic_read_unchecked(&fscache_n_allocs),
47491 + atomic_read_unchecked(&fscache_n_allocs_ok),
47492 + atomic_read_unchecked(&fscache_n_allocs_wait),
47493 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47494 + atomic_read_unchecked(&fscache_n_allocs_intr));
47495 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47496 - atomic_read(&fscache_n_alloc_ops),
47497 - atomic_read(&fscache_n_alloc_op_waits),
47498 - atomic_read(&fscache_n_allocs_object_dead));
47499 + atomic_read_unchecked(&fscache_n_alloc_ops),
47500 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47501 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47502
47503 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47504 " int=%u oom=%u\n",
47505 - atomic_read(&fscache_n_retrievals),
47506 - atomic_read(&fscache_n_retrievals_ok),
47507 - atomic_read(&fscache_n_retrievals_wait),
47508 - atomic_read(&fscache_n_retrievals_nodata),
47509 - atomic_read(&fscache_n_retrievals_nobufs),
47510 - atomic_read(&fscache_n_retrievals_intr),
47511 - atomic_read(&fscache_n_retrievals_nomem));
47512 + atomic_read_unchecked(&fscache_n_retrievals),
47513 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47514 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47515 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47516 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47517 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47518 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47519 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47520 - atomic_read(&fscache_n_retrieval_ops),
47521 - atomic_read(&fscache_n_retrieval_op_waits),
47522 - atomic_read(&fscache_n_retrievals_object_dead));
47523 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47524 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47525 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47526
47527 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47528 - atomic_read(&fscache_n_stores),
47529 - atomic_read(&fscache_n_stores_ok),
47530 - atomic_read(&fscache_n_stores_again),
47531 - atomic_read(&fscache_n_stores_nobufs),
47532 - atomic_read(&fscache_n_stores_oom));
47533 + atomic_read_unchecked(&fscache_n_stores),
47534 + atomic_read_unchecked(&fscache_n_stores_ok),
47535 + atomic_read_unchecked(&fscache_n_stores_again),
47536 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47537 + atomic_read_unchecked(&fscache_n_stores_oom));
47538 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47539 - atomic_read(&fscache_n_store_ops),
47540 - atomic_read(&fscache_n_store_calls),
47541 - atomic_read(&fscache_n_store_pages),
47542 - atomic_read(&fscache_n_store_radix_deletes),
47543 - atomic_read(&fscache_n_store_pages_over_limit));
47544 + atomic_read_unchecked(&fscache_n_store_ops),
47545 + atomic_read_unchecked(&fscache_n_store_calls),
47546 + atomic_read_unchecked(&fscache_n_store_pages),
47547 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47548 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47549
47550 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47551 - atomic_read(&fscache_n_store_vmscan_not_storing),
47552 - atomic_read(&fscache_n_store_vmscan_gone),
47553 - atomic_read(&fscache_n_store_vmscan_busy),
47554 - atomic_read(&fscache_n_store_vmscan_cancelled));
47555 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47556 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47557 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47558 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47559
47560 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47561 - atomic_read(&fscache_n_op_pend),
47562 - atomic_read(&fscache_n_op_run),
47563 - atomic_read(&fscache_n_op_enqueue),
47564 - atomic_read(&fscache_n_op_cancelled),
47565 - atomic_read(&fscache_n_op_rejected));
47566 + atomic_read_unchecked(&fscache_n_op_pend),
47567 + atomic_read_unchecked(&fscache_n_op_run),
47568 + atomic_read_unchecked(&fscache_n_op_enqueue),
47569 + atomic_read_unchecked(&fscache_n_op_cancelled),
47570 + atomic_read_unchecked(&fscache_n_op_rejected));
47571 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47572 - atomic_read(&fscache_n_op_deferred_release),
47573 - atomic_read(&fscache_n_op_release),
47574 - atomic_read(&fscache_n_op_gc));
47575 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47576 + atomic_read_unchecked(&fscache_n_op_release),
47577 + atomic_read_unchecked(&fscache_n_op_gc));
47578
47579 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47580 atomic_read(&fscache_n_cop_alloc_object),
47581 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47582 index ee8d550..7189d8c 100644
47583 --- a/fs/fuse/cuse.c
47584 +++ b/fs/fuse/cuse.c
47585 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47586 INIT_LIST_HEAD(&cuse_conntbl[i]);
47587
47588 /* inherit and extend fuse_dev_operations */
47589 - cuse_channel_fops = fuse_dev_operations;
47590 - cuse_channel_fops.owner = THIS_MODULE;
47591 - cuse_channel_fops.open = cuse_channel_open;
47592 - cuse_channel_fops.release = cuse_channel_release;
47593 + pax_open_kernel();
47594 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47595 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47596 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47597 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47598 + pax_close_kernel();
47599
47600 cuse_class = class_create(THIS_MODULE, "cuse");
47601 if (IS_ERR(cuse_class))
47602 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47603 index f4246cf..b4aed1d 100644
47604 --- a/fs/fuse/dev.c
47605 +++ b/fs/fuse/dev.c
47606 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47607 ret = 0;
47608 pipe_lock(pipe);
47609
47610 - if (!pipe->readers) {
47611 + if (!atomic_read(&pipe->readers)) {
47612 send_sig(SIGPIPE, current, 0);
47613 if (!ret)
47614 ret = -EPIPE;
47615 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47616 index 324bc08..4fdd56e 100644
47617 --- a/fs/fuse/dir.c
47618 +++ b/fs/fuse/dir.c
47619 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47620 return link;
47621 }
47622
47623 -static void free_link(char *link)
47624 +static void free_link(const char *link)
47625 {
47626 if (!IS_ERR(link))
47627 free_page((unsigned long) link);
47628 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47629 index 753af3d..f7b021a 100644
47630 --- a/fs/gfs2/inode.c
47631 +++ b/fs/gfs2/inode.c
47632 @@ -1498,7 +1498,7 @@ out:
47633
47634 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47635 {
47636 - char *s = nd_get_link(nd);
47637 + const char *s = nd_get_link(nd);
47638 if (!IS_ERR(s))
47639 kfree(s);
47640 }
47641 diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47642 index a3bde91..2524579 100644
47643 --- a/fs/gfs2/quota.c
47644 +++ b/fs/gfs2/quota.c
47645 @@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47646 struct gfs2_quota_data **qd;
47647 int error;
47648
47649 - if (ip->i_res == NULL)
47650 - gfs2_rs_alloc(ip);
47651 + if (ip->i_res == NULL) {
47652 + error = gfs2_rs_alloc(ip);
47653 + if (error)
47654 + return error;
47655 + }
47656
47657 qd = ip->i_res->rs_qa_qd;
47658
47659 diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47660 index c9ed814..4a45d5f 100644
47661 --- a/fs/gfs2/rgrp.c
47662 +++ b/fs/gfs2/rgrp.c
47663 @@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47664 */
47665 int gfs2_rs_alloc(struct gfs2_inode *ip)
47666 {
47667 - int error = 0;
47668 struct gfs2_blkreserv *res;
47669
47670 if (ip->i_res)
47671 @@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47672
47673 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47674 if (!res)
47675 - error = -ENOMEM;
47676 + return -ENOMEM;
47677
47678 down_write(&ip->i_rw_mutex);
47679 if (ip->i_res)
47680 @@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47681 else
47682 ip->i_res = res;
47683 up_write(&ip->i_rw_mutex);
47684 - return error;
47685 + return 0;
47686 }
47687
47688 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47689 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47690 index 8349a89..51a0254 100644
47691 --- a/fs/hugetlbfs/inode.c
47692 +++ b/fs/hugetlbfs/inode.c
47693 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47694 .kill_sb = kill_litter_super,
47695 };
47696
47697 -static struct vfsmount *hugetlbfs_vfsmount;
47698 +struct vfsmount *hugetlbfs_vfsmount;
47699
47700 static int can_do_hugetlb_shm(void)
47701 {
47702 diff --git a/fs/inode.c b/fs/inode.c
47703 index ac8d904..9f45d40 100644
47704 --- a/fs/inode.c
47705 +++ b/fs/inode.c
47706 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47707
47708 #ifdef CONFIG_SMP
47709 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47710 - static atomic_t shared_last_ino;
47711 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47712 + static atomic_unchecked_t shared_last_ino;
47713 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47714
47715 res = next - LAST_INO_BATCH;
47716 }
47717 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47718 index 4a6cf28..d3a29d3 100644
47719 --- a/fs/jffs2/erase.c
47720 +++ b/fs/jffs2/erase.c
47721 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47722 struct jffs2_unknown_node marker = {
47723 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47724 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47725 - .totlen = cpu_to_je32(c->cleanmarker_size)
47726 + .totlen = cpu_to_je32(c->cleanmarker_size),
47727 + .hdr_crc = cpu_to_je32(0)
47728 };
47729
47730 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47731 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47732 index a6597d6..41b30ec 100644
47733 --- a/fs/jffs2/wbuf.c
47734 +++ b/fs/jffs2/wbuf.c
47735 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47736 {
47737 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47738 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47739 - .totlen = constant_cpu_to_je32(8)
47740 + .totlen = constant_cpu_to_je32(8),
47741 + .hdr_crc = constant_cpu_to_je32(0)
47742 };
47743
47744 /*
47745 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47746 index c55c745..f67ee56 100644
47747 --- a/fs/jfs/super.c
47748 +++ b/fs/jfs/super.c
47749 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47750
47751 jfs_inode_cachep =
47752 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47753 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47754 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47755 init_once);
47756 if (jfs_inode_cachep == NULL)
47757 return -ENOMEM;
47758 diff --git a/fs/libfs.c b/fs/libfs.c
47759 index a74cb17..37fcbe4 100644
47760 --- a/fs/libfs.c
47761 +++ b/fs/libfs.c
47762 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47763
47764 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47765 struct dentry *next;
47766 + char d_name[sizeof(next->d_iname)];
47767 + const unsigned char *name;
47768 +
47769 next = list_entry(p, struct dentry, d_u.d_child);
47770 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47771 if (!simple_positive(next)) {
47772 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47773
47774 spin_unlock(&next->d_lock);
47775 spin_unlock(&dentry->d_lock);
47776 - if (filldir(dirent, next->d_name.name,
47777 + name = next->d_name.name;
47778 + if (name == next->d_iname) {
47779 + memcpy(d_name, name, next->d_name.len);
47780 + name = d_name;
47781 + }
47782 + if (filldir(dirent, name,
47783 next->d_name.len, filp->f_pos,
47784 next->d_inode->i_ino,
47785 dt_type(next->d_inode)) < 0)
47786 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47787 index 05d2912..760abfa 100644
47788 --- a/fs/lockd/clntproc.c
47789 +++ b/fs/lockd/clntproc.c
47790 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47791 /*
47792 * Cookie counter for NLM requests
47793 */
47794 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47795 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47796
47797 void nlmclnt_next_cookie(struct nlm_cookie *c)
47798 {
47799 - u32 cookie = atomic_inc_return(&nlm_cookie);
47800 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47801
47802 memcpy(c->data, &cookie, 4);
47803 c->len=4;
47804 diff --git a/fs/locks.c b/fs/locks.c
47805 index 7e81bfc..c3649aa 100644
47806 --- a/fs/locks.c
47807 +++ b/fs/locks.c
47808 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47809 return;
47810
47811 if (filp->f_op && filp->f_op->flock) {
47812 - struct file_lock fl = {
47813 + struct file_lock flock = {
47814 .fl_pid = current->tgid,
47815 .fl_file = filp,
47816 .fl_flags = FL_FLOCK,
47817 .fl_type = F_UNLCK,
47818 .fl_end = OFFSET_MAX,
47819 };
47820 - filp->f_op->flock(filp, F_SETLKW, &fl);
47821 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47822 - fl.fl_ops->fl_release_private(&fl);
47823 + filp->f_op->flock(filp, F_SETLKW, &flock);
47824 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47825 + flock.fl_ops->fl_release_private(&flock);
47826 }
47827
47828 lock_flocks();
47829 diff --git a/fs/namei.c b/fs/namei.c
47830 index 091c4b7..fbcb268 100644
47831 --- a/fs/namei.c
47832 +++ b/fs/namei.c
47833 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47834 if (ret != -EACCES)
47835 return ret;
47836
47837 +#ifdef CONFIG_GRKERNSEC
47838 + /* we'll block if we have to log due to a denied capability use */
47839 + if (mask & MAY_NOT_BLOCK)
47840 + return -ECHILD;
47841 +#endif
47842 +
47843 if (S_ISDIR(inode->i_mode)) {
47844 /* DACs are overridable for directories */
47845 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47846 - return 0;
47847 if (!(mask & MAY_WRITE))
47848 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47849 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47850 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47851 return 0;
47852 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47853 + return 0;
47854 return -EACCES;
47855 }
47856 /*
47857 + * Searching includes executable on directories, else just read.
47858 + */
47859 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47860 + if (mask == MAY_READ)
47861 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47862 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47863 + return 0;
47864 +
47865 + /*
47866 * Read/write DACs are always overridable.
47867 * Executable DACs are overridable when there is
47868 * at least one exec bit set.
47869 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47870 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47871 return 0;
47872
47873 - /*
47874 - * Searching includes executable on directories, else just read.
47875 - */
47876 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47877 - if (mask == MAY_READ)
47878 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47879 - return 0;
47880 -
47881 return -EACCES;
47882 }
47883
47884 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47885 {
47886 struct dentry *dentry = link->dentry;
47887 int error;
47888 - char *s;
47889 + const char *s;
47890
47891 BUG_ON(nd->flags & LOOKUP_RCU);
47892
47893 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47894 if (error)
47895 goto out_put_nd_path;
47896
47897 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47898 + dentry->d_inode, dentry, nd->path.mnt)) {
47899 + error = -EACCES;
47900 + goto out_put_nd_path;
47901 + }
47902 +
47903 nd->last_type = LAST_BIND;
47904 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47905 error = PTR_ERR(*p);
47906 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47907 break;
47908 res = walk_component(nd, path, &nd->last,
47909 nd->last_type, LOOKUP_FOLLOW);
47910 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47911 + res = -EACCES;
47912 put_link(nd, &link, cookie);
47913 } while (res > 0);
47914
47915 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
47916 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47917 {
47918 unsigned long a, b, adata, bdata, mask, hash, len;
47919 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47920 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47921
47922 hash = a = 0;
47923 len = -sizeof(unsigned long);
47924 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47925 if (err)
47926 break;
47927 err = lookup_last(nd, &path);
47928 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47929 + err = -EACCES;
47930 put_link(nd, &link, cookie);
47931 }
47932 }
47933 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47934 if (!err)
47935 err = complete_walk(nd);
47936
47937 + if (!(nd->flags & LOOKUP_PARENT)) {
47938 +#ifdef CONFIG_GRKERNSEC
47939 + if (flags & LOOKUP_RCU) {
47940 + if (!err)
47941 + path_put(&nd->path);
47942 + err = -ECHILD;
47943 + } else
47944 +#endif
47945 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47946 + if (!err)
47947 + path_put(&nd->path);
47948 + err = -ENOENT;
47949 + }
47950 + }
47951 +
47952 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47953 if (!nd->inode->i_op->lookup) {
47954 path_put(&nd->path);
47955 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47956 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47957
47958 if (likely(!retval)) {
47959 + if (*name != '/' && nd->path.dentry && nd->inode) {
47960 +#ifdef CONFIG_GRKERNSEC
47961 + if (flags & LOOKUP_RCU)
47962 + return -ECHILD;
47963 +#endif
47964 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47965 + return -ENOENT;
47966 + }
47967 +
47968 if (unlikely(!audit_dummy_context())) {
47969 if (nd->path.dentry && nd->inode)
47970 audit_inode(name, nd->path.dentry);
47971 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47972 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47973 return -EPERM;
47974
47975 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47976 + return -EPERM;
47977 + if (gr_handle_rawio(inode))
47978 + return -EPERM;
47979 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47980 + return -EACCES;
47981 +
47982 return 0;
47983 }
47984
47985 @@ -2557,7 +2606,7 @@ looked_up:
47986 * cleared otherwise prior to returning.
47987 */
47988 static int lookup_open(struct nameidata *nd, struct path *path,
47989 - struct file *file,
47990 + struct path *link, struct file *file,
47991 const struct open_flags *op,
47992 bool got_write, int *opened)
47993 {
47994 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47995 /* Negative dentry, just create the file */
47996 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47997 umode_t mode = op->mode;
47998 +
47999 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48000 + error = -EACCES;
48001 + goto out_dput;
48002 + }
48003 +
48004 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48005 + error = -EACCES;
48006 + goto out_dput;
48007 + }
48008 +
48009 if (!IS_POSIXACL(dir->d_inode))
48010 mode &= ~current_umask();
48011 /*
48012 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48013 nd->flags & LOOKUP_EXCL);
48014 if (error)
48015 goto out_dput;
48016 + else
48017 + gr_handle_create(dentry, nd->path.mnt);
48018 }
48019 out_no_open:
48020 path->dentry = dentry;
48021 @@ -2627,7 +2689,7 @@ out_dput:
48022 /*
48023 * Handle the last step of open()
48024 */
48025 -static int do_last(struct nameidata *nd, struct path *path,
48026 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48027 struct file *file, const struct open_flags *op,
48028 int *opened, const char *pathname)
48029 {
48030 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48031 error = complete_walk(nd);
48032 if (error)
48033 return error;
48034 +#ifdef CONFIG_GRKERNSEC
48035 + if (nd->flags & LOOKUP_RCU) {
48036 + error = -ECHILD;
48037 + goto out;
48038 + }
48039 +#endif
48040 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48041 + error = -ENOENT;
48042 + goto out;
48043 + }
48044 audit_inode(pathname, nd->path.dentry);
48045 if (open_flag & O_CREAT) {
48046 error = -EISDIR;
48047 goto out;
48048 }
48049 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48050 + error = -EACCES;
48051 + goto out;
48052 + }
48053 goto finish_open;
48054 case LAST_BIND:
48055 error = complete_walk(nd);
48056 if (error)
48057 return error;
48058 +#ifdef CONFIG_GRKERNSEC
48059 + if (nd->flags & LOOKUP_RCU) {
48060 + error = -ECHILD;
48061 + goto out;
48062 + }
48063 +#endif
48064 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48065 + error = -ENOENT;
48066 + goto out;
48067 + }
48068 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48069 + error = -EACCES;
48070 + goto out;
48071 + }
48072 audit_inode(pathname, dir);
48073 goto finish_open;
48074 }
48075 @@ -2714,7 +2804,7 @@ retry_lookup:
48076 */
48077 }
48078 mutex_lock(&dir->d_inode->i_mutex);
48079 - error = lookup_open(nd, path, file, op, got_write, opened);
48080 + error = lookup_open(nd, path, link, file, op, got_write, opened);
48081 mutex_unlock(&dir->d_inode->i_mutex);
48082
48083 if (error <= 0) {
48084 @@ -2738,11 +2828,28 @@ retry_lookup:
48085 goto finish_open_created;
48086 }
48087
48088 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48089 + error = -ENOENT;
48090 + goto exit_dput;
48091 + }
48092 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48093 + error = -EACCES;
48094 + goto exit_dput;
48095 + }
48096 +
48097 /*
48098 * create/update audit record if it already exists.
48099 */
48100 - if (path->dentry->d_inode)
48101 + if (path->dentry->d_inode) {
48102 + /* only check if O_CREAT is specified, all other checks need to go
48103 + into may_open */
48104 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48105 + error = -EACCES;
48106 + goto exit_dput;
48107 + }
48108 +
48109 audit_inode(pathname, path->dentry);
48110 + }
48111
48112 /*
48113 * If atomic_open() acquired write access it is dropped now due to
48114 @@ -2783,6 +2890,11 @@ finish_lookup:
48115 }
48116 }
48117 BUG_ON(inode != path->dentry->d_inode);
48118 + /* if we're resolving a symlink to another symlink */
48119 + if (link && gr_handle_symlink_owner(link, inode)) {
48120 + error = -EACCES;
48121 + goto out;
48122 + }
48123 return 1;
48124 }
48125
48126 @@ -2792,7 +2904,6 @@ finish_lookup:
48127 save_parent.dentry = nd->path.dentry;
48128 save_parent.mnt = mntget(path->mnt);
48129 nd->path.dentry = path->dentry;
48130 -
48131 }
48132 nd->inode = inode;
48133 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48134 @@ -2801,6 +2912,22 @@ finish_lookup:
48135 path_put(&save_parent);
48136 return error;
48137 }
48138 +
48139 +#ifdef CONFIG_GRKERNSEC
48140 + if (nd->flags & LOOKUP_RCU) {
48141 + error = -ECHILD;
48142 + goto out;
48143 + }
48144 +#endif
48145 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48146 + error = -ENOENT;
48147 + goto out;
48148 + }
48149 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48150 + error = -EACCES;
48151 + goto out;
48152 + }
48153 +
48154 error = -EISDIR;
48155 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48156 goto out;
48157 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48158 if (unlikely(error))
48159 goto out;
48160
48161 - error = do_last(nd, &path, file, op, &opened, pathname);
48162 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48163 while (unlikely(error > 0)) { /* trailing symlink */
48164 struct path link = path;
48165 void *cookie;
48166 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48167 error = follow_link(&link, nd, &cookie);
48168 if (unlikely(error))
48169 break;
48170 - error = do_last(nd, &path, file, op, &opened, pathname);
48171 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48172 put_link(nd, &link, cookie);
48173 }
48174 out:
48175 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48176 goto unlock;
48177
48178 error = -EEXIST;
48179 - if (dentry->d_inode)
48180 + if (dentry->d_inode) {
48181 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48182 + error = -ENOENT;
48183 + }
48184 goto fail;
48185 + }
48186 /*
48187 * Special case - lookup gave negative, but... we had foo/bar/
48188 * From the vfs_mknod() POV we just have a negative dentry -
48189 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48190 }
48191 EXPORT_SYMBOL(user_path_create);
48192
48193 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48194 +{
48195 + char *tmp = getname(pathname);
48196 + struct dentry *res;
48197 + if (IS_ERR(tmp))
48198 + return ERR_CAST(tmp);
48199 + res = kern_path_create(dfd, tmp, path, is_dir);
48200 + if (IS_ERR(res))
48201 + putname(tmp);
48202 + else
48203 + *to = tmp;
48204 + return res;
48205 +}
48206 +
48207 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48208 {
48209 int error = may_create(dir, dentry);
48210 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48211
48212 if (!IS_POSIXACL(path.dentry->d_inode))
48213 mode &= ~current_umask();
48214 +
48215 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48216 + error = -EPERM;
48217 + goto out;
48218 + }
48219 +
48220 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48221 + error = -EACCES;
48222 + goto out;
48223 + }
48224 +
48225 error = security_path_mknod(&path, dentry, mode, dev);
48226 if (error)
48227 goto out;
48228 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48229 break;
48230 }
48231 out:
48232 + if (!error)
48233 + gr_handle_create(dentry, path.mnt);
48234 done_path_create(&path, dentry);
48235 return error;
48236 }
48237 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48238
48239 if (!IS_POSIXACL(path.dentry->d_inode))
48240 mode &= ~current_umask();
48241 +
48242 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48243 + error = -EACCES;
48244 + goto out;
48245 + }
48246 +
48247 error = security_path_mkdir(&path, dentry, mode);
48248 if (!error)
48249 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48250 + if (!error)
48251 + gr_handle_create(dentry, path.mnt);
48252 +out:
48253 done_path_create(&path, dentry);
48254 return error;
48255 }
48256 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48257 char * name;
48258 struct dentry *dentry;
48259 struct nameidata nd;
48260 + ino_t saved_ino = 0;
48261 + dev_t saved_dev = 0;
48262
48263 error = user_path_parent(dfd, pathname, &nd, &name);
48264 if (error)
48265 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48266 error = -ENOENT;
48267 goto exit3;
48268 }
48269 +
48270 + saved_ino = dentry->d_inode->i_ino;
48271 + saved_dev = gr_get_dev_from_dentry(dentry);
48272 +
48273 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48274 + error = -EACCES;
48275 + goto exit3;
48276 + }
48277 +
48278 error = security_path_rmdir(&nd.path, dentry);
48279 if (error)
48280 goto exit3;
48281 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48282 + if (!error && (saved_dev || saved_ino))
48283 + gr_handle_delete(saved_ino, saved_dev);
48284 exit3:
48285 dput(dentry);
48286 exit2:
48287 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48288 struct dentry *dentry;
48289 struct nameidata nd;
48290 struct inode *inode = NULL;
48291 + ino_t saved_ino = 0;
48292 + dev_t saved_dev = 0;
48293
48294 error = user_path_parent(dfd, pathname, &nd, &name);
48295 if (error)
48296 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48297 if (!inode)
48298 goto slashes;
48299 ihold(inode);
48300 +
48301 + if (inode->i_nlink <= 1) {
48302 + saved_ino = inode->i_ino;
48303 + saved_dev = gr_get_dev_from_dentry(dentry);
48304 + }
48305 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48306 + error = -EACCES;
48307 + goto exit2;
48308 + }
48309 +
48310 error = security_path_unlink(&nd.path, dentry);
48311 if (error)
48312 goto exit2;
48313 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48314 + if (!error && (saved_ino || saved_dev))
48315 + gr_handle_delete(saved_ino, saved_dev);
48316 exit2:
48317 dput(dentry);
48318 }
48319 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48320 if (IS_ERR(dentry))
48321 goto out_putname;
48322
48323 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48324 + error = -EACCES;
48325 + goto out;
48326 + }
48327 +
48328 error = security_path_symlink(&path, dentry, from);
48329 if (!error)
48330 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48331 + if (!error)
48332 + gr_handle_create(dentry, path.mnt);
48333 +out:
48334 done_path_create(&path, dentry);
48335 out_putname:
48336 putname(from);
48337 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48338 {
48339 struct dentry *new_dentry;
48340 struct path old_path, new_path;
48341 + char *to = NULL;
48342 int how = 0;
48343 int error;
48344
48345 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48346 if (error)
48347 return error;
48348
48349 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48350 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48351 error = PTR_ERR(new_dentry);
48352 if (IS_ERR(new_dentry))
48353 goto out;
48354 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48355 error = may_linkat(&old_path);
48356 if (unlikely(error))
48357 goto out_dput;
48358 +
48359 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48360 + old_path.dentry->d_inode,
48361 + old_path.dentry->d_inode->i_mode, to)) {
48362 + error = -EACCES;
48363 + goto out_dput;
48364 + }
48365 +
48366 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48367 + old_path.dentry, old_path.mnt, to)) {
48368 + error = -EACCES;
48369 + goto out_dput;
48370 + }
48371 +
48372 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48373 if (error)
48374 goto out_dput;
48375 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48376 + if (!error)
48377 + gr_handle_create(new_dentry, new_path.mnt);
48378 out_dput:
48379 + putname(to);
48380 done_path_create(&new_path, new_dentry);
48381 out:
48382 path_put(&old_path);
48383 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48384 if (new_dentry == trap)
48385 goto exit5;
48386
48387 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48388 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48389 + to);
48390 + if (error)
48391 + goto exit5;
48392 +
48393 error = security_path_rename(&oldnd.path, old_dentry,
48394 &newnd.path, new_dentry);
48395 if (error)
48396 goto exit5;
48397 error = vfs_rename(old_dir->d_inode, old_dentry,
48398 new_dir->d_inode, new_dentry);
48399 + if (!error)
48400 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48401 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48402 exit5:
48403 dput(new_dentry);
48404 exit4:
48405 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48406
48407 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48408 {
48409 + char tmpbuf[64];
48410 + const char *newlink;
48411 int len;
48412
48413 len = PTR_ERR(link);
48414 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48415 len = strlen(link);
48416 if (len > (unsigned) buflen)
48417 len = buflen;
48418 - if (copy_to_user(buffer, link, len))
48419 +
48420 + if (len < sizeof(tmpbuf)) {
48421 + memcpy(tmpbuf, link, len);
48422 + newlink = tmpbuf;
48423 + } else
48424 + newlink = link;
48425 +
48426 + if (copy_to_user(buffer, newlink, len))
48427 len = -EFAULT;
48428 out:
48429 return len;
48430 diff --git a/fs/namespace.c b/fs/namespace.c
48431 index 7bdf790..eb79c4b 100644
48432 --- a/fs/namespace.c
48433 +++ b/fs/namespace.c
48434 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48435 if (!(sb->s_flags & MS_RDONLY))
48436 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48437 up_write(&sb->s_umount);
48438 +
48439 + gr_log_remount(mnt->mnt_devname, retval);
48440 +
48441 return retval;
48442 }
48443
48444 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48445 br_write_unlock(&vfsmount_lock);
48446 up_write(&namespace_sem);
48447 release_mounts(&umount_list);
48448 +
48449 + gr_log_unmount(mnt->mnt_devname, retval);
48450 +
48451 return retval;
48452 }
48453
48454 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48455 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48456 MS_STRICTATIME);
48457
48458 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48459 + retval = -EPERM;
48460 + goto dput_out;
48461 + }
48462 +
48463 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48464 + retval = -EPERM;
48465 + goto dput_out;
48466 + }
48467 +
48468 if (flags & MS_REMOUNT)
48469 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48470 data_page);
48471 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48472 dev_name, data_page);
48473 dput_out:
48474 path_put(&path);
48475 +
48476 + gr_log_mount(dev_name, dir_name, retval);
48477 +
48478 return retval;
48479 }
48480
48481 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48482 if (error)
48483 goto out2;
48484
48485 + if (gr_handle_chroot_pivot()) {
48486 + error = -EPERM;
48487 + goto out2;
48488 + }
48489 +
48490 get_fs_root(current->fs, &root);
48491 error = lock_mount(&old);
48492 if (error)
48493 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48494 index 9b47610..066975e 100644
48495 --- a/fs/nfs/inode.c
48496 +++ b/fs/nfs/inode.c
48497 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48498 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48499 }
48500
48501 -static atomic_long_t nfs_attr_generation_counter;
48502 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48503
48504 static unsigned long nfs_read_attr_generation_counter(void)
48505 {
48506 - return atomic_long_read(&nfs_attr_generation_counter);
48507 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48508 }
48509
48510 unsigned long nfs_inc_attr_generation_counter(void)
48511 {
48512 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48513 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48514 }
48515
48516 void nfs_fattr_init(struct nfs_fattr *fattr)
48517 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48518 index a9269f1..5490437 100644
48519 --- a/fs/nfsd/vfs.c
48520 +++ b/fs/nfsd/vfs.c
48521 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48522 } else {
48523 oldfs = get_fs();
48524 set_fs(KERNEL_DS);
48525 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48526 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48527 set_fs(oldfs);
48528 }
48529
48530 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48531
48532 /* Write the data. */
48533 oldfs = get_fs(); set_fs(KERNEL_DS);
48534 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48535 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48536 set_fs(oldfs);
48537 if (host_err < 0)
48538 goto out_nfserr;
48539 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48540 */
48541
48542 oldfs = get_fs(); set_fs(KERNEL_DS);
48543 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48544 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48545 set_fs(oldfs);
48546
48547 if (host_err < 0)
48548 diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
48549 index f35794b..a506360 100644
48550 --- a/fs/notify/fanotify/fanotify.c
48551 +++ b/fs/notify/fanotify/fanotify.c
48552 @@ -21,6 +21,7 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
48553 if ((old->path.mnt == new->path.mnt) &&
48554 (old->path.dentry == new->path.dentry))
48555 return true;
48556 + break;
48557 case (FSNOTIFY_EVENT_NONE):
48558 return true;
48559 default:
48560 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48561 index d438036..0ecadde 100644
48562 --- a/fs/notify/fanotify/fanotify_user.c
48563 +++ b/fs/notify/fanotify/fanotify_user.c
48564 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48565 goto out_close_fd;
48566
48567 ret = -EFAULT;
48568 - if (copy_to_user(buf, &fanotify_event_metadata,
48569 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48570 + copy_to_user(buf, &fanotify_event_metadata,
48571 fanotify_event_metadata.event_len))
48572 goto out_kill_access_response;
48573
48574 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48575 index c887b13..0fdf472 100644
48576 --- a/fs/notify/notification.c
48577 +++ b/fs/notify/notification.c
48578 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48579 * get set to 0 so it will never get 'freed'
48580 */
48581 static struct fsnotify_event *q_overflow_event;
48582 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48583 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48584
48585 /**
48586 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48587 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48588 */
48589 u32 fsnotify_get_cookie(void)
48590 {
48591 - return atomic_inc_return(&fsnotify_sync_cookie);
48592 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48593 }
48594 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48595
48596 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48597 index 99e3610..02c1068 100644
48598 --- a/fs/ntfs/dir.c
48599 +++ b/fs/ntfs/dir.c
48600 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48601 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48602 ~(s64)(ndir->itype.index.block_size - 1)));
48603 /* Bounds checks. */
48604 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48605 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48606 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48607 "inode 0x%lx or driver bug.", vdir->i_ino);
48608 goto err_out;
48609 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48610 index 1ecf464..e1ff8bf 100644
48611 --- a/fs/ntfs/file.c
48612 +++ b/fs/ntfs/file.c
48613 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48614 #endif /* NTFS_RW */
48615 };
48616
48617 -const struct file_operations ntfs_empty_file_ops = {};
48618 +const struct file_operations ntfs_empty_file_ops __read_only;
48619
48620 -const struct inode_operations ntfs_empty_inode_ops = {};
48621 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48622 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48623 index a9f78c7..ed8a381 100644
48624 --- a/fs/ocfs2/localalloc.c
48625 +++ b/fs/ocfs2/localalloc.c
48626 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48627 goto bail;
48628 }
48629
48630 - atomic_inc(&osb->alloc_stats.moves);
48631 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48632
48633 bail:
48634 if (handle)
48635 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48636 index d355e6e..578d905 100644
48637 --- a/fs/ocfs2/ocfs2.h
48638 +++ b/fs/ocfs2/ocfs2.h
48639 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48640
48641 struct ocfs2_alloc_stats
48642 {
48643 - atomic_t moves;
48644 - atomic_t local_data;
48645 - atomic_t bitmap_data;
48646 - atomic_t bg_allocs;
48647 - atomic_t bg_extends;
48648 + atomic_unchecked_t moves;
48649 + atomic_unchecked_t local_data;
48650 + atomic_unchecked_t bitmap_data;
48651 + atomic_unchecked_t bg_allocs;
48652 + atomic_unchecked_t bg_extends;
48653 };
48654
48655 enum ocfs2_local_alloc_state
48656 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48657 index f169da4..9112253 100644
48658 --- a/fs/ocfs2/suballoc.c
48659 +++ b/fs/ocfs2/suballoc.c
48660 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48661 mlog_errno(status);
48662 goto bail;
48663 }
48664 - atomic_inc(&osb->alloc_stats.bg_extends);
48665 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48666
48667 /* You should never ask for this much metadata */
48668 BUG_ON(bits_wanted >
48669 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48670 mlog_errno(status);
48671 goto bail;
48672 }
48673 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48674 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48675
48676 *suballoc_loc = res.sr_bg_blkno;
48677 *suballoc_bit_start = res.sr_bit_offset;
48678 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48679 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48680 res->sr_bits);
48681
48682 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48683 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48684
48685 BUG_ON(res->sr_bits != 1);
48686
48687 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48688 mlog_errno(status);
48689 goto bail;
48690 }
48691 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48692 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48693
48694 BUG_ON(res.sr_bits != 1);
48695
48696 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48697 cluster_start,
48698 num_clusters);
48699 if (!status)
48700 - atomic_inc(&osb->alloc_stats.local_data);
48701 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48702 } else {
48703 if (min_clusters > (osb->bitmap_cpg - 1)) {
48704 /* The only paths asking for contiguousness
48705 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48706 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48707 res.sr_bg_blkno,
48708 res.sr_bit_offset);
48709 - atomic_inc(&osb->alloc_stats.bitmap_data);
48710 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48711 *num_clusters = res.sr_bits;
48712 }
48713 }
48714 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48715 index 68f4541..89cfe6a 100644
48716 --- a/fs/ocfs2/super.c
48717 +++ b/fs/ocfs2/super.c
48718 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48719 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48720 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48721 "Stats",
48722 - atomic_read(&osb->alloc_stats.bitmap_data),
48723 - atomic_read(&osb->alloc_stats.local_data),
48724 - atomic_read(&osb->alloc_stats.bg_allocs),
48725 - atomic_read(&osb->alloc_stats.moves),
48726 - atomic_read(&osb->alloc_stats.bg_extends));
48727 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48728 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48729 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48730 + atomic_read_unchecked(&osb->alloc_stats.moves),
48731 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48732
48733 out += snprintf(buf + out, len - out,
48734 "%10s => State: %u Descriptor: %llu Size: %u bits "
48735 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48736 spin_lock_init(&osb->osb_xattr_lock);
48737 ocfs2_init_steal_slots(osb);
48738
48739 - atomic_set(&osb->alloc_stats.moves, 0);
48740 - atomic_set(&osb->alloc_stats.local_data, 0);
48741 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48742 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48743 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48744 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48745 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48746 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48747 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48748 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48749
48750 /* Copy the blockcheck stats from the superblock probe */
48751 osb->osb_ecc_stats = *stats;
48752 diff --git a/fs/open.c b/fs/open.c
48753 index e1f2cdb..3bd5f39 100644
48754 --- a/fs/open.c
48755 +++ b/fs/open.c
48756 @@ -31,6 +31,8 @@
48757 #include <linux/ima.h>
48758 #include <linux/dnotify.h>
48759
48760 +#define CREATE_TRACE_POINTS
48761 +#include <trace/events/fs.h>
48762 #include "internal.h"
48763
48764 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48765 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48766 error = locks_verify_truncate(inode, NULL, length);
48767 if (!error)
48768 error = security_path_truncate(&path);
48769 +
48770 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48771 + error = -EACCES;
48772 +
48773 if (!error)
48774 error = do_truncate(path.dentry, length, 0, NULL);
48775
48776 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48777 if (__mnt_is_readonly(path.mnt))
48778 res = -EROFS;
48779
48780 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48781 + res = -EACCES;
48782 +
48783 out_path_release:
48784 path_put(&path);
48785 out:
48786 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48787 if (error)
48788 goto dput_and_out;
48789
48790 + gr_log_chdir(path.dentry, path.mnt);
48791 +
48792 set_fs_pwd(current->fs, &path);
48793
48794 dput_and_out:
48795 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48796 goto out_putf;
48797
48798 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48799 +
48800 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48801 + error = -EPERM;
48802 +
48803 + if (!error)
48804 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48805 +
48806 if (!error)
48807 set_fs_pwd(current->fs, &file->f_path);
48808 out_putf:
48809 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48810 if (error)
48811 goto dput_and_out;
48812
48813 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48814 + goto dput_and_out;
48815 +
48816 set_fs_root(current->fs, &path);
48817 +
48818 + gr_handle_chroot_chdir(&path);
48819 +
48820 error = 0;
48821 dput_and_out:
48822 path_put(&path);
48823 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48824 if (error)
48825 return error;
48826 mutex_lock(&inode->i_mutex);
48827 +
48828 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48829 + error = -EACCES;
48830 + goto out_unlock;
48831 + }
48832 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48833 + error = -EACCES;
48834 + goto out_unlock;
48835 + }
48836 +
48837 error = security_path_chmod(path, mode);
48838 if (error)
48839 goto out_unlock;
48840 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48841 uid = make_kuid(current_user_ns(), user);
48842 gid = make_kgid(current_user_ns(), group);
48843
48844 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48845 + return -EACCES;
48846 +
48847 newattrs.ia_valid = ATTR_CTIME;
48848 if (user != (uid_t) -1) {
48849 if (!uid_valid(uid))
48850 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48851 } else {
48852 fsnotify_open(f);
48853 fd_install(fd, f);
48854 + trace_do_sys_open(tmp, flags, mode);
48855 }
48856 }
48857 putname(tmp);
48858 diff --git a/fs/pipe.c b/fs/pipe.c
48859 index 8d85d70..581036b 100644
48860 --- a/fs/pipe.c
48861 +++ b/fs/pipe.c
48862 @@ -438,9 +438,9 @@ redo:
48863 }
48864 if (bufs) /* More to do? */
48865 continue;
48866 - if (!pipe->writers)
48867 + if (!atomic_read(&pipe->writers))
48868 break;
48869 - if (!pipe->waiting_writers) {
48870 + if (!atomic_read(&pipe->waiting_writers)) {
48871 /* syscall merging: Usually we must not sleep
48872 * if O_NONBLOCK is set, or if we got some data.
48873 * But if a writer sleeps in kernel space, then
48874 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48875 mutex_lock(&inode->i_mutex);
48876 pipe = inode->i_pipe;
48877
48878 - if (!pipe->readers) {
48879 + if (!atomic_read(&pipe->readers)) {
48880 send_sig(SIGPIPE, current, 0);
48881 ret = -EPIPE;
48882 goto out;
48883 @@ -553,7 +553,7 @@ redo1:
48884 for (;;) {
48885 int bufs;
48886
48887 - if (!pipe->readers) {
48888 + if (!atomic_read(&pipe->readers)) {
48889 send_sig(SIGPIPE, current, 0);
48890 if (!ret)
48891 ret = -EPIPE;
48892 @@ -644,9 +644,9 @@ redo2:
48893 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48894 do_wakeup = 0;
48895 }
48896 - pipe->waiting_writers++;
48897 + atomic_inc(&pipe->waiting_writers);
48898 pipe_wait(pipe);
48899 - pipe->waiting_writers--;
48900 + atomic_dec(&pipe->waiting_writers);
48901 }
48902 out:
48903 mutex_unlock(&inode->i_mutex);
48904 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48905 mask = 0;
48906 if (filp->f_mode & FMODE_READ) {
48907 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48908 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48909 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48910 mask |= POLLHUP;
48911 }
48912
48913 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48914 * Most Unices do not set POLLERR for FIFOs but on Linux they
48915 * behave exactly like pipes for poll().
48916 */
48917 - if (!pipe->readers)
48918 + if (!atomic_read(&pipe->readers))
48919 mask |= POLLERR;
48920 }
48921
48922 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48923
48924 mutex_lock(&inode->i_mutex);
48925 pipe = inode->i_pipe;
48926 - pipe->readers -= decr;
48927 - pipe->writers -= decw;
48928 + atomic_sub(decr, &pipe->readers);
48929 + atomic_sub(decw, &pipe->writers);
48930
48931 - if (!pipe->readers && !pipe->writers) {
48932 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48933 free_pipe_info(inode);
48934 } else {
48935 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48936 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48937
48938 if (inode->i_pipe) {
48939 ret = 0;
48940 - inode->i_pipe->readers++;
48941 + atomic_inc(&inode->i_pipe->readers);
48942 }
48943
48944 mutex_unlock(&inode->i_mutex);
48945 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48946
48947 if (inode->i_pipe) {
48948 ret = 0;
48949 - inode->i_pipe->writers++;
48950 + atomic_inc(&inode->i_pipe->writers);
48951 }
48952
48953 mutex_unlock(&inode->i_mutex);
48954 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48955 if (inode->i_pipe) {
48956 ret = 0;
48957 if (filp->f_mode & FMODE_READ)
48958 - inode->i_pipe->readers++;
48959 + atomic_inc(&inode->i_pipe->readers);
48960 if (filp->f_mode & FMODE_WRITE)
48961 - inode->i_pipe->writers++;
48962 + atomic_inc(&inode->i_pipe->writers);
48963 }
48964
48965 mutex_unlock(&inode->i_mutex);
48966 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48967 inode->i_pipe = NULL;
48968 }
48969
48970 -static struct vfsmount *pipe_mnt __read_mostly;
48971 +struct vfsmount *pipe_mnt __read_mostly;
48972
48973 /*
48974 * pipefs_dname() is called from d_path().
48975 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48976 goto fail_iput;
48977 inode->i_pipe = pipe;
48978
48979 - pipe->readers = pipe->writers = 1;
48980 + atomic_set(&pipe->readers, 1);
48981 + atomic_set(&pipe->writers, 1);
48982 inode->i_fop = &rdwr_pipefifo_fops;
48983
48984 /*
48985 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48986 index 15af622..0e9f4467 100644
48987 --- a/fs/proc/Kconfig
48988 +++ b/fs/proc/Kconfig
48989 @@ -30,12 +30,12 @@ config PROC_FS
48990
48991 config PROC_KCORE
48992 bool "/proc/kcore support" if !ARM
48993 - depends on PROC_FS && MMU
48994 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48995
48996 config PROC_VMCORE
48997 bool "/proc/vmcore support"
48998 - depends on PROC_FS && CRASH_DUMP
48999 - default y
49000 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49001 + default n
49002 help
49003 Exports the dump image of crashed kernel in ELF format.
49004
49005 @@ -59,8 +59,8 @@ config PROC_SYSCTL
49006 limited in memory.
49007
49008 config PROC_PAGE_MONITOR
49009 - default y
49010 - depends on PROC_FS && MMU
49011 + default n
49012 + depends on PROC_FS && MMU && !GRKERNSEC
49013 bool "Enable /proc page monitoring" if EXPERT
49014 help
49015 Various /proc files exist to monitor process memory utilization:
49016 diff --git a/fs/proc/array.c b/fs/proc/array.c
49017 index c1c207c..01ce725 100644
49018 --- a/fs/proc/array.c
49019 +++ b/fs/proc/array.c
49020 @@ -60,6 +60,7 @@
49021 #include <linux/tty.h>
49022 #include <linux/string.h>
49023 #include <linux/mman.h>
49024 +#include <linux/grsecurity.h>
49025 #include <linux/proc_fs.h>
49026 #include <linux/ioport.h>
49027 #include <linux/uaccess.h>
49028 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49029 seq_putc(m, '\n');
49030 }
49031
49032 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49033 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49034 +{
49035 + if (p->mm)
49036 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49037 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49038 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49039 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49040 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49041 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49042 + else
49043 + seq_printf(m, "PaX:\t-----\n");
49044 +}
49045 +#endif
49046 +
49047 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49048 struct pid *pid, struct task_struct *task)
49049 {
49050 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49051 task_cpus_allowed(m, task);
49052 cpuset_task_status_allowed(m, task);
49053 task_context_switch_counts(m, task);
49054 +
49055 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49056 + task_pax(m, task);
49057 +#endif
49058 +
49059 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49060 + task_grsec_rbac(m, task);
49061 +#endif
49062 +
49063 return 0;
49064 }
49065
49066 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49067 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49068 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49069 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49070 +#endif
49071 +
49072 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49073 struct pid *pid, struct task_struct *task, int whole)
49074 {
49075 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49076 char tcomm[sizeof(task->comm)];
49077 unsigned long flags;
49078
49079 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49080 + if (current->exec_id != m->exec_id) {
49081 + gr_log_badprocpid("stat");
49082 + return 0;
49083 + }
49084 +#endif
49085 +
49086 state = *get_task_state(task);
49087 vsize = eip = esp = 0;
49088 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49089 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49090 gtime = task->gtime;
49091 }
49092
49093 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49094 + if (PAX_RAND_FLAGS(mm)) {
49095 + eip = 0;
49096 + esp = 0;
49097 + wchan = 0;
49098 + }
49099 +#endif
49100 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49101 + wchan = 0;
49102 + eip =0;
49103 + esp =0;
49104 +#endif
49105 +
49106 /* scale priority and nice values from timeslices to -20..20 */
49107 /* to make it look like a "normal" Unix priority/nice value */
49108 priority = task_prio(task);
49109 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49110 seq_put_decimal_ull(m, ' ', vsize);
49111 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49112 seq_put_decimal_ull(m, ' ', rsslim);
49113 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49114 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49115 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49116 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49117 +#else
49118 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49119 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49120 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49121 +#endif
49122 seq_put_decimal_ull(m, ' ', esp);
49123 seq_put_decimal_ull(m, ' ', eip);
49124 /* The signal information here is obsolete.
49125 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49126 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49127 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49128
49129 - if (mm && permitted) {
49130 + if (mm && permitted
49131 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49132 + && !PAX_RAND_FLAGS(mm)
49133 +#endif
49134 + ) {
49135 seq_put_decimal_ull(m, ' ', mm->start_data);
49136 seq_put_decimal_ull(m, ' ', mm->end_data);
49137 seq_put_decimal_ull(m, ' ', mm->start_brk);
49138 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49139 struct pid *pid, struct task_struct *task)
49140 {
49141 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49142 - struct mm_struct *mm = get_task_mm(task);
49143 + struct mm_struct *mm;
49144
49145 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49146 + if (current->exec_id != m->exec_id) {
49147 + gr_log_badprocpid("statm");
49148 + return 0;
49149 + }
49150 +#endif
49151 + mm = get_task_mm(task);
49152 if (mm) {
49153 size = task_statm(mm, &shared, &text, &data, &resident);
49154 mmput(mm);
49155 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49156 return 0;
49157 }
49158
49159 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49160 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49161 +{
49162 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49163 +}
49164 +#endif
49165 +
49166 #ifdef CONFIG_CHECKPOINT_RESTORE
49167 static struct pid *
49168 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49169 diff --git a/fs/proc/base.c b/fs/proc/base.c
49170 index 1b6c84c..66b738b 100644
49171 --- a/fs/proc/base.c
49172 +++ b/fs/proc/base.c
49173 @@ -110,6 +110,14 @@ struct pid_entry {
49174 union proc_op op;
49175 };
49176
49177 +struct getdents_callback {
49178 + struct linux_dirent __user * current_dir;
49179 + struct linux_dirent __user * previous;
49180 + struct file * file;
49181 + int count;
49182 + int error;
49183 +};
49184 +
49185 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49186 .name = (NAME), \
49187 .len = sizeof(NAME) - 1, \
49188 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49189 if (!mm->arg_end)
49190 goto out_mm; /* Shh! No looking before we're done */
49191
49192 + if (gr_acl_handle_procpidmem(task))
49193 + goto out_mm;
49194 +
49195 len = mm->arg_end - mm->arg_start;
49196
49197 if (len > PAGE_SIZE)
49198 @@ -236,12 +247,28 @@ out:
49199 return res;
49200 }
49201
49202 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49203 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49204 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49205 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49206 +#endif
49207 +
49208 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49209 {
49210 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49211 int res = PTR_ERR(mm);
49212 if (mm && !IS_ERR(mm)) {
49213 unsigned int nwords = 0;
49214 +
49215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49216 + /* allow if we're currently ptracing this task */
49217 + if (PAX_RAND_FLAGS(mm) &&
49218 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49219 + mmput(mm);
49220 + return 0;
49221 + }
49222 +#endif
49223 +
49224 do {
49225 nwords += 2;
49226 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49227 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49228 }
49229
49230
49231 -#ifdef CONFIG_KALLSYMS
49232 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49233 /*
49234 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49235 * Returns the resolved symbol. If that fails, simply return the address.
49236 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49237 mutex_unlock(&task->signal->cred_guard_mutex);
49238 }
49239
49240 -#ifdef CONFIG_STACKTRACE
49241 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49242
49243 #define MAX_STACK_TRACE_DEPTH 64
49244
49245 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49246 return count;
49247 }
49248
49249 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49250 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49251 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49252 {
49253 long nr;
49254 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49255 /************************************************************************/
49256
49257 /* permission checks */
49258 -static int proc_fd_access_allowed(struct inode *inode)
49259 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49260 {
49261 struct task_struct *task;
49262 int allowed = 0;
49263 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49264 */
49265 task = get_proc_task(inode);
49266 if (task) {
49267 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49268 + if (log)
49269 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49270 + else
49271 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49272 put_task_struct(task);
49273 }
49274 return allowed;
49275 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49276 struct task_struct *task,
49277 int hide_pid_min)
49278 {
49279 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49280 + return false;
49281 +
49282 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49283 + rcu_read_lock();
49284 + {
49285 + const struct cred *tmpcred = current_cred();
49286 + const struct cred *cred = __task_cred(task);
49287 +
49288 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49289 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49290 + || in_group_p(grsec_proc_gid)
49291 +#endif
49292 + ) {
49293 + rcu_read_unlock();
49294 + return true;
49295 + }
49296 + }
49297 + rcu_read_unlock();
49298 +
49299 + if (!pid->hide_pid)
49300 + return false;
49301 +#endif
49302 +
49303 if (pid->hide_pid < hide_pid_min)
49304 return true;
49305 if (in_group_p(pid->pid_gid))
49306 return true;
49307 +
49308 return ptrace_may_access(task, PTRACE_MODE_READ);
49309 }
49310
49311 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49312 put_task_struct(task);
49313
49314 if (!has_perms) {
49315 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49316 + {
49317 +#else
49318 if (pid->hide_pid == 2) {
49319 +#endif
49320 /*
49321 * Let's make getdents(), stat(), and open()
49322 * consistent with each other. If a process
49323 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49324 if (!task)
49325 return -ESRCH;
49326
49327 + if (gr_acl_handle_procpidmem(task)) {
49328 + put_task_struct(task);
49329 + return -EPERM;
49330 + }
49331 +
49332 mm = mm_access(task, mode);
49333 put_task_struct(task);
49334
49335 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49336
49337 file->private_data = mm;
49338
49339 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49340 + file->f_version = current->exec_id;
49341 +#endif
49342 +
49343 return 0;
49344 }
49345
49346 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49347 ssize_t copied;
49348 char *page;
49349
49350 +#ifdef CONFIG_GRKERNSEC
49351 + if (write)
49352 + return -EPERM;
49353 +#endif
49354 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49355 + if (file->f_version != current->exec_id) {
49356 + gr_log_badprocpid("mem");
49357 + return 0;
49358 + }
49359 +#endif
49360 +
49361 if (!mm)
49362 return 0;
49363
49364 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49365 if (!mm)
49366 return 0;
49367
49368 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49369 + if (file->f_version != current->exec_id) {
49370 + gr_log_badprocpid("environ");
49371 + return 0;
49372 + }
49373 +#endif
49374 +
49375 page = (char *)__get_free_page(GFP_TEMPORARY);
49376 if (!page)
49377 return -ENOMEM;
49378 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49379 int error = -EACCES;
49380
49381 /* Are we allowed to snoop on the tasks file descriptors? */
49382 - if (!proc_fd_access_allowed(inode))
49383 + if (!proc_fd_access_allowed(inode, 0))
49384 goto out;
49385
49386 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49387 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49388 struct path path;
49389
49390 /* Are we allowed to snoop on the tasks file descriptors? */
49391 - if (!proc_fd_access_allowed(inode))
49392 - goto out;
49393 + /* logging this is needed for learning on chromium to work properly,
49394 + but we don't want to flood the logs from 'ps' which does a readlink
49395 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49396 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49397 + */
49398 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49399 + if (!proc_fd_access_allowed(inode,0))
49400 + goto out;
49401 + } else {
49402 + if (!proc_fd_access_allowed(inode,1))
49403 + goto out;
49404 + }
49405
49406 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49407 if (error)
49408 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49409 rcu_read_lock();
49410 cred = __task_cred(task);
49411 inode->i_uid = cred->euid;
49412 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49413 + inode->i_gid = grsec_proc_gid;
49414 +#else
49415 inode->i_gid = cred->egid;
49416 +#endif
49417 rcu_read_unlock();
49418 }
49419 security_task_to_inode(task, inode);
49420 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49421 return -ENOENT;
49422 }
49423 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49424 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49425 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49426 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49427 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49428 +#endif
49429 task_dumpable(task)) {
49430 cred = __task_cred(task);
49431 stat->uid = cred->euid;
49432 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49433 + stat->gid = grsec_proc_gid;
49434 +#else
49435 stat->gid = cred->egid;
49436 +#endif
49437 }
49438 }
49439 rcu_read_unlock();
49440 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49441
49442 if (task) {
49443 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49444 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49445 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49446 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49447 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49448 +#endif
49449 task_dumpable(task)) {
49450 rcu_read_lock();
49451 cred = __task_cred(task);
49452 inode->i_uid = cred->euid;
49453 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49454 + inode->i_gid = grsec_proc_gid;
49455 +#else
49456 inode->i_gid = cred->egid;
49457 +#endif
49458 rcu_read_unlock();
49459 } else {
49460 inode->i_uid = GLOBAL_ROOT_UID;
49461 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49462 int fd = proc_fd(inode);
49463
49464 if (task) {
49465 - files = get_files_struct(task);
49466 + if (!gr_acl_handle_procpidmem(task))
49467 + files = get_files_struct(task);
49468 put_task_struct(task);
49469 }
49470 if (files) {
49471 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49472 */
49473 static int proc_fd_permission(struct inode *inode, int mask)
49474 {
49475 + struct task_struct *task;
49476 int rv = generic_permission(inode, mask);
49477 - if (rv == 0)
49478 - return 0;
49479 +
49480 if (task_pid(current) == proc_pid(inode))
49481 rv = 0;
49482 +
49483 + task = get_proc_task(inode);
49484 + if (task == NULL)
49485 + return rv;
49486 +
49487 + if (gr_acl_handle_procpidmem(task))
49488 + rv = -EACCES;
49489 +
49490 + put_task_struct(task);
49491 +
49492 return rv;
49493 }
49494
49495 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49496 if (!task)
49497 goto out_no_task;
49498
49499 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49500 + goto out;
49501 +
49502 /*
49503 * Yes, it does not scale. And it should not. Don't add
49504 * new entries into /proc/<tgid>/ without very good reasons.
49505 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49506 if (!task)
49507 goto out_no_task;
49508
49509 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49510 + goto out;
49511 +
49512 ret = 0;
49513 i = filp->f_pos;
49514 switch (i) {
49515 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49516 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49517 void *cookie)
49518 {
49519 - char *s = nd_get_link(nd);
49520 + const char *s = nd_get_link(nd);
49521 if (!IS_ERR(s))
49522 __putname(s);
49523 }
49524 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49525 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49526 #endif
49527 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49528 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49529 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49530 INF("syscall", S_IRUGO, proc_pid_syscall),
49531 #endif
49532 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49533 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49534 #ifdef CONFIG_SECURITY
49535 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49536 #endif
49537 -#ifdef CONFIG_KALLSYMS
49538 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49539 INF("wchan", S_IRUGO, proc_pid_wchan),
49540 #endif
49541 -#ifdef CONFIG_STACKTRACE
49542 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49543 ONE("stack", S_IRUGO, proc_pid_stack),
49544 #endif
49545 #ifdef CONFIG_SCHEDSTATS
49546 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49547 #ifdef CONFIG_HARDWALL
49548 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49549 #endif
49550 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49551 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49552 +#endif
49553 #ifdef CONFIG_USER_NS
49554 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49555 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49556 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49557 if (!inode)
49558 goto out;
49559
49560 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49561 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49562 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49563 + inode->i_gid = grsec_proc_gid;
49564 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49565 +#else
49566 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49567 +#endif
49568 inode->i_op = &proc_tgid_base_inode_operations;
49569 inode->i_fop = &proc_tgid_base_operations;
49570 inode->i_flags|=S_IMMUTABLE;
49571 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49572 if (!task)
49573 goto out;
49574
49575 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49576 + goto out_put_task;
49577 +
49578 result = proc_pid_instantiate(dir, dentry, task, NULL);
49579 +out_put_task:
49580 put_task_struct(task);
49581 out:
49582 return result;
49583 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49584 static int fake_filldir(void *buf, const char *name, int namelen,
49585 loff_t offset, u64 ino, unsigned d_type)
49586 {
49587 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49588 + __buf->error = -EINVAL;
49589 return 0;
49590 }
49591
49592 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49593 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49594 #endif
49595 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49596 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49597 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49598 INF("syscall", S_IRUGO, proc_pid_syscall),
49599 #endif
49600 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49601 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49602 #ifdef CONFIG_SECURITY
49603 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49604 #endif
49605 -#ifdef CONFIG_KALLSYMS
49606 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49607 INF("wchan", S_IRUGO, proc_pid_wchan),
49608 #endif
49609 -#ifdef CONFIG_STACKTRACE
49610 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49611 ONE("stack", S_IRUGO, proc_pid_stack),
49612 #endif
49613 #ifdef CONFIG_SCHEDSTATS
49614 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49615 index 82676e3..5f8518a 100644
49616 --- a/fs/proc/cmdline.c
49617 +++ b/fs/proc/cmdline.c
49618 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49619
49620 static int __init proc_cmdline_init(void)
49621 {
49622 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49623 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49624 +#else
49625 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49626 +#endif
49627 return 0;
49628 }
49629 module_init(proc_cmdline_init);
49630 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49631 index b143471..bb105e5 100644
49632 --- a/fs/proc/devices.c
49633 +++ b/fs/proc/devices.c
49634 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49635
49636 static int __init proc_devices_init(void)
49637 {
49638 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49639 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49640 +#else
49641 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49642 +#endif
49643 return 0;
49644 }
49645 module_init(proc_devices_init);
49646 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49647 index 7ac817b..c5c9eb0 100644
49648 --- a/fs/proc/inode.c
49649 +++ b/fs/proc/inode.c
49650 @@ -21,11 +21,17 @@
49651 #include <linux/seq_file.h>
49652 #include <linux/slab.h>
49653 #include <linux/mount.h>
49654 +#include <linux/grsecurity.h>
49655
49656 #include <asm/uaccess.h>
49657
49658 #include "internal.h"
49659
49660 +#ifdef CONFIG_PROC_SYSCTL
49661 +extern const struct inode_operations proc_sys_inode_operations;
49662 +extern const struct inode_operations proc_sys_dir_operations;
49663 +#endif
49664 +
49665 static void proc_evict_inode(struct inode *inode)
49666 {
49667 struct proc_dir_entry *de;
49668 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49669 ns_ops = PROC_I(inode)->ns_ops;
49670 if (ns_ops && ns_ops->put)
49671 ns_ops->put(PROC_I(inode)->ns);
49672 +
49673 +#ifdef CONFIG_PROC_SYSCTL
49674 + if (inode->i_op == &proc_sys_inode_operations ||
49675 + inode->i_op == &proc_sys_dir_operations)
49676 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49677 +#endif
49678 +
49679 }
49680
49681 static struct kmem_cache * proc_inode_cachep;
49682 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49683 if (de->mode) {
49684 inode->i_mode = de->mode;
49685 inode->i_uid = de->uid;
49686 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49687 + inode->i_gid = grsec_proc_gid;
49688 +#else
49689 inode->i_gid = de->gid;
49690 +#endif
49691 }
49692 if (de->size)
49693 inode->i_size = de->size;
49694 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49695 index e1167a1..bd24f20 100644
49696 --- a/fs/proc/internal.h
49697 +++ b/fs/proc/internal.h
49698 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49699 struct pid *pid, struct task_struct *task);
49700 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49701 struct pid *pid, struct task_struct *task);
49702 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49703 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49704 +#endif
49705 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49706
49707 extern const struct file_operations proc_tid_children_operations;
49708 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49709 index 86c67ee..cdca321 100644
49710 --- a/fs/proc/kcore.c
49711 +++ b/fs/proc/kcore.c
49712 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49713 * the addresses in the elf_phdr on our list.
49714 */
49715 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49716 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49717 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49718 + if (tsz > buflen)
49719 tsz = buflen;
49720 -
49721 +
49722 while (buflen) {
49723 struct kcore_list *m;
49724
49725 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49726 kfree(elf_buf);
49727 } else {
49728 if (kern_addr_valid(start)) {
49729 - unsigned long n;
49730 + char *elf_buf;
49731 + mm_segment_t oldfs;
49732
49733 - n = copy_to_user(buffer, (char *)start, tsz);
49734 - /*
49735 - * We cannot distinguish between fault on source
49736 - * and fault on destination. When this happens
49737 - * we clear too and hope it will trigger the
49738 - * EFAULT again.
49739 - */
49740 - if (n) {
49741 - if (clear_user(buffer + tsz - n,
49742 - n))
49743 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49744 + if (!elf_buf)
49745 + return -ENOMEM;
49746 + oldfs = get_fs();
49747 + set_fs(KERNEL_DS);
49748 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49749 + set_fs(oldfs);
49750 + if (copy_to_user(buffer, elf_buf, tsz)) {
49751 + kfree(elf_buf);
49752 return -EFAULT;
49753 + }
49754 }
49755 + set_fs(oldfs);
49756 + kfree(elf_buf);
49757 } else {
49758 if (clear_user(buffer, tsz))
49759 return -EFAULT;
49760 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49761
49762 static int open_kcore(struct inode *inode, struct file *filp)
49763 {
49764 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49765 + return -EPERM;
49766 +#endif
49767 if (!capable(CAP_SYS_RAWIO))
49768 return -EPERM;
49769 if (kcore_need_update)
49770 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49771 index 80e4645..53e5fcf 100644
49772 --- a/fs/proc/meminfo.c
49773 +++ b/fs/proc/meminfo.c
49774 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49775 vmi.used >> 10,
49776 vmi.largest_chunk >> 10
49777 #ifdef CONFIG_MEMORY_FAILURE
49778 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49779 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49780 #endif
49781 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49782 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49783 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49784 index b1822dd..df622cb 100644
49785 --- a/fs/proc/nommu.c
49786 +++ b/fs/proc/nommu.c
49787 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49788 if (len < 1)
49789 len = 1;
49790 seq_printf(m, "%*c", len, ' ');
49791 - seq_path(m, &file->f_path, "");
49792 + seq_path(m, &file->f_path, "\n\\");
49793 }
49794
49795 seq_putc(m, '\n');
49796 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49797 index fe72cd0..cb9b67d 100644
49798 --- a/fs/proc/proc_net.c
49799 +++ b/fs/proc/proc_net.c
49800 @@ -23,6 +23,7 @@
49801 #include <linux/nsproxy.h>
49802 #include <net/net_namespace.h>
49803 #include <linux/seq_file.h>
49804 +#include <linux/grsecurity.h>
49805
49806 #include "internal.h"
49807
49808 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49809 struct task_struct *task;
49810 struct nsproxy *ns;
49811 struct net *net = NULL;
49812 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49813 + const struct cred *cred = current_cred();
49814 +#endif
49815 +
49816 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49817 + if (cred->fsuid)
49818 + return net;
49819 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49820 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49821 + return net;
49822 +#endif
49823
49824 rcu_read_lock();
49825 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49826 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49827 index eb7cc91..7327a46 100644
49828 --- a/fs/proc/proc_sysctl.c
49829 +++ b/fs/proc/proc_sysctl.c
49830 @@ -12,11 +12,15 @@
49831 #include <linux/module.h>
49832 #include "internal.h"
49833
49834 +extern int gr_handle_chroot_sysctl(const int op);
49835 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49836 + const int op);
49837 +
49838 static const struct dentry_operations proc_sys_dentry_operations;
49839 static const struct file_operations proc_sys_file_operations;
49840 -static const struct inode_operations proc_sys_inode_operations;
49841 +const struct inode_operations proc_sys_inode_operations;
49842 static const struct file_operations proc_sys_dir_file_operations;
49843 -static const struct inode_operations proc_sys_dir_operations;
49844 +const struct inode_operations proc_sys_dir_operations;
49845
49846 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49847 {
49848 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49849
49850 err = NULL;
49851 d_set_d_op(dentry, &proc_sys_dentry_operations);
49852 +
49853 + gr_handle_proc_create(dentry, inode);
49854 +
49855 d_add(dentry, inode);
49856
49857 out:
49858 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49859 struct inode *inode = filp->f_path.dentry->d_inode;
49860 struct ctl_table_header *head = grab_header(inode);
49861 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49862 + int op = write ? MAY_WRITE : MAY_READ;
49863 ssize_t error;
49864 size_t res;
49865
49866 if (IS_ERR(head))
49867 return PTR_ERR(head);
49868
49869 +
49870 /*
49871 * At this point we know that the sysctl was not unregistered
49872 * and won't be until we finish.
49873 */
49874 error = -EPERM;
49875 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49876 + if (sysctl_perm(head->root, table, op))
49877 goto out;
49878
49879 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49880 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49881 if (!table->proc_handler)
49882 goto out;
49883
49884 +#ifdef CONFIG_GRKERNSEC
49885 + error = -EPERM;
49886 + if (gr_handle_chroot_sysctl(op))
49887 + goto out;
49888 + dget(filp->f_path.dentry);
49889 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49890 + dput(filp->f_path.dentry);
49891 + goto out;
49892 + }
49893 + dput(filp->f_path.dentry);
49894 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49895 + goto out;
49896 + if (write && !capable(CAP_SYS_ADMIN))
49897 + goto out;
49898 +#endif
49899 +
49900 /* careful: calling conventions are nasty here */
49901 res = count;
49902 error = table->proc_handler(table, write, buf, &res, ppos);
49903 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49904 return -ENOMEM;
49905 } else {
49906 d_set_d_op(child, &proc_sys_dentry_operations);
49907 +
49908 + gr_handle_proc_create(child, inode);
49909 +
49910 d_add(child, inode);
49911 }
49912 } else {
49913 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49914 if ((*pos)++ < file->f_pos)
49915 return 0;
49916
49917 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49918 + return 0;
49919 +
49920 if (unlikely(S_ISLNK(table->mode)))
49921 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49922 else
49923 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49924 if (IS_ERR(head))
49925 return PTR_ERR(head);
49926
49927 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49928 + return -ENOENT;
49929 +
49930 generic_fillattr(inode, stat);
49931 if (table)
49932 stat->mode = (stat->mode & S_IFMT) | table->mode;
49933 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49934 .llseek = generic_file_llseek,
49935 };
49936
49937 -static const struct inode_operations proc_sys_inode_operations = {
49938 +const struct inode_operations proc_sys_inode_operations = {
49939 .permission = proc_sys_permission,
49940 .setattr = proc_sys_setattr,
49941 .getattr = proc_sys_getattr,
49942 };
49943
49944 -static const struct inode_operations proc_sys_dir_operations = {
49945 +const struct inode_operations proc_sys_dir_operations = {
49946 .lookup = proc_sys_lookup,
49947 .permission = proc_sys_permission,
49948 .setattr = proc_sys_setattr,
49949 diff --git a/fs/proc/root.c b/fs/proc/root.c
49950 index 9a2d9fd..ddfc92a 100644
49951 --- a/fs/proc/root.c
49952 +++ b/fs/proc/root.c
49953 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49954 #ifdef CONFIG_PROC_DEVICETREE
49955 proc_device_tree_init();
49956 #endif
49957 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49958 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49959 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49960 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49961 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49962 +#endif
49963 +#else
49964 proc_mkdir("bus", NULL);
49965 +#endif
49966 proc_sys_init();
49967 }
49968
49969 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49970 index 4540b8f..1b9772f 100644
49971 --- a/fs/proc/task_mmu.c
49972 +++ b/fs/proc/task_mmu.c
49973 @@ -11,12 +11,19 @@
49974 #include <linux/rmap.h>
49975 #include <linux/swap.h>
49976 #include <linux/swapops.h>
49977 +#include <linux/grsecurity.h>
49978
49979 #include <asm/elf.h>
49980 #include <asm/uaccess.h>
49981 #include <asm/tlbflush.h>
49982 #include "internal.h"
49983
49984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49985 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49986 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49987 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49988 +#endif
49989 +
49990 void task_mem(struct seq_file *m, struct mm_struct *mm)
49991 {
49992 unsigned long data, text, lib, swap;
49993 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49994 "VmExe:\t%8lu kB\n"
49995 "VmLib:\t%8lu kB\n"
49996 "VmPTE:\t%8lu kB\n"
49997 - "VmSwap:\t%8lu kB\n",
49998 - hiwater_vm << (PAGE_SHIFT-10),
49999 + "VmSwap:\t%8lu kB\n"
50000 +
50001 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50002 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50003 +#endif
50004 +
50005 + ,hiwater_vm << (PAGE_SHIFT-10),
50006 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50007 mm->locked_vm << (PAGE_SHIFT-10),
50008 mm->pinned_vm << (PAGE_SHIFT-10),
50009 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50010 data << (PAGE_SHIFT-10),
50011 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50012 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50013 - swap << (PAGE_SHIFT-10));
50014 + swap << (PAGE_SHIFT-10)
50015 +
50016 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50017 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50018 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50019 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50020 +#else
50021 + , mm->context.user_cs_base
50022 + , mm->context.user_cs_limit
50023 +#endif
50024 +#endif
50025 +
50026 + );
50027 }
50028
50029 unsigned long task_vsize(struct mm_struct *mm)
50030 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50031 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50032 }
50033
50034 - /* We don't show the stack guard page in /proc/maps */
50035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50036 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50037 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50038 +#else
50039 start = vma->vm_start;
50040 - if (stack_guard_page_start(vma, start))
50041 - start += PAGE_SIZE;
50042 end = vma->vm_end;
50043 - if (stack_guard_page_end(vma, end))
50044 - end -= PAGE_SIZE;
50045 +#endif
50046
50047 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50048 start,
50049 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50050 flags & VM_WRITE ? 'w' : '-',
50051 flags & VM_EXEC ? 'x' : '-',
50052 flags & VM_MAYSHARE ? 's' : 'p',
50053 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50054 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50055 +#else
50056 pgoff,
50057 +#endif
50058 MAJOR(dev), MINOR(dev), ino, &len);
50059
50060 /*
50061 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50062 */
50063 if (file) {
50064 pad_len_spaces(m, len);
50065 - seq_path(m, &file->f_path, "\n");
50066 + seq_path(m, &file->f_path, "\n\\");
50067 goto done;
50068 }
50069
50070 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50071 * Thread stack in /proc/PID/task/TID/maps or
50072 * the main process stack.
50073 */
50074 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
50075 - vma->vm_end >= mm->start_stack)) {
50076 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50077 + (vma->vm_start <= mm->start_stack &&
50078 + vma->vm_end >= mm->start_stack)) {
50079 name = "[stack]";
50080 } else {
50081 /* Thread stack in /proc/PID/maps */
50082 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50083 struct proc_maps_private *priv = m->private;
50084 struct task_struct *task = priv->task;
50085
50086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50087 + if (current->exec_id != m->exec_id) {
50088 + gr_log_badprocpid("maps");
50089 + return 0;
50090 + }
50091 +#endif
50092 +
50093 show_map_vma(m, vma, is_pid);
50094
50095 if (m->count < m->size) /* vma is copied successfully */
50096 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50097 .private = &mss,
50098 };
50099
50100 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50101 + if (current->exec_id != m->exec_id) {
50102 + gr_log_badprocpid("smaps");
50103 + return 0;
50104 + }
50105 +#endif
50106 memset(&mss, 0, sizeof mss);
50107 - mss.vma = vma;
50108 - /* mmap_sem is held in m_start */
50109 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50110 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50111 -
50112 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50113 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50114 +#endif
50115 + mss.vma = vma;
50116 + /* mmap_sem is held in m_start */
50117 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50118 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50119 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50120 + }
50121 +#endif
50122 show_map_vma(m, vma, is_pid);
50123
50124 seq_printf(m,
50125 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50126 "KernelPageSize: %8lu kB\n"
50127 "MMUPageSize: %8lu kB\n"
50128 "Locked: %8lu kB\n",
50129 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50130 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50131 +#else
50132 (vma->vm_end - vma->vm_start) >> 10,
50133 +#endif
50134 mss.resident >> 10,
50135 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50136 mss.shared_clean >> 10,
50137 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50138 int n;
50139 char buffer[50];
50140
50141 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50142 + if (current->exec_id != m->exec_id) {
50143 + gr_log_badprocpid("numa_maps");
50144 + return 0;
50145 + }
50146 +#endif
50147 +
50148 if (!mm)
50149 return 0;
50150
50151 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50152 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50153 mpol_cond_put(pol);
50154
50155 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50156 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50157 +#else
50158 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50159 +#endif
50160
50161 if (file) {
50162 seq_printf(m, " file=");
50163 - seq_path(m, &file->f_path, "\n\t= ");
50164 + seq_path(m, &file->f_path, "\n\t\\= ");
50165 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50166 seq_printf(m, " heap");
50167 } else {
50168 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50169 index 1ccfa53..0848f95 100644
50170 --- a/fs/proc/task_nommu.c
50171 +++ b/fs/proc/task_nommu.c
50172 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50173 else
50174 bytes += kobjsize(mm);
50175
50176 - if (current->fs && current->fs->users > 1)
50177 + if (current->fs && atomic_read(&current->fs->users) > 1)
50178 sbytes += kobjsize(current->fs);
50179 else
50180 bytes += kobjsize(current->fs);
50181 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50182
50183 if (file) {
50184 pad_len_spaces(m, len);
50185 - seq_path(m, &file->f_path, "");
50186 + seq_path(m, &file->f_path, "\n\\");
50187 } else if (mm) {
50188 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50189
50190 diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
50191 index 29996e8..2d1e0f3 100644
50192 --- a/fs/pstore/platform.c
50193 +++ b/fs/pstore/platform.c
50194 @@ -161,12 +161,13 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
50195
50196 while (s < e) {
50197 unsigned long flags;
50198 + u64 id;
50199
50200 if (c > psinfo->bufsize)
50201 c = psinfo->bufsize;
50202 spin_lock_irqsave(&psinfo->buf_lock, flags);
50203 memcpy(psinfo->buf, s, c);
50204 - psinfo->write(PSTORE_TYPE_CONSOLE, 0, NULL, 0, c, psinfo);
50205 + psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
50206 spin_unlock_irqrestore(&psinfo->buf_lock, flags);
50207 s += c;
50208 c = e - s;
50209 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50210 index d67908b..d13f6a6 100644
50211 --- a/fs/quota/netlink.c
50212 +++ b/fs/quota/netlink.c
50213 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50214 void quota_send_warning(short type, unsigned int id, dev_t dev,
50215 const char warntype)
50216 {
50217 - static atomic_t seq;
50218 + static atomic_unchecked_t seq;
50219 struct sk_buff *skb;
50220 void *msg_head;
50221 int ret;
50222 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50223 "VFS: Not enough memory to send quota warning.\n");
50224 return;
50225 }
50226 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50227 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50228 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50229 if (!msg_head) {
50230 printk(KERN_ERR
50231 diff --git a/fs/readdir.c b/fs/readdir.c
50232 index 39e3370..20d446d 100644
50233 --- a/fs/readdir.c
50234 +++ b/fs/readdir.c
50235 @@ -17,6 +17,7 @@
50236 #include <linux/security.h>
50237 #include <linux/syscalls.h>
50238 #include <linux/unistd.h>
50239 +#include <linux/namei.h>
50240
50241 #include <asm/uaccess.h>
50242
50243 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50244
50245 struct readdir_callback {
50246 struct old_linux_dirent __user * dirent;
50247 + struct file * file;
50248 int result;
50249 };
50250
50251 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50252 buf->result = -EOVERFLOW;
50253 return -EOVERFLOW;
50254 }
50255 +
50256 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50257 + return 0;
50258 +
50259 buf->result++;
50260 dirent = buf->dirent;
50261 if (!access_ok(VERIFY_WRITE, dirent,
50262 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50263
50264 buf.result = 0;
50265 buf.dirent = dirent;
50266 + buf.file = file;
50267
50268 error = vfs_readdir(file, fillonedir, &buf);
50269 if (buf.result)
50270 @@ -141,6 +148,7 @@ struct linux_dirent {
50271 struct getdents_callback {
50272 struct linux_dirent __user * current_dir;
50273 struct linux_dirent __user * previous;
50274 + struct file * file;
50275 int count;
50276 int error;
50277 };
50278 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50279 buf->error = -EOVERFLOW;
50280 return -EOVERFLOW;
50281 }
50282 +
50283 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50284 + return 0;
50285 +
50286 dirent = buf->previous;
50287 if (dirent) {
50288 if (__put_user(offset, &dirent->d_off))
50289 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50290 buf.previous = NULL;
50291 buf.count = count;
50292 buf.error = 0;
50293 + buf.file = file;
50294
50295 error = vfs_readdir(file, filldir, &buf);
50296 if (error >= 0)
50297 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50298 struct getdents_callback64 {
50299 struct linux_dirent64 __user * current_dir;
50300 struct linux_dirent64 __user * previous;
50301 + struct file *file;
50302 int count;
50303 int error;
50304 };
50305 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50306 buf->error = -EINVAL; /* only used if we fail.. */
50307 if (reclen > buf->count)
50308 return -EINVAL;
50309 +
50310 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50311 + return 0;
50312 +
50313 dirent = buf->previous;
50314 if (dirent) {
50315 if (__put_user(offset, &dirent->d_off))
50316 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50317
50318 buf.current_dir = dirent;
50319 buf.previous = NULL;
50320 + buf.file = file;
50321 buf.count = count;
50322 buf.error = 0;
50323
50324 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50325 error = buf.error;
50326 lastdirent = buf.previous;
50327 if (lastdirent) {
50328 - typeof(lastdirent->d_off) d_off = file->f_pos;
50329 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50330 if (__put_user(d_off, &lastdirent->d_off))
50331 error = -EFAULT;
50332 else
50333 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50334 index 2b7882b..1c5ef48 100644
50335 --- a/fs/reiserfs/do_balan.c
50336 +++ b/fs/reiserfs/do_balan.c
50337 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50338 return;
50339 }
50340
50341 - atomic_inc(&(fs_generation(tb->tb_sb)));
50342 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50343 do_balance_starts(tb);
50344
50345 /* balance leaf returns 0 except if combining L R and S into
50346 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50347 index e60e870..f40ac16 100644
50348 --- a/fs/reiserfs/procfs.c
50349 +++ b/fs/reiserfs/procfs.c
50350 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50351 "SMALL_TAILS " : "NO_TAILS ",
50352 replay_only(sb) ? "REPLAY_ONLY " : "",
50353 convert_reiserfs(sb) ? "CONV " : "",
50354 - atomic_read(&r->s_generation_counter),
50355 + atomic_read_unchecked(&r->s_generation_counter),
50356 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50357 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50358 SF(s_good_search_by_key_reada), SF(s_bmaps),
50359 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50360 index 33215f5..c5d427a 100644
50361 --- a/fs/reiserfs/reiserfs.h
50362 +++ b/fs/reiserfs/reiserfs.h
50363 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50364 /* Comment? -Hans */
50365 wait_queue_head_t s_wait;
50366 /* To be obsoleted soon by per buffer seals.. -Hans */
50367 - atomic_t s_generation_counter; // increased by one every time the
50368 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50369 // tree gets re-balanced
50370 unsigned long s_properties; /* File system properties. Currently holds
50371 on-disk FS format */
50372 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50373 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50374
50375 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50376 -#define get_generation(s) atomic_read (&fs_generation(s))
50377 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50378 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50379 #define __fs_changed(gen,s) (gen != get_generation (s))
50380 #define fs_changed(gen,s) \
50381 diff --git a/fs/select.c b/fs/select.c
50382 index db14c78..3aae1bd 100644
50383 --- a/fs/select.c
50384 +++ b/fs/select.c
50385 @@ -20,6 +20,7 @@
50386 #include <linux/export.h>
50387 #include <linux/slab.h>
50388 #include <linux/poll.h>
50389 +#include <linux/security.h>
50390 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50391 #include <linux/file.h>
50392 #include <linux/fdtable.h>
50393 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50394 struct poll_list *walk = head;
50395 unsigned long todo = nfds;
50396
50397 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50398 if (nfds > rlimit(RLIMIT_NOFILE))
50399 return -EINVAL;
50400
50401 diff --git a/fs/seq_file.c b/fs/seq_file.c
50402 index 14cf9de..adc4d5b 100644
50403 --- a/fs/seq_file.c
50404 +++ b/fs/seq_file.c
50405 @@ -9,6 +9,7 @@
50406 #include <linux/export.h>
50407 #include <linux/seq_file.h>
50408 #include <linux/slab.h>
50409 +#include <linux/sched.h>
50410
50411 #include <asm/uaccess.h>
50412 #include <asm/page.h>
50413 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50414 memset(p, 0, sizeof(*p));
50415 mutex_init(&p->lock);
50416 p->op = op;
50417 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50418 + p->exec_id = current->exec_id;
50419 +#endif
50420
50421 /*
50422 * Wrappers around seq_open(e.g. swaps_open) need to be
50423 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50424 return 0;
50425 }
50426 if (!m->buf) {
50427 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50428 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50429 if (!m->buf)
50430 return -ENOMEM;
50431 }
50432 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50433 Eoverflow:
50434 m->op->stop(m, p);
50435 kfree(m->buf);
50436 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50437 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50438 return !m->buf ? -ENOMEM : -EAGAIN;
50439 }
50440
50441 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50442
50443 /* grab buffer if we didn't have one */
50444 if (!m->buf) {
50445 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50446 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50447 if (!m->buf)
50448 goto Enomem;
50449 }
50450 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50451 goto Fill;
50452 m->op->stop(m, p);
50453 kfree(m->buf);
50454 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50455 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50456 if (!m->buf)
50457 goto Enomem;
50458 m->count = 0;
50459 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50460 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50461 void *data)
50462 {
50463 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50464 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50465 int res = -ENOMEM;
50466
50467 if (op) {
50468 diff --git a/fs/splice.c b/fs/splice.c
50469 index 41514dd..6564a93 100644
50470 --- a/fs/splice.c
50471 +++ b/fs/splice.c
50472 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50473 pipe_lock(pipe);
50474
50475 for (;;) {
50476 - if (!pipe->readers) {
50477 + if (!atomic_read(&pipe->readers)) {
50478 send_sig(SIGPIPE, current, 0);
50479 if (!ret)
50480 ret = -EPIPE;
50481 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50482 do_wakeup = 0;
50483 }
50484
50485 - pipe->waiting_writers++;
50486 + atomic_inc(&pipe->waiting_writers);
50487 pipe_wait(pipe);
50488 - pipe->waiting_writers--;
50489 + atomic_dec(&pipe->waiting_writers);
50490 }
50491
50492 pipe_unlock(pipe);
50493 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50494 old_fs = get_fs();
50495 set_fs(get_ds());
50496 /* The cast to a user pointer is valid due to the set_fs() */
50497 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50498 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50499 set_fs(old_fs);
50500
50501 return res;
50502 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50503 old_fs = get_fs();
50504 set_fs(get_ds());
50505 /* The cast to a user pointer is valid due to the set_fs() */
50506 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50507 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50508 set_fs(old_fs);
50509
50510 return res;
50511 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50512 goto err;
50513
50514 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50515 - vec[i].iov_base = (void __user *) page_address(page);
50516 + vec[i].iov_base = (void __force_user *) page_address(page);
50517 vec[i].iov_len = this_len;
50518 spd.pages[i] = page;
50519 spd.nr_pages++;
50520 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50521 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50522 {
50523 while (!pipe->nrbufs) {
50524 - if (!pipe->writers)
50525 + if (!atomic_read(&pipe->writers))
50526 return 0;
50527
50528 - if (!pipe->waiting_writers && sd->num_spliced)
50529 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50530 return 0;
50531
50532 if (sd->flags & SPLICE_F_NONBLOCK)
50533 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50534 * out of the pipe right after the splice_to_pipe(). So set
50535 * PIPE_READERS appropriately.
50536 */
50537 - pipe->readers = 1;
50538 + atomic_set(&pipe->readers, 1);
50539
50540 current->splice_pipe = pipe;
50541 }
50542 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50543 ret = -ERESTARTSYS;
50544 break;
50545 }
50546 - if (!pipe->writers)
50547 + if (!atomic_read(&pipe->writers))
50548 break;
50549 - if (!pipe->waiting_writers) {
50550 + if (!atomic_read(&pipe->waiting_writers)) {
50551 if (flags & SPLICE_F_NONBLOCK) {
50552 ret = -EAGAIN;
50553 break;
50554 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50555 pipe_lock(pipe);
50556
50557 while (pipe->nrbufs >= pipe->buffers) {
50558 - if (!pipe->readers) {
50559 + if (!atomic_read(&pipe->readers)) {
50560 send_sig(SIGPIPE, current, 0);
50561 ret = -EPIPE;
50562 break;
50563 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50564 ret = -ERESTARTSYS;
50565 break;
50566 }
50567 - pipe->waiting_writers++;
50568 + atomic_inc(&pipe->waiting_writers);
50569 pipe_wait(pipe);
50570 - pipe->waiting_writers--;
50571 + atomic_dec(&pipe->waiting_writers);
50572 }
50573
50574 pipe_unlock(pipe);
50575 @@ -1828,14 +1828,14 @@ retry:
50576 pipe_double_lock(ipipe, opipe);
50577
50578 do {
50579 - if (!opipe->readers) {
50580 + if (!atomic_read(&opipe->readers)) {
50581 send_sig(SIGPIPE, current, 0);
50582 if (!ret)
50583 ret = -EPIPE;
50584 break;
50585 }
50586
50587 - if (!ipipe->nrbufs && !ipipe->writers)
50588 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50589 break;
50590
50591 /*
50592 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50593 pipe_double_lock(ipipe, opipe);
50594
50595 do {
50596 - if (!opipe->readers) {
50597 + if (!atomic_read(&opipe->readers)) {
50598 send_sig(SIGPIPE, current, 0);
50599 if (!ret)
50600 ret = -EPIPE;
50601 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50602 * return EAGAIN if we have the potential of some data in the
50603 * future, otherwise just return 0
50604 */
50605 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50606 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50607 ret = -EAGAIN;
50608
50609 pipe_unlock(ipipe);
50610 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50611 index 2fbdff6..5530a61 100644
50612 --- a/fs/sysfs/dir.c
50613 +++ b/fs/sysfs/dir.c
50614 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50615 struct sysfs_dirent *sd;
50616 int rc;
50617
50618 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50619 + const char *parent_name = parent_sd->s_name;
50620 +
50621 + mode = S_IFDIR | S_IRWXU;
50622 +
50623 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50624 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50625 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50626 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50627 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50628 +#endif
50629 +
50630 /* allocate */
50631 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50632 if (!sd)
50633 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50634 index 00012e3..8392349 100644
50635 --- a/fs/sysfs/file.c
50636 +++ b/fs/sysfs/file.c
50637 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50638
50639 struct sysfs_open_dirent {
50640 atomic_t refcnt;
50641 - atomic_t event;
50642 + atomic_unchecked_t event;
50643 wait_queue_head_t poll;
50644 struct list_head buffers; /* goes through sysfs_buffer.list */
50645 };
50646 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50647 if (!sysfs_get_active(attr_sd))
50648 return -ENODEV;
50649
50650 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50651 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50652 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50653
50654 sysfs_put_active(attr_sd);
50655 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50656 return -ENOMEM;
50657
50658 atomic_set(&new_od->refcnt, 0);
50659 - atomic_set(&new_od->event, 1);
50660 + atomic_set_unchecked(&new_od->event, 1);
50661 init_waitqueue_head(&new_od->poll);
50662 INIT_LIST_HEAD(&new_od->buffers);
50663 goto retry;
50664 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50665
50666 sysfs_put_active(attr_sd);
50667
50668 - if (buffer->event != atomic_read(&od->event))
50669 + if (buffer->event != atomic_read_unchecked(&od->event))
50670 goto trigger;
50671
50672 return DEFAULT_POLLMASK;
50673 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50674
50675 od = sd->s_attr.open;
50676 if (od) {
50677 - atomic_inc(&od->event);
50678 + atomic_inc_unchecked(&od->event);
50679 wake_up_interruptible(&od->poll);
50680 }
50681
50682 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50683 index a7ac78f..02158e1 100644
50684 --- a/fs/sysfs/symlink.c
50685 +++ b/fs/sysfs/symlink.c
50686 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50687
50688 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50689 {
50690 - char *page = nd_get_link(nd);
50691 + const char *page = nd_get_link(nd);
50692 if (!IS_ERR(page))
50693 free_page((unsigned long)page);
50694 }
50695 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50696 index c175b4d..8f36a16 100644
50697 --- a/fs/udf/misc.c
50698 +++ b/fs/udf/misc.c
50699 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50700
50701 u8 udf_tag_checksum(const struct tag *t)
50702 {
50703 - u8 *data = (u8 *)t;
50704 + const u8 *data = (const u8 *)t;
50705 u8 checksum = 0;
50706 int i;
50707 for (i = 0; i < sizeof(struct tag); ++i)
50708 diff --git a/fs/utimes.c b/fs/utimes.c
50709 index fa4dbe4..e12d1b9 100644
50710 --- a/fs/utimes.c
50711 +++ b/fs/utimes.c
50712 @@ -1,6 +1,7 @@
50713 #include <linux/compiler.h>
50714 #include <linux/file.h>
50715 #include <linux/fs.h>
50716 +#include <linux/security.h>
50717 #include <linux/linkage.h>
50718 #include <linux/mount.h>
50719 #include <linux/namei.h>
50720 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50721 goto mnt_drop_write_and_out;
50722 }
50723 }
50724 +
50725 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50726 + error = -EACCES;
50727 + goto mnt_drop_write_and_out;
50728 + }
50729 +
50730 mutex_lock(&inode->i_mutex);
50731 error = notify_change(path->dentry, &newattrs);
50732 mutex_unlock(&inode->i_mutex);
50733 diff --git a/fs/xattr.c b/fs/xattr.c
50734 index 4d45b71..2ec08e10 100644
50735 --- a/fs/xattr.c
50736 +++ b/fs/xattr.c
50737 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50738 * Extended attribute SET operations
50739 */
50740 static long
50741 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50742 +setxattr(struct path *path, const char __user *name, const void __user *value,
50743 size_t size, int flags)
50744 {
50745 int error;
50746 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50747 }
50748 }
50749
50750 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50751 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50752 + error = -EACCES;
50753 + goto out;
50754 + }
50755 +
50756 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50757 out:
50758 if (vvalue)
50759 vfree(vvalue);
50760 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50761 return error;
50762 error = mnt_want_write(path.mnt);
50763 if (!error) {
50764 - error = setxattr(path.dentry, name, value, size, flags);
50765 + error = setxattr(&path, name, value, size, flags);
50766 mnt_drop_write(path.mnt);
50767 }
50768 path_put(&path);
50769 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50770 return error;
50771 error = mnt_want_write(path.mnt);
50772 if (!error) {
50773 - error = setxattr(path.dentry, name, value, size, flags);
50774 + error = setxattr(&path, name, value, size, flags);
50775 mnt_drop_write(path.mnt);
50776 }
50777 path_put(&path);
50778 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50779 {
50780 int fput_needed;
50781 struct file *f;
50782 - struct dentry *dentry;
50783 int error = -EBADF;
50784
50785 f = fget_light(fd, &fput_needed);
50786 if (!f)
50787 return error;
50788 - dentry = f->f_path.dentry;
50789 - audit_inode(NULL, dentry);
50790 + audit_inode(NULL, f->f_path.dentry);
50791 error = mnt_want_write_file(f);
50792 if (!error) {
50793 - error = setxattr(dentry, name, value, size, flags);
50794 + error = setxattr(&f->f_path, name, value, size, flags);
50795 mnt_drop_write_file(f);
50796 }
50797 fput_light(f, fput_needed);
50798 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50799 index 69d06b0..c0996e5 100644
50800 --- a/fs/xattr_acl.c
50801 +++ b/fs/xattr_acl.c
50802 @@ -17,8 +17,8 @@
50803 struct posix_acl *
50804 posix_acl_from_xattr(const void *value, size_t size)
50805 {
50806 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50807 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50808 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50809 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50810 int count;
50811 struct posix_acl *acl;
50812 struct posix_acl_entry *acl_e;
50813 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50814 index 848ffa7..1f249bf 100644
50815 --- a/fs/xfs/xfs_bmap.c
50816 +++ b/fs/xfs/xfs_bmap.c
50817 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50818 int nmap,
50819 int ret_nmap);
50820 #else
50821 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50822 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50823 #endif /* DEBUG */
50824
50825 STATIC int
50826 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50827 index 1b9fc3e..e1bdde0 100644
50828 --- a/fs/xfs/xfs_dir2_sf.c
50829 +++ b/fs/xfs/xfs_dir2_sf.c
50830 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50831 }
50832
50833 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50834 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50835 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50836 + char name[sfep->namelen];
50837 + memcpy(name, sfep->name, sfep->namelen);
50838 + if (filldir(dirent, name, sfep->namelen,
50839 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50840 + *offset = off & 0x7fffffff;
50841 + return 0;
50842 + }
50843 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50844 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50845 *offset = off & 0x7fffffff;
50846 return 0;
50847 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50848 index 0e0232c..fa5c3fe 100644
50849 --- a/fs/xfs/xfs_ioctl.c
50850 +++ b/fs/xfs/xfs_ioctl.c
50851 @@ -126,7 +126,7 @@ xfs_find_handle(
50852 }
50853
50854 error = -EFAULT;
50855 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50856 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50857 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50858 goto out_put;
50859
50860 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50861 index 4e00cf0..3374374 100644
50862 --- a/fs/xfs/xfs_iops.c
50863 +++ b/fs/xfs/xfs_iops.c
50864 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50865 struct nameidata *nd,
50866 void *p)
50867 {
50868 - char *s = nd_get_link(nd);
50869 + const char *s = nd_get_link(nd);
50870
50871 if (!IS_ERR(s))
50872 kfree(s);
50873 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50874 new file mode 100644
50875 index 0000000..d38b430
50876 --- /dev/null
50877 +++ b/grsecurity/Kconfig
50878 @@ -0,0 +1,947 @@
50879 +#
50880 +# grecurity configuration
50881 +#
50882 +menu "Memory Protections"
50883 +depends on GRKERNSEC
50884 +
50885 +config GRKERNSEC_KMEM
50886 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50887 + default y if GRKERNSEC_CONFIG_AUTO
50888 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50889 + help
50890 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50891 + be written to or read from to modify or leak the contents of the running
50892 + kernel. /dev/port will also not be allowed to be opened. If you have module
50893 + support disabled, enabling this will close up four ways that are
50894 + currently used to insert malicious code into the running kernel.
50895 + Even with all these features enabled, we still highly recommend that
50896 + you use the RBAC system, as it is still possible for an attacker to
50897 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50898 + If you are not using XFree86, you may be able to stop this additional
50899 + case by enabling the 'Disable privileged I/O' option. Though nothing
50900 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50901 + but only to video memory, which is the only writing we allow in this
50902 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50903 + not be allowed to mprotect it with PROT_WRITE later.
50904 + It is highly recommended that you say Y here if you meet all the
50905 + conditions above.
50906 +
50907 +config GRKERNSEC_VM86
50908 + bool "Restrict VM86 mode"
50909 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50910 + depends on X86_32
50911 +
50912 + help
50913 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50914 + make use of a special execution mode on 32bit x86 processors called
50915 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50916 + video cards and will still work with this option enabled. The purpose
50917 + of the option is to prevent exploitation of emulation errors in
50918 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50919 + Nearly all users should be able to enable this option.
50920 +
50921 +config GRKERNSEC_IO
50922 + bool "Disable privileged I/O"
50923 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50924 + depends on X86
50925 + select RTC_CLASS
50926 + select RTC_INTF_DEV
50927 + select RTC_DRV_CMOS
50928 +
50929 + help
50930 + If you say Y here, all ioperm and iopl calls will return an error.
50931 + Ioperm and iopl can be used to modify the running kernel.
50932 + Unfortunately, some programs need this access to operate properly,
50933 + the most notable of which are XFree86 and hwclock. hwclock can be
50934 + remedied by having RTC support in the kernel, so real-time
50935 + clock support is enabled if this option is enabled, to ensure
50936 + that hwclock operates correctly. XFree86 still will not
50937 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50938 + IF YOU USE XFree86. If you use XFree86 and you still want to
50939 + protect your kernel against modification, use the RBAC system.
50940 +
50941 +config GRKERNSEC_PROC_MEMMAP
50942 + bool "Harden ASLR against information leaks and entropy reduction"
50943 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50944 + depends on PAX_NOEXEC || PAX_ASLR
50945 + help
50946 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50947 + give no information about the addresses of its mappings if
50948 + PaX features that rely on random addresses are enabled on the task.
50949 + In addition to sanitizing this information and disabling other
50950 + dangerous sources of information, this option causes reads of sensitive
50951 + /proc/<pid> entries where the file descriptor was opened in a different
50952 + task than the one performing the read. Such attempts are logged.
50953 + This option also limits argv/env strings for suid/sgid binaries
50954 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50955 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50956 + binaries to prevent alternative mmap layouts from being abused.
50957 +
50958 + If you use PaX it is essential that you say Y here as it closes up
50959 + several holes that make full ASLR useless locally.
50960 +
50961 +config GRKERNSEC_BRUTE
50962 + bool "Deter exploit bruteforcing"
50963 + default y if GRKERNSEC_CONFIG_AUTO
50964 + help
50965 + If you say Y here, attempts to bruteforce exploits against forking
50966 + daemons such as apache or sshd, as well as against suid/sgid binaries
50967 + will be deterred. When a child of a forking daemon is killed by PaX
50968 + or crashes due to an illegal instruction or other suspicious signal,
50969 + the parent process will be delayed 30 seconds upon every subsequent
50970 + fork until the administrator is able to assess the situation and
50971 + restart the daemon.
50972 + In the suid/sgid case, the attempt is logged, the user has all their
50973 + processes terminated, and they are prevented from executing any further
50974 + processes for 15 minutes.
50975 + It is recommended that you also enable signal logging in the auditing
50976 + section so that logs are generated when a process triggers a suspicious
50977 + signal.
50978 + If the sysctl option is enabled, a sysctl option with name
50979 + "deter_bruteforce" is created.
50980 +
50981 +
50982 +config GRKERNSEC_MODHARDEN
50983 + bool "Harden module auto-loading"
50984 + default y if GRKERNSEC_CONFIG_AUTO
50985 + depends on MODULES
50986 + help
50987 + If you say Y here, module auto-loading in response to use of some
50988 + feature implemented by an unloaded module will be restricted to
50989 + root users. Enabling this option helps defend against attacks
50990 + by unprivileged users who abuse the auto-loading behavior to
50991 + cause a vulnerable module to load that is then exploited.
50992 +
50993 + If this option prevents a legitimate use of auto-loading for a
50994 + non-root user, the administrator can execute modprobe manually
50995 + with the exact name of the module mentioned in the alert log.
50996 + Alternatively, the administrator can add the module to the list
50997 + of modules loaded at boot by modifying init scripts.
50998 +
50999 + Modification of init scripts will most likely be needed on
51000 + Ubuntu servers with encrypted home directory support enabled,
51001 + as the first non-root user logging in will cause the ecb(aes),
51002 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51003 +
51004 +config GRKERNSEC_HIDESYM
51005 + bool "Hide kernel symbols"
51006 + default y if GRKERNSEC_CONFIG_AUTO
51007 + select PAX_USERCOPY_SLABS
51008 + help
51009 + If you say Y here, getting information on loaded modules, and
51010 + displaying all kernel symbols through a syscall will be restricted
51011 + to users with CAP_SYS_MODULE. For software compatibility reasons,
51012 + /proc/kallsyms will be restricted to the root user. The RBAC
51013 + system can hide that entry even from root.
51014 +
51015 + This option also prevents leaking of kernel addresses through
51016 + several /proc entries.
51017 +
51018 + Note that this option is only effective provided the following
51019 + conditions are met:
51020 + 1) The kernel using grsecurity is not precompiled by some distribution
51021 + 2) You have also enabled GRKERNSEC_DMESG
51022 + 3) You are using the RBAC system and hiding other files such as your
51023 + kernel image and System.map. Alternatively, enabling this option
51024 + causes the permissions on /boot, /lib/modules, and the kernel
51025 + source directory to change at compile time to prevent
51026 + reading by non-root users.
51027 + If the above conditions are met, this option will aid in providing a
51028 + useful protection against local kernel exploitation of overflows
51029 + and arbitrary read/write vulnerabilities.
51030 +
51031 +config GRKERNSEC_KERN_LOCKOUT
51032 + bool "Active kernel exploit response"
51033 + default y if GRKERNSEC_CONFIG_AUTO
51034 + depends on X86 || ARM || PPC || SPARC
51035 + help
51036 + If you say Y here, when a PaX alert is triggered due to suspicious
51037 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51038 + or an OOPS occurs due to bad memory accesses, instead of just
51039 + terminating the offending process (and potentially allowing
51040 + a subsequent exploit from the same user), we will take one of two
51041 + actions:
51042 + If the user was root, we will panic the system
51043 + If the user was non-root, we will log the attempt, terminate
51044 + all processes owned by the user, then prevent them from creating
51045 + any new processes until the system is restarted
51046 + This deters repeated kernel exploitation/bruteforcing attempts
51047 + and is useful for later forensics.
51048 +
51049 +endmenu
51050 +menu "Role Based Access Control Options"
51051 +depends on GRKERNSEC
51052 +
51053 +config GRKERNSEC_RBAC_DEBUG
51054 + bool
51055 +
51056 +config GRKERNSEC_NO_RBAC
51057 + bool "Disable RBAC system"
51058 + help
51059 + If you say Y here, the /dev/grsec device will be removed from the kernel,
51060 + preventing the RBAC system from being enabled. You should only say Y
51061 + here if you have no intention of using the RBAC system, so as to prevent
51062 + an attacker with root access from misusing the RBAC system to hide files
51063 + and processes when loadable module support and /dev/[k]mem have been
51064 + locked down.
51065 +
51066 +config GRKERNSEC_ACL_HIDEKERN
51067 + bool "Hide kernel processes"
51068 + help
51069 + If you say Y here, all kernel threads will be hidden to all
51070 + processes but those whose subject has the "view hidden processes"
51071 + flag.
51072 +
51073 +config GRKERNSEC_ACL_MAXTRIES
51074 + int "Maximum tries before password lockout"
51075 + default 3
51076 + help
51077 + This option enforces the maximum number of times a user can attempt
51078 + to authorize themselves with the grsecurity RBAC system before being
51079 + denied the ability to attempt authorization again for a specified time.
51080 + The lower the number, the harder it will be to brute-force a password.
51081 +
51082 +config GRKERNSEC_ACL_TIMEOUT
51083 + int "Time to wait after max password tries, in seconds"
51084 + default 30
51085 + help
51086 + This option specifies the time the user must wait after attempting to
51087 + authorize to the RBAC system with the maximum number of invalid
51088 + passwords. The higher the number, the harder it will be to brute-force
51089 + a password.
51090 +
51091 +endmenu
51092 +menu "Filesystem Protections"
51093 +depends on GRKERNSEC
51094 +
51095 +config GRKERNSEC_PROC
51096 + bool "Proc restrictions"
51097 + default y if GRKERNSEC_CONFIG_AUTO
51098 + help
51099 + If you say Y here, the permissions of the /proc filesystem
51100 + will be altered to enhance system security and privacy. You MUST
51101 + choose either a user only restriction or a user and group restriction.
51102 + Depending upon the option you choose, you can either restrict users to
51103 + see only the processes they themselves run, or choose a group that can
51104 + view all processes and files normally restricted to root if you choose
51105 + the "restrict to user only" option. NOTE: If you're running identd or
51106 + ntpd as a non-root user, you will have to run it as the group you
51107 + specify here.
51108 +
51109 +config GRKERNSEC_PROC_USER
51110 + bool "Restrict /proc to user only"
51111 + depends on GRKERNSEC_PROC
51112 + help
51113 + If you say Y here, non-root users will only be able to view their own
51114 + processes, and restricts them from viewing network-related information,
51115 + and viewing kernel symbol and module information.
51116 +
51117 +config GRKERNSEC_PROC_USERGROUP
51118 + bool "Allow special group"
51119 + default y if GRKERNSEC_CONFIG_AUTO
51120 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51121 + help
51122 + If you say Y here, you will be able to select a group that will be
51123 + able to view all processes and network-related information. If you've
51124 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51125 + remain hidden. This option is useful if you want to run identd as
51126 + a non-root user. The group you select may also be chosen at boot time
51127 + via "grsec_proc_gid=" on the kernel commandline.
51128 +
51129 +config GRKERNSEC_PROC_GID
51130 + int "GID for special group"
51131 + depends on GRKERNSEC_PROC_USERGROUP
51132 + default 1001
51133 +
51134 +config GRKERNSEC_PROC_ADD
51135 + bool "Additional restrictions"
51136 + default y if GRKERNSEC_CONFIG_AUTO
51137 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51138 + help
51139 + If you say Y here, additional restrictions will be placed on
51140 + /proc that keep normal users from viewing device information and
51141 + slabinfo information that could be useful for exploits.
51142 +
51143 +config GRKERNSEC_LINK
51144 + bool "Linking restrictions"
51145 + default y if GRKERNSEC_CONFIG_AUTO
51146 + help
51147 + If you say Y here, /tmp race exploits will be prevented, since users
51148 + will no longer be able to follow symlinks owned by other users in
51149 + world-writable +t directories (e.g. /tmp), unless the owner of the
51150 + symlink is the owner of the directory. users will also not be
51151 + able to hardlink to files they do not own. If the sysctl option is
51152 + enabled, a sysctl option with name "linking_restrictions" is created.
51153 +
51154 +config GRKERNSEC_SYMLINKOWN
51155 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51156 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51157 + help
51158 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51159 + that prevents it from being used as a security feature. As Apache
51160 + verifies the symlink by performing a stat() against the target of
51161 + the symlink before it is followed, an attacker can setup a symlink
51162 + to point to a same-owned file, then replace the symlink with one
51163 + that targets another user's file just after Apache "validates" the
51164 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51165 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51166 + will be in place for the group you specify. If the sysctl option
51167 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51168 + created.
51169 +
51170 +config GRKERNSEC_SYMLINKOWN_GID
51171 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51172 + depends on GRKERNSEC_SYMLINKOWN
51173 + default 1006
51174 + help
51175 + Setting this GID determines what group kernel-enforced
51176 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51177 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51178 +
51179 +config GRKERNSEC_FIFO
51180 + bool "FIFO restrictions"
51181 + default y if GRKERNSEC_CONFIG_AUTO
51182 + help
51183 + If you say Y here, users will not be able to write to FIFOs they don't
51184 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51185 + the FIFO is the same owner of the directory it's held in. If the sysctl
51186 + option is enabled, a sysctl option with name "fifo_restrictions" is
51187 + created.
51188 +
51189 +config GRKERNSEC_SYSFS_RESTRICT
51190 + bool "Sysfs/debugfs restriction"
51191 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51192 + depends on SYSFS
51193 + help
51194 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51195 + any filesystem normally mounted under it (e.g. debugfs) will be
51196 + mostly accessible only by root. These filesystems generally provide access
51197 + to hardware and debug information that isn't appropriate for unprivileged
51198 + users of the system. Sysfs and debugfs have also become a large source
51199 + of new vulnerabilities, ranging from infoleaks to local compromise.
51200 + There has been very little oversight with an eye toward security involved
51201 + in adding new exporters of information to these filesystems, so their
51202 + use is discouraged.
51203 + For reasons of compatibility, a few directories have been whitelisted
51204 + for access by non-root users:
51205 + /sys/fs/selinux
51206 + /sys/fs/fuse
51207 + /sys/devices/system/cpu
51208 +
51209 +config GRKERNSEC_ROFS
51210 + bool "Runtime read-only mount protection"
51211 + help
51212 + If you say Y here, a sysctl option with name "romount_protect" will
51213 + be created. By setting this option to 1 at runtime, filesystems
51214 + will be protected in the following ways:
51215 + * No new writable mounts will be allowed
51216 + * Existing read-only mounts won't be able to be remounted read/write
51217 + * Write operations will be denied on all block devices
51218 + This option acts independently of grsec_lock: once it is set to 1,
51219 + it cannot be turned off. Therefore, please be mindful of the resulting
51220 + behavior if this option is enabled in an init script on a read-only
51221 + filesystem. This feature is mainly intended for secure embedded systems.
51222 +
51223 +config GRKERNSEC_CHROOT
51224 + bool "Chroot jail restrictions"
51225 + default y if GRKERNSEC_CONFIG_AUTO
51226 + help
51227 + If you say Y here, you will be able to choose several options that will
51228 + make breaking out of a chrooted jail much more difficult. If you
51229 + encounter no software incompatibilities with the following options, it
51230 + is recommended that you enable each one.
51231 +
51232 +config GRKERNSEC_CHROOT_MOUNT
51233 + bool "Deny mounts"
51234 + default y if GRKERNSEC_CONFIG_AUTO
51235 + depends on GRKERNSEC_CHROOT
51236 + help
51237 + If you say Y here, processes inside a chroot will not be able to
51238 + mount or remount filesystems. If the sysctl option is enabled, a
51239 + sysctl option with name "chroot_deny_mount" is created.
51240 +
51241 +config GRKERNSEC_CHROOT_DOUBLE
51242 + bool "Deny double-chroots"
51243 + default y if GRKERNSEC_CONFIG_AUTO
51244 + depends on GRKERNSEC_CHROOT
51245 + help
51246 + If you say Y here, processes inside a chroot will not be able to chroot
51247 + again outside the chroot. This is a widely used method of breaking
51248 + out of a chroot jail and should not be allowed. If the sysctl
51249 + option is enabled, a sysctl option with name
51250 + "chroot_deny_chroot" is created.
51251 +
51252 +config GRKERNSEC_CHROOT_PIVOT
51253 + bool "Deny pivot_root in chroot"
51254 + default y if GRKERNSEC_CONFIG_AUTO
51255 + depends on GRKERNSEC_CHROOT
51256 + help
51257 + If you say Y here, processes inside a chroot will not be able to use
51258 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51259 + works similar to chroot in that it changes the root filesystem. This
51260 + function could be misused in a chrooted process to attempt to break out
51261 + of the chroot, and therefore should not be allowed. If the sysctl
51262 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51263 + created.
51264 +
51265 +config GRKERNSEC_CHROOT_CHDIR
51266 + bool "Enforce chdir(\"/\") on all chroots"
51267 + default y if GRKERNSEC_CONFIG_AUTO
51268 + depends on GRKERNSEC_CHROOT
51269 + help
51270 + If you say Y here, the current working directory of all newly-chrooted
51271 + applications will be set to the the root directory of the chroot.
51272 + The man page on chroot(2) states:
51273 + Note that this call does not change the current working
51274 + directory, so that `.' can be outside the tree rooted at
51275 + `/'. In particular, the super-user can escape from a
51276 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51277 +
51278 + It is recommended that you say Y here, since it's not known to break
51279 + any software. If the sysctl option is enabled, a sysctl option with
51280 + name "chroot_enforce_chdir" is created.
51281 +
51282 +config GRKERNSEC_CHROOT_CHMOD
51283 + bool "Deny (f)chmod +s"
51284 + default y if GRKERNSEC_CONFIG_AUTO
51285 + depends on GRKERNSEC_CHROOT
51286 + help
51287 + If you say Y here, processes inside a chroot will not be able to chmod
51288 + or fchmod files to make them have suid or sgid bits. This protects
51289 + against another published method of breaking a chroot. If the sysctl
51290 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51291 + created.
51292 +
51293 +config GRKERNSEC_CHROOT_FCHDIR
51294 + bool "Deny fchdir out of chroot"
51295 + default y if GRKERNSEC_CONFIG_AUTO
51296 + depends on GRKERNSEC_CHROOT
51297 + help
51298 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51299 + to a file descriptor of the chrooting process that points to a directory
51300 + outside the filesystem will be stopped. If the sysctl option
51301 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51302 +
51303 +config GRKERNSEC_CHROOT_MKNOD
51304 + bool "Deny mknod"
51305 + default y if GRKERNSEC_CONFIG_AUTO
51306 + depends on GRKERNSEC_CHROOT
51307 + help
51308 + If you say Y here, processes inside a chroot will not be allowed to
51309 + mknod. The problem with using mknod inside a chroot is that it
51310 + would allow an attacker to create a device entry that is the same
51311 + as one on the physical root of your system, which could range from
51312 + anything from the console device to a device for your harddrive (which
51313 + they could then use to wipe the drive or steal data). It is recommended
51314 + that you say Y here, unless you run into software incompatibilities.
51315 + If the sysctl option is enabled, a sysctl option with name
51316 + "chroot_deny_mknod" is created.
51317 +
51318 +config GRKERNSEC_CHROOT_SHMAT
51319 + bool "Deny shmat() out of chroot"
51320 + default y if GRKERNSEC_CONFIG_AUTO
51321 + depends on GRKERNSEC_CHROOT
51322 + help
51323 + If you say Y here, processes inside a chroot will not be able to attach
51324 + to shared memory segments that were created outside of the chroot jail.
51325 + It is recommended that you say Y here. If the sysctl option is enabled,
51326 + a sysctl option with name "chroot_deny_shmat" is created.
51327 +
51328 +config GRKERNSEC_CHROOT_UNIX
51329 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51330 + default y if GRKERNSEC_CONFIG_AUTO
51331 + depends on GRKERNSEC_CHROOT
51332 + help
51333 + If you say Y here, processes inside a chroot will not be able to
51334 + connect to abstract (meaning not belonging to a filesystem) Unix
51335 + domain sockets that were bound outside of a chroot. It is recommended
51336 + that you say Y here. If the sysctl option is enabled, a sysctl option
51337 + with name "chroot_deny_unix" is created.
51338 +
51339 +config GRKERNSEC_CHROOT_FINDTASK
51340 + bool "Protect outside processes"
51341 + default y if GRKERNSEC_CONFIG_AUTO
51342 + depends on GRKERNSEC_CHROOT
51343 + help
51344 + If you say Y here, processes inside a chroot will not be able to
51345 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51346 + getsid, or view any process outside of the chroot. If the sysctl
51347 + option is enabled, a sysctl option with name "chroot_findtask" is
51348 + created.
51349 +
51350 +config GRKERNSEC_CHROOT_NICE
51351 + bool "Restrict priority changes"
51352 + default y if GRKERNSEC_CONFIG_AUTO
51353 + depends on GRKERNSEC_CHROOT
51354 + help
51355 + If you say Y here, processes inside a chroot will not be able to raise
51356 + the priority of processes in the chroot, or alter the priority of
51357 + processes outside the chroot. This provides more security than simply
51358 + removing CAP_SYS_NICE from the process' capability set. If the
51359 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51360 + is created.
51361 +
51362 +config GRKERNSEC_CHROOT_SYSCTL
51363 + bool "Deny sysctl writes"
51364 + default y if GRKERNSEC_CONFIG_AUTO
51365 + depends on GRKERNSEC_CHROOT
51366 + help
51367 + If you say Y here, an attacker in a chroot will not be able to
51368 + write to sysctl entries, either by sysctl(2) or through a /proc
51369 + interface. It is strongly recommended that you say Y here. If the
51370 + sysctl option is enabled, a sysctl option with name
51371 + "chroot_deny_sysctl" is created.
51372 +
51373 +config GRKERNSEC_CHROOT_CAPS
51374 + bool "Capability restrictions"
51375 + default y if GRKERNSEC_CONFIG_AUTO
51376 + depends on GRKERNSEC_CHROOT
51377 + help
51378 + If you say Y here, the capabilities on all processes within a
51379 + chroot jail will be lowered to stop module insertion, raw i/o,
51380 + system and net admin tasks, rebooting the system, modifying immutable
51381 + files, modifying IPC owned by another, and changing the system time.
51382 + This is left an option because it can break some apps. Disable this
51383 + if your chrooted apps are having problems performing those kinds of
51384 + tasks. If the sysctl option is enabled, a sysctl option with
51385 + name "chroot_caps" is created.
51386 +
51387 +endmenu
51388 +menu "Kernel Auditing"
51389 +depends on GRKERNSEC
51390 +
51391 +config GRKERNSEC_AUDIT_GROUP
51392 + bool "Single group for auditing"
51393 + help
51394 + If you say Y here, the exec, chdir, and (un)mount logging features
51395 + will only operate on a group you specify. This option is recommended
51396 + if you only want to watch certain users instead of having a large
51397 + amount of logs from the entire system. If the sysctl option is enabled,
51398 + a sysctl option with name "audit_group" is created.
51399 +
51400 +config GRKERNSEC_AUDIT_GID
51401 + int "GID for auditing"
51402 + depends on GRKERNSEC_AUDIT_GROUP
51403 + default 1007
51404 +
51405 +config GRKERNSEC_EXECLOG
51406 + bool "Exec logging"
51407 + help
51408 + If you say Y here, all execve() calls will be logged (since the
51409 + other exec*() calls are frontends to execve(), all execution
51410 + will be logged). Useful for shell-servers that like to keep track
51411 + of their users. If the sysctl option is enabled, a sysctl option with
51412 + name "exec_logging" is created.
51413 + WARNING: This option when enabled will produce a LOT of logs, especially
51414 + on an active system.
51415 +
51416 +config GRKERNSEC_RESLOG
51417 + bool "Resource logging"
51418 + default y if GRKERNSEC_CONFIG_AUTO
51419 + help
51420 + If you say Y here, all attempts to overstep resource limits will
51421 + be logged with the resource name, the requested size, and the current
51422 + limit. It is highly recommended that you say Y here. If the sysctl
51423 + option is enabled, a sysctl option with name "resource_logging" is
51424 + created. If the RBAC system is enabled, the sysctl value is ignored.
51425 +
51426 +config GRKERNSEC_CHROOT_EXECLOG
51427 + bool "Log execs within chroot"
51428 + help
51429 + If you say Y here, all executions inside a chroot jail will be logged
51430 + to syslog. This can cause a large amount of logs if certain
51431 + applications (eg. djb's daemontools) are installed on the system, and
51432 + is therefore left as an option. If the sysctl option is enabled, a
51433 + sysctl option with name "chroot_execlog" is created.
51434 +
51435 +config GRKERNSEC_AUDIT_PTRACE
51436 + bool "Ptrace logging"
51437 + help
51438 + If you say Y here, all attempts to attach to a process via ptrace
51439 + will be logged. If the sysctl option is enabled, a sysctl option
51440 + with name "audit_ptrace" is created.
51441 +
51442 +config GRKERNSEC_AUDIT_CHDIR
51443 + bool "Chdir logging"
51444 + help
51445 + If you say Y here, all chdir() calls will be logged. If the sysctl
51446 + option is enabled, a sysctl option with name "audit_chdir" is created.
51447 +
51448 +config GRKERNSEC_AUDIT_MOUNT
51449 + bool "(Un)Mount logging"
51450 + help
51451 + If you say Y here, all mounts and unmounts will be logged. If the
51452 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51453 + created.
51454 +
51455 +config GRKERNSEC_SIGNAL
51456 + bool "Signal logging"
51457 + default y if GRKERNSEC_CONFIG_AUTO
51458 + help
51459 + If you say Y here, certain important signals will be logged, such as
51460 + SIGSEGV, which will as a result inform you of when a error in a program
51461 + occurred, which in some cases could mean a possible exploit attempt.
51462 + If the sysctl option is enabled, a sysctl option with name
51463 + "signal_logging" is created.
51464 +
51465 +config GRKERNSEC_FORKFAIL
51466 + bool "Fork failure logging"
51467 + help
51468 + If you say Y here, all failed fork() attempts will be logged.
51469 + This could suggest a fork bomb, or someone attempting to overstep
51470 + their process limit. If the sysctl option is enabled, a sysctl option
51471 + with name "forkfail_logging" is created.
51472 +
51473 +config GRKERNSEC_TIME
51474 + bool "Time change logging"
51475 + default y if GRKERNSEC_CONFIG_AUTO
51476 + help
51477 + If you say Y here, any changes of the system clock will be logged.
51478 + If the sysctl option is enabled, a sysctl option with name
51479 + "timechange_logging" is created.
51480 +
51481 +config GRKERNSEC_PROC_IPADDR
51482 + bool "/proc/<pid>/ipaddr support"
51483 + default y if GRKERNSEC_CONFIG_AUTO
51484 + help
51485 + If you say Y here, a new entry will be added to each /proc/<pid>
51486 + directory that contains the IP address of the person using the task.
51487 + The IP is carried across local TCP and AF_UNIX stream sockets.
51488 + This information can be useful for IDS/IPSes to perform remote response
51489 + to a local attack. The entry is readable by only the owner of the
51490 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51491 + the RBAC system), and thus does not create privacy concerns.
51492 +
51493 +config GRKERNSEC_RWXMAP_LOG
51494 + bool 'Denied RWX mmap/mprotect logging'
51495 + default y if GRKERNSEC_CONFIG_AUTO
51496 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51497 + help
51498 + If you say Y here, calls to mmap() and mprotect() with explicit
51499 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51500 + denied by the PAX_MPROTECT feature. If the sysctl option is
51501 + enabled, a sysctl option with name "rwxmap_logging" is created.
51502 +
51503 +config GRKERNSEC_AUDIT_TEXTREL
51504 + bool 'ELF text relocations logging (READ HELP)'
51505 + depends on PAX_MPROTECT
51506 + help
51507 + If you say Y here, text relocations will be logged with the filename
51508 + of the offending library or binary. The purpose of the feature is
51509 + to help Linux distribution developers get rid of libraries and
51510 + binaries that need text relocations which hinder the future progress
51511 + of PaX. Only Linux distribution developers should say Y here, and
51512 + never on a production machine, as this option creates an information
51513 + leak that could aid an attacker in defeating the randomization of
51514 + a single memory region. If the sysctl option is enabled, a sysctl
51515 + option with name "audit_textrel" is created.
51516 +
51517 +endmenu
51518 +
51519 +menu "Executable Protections"
51520 +depends on GRKERNSEC
51521 +
51522 +config GRKERNSEC_DMESG
51523 + bool "Dmesg(8) restriction"
51524 + default y if GRKERNSEC_CONFIG_AUTO
51525 + help
51526 + If you say Y here, non-root users will not be able to use dmesg(8)
51527 + to view up to the last 4kb of messages in the kernel's log buffer.
51528 + The kernel's log buffer often contains kernel addresses and other
51529 + identifying information useful to an attacker in fingerprinting a
51530 + system for a targeted exploit.
51531 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51532 + created.
51533 +
51534 +config GRKERNSEC_HARDEN_PTRACE
51535 + bool "Deter ptrace-based process snooping"
51536 + default y if GRKERNSEC_CONFIG_AUTO
51537 + help
51538 + If you say Y here, TTY sniffers and other malicious monitoring
51539 + programs implemented through ptrace will be defeated. If you
51540 + have been using the RBAC system, this option has already been
51541 + enabled for several years for all users, with the ability to make
51542 + fine-grained exceptions.
51543 +
51544 + This option only affects the ability of non-root users to ptrace
51545 + processes that are not a descendent of the ptracing process.
51546 + This means that strace ./binary and gdb ./binary will still work,
51547 + but attaching to arbitrary processes will not. If the sysctl
51548 + option is enabled, a sysctl option with name "harden_ptrace" is
51549 + created.
51550 +
51551 +config GRKERNSEC_PTRACE_READEXEC
51552 + bool "Require read access to ptrace sensitive binaries"
51553 + default y if GRKERNSEC_CONFIG_AUTO
51554 + help
51555 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51556 + binaries. This option is useful in environments that
51557 + remove the read bits (e.g. file mode 4711) from suid binaries to
51558 + prevent infoleaking of their contents. This option adds
51559 + consistency to the use of that file mode, as the binary could normally
51560 + be read out when run without privileges while ptracing.
51561 +
51562 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51563 + is created.
51564 +
51565 +config GRKERNSEC_SETXID
51566 + bool "Enforce consistent multithreaded privileges"
51567 + default y if GRKERNSEC_CONFIG_AUTO
51568 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51569 + help
51570 + If you say Y here, a change from a root uid to a non-root uid
51571 + in a multithreaded application will cause the resulting uids,
51572 + gids, supplementary groups, and capabilities in that thread
51573 + to be propagated to the other threads of the process. In most
51574 + cases this is unnecessary, as glibc will emulate this behavior
51575 + on behalf of the application. Other libcs do not act in the
51576 + same way, allowing the other threads of the process to continue
51577 + running with root privileges. If the sysctl option is enabled,
51578 + a sysctl option with name "consistent_setxid" is created.
51579 +
51580 +config GRKERNSEC_TPE
51581 + bool "Trusted Path Execution (TPE)"
51582 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51583 + help
51584 + If you say Y here, you will be able to choose a gid to add to the
51585 + supplementary groups of users you want to mark as "untrusted."
51586 + These users will not be able to execute any files that are not in
51587 + root-owned directories writable only by root. If the sysctl option
51588 + is enabled, a sysctl option with name "tpe" is created.
51589 +
51590 +config GRKERNSEC_TPE_ALL
51591 + bool "Partially restrict all non-root users"
51592 + depends on GRKERNSEC_TPE
51593 + help
51594 + If you say Y here, all non-root users will be covered under
51595 + a weaker TPE restriction. This is separate from, and in addition to,
51596 + the main TPE options that you have selected elsewhere. Thus, if a
51597 + "trusted" GID is chosen, this restriction applies to even that GID.
51598 + Under this restriction, all non-root users will only be allowed to
51599 + execute files in directories they own that are not group or
51600 + world-writable, or in directories owned by root and writable only by
51601 + root. If the sysctl option is enabled, a sysctl option with name
51602 + "tpe_restrict_all" is created.
51603 +
51604 +config GRKERNSEC_TPE_INVERT
51605 + bool "Invert GID option"
51606 + depends on GRKERNSEC_TPE
51607 + help
51608 + If you say Y here, the group you specify in the TPE configuration will
51609 + decide what group TPE restrictions will be *disabled* for. This
51610 + option is useful if you want TPE restrictions to be applied to most
51611 + users on the system. If the sysctl option is enabled, a sysctl option
51612 + with name "tpe_invert" is created. Unlike other sysctl options, this
51613 + entry will default to on for backward-compatibility.
51614 +
51615 +config GRKERNSEC_TPE_GID
51616 + int
51617 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51618 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51619 +
51620 +config GRKERNSEC_TPE_UNTRUSTED_GID
51621 + int "GID for TPE-untrusted users"
51622 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51623 + default 1005
51624 + help
51625 + Setting this GID determines what group TPE restrictions will be
51626 + *enabled* for. If the sysctl option is enabled, a sysctl option
51627 + with name "tpe_gid" is created.
51628 +
51629 +config GRKERNSEC_TPE_TRUSTED_GID
51630 + int "GID for TPE-trusted users"
51631 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51632 + default 1005
51633 + help
51634 + Setting this GID determines what group TPE restrictions will be
51635 + *disabled* for. If the sysctl option is enabled, a sysctl option
51636 + with name "tpe_gid" is created.
51637 +
51638 +endmenu
51639 +menu "Network Protections"
51640 +depends on GRKERNSEC
51641 +
51642 +config GRKERNSEC_RANDNET
51643 + bool "Larger entropy pools"
51644 + default y if GRKERNSEC_CONFIG_AUTO
51645 + help
51646 + If you say Y here, the entropy pools used for many features of Linux
51647 + and grsecurity will be doubled in size. Since several grsecurity
51648 + features use additional randomness, it is recommended that you say Y
51649 + here. Saying Y here has a similar effect as modifying
51650 + /proc/sys/kernel/random/poolsize.
51651 +
51652 +config GRKERNSEC_BLACKHOLE
51653 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51654 + default y if GRKERNSEC_CONFIG_AUTO
51655 + depends on NET
51656 + help
51657 + If you say Y here, neither TCP resets nor ICMP
51658 + destination-unreachable packets will be sent in response to packets
51659 + sent to ports for which no associated listening process exists.
51660 + This feature supports both IPV4 and IPV6 and exempts the
51661 + loopback interface from blackholing. Enabling this feature
51662 + makes a host more resilient to DoS attacks and reduces network
51663 + visibility against scanners.
51664 +
51665 + The blackhole feature as-implemented is equivalent to the FreeBSD
51666 + blackhole feature, as it prevents RST responses to all packets, not
51667 + just SYNs. Under most application behavior this causes no
51668 + problems, but applications (like haproxy) may not close certain
51669 + connections in a way that cleanly terminates them on the remote
51670 + end, leaving the remote host in LAST_ACK state. Because of this
51671 + side-effect and to prevent intentional LAST_ACK DoSes, this
51672 + feature also adds automatic mitigation against such attacks.
51673 + The mitigation drastically reduces the amount of time a socket
51674 + can spend in LAST_ACK state. If you're using haproxy and not
51675 + all servers it connects to have this option enabled, consider
51676 + disabling this feature on the haproxy host.
51677 +
51678 + If the sysctl option is enabled, two sysctl options with names
51679 + "ip_blackhole" and "lastack_retries" will be created.
51680 + While "ip_blackhole" takes the standard zero/non-zero on/off
51681 + toggle, "lastack_retries" uses the same kinds of values as
51682 + "tcp_retries1" and "tcp_retries2". The default value of 4
51683 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51684 + state.
51685 +
51686 +config GRKERNSEC_SOCKET
51687 + bool "Socket restrictions"
51688 + depends on NET
51689 + help
51690 + If you say Y here, you will be able to choose from several options.
51691 + If you assign a GID on your system and add it to the supplementary
51692 + groups of users you want to restrict socket access to, this patch
51693 + will perform up to three things, based on the option(s) you choose.
51694 +
51695 +config GRKERNSEC_SOCKET_ALL
51696 + bool "Deny any sockets to group"
51697 + depends on GRKERNSEC_SOCKET
51698 + help
51699 + If you say Y here, you will be able to choose a GID of whose users will
51700 + be unable to connect to other hosts from your machine or run server
51701 + applications from your machine. If the sysctl option is enabled, a
51702 + sysctl option with name "socket_all" is created.
51703 +
51704 +config GRKERNSEC_SOCKET_ALL_GID
51705 + int "GID to deny all sockets for"
51706 + depends on GRKERNSEC_SOCKET_ALL
51707 + default 1004
51708 + help
51709 + Here you can choose the GID to disable socket access for. Remember to
51710 + add the users you want socket access disabled for to the GID
51711 + specified here. If the sysctl option is enabled, a sysctl option
51712 + with name "socket_all_gid" is created.
51713 +
51714 +config GRKERNSEC_SOCKET_CLIENT
51715 + bool "Deny client sockets to group"
51716 + depends on GRKERNSEC_SOCKET
51717 + help
51718 + If you say Y here, you will be able to choose a GID of whose users will
51719 + be unable to connect to other hosts from your machine, but will be
51720 + able to run servers. If this option is enabled, all users in the group
51721 + you specify will have to use passive mode when initiating ftp transfers
51722 + from the shell on your machine. If the sysctl option is enabled, a
51723 + sysctl option with name "socket_client" is created.
51724 +
51725 +config GRKERNSEC_SOCKET_CLIENT_GID
51726 + int "GID to deny client sockets for"
51727 + depends on GRKERNSEC_SOCKET_CLIENT
51728 + default 1003
51729 + help
51730 + Here you can choose the GID to disable client socket access for.
51731 + Remember to add the users you want client socket access disabled for to
51732 + the GID specified here. If the sysctl option is enabled, a sysctl
51733 + option with name "socket_client_gid" is created.
51734 +
51735 +config GRKERNSEC_SOCKET_SERVER
51736 + bool "Deny server sockets to group"
51737 + depends on GRKERNSEC_SOCKET
51738 + help
51739 + If you say Y here, you will be able to choose a GID of whose users will
51740 + be unable to run server applications from your machine. If the sysctl
51741 + option is enabled, a sysctl option with name "socket_server" is created.
51742 +
51743 +config GRKERNSEC_SOCKET_SERVER_GID
51744 + int "GID to deny server sockets for"
51745 + depends on GRKERNSEC_SOCKET_SERVER
51746 + default 1002
51747 + help
51748 + Here you can choose the GID to disable server socket access for.
51749 + Remember to add the users you want server socket access disabled for to
51750 + the GID specified here. If the sysctl option is enabled, a sysctl
51751 + option with name "socket_server_gid" is created.
51752 +
51753 +endmenu
51754 +menu "Sysctl Support"
51755 +depends on GRKERNSEC && SYSCTL
51756 +
51757 +config GRKERNSEC_SYSCTL
51758 + bool "Sysctl support"
51759 + default y if GRKERNSEC_CONFIG_AUTO
51760 + help
51761 + If you say Y here, you will be able to change the options that
51762 + grsecurity runs with at bootup, without having to recompile your
51763 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51764 + to enable (1) or disable (0) various features. All the sysctl entries
51765 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51766 + All features enabled in the kernel configuration are disabled at boot
51767 + if you do not say Y to the "Turn on features by default" option.
51768 + All options should be set at startup, and the grsec_lock entry should
51769 + be set to a non-zero value after all the options are set.
51770 + *THIS IS EXTREMELY IMPORTANT*
51771 +
51772 +config GRKERNSEC_SYSCTL_DISTRO
51773 + bool "Extra sysctl support for distro makers (READ HELP)"
51774 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51775 + help
51776 + If you say Y here, additional sysctl options will be created
51777 + for features that affect processes running as root. Therefore,
51778 + it is critical when using this option that the grsec_lock entry be
51779 + enabled after boot. Only distros with prebuilt kernel packages
51780 + with this option enabled that can ensure grsec_lock is enabled
51781 + after boot should use this option.
51782 + *Failure to set grsec_lock after boot makes all grsec features
51783 + this option covers useless*
51784 +
51785 + Currently this option creates the following sysctl entries:
51786 + "Disable Privileged I/O": "disable_priv_io"
51787 +
51788 +config GRKERNSEC_SYSCTL_ON
51789 + bool "Turn on features by default"
51790 + default y if GRKERNSEC_CONFIG_AUTO
51791 + depends on GRKERNSEC_SYSCTL
51792 + help
51793 + If you say Y here, instead of having all features enabled in the
51794 + kernel configuration disabled at boot time, the features will be
51795 + enabled at boot time. It is recommended you say Y here unless
51796 + there is some reason you would want all sysctl-tunable features to
51797 + be disabled by default. As mentioned elsewhere, it is important
51798 + to enable the grsec_lock entry once you have finished modifying
51799 + the sysctl entries.
51800 +
51801 +endmenu
51802 +menu "Logging Options"
51803 +depends on GRKERNSEC
51804 +
51805 +config GRKERNSEC_FLOODTIME
51806 + int "Seconds in between log messages (minimum)"
51807 + default 10
51808 + help
51809 + This option allows you to enforce the number of seconds between
51810 + grsecurity log messages. The default should be suitable for most
51811 + people, however, if you choose to change it, choose a value small enough
51812 + to allow informative logs to be produced, but large enough to
51813 + prevent flooding.
51814 +
51815 +config GRKERNSEC_FLOODBURST
51816 + int "Number of messages in a burst (maximum)"
51817 + default 6
51818 + help
51819 + This option allows you to choose the maximum number of messages allowed
51820 + within the flood time interval you chose in a separate option. The
51821 + default should be suitable for most people, however if you find that
51822 + many of your logs are being interpreted as flooding, you may want to
51823 + raise this value.
51824 +
51825 +endmenu
51826 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51827 new file mode 100644
51828 index 0000000..1b9afa9
51829 --- /dev/null
51830 +++ b/grsecurity/Makefile
51831 @@ -0,0 +1,38 @@
51832 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51833 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51834 +# into an RBAC system
51835 +#
51836 +# All code in this directory and various hooks inserted throughout the kernel
51837 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51838 +# under the GPL v2 or higher
51839 +
51840 +KBUILD_CFLAGS += -Werror
51841 +
51842 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51843 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51844 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51845 +
51846 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51847 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51848 + gracl_learn.o grsec_log.o
51849 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51850 +
51851 +ifdef CONFIG_NET
51852 +obj-y += grsec_sock.o
51853 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51854 +endif
51855 +
51856 +ifndef CONFIG_GRKERNSEC
51857 +obj-y += grsec_disabled.o
51858 +endif
51859 +
51860 +ifdef CONFIG_GRKERNSEC_HIDESYM
51861 +extra-y := grsec_hidesym.o
51862 +$(obj)/grsec_hidesym.o:
51863 + @-chmod -f 500 /boot
51864 + @-chmod -f 500 /lib/modules
51865 + @-chmod -f 500 /lib64/modules
51866 + @-chmod -f 500 /lib32/modules
51867 + @-chmod -f 700 .
51868 + @echo ' grsec: protected kernel image paths'
51869 +endif
51870 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51871 new file mode 100644
51872 index 0000000..b736032
51873 --- /dev/null
51874 +++ b/grsecurity/gracl.c
51875 @@ -0,0 +1,4040 @@
51876 +#include <linux/kernel.h>
51877 +#include <linux/module.h>
51878 +#include <linux/sched.h>
51879 +#include <linux/mm.h>
51880 +#include <linux/file.h>
51881 +#include <linux/fs.h>
51882 +#include <linux/namei.h>
51883 +#include <linux/mount.h>
51884 +#include <linux/tty.h>
51885 +#include <linux/proc_fs.h>
51886 +#include <linux/lglock.h>
51887 +#include <linux/slab.h>
51888 +#include <linux/vmalloc.h>
51889 +#include <linux/types.h>
51890 +#include <linux/sysctl.h>
51891 +#include <linux/netdevice.h>
51892 +#include <linux/ptrace.h>
51893 +#include <linux/gracl.h>
51894 +#include <linux/gralloc.h>
51895 +#include <linux/security.h>
51896 +#include <linux/grinternal.h>
51897 +#include <linux/pid_namespace.h>
51898 +#include <linux/stop_machine.h>
51899 +#include <linux/fdtable.h>
51900 +#include <linux/percpu.h>
51901 +#include <linux/lglock.h>
51902 +#include "../fs/mount.h"
51903 +
51904 +#include <asm/uaccess.h>
51905 +#include <asm/errno.h>
51906 +#include <asm/mman.h>
51907 +
51908 +extern struct lglock vfsmount_lock;
51909 +
51910 +static struct acl_role_db acl_role_set;
51911 +static struct name_db name_set;
51912 +static struct inodev_db inodev_set;
51913 +
51914 +/* for keeping track of userspace pointers used for subjects, so we
51915 + can share references in the kernel as well
51916 +*/
51917 +
51918 +static struct path real_root;
51919 +
51920 +static struct acl_subj_map_db subj_map_set;
51921 +
51922 +static struct acl_role_label *default_role;
51923 +
51924 +static struct acl_role_label *role_list;
51925 +
51926 +static u16 acl_sp_role_value;
51927 +
51928 +extern char *gr_shared_page[4];
51929 +static DEFINE_MUTEX(gr_dev_mutex);
51930 +DEFINE_RWLOCK(gr_inode_lock);
51931 +
51932 +struct gr_arg *gr_usermode;
51933 +
51934 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51935 +
51936 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51937 +extern void gr_clear_learn_entries(void);
51938 +
51939 +#ifdef CONFIG_GRKERNSEC_RESLOG
51940 +extern void gr_log_resource(const struct task_struct *task,
51941 + const int res, const unsigned long wanted, const int gt);
51942 +#endif
51943 +
51944 +unsigned char *gr_system_salt;
51945 +unsigned char *gr_system_sum;
51946 +
51947 +static struct sprole_pw **acl_special_roles = NULL;
51948 +static __u16 num_sprole_pws = 0;
51949 +
51950 +static struct acl_role_label *kernel_role = NULL;
51951 +
51952 +static unsigned int gr_auth_attempts = 0;
51953 +static unsigned long gr_auth_expires = 0UL;
51954 +
51955 +#ifdef CONFIG_NET
51956 +extern struct vfsmount *sock_mnt;
51957 +#endif
51958 +
51959 +extern struct vfsmount *pipe_mnt;
51960 +extern struct vfsmount *shm_mnt;
51961 +#ifdef CONFIG_HUGETLBFS
51962 +extern struct vfsmount *hugetlbfs_vfsmount;
51963 +#endif
51964 +
51965 +static struct acl_object_label *fakefs_obj_rw;
51966 +static struct acl_object_label *fakefs_obj_rwx;
51967 +
51968 +extern int gr_init_uidset(void);
51969 +extern void gr_free_uidset(void);
51970 +extern void gr_remove_uid(uid_t uid);
51971 +extern int gr_find_uid(uid_t uid);
51972 +
51973 +__inline__ int
51974 +gr_acl_is_enabled(void)
51975 +{
51976 + return (gr_status & GR_READY);
51977 +}
51978 +
51979 +#ifdef CONFIG_BTRFS_FS
51980 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51981 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51982 +#endif
51983 +
51984 +static inline dev_t __get_dev(const struct dentry *dentry)
51985 +{
51986 +#ifdef CONFIG_BTRFS_FS
51987 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51988 + return get_btrfs_dev_from_inode(dentry->d_inode);
51989 + else
51990 +#endif
51991 + return dentry->d_inode->i_sb->s_dev;
51992 +}
51993 +
51994 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51995 +{
51996 + return __get_dev(dentry);
51997 +}
51998 +
51999 +static char gr_task_roletype_to_char(struct task_struct *task)
52000 +{
52001 + switch (task->role->roletype &
52002 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52003 + GR_ROLE_SPECIAL)) {
52004 + case GR_ROLE_DEFAULT:
52005 + return 'D';
52006 + case GR_ROLE_USER:
52007 + return 'U';
52008 + case GR_ROLE_GROUP:
52009 + return 'G';
52010 + case GR_ROLE_SPECIAL:
52011 + return 'S';
52012 + }
52013 +
52014 + return 'X';
52015 +}
52016 +
52017 +char gr_roletype_to_char(void)
52018 +{
52019 + return gr_task_roletype_to_char(current);
52020 +}
52021 +
52022 +__inline__ int
52023 +gr_acl_tpe_check(void)
52024 +{
52025 + if (unlikely(!(gr_status & GR_READY)))
52026 + return 0;
52027 + if (current->role->roletype & GR_ROLE_TPE)
52028 + return 1;
52029 + else
52030 + return 0;
52031 +}
52032 +
52033 +int
52034 +gr_handle_rawio(const struct inode *inode)
52035 +{
52036 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52037 + if (inode && S_ISBLK(inode->i_mode) &&
52038 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52039 + !capable(CAP_SYS_RAWIO))
52040 + return 1;
52041 +#endif
52042 + return 0;
52043 +}
52044 +
52045 +static int
52046 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52047 +{
52048 + if (likely(lena != lenb))
52049 + return 0;
52050 +
52051 + return !memcmp(a, b, lena);
52052 +}
52053 +
52054 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52055 +{
52056 + *buflen -= namelen;
52057 + if (*buflen < 0)
52058 + return -ENAMETOOLONG;
52059 + *buffer -= namelen;
52060 + memcpy(*buffer, str, namelen);
52061 + return 0;
52062 +}
52063 +
52064 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52065 +{
52066 + return prepend(buffer, buflen, name->name, name->len);
52067 +}
52068 +
52069 +static int prepend_path(const struct path *path, struct path *root,
52070 + char **buffer, int *buflen)
52071 +{
52072 + struct dentry *dentry = path->dentry;
52073 + struct vfsmount *vfsmnt = path->mnt;
52074 + struct mount *mnt = real_mount(vfsmnt);
52075 + bool slash = false;
52076 + int error = 0;
52077 +
52078 + while (dentry != root->dentry || vfsmnt != root->mnt) {
52079 + struct dentry * parent;
52080 +
52081 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52082 + /* Global root? */
52083 + if (!mnt_has_parent(mnt)) {
52084 + goto out;
52085 + }
52086 + dentry = mnt->mnt_mountpoint;
52087 + mnt = mnt->mnt_parent;
52088 + vfsmnt = &mnt->mnt;
52089 + continue;
52090 + }
52091 + parent = dentry->d_parent;
52092 + prefetch(parent);
52093 + spin_lock(&dentry->d_lock);
52094 + error = prepend_name(buffer, buflen, &dentry->d_name);
52095 + spin_unlock(&dentry->d_lock);
52096 + if (!error)
52097 + error = prepend(buffer, buflen, "/", 1);
52098 + if (error)
52099 + break;
52100 +
52101 + slash = true;
52102 + dentry = parent;
52103 + }
52104 +
52105 +out:
52106 + if (!error && !slash)
52107 + error = prepend(buffer, buflen, "/", 1);
52108 +
52109 + return error;
52110 +}
52111 +
52112 +/* this must be called with vfsmount_lock and rename_lock held */
52113 +
52114 +static char *__our_d_path(const struct path *path, struct path *root,
52115 + char *buf, int buflen)
52116 +{
52117 + char *res = buf + buflen;
52118 + int error;
52119 +
52120 + prepend(&res, &buflen, "\0", 1);
52121 + error = prepend_path(path, root, &res, &buflen);
52122 + if (error)
52123 + return ERR_PTR(error);
52124 +
52125 + return res;
52126 +}
52127 +
52128 +static char *
52129 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52130 +{
52131 + char *retval;
52132 +
52133 + retval = __our_d_path(path, root, buf, buflen);
52134 + if (unlikely(IS_ERR(retval)))
52135 + retval = strcpy(buf, "<path too long>");
52136 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52137 + retval[1] = '\0';
52138 +
52139 + return retval;
52140 +}
52141 +
52142 +static char *
52143 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52144 + char *buf, int buflen)
52145 +{
52146 + struct path path;
52147 + char *res;
52148 +
52149 + path.dentry = (struct dentry *)dentry;
52150 + path.mnt = (struct vfsmount *)vfsmnt;
52151 +
52152 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52153 + by the RBAC system */
52154 + res = gen_full_path(&path, &real_root, buf, buflen);
52155 +
52156 + return res;
52157 +}
52158 +
52159 +static char *
52160 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52161 + char *buf, int buflen)
52162 +{
52163 + char *res;
52164 + struct path path;
52165 + struct path root;
52166 + struct task_struct *reaper = init_pid_ns.child_reaper;
52167 +
52168 + path.dentry = (struct dentry *)dentry;
52169 + path.mnt = (struct vfsmount *)vfsmnt;
52170 +
52171 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52172 + get_fs_root(reaper->fs, &root);
52173 +
52174 + write_seqlock(&rename_lock);
52175 + br_read_lock(&vfsmount_lock);
52176 + res = gen_full_path(&path, &root, buf, buflen);
52177 + br_read_unlock(&vfsmount_lock);
52178 + write_sequnlock(&rename_lock);
52179 +
52180 + path_put(&root);
52181 + return res;
52182 +}
52183 +
52184 +static char *
52185 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52186 +{
52187 + char *ret;
52188 + write_seqlock(&rename_lock);
52189 + br_read_lock(&vfsmount_lock);
52190 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52191 + PAGE_SIZE);
52192 + br_read_unlock(&vfsmount_lock);
52193 + write_sequnlock(&rename_lock);
52194 + return ret;
52195 +}
52196 +
52197 +static char *
52198 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52199 +{
52200 + char *ret;
52201 + char *buf;
52202 + int buflen;
52203 +
52204 + write_seqlock(&rename_lock);
52205 + br_read_lock(&vfsmount_lock);
52206 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52207 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52208 + buflen = (int)(ret - buf);
52209 + if (buflen >= 5)
52210 + prepend(&ret, &buflen, "/proc", 5);
52211 + else
52212 + ret = strcpy(buf, "<path too long>");
52213 + br_read_unlock(&vfsmount_lock);
52214 + write_sequnlock(&rename_lock);
52215 + return ret;
52216 +}
52217 +
52218 +char *
52219 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52220 +{
52221 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52222 + PAGE_SIZE);
52223 +}
52224 +
52225 +char *
52226 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52227 +{
52228 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52229 + PAGE_SIZE);
52230 +}
52231 +
52232 +char *
52233 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52234 +{
52235 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52236 + PAGE_SIZE);
52237 +}
52238 +
52239 +char *
52240 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52241 +{
52242 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52243 + PAGE_SIZE);
52244 +}
52245 +
52246 +char *
52247 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52248 +{
52249 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52250 + PAGE_SIZE);
52251 +}
52252 +
52253 +__inline__ __u32
52254 +to_gr_audit(const __u32 reqmode)
52255 +{
52256 + /* masks off auditable permission flags, then shifts them to create
52257 + auditing flags, and adds the special case of append auditing if
52258 + we're requesting write */
52259 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52260 +}
52261 +
52262 +struct acl_subject_label *
52263 +lookup_subject_map(const struct acl_subject_label *userp)
52264 +{
52265 + unsigned int index = shash(userp, subj_map_set.s_size);
52266 + struct subject_map *match;
52267 +
52268 + match = subj_map_set.s_hash[index];
52269 +
52270 + while (match && match->user != userp)
52271 + match = match->next;
52272 +
52273 + if (match != NULL)
52274 + return match->kernel;
52275 + else
52276 + return NULL;
52277 +}
52278 +
52279 +static void
52280 +insert_subj_map_entry(struct subject_map *subjmap)
52281 +{
52282 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52283 + struct subject_map **curr;
52284 +
52285 + subjmap->prev = NULL;
52286 +
52287 + curr = &subj_map_set.s_hash[index];
52288 + if (*curr != NULL)
52289 + (*curr)->prev = subjmap;
52290 +
52291 + subjmap->next = *curr;
52292 + *curr = subjmap;
52293 +
52294 + return;
52295 +}
52296 +
52297 +static struct acl_role_label *
52298 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52299 + const gid_t gid)
52300 +{
52301 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52302 + struct acl_role_label *match;
52303 + struct role_allowed_ip *ipp;
52304 + unsigned int x;
52305 + u32 curr_ip = task->signal->curr_ip;
52306 +
52307 + task->signal->saved_ip = curr_ip;
52308 +
52309 + match = acl_role_set.r_hash[index];
52310 +
52311 + while (match) {
52312 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52313 + for (x = 0; x < match->domain_child_num; x++) {
52314 + if (match->domain_children[x] == uid)
52315 + goto found;
52316 + }
52317 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52318 + break;
52319 + match = match->next;
52320 + }
52321 +found:
52322 + if (match == NULL) {
52323 + try_group:
52324 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52325 + match = acl_role_set.r_hash[index];
52326 +
52327 + while (match) {
52328 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52329 + for (x = 0; x < match->domain_child_num; x++) {
52330 + if (match->domain_children[x] == gid)
52331 + goto found2;
52332 + }
52333 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52334 + break;
52335 + match = match->next;
52336 + }
52337 +found2:
52338 + if (match == NULL)
52339 + match = default_role;
52340 + if (match->allowed_ips == NULL)
52341 + return match;
52342 + else {
52343 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52344 + if (likely
52345 + ((ntohl(curr_ip) & ipp->netmask) ==
52346 + (ntohl(ipp->addr) & ipp->netmask)))
52347 + return match;
52348 + }
52349 + match = default_role;
52350 + }
52351 + } else if (match->allowed_ips == NULL) {
52352 + return match;
52353 + } else {
52354 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52355 + if (likely
52356 + ((ntohl(curr_ip) & ipp->netmask) ==
52357 + (ntohl(ipp->addr) & ipp->netmask)))
52358 + return match;
52359 + }
52360 + goto try_group;
52361 + }
52362 +
52363 + return match;
52364 +}
52365 +
52366 +struct acl_subject_label *
52367 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52368 + const struct acl_role_label *role)
52369 +{
52370 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52371 + struct acl_subject_label *match;
52372 +
52373 + match = role->subj_hash[index];
52374 +
52375 + while (match && (match->inode != ino || match->device != dev ||
52376 + (match->mode & GR_DELETED))) {
52377 + match = match->next;
52378 + }
52379 +
52380 + if (match && !(match->mode & GR_DELETED))
52381 + return match;
52382 + else
52383 + return NULL;
52384 +}
52385 +
52386 +struct acl_subject_label *
52387 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52388 + const struct acl_role_label *role)
52389 +{
52390 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52391 + struct acl_subject_label *match;
52392 +
52393 + match = role->subj_hash[index];
52394 +
52395 + while (match && (match->inode != ino || match->device != dev ||
52396 + !(match->mode & GR_DELETED))) {
52397 + match = match->next;
52398 + }
52399 +
52400 + if (match && (match->mode & GR_DELETED))
52401 + return match;
52402 + else
52403 + return NULL;
52404 +}
52405 +
52406 +static struct acl_object_label *
52407 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52408 + const struct acl_subject_label *subj)
52409 +{
52410 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52411 + struct acl_object_label *match;
52412 +
52413 + match = subj->obj_hash[index];
52414 +
52415 + while (match && (match->inode != ino || match->device != dev ||
52416 + (match->mode & GR_DELETED))) {
52417 + match = match->next;
52418 + }
52419 +
52420 + if (match && !(match->mode & GR_DELETED))
52421 + return match;
52422 + else
52423 + return NULL;
52424 +}
52425 +
52426 +static struct acl_object_label *
52427 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52428 + const struct acl_subject_label *subj)
52429 +{
52430 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52431 + struct acl_object_label *match;
52432 +
52433 + match = subj->obj_hash[index];
52434 +
52435 + while (match && (match->inode != ino || match->device != dev ||
52436 + !(match->mode & GR_DELETED))) {
52437 + match = match->next;
52438 + }
52439 +
52440 + if (match && (match->mode & GR_DELETED))
52441 + return match;
52442 +
52443 + match = subj->obj_hash[index];
52444 +
52445 + while (match && (match->inode != ino || match->device != dev ||
52446 + (match->mode & GR_DELETED))) {
52447 + match = match->next;
52448 + }
52449 +
52450 + if (match && !(match->mode & GR_DELETED))
52451 + return match;
52452 + else
52453 + return NULL;
52454 +}
52455 +
52456 +static struct name_entry *
52457 +lookup_name_entry(const char *name)
52458 +{
52459 + unsigned int len = strlen(name);
52460 + unsigned int key = full_name_hash(name, len);
52461 + unsigned int index = key % name_set.n_size;
52462 + struct name_entry *match;
52463 +
52464 + match = name_set.n_hash[index];
52465 +
52466 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52467 + match = match->next;
52468 +
52469 + return match;
52470 +}
52471 +
52472 +static struct name_entry *
52473 +lookup_name_entry_create(const char *name)
52474 +{
52475 + unsigned int len = strlen(name);
52476 + unsigned int key = full_name_hash(name, len);
52477 + unsigned int index = key % name_set.n_size;
52478 + struct name_entry *match;
52479 +
52480 + match = name_set.n_hash[index];
52481 +
52482 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52483 + !match->deleted))
52484 + match = match->next;
52485 +
52486 + if (match && match->deleted)
52487 + return match;
52488 +
52489 + match = name_set.n_hash[index];
52490 +
52491 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52492 + match->deleted))
52493 + match = match->next;
52494 +
52495 + if (match && !match->deleted)
52496 + return match;
52497 + else
52498 + return NULL;
52499 +}
52500 +
52501 +static struct inodev_entry *
52502 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52503 +{
52504 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52505 + struct inodev_entry *match;
52506 +
52507 + match = inodev_set.i_hash[index];
52508 +
52509 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52510 + match = match->next;
52511 +
52512 + return match;
52513 +}
52514 +
52515 +static void
52516 +insert_inodev_entry(struct inodev_entry *entry)
52517 +{
52518 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52519 + inodev_set.i_size);
52520 + struct inodev_entry **curr;
52521 +
52522 + entry->prev = NULL;
52523 +
52524 + curr = &inodev_set.i_hash[index];
52525 + if (*curr != NULL)
52526 + (*curr)->prev = entry;
52527 +
52528 + entry->next = *curr;
52529 + *curr = entry;
52530 +
52531 + return;
52532 +}
52533 +
52534 +static void
52535 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52536 +{
52537 + unsigned int index =
52538 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52539 + struct acl_role_label **curr;
52540 + struct acl_role_label *tmp, *tmp2;
52541 +
52542 + curr = &acl_role_set.r_hash[index];
52543 +
52544 + /* simple case, slot is empty, just set it to our role */
52545 + if (*curr == NULL) {
52546 + *curr = role;
52547 + } else {
52548 + /* example:
52549 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52550 + 2 -> 3
52551 + */
52552 + /* first check to see if we can already be reached via this slot */
52553 + tmp = *curr;
52554 + while (tmp && tmp != role)
52555 + tmp = tmp->next;
52556 + if (tmp == role) {
52557 + /* we don't need to add ourselves to this slot's chain */
52558 + return;
52559 + }
52560 + /* we need to add ourselves to this chain, two cases */
52561 + if (role->next == NULL) {
52562 + /* simple case, append the current chain to our role */
52563 + role->next = *curr;
52564 + *curr = role;
52565 + } else {
52566 + /* 1 -> 2 -> 3 -> 4
52567 + 2 -> 3 -> 4
52568 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52569 + */
52570 + /* trickier case: walk our role's chain until we find
52571 + the role for the start of the current slot's chain */
52572 + tmp = role;
52573 + tmp2 = *curr;
52574 + while (tmp->next && tmp->next != tmp2)
52575 + tmp = tmp->next;
52576 + if (tmp->next == tmp2) {
52577 + /* from example above, we found 3, so just
52578 + replace this slot's chain with ours */
52579 + *curr = role;
52580 + } else {
52581 + /* we didn't find a subset of our role's chain
52582 + in the current slot's chain, so append their
52583 + chain to ours, and set us as the first role in
52584 + the slot's chain
52585 +
52586 + we could fold this case with the case above,
52587 + but making it explicit for clarity
52588 + */
52589 + tmp->next = tmp2;
52590 + *curr = role;
52591 + }
52592 + }
52593 + }
52594 +
52595 + return;
52596 +}
52597 +
52598 +static void
52599 +insert_acl_role_label(struct acl_role_label *role)
52600 +{
52601 + int i;
52602 +
52603 + if (role_list == NULL) {
52604 + role_list = role;
52605 + role->prev = NULL;
52606 + } else {
52607 + role->prev = role_list;
52608 + role_list = role;
52609 + }
52610 +
52611 + /* used for hash chains */
52612 + role->next = NULL;
52613 +
52614 + if (role->roletype & GR_ROLE_DOMAIN) {
52615 + for (i = 0; i < role->domain_child_num; i++)
52616 + __insert_acl_role_label(role, role->domain_children[i]);
52617 + } else
52618 + __insert_acl_role_label(role, role->uidgid);
52619 +}
52620 +
52621 +static int
52622 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52623 +{
52624 + struct name_entry **curr, *nentry;
52625 + struct inodev_entry *ientry;
52626 + unsigned int len = strlen(name);
52627 + unsigned int key = full_name_hash(name, len);
52628 + unsigned int index = key % name_set.n_size;
52629 +
52630 + curr = &name_set.n_hash[index];
52631 +
52632 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52633 + curr = &((*curr)->next);
52634 +
52635 + if (*curr != NULL)
52636 + return 1;
52637 +
52638 + nentry = acl_alloc(sizeof (struct name_entry));
52639 + if (nentry == NULL)
52640 + return 0;
52641 + ientry = acl_alloc(sizeof (struct inodev_entry));
52642 + if (ientry == NULL)
52643 + return 0;
52644 + ientry->nentry = nentry;
52645 +
52646 + nentry->key = key;
52647 + nentry->name = name;
52648 + nentry->inode = inode;
52649 + nentry->device = device;
52650 + nentry->len = len;
52651 + nentry->deleted = deleted;
52652 +
52653 + nentry->prev = NULL;
52654 + curr = &name_set.n_hash[index];
52655 + if (*curr != NULL)
52656 + (*curr)->prev = nentry;
52657 + nentry->next = *curr;
52658 + *curr = nentry;
52659 +
52660 + /* insert us into the table searchable by inode/dev */
52661 + insert_inodev_entry(ientry);
52662 +
52663 + return 1;
52664 +}
52665 +
52666 +static void
52667 +insert_acl_obj_label(struct acl_object_label *obj,
52668 + struct acl_subject_label *subj)
52669 +{
52670 + unsigned int index =
52671 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52672 + struct acl_object_label **curr;
52673 +
52674 +
52675 + obj->prev = NULL;
52676 +
52677 + curr = &subj->obj_hash[index];
52678 + if (*curr != NULL)
52679 + (*curr)->prev = obj;
52680 +
52681 + obj->next = *curr;
52682 + *curr = obj;
52683 +
52684 + return;
52685 +}
52686 +
52687 +static void
52688 +insert_acl_subj_label(struct acl_subject_label *obj,
52689 + struct acl_role_label *role)
52690 +{
52691 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52692 + struct acl_subject_label **curr;
52693 +
52694 + obj->prev = NULL;
52695 +
52696 + curr = &role->subj_hash[index];
52697 + if (*curr != NULL)
52698 + (*curr)->prev = obj;
52699 +
52700 + obj->next = *curr;
52701 + *curr = obj;
52702 +
52703 + return;
52704 +}
52705 +
52706 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52707 +
52708 +static void *
52709 +create_table(__u32 * len, int elementsize)
52710 +{
52711 + unsigned int table_sizes[] = {
52712 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52713 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52714 + 4194301, 8388593, 16777213, 33554393, 67108859
52715 + };
52716 + void *newtable = NULL;
52717 + unsigned int pwr = 0;
52718 +
52719 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52720 + table_sizes[pwr] <= *len)
52721 + pwr++;
52722 +
52723 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52724 + return newtable;
52725 +
52726 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52727 + newtable =
52728 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52729 + else
52730 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52731 +
52732 + *len = table_sizes[pwr];
52733 +
52734 + return newtable;
52735 +}
52736 +
52737 +static int
52738 +init_variables(const struct gr_arg *arg)
52739 +{
52740 + struct task_struct *reaper = init_pid_ns.child_reaper;
52741 + unsigned int stacksize;
52742 +
52743 + subj_map_set.s_size = arg->role_db.num_subjects;
52744 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52745 + name_set.n_size = arg->role_db.num_objects;
52746 + inodev_set.i_size = arg->role_db.num_objects;
52747 +
52748 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52749 + !name_set.n_size || !inodev_set.i_size)
52750 + return 1;
52751 +
52752 + if (!gr_init_uidset())
52753 + return 1;
52754 +
52755 + /* set up the stack that holds allocation info */
52756 +
52757 + stacksize = arg->role_db.num_pointers + 5;
52758 +
52759 + if (!acl_alloc_stack_init(stacksize))
52760 + return 1;
52761 +
52762 + /* grab reference for the real root dentry and vfsmount */
52763 + get_fs_root(reaper->fs, &real_root);
52764 +
52765 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52766 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52767 +#endif
52768 +
52769 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52770 + if (fakefs_obj_rw == NULL)
52771 + return 1;
52772 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52773 +
52774 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52775 + if (fakefs_obj_rwx == NULL)
52776 + return 1;
52777 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52778 +
52779 + subj_map_set.s_hash =
52780 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52781 + acl_role_set.r_hash =
52782 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52783 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52784 + inodev_set.i_hash =
52785 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52786 +
52787 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52788 + !name_set.n_hash || !inodev_set.i_hash)
52789 + return 1;
52790 +
52791 + memset(subj_map_set.s_hash, 0,
52792 + sizeof(struct subject_map *) * subj_map_set.s_size);
52793 + memset(acl_role_set.r_hash, 0,
52794 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52795 + memset(name_set.n_hash, 0,
52796 + sizeof (struct name_entry *) * name_set.n_size);
52797 + memset(inodev_set.i_hash, 0,
52798 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52799 +
52800 + return 0;
52801 +}
52802 +
52803 +/* free information not needed after startup
52804 + currently contains user->kernel pointer mappings for subjects
52805 +*/
52806 +
52807 +static void
52808 +free_init_variables(void)
52809 +{
52810 + __u32 i;
52811 +
52812 + if (subj_map_set.s_hash) {
52813 + for (i = 0; i < subj_map_set.s_size; i++) {
52814 + if (subj_map_set.s_hash[i]) {
52815 + kfree(subj_map_set.s_hash[i]);
52816 + subj_map_set.s_hash[i] = NULL;
52817 + }
52818 + }
52819 +
52820 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52821 + PAGE_SIZE)
52822 + kfree(subj_map_set.s_hash);
52823 + else
52824 + vfree(subj_map_set.s_hash);
52825 + }
52826 +
52827 + return;
52828 +}
52829 +
52830 +static void
52831 +free_variables(void)
52832 +{
52833 + struct acl_subject_label *s;
52834 + struct acl_role_label *r;
52835 + struct task_struct *task, *task2;
52836 + unsigned int x;
52837 +
52838 + gr_clear_learn_entries();
52839 +
52840 + read_lock(&tasklist_lock);
52841 + do_each_thread(task2, task) {
52842 + task->acl_sp_role = 0;
52843 + task->acl_role_id = 0;
52844 + task->acl = NULL;
52845 + task->role = NULL;
52846 + } while_each_thread(task2, task);
52847 + read_unlock(&tasklist_lock);
52848 +
52849 + /* release the reference to the real root dentry and vfsmount */
52850 + path_put(&real_root);
52851 + memset(&real_root, 0, sizeof(real_root));
52852 +
52853 + /* free all object hash tables */
52854 +
52855 + FOR_EACH_ROLE_START(r)
52856 + if (r->subj_hash == NULL)
52857 + goto next_role;
52858 + FOR_EACH_SUBJECT_START(r, s, x)
52859 + if (s->obj_hash == NULL)
52860 + break;
52861 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52862 + kfree(s->obj_hash);
52863 + else
52864 + vfree(s->obj_hash);
52865 + FOR_EACH_SUBJECT_END(s, x)
52866 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52867 + if (s->obj_hash == NULL)
52868 + break;
52869 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52870 + kfree(s->obj_hash);
52871 + else
52872 + vfree(s->obj_hash);
52873 + FOR_EACH_NESTED_SUBJECT_END(s)
52874 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52875 + kfree(r->subj_hash);
52876 + else
52877 + vfree(r->subj_hash);
52878 + r->subj_hash = NULL;
52879 +next_role:
52880 + FOR_EACH_ROLE_END(r)
52881 +
52882 + acl_free_all();
52883 +
52884 + if (acl_role_set.r_hash) {
52885 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52886 + PAGE_SIZE)
52887 + kfree(acl_role_set.r_hash);
52888 + else
52889 + vfree(acl_role_set.r_hash);
52890 + }
52891 + if (name_set.n_hash) {
52892 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52893 + PAGE_SIZE)
52894 + kfree(name_set.n_hash);
52895 + else
52896 + vfree(name_set.n_hash);
52897 + }
52898 +
52899 + if (inodev_set.i_hash) {
52900 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52901 + PAGE_SIZE)
52902 + kfree(inodev_set.i_hash);
52903 + else
52904 + vfree(inodev_set.i_hash);
52905 + }
52906 +
52907 + gr_free_uidset();
52908 +
52909 + memset(&name_set, 0, sizeof (struct name_db));
52910 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52911 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52912 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52913 +
52914 + default_role = NULL;
52915 + kernel_role = NULL;
52916 + role_list = NULL;
52917 +
52918 + return;
52919 +}
52920 +
52921 +static __u32
52922 +count_user_objs(struct acl_object_label *userp)
52923 +{
52924 + struct acl_object_label o_tmp;
52925 + __u32 num = 0;
52926 +
52927 + while (userp) {
52928 + if (copy_from_user(&o_tmp, userp,
52929 + sizeof (struct acl_object_label)))
52930 + break;
52931 +
52932 + userp = o_tmp.prev;
52933 + num++;
52934 + }
52935 +
52936 + return num;
52937 +}
52938 +
52939 +static struct acl_subject_label *
52940 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
52941 +
52942 +static int
52943 +copy_user_glob(struct acl_object_label *obj)
52944 +{
52945 + struct acl_object_label *g_tmp, **guser;
52946 + unsigned int len;
52947 + char *tmp;
52948 +
52949 + if (obj->globbed == NULL)
52950 + return 0;
52951 +
52952 + guser = &obj->globbed;
52953 + while (*guser) {
52954 + g_tmp = (struct acl_object_label *)
52955 + acl_alloc(sizeof (struct acl_object_label));
52956 + if (g_tmp == NULL)
52957 + return -ENOMEM;
52958 +
52959 + if (copy_from_user(g_tmp, *guser,
52960 + sizeof (struct acl_object_label)))
52961 + return -EFAULT;
52962 +
52963 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52964 +
52965 + if (!len || len >= PATH_MAX)
52966 + return -EINVAL;
52967 +
52968 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52969 + return -ENOMEM;
52970 +
52971 + if (copy_from_user(tmp, g_tmp->filename, len))
52972 + return -EFAULT;
52973 + tmp[len-1] = '\0';
52974 + g_tmp->filename = tmp;
52975 +
52976 + *guser = g_tmp;
52977 + guser = &(g_tmp->next);
52978 + }
52979 +
52980 + return 0;
52981 +}
52982 +
52983 +static int
52984 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52985 + struct acl_role_label *role)
52986 +{
52987 + struct acl_object_label *o_tmp;
52988 + unsigned int len;
52989 + int ret;
52990 + char *tmp;
52991 +
52992 + while (userp) {
52993 + if ((o_tmp = (struct acl_object_label *)
52994 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52995 + return -ENOMEM;
52996 +
52997 + if (copy_from_user(o_tmp, userp,
52998 + sizeof (struct acl_object_label)))
52999 + return -EFAULT;
53000 +
53001 + userp = o_tmp->prev;
53002 +
53003 + len = strnlen_user(o_tmp->filename, PATH_MAX);
53004 +
53005 + if (!len || len >= PATH_MAX)
53006 + return -EINVAL;
53007 +
53008 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53009 + return -ENOMEM;
53010 +
53011 + if (copy_from_user(tmp, o_tmp->filename, len))
53012 + return -EFAULT;
53013 + tmp[len-1] = '\0';
53014 + o_tmp->filename = tmp;
53015 +
53016 + insert_acl_obj_label(o_tmp, subj);
53017 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53018 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53019 + return -ENOMEM;
53020 +
53021 + ret = copy_user_glob(o_tmp);
53022 + if (ret)
53023 + return ret;
53024 +
53025 + if (o_tmp->nested) {
53026 + int already_copied;
53027 +
53028 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53029 + if (IS_ERR(o_tmp->nested))
53030 + return PTR_ERR(o_tmp->nested);
53031 +
53032 + /* insert into nested subject list if we haven't copied this one yet
53033 + to prevent duplicate entries */
53034 + if (!already_copied) {
53035 + o_tmp->nested->next = role->hash->first;
53036 + role->hash->first = o_tmp->nested;
53037 + }
53038 + }
53039 + }
53040 +
53041 + return 0;
53042 +}
53043 +
53044 +static __u32
53045 +count_user_subjs(struct acl_subject_label *userp)
53046 +{
53047 + struct acl_subject_label s_tmp;
53048 + __u32 num = 0;
53049 +
53050 + while (userp) {
53051 + if (copy_from_user(&s_tmp, userp,
53052 + sizeof (struct acl_subject_label)))
53053 + break;
53054 +
53055 + userp = s_tmp.prev;
53056 + /* do not count nested subjects against this count, since
53057 + they are not included in the hash table, but are
53058 + attached to objects. We have already counted
53059 + the subjects in userspace for the allocation
53060 + stack
53061 + */
53062 + if (!(s_tmp.mode & GR_NESTED))
53063 + num++;
53064 + }
53065 +
53066 + return num;
53067 +}
53068 +
53069 +static int
53070 +copy_user_allowedips(struct acl_role_label *rolep)
53071 +{
53072 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53073 +
53074 + ruserip = rolep->allowed_ips;
53075 +
53076 + while (ruserip) {
53077 + rlast = rtmp;
53078 +
53079 + if ((rtmp = (struct role_allowed_ip *)
53080 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53081 + return -ENOMEM;
53082 +
53083 + if (copy_from_user(rtmp, ruserip,
53084 + sizeof (struct role_allowed_ip)))
53085 + return -EFAULT;
53086 +
53087 + ruserip = rtmp->prev;
53088 +
53089 + if (!rlast) {
53090 + rtmp->prev = NULL;
53091 + rolep->allowed_ips = rtmp;
53092 + } else {
53093 + rlast->next = rtmp;
53094 + rtmp->prev = rlast;
53095 + }
53096 +
53097 + if (!ruserip)
53098 + rtmp->next = NULL;
53099 + }
53100 +
53101 + return 0;
53102 +}
53103 +
53104 +static int
53105 +copy_user_transitions(struct acl_role_label *rolep)
53106 +{
53107 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53108 +
53109 + unsigned int len;
53110 + char *tmp;
53111 +
53112 + rusertp = rolep->transitions;
53113 +
53114 + while (rusertp) {
53115 + rlast = rtmp;
53116 +
53117 + if ((rtmp = (struct role_transition *)
53118 + acl_alloc(sizeof (struct role_transition))) == NULL)
53119 + return -ENOMEM;
53120 +
53121 + if (copy_from_user(rtmp, rusertp,
53122 + sizeof (struct role_transition)))
53123 + return -EFAULT;
53124 +
53125 + rusertp = rtmp->prev;
53126 +
53127 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53128 +
53129 + if (!len || len >= GR_SPROLE_LEN)
53130 + return -EINVAL;
53131 +
53132 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53133 + return -ENOMEM;
53134 +
53135 + if (copy_from_user(tmp, rtmp->rolename, len))
53136 + return -EFAULT;
53137 + tmp[len-1] = '\0';
53138 + rtmp->rolename = tmp;
53139 +
53140 + if (!rlast) {
53141 + rtmp->prev = NULL;
53142 + rolep->transitions = rtmp;
53143 + } else {
53144 + rlast->next = rtmp;
53145 + rtmp->prev = rlast;
53146 + }
53147 +
53148 + if (!rusertp)
53149 + rtmp->next = NULL;
53150 + }
53151 +
53152 + return 0;
53153 +}
53154 +
53155 +static struct acl_subject_label *
53156 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53157 +{
53158 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53159 + unsigned int len;
53160 + char *tmp;
53161 + __u32 num_objs;
53162 + struct acl_ip_label **i_tmp, *i_utmp2;
53163 + struct gr_hash_struct ghash;
53164 + struct subject_map *subjmap;
53165 + unsigned int i_num;
53166 + int err;
53167 +
53168 + if (already_copied != NULL)
53169 + *already_copied = 0;
53170 +
53171 + s_tmp = lookup_subject_map(userp);
53172 +
53173 + /* we've already copied this subject into the kernel, just return
53174 + the reference to it, and don't copy it over again
53175 + */
53176 + if (s_tmp) {
53177 + if (already_copied != NULL)
53178 + *already_copied = 1;
53179 + return(s_tmp);
53180 + }
53181 +
53182 + if ((s_tmp = (struct acl_subject_label *)
53183 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53184 + return ERR_PTR(-ENOMEM);
53185 +
53186 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53187 + if (subjmap == NULL)
53188 + return ERR_PTR(-ENOMEM);
53189 +
53190 + subjmap->user = userp;
53191 + subjmap->kernel = s_tmp;
53192 + insert_subj_map_entry(subjmap);
53193 +
53194 + if (copy_from_user(s_tmp, userp,
53195 + sizeof (struct acl_subject_label)))
53196 + return ERR_PTR(-EFAULT);
53197 +
53198 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53199 +
53200 + if (!len || len >= PATH_MAX)
53201 + return ERR_PTR(-EINVAL);
53202 +
53203 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53204 + return ERR_PTR(-ENOMEM);
53205 +
53206 + if (copy_from_user(tmp, s_tmp->filename, len))
53207 + return ERR_PTR(-EFAULT);
53208 + tmp[len-1] = '\0';
53209 + s_tmp->filename = tmp;
53210 +
53211 + if (!strcmp(s_tmp->filename, "/"))
53212 + role->root_label = s_tmp;
53213 +
53214 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53215 + return ERR_PTR(-EFAULT);
53216 +
53217 + /* copy user and group transition tables */
53218 +
53219 + if (s_tmp->user_trans_num) {
53220 + uid_t *uidlist;
53221 +
53222 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53223 + if (uidlist == NULL)
53224 + return ERR_PTR(-ENOMEM);
53225 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53226 + return ERR_PTR(-EFAULT);
53227 +
53228 + s_tmp->user_transitions = uidlist;
53229 + }
53230 +
53231 + if (s_tmp->group_trans_num) {
53232 + gid_t *gidlist;
53233 +
53234 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53235 + if (gidlist == NULL)
53236 + return ERR_PTR(-ENOMEM);
53237 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53238 + return ERR_PTR(-EFAULT);
53239 +
53240 + s_tmp->group_transitions = gidlist;
53241 + }
53242 +
53243 + /* set up object hash table */
53244 + num_objs = count_user_objs(ghash.first);
53245 +
53246 + s_tmp->obj_hash_size = num_objs;
53247 + s_tmp->obj_hash =
53248 + (struct acl_object_label **)
53249 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53250 +
53251 + if (!s_tmp->obj_hash)
53252 + return ERR_PTR(-ENOMEM);
53253 +
53254 + memset(s_tmp->obj_hash, 0,
53255 + s_tmp->obj_hash_size *
53256 + sizeof (struct acl_object_label *));
53257 +
53258 + /* add in objects */
53259 + err = copy_user_objs(ghash.first, s_tmp, role);
53260 +
53261 + if (err)
53262 + return ERR_PTR(err);
53263 +
53264 + /* set pointer for parent subject */
53265 + if (s_tmp->parent_subject) {
53266 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53267 +
53268 + if (IS_ERR(s_tmp2))
53269 + return s_tmp2;
53270 +
53271 + s_tmp->parent_subject = s_tmp2;
53272 + }
53273 +
53274 + /* add in ip acls */
53275 +
53276 + if (!s_tmp->ip_num) {
53277 + s_tmp->ips = NULL;
53278 + goto insert;
53279 + }
53280 +
53281 + i_tmp =
53282 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53283 + sizeof (struct acl_ip_label *));
53284 +
53285 + if (!i_tmp)
53286 + return ERR_PTR(-ENOMEM);
53287 +
53288 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53289 + *(i_tmp + i_num) =
53290 + (struct acl_ip_label *)
53291 + acl_alloc(sizeof (struct acl_ip_label));
53292 + if (!*(i_tmp + i_num))
53293 + return ERR_PTR(-ENOMEM);
53294 +
53295 + if (copy_from_user
53296 + (&i_utmp2, s_tmp->ips + i_num,
53297 + sizeof (struct acl_ip_label *)))
53298 + return ERR_PTR(-EFAULT);
53299 +
53300 + if (copy_from_user
53301 + (*(i_tmp + i_num), i_utmp2,
53302 + sizeof (struct acl_ip_label)))
53303 + return ERR_PTR(-EFAULT);
53304 +
53305 + if ((*(i_tmp + i_num))->iface == NULL)
53306 + continue;
53307 +
53308 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53309 + if (!len || len >= IFNAMSIZ)
53310 + return ERR_PTR(-EINVAL);
53311 + tmp = acl_alloc(len);
53312 + if (tmp == NULL)
53313 + return ERR_PTR(-ENOMEM);
53314 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53315 + return ERR_PTR(-EFAULT);
53316 + (*(i_tmp + i_num))->iface = tmp;
53317 + }
53318 +
53319 + s_tmp->ips = i_tmp;
53320 +
53321 +insert:
53322 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53323 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53324 + return ERR_PTR(-ENOMEM);
53325 +
53326 + return s_tmp;
53327 +}
53328 +
53329 +static int
53330 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53331 +{
53332 + struct acl_subject_label s_pre;
53333 + struct acl_subject_label * ret;
53334 + int err;
53335 +
53336 + while (userp) {
53337 + if (copy_from_user(&s_pre, userp,
53338 + sizeof (struct acl_subject_label)))
53339 + return -EFAULT;
53340 +
53341 + /* do not add nested subjects here, add
53342 + while parsing objects
53343 + */
53344 +
53345 + if (s_pre.mode & GR_NESTED) {
53346 + userp = s_pre.prev;
53347 + continue;
53348 + }
53349 +
53350 + ret = do_copy_user_subj(userp, role, NULL);
53351 +
53352 + err = PTR_ERR(ret);
53353 + if (IS_ERR(ret))
53354 + return err;
53355 +
53356 + insert_acl_subj_label(ret, role);
53357 +
53358 + userp = s_pre.prev;
53359 + }
53360 +
53361 + return 0;
53362 +}
53363 +
53364 +static int
53365 +copy_user_acl(struct gr_arg *arg)
53366 +{
53367 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53368 + struct acl_subject_label *subj_list;
53369 + struct sprole_pw *sptmp;
53370 + struct gr_hash_struct *ghash;
53371 + uid_t *domainlist;
53372 + unsigned int r_num;
53373 + unsigned int len;
53374 + char *tmp;
53375 + int err = 0;
53376 + __u16 i;
53377 + __u32 num_subjs;
53378 +
53379 + /* we need a default and kernel role */
53380 + if (arg->role_db.num_roles < 2)
53381 + return -EINVAL;
53382 +
53383 + /* copy special role authentication info from userspace */
53384 +
53385 + num_sprole_pws = arg->num_sprole_pws;
53386 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53387 +
53388 + if (!acl_special_roles && num_sprole_pws)
53389 + return -ENOMEM;
53390 +
53391 + for (i = 0; i < num_sprole_pws; i++) {
53392 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53393 + if (!sptmp)
53394 + return -ENOMEM;
53395 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53396 + sizeof (struct sprole_pw)))
53397 + return -EFAULT;
53398 +
53399 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53400 +
53401 + if (!len || len >= GR_SPROLE_LEN)
53402 + return -EINVAL;
53403 +
53404 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53405 + return -ENOMEM;
53406 +
53407 + if (copy_from_user(tmp, sptmp->rolename, len))
53408 + return -EFAULT;
53409 +
53410 + tmp[len-1] = '\0';
53411 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53412 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53413 +#endif
53414 + sptmp->rolename = tmp;
53415 + acl_special_roles[i] = sptmp;
53416 + }
53417 +
53418 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53419 +
53420 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53421 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53422 +
53423 + if (!r_tmp)
53424 + return -ENOMEM;
53425 +
53426 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53427 + sizeof (struct acl_role_label *)))
53428 + return -EFAULT;
53429 +
53430 + if (copy_from_user(r_tmp, r_utmp2,
53431 + sizeof (struct acl_role_label)))
53432 + return -EFAULT;
53433 +
53434 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53435 +
53436 + if (!len || len >= PATH_MAX)
53437 + return -EINVAL;
53438 +
53439 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53440 + return -ENOMEM;
53441 +
53442 + if (copy_from_user(tmp, r_tmp->rolename, len))
53443 + return -EFAULT;
53444 +
53445 + tmp[len-1] = '\0';
53446 + r_tmp->rolename = tmp;
53447 +
53448 + if (!strcmp(r_tmp->rolename, "default")
53449 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53450 + default_role = r_tmp;
53451 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53452 + kernel_role = r_tmp;
53453 + }
53454 +
53455 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53456 + return -ENOMEM;
53457 +
53458 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53459 + return -EFAULT;
53460 +
53461 + r_tmp->hash = ghash;
53462 +
53463 + num_subjs = count_user_subjs(r_tmp->hash->first);
53464 +
53465 + r_tmp->subj_hash_size = num_subjs;
53466 + r_tmp->subj_hash =
53467 + (struct acl_subject_label **)
53468 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53469 +
53470 + if (!r_tmp->subj_hash)
53471 + return -ENOMEM;
53472 +
53473 + err = copy_user_allowedips(r_tmp);
53474 + if (err)
53475 + return err;
53476 +
53477 + /* copy domain info */
53478 + if (r_tmp->domain_children != NULL) {
53479 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53480 + if (domainlist == NULL)
53481 + return -ENOMEM;
53482 +
53483 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53484 + return -EFAULT;
53485 +
53486 + r_tmp->domain_children = domainlist;
53487 + }
53488 +
53489 + err = copy_user_transitions(r_tmp);
53490 + if (err)
53491 + return err;
53492 +
53493 + memset(r_tmp->subj_hash, 0,
53494 + r_tmp->subj_hash_size *
53495 + sizeof (struct acl_subject_label *));
53496 +
53497 + /* acquire the list of subjects, then NULL out
53498 + the list prior to parsing the subjects for this role,
53499 + as during this parsing the list is replaced with a list
53500 + of *nested* subjects for the role
53501 + */
53502 + subj_list = r_tmp->hash->first;
53503 +
53504 + /* set nested subject list to null */
53505 + r_tmp->hash->first = NULL;
53506 +
53507 + err = copy_user_subjs(subj_list, r_tmp);
53508 +
53509 + if (err)
53510 + return err;
53511 +
53512 + insert_acl_role_label(r_tmp);
53513 + }
53514 +
53515 + if (default_role == NULL || kernel_role == NULL)
53516 + return -EINVAL;
53517 +
53518 + return err;
53519 +}
53520 +
53521 +static int
53522 +gracl_init(struct gr_arg *args)
53523 +{
53524 + int error = 0;
53525 +
53526 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53527 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53528 +
53529 + if (init_variables(args)) {
53530 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53531 + error = -ENOMEM;
53532 + free_variables();
53533 + goto out;
53534 + }
53535 +
53536 + error = copy_user_acl(args);
53537 + free_init_variables();
53538 + if (error) {
53539 + free_variables();
53540 + goto out;
53541 + }
53542 +
53543 + if ((error = gr_set_acls(0))) {
53544 + free_variables();
53545 + goto out;
53546 + }
53547 +
53548 + pax_open_kernel();
53549 + gr_status |= GR_READY;
53550 + pax_close_kernel();
53551 +
53552 + out:
53553 + return error;
53554 +}
53555 +
53556 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53557 +
53558 +static int
53559 +glob_match(const char *p, const char *n)
53560 +{
53561 + char c;
53562 +
53563 + while ((c = *p++) != '\0') {
53564 + switch (c) {
53565 + case '?':
53566 + if (*n == '\0')
53567 + return 1;
53568 + else if (*n == '/')
53569 + return 1;
53570 + break;
53571 + case '\\':
53572 + if (*n != c)
53573 + return 1;
53574 + break;
53575 + case '*':
53576 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53577 + if (*n == '/')
53578 + return 1;
53579 + else if (c == '?') {
53580 + if (*n == '\0')
53581 + return 1;
53582 + else
53583 + ++n;
53584 + }
53585 + }
53586 + if (c == '\0') {
53587 + return 0;
53588 + } else {
53589 + const char *endp;
53590 +
53591 + if ((endp = strchr(n, '/')) == NULL)
53592 + endp = n + strlen(n);
53593 +
53594 + if (c == '[') {
53595 + for (--p; n < endp; ++n)
53596 + if (!glob_match(p, n))
53597 + return 0;
53598 + } else if (c == '/') {
53599 + while (*n != '\0' && *n != '/')
53600 + ++n;
53601 + if (*n == '/' && !glob_match(p, n + 1))
53602 + return 0;
53603 + } else {
53604 + for (--p; n < endp; ++n)
53605 + if (*n == c && !glob_match(p, n))
53606 + return 0;
53607 + }
53608 +
53609 + return 1;
53610 + }
53611 + case '[':
53612 + {
53613 + int not;
53614 + char cold;
53615 +
53616 + if (*n == '\0' || *n == '/')
53617 + return 1;
53618 +
53619 + not = (*p == '!' || *p == '^');
53620 + if (not)
53621 + ++p;
53622 +
53623 + c = *p++;
53624 + for (;;) {
53625 + unsigned char fn = (unsigned char)*n;
53626 +
53627 + if (c == '\0')
53628 + return 1;
53629 + else {
53630 + if (c == fn)
53631 + goto matched;
53632 + cold = c;
53633 + c = *p++;
53634 +
53635 + if (c == '-' && *p != ']') {
53636 + unsigned char cend = *p++;
53637 +
53638 + if (cend == '\0')
53639 + return 1;
53640 +
53641 + if (cold <= fn && fn <= cend)
53642 + goto matched;
53643 +
53644 + c = *p++;
53645 + }
53646 + }
53647 +
53648 + if (c == ']')
53649 + break;
53650 + }
53651 + if (!not)
53652 + return 1;
53653 + break;
53654 + matched:
53655 + while (c != ']') {
53656 + if (c == '\0')
53657 + return 1;
53658 +
53659 + c = *p++;
53660 + }
53661 + if (not)
53662 + return 1;
53663 + }
53664 + break;
53665 + default:
53666 + if (c != *n)
53667 + return 1;
53668 + }
53669 +
53670 + ++n;
53671 + }
53672 +
53673 + if (*n == '\0')
53674 + return 0;
53675 +
53676 + if (*n == '/')
53677 + return 0;
53678 +
53679 + return 1;
53680 +}
53681 +
53682 +static struct acl_object_label *
53683 +chk_glob_label(struct acl_object_label *globbed,
53684 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53685 +{
53686 + struct acl_object_label *tmp;
53687 +
53688 + if (*path == NULL)
53689 + *path = gr_to_filename_nolock(dentry, mnt);
53690 +
53691 + tmp = globbed;
53692 +
53693 + while (tmp) {
53694 + if (!glob_match(tmp->filename, *path))
53695 + return tmp;
53696 + tmp = tmp->next;
53697 + }
53698 +
53699 + return NULL;
53700 +}
53701 +
53702 +static struct acl_object_label *
53703 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53704 + const ino_t curr_ino, const dev_t curr_dev,
53705 + const struct acl_subject_label *subj, char **path, const int checkglob)
53706 +{
53707 + struct acl_subject_label *tmpsubj;
53708 + struct acl_object_label *retval;
53709 + struct acl_object_label *retval2;
53710 +
53711 + tmpsubj = (struct acl_subject_label *) subj;
53712 + read_lock(&gr_inode_lock);
53713 + do {
53714 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53715 + if (retval) {
53716 + if (checkglob && retval->globbed) {
53717 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53718 + if (retval2)
53719 + retval = retval2;
53720 + }
53721 + break;
53722 + }
53723 + } while ((tmpsubj = tmpsubj->parent_subject));
53724 + read_unlock(&gr_inode_lock);
53725 +
53726 + return retval;
53727 +}
53728 +
53729 +static __inline__ struct acl_object_label *
53730 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53731 + struct dentry *curr_dentry,
53732 + const struct acl_subject_label *subj, char **path, const int checkglob)
53733 +{
53734 + int newglob = checkglob;
53735 + ino_t inode;
53736 + dev_t device;
53737 +
53738 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53739 + as we don't want a / * rule to match instead of the / object
53740 + don't do this for create lookups that call this function though, since they're looking up
53741 + on the parent and thus need globbing checks on all paths
53742 + */
53743 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53744 + newglob = GR_NO_GLOB;
53745 +
53746 + spin_lock(&curr_dentry->d_lock);
53747 + inode = curr_dentry->d_inode->i_ino;
53748 + device = __get_dev(curr_dentry);
53749 + spin_unlock(&curr_dentry->d_lock);
53750 +
53751 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53752 +}
53753 +
53754 +static struct acl_object_label *
53755 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53756 + const struct acl_subject_label *subj, char *path, const int checkglob)
53757 +{
53758 + struct dentry *dentry = (struct dentry *) l_dentry;
53759 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53760 + struct mount *real_mnt = real_mount(mnt);
53761 + struct acl_object_label *retval;
53762 + struct dentry *parent;
53763 +
53764 + write_seqlock(&rename_lock);
53765 + br_read_lock(&vfsmount_lock);
53766 +
53767 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53768 +#ifdef CONFIG_NET
53769 + mnt == sock_mnt ||
53770 +#endif
53771 +#ifdef CONFIG_HUGETLBFS
53772 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53773 +#endif
53774 + /* ignore Eric Biederman */
53775 + IS_PRIVATE(l_dentry->d_inode))) {
53776 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53777 + goto out;
53778 + }
53779 +
53780 + for (;;) {
53781 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53782 + break;
53783 +
53784 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53785 + if (!mnt_has_parent(real_mnt))
53786 + break;
53787 +
53788 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53789 + if (retval != NULL)
53790 + goto out;
53791 +
53792 + dentry = real_mnt->mnt_mountpoint;
53793 + real_mnt = real_mnt->mnt_parent;
53794 + mnt = &real_mnt->mnt;
53795 + continue;
53796 + }
53797 +
53798 + parent = dentry->d_parent;
53799 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53800 + if (retval != NULL)
53801 + goto out;
53802 +
53803 + dentry = parent;
53804 + }
53805 +
53806 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53807 +
53808 + /* real_root is pinned so we don't have to hold a reference */
53809 + if (retval == NULL)
53810 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53811 +out:
53812 + br_read_unlock(&vfsmount_lock);
53813 + write_sequnlock(&rename_lock);
53814 +
53815 + BUG_ON(retval == NULL);
53816 +
53817 + return retval;
53818 +}
53819 +
53820 +static __inline__ struct acl_object_label *
53821 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53822 + const struct acl_subject_label *subj)
53823 +{
53824 + char *path = NULL;
53825 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53826 +}
53827 +
53828 +static __inline__ struct acl_object_label *
53829 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53830 + const struct acl_subject_label *subj)
53831 +{
53832 + char *path = NULL;
53833 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53834 +}
53835 +
53836 +static __inline__ struct acl_object_label *
53837 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53838 + const struct acl_subject_label *subj, char *path)
53839 +{
53840 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53841 +}
53842 +
53843 +static struct acl_subject_label *
53844 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53845 + const struct acl_role_label *role)
53846 +{
53847 + struct dentry *dentry = (struct dentry *) l_dentry;
53848 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53849 + struct mount *real_mnt = real_mount(mnt);
53850 + struct acl_subject_label *retval;
53851 + struct dentry *parent;
53852 +
53853 + write_seqlock(&rename_lock);
53854 + br_read_lock(&vfsmount_lock);
53855 +
53856 + for (;;) {
53857 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53858 + break;
53859 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53860 + if (!mnt_has_parent(real_mnt))
53861 + break;
53862 +
53863 + spin_lock(&dentry->d_lock);
53864 + read_lock(&gr_inode_lock);
53865 + retval =
53866 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53867 + __get_dev(dentry), role);
53868 + read_unlock(&gr_inode_lock);
53869 + spin_unlock(&dentry->d_lock);
53870 + if (retval != NULL)
53871 + goto out;
53872 +
53873 + dentry = real_mnt->mnt_mountpoint;
53874 + real_mnt = real_mnt->mnt_parent;
53875 + mnt = &real_mnt->mnt;
53876 + continue;
53877 + }
53878 +
53879 + spin_lock(&dentry->d_lock);
53880 + read_lock(&gr_inode_lock);
53881 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53882 + __get_dev(dentry), role);
53883 + read_unlock(&gr_inode_lock);
53884 + parent = dentry->d_parent;
53885 + spin_unlock(&dentry->d_lock);
53886 +
53887 + if (retval != NULL)
53888 + goto out;
53889 +
53890 + dentry = parent;
53891 + }
53892 +
53893 + spin_lock(&dentry->d_lock);
53894 + read_lock(&gr_inode_lock);
53895 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53896 + __get_dev(dentry), role);
53897 + read_unlock(&gr_inode_lock);
53898 + spin_unlock(&dentry->d_lock);
53899 +
53900 + if (unlikely(retval == NULL)) {
53901 + /* real_root is pinned, we don't need to hold a reference */
53902 + read_lock(&gr_inode_lock);
53903 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53904 + __get_dev(real_root.dentry), role);
53905 + read_unlock(&gr_inode_lock);
53906 + }
53907 +out:
53908 + br_read_unlock(&vfsmount_lock);
53909 + write_sequnlock(&rename_lock);
53910 +
53911 + BUG_ON(retval == NULL);
53912 +
53913 + return retval;
53914 +}
53915 +
53916 +static void
53917 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53918 +{
53919 + struct task_struct *task = current;
53920 + const struct cred *cred = current_cred();
53921 +
53922 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53923 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53924 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53925 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53926 +
53927 + return;
53928 +}
53929 +
53930 +static void
53931 +gr_log_learn_id_change(const char type, const unsigned int real,
53932 + const unsigned int effective, const unsigned int fs)
53933 +{
53934 + struct task_struct *task = current;
53935 + const struct cred *cred = current_cred();
53936 +
53937 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53938 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53939 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53940 + type, real, effective, fs, &task->signal->saved_ip);
53941 +
53942 + return;
53943 +}
53944 +
53945 +__u32
53946 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53947 + const struct vfsmount * mnt)
53948 +{
53949 + __u32 retval = mode;
53950 + struct acl_subject_label *curracl;
53951 + struct acl_object_label *currobj;
53952 +
53953 + if (unlikely(!(gr_status & GR_READY)))
53954 + return (mode & ~GR_AUDITS);
53955 +
53956 + curracl = current->acl;
53957 +
53958 + currobj = chk_obj_label(dentry, mnt, curracl);
53959 + retval = currobj->mode & mode;
53960 +
53961 + /* if we're opening a specified transfer file for writing
53962 + (e.g. /dev/initctl), then transfer our role to init
53963 + */
53964 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53965 + current->role->roletype & GR_ROLE_PERSIST)) {
53966 + struct task_struct *task = init_pid_ns.child_reaper;
53967 +
53968 + if (task->role != current->role) {
53969 + task->acl_sp_role = 0;
53970 + task->acl_role_id = current->acl_role_id;
53971 + task->role = current->role;
53972 + rcu_read_lock();
53973 + read_lock(&grsec_exec_file_lock);
53974 + gr_apply_subject_to_task(task);
53975 + read_unlock(&grsec_exec_file_lock);
53976 + rcu_read_unlock();
53977 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53978 + }
53979 + }
53980 +
53981 + if (unlikely
53982 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53983 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53984 + __u32 new_mode = mode;
53985 +
53986 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53987 +
53988 + retval = new_mode;
53989 +
53990 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53991 + new_mode |= GR_INHERIT;
53992 +
53993 + if (!(mode & GR_NOLEARN))
53994 + gr_log_learn(dentry, mnt, new_mode);
53995 + }
53996 +
53997 + return retval;
53998 +}
53999 +
54000 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54001 + const struct dentry *parent,
54002 + const struct vfsmount *mnt)
54003 +{
54004 + struct name_entry *match;
54005 + struct acl_object_label *matchpo;
54006 + struct acl_subject_label *curracl;
54007 + char *path;
54008 +
54009 + if (unlikely(!(gr_status & GR_READY)))
54010 + return NULL;
54011 +
54012 + preempt_disable();
54013 + path = gr_to_filename_rbac(new_dentry, mnt);
54014 + match = lookup_name_entry_create(path);
54015 +
54016 + curracl = current->acl;
54017 +
54018 + if (match) {
54019 + read_lock(&gr_inode_lock);
54020 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54021 + read_unlock(&gr_inode_lock);
54022 +
54023 + if (matchpo) {
54024 + preempt_enable();
54025 + return matchpo;
54026 + }
54027 + }
54028 +
54029 + // lookup parent
54030 +
54031 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54032 +
54033 + preempt_enable();
54034 + return matchpo;
54035 +}
54036 +
54037 +__u32
54038 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54039 + const struct vfsmount * mnt, const __u32 mode)
54040 +{
54041 + struct acl_object_label *matchpo;
54042 + __u32 retval;
54043 +
54044 + if (unlikely(!(gr_status & GR_READY)))
54045 + return (mode & ~GR_AUDITS);
54046 +
54047 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
54048 +
54049 + retval = matchpo->mode & mode;
54050 +
54051 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54052 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54053 + __u32 new_mode = mode;
54054 +
54055 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54056 +
54057 + gr_log_learn(new_dentry, mnt, new_mode);
54058 + return new_mode;
54059 + }
54060 +
54061 + return retval;
54062 +}
54063 +
54064 +__u32
54065 +gr_check_link(const struct dentry * new_dentry,
54066 + const struct dentry * parent_dentry,
54067 + const struct vfsmount * parent_mnt,
54068 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54069 +{
54070 + struct acl_object_label *obj;
54071 + __u32 oldmode, newmode;
54072 + __u32 needmode;
54073 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54074 + GR_DELETE | GR_INHERIT;
54075 +
54076 + if (unlikely(!(gr_status & GR_READY)))
54077 + return (GR_CREATE | GR_LINK);
54078 +
54079 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54080 + oldmode = obj->mode;
54081 +
54082 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54083 + newmode = obj->mode;
54084 +
54085 + needmode = newmode & checkmodes;
54086 +
54087 + // old name for hardlink must have at least the permissions of the new name
54088 + if ((oldmode & needmode) != needmode)
54089 + goto bad;
54090 +
54091 + // if old name had restrictions/auditing, make sure the new name does as well
54092 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54093 +
54094 + // don't allow hardlinking of suid/sgid/fcapped files without permission
54095 + if (is_privileged_binary(old_dentry))
54096 + needmode |= GR_SETID;
54097 +
54098 + if ((newmode & needmode) != needmode)
54099 + goto bad;
54100 +
54101 + // enforce minimum permissions
54102 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54103 + return newmode;
54104 +bad:
54105 + needmode = oldmode;
54106 + if (is_privileged_binary(old_dentry))
54107 + needmode |= GR_SETID;
54108 +
54109 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54110 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54111 + return (GR_CREATE | GR_LINK);
54112 + } else if (newmode & GR_SUPPRESS)
54113 + return GR_SUPPRESS;
54114 + else
54115 + return 0;
54116 +}
54117 +
54118 +int
54119 +gr_check_hidden_task(const struct task_struct *task)
54120 +{
54121 + if (unlikely(!(gr_status & GR_READY)))
54122 + return 0;
54123 +
54124 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54125 + return 1;
54126 +
54127 + return 0;
54128 +}
54129 +
54130 +int
54131 +gr_check_protected_task(const struct task_struct *task)
54132 +{
54133 + if (unlikely(!(gr_status & GR_READY) || !task))
54134 + return 0;
54135 +
54136 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54137 + task->acl != current->acl)
54138 + return 1;
54139 +
54140 + return 0;
54141 +}
54142 +
54143 +int
54144 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54145 +{
54146 + struct task_struct *p;
54147 + int ret = 0;
54148 +
54149 + if (unlikely(!(gr_status & GR_READY) || !pid))
54150 + return ret;
54151 +
54152 + read_lock(&tasklist_lock);
54153 + do_each_pid_task(pid, type, p) {
54154 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54155 + p->acl != current->acl) {
54156 + ret = 1;
54157 + goto out;
54158 + }
54159 + } while_each_pid_task(pid, type, p);
54160 +out:
54161 + read_unlock(&tasklist_lock);
54162 +
54163 + return ret;
54164 +}
54165 +
54166 +void
54167 +gr_copy_label(struct task_struct *tsk)
54168 +{
54169 + tsk->signal->used_accept = 0;
54170 + tsk->acl_sp_role = 0;
54171 + tsk->acl_role_id = current->acl_role_id;
54172 + tsk->acl = current->acl;
54173 + tsk->role = current->role;
54174 + tsk->signal->curr_ip = current->signal->curr_ip;
54175 + tsk->signal->saved_ip = current->signal->saved_ip;
54176 + if (current->exec_file)
54177 + get_file(current->exec_file);
54178 + tsk->exec_file = current->exec_file;
54179 + tsk->is_writable = current->is_writable;
54180 + if (unlikely(current->signal->used_accept)) {
54181 + current->signal->curr_ip = 0;
54182 + current->signal->saved_ip = 0;
54183 + }
54184 +
54185 + return;
54186 +}
54187 +
54188 +static void
54189 +gr_set_proc_res(struct task_struct *task)
54190 +{
54191 + struct acl_subject_label *proc;
54192 + unsigned short i;
54193 +
54194 + proc = task->acl;
54195 +
54196 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54197 + return;
54198 +
54199 + for (i = 0; i < RLIM_NLIMITS; i++) {
54200 + if (!(proc->resmask & (1 << i)))
54201 + continue;
54202 +
54203 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54204 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54205 + }
54206 +
54207 + return;
54208 +}
54209 +
54210 +extern int __gr_process_user_ban(struct user_struct *user);
54211 +
54212 +int
54213 +gr_check_user_change(int real, int effective, int fs)
54214 +{
54215 + unsigned int i;
54216 + __u16 num;
54217 + uid_t *uidlist;
54218 + int curuid;
54219 + int realok = 0;
54220 + int effectiveok = 0;
54221 + int fsok = 0;
54222 +
54223 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54224 + struct user_struct *user;
54225 +
54226 + if (real == -1)
54227 + goto skipit;
54228 +
54229 + user = find_user(real);
54230 + if (user == NULL)
54231 + goto skipit;
54232 +
54233 + if (__gr_process_user_ban(user)) {
54234 + /* for find_user */
54235 + free_uid(user);
54236 + return 1;
54237 + }
54238 +
54239 + /* for find_user */
54240 + free_uid(user);
54241 +
54242 +skipit:
54243 +#endif
54244 +
54245 + if (unlikely(!(gr_status & GR_READY)))
54246 + return 0;
54247 +
54248 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54249 + gr_log_learn_id_change('u', real, effective, fs);
54250 +
54251 + num = current->acl->user_trans_num;
54252 + uidlist = current->acl->user_transitions;
54253 +
54254 + if (uidlist == NULL)
54255 + return 0;
54256 +
54257 + if (real == -1)
54258 + realok = 1;
54259 + if (effective == -1)
54260 + effectiveok = 1;
54261 + if (fs == -1)
54262 + fsok = 1;
54263 +
54264 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54265 + for (i = 0; i < num; i++) {
54266 + curuid = (int)uidlist[i];
54267 + if (real == curuid)
54268 + realok = 1;
54269 + if (effective == curuid)
54270 + effectiveok = 1;
54271 + if (fs == curuid)
54272 + fsok = 1;
54273 + }
54274 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54275 + for (i = 0; i < num; i++) {
54276 + curuid = (int)uidlist[i];
54277 + if (real == curuid)
54278 + break;
54279 + if (effective == curuid)
54280 + break;
54281 + if (fs == curuid)
54282 + break;
54283 + }
54284 + /* not in deny list */
54285 + if (i == num) {
54286 + realok = 1;
54287 + effectiveok = 1;
54288 + fsok = 1;
54289 + }
54290 + }
54291 +
54292 + if (realok && effectiveok && fsok)
54293 + return 0;
54294 + else {
54295 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54296 + return 1;
54297 + }
54298 +}
54299 +
54300 +int
54301 +gr_check_group_change(int real, int effective, int fs)
54302 +{
54303 + unsigned int i;
54304 + __u16 num;
54305 + gid_t *gidlist;
54306 + int curgid;
54307 + int realok = 0;
54308 + int effectiveok = 0;
54309 + int fsok = 0;
54310 +
54311 + if (unlikely(!(gr_status & GR_READY)))
54312 + return 0;
54313 +
54314 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54315 + gr_log_learn_id_change('g', real, effective, fs);
54316 +
54317 + num = current->acl->group_trans_num;
54318 + gidlist = current->acl->group_transitions;
54319 +
54320 + if (gidlist == NULL)
54321 + return 0;
54322 +
54323 + if (real == -1)
54324 + realok = 1;
54325 + if (effective == -1)
54326 + effectiveok = 1;
54327 + if (fs == -1)
54328 + fsok = 1;
54329 +
54330 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54331 + for (i = 0; i < num; i++) {
54332 + curgid = (int)gidlist[i];
54333 + if (real == curgid)
54334 + realok = 1;
54335 + if (effective == curgid)
54336 + effectiveok = 1;
54337 + if (fs == curgid)
54338 + fsok = 1;
54339 + }
54340 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54341 + for (i = 0; i < num; i++) {
54342 + curgid = (int)gidlist[i];
54343 + if (real == curgid)
54344 + break;
54345 + if (effective == curgid)
54346 + break;
54347 + if (fs == curgid)
54348 + break;
54349 + }
54350 + /* not in deny list */
54351 + if (i == num) {
54352 + realok = 1;
54353 + effectiveok = 1;
54354 + fsok = 1;
54355 + }
54356 + }
54357 +
54358 + if (realok && effectiveok && fsok)
54359 + return 0;
54360 + else {
54361 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54362 + return 1;
54363 + }
54364 +}
54365 +
54366 +extern int gr_acl_is_capable(const int cap);
54367 +
54368 +void
54369 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54370 +{
54371 + struct acl_role_label *role = task->role;
54372 + struct acl_subject_label *subj = NULL;
54373 + struct acl_object_label *obj;
54374 + struct file *filp;
54375 +
54376 + if (unlikely(!(gr_status & GR_READY)))
54377 + return;
54378 +
54379 + filp = task->exec_file;
54380 +
54381 + /* kernel process, we'll give them the kernel role */
54382 + if (unlikely(!filp)) {
54383 + task->role = kernel_role;
54384 + task->acl = kernel_role->root_label;
54385 + return;
54386 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54387 + role = lookup_acl_role_label(task, uid, gid);
54388 +
54389 + /* don't change the role if we're not a privileged process */
54390 + if (role && task->role != role &&
54391 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54392 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54393 + return;
54394 +
54395 + /* perform subject lookup in possibly new role
54396 + we can use this result below in the case where role == task->role
54397 + */
54398 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54399 +
54400 + /* if we changed uid/gid, but result in the same role
54401 + and are using inheritance, don't lose the inherited subject
54402 + if current subject is other than what normal lookup
54403 + would result in, we arrived via inheritance, don't
54404 + lose subject
54405 + */
54406 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54407 + (subj == task->acl)))
54408 + task->acl = subj;
54409 +
54410 + task->role = role;
54411 +
54412 + task->is_writable = 0;
54413 +
54414 + /* ignore additional mmap checks for processes that are writable
54415 + by the default ACL */
54416 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54417 + if (unlikely(obj->mode & GR_WRITE))
54418 + task->is_writable = 1;
54419 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54420 + if (unlikely(obj->mode & GR_WRITE))
54421 + task->is_writable = 1;
54422 +
54423 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54424 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54425 +#endif
54426 +
54427 + gr_set_proc_res(task);
54428 +
54429 + return;
54430 +}
54431 +
54432 +int
54433 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54434 + const int unsafe_flags)
54435 +{
54436 + struct task_struct *task = current;
54437 + struct acl_subject_label *newacl;
54438 + struct acl_object_label *obj;
54439 + __u32 retmode;
54440 +
54441 + if (unlikely(!(gr_status & GR_READY)))
54442 + return 0;
54443 +
54444 + newacl = chk_subj_label(dentry, mnt, task->role);
54445 +
54446 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54447 + did an exec
54448 + */
54449 + rcu_read_lock();
54450 + read_lock(&tasklist_lock);
54451 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54452 + (task->parent->acl->mode & GR_POVERRIDE))) {
54453 + read_unlock(&tasklist_lock);
54454 + rcu_read_unlock();
54455 + goto skip_check;
54456 + }
54457 + read_unlock(&tasklist_lock);
54458 + rcu_read_unlock();
54459 +
54460 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54461 + !(task->role->roletype & GR_ROLE_GOD) &&
54462 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54463 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54464 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54465 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54466 + else
54467 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54468 + return -EACCES;
54469 + }
54470 +
54471 +skip_check:
54472 +
54473 + obj = chk_obj_label(dentry, mnt, task->acl);
54474 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54475 +
54476 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54477 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54478 + if (obj->nested)
54479 + task->acl = obj->nested;
54480 + else
54481 + task->acl = newacl;
54482 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54483 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54484 +
54485 + task->is_writable = 0;
54486 +
54487 + /* ignore additional mmap checks for processes that are writable
54488 + by the default ACL */
54489 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54490 + if (unlikely(obj->mode & GR_WRITE))
54491 + task->is_writable = 1;
54492 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54493 + if (unlikely(obj->mode & GR_WRITE))
54494 + task->is_writable = 1;
54495 +
54496 + gr_set_proc_res(task);
54497 +
54498 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54499 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54500 +#endif
54501 + return 0;
54502 +}
54503 +
54504 +/* always called with valid inodev ptr */
54505 +static void
54506 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54507 +{
54508 + struct acl_object_label *matchpo;
54509 + struct acl_subject_label *matchps;
54510 + struct acl_subject_label *subj;
54511 + struct acl_role_label *role;
54512 + unsigned int x;
54513 +
54514 + FOR_EACH_ROLE_START(role)
54515 + FOR_EACH_SUBJECT_START(role, subj, x)
54516 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54517 + matchpo->mode |= GR_DELETED;
54518 + FOR_EACH_SUBJECT_END(subj,x)
54519 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54520 + /* nested subjects aren't in the role's subj_hash table */
54521 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54522 + matchpo->mode |= GR_DELETED;
54523 + FOR_EACH_NESTED_SUBJECT_END(subj)
54524 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54525 + matchps->mode |= GR_DELETED;
54526 + FOR_EACH_ROLE_END(role)
54527 +
54528 + inodev->nentry->deleted = 1;
54529 +
54530 + return;
54531 +}
54532 +
54533 +void
54534 +gr_handle_delete(const ino_t ino, const dev_t dev)
54535 +{
54536 + struct inodev_entry *inodev;
54537 +
54538 + if (unlikely(!(gr_status & GR_READY)))
54539 + return;
54540 +
54541 + write_lock(&gr_inode_lock);
54542 + inodev = lookup_inodev_entry(ino, dev);
54543 + if (inodev != NULL)
54544 + do_handle_delete(inodev, ino, dev);
54545 + write_unlock(&gr_inode_lock);
54546 +
54547 + return;
54548 +}
54549 +
54550 +static void
54551 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54552 + const ino_t newinode, const dev_t newdevice,
54553 + struct acl_subject_label *subj)
54554 +{
54555 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54556 + struct acl_object_label *match;
54557 +
54558 + match = subj->obj_hash[index];
54559 +
54560 + while (match && (match->inode != oldinode ||
54561 + match->device != olddevice ||
54562 + !(match->mode & GR_DELETED)))
54563 + match = match->next;
54564 +
54565 + if (match && (match->inode == oldinode)
54566 + && (match->device == olddevice)
54567 + && (match->mode & GR_DELETED)) {
54568 + if (match->prev == NULL) {
54569 + subj->obj_hash[index] = match->next;
54570 + if (match->next != NULL)
54571 + match->next->prev = NULL;
54572 + } else {
54573 + match->prev->next = match->next;
54574 + if (match->next != NULL)
54575 + match->next->prev = match->prev;
54576 + }
54577 + match->prev = NULL;
54578 + match->next = NULL;
54579 + match->inode = newinode;
54580 + match->device = newdevice;
54581 + match->mode &= ~GR_DELETED;
54582 +
54583 + insert_acl_obj_label(match, subj);
54584 + }
54585 +
54586 + return;
54587 +}
54588 +
54589 +static void
54590 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54591 + const ino_t newinode, const dev_t newdevice,
54592 + struct acl_role_label *role)
54593 +{
54594 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54595 + struct acl_subject_label *match;
54596 +
54597 + match = role->subj_hash[index];
54598 +
54599 + while (match && (match->inode != oldinode ||
54600 + match->device != olddevice ||
54601 + !(match->mode & GR_DELETED)))
54602 + match = match->next;
54603 +
54604 + if (match && (match->inode == oldinode)
54605 + && (match->device == olddevice)
54606 + && (match->mode & GR_DELETED)) {
54607 + if (match->prev == NULL) {
54608 + role->subj_hash[index] = match->next;
54609 + if (match->next != NULL)
54610 + match->next->prev = NULL;
54611 + } else {
54612 + match->prev->next = match->next;
54613 + if (match->next != NULL)
54614 + match->next->prev = match->prev;
54615 + }
54616 + match->prev = NULL;
54617 + match->next = NULL;
54618 + match->inode = newinode;
54619 + match->device = newdevice;
54620 + match->mode &= ~GR_DELETED;
54621 +
54622 + insert_acl_subj_label(match, role);
54623 + }
54624 +
54625 + return;
54626 +}
54627 +
54628 +static void
54629 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54630 + const ino_t newinode, const dev_t newdevice)
54631 +{
54632 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54633 + struct inodev_entry *match;
54634 +
54635 + match = inodev_set.i_hash[index];
54636 +
54637 + while (match && (match->nentry->inode != oldinode ||
54638 + match->nentry->device != olddevice || !match->nentry->deleted))
54639 + match = match->next;
54640 +
54641 + if (match && (match->nentry->inode == oldinode)
54642 + && (match->nentry->device == olddevice) &&
54643 + match->nentry->deleted) {
54644 + if (match->prev == NULL) {
54645 + inodev_set.i_hash[index] = match->next;
54646 + if (match->next != NULL)
54647 + match->next->prev = NULL;
54648 + } else {
54649 + match->prev->next = match->next;
54650 + if (match->next != NULL)
54651 + match->next->prev = match->prev;
54652 + }
54653 + match->prev = NULL;
54654 + match->next = NULL;
54655 + match->nentry->inode = newinode;
54656 + match->nentry->device = newdevice;
54657 + match->nentry->deleted = 0;
54658 +
54659 + insert_inodev_entry(match);
54660 + }
54661 +
54662 + return;
54663 +}
54664 +
54665 +static void
54666 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54667 +{
54668 + struct acl_subject_label *subj;
54669 + struct acl_role_label *role;
54670 + unsigned int x;
54671 +
54672 + FOR_EACH_ROLE_START(role)
54673 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54674 +
54675 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54676 + if ((subj->inode == ino) && (subj->device == dev)) {
54677 + subj->inode = ino;
54678 + subj->device = dev;
54679 + }
54680 + /* nested subjects aren't in the role's subj_hash table */
54681 + update_acl_obj_label(matchn->inode, matchn->device,
54682 + ino, dev, subj);
54683 + FOR_EACH_NESTED_SUBJECT_END(subj)
54684 + FOR_EACH_SUBJECT_START(role, subj, x)
54685 + update_acl_obj_label(matchn->inode, matchn->device,
54686 + ino, dev, subj);
54687 + FOR_EACH_SUBJECT_END(subj,x)
54688 + FOR_EACH_ROLE_END(role)
54689 +
54690 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54691 +
54692 + return;
54693 +}
54694 +
54695 +static void
54696 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54697 + const struct vfsmount *mnt)
54698 +{
54699 + ino_t ino = dentry->d_inode->i_ino;
54700 + dev_t dev = __get_dev(dentry);
54701 +
54702 + __do_handle_create(matchn, ino, dev);
54703 +
54704 + return;
54705 +}
54706 +
54707 +void
54708 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54709 +{
54710 + struct name_entry *matchn;
54711 +
54712 + if (unlikely(!(gr_status & GR_READY)))
54713 + return;
54714 +
54715 + preempt_disable();
54716 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54717 +
54718 + if (unlikely((unsigned long)matchn)) {
54719 + write_lock(&gr_inode_lock);
54720 + do_handle_create(matchn, dentry, mnt);
54721 + write_unlock(&gr_inode_lock);
54722 + }
54723 + preempt_enable();
54724 +
54725 + return;
54726 +}
54727 +
54728 +void
54729 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54730 +{
54731 + struct name_entry *matchn;
54732 +
54733 + if (unlikely(!(gr_status & GR_READY)))
54734 + return;
54735 +
54736 + preempt_disable();
54737 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54738 +
54739 + if (unlikely((unsigned long)matchn)) {
54740 + write_lock(&gr_inode_lock);
54741 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54742 + write_unlock(&gr_inode_lock);
54743 + }
54744 + preempt_enable();
54745 +
54746 + return;
54747 +}
54748 +
54749 +void
54750 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54751 + struct dentry *old_dentry,
54752 + struct dentry *new_dentry,
54753 + struct vfsmount *mnt, const __u8 replace)
54754 +{
54755 + struct name_entry *matchn;
54756 + struct inodev_entry *inodev;
54757 + struct inode *inode = new_dentry->d_inode;
54758 + ino_t old_ino = old_dentry->d_inode->i_ino;
54759 + dev_t old_dev = __get_dev(old_dentry);
54760 +
54761 + /* vfs_rename swaps the name and parent link for old_dentry and
54762 + new_dentry
54763 + at this point, old_dentry has the new name, parent link, and inode
54764 + for the renamed file
54765 + if a file is being replaced by a rename, new_dentry has the inode
54766 + and name for the replaced file
54767 + */
54768 +
54769 + if (unlikely(!(gr_status & GR_READY)))
54770 + return;
54771 +
54772 + preempt_disable();
54773 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54774 +
54775 + /* we wouldn't have to check d_inode if it weren't for
54776 + NFS silly-renaming
54777 + */
54778 +
54779 + write_lock(&gr_inode_lock);
54780 + if (unlikely(replace && inode)) {
54781 + ino_t new_ino = inode->i_ino;
54782 + dev_t new_dev = __get_dev(new_dentry);
54783 +
54784 + inodev = lookup_inodev_entry(new_ino, new_dev);
54785 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54786 + do_handle_delete(inodev, new_ino, new_dev);
54787 + }
54788 +
54789 + inodev = lookup_inodev_entry(old_ino, old_dev);
54790 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54791 + do_handle_delete(inodev, old_ino, old_dev);
54792 +
54793 + if (unlikely((unsigned long)matchn))
54794 + do_handle_create(matchn, old_dentry, mnt);
54795 +
54796 + write_unlock(&gr_inode_lock);
54797 + preempt_enable();
54798 +
54799 + return;
54800 +}
54801 +
54802 +static int
54803 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54804 + unsigned char **sum)
54805 +{
54806 + struct acl_role_label *r;
54807 + struct role_allowed_ip *ipp;
54808 + struct role_transition *trans;
54809 + unsigned int i;
54810 + int found = 0;
54811 + u32 curr_ip = current->signal->curr_ip;
54812 +
54813 + current->signal->saved_ip = curr_ip;
54814 +
54815 + /* check transition table */
54816 +
54817 + for (trans = current->role->transitions; trans; trans = trans->next) {
54818 + if (!strcmp(rolename, trans->rolename)) {
54819 + found = 1;
54820 + break;
54821 + }
54822 + }
54823 +
54824 + if (!found)
54825 + return 0;
54826 +
54827 + /* handle special roles that do not require authentication
54828 + and check ip */
54829 +
54830 + FOR_EACH_ROLE_START(r)
54831 + if (!strcmp(rolename, r->rolename) &&
54832 + (r->roletype & GR_ROLE_SPECIAL)) {
54833 + found = 0;
54834 + if (r->allowed_ips != NULL) {
54835 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54836 + if ((ntohl(curr_ip) & ipp->netmask) ==
54837 + (ntohl(ipp->addr) & ipp->netmask))
54838 + found = 1;
54839 + }
54840 + } else
54841 + found = 2;
54842 + if (!found)
54843 + return 0;
54844 +
54845 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54846 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54847 + *salt = NULL;
54848 + *sum = NULL;
54849 + return 1;
54850 + }
54851 + }
54852 + FOR_EACH_ROLE_END(r)
54853 +
54854 + for (i = 0; i < num_sprole_pws; i++) {
54855 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54856 + *salt = acl_special_roles[i]->salt;
54857 + *sum = acl_special_roles[i]->sum;
54858 + return 1;
54859 + }
54860 + }
54861 +
54862 + return 0;
54863 +}
54864 +
54865 +static void
54866 +assign_special_role(char *rolename)
54867 +{
54868 + struct acl_object_label *obj;
54869 + struct acl_role_label *r;
54870 + struct acl_role_label *assigned = NULL;
54871 + struct task_struct *tsk;
54872 + struct file *filp;
54873 +
54874 + FOR_EACH_ROLE_START(r)
54875 + if (!strcmp(rolename, r->rolename) &&
54876 + (r->roletype & GR_ROLE_SPECIAL)) {
54877 + assigned = r;
54878 + break;
54879 + }
54880 + FOR_EACH_ROLE_END(r)
54881 +
54882 + if (!assigned)
54883 + return;
54884 +
54885 + read_lock(&tasklist_lock);
54886 + read_lock(&grsec_exec_file_lock);
54887 +
54888 + tsk = current->real_parent;
54889 + if (tsk == NULL)
54890 + goto out_unlock;
54891 +
54892 + filp = tsk->exec_file;
54893 + if (filp == NULL)
54894 + goto out_unlock;
54895 +
54896 + tsk->is_writable = 0;
54897 +
54898 + tsk->acl_sp_role = 1;
54899 + tsk->acl_role_id = ++acl_sp_role_value;
54900 + tsk->role = assigned;
54901 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54902 +
54903 + /* ignore additional mmap checks for processes that are writable
54904 + by the default ACL */
54905 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54906 + if (unlikely(obj->mode & GR_WRITE))
54907 + tsk->is_writable = 1;
54908 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54909 + if (unlikely(obj->mode & GR_WRITE))
54910 + tsk->is_writable = 1;
54911 +
54912 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54913 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54914 +#endif
54915 +
54916 +out_unlock:
54917 + read_unlock(&grsec_exec_file_lock);
54918 + read_unlock(&tasklist_lock);
54919 + return;
54920 +}
54921 +
54922 +int gr_check_secure_terminal(struct task_struct *task)
54923 +{
54924 + struct task_struct *p, *p2, *p3;
54925 + struct files_struct *files;
54926 + struct fdtable *fdt;
54927 + struct file *our_file = NULL, *file;
54928 + int i;
54929 +
54930 + if (task->signal->tty == NULL)
54931 + return 1;
54932 +
54933 + files = get_files_struct(task);
54934 + if (files != NULL) {
54935 + rcu_read_lock();
54936 + fdt = files_fdtable(files);
54937 + for (i=0; i < fdt->max_fds; i++) {
54938 + file = fcheck_files(files, i);
54939 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54940 + get_file(file);
54941 + our_file = file;
54942 + }
54943 + }
54944 + rcu_read_unlock();
54945 + put_files_struct(files);
54946 + }
54947 +
54948 + if (our_file == NULL)
54949 + return 1;
54950 +
54951 + read_lock(&tasklist_lock);
54952 + do_each_thread(p2, p) {
54953 + files = get_files_struct(p);
54954 + if (files == NULL ||
54955 + (p->signal && p->signal->tty == task->signal->tty)) {
54956 + if (files != NULL)
54957 + put_files_struct(files);
54958 + continue;
54959 + }
54960 + rcu_read_lock();
54961 + fdt = files_fdtable(files);
54962 + for (i=0; i < fdt->max_fds; i++) {
54963 + file = fcheck_files(files, i);
54964 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54965 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54966 + p3 = task;
54967 + while (p3->pid > 0) {
54968 + if (p3 == p)
54969 + break;
54970 + p3 = p3->real_parent;
54971 + }
54972 + if (p3 == p)
54973 + break;
54974 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54975 + gr_handle_alertkill(p);
54976 + rcu_read_unlock();
54977 + put_files_struct(files);
54978 + read_unlock(&tasklist_lock);
54979 + fput(our_file);
54980 + return 0;
54981 + }
54982 + }
54983 + rcu_read_unlock();
54984 + put_files_struct(files);
54985 + } while_each_thread(p2, p);
54986 + read_unlock(&tasklist_lock);
54987 +
54988 + fput(our_file);
54989 + return 1;
54990 +}
54991 +
54992 +static int gr_rbac_disable(void *unused)
54993 +{
54994 + pax_open_kernel();
54995 + gr_status &= ~GR_READY;
54996 + pax_close_kernel();
54997 +
54998 + return 0;
54999 +}
55000 +
55001 +ssize_t
55002 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55003 +{
55004 + struct gr_arg_wrapper uwrap;
55005 + unsigned char *sprole_salt = NULL;
55006 + unsigned char *sprole_sum = NULL;
55007 + int error = sizeof (struct gr_arg_wrapper);
55008 + int error2 = 0;
55009 +
55010 + mutex_lock(&gr_dev_mutex);
55011 +
55012 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55013 + error = -EPERM;
55014 + goto out;
55015 + }
55016 +
55017 + if (count != sizeof (struct gr_arg_wrapper)) {
55018 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55019 + error = -EINVAL;
55020 + goto out;
55021 + }
55022 +
55023 +
55024 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55025 + gr_auth_expires = 0;
55026 + gr_auth_attempts = 0;
55027 + }
55028 +
55029 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55030 + error = -EFAULT;
55031 + goto out;
55032 + }
55033 +
55034 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55035 + error = -EINVAL;
55036 + goto out;
55037 + }
55038 +
55039 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55040 + error = -EFAULT;
55041 + goto out;
55042 + }
55043 +
55044 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55045 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55046 + time_after(gr_auth_expires, get_seconds())) {
55047 + error = -EBUSY;
55048 + goto out;
55049 + }
55050 +
55051 + /* if non-root trying to do anything other than use a special role,
55052 + do not attempt authentication, do not count towards authentication
55053 + locking
55054 + */
55055 +
55056 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55057 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55058 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55059 + error = -EPERM;
55060 + goto out;
55061 + }
55062 +
55063 + /* ensure pw and special role name are null terminated */
55064 +
55065 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55066 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55067 +
55068 + /* Okay.
55069 + * We have our enough of the argument structure..(we have yet
55070 + * to copy_from_user the tables themselves) . Copy the tables
55071 + * only if we need them, i.e. for loading operations. */
55072 +
55073 + switch (gr_usermode->mode) {
55074 + case GR_STATUS:
55075 + if (gr_status & GR_READY) {
55076 + error = 1;
55077 + if (!gr_check_secure_terminal(current))
55078 + error = 3;
55079 + } else
55080 + error = 2;
55081 + goto out;
55082 + case GR_SHUTDOWN:
55083 + if ((gr_status & GR_READY)
55084 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55085 + stop_machine(gr_rbac_disable, NULL, NULL);
55086 + free_variables();
55087 + memset(gr_usermode, 0, sizeof (struct gr_arg));
55088 + memset(gr_system_salt, 0, GR_SALT_LEN);
55089 + memset(gr_system_sum, 0, GR_SHA_LEN);
55090 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55091 + } else if (gr_status & GR_READY) {
55092 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55093 + error = -EPERM;
55094 + } else {
55095 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55096 + error = -EAGAIN;
55097 + }
55098 + break;
55099 + case GR_ENABLE:
55100 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55101 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55102 + else {
55103 + if (gr_status & GR_READY)
55104 + error = -EAGAIN;
55105 + else
55106 + error = error2;
55107 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55108 + }
55109 + break;
55110 + case GR_RELOAD:
55111 + if (!(gr_status & GR_READY)) {
55112 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55113 + error = -EAGAIN;
55114 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55115 + stop_machine(gr_rbac_disable, NULL, NULL);
55116 + free_variables();
55117 + error2 = gracl_init(gr_usermode);
55118 + if (!error2)
55119 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55120 + else {
55121 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55122 + error = error2;
55123 + }
55124 + } else {
55125 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55126 + error = -EPERM;
55127 + }
55128 + break;
55129 + case GR_SEGVMOD:
55130 + if (unlikely(!(gr_status & GR_READY))) {
55131 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55132 + error = -EAGAIN;
55133 + break;
55134 + }
55135 +
55136 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55137 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55138 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55139 + struct acl_subject_label *segvacl;
55140 + segvacl =
55141 + lookup_acl_subj_label(gr_usermode->segv_inode,
55142 + gr_usermode->segv_device,
55143 + current->role);
55144 + if (segvacl) {
55145 + segvacl->crashes = 0;
55146 + segvacl->expires = 0;
55147 + }
55148 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55149 + gr_remove_uid(gr_usermode->segv_uid);
55150 + }
55151 + } else {
55152 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55153 + error = -EPERM;
55154 + }
55155 + break;
55156 + case GR_SPROLE:
55157 + case GR_SPROLEPAM:
55158 + if (unlikely(!(gr_status & GR_READY))) {
55159 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55160 + error = -EAGAIN;
55161 + break;
55162 + }
55163 +
55164 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55165 + current->role->expires = 0;
55166 + current->role->auth_attempts = 0;
55167 + }
55168 +
55169 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55170 + time_after(current->role->expires, get_seconds())) {
55171 + error = -EBUSY;
55172 + goto out;
55173 + }
55174 +
55175 + if (lookup_special_role_auth
55176 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55177 + && ((!sprole_salt && !sprole_sum)
55178 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55179 + char *p = "";
55180 + assign_special_role(gr_usermode->sp_role);
55181 + read_lock(&tasklist_lock);
55182 + if (current->real_parent)
55183 + p = current->real_parent->role->rolename;
55184 + read_unlock(&tasklist_lock);
55185 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55186 + p, acl_sp_role_value);
55187 + } else {
55188 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55189 + error = -EPERM;
55190 + if(!(current->role->auth_attempts++))
55191 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55192 +
55193 + goto out;
55194 + }
55195 + break;
55196 + case GR_UNSPROLE:
55197 + if (unlikely(!(gr_status & GR_READY))) {
55198 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55199 + error = -EAGAIN;
55200 + break;
55201 + }
55202 +
55203 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55204 + char *p = "";
55205 + int i = 0;
55206 +
55207 + read_lock(&tasklist_lock);
55208 + if (current->real_parent) {
55209 + p = current->real_parent->role->rolename;
55210 + i = current->real_parent->acl_role_id;
55211 + }
55212 + read_unlock(&tasklist_lock);
55213 +
55214 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55215 + gr_set_acls(1);
55216 + } else {
55217 + error = -EPERM;
55218 + goto out;
55219 + }
55220 + break;
55221 + default:
55222 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55223 + error = -EINVAL;
55224 + break;
55225 + }
55226 +
55227 + if (error != -EPERM)
55228 + goto out;
55229 +
55230 + if(!(gr_auth_attempts++))
55231 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55232 +
55233 + out:
55234 + mutex_unlock(&gr_dev_mutex);
55235 + return error;
55236 +}
55237 +
55238 +/* must be called with
55239 + rcu_read_lock();
55240 + read_lock(&tasklist_lock);
55241 + read_lock(&grsec_exec_file_lock);
55242 +*/
55243 +int gr_apply_subject_to_task(struct task_struct *task)
55244 +{
55245 + struct acl_object_label *obj;
55246 + char *tmpname;
55247 + struct acl_subject_label *tmpsubj;
55248 + struct file *filp;
55249 + struct name_entry *nmatch;
55250 +
55251 + filp = task->exec_file;
55252 + if (filp == NULL)
55253 + return 0;
55254 +
55255 + /* the following is to apply the correct subject
55256 + on binaries running when the RBAC system
55257 + is enabled, when the binaries have been
55258 + replaced or deleted since their execution
55259 + -----
55260 + when the RBAC system starts, the inode/dev
55261 + from exec_file will be one the RBAC system
55262 + is unaware of. It only knows the inode/dev
55263 + of the present file on disk, or the absence
55264 + of it.
55265 + */
55266 + preempt_disable();
55267 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55268 +
55269 + nmatch = lookup_name_entry(tmpname);
55270 + preempt_enable();
55271 + tmpsubj = NULL;
55272 + if (nmatch) {
55273 + if (nmatch->deleted)
55274 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55275 + else
55276 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55277 + if (tmpsubj != NULL)
55278 + task->acl = tmpsubj;
55279 + }
55280 + if (tmpsubj == NULL)
55281 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55282 + task->role);
55283 + if (task->acl) {
55284 + task->is_writable = 0;
55285 + /* ignore additional mmap checks for processes that are writable
55286 + by the default ACL */
55287 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55288 + if (unlikely(obj->mode & GR_WRITE))
55289 + task->is_writable = 1;
55290 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55291 + if (unlikely(obj->mode & GR_WRITE))
55292 + task->is_writable = 1;
55293 +
55294 + gr_set_proc_res(task);
55295 +
55296 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55297 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55298 +#endif
55299 + } else {
55300 + return 1;
55301 + }
55302 +
55303 + return 0;
55304 +}
55305 +
55306 +int
55307 +gr_set_acls(const int type)
55308 +{
55309 + struct task_struct *task, *task2;
55310 + struct acl_role_label *role = current->role;
55311 + __u16 acl_role_id = current->acl_role_id;
55312 + const struct cred *cred;
55313 + int ret;
55314 +
55315 + rcu_read_lock();
55316 + read_lock(&tasklist_lock);
55317 + read_lock(&grsec_exec_file_lock);
55318 + do_each_thread(task2, task) {
55319 + /* check to see if we're called from the exit handler,
55320 + if so, only replace ACLs that have inherited the admin
55321 + ACL */
55322 +
55323 + if (type && (task->role != role ||
55324 + task->acl_role_id != acl_role_id))
55325 + continue;
55326 +
55327 + task->acl_role_id = 0;
55328 + task->acl_sp_role = 0;
55329 +
55330 + if (task->exec_file) {
55331 + cred = __task_cred(task);
55332 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55333 + ret = gr_apply_subject_to_task(task);
55334 + if (ret) {
55335 + read_unlock(&grsec_exec_file_lock);
55336 + read_unlock(&tasklist_lock);
55337 + rcu_read_unlock();
55338 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55339 + return ret;
55340 + }
55341 + } else {
55342 + // it's a kernel process
55343 + task->role = kernel_role;
55344 + task->acl = kernel_role->root_label;
55345 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55346 + task->acl->mode &= ~GR_PROCFIND;
55347 +#endif
55348 + }
55349 + } while_each_thread(task2, task);
55350 + read_unlock(&grsec_exec_file_lock);
55351 + read_unlock(&tasklist_lock);
55352 + rcu_read_unlock();
55353 +
55354 + return 0;
55355 +}
55356 +
55357 +void
55358 +gr_learn_resource(const struct task_struct *task,
55359 + const int res, const unsigned long wanted, const int gt)
55360 +{
55361 + struct acl_subject_label *acl;
55362 + const struct cred *cred;
55363 +
55364 + if (unlikely((gr_status & GR_READY) &&
55365 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55366 + goto skip_reslog;
55367 +
55368 +#ifdef CONFIG_GRKERNSEC_RESLOG
55369 + gr_log_resource(task, res, wanted, gt);
55370 +#endif
55371 + skip_reslog:
55372 +
55373 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55374 + return;
55375 +
55376 + acl = task->acl;
55377 +
55378 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55379 + !(acl->resmask & (1 << (unsigned short) res))))
55380 + return;
55381 +
55382 + if (wanted >= acl->res[res].rlim_cur) {
55383 + unsigned long res_add;
55384 +
55385 + res_add = wanted;
55386 + switch (res) {
55387 + case RLIMIT_CPU:
55388 + res_add += GR_RLIM_CPU_BUMP;
55389 + break;
55390 + case RLIMIT_FSIZE:
55391 + res_add += GR_RLIM_FSIZE_BUMP;
55392 + break;
55393 + case RLIMIT_DATA:
55394 + res_add += GR_RLIM_DATA_BUMP;
55395 + break;
55396 + case RLIMIT_STACK:
55397 + res_add += GR_RLIM_STACK_BUMP;
55398 + break;
55399 + case RLIMIT_CORE:
55400 + res_add += GR_RLIM_CORE_BUMP;
55401 + break;
55402 + case RLIMIT_RSS:
55403 + res_add += GR_RLIM_RSS_BUMP;
55404 + break;
55405 + case RLIMIT_NPROC:
55406 + res_add += GR_RLIM_NPROC_BUMP;
55407 + break;
55408 + case RLIMIT_NOFILE:
55409 + res_add += GR_RLIM_NOFILE_BUMP;
55410 + break;
55411 + case RLIMIT_MEMLOCK:
55412 + res_add += GR_RLIM_MEMLOCK_BUMP;
55413 + break;
55414 + case RLIMIT_AS:
55415 + res_add += GR_RLIM_AS_BUMP;
55416 + break;
55417 + case RLIMIT_LOCKS:
55418 + res_add += GR_RLIM_LOCKS_BUMP;
55419 + break;
55420 + case RLIMIT_SIGPENDING:
55421 + res_add += GR_RLIM_SIGPENDING_BUMP;
55422 + break;
55423 + case RLIMIT_MSGQUEUE:
55424 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55425 + break;
55426 + case RLIMIT_NICE:
55427 + res_add += GR_RLIM_NICE_BUMP;
55428 + break;
55429 + case RLIMIT_RTPRIO:
55430 + res_add += GR_RLIM_RTPRIO_BUMP;
55431 + break;
55432 + case RLIMIT_RTTIME:
55433 + res_add += GR_RLIM_RTTIME_BUMP;
55434 + break;
55435 + }
55436 +
55437 + acl->res[res].rlim_cur = res_add;
55438 +
55439 + if (wanted > acl->res[res].rlim_max)
55440 + acl->res[res].rlim_max = res_add;
55441 +
55442 + /* only log the subject filename, since resource logging is supported for
55443 + single-subject learning only */
55444 + rcu_read_lock();
55445 + cred = __task_cred(task);
55446 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55447 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55448 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55449 + "", (unsigned long) res, &task->signal->saved_ip);
55450 + rcu_read_unlock();
55451 + }
55452 +
55453 + return;
55454 +}
55455 +
55456 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55457 +void
55458 +pax_set_initial_flags(struct linux_binprm *bprm)
55459 +{
55460 + struct task_struct *task = current;
55461 + struct acl_subject_label *proc;
55462 + unsigned long flags;
55463 +
55464 + if (unlikely(!(gr_status & GR_READY)))
55465 + return;
55466 +
55467 + flags = pax_get_flags(task);
55468 +
55469 + proc = task->acl;
55470 +
55471 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55472 + flags &= ~MF_PAX_PAGEEXEC;
55473 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55474 + flags &= ~MF_PAX_SEGMEXEC;
55475 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55476 + flags &= ~MF_PAX_RANDMMAP;
55477 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55478 + flags &= ~MF_PAX_EMUTRAMP;
55479 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55480 + flags &= ~MF_PAX_MPROTECT;
55481 +
55482 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55483 + flags |= MF_PAX_PAGEEXEC;
55484 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55485 + flags |= MF_PAX_SEGMEXEC;
55486 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55487 + flags |= MF_PAX_RANDMMAP;
55488 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55489 + flags |= MF_PAX_EMUTRAMP;
55490 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55491 + flags |= MF_PAX_MPROTECT;
55492 +
55493 + pax_set_flags(task, flags);
55494 +
55495 + return;
55496 +}
55497 +#endif
55498 +
55499 +int
55500 +gr_handle_proc_ptrace(struct task_struct *task)
55501 +{
55502 + struct file *filp;
55503 + struct task_struct *tmp = task;
55504 + struct task_struct *curtemp = current;
55505 + __u32 retmode;
55506 +
55507 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55508 + if (unlikely(!(gr_status & GR_READY)))
55509 + return 0;
55510 +#endif
55511 +
55512 + read_lock(&tasklist_lock);
55513 + read_lock(&grsec_exec_file_lock);
55514 + filp = task->exec_file;
55515 +
55516 + while (tmp->pid > 0) {
55517 + if (tmp == curtemp)
55518 + break;
55519 + tmp = tmp->real_parent;
55520 + }
55521 +
55522 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55523 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55524 + read_unlock(&grsec_exec_file_lock);
55525 + read_unlock(&tasklist_lock);
55526 + return 1;
55527 + }
55528 +
55529 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55530 + if (!(gr_status & GR_READY)) {
55531 + read_unlock(&grsec_exec_file_lock);
55532 + read_unlock(&tasklist_lock);
55533 + return 0;
55534 + }
55535 +#endif
55536 +
55537 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55538 + read_unlock(&grsec_exec_file_lock);
55539 + read_unlock(&tasklist_lock);
55540 +
55541 + if (retmode & GR_NOPTRACE)
55542 + return 1;
55543 +
55544 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55545 + && (current->acl != task->acl || (current->acl != current->role->root_label
55546 + && current->pid != task->pid)))
55547 + return 1;
55548 +
55549 + return 0;
55550 +}
55551 +
55552 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55553 +{
55554 + if (unlikely(!(gr_status & GR_READY)))
55555 + return;
55556 +
55557 + if (!(current->role->roletype & GR_ROLE_GOD))
55558 + return;
55559 +
55560 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55561 + p->role->rolename, gr_task_roletype_to_char(p),
55562 + p->acl->filename);
55563 +}
55564 +
55565 +int
55566 +gr_handle_ptrace(struct task_struct *task, const long request)
55567 +{
55568 + struct task_struct *tmp = task;
55569 + struct task_struct *curtemp = current;
55570 + __u32 retmode;
55571 +
55572 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55573 + if (unlikely(!(gr_status & GR_READY)))
55574 + return 0;
55575 +#endif
55576 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55577 + read_lock(&tasklist_lock);
55578 + while (tmp->pid > 0) {
55579 + if (tmp == curtemp)
55580 + break;
55581 + tmp = tmp->real_parent;
55582 + }
55583 +
55584 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55585 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55586 + read_unlock(&tasklist_lock);
55587 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55588 + return 1;
55589 + }
55590 + read_unlock(&tasklist_lock);
55591 + }
55592 +
55593 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55594 + if (!(gr_status & GR_READY))
55595 + return 0;
55596 +#endif
55597 +
55598 + read_lock(&grsec_exec_file_lock);
55599 + if (unlikely(!task->exec_file)) {
55600 + read_unlock(&grsec_exec_file_lock);
55601 + return 0;
55602 + }
55603 +
55604 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55605 + read_unlock(&grsec_exec_file_lock);
55606 +
55607 + if (retmode & GR_NOPTRACE) {
55608 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55609 + return 1;
55610 + }
55611 +
55612 + if (retmode & GR_PTRACERD) {
55613 + switch (request) {
55614 + case PTRACE_SEIZE:
55615 + case PTRACE_POKETEXT:
55616 + case PTRACE_POKEDATA:
55617 + case PTRACE_POKEUSR:
55618 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55619 + case PTRACE_SETREGS:
55620 + case PTRACE_SETFPREGS:
55621 +#endif
55622 +#ifdef CONFIG_X86
55623 + case PTRACE_SETFPXREGS:
55624 +#endif
55625 +#ifdef CONFIG_ALTIVEC
55626 + case PTRACE_SETVRREGS:
55627 +#endif
55628 + return 1;
55629 + default:
55630 + return 0;
55631 + }
55632 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55633 + !(current->role->roletype & GR_ROLE_GOD) &&
55634 + (current->acl != task->acl)) {
55635 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55636 + return 1;
55637 + }
55638 +
55639 + return 0;
55640 +}
55641 +
55642 +static int is_writable_mmap(const struct file *filp)
55643 +{
55644 + struct task_struct *task = current;
55645 + struct acl_object_label *obj, *obj2;
55646 +
55647 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55648 + !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))) {
55649 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55650 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55651 + task->role->root_label);
55652 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55653 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55654 + return 1;
55655 + }
55656 + }
55657 + return 0;
55658 +}
55659 +
55660 +int
55661 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55662 +{
55663 + __u32 mode;
55664 +
55665 + if (unlikely(!file || !(prot & PROT_EXEC)))
55666 + return 1;
55667 +
55668 + if (is_writable_mmap(file))
55669 + return 0;
55670 +
55671 + mode =
55672 + gr_search_file(file->f_path.dentry,
55673 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55674 + file->f_path.mnt);
55675 +
55676 + if (!gr_tpe_allow(file))
55677 + return 0;
55678 +
55679 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55680 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55681 + return 0;
55682 + } else if (unlikely(!(mode & GR_EXEC))) {
55683 + return 0;
55684 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55685 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55686 + return 1;
55687 + }
55688 +
55689 + return 1;
55690 +}
55691 +
55692 +int
55693 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55694 +{
55695 + __u32 mode;
55696 +
55697 + if (unlikely(!file || !(prot & PROT_EXEC)))
55698 + return 1;
55699 +
55700 + if (is_writable_mmap(file))
55701 + return 0;
55702 +
55703 + mode =
55704 + gr_search_file(file->f_path.dentry,
55705 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55706 + file->f_path.mnt);
55707 +
55708 + if (!gr_tpe_allow(file))
55709 + return 0;
55710 +
55711 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55712 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55713 + return 0;
55714 + } else if (unlikely(!(mode & GR_EXEC))) {
55715 + return 0;
55716 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55717 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55718 + return 1;
55719 + }
55720 +
55721 + return 1;
55722 +}
55723 +
55724 +void
55725 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55726 +{
55727 + unsigned long runtime;
55728 + unsigned long cputime;
55729 + unsigned int wday, cday;
55730 + __u8 whr, chr;
55731 + __u8 wmin, cmin;
55732 + __u8 wsec, csec;
55733 + struct timespec timeval;
55734 +
55735 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55736 + !(task->acl->mode & GR_PROCACCT)))
55737 + return;
55738 +
55739 + do_posix_clock_monotonic_gettime(&timeval);
55740 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55741 + wday = runtime / (3600 * 24);
55742 + runtime -= wday * (3600 * 24);
55743 + whr = runtime / 3600;
55744 + runtime -= whr * 3600;
55745 + wmin = runtime / 60;
55746 + runtime -= wmin * 60;
55747 + wsec = runtime;
55748 +
55749 + cputime = (task->utime + task->stime) / HZ;
55750 + cday = cputime / (3600 * 24);
55751 + cputime -= cday * (3600 * 24);
55752 + chr = cputime / 3600;
55753 + cputime -= chr * 3600;
55754 + cmin = cputime / 60;
55755 + cputime -= cmin * 60;
55756 + csec = cputime;
55757 +
55758 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55759 +
55760 + return;
55761 +}
55762 +
55763 +void gr_set_kernel_label(struct task_struct *task)
55764 +{
55765 + if (gr_status & GR_READY) {
55766 + task->role = kernel_role;
55767 + task->acl = kernel_role->root_label;
55768 + }
55769 + return;
55770 +}
55771 +
55772 +#ifdef CONFIG_TASKSTATS
55773 +int gr_is_taskstats_denied(int pid)
55774 +{
55775 + struct task_struct *task;
55776 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55777 + const struct cred *cred;
55778 +#endif
55779 + int ret = 0;
55780 +
55781 + /* restrict taskstats viewing to un-chrooted root users
55782 + who have the 'view' subject flag if the RBAC system is enabled
55783 + */
55784 +
55785 + rcu_read_lock();
55786 + read_lock(&tasklist_lock);
55787 + task = find_task_by_vpid(pid);
55788 + if (task) {
55789 +#ifdef CONFIG_GRKERNSEC_CHROOT
55790 + if (proc_is_chrooted(task))
55791 + ret = -EACCES;
55792 +#endif
55793 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55794 + cred = __task_cred(task);
55795 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55796 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55797 + ret = -EACCES;
55798 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55799 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55800 + ret = -EACCES;
55801 +#endif
55802 +#endif
55803 + if (gr_status & GR_READY) {
55804 + if (!(task->acl->mode & GR_VIEW))
55805 + ret = -EACCES;
55806 + }
55807 + } else
55808 + ret = -ENOENT;
55809 +
55810 + read_unlock(&tasklist_lock);
55811 + rcu_read_unlock();
55812 +
55813 + return ret;
55814 +}
55815 +#endif
55816 +
55817 +/* AUXV entries are filled via a descendant of search_binary_handler
55818 + after we've already applied the subject for the target
55819 +*/
55820 +int gr_acl_enable_at_secure(void)
55821 +{
55822 + if (unlikely(!(gr_status & GR_READY)))
55823 + return 0;
55824 +
55825 + if (current->acl->mode & GR_ATSECURE)
55826 + return 1;
55827 +
55828 + return 0;
55829 +}
55830 +
55831 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55832 +{
55833 + struct task_struct *task = current;
55834 + struct dentry *dentry = file->f_path.dentry;
55835 + struct vfsmount *mnt = file->f_path.mnt;
55836 + struct acl_object_label *obj, *tmp;
55837 + struct acl_subject_label *subj;
55838 + unsigned int bufsize;
55839 + int is_not_root;
55840 + char *path;
55841 + dev_t dev = __get_dev(dentry);
55842 +
55843 + if (unlikely(!(gr_status & GR_READY)))
55844 + return 1;
55845 +
55846 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55847 + return 1;
55848 +
55849 + /* ignore Eric Biederman */
55850 + if (IS_PRIVATE(dentry->d_inode))
55851 + return 1;
55852 +
55853 + subj = task->acl;
55854 + read_lock(&gr_inode_lock);
55855 + do {
55856 + obj = lookup_acl_obj_label(ino, dev, subj);
55857 + if (obj != NULL) {
55858 + read_unlock(&gr_inode_lock);
55859 + return (obj->mode & GR_FIND) ? 1 : 0;
55860 + }
55861 + } while ((subj = subj->parent_subject));
55862 + read_unlock(&gr_inode_lock);
55863 +
55864 + /* this is purely an optimization since we're looking for an object
55865 + for the directory we're doing a readdir on
55866 + if it's possible for any globbed object to match the entry we're
55867 + filling into the directory, then the object we find here will be
55868 + an anchor point with attached globbed objects
55869 + */
55870 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55871 + if (obj->globbed == NULL)
55872 + return (obj->mode & GR_FIND) ? 1 : 0;
55873 +
55874 + is_not_root = ((obj->filename[0] == '/') &&
55875 + (obj->filename[1] == '\0')) ? 0 : 1;
55876 + bufsize = PAGE_SIZE - namelen - is_not_root;
55877 +
55878 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55879 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55880 + return 1;
55881 +
55882 + preempt_disable();
55883 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55884 + bufsize);
55885 +
55886 + bufsize = strlen(path);
55887 +
55888 + /* if base is "/", don't append an additional slash */
55889 + if (is_not_root)
55890 + *(path + bufsize) = '/';
55891 + memcpy(path + bufsize + is_not_root, name, namelen);
55892 + *(path + bufsize + namelen + is_not_root) = '\0';
55893 +
55894 + tmp = obj->globbed;
55895 + while (tmp) {
55896 + if (!glob_match(tmp->filename, path)) {
55897 + preempt_enable();
55898 + return (tmp->mode & GR_FIND) ? 1 : 0;
55899 + }
55900 + tmp = tmp->next;
55901 + }
55902 + preempt_enable();
55903 + return (obj->mode & GR_FIND) ? 1 : 0;
55904 +}
55905 +
55906 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55907 +EXPORT_SYMBOL(gr_acl_is_enabled);
55908 +#endif
55909 +EXPORT_SYMBOL(gr_learn_resource);
55910 +EXPORT_SYMBOL(gr_set_kernel_label);
55911 +#ifdef CONFIG_SECURITY
55912 +EXPORT_SYMBOL(gr_check_user_change);
55913 +EXPORT_SYMBOL(gr_check_group_change);
55914 +#endif
55915 +
55916 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55917 new file mode 100644
55918 index 0000000..34fefda
55919 --- /dev/null
55920 +++ b/grsecurity/gracl_alloc.c
55921 @@ -0,0 +1,105 @@
55922 +#include <linux/kernel.h>
55923 +#include <linux/mm.h>
55924 +#include <linux/slab.h>
55925 +#include <linux/vmalloc.h>
55926 +#include <linux/gracl.h>
55927 +#include <linux/grsecurity.h>
55928 +
55929 +static unsigned long alloc_stack_next = 1;
55930 +static unsigned long alloc_stack_size = 1;
55931 +static void **alloc_stack;
55932 +
55933 +static __inline__ int
55934 +alloc_pop(void)
55935 +{
55936 + if (alloc_stack_next == 1)
55937 + return 0;
55938 +
55939 + kfree(alloc_stack[alloc_stack_next - 2]);
55940 +
55941 + alloc_stack_next--;
55942 +
55943 + return 1;
55944 +}
55945 +
55946 +static __inline__ int
55947 +alloc_push(void *buf)
55948 +{
55949 + if (alloc_stack_next >= alloc_stack_size)
55950 + return 1;
55951 +
55952 + alloc_stack[alloc_stack_next - 1] = buf;
55953 +
55954 + alloc_stack_next++;
55955 +
55956 + return 0;
55957 +}
55958 +
55959 +void *
55960 +acl_alloc(unsigned long len)
55961 +{
55962 + void *ret = NULL;
55963 +
55964 + if (!len || len > PAGE_SIZE)
55965 + goto out;
55966 +
55967 + ret = kmalloc(len, GFP_KERNEL);
55968 +
55969 + if (ret) {
55970 + if (alloc_push(ret)) {
55971 + kfree(ret);
55972 + ret = NULL;
55973 + }
55974 + }
55975 +
55976 +out:
55977 + return ret;
55978 +}
55979 +
55980 +void *
55981 +acl_alloc_num(unsigned long num, unsigned long len)
55982 +{
55983 + if (!len || (num > (PAGE_SIZE / len)))
55984 + return NULL;
55985 +
55986 + return acl_alloc(num * len);
55987 +}
55988 +
55989 +void
55990 +acl_free_all(void)
55991 +{
55992 + if (gr_acl_is_enabled() || !alloc_stack)
55993 + return;
55994 +
55995 + while (alloc_pop()) ;
55996 +
55997 + if (alloc_stack) {
55998 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55999 + kfree(alloc_stack);
56000 + else
56001 + vfree(alloc_stack);
56002 + }
56003 +
56004 + alloc_stack = NULL;
56005 + alloc_stack_size = 1;
56006 + alloc_stack_next = 1;
56007 +
56008 + return;
56009 +}
56010 +
56011 +int
56012 +acl_alloc_stack_init(unsigned long size)
56013 +{
56014 + if ((size * sizeof (void *)) <= PAGE_SIZE)
56015 + alloc_stack =
56016 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56017 + else
56018 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
56019 +
56020 + alloc_stack_size = size;
56021 +
56022 + if (!alloc_stack)
56023 + return 0;
56024 + else
56025 + return 1;
56026 +}
56027 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56028 new file mode 100644
56029 index 0000000..6d21049
56030 --- /dev/null
56031 +++ b/grsecurity/gracl_cap.c
56032 @@ -0,0 +1,110 @@
56033 +#include <linux/kernel.h>
56034 +#include <linux/module.h>
56035 +#include <linux/sched.h>
56036 +#include <linux/gracl.h>
56037 +#include <linux/grsecurity.h>
56038 +#include <linux/grinternal.h>
56039 +
56040 +extern const char *captab_log[];
56041 +extern int captab_log_entries;
56042 +
56043 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56044 +{
56045 + struct acl_subject_label *curracl;
56046 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56047 + kernel_cap_t cap_audit = __cap_empty_set;
56048 +
56049 + if (!gr_acl_is_enabled())
56050 + return 1;
56051 +
56052 + curracl = task->acl;
56053 +
56054 + cap_drop = curracl->cap_lower;
56055 + cap_mask = curracl->cap_mask;
56056 + cap_audit = curracl->cap_invert_audit;
56057 +
56058 + while ((curracl = curracl->parent_subject)) {
56059 + /* if the cap isn't specified in the current computed mask but is specified in the
56060 + current level subject, and is lowered in the current level subject, then add
56061 + it to the set of dropped capabilities
56062 + otherwise, add the current level subject's mask to the current computed mask
56063 + */
56064 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56065 + cap_raise(cap_mask, cap);
56066 + if (cap_raised(curracl->cap_lower, cap))
56067 + cap_raise(cap_drop, cap);
56068 + if (cap_raised(curracl->cap_invert_audit, cap))
56069 + cap_raise(cap_audit, cap);
56070 + }
56071 + }
56072 +
56073 + if (!cap_raised(cap_drop, cap)) {
56074 + if (cap_raised(cap_audit, cap))
56075 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56076 + return 1;
56077 + }
56078 +
56079 + curracl = task->acl;
56080 +
56081 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56082 + && cap_raised(cred->cap_effective, cap)) {
56083 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56084 + task->role->roletype, cred->uid,
56085 + cred->gid, task->exec_file ?
56086 + gr_to_filename(task->exec_file->f_path.dentry,
56087 + task->exec_file->f_path.mnt) : curracl->filename,
56088 + curracl->filename, 0UL,
56089 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56090 + return 1;
56091 + }
56092 +
56093 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56094 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56095 +
56096 + return 0;
56097 +}
56098 +
56099 +int
56100 +gr_acl_is_capable(const int cap)
56101 +{
56102 + return gr_task_acl_is_capable(current, current_cred(), cap);
56103 +}
56104 +
56105 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56106 +{
56107 + struct acl_subject_label *curracl;
56108 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56109 +
56110 + if (!gr_acl_is_enabled())
56111 + return 1;
56112 +
56113 + curracl = task->acl;
56114 +
56115 + cap_drop = curracl->cap_lower;
56116 + cap_mask = curracl->cap_mask;
56117 +
56118 + while ((curracl = curracl->parent_subject)) {
56119 + /* if the cap isn't specified in the current computed mask but is specified in the
56120 + current level subject, and is lowered in the current level subject, then add
56121 + it to the set of dropped capabilities
56122 + otherwise, add the current level subject's mask to the current computed mask
56123 + */
56124 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56125 + cap_raise(cap_mask, cap);
56126 + if (cap_raised(curracl->cap_lower, cap))
56127 + cap_raise(cap_drop, cap);
56128 + }
56129 + }
56130 +
56131 + if (!cap_raised(cap_drop, cap))
56132 + return 1;
56133 +
56134 + return 0;
56135 +}
56136 +
56137 +int
56138 +gr_acl_is_capable_nolog(const int cap)
56139 +{
56140 + return gr_task_acl_is_capable_nolog(current, cap);
56141 +}
56142 +
56143 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56144 new file mode 100644
56145 index 0000000..d28e241
56146 --- /dev/null
56147 +++ b/grsecurity/gracl_fs.c
56148 @@ -0,0 +1,437 @@
56149 +#include <linux/kernel.h>
56150 +#include <linux/sched.h>
56151 +#include <linux/types.h>
56152 +#include <linux/fs.h>
56153 +#include <linux/file.h>
56154 +#include <linux/stat.h>
56155 +#include <linux/grsecurity.h>
56156 +#include <linux/grinternal.h>
56157 +#include <linux/gracl.h>
56158 +
56159 +umode_t
56160 +gr_acl_umask(void)
56161 +{
56162 + if (unlikely(!gr_acl_is_enabled()))
56163 + return 0;
56164 +
56165 + return current->role->umask;
56166 +}
56167 +
56168 +__u32
56169 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56170 + const struct vfsmount * mnt)
56171 +{
56172 + __u32 mode;
56173 +
56174 + if (unlikely(!dentry->d_inode))
56175 + return GR_FIND;
56176 +
56177 + mode =
56178 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56179 +
56180 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56181 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56182 + return mode;
56183 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56184 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56185 + return 0;
56186 + } else if (unlikely(!(mode & GR_FIND)))
56187 + return 0;
56188 +
56189 + return GR_FIND;
56190 +}
56191 +
56192 +__u32
56193 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56194 + int acc_mode)
56195 +{
56196 + __u32 reqmode = GR_FIND;
56197 + __u32 mode;
56198 +
56199 + if (unlikely(!dentry->d_inode))
56200 + return reqmode;
56201 +
56202 + if (acc_mode & MAY_APPEND)
56203 + reqmode |= GR_APPEND;
56204 + else if (acc_mode & MAY_WRITE)
56205 + reqmode |= GR_WRITE;
56206 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56207 + reqmode |= GR_READ;
56208 +
56209 + mode =
56210 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56211 + mnt);
56212 +
56213 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56214 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56215 + reqmode & GR_READ ? " reading" : "",
56216 + reqmode & GR_WRITE ? " writing" : reqmode &
56217 + GR_APPEND ? " appending" : "");
56218 + return reqmode;
56219 + } else
56220 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56221 + {
56222 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56223 + reqmode & GR_READ ? " reading" : "",
56224 + reqmode & GR_WRITE ? " writing" : reqmode &
56225 + GR_APPEND ? " appending" : "");
56226 + return 0;
56227 + } else if (unlikely((mode & reqmode) != reqmode))
56228 + return 0;
56229 +
56230 + return reqmode;
56231 +}
56232 +
56233 +__u32
56234 +gr_acl_handle_creat(const struct dentry * dentry,
56235 + const struct dentry * p_dentry,
56236 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56237 + const int imode)
56238 +{
56239 + __u32 reqmode = GR_WRITE | GR_CREATE;
56240 + __u32 mode;
56241 +
56242 + if (acc_mode & MAY_APPEND)
56243 + reqmode |= GR_APPEND;
56244 + // if a directory was required or the directory already exists, then
56245 + // don't count this open as a read
56246 + if ((acc_mode & MAY_READ) &&
56247 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56248 + reqmode |= GR_READ;
56249 + if ((open_flags & O_CREAT) &&
56250 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56251 + reqmode |= GR_SETID;
56252 +
56253 + mode =
56254 + gr_check_create(dentry, p_dentry, p_mnt,
56255 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56256 +
56257 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56258 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56259 + reqmode & GR_READ ? " reading" : "",
56260 + reqmode & GR_WRITE ? " writing" : reqmode &
56261 + GR_APPEND ? " appending" : "");
56262 + return reqmode;
56263 + } else
56264 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56265 + {
56266 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56267 + reqmode & GR_READ ? " reading" : "",
56268 + reqmode & GR_WRITE ? " writing" : reqmode &
56269 + GR_APPEND ? " appending" : "");
56270 + return 0;
56271 + } else if (unlikely((mode & reqmode) != reqmode))
56272 + return 0;
56273 +
56274 + return reqmode;
56275 +}
56276 +
56277 +__u32
56278 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56279 + const int fmode)
56280 +{
56281 + __u32 mode, reqmode = GR_FIND;
56282 +
56283 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56284 + reqmode |= GR_EXEC;
56285 + if (fmode & S_IWOTH)
56286 + reqmode |= GR_WRITE;
56287 + if (fmode & S_IROTH)
56288 + reqmode |= GR_READ;
56289 +
56290 + mode =
56291 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56292 + mnt);
56293 +
56294 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56295 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56296 + reqmode & GR_READ ? " reading" : "",
56297 + reqmode & GR_WRITE ? " writing" : "",
56298 + reqmode & GR_EXEC ? " executing" : "");
56299 + return reqmode;
56300 + } else
56301 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56302 + {
56303 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56304 + reqmode & GR_READ ? " reading" : "",
56305 + reqmode & GR_WRITE ? " writing" : "",
56306 + reqmode & GR_EXEC ? " executing" : "");
56307 + return 0;
56308 + } else if (unlikely((mode & reqmode) != reqmode))
56309 + return 0;
56310 +
56311 + return reqmode;
56312 +}
56313 +
56314 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56315 +{
56316 + __u32 mode;
56317 +
56318 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56319 +
56320 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56321 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56322 + return mode;
56323 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56324 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56325 + return 0;
56326 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56327 + return 0;
56328 +
56329 + return (reqmode);
56330 +}
56331 +
56332 +__u32
56333 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56334 +{
56335 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56336 +}
56337 +
56338 +__u32
56339 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56340 +{
56341 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56342 +}
56343 +
56344 +__u32
56345 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56346 +{
56347 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56348 +}
56349 +
56350 +__u32
56351 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56352 +{
56353 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56354 +}
56355 +
56356 +__u32
56357 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56358 + umode_t *modeptr)
56359 +{
56360 + umode_t mode;
56361 +
56362 + *modeptr &= ~gr_acl_umask();
56363 + mode = *modeptr;
56364 +
56365 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56366 + return 1;
56367 +
56368 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56369 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56370 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56371 + GR_CHMOD_ACL_MSG);
56372 + } else {
56373 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56374 + }
56375 +}
56376 +
56377 +__u32
56378 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56379 +{
56380 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56381 +}
56382 +
56383 +__u32
56384 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56385 +{
56386 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56387 +}
56388 +
56389 +__u32
56390 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56391 +{
56392 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56393 +}
56394 +
56395 +__u32
56396 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56397 +{
56398 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56399 + GR_UNIXCONNECT_ACL_MSG);
56400 +}
56401 +
56402 +/* hardlinks require at minimum create and link permission,
56403 + any additional privilege required is based on the
56404 + privilege of the file being linked to
56405 +*/
56406 +__u32
56407 +gr_acl_handle_link(const struct dentry * new_dentry,
56408 + const struct dentry * parent_dentry,
56409 + const struct vfsmount * parent_mnt,
56410 + const struct dentry * old_dentry,
56411 + const struct vfsmount * old_mnt, const char *to)
56412 +{
56413 + __u32 mode;
56414 + __u32 needmode = GR_CREATE | GR_LINK;
56415 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56416 +
56417 + mode =
56418 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56419 + old_mnt);
56420 +
56421 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56422 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56423 + return mode;
56424 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56425 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56426 + return 0;
56427 + } else if (unlikely((mode & needmode) != needmode))
56428 + return 0;
56429 +
56430 + return 1;
56431 +}
56432 +
56433 +__u32
56434 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56435 + const struct dentry * parent_dentry,
56436 + const struct vfsmount * parent_mnt, const char *from)
56437 +{
56438 + __u32 needmode = GR_WRITE | GR_CREATE;
56439 + __u32 mode;
56440 +
56441 + mode =
56442 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56443 + GR_CREATE | GR_AUDIT_CREATE |
56444 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56445 +
56446 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56447 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56448 + return mode;
56449 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56450 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56451 + return 0;
56452 + } else if (unlikely((mode & needmode) != needmode))
56453 + return 0;
56454 +
56455 + return (GR_WRITE | GR_CREATE);
56456 +}
56457 +
56458 +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)
56459 +{
56460 + __u32 mode;
56461 +
56462 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56463 +
56464 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56465 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56466 + return mode;
56467 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56468 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56469 + return 0;
56470 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56471 + return 0;
56472 +
56473 + return (reqmode);
56474 +}
56475 +
56476 +__u32
56477 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56478 + const struct dentry * parent_dentry,
56479 + const struct vfsmount * parent_mnt,
56480 + const int mode)
56481 +{
56482 + __u32 reqmode = GR_WRITE | GR_CREATE;
56483 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56484 + reqmode |= GR_SETID;
56485 +
56486 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56487 + reqmode, GR_MKNOD_ACL_MSG);
56488 +}
56489 +
56490 +__u32
56491 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56492 + const struct dentry *parent_dentry,
56493 + const struct vfsmount *parent_mnt)
56494 +{
56495 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56496 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56497 +}
56498 +
56499 +#define RENAME_CHECK_SUCCESS(old, new) \
56500 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56501 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56502 +
56503 +int
56504 +gr_acl_handle_rename(struct dentry *new_dentry,
56505 + struct dentry *parent_dentry,
56506 + const struct vfsmount *parent_mnt,
56507 + struct dentry *old_dentry,
56508 + struct inode *old_parent_inode,
56509 + struct vfsmount *old_mnt, const char *newname)
56510 +{
56511 + __u32 comp1, comp2;
56512 + int error = 0;
56513 +
56514 + if (unlikely(!gr_acl_is_enabled()))
56515 + return 0;
56516 +
56517 + if (!new_dentry->d_inode) {
56518 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56519 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56520 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56521 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56522 + GR_DELETE | GR_AUDIT_DELETE |
56523 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56524 + GR_SUPPRESS, old_mnt);
56525 + } else {
56526 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56527 + GR_CREATE | GR_DELETE |
56528 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56529 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56530 + GR_SUPPRESS, parent_mnt);
56531 + comp2 =
56532 + gr_search_file(old_dentry,
56533 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56534 + GR_DELETE | GR_AUDIT_DELETE |
56535 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56536 + }
56537 +
56538 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56539 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56540 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56541 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56542 + && !(comp2 & GR_SUPPRESS)) {
56543 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56544 + error = -EACCES;
56545 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56546 + error = -EACCES;
56547 +
56548 + return error;
56549 +}
56550 +
56551 +void
56552 +gr_acl_handle_exit(void)
56553 +{
56554 + u16 id;
56555 + char *rolename;
56556 + struct file *exec_file;
56557 +
56558 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56559 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56560 + id = current->acl_role_id;
56561 + rolename = current->role->rolename;
56562 + gr_set_acls(1);
56563 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56564 + }
56565 +
56566 + write_lock(&grsec_exec_file_lock);
56567 + exec_file = current->exec_file;
56568 + current->exec_file = NULL;
56569 + write_unlock(&grsec_exec_file_lock);
56570 +
56571 + if (exec_file)
56572 + fput(exec_file);
56573 +}
56574 +
56575 +int
56576 +gr_acl_handle_procpidmem(const struct task_struct *task)
56577 +{
56578 + if (unlikely(!gr_acl_is_enabled()))
56579 + return 0;
56580 +
56581 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56582 + return -EACCES;
56583 +
56584 + return 0;
56585 +}
56586 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56587 new file mode 100644
56588 index 0000000..58800a7
56589 --- /dev/null
56590 +++ b/grsecurity/gracl_ip.c
56591 @@ -0,0 +1,384 @@
56592 +#include <linux/kernel.h>
56593 +#include <asm/uaccess.h>
56594 +#include <asm/errno.h>
56595 +#include <net/sock.h>
56596 +#include <linux/file.h>
56597 +#include <linux/fs.h>
56598 +#include <linux/net.h>
56599 +#include <linux/in.h>
56600 +#include <linux/skbuff.h>
56601 +#include <linux/ip.h>
56602 +#include <linux/udp.h>
56603 +#include <linux/types.h>
56604 +#include <linux/sched.h>
56605 +#include <linux/netdevice.h>
56606 +#include <linux/inetdevice.h>
56607 +#include <linux/gracl.h>
56608 +#include <linux/grsecurity.h>
56609 +#include <linux/grinternal.h>
56610 +
56611 +#define GR_BIND 0x01
56612 +#define GR_CONNECT 0x02
56613 +#define GR_INVERT 0x04
56614 +#define GR_BINDOVERRIDE 0x08
56615 +#define GR_CONNECTOVERRIDE 0x10
56616 +#define GR_SOCK_FAMILY 0x20
56617 +
56618 +static const char * gr_protocols[IPPROTO_MAX] = {
56619 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56620 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56621 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56622 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56623 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56624 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56625 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56626 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56627 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56628 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56629 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56630 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56631 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56632 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56633 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56634 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56635 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56636 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56637 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56638 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56639 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56640 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56641 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56642 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56643 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56644 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56645 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56646 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56647 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56648 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56649 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56650 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56651 + };
56652 +
56653 +static const char * gr_socktypes[SOCK_MAX] = {
56654 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56655 + "unknown:7", "unknown:8", "unknown:9", "packet"
56656 + };
56657 +
56658 +static const char * gr_sockfamilies[AF_MAX+1] = {
56659 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56660 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56661 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56662 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56663 + };
56664 +
56665 +const char *
56666 +gr_proto_to_name(unsigned char proto)
56667 +{
56668 + return gr_protocols[proto];
56669 +}
56670 +
56671 +const char *
56672 +gr_socktype_to_name(unsigned char type)
56673 +{
56674 + return gr_socktypes[type];
56675 +}
56676 +
56677 +const char *
56678 +gr_sockfamily_to_name(unsigned char family)
56679 +{
56680 + return gr_sockfamilies[family];
56681 +}
56682 +
56683 +int
56684 +gr_search_socket(const int domain, const int type, const int protocol)
56685 +{
56686 + struct acl_subject_label *curr;
56687 + const struct cred *cred = current_cred();
56688 +
56689 + if (unlikely(!gr_acl_is_enabled()))
56690 + goto exit;
56691 +
56692 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56693 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56694 + goto exit; // let the kernel handle it
56695 +
56696 + curr = current->acl;
56697 +
56698 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56699 + /* the family is allowed, if this is PF_INET allow it only if
56700 + the extra sock type/protocol checks pass */
56701 + if (domain == PF_INET)
56702 + goto inet_check;
56703 + goto exit;
56704 + } else {
56705 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56706 + __u32 fakeip = 0;
56707 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56708 + current->role->roletype, cred->uid,
56709 + cred->gid, current->exec_file ?
56710 + gr_to_filename(current->exec_file->f_path.dentry,
56711 + current->exec_file->f_path.mnt) :
56712 + curr->filename, curr->filename,
56713 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56714 + &current->signal->saved_ip);
56715 + goto exit;
56716 + }
56717 + goto exit_fail;
56718 + }
56719 +
56720 +inet_check:
56721 + /* the rest of this checking is for IPv4 only */
56722 + if (!curr->ips)
56723 + goto exit;
56724 +
56725 + if ((curr->ip_type & (1 << type)) &&
56726 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56727 + goto exit;
56728 +
56729 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56730 + /* we don't place acls on raw sockets , and sometimes
56731 + dgram/ip sockets are opened for ioctl and not
56732 + bind/connect, so we'll fake a bind learn log */
56733 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56734 + __u32 fakeip = 0;
56735 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56736 + current->role->roletype, cred->uid,
56737 + cred->gid, current->exec_file ?
56738 + gr_to_filename(current->exec_file->f_path.dentry,
56739 + current->exec_file->f_path.mnt) :
56740 + curr->filename, curr->filename,
56741 + &fakeip, 0, type,
56742 + protocol, GR_CONNECT, &current->signal->saved_ip);
56743 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56744 + __u32 fakeip = 0;
56745 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56746 + current->role->roletype, cred->uid,
56747 + cred->gid, current->exec_file ?
56748 + gr_to_filename(current->exec_file->f_path.dentry,
56749 + current->exec_file->f_path.mnt) :
56750 + curr->filename, curr->filename,
56751 + &fakeip, 0, type,
56752 + protocol, GR_BIND, &current->signal->saved_ip);
56753 + }
56754 + /* we'll log when they use connect or bind */
56755 + goto exit;
56756 + }
56757 +
56758 +exit_fail:
56759 + if (domain == PF_INET)
56760 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56761 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56762 + else
56763 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56764 + gr_socktype_to_name(type), protocol);
56765 +
56766 + return 0;
56767 +exit:
56768 + return 1;
56769 +}
56770 +
56771 +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)
56772 +{
56773 + if ((ip->mode & mode) &&
56774 + (ip_port >= ip->low) &&
56775 + (ip_port <= ip->high) &&
56776 + ((ntohl(ip_addr) & our_netmask) ==
56777 + (ntohl(our_addr) & our_netmask))
56778 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56779 + && (ip->type & (1 << type))) {
56780 + if (ip->mode & GR_INVERT)
56781 + return 2; // specifically denied
56782 + else
56783 + return 1; // allowed
56784 + }
56785 +
56786 + return 0; // not specifically allowed, may continue parsing
56787 +}
56788 +
56789 +static int
56790 +gr_search_connectbind(const int full_mode, struct sock *sk,
56791 + struct sockaddr_in *addr, const int type)
56792 +{
56793 + char iface[IFNAMSIZ] = {0};
56794 + struct acl_subject_label *curr;
56795 + struct acl_ip_label *ip;
56796 + struct inet_sock *isk;
56797 + struct net_device *dev;
56798 + struct in_device *idev;
56799 + unsigned long i;
56800 + int ret;
56801 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56802 + __u32 ip_addr = 0;
56803 + __u32 our_addr;
56804 + __u32 our_netmask;
56805 + char *p;
56806 + __u16 ip_port = 0;
56807 + const struct cred *cred = current_cred();
56808 +
56809 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56810 + return 0;
56811 +
56812 + curr = current->acl;
56813 + isk = inet_sk(sk);
56814 +
56815 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56816 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56817 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56818 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56819 + struct sockaddr_in saddr;
56820 + int err;
56821 +
56822 + saddr.sin_family = AF_INET;
56823 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56824 + saddr.sin_port = isk->inet_sport;
56825 +
56826 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56827 + if (err)
56828 + return err;
56829 +
56830 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56831 + if (err)
56832 + return err;
56833 + }
56834 +
56835 + if (!curr->ips)
56836 + return 0;
56837 +
56838 + ip_addr = addr->sin_addr.s_addr;
56839 + ip_port = ntohs(addr->sin_port);
56840 +
56841 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56842 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56843 + current->role->roletype, cred->uid,
56844 + cred->gid, current->exec_file ?
56845 + gr_to_filename(current->exec_file->f_path.dentry,
56846 + current->exec_file->f_path.mnt) :
56847 + curr->filename, curr->filename,
56848 + &ip_addr, ip_port, type,
56849 + sk->sk_protocol, mode, &current->signal->saved_ip);
56850 + return 0;
56851 + }
56852 +
56853 + for (i = 0; i < curr->ip_num; i++) {
56854 + ip = *(curr->ips + i);
56855 + if (ip->iface != NULL) {
56856 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56857 + p = strchr(iface, ':');
56858 + if (p != NULL)
56859 + *p = '\0';
56860 + dev = dev_get_by_name(sock_net(sk), iface);
56861 + if (dev == NULL)
56862 + continue;
56863 + idev = in_dev_get(dev);
56864 + if (idev == NULL) {
56865 + dev_put(dev);
56866 + continue;
56867 + }
56868 + rcu_read_lock();
56869 + for_ifa(idev) {
56870 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56871 + our_addr = ifa->ifa_address;
56872 + our_netmask = 0xffffffff;
56873 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56874 + if (ret == 1) {
56875 + rcu_read_unlock();
56876 + in_dev_put(idev);
56877 + dev_put(dev);
56878 + return 0;
56879 + } else if (ret == 2) {
56880 + rcu_read_unlock();
56881 + in_dev_put(idev);
56882 + dev_put(dev);
56883 + goto denied;
56884 + }
56885 + }
56886 + } endfor_ifa(idev);
56887 + rcu_read_unlock();
56888 + in_dev_put(idev);
56889 + dev_put(dev);
56890 + } else {
56891 + our_addr = ip->addr;
56892 + our_netmask = ip->netmask;
56893 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56894 + if (ret == 1)
56895 + return 0;
56896 + else if (ret == 2)
56897 + goto denied;
56898 + }
56899 + }
56900 +
56901 +denied:
56902 + if (mode == GR_BIND)
56903 + 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));
56904 + else if (mode == GR_CONNECT)
56905 + 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));
56906 +
56907 + return -EACCES;
56908 +}
56909 +
56910 +int
56911 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56912 +{
56913 + /* always allow disconnection of dgram sockets with connect */
56914 + if (addr->sin_family == AF_UNSPEC)
56915 + return 0;
56916 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56917 +}
56918 +
56919 +int
56920 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56921 +{
56922 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56923 +}
56924 +
56925 +int gr_search_listen(struct socket *sock)
56926 +{
56927 + struct sock *sk = sock->sk;
56928 + struct sockaddr_in addr;
56929 +
56930 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56931 + addr.sin_port = inet_sk(sk)->inet_sport;
56932 +
56933 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56934 +}
56935 +
56936 +int gr_search_accept(struct socket *sock)
56937 +{
56938 + struct sock *sk = sock->sk;
56939 + struct sockaddr_in addr;
56940 +
56941 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56942 + addr.sin_port = inet_sk(sk)->inet_sport;
56943 +
56944 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56945 +}
56946 +
56947 +int
56948 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56949 +{
56950 + if (addr)
56951 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56952 + else {
56953 + struct sockaddr_in sin;
56954 + const struct inet_sock *inet = inet_sk(sk);
56955 +
56956 + sin.sin_addr.s_addr = inet->inet_daddr;
56957 + sin.sin_port = inet->inet_dport;
56958 +
56959 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56960 + }
56961 +}
56962 +
56963 +int
56964 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56965 +{
56966 + struct sockaddr_in sin;
56967 +
56968 + if (unlikely(skb->len < sizeof (struct udphdr)))
56969 + return 0; // skip this packet
56970 +
56971 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56972 + sin.sin_port = udp_hdr(skb)->source;
56973 +
56974 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56975 +}
56976 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56977 new file mode 100644
56978 index 0000000..25f54ef
56979 --- /dev/null
56980 +++ b/grsecurity/gracl_learn.c
56981 @@ -0,0 +1,207 @@
56982 +#include <linux/kernel.h>
56983 +#include <linux/mm.h>
56984 +#include <linux/sched.h>
56985 +#include <linux/poll.h>
56986 +#include <linux/string.h>
56987 +#include <linux/file.h>
56988 +#include <linux/types.h>
56989 +#include <linux/vmalloc.h>
56990 +#include <linux/grinternal.h>
56991 +
56992 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56993 + size_t count, loff_t *ppos);
56994 +extern int gr_acl_is_enabled(void);
56995 +
56996 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56997 +static int gr_learn_attached;
56998 +
56999 +/* use a 512k buffer */
57000 +#define LEARN_BUFFER_SIZE (512 * 1024)
57001 +
57002 +static DEFINE_SPINLOCK(gr_learn_lock);
57003 +static DEFINE_MUTEX(gr_learn_user_mutex);
57004 +
57005 +/* we need to maintain two buffers, so that the kernel context of grlearn
57006 + uses a semaphore around the userspace copying, and the other kernel contexts
57007 + use a spinlock when copying into the buffer, since they cannot sleep
57008 +*/
57009 +static char *learn_buffer;
57010 +static char *learn_buffer_user;
57011 +static int learn_buffer_len;
57012 +static int learn_buffer_user_len;
57013 +
57014 +static ssize_t
57015 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57016 +{
57017 + DECLARE_WAITQUEUE(wait, current);
57018 + ssize_t retval = 0;
57019 +
57020 + add_wait_queue(&learn_wait, &wait);
57021 + set_current_state(TASK_INTERRUPTIBLE);
57022 + do {
57023 + mutex_lock(&gr_learn_user_mutex);
57024 + spin_lock(&gr_learn_lock);
57025 + if (learn_buffer_len)
57026 + break;
57027 + spin_unlock(&gr_learn_lock);
57028 + mutex_unlock(&gr_learn_user_mutex);
57029 + if (file->f_flags & O_NONBLOCK) {
57030 + retval = -EAGAIN;
57031 + goto out;
57032 + }
57033 + if (signal_pending(current)) {
57034 + retval = -ERESTARTSYS;
57035 + goto out;
57036 + }
57037 +
57038 + schedule();
57039 + } while (1);
57040 +
57041 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57042 + learn_buffer_user_len = learn_buffer_len;
57043 + retval = learn_buffer_len;
57044 + learn_buffer_len = 0;
57045 +
57046 + spin_unlock(&gr_learn_lock);
57047 +
57048 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57049 + retval = -EFAULT;
57050 +
57051 + mutex_unlock(&gr_learn_user_mutex);
57052 +out:
57053 + set_current_state(TASK_RUNNING);
57054 + remove_wait_queue(&learn_wait, &wait);
57055 + return retval;
57056 +}
57057 +
57058 +static unsigned int
57059 +poll_learn(struct file * file, poll_table * wait)
57060 +{
57061 + poll_wait(file, &learn_wait, wait);
57062 +
57063 + if (learn_buffer_len)
57064 + return (POLLIN | POLLRDNORM);
57065 +
57066 + return 0;
57067 +}
57068 +
57069 +void
57070 +gr_clear_learn_entries(void)
57071 +{
57072 + char *tmp;
57073 +
57074 + mutex_lock(&gr_learn_user_mutex);
57075 + spin_lock(&gr_learn_lock);
57076 + tmp = learn_buffer;
57077 + learn_buffer = NULL;
57078 + spin_unlock(&gr_learn_lock);
57079 + if (tmp)
57080 + vfree(tmp);
57081 + if (learn_buffer_user != NULL) {
57082 + vfree(learn_buffer_user);
57083 + learn_buffer_user = NULL;
57084 + }
57085 + learn_buffer_len = 0;
57086 + mutex_unlock(&gr_learn_user_mutex);
57087 +
57088 + return;
57089 +}
57090 +
57091 +void
57092 +gr_add_learn_entry(const char *fmt, ...)
57093 +{
57094 + va_list args;
57095 + unsigned int len;
57096 +
57097 + if (!gr_learn_attached)
57098 + return;
57099 +
57100 + spin_lock(&gr_learn_lock);
57101 +
57102 + /* leave a gap at the end so we know when it's "full" but don't have to
57103 + compute the exact length of the string we're trying to append
57104 + */
57105 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57106 + spin_unlock(&gr_learn_lock);
57107 + wake_up_interruptible(&learn_wait);
57108 + return;
57109 + }
57110 + if (learn_buffer == NULL) {
57111 + spin_unlock(&gr_learn_lock);
57112 + return;
57113 + }
57114 +
57115 + va_start(args, fmt);
57116 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57117 + va_end(args);
57118 +
57119 + learn_buffer_len += len + 1;
57120 +
57121 + spin_unlock(&gr_learn_lock);
57122 + wake_up_interruptible(&learn_wait);
57123 +
57124 + return;
57125 +}
57126 +
57127 +static int
57128 +open_learn(struct inode *inode, struct file *file)
57129 +{
57130 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57131 + return -EBUSY;
57132 + if (file->f_mode & FMODE_READ) {
57133 + int retval = 0;
57134 + mutex_lock(&gr_learn_user_mutex);
57135 + if (learn_buffer == NULL)
57136 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57137 + if (learn_buffer_user == NULL)
57138 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57139 + if (learn_buffer == NULL) {
57140 + retval = -ENOMEM;
57141 + goto out_error;
57142 + }
57143 + if (learn_buffer_user == NULL) {
57144 + retval = -ENOMEM;
57145 + goto out_error;
57146 + }
57147 + learn_buffer_len = 0;
57148 + learn_buffer_user_len = 0;
57149 + gr_learn_attached = 1;
57150 +out_error:
57151 + mutex_unlock(&gr_learn_user_mutex);
57152 + return retval;
57153 + }
57154 + return 0;
57155 +}
57156 +
57157 +static int
57158 +close_learn(struct inode *inode, struct file *file)
57159 +{
57160 + if (file->f_mode & FMODE_READ) {
57161 + char *tmp = NULL;
57162 + mutex_lock(&gr_learn_user_mutex);
57163 + spin_lock(&gr_learn_lock);
57164 + tmp = learn_buffer;
57165 + learn_buffer = NULL;
57166 + spin_unlock(&gr_learn_lock);
57167 + if (tmp)
57168 + vfree(tmp);
57169 + if (learn_buffer_user != NULL) {
57170 + vfree(learn_buffer_user);
57171 + learn_buffer_user = NULL;
57172 + }
57173 + learn_buffer_len = 0;
57174 + learn_buffer_user_len = 0;
57175 + gr_learn_attached = 0;
57176 + mutex_unlock(&gr_learn_user_mutex);
57177 + }
57178 +
57179 + return 0;
57180 +}
57181 +
57182 +const struct file_operations grsec_fops = {
57183 + .read = read_learn,
57184 + .write = write_grsec_handler,
57185 + .open = open_learn,
57186 + .release = close_learn,
57187 + .poll = poll_learn,
57188 +};
57189 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57190 new file mode 100644
57191 index 0000000..39645c9
57192 --- /dev/null
57193 +++ b/grsecurity/gracl_res.c
57194 @@ -0,0 +1,68 @@
57195 +#include <linux/kernel.h>
57196 +#include <linux/sched.h>
57197 +#include <linux/gracl.h>
57198 +#include <linux/grinternal.h>
57199 +
57200 +static const char *restab_log[] = {
57201 + [RLIMIT_CPU] = "RLIMIT_CPU",
57202 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57203 + [RLIMIT_DATA] = "RLIMIT_DATA",
57204 + [RLIMIT_STACK] = "RLIMIT_STACK",
57205 + [RLIMIT_CORE] = "RLIMIT_CORE",
57206 + [RLIMIT_RSS] = "RLIMIT_RSS",
57207 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57208 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57209 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57210 + [RLIMIT_AS] = "RLIMIT_AS",
57211 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57212 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57213 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57214 + [RLIMIT_NICE] = "RLIMIT_NICE",
57215 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57216 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57217 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57218 +};
57219 +
57220 +void
57221 +gr_log_resource(const struct task_struct *task,
57222 + const int res, const unsigned long wanted, const int gt)
57223 +{
57224 + const struct cred *cred;
57225 + unsigned long rlim;
57226 +
57227 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57228 + return;
57229 +
57230 + // not yet supported resource
57231 + if (unlikely(!restab_log[res]))
57232 + return;
57233 +
57234 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57235 + rlim = task_rlimit_max(task, res);
57236 + else
57237 + rlim = task_rlimit(task, res);
57238 +
57239 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57240 + return;
57241 +
57242 + rcu_read_lock();
57243 + cred = __task_cred(task);
57244 +
57245 + if (res == RLIMIT_NPROC &&
57246 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57247 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57248 + goto out_rcu_unlock;
57249 + else if (res == RLIMIT_MEMLOCK &&
57250 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57251 + goto out_rcu_unlock;
57252 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57253 + goto out_rcu_unlock;
57254 + rcu_read_unlock();
57255 +
57256 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57257 +
57258 + return;
57259 +out_rcu_unlock:
57260 + rcu_read_unlock();
57261 + return;
57262 +}
57263 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57264 new file mode 100644
57265 index 0000000..25197e9
57266 --- /dev/null
57267 +++ b/grsecurity/gracl_segv.c
57268 @@ -0,0 +1,299 @@
57269 +#include <linux/kernel.h>
57270 +#include <linux/mm.h>
57271 +#include <asm/uaccess.h>
57272 +#include <asm/errno.h>
57273 +#include <asm/mman.h>
57274 +#include <net/sock.h>
57275 +#include <linux/file.h>
57276 +#include <linux/fs.h>
57277 +#include <linux/net.h>
57278 +#include <linux/in.h>
57279 +#include <linux/slab.h>
57280 +#include <linux/types.h>
57281 +#include <linux/sched.h>
57282 +#include <linux/timer.h>
57283 +#include <linux/gracl.h>
57284 +#include <linux/grsecurity.h>
57285 +#include <linux/grinternal.h>
57286 +
57287 +static struct crash_uid *uid_set;
57288 +static unsigned short uid_used;
57289 +static DEFINE_SPINLOCK(gr_uid_lock);
57290 +extern rwlock_t gr_inode_lock;
57291 +extern struct acl_subject_label *
57292 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57293 + struct acl_role_label *role);
57294 +
57295 +#ifdef CONFIG_BTRFS_FS
57296 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57297 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57298 +#endif
57299 +
57300 +static inline dev_t __get_dev(const struct dentry *dentry)
57301 +{
57302 +#ifdef CONFIG_BTRFS_FS
57303 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57304 + return get_btrfs_dev_from_inode(dentry->d_inode);
57305 + else
57306 +#endif
57307 + return dentry->d_inode->i_sb->s_dev;
57308 +}
57309 +
57310 +int
57311 +gr_init_uidset(void)
57312 +{
57313 + uid_set =
57314 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57315 + uid_used = 0;
57316 +
57317 + return uid_set ? 1 : 0;
57318 +}
57319 +
57320 +void
57321 +gr_free_uidset(void)
57322 +{
57323 + if (uid_set)
57324 + kfree(uid_set);
57325 +
57326 + return;
57327 +}
57328 +
57329 +int
57330 +gr_find_uid(const uid_t uid)
57331 +{
57332 + struct crash_uid *tmp = uid_set;
57333 + uid_t buid;
57334 + int low = 0, high = uid_used - 1, mid;
57335 +
57336 + while (high >= low) {
57337 + mid = (low + high) >> 1;
57338 + buid = tmp[mid].uid;
57339 + if (buid == uid)
57340 + return mid;
57341 + if (buid > uid)
57342 + high = mid - 1;
57343 + if (buid < uid)
57344 + low = mid + 1;
57345 + }
57346 +
57347 + return -1;
57348 +}
57349 +
57350 +static __inline__ void
57351 +gr_insertsort(void)
57352 +{
57353 + unsigned short i, j;
57354 + struct crash_uid index;
57355 +
57356 + for (i = 1; i < uid_used; i++) {
57357 + index = uid_set[i];
57358 + j = i;
57359 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57360 + uid_set[j] = uid_set[j - 1];
57361 + j--;
57362 + }
57363 + uid_set[j] = index;
57364 + }
57365 +
57366 + return;
57367 +}
57368 +
57369 +static __inline__ void
57370 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57371 +{
57372 + int loc;
57373 +
57374 + if (uid_used == GR_UIDTABLE_MAX)
57375 + return;
57376 +
57377 + loc = gr_find_uid(uid);
57378 +
57379 + if (loc >= 0) {
57380 + uid_set[loc].expires = expires;
57381 + return;
57382 + }
57383 +
57384 + uid_set[uid_used].uid = uid;
57385 + uid_set[uid_used].expires = expires;
57386 + uid_used++;
57387 +
57388 + gr_insertsort();
57389 +
57390 + return;
57391 +}
57392 +
57393 +void
57394 +gr_remove_uid(const unsigned short loc)
57395 +{
57396 + unsigned short i;
57397 +
57398 + for (i = loc + 1; i < uid_used; i++)
57399 + uid_set[i - 1] = uid_set[i];
57400 +
57401 + uid_used--;
57402 +
57403 + return;
57404 +}
57405 +
57406 +int
57407 +gr_check_crash_uid(const uid_t uid)
57408 +{
57409 + int loc;
57410 + int ret = 0;
57411 +
57412 + if (unlikely(!gr_acl_is_enabled()))
57413 + return 0;
57414 +
57415 + spin_lock(&gr_uid_lock);
57416 + loc = gr_find_uid(uid);
57417 +
57418 + if (loc < 0)
57419 + goto out_unlock;
57420 +
57421 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57422 + gr_remove_uid(loc);
57423 + else
57424 + ret = 1;
57425 +
57426 +out_unlock:
57427 + spin_unlock(&gr_uid_lock);
57428 + return ret;
57429 +}
57430 +
57431 +static __inline__ int
57432 +proc_is_setxid(const struct cred *cred)
57433 +{
57434 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57435 + !uid_eq(cred->uid, cred->fsuid))
57436 + return 1;
57437 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57438 + !uid_eq(cred->gid, cred->fsgid))
57439 + return 1;
57440 +
57441 + return 0;
57442 +}
57443 +
57444 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57445 +
57446 +void
57447 +gr_handle_crash(struct task_struct *task, const int sig)
57448 +{
57449 + struct acl_subject_label *curr;
57450 + struct task_struct *tsk, *tsk2;
57451 + const struct cred *cred;
57452 + const struct cred *cred2;
57453 +
57454 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57455 + return;
57456 +
57457 + if (unlikely(!gr_acl_is_enabled()))
57458 + return;
57459 +
57460 + curr = task->acl;
57461 +
57462 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57463 + return;
57464 +
57465 + if (time_before_eq(curr->expires, get_seconds())) {
57466 + curr->expires = 0;
57467 + curr->crashes = 0;
57468 + }
57469 +
57470 + curr->crashes++;
57471 +
57472 + if (!curr->expires)
57473 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57474 +
57475 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57476 + time_after(curr->expires, get_seconds())) {
57477 + rcu_read_lock();
57478 + cred = __task_cred(task);
57479 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57480 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57481 + spin_lock(&gr_uid_lock);
57482 + gr_insert_uid(cred->uid, curr->expires);
57483 + spin_unlock(&gr_uid_lock);
57484 + curr->expires = 0;
57485 + curr->crashes = 0;
57486 + read_lock(&tasklist_lock);
57487 + do_each_thread(tsk2, tsk) {
57488 + cred2 = __task_cred(tsk);
57489 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57490 + gr_fake_force_sig(SIGKILL, tsk);
57491 + } while_each_thread(tsk2, tsk);
57492 + read_unlock(&tasklist_lock);
57493 + } else {
57494 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57495 + read_lock(&tasklist_lock);
57496 + read_lock(&grsec_exec_file_lock);
57497 + do_each_thread(tsk2, tsk) {
57498 + if (likely(tsk != task)) {
57499 + // if this thread has the same subject as the one that triggered
57500 + // RES_CRASH and it's the same binary, kill it
57501 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57502 + gr_fake_force_sig(SIGKILL, tsk);
57503 + }
57504 + } while_each_thread(tsk2, tsk);
57505 + read_unlock(&grsec_exec_file_lock);
57506 + read_unlock(&tasklist_lock);
57507 + }
57508 + rcu_read_unlock();
57509 + }
57510 +
57511 + return;
57512 +}
57513 +
57514 +int
57515 +gr_check_crash_exec(const struct file *filp)
57516 +{
57517 + struct acl_subject_label *curr;
57518 +
57519 + if (unlikely(!gr_acl_is_enabled()))
57520 + return 0;
57521 +
57522 + read_lock(&gr_inode_lock);
57523 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57524 + __get_dev(filp->f_path.dentry),
57525 + current->role);
57526 + read_unlock(&gr_inode_lock);
57527 +
57528 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57529 + (!curr->crashes && !curr->expires))
57530 + return 0;
57531 +
57532 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57533 + time_after(curr->expires, get_seconds()))
57534 + return 1;
57535 + else if (time_before_eq(curr->expires, get_seconds())) {
57536 + curr->crashes = 0;
57537 + curr->expires = 0;
57538 + }
57539 +
57540 + return 0;
57541 +}
57542 +
57543 +void
57544 +gr_handle_alertkill(struct task_struct *task)
57545 +{
57546 + struct acl_subject_label *curracl;
57547 + __u32 curr_ip;
57548 + struct task_struct *p, *p2;
57549 +
57550 + if (unlikely(!gr_acl_is_enabled()))
57551 + return;
57552 +
57553 + curracl = task->acl;
57554 + curr_ip = task->signal->curr_ip;
57555 +
57556 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57557 + read_lock(&tasklist_lock);
57558 + do_each_thread(p2, p) {
57559 + if (p->signal->curr_ip == curr_ip)
57560 + gr_fake_force_sig(SIGKILL, p);
57561 + } while_each_thread(p2, p);
57562 + read_unlock(&tasklist_lock);
57563 + } else if (curracl->mode & GR_KILLPROC)
57564 + gr_fake_force_sig(SIGKILL, task);
57565 +
57566 + return;
57567 +}
57568 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57569 new file mode 100644
57570 index 0000000..9d83a69
57571 --- /dev/null
57572 +++ b/grsecurity/gracl_shm.c
57573 @@ -0,0 +1,40 @@
57574 +#include <linux/kernel.h>
57575 +#include <linux/mm.h>
57576 +#include <linux/sched.h>
57577 +#include <linux/file.h>
57578 +#include <linux/ipc.h>
57579 +#include <linux/gracl.h>
57580 +#include <linux/grsecurity.h>
57581 +#include <linux/grinternal.h>
57582 +
57583 +int
57584 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57585 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57586 +{
57587 + struct task_struct *task;
57588 +
57589 + if (!gr_acl_is_enabled())
57590 + return 1;
57591 +
57592 + rcu_read_lock();
57593 + read_lock(&tasklist_lock);
57594 +
57595 + task = find_task_by_vpid(shm_cprid);
57596 +
57597 + if (unlikely(!task))
57598 + task = find_task_by_vpid(shm_lapid);
57599 +
57600 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57601 + (task->pid == shm_lapid)) &&
57602 + (task->acl->mode & GR_PROTSHM) &&
57603 + (task->acl != current->acl))) {
57604 + read_unlock(&tasklist_lock);
57605 + rcu_read_unlock();
57606 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57607 + return 0;
57608 + }
57609 + read_unlock(&tasklist_lock);
57610 + rcu_read_unlock();
57611 +
57612 + return 1;
57613 +}
57614 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57615 new file mode 100644
57616 index 0000000..bc0be01
57617 --- /dev/null
57618 +++ b/grsecurity/grsec_chdir.c
57619 @@ -0,0 +1,19 @@
57620 +#include <linux/kernel.h>
57621 +#include <linux/sched.h>
57622 +#include <linux/fs.h>
57623 +#include <linux/file.h>
57624 +#include <linux/grsecurity.h>
57625 +#include <linux/grinternal.h>
57626 +
57627 +void
57628 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57629 +{
57630 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57631 + if ((grsec_enable_chdir && grsec_enable_group &&
57632 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57633 + !grsec_enable_group)) {
57634 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57635 + }
57636 +#endif
57637 + return;
57638 +}
57639 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57640 new file mode 100644
57641 index 0000000..9807ee2
57642 --- /dev/null
57643 +++ b/grsecurity/grsec_chroot.c
57644 @@ -0,0 +1,368 @@
57645 +#include <linux/kernel.h>
57646 +#include <linux/module.h>
57647 +#include <linux/sched.h>
57648 +#include <linux/file.h>
57649 +#include <linux/fs.h>
57650 +#include <linux/mount.h>
57651 +#include <linux/types.h>
57652 +#include "../fs/mount.h"
57653 +#include <linux/grsecurity.h>
57654 +#include <linux/grinternal.h>
57655 +
57656 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57657 +{
57658 +#ifdef CONFIG_GRKERNSEC
57659 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57660 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57661 + task->gr_is_chrooted = 1;
57662 + else
57663 + task->gr_is_chrooted = 0;
57664 +
57665 + task->gr_chroot_dentry = path->dentry;
57666 +#endif
57667 + return;
57668 +}
57669 +
57670 +void gr_clear_chroot_entries(struct task_struct *task)
57671 +{
57672 +#ifdef CONFIG_GRKERNSEC
57673 + task->gr_is_chrooted = 0;
57674 + task->gr_chroot_dentry = NULL;
57675 +#endif
57676 + return;
57677 +}
57678 +
57679 +int
57680 +gr_handle_chroot_unix(const pid_t pid)
57681 +{
57682 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57683 + struct task_struct *p;
57684 +
57685 + if (unlikely(!grsec_enable_chroot_unix))
57686 + return 1;
57687 +
57688 + if (likely(!proc_is_chrooted(current)))
57689 + return 1;
57690 +
57691 + rcu_read_lock();
57692 + read_lock(&tasklist_lock);
57693 + p = find_task_by_vpid_unrestricted(pid);
57694 + if (unlikely(p && !have_same_root(current, p))) {
57695 + read_unlock(&tasklist_lock);
57696 + rcu_read_unlock();
57697 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57698 + return 0;
57699 + }
57700 + read_unlock(&tasklist_lock);
57701 + rcu_read_unlock();
57702 +#endif
57703 + return 1;
57704 +}
57705 +
57706 +int
57707 +gr_handle_chroot_nice(void)
57708 +{
57709 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57710 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57711 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57712 + return -EPERM;
57713 + }
57714 +#endif
57715 + return 0;
57716 +}
57717 +
57718 +int
57719 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57720 +{
57721 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57722 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57723 + && proc_is_chrooted(current)) {
57724 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57725 + return -EACCES;
57726 + }
57727 +#endif
57728 + return 0;
57729 +}
57730 +
57731 +int
57732 +gr_handle_chroot_rawio(const struct inode *inode)
57733 +{
57734 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57735 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57736 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57737 + return 1;
57738 +#endif
57739 + return 0;
57740 +}
57741 +
57742 +int
57743 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57744 +{
57745 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57746 + struct task_struct *p;
57747 + int ret = 0;
57748 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57749 + return ret;
57750 +
57751 + read_lock(&tasklist_lock);
57752 + do_each_pid_task(pid, type, p) {
57753 + if (!have_same_root(current, p)) {
57754 + ret = 1;
57755 + goto out;
57756 + }
57757 + } while_each_pid_task(pid, type, p);
57758 +out:
57759 + read_unlock(&tasklist_lock);
57760 + return ret;
57761 +#endif
57762 + return 0;
57763 +}
57764 +
57765 +int
57766 +gr_pid_is_chrooted(struct task_struct *p)
57767 +{
57768 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57769 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57770 + return 0;
57771 +
57772 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57773 + !have_same_root(current, p)) {
57774 + return 1;
57775 + }
57776 +#endif
57777 + return 0;
57778 +}
57779 +
57780 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57781 +
57782 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57783 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57784 +{
57785 + struct path path, currentroot;
57786 + int ret = 0;
57787 +
57788 + path.dentry = (struct dentry *)u_dentry;
57789 + path.mnt = (struct vfsmount *)u_mnt;
57790 + get_fs_root(current->fs, &currentroot);
57791 + if (path_is_under(&path, &currentroot))
57792 + ret = 1;
57793 + path_put(&currentroot);
57794 +
57795 + return ret;
57796 +}
57797 +#endif
57798 +
57799 +int
57800 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57801 +{
57802 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57803 + if (!grsec_enable_chroot_fchdir)
57804 + return 1;
57805 +
57806 + if (!proc_is_chrooted(current))
57807 + return 1;
57808 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57809 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57810 + return 0;
57811 + }
57812 +#endif
57813 + return 1;
57814 +}
57815 +
57816 +int
57817 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57818 + const time_t shm_createtime)
57819 +{
57820 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57821 + struct task_struct *p;
57822 + time_t starttime;
57823 +
57824 + if (unlikely(!grsec_enable_chroot_shmat))
57825 + return 1;
57826 +
57827 + if (likely(!proc_is_chrooted(current)))
57828 + return 1;
57829 +
57830 + rcu_read_lock();
57831 + read_lock(&tasklist_lock);
57832 +
57833 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57834 + starttime = p->start_time.tv_sec;
57835 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57836 + if (have_same_root(current, p)) {
57837 + goto allow;
57838 + } else {
57839 + read_unlock(&tasklist_lock);
57840 + rcu_read_unlock();
57841 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57842 + return 0;
57843 + }
57844 + }
57845 + /* creator exited, pid reuse, fall through to next check */
57846 + }
57847 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57848 + if (unlikely(!have_same_root(current, p))) {
57849 + read_unlock(&tasklist_lock);
57850 + rcu_read_unlock();
57851 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57852 + return 0;
57853 + }
57854 + }
57855 +
57856 +allow:
57857 + read_unlock(&tasklist_lock);
57858 + rcu_read_unlock();
57859 +#endif
57860 + return 1;
57861 +}
57862 +
57863 +void
57864 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57865 +{
57866 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57867 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57868 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57869 +#endif
57870 + return;
57871 +}
57872 +
57873 +int
57874 +gr_handle_chroot_mknod(const struct dentry *dentry,
57875 + const struct vfsmount *mnt, const int mode)
57876 +{
57877 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57878 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57879 + proc_is_chrooted(current)) {
57880 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57881 + return -EPERM;
57882 + }
57883 +#endif
57884 + return 0;
57885 +}
57886 +
57887 +int
57888 +gr_handle_chroot_mount(const struct dentry *dentry,
57889 + const struct vfsmount *mnt, const char *dev_name)
57890 +{
57891 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57892 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57893 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57894 + return -EPERM;
57895 + }
57896 +#endif
57897 + return 0;
57898 +}
57899 +
57900 +int
57901 +gr_handle_chroot_pivot(void)
57902 +{
57903 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57904 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57905 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57906 + return -EPERM;
57907 + }
57908 +#endif
57909 + return 0;
57910 +}
57911 +
57912 +int
57913 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57914 +{
57915 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57916 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57917 + !gr_is_outside_chroot(dentry, mnt)) {
57918 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57919 + return -EPERM;
57920 + }
57921 +#endif
57922 + return 0;
57923 +}
57924 +
57925 +extern const char *captab_log[];
57926 +extern int captab_log_entries;
57927 +
57928 +int
57929 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57930 +{
57931 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57932 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57933 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57934 + if (cap_raised(chroot_caps, cap)) {
57935 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57936 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57937 + }
57938 + return 0;
57939 + }
57940 + }
57941 +#endif
57942 + return 1;
57943 +}
57944 +
57945 +int
57946 +gr_chroot_is_capable(const int cap)
57947 +{
57948 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57949 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57950 +#endif
57951 + return 1;
57952 +}
57953 +
57954 +int
57955 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57956 +{
57957 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57958 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57959 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57960 + if (cap_raised(chroot_caps, cap)) {
57961 + return 0;
57962 + }
57963 + }
57964 +#endif
57965 + return 1;
57966 +}
57967 +
57968 +int
57969 +gr_chroot_is_capable_nolog(const int cap)
57970 +{
57971 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57972 + return gr_task_chroot_is_capable_nolog(current, cap);
57973 +#endif
57974 + return 1;
57975 +}
57976 +
57977 +int
57978 +gr_handle_chroot_sysctl(const int op)
57979 +{
57980 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57981 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57982 + proc_is_chrooted(current))
57983 + return -EACCES;
57984 +#endif
57985 + return 0;
57986 +}
57987 +
57988 +void
57989 +gr_handle_chroot_chdir(struct path *path)
57990 +{
57991 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57992 + if (grsec_enable_chroot_chdir)
57993 + set_fs_pwd(current->fs, path);
57994 +#endif
57995 + return;
57996 +}
57997 +
57998 +int
57999 +gr_handle_chroot_chmod(const struct dentry *dentry,
58000 + const struct vfsmount *mnt, const int mode)
58001 +{
58002 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58003 + /* allow chmod +s on directories, but not files */
58004 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58005 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58006 + proc_is_chrooted(current)) {
58007 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58008 + return -EPERM;
58009 + }
58010 +#endif
58011 + return 0;
58012 +}
58013 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58014 new file mode 100644
58015 index 0000000..213ad8b
58016 --- /dev/null
58017 +++ b/grsecurity/grsec_disabled.c
58018 @@ -0,0 +1,437 @@
58019 +#include <linux/kernel.h>
58020 +#include <linux/module.h>
58021 +#include <linux/sched.h>
58022 +#include <linux/file.h>
58023 +#include <linux/fs.h>
58024 +#include <linux/kdev_t.h>
58025 +#include <linux/net.h>
58026 +#include <linux/in.h>
58027 +#include <linux/ip.h>
58028 +#include <linux/skbuff.h>
58029 +#include <linux/sysctl.h>
58030 +
58031 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58032 +void
58033 +pax_set_initial_flags(struct linux_binprm *bprm)
58034 +{
58035 + return;
58036 +}
58037 +#endif
58038 +
58039 +#ifdef CONFIG_SYSCTL
58040 +__u32
58041 +gr_handle_sysctl(const struct ctl_table * table, const int op)
58042 +{
58043 + return 0;
58044 +}
58045 +#endif
58046 +
58047 +#ifdef CONFIG_TASKSTATS
58048 +int gr_is_taskstats_denied(int pid)
58049 +{
58050 + return 0;
58051 +}
58052 +#endif
58053 +
58054 +int
58055 +gr_acl_is_enabled(void)
58056 +{
58057 + return 0;
58058 +}
58059 +
58060 +void
58061 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58062 +{
58063 + return;
58064 +}
58065 +
58066 +int
58067 +gr_handle_rawio(const struct inode *inode)
58068 +{
58069 + return 0;
58070 +}
58071 +
58072 +void
58073 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58074 +{
58075 + return;
58076 +}
58077 +
58078 +int
58079 +gr_handle_ptrace(struct task_struct *task, const long request)
58080 +{
58081 + return 0;
58082 +}
58083 +
58084 +int
58085 +gr_handle_proc_ptrace(struct task_struct *task)
58086 +{
58087 + return 0;
58088 +}
58089 +
58090 +void
58091 +gr_learn_resource(const struct task_struct *task,
58092 + const int res, const unsigned long wanted, const int gt)
58093 +{
58094 + return;
58095 +}
58096 +
58097 +int
58098 +gr_set_acls(const int type)
58099 +{
58100 + return 0;
58101 +}
58102 +
58103 +int
58104 +gr_check_hidden_task(const struct task_struct *tsk)
58105 +{
58106 + return 0;
58107 +}
58108 +
58109 +int
58110 +gr_check_protected_task(const struct task_struct *task)
58111 +{
58112 + return 0;
58113 +}
58114 +
58115 +int
58116 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58117 +{
58118 + return 0;
58119 +}
58120 +
58121 +void
58122 +gr_copy_label(struct task_struct *tsk)
58123 +{
58124 + return;
58125 +}
58126 +
58127 +void
58128 +gr_set_pax_flags(struct task_struct *task)
58129 +{
58130 + return;
58131 +}
58132 +
58133 +int
58134 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58135 + const int unsafe_share)
58136 +{
58137 + return 0;
58138 +}
58139 +
58140 +void
58141 +gr_handle_delete(const ino_t ino, const dev_t dev)
58142 +{
58143 + return;
58144 +}
58145 +
58146 +void
58147 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58148 +{
58149 + return;
58150 +}
58151 +
58152 +void
58153 +gr_handle_crash(struct task_struct *task, const int sig)
58154 +{
58155 + return;
58156 +}
58157 +
58158 +int
58159 +gr_check_crash_exec(const struct file *filp)
58160 +{
58161 + return 0;
58162 +}
58163 +
58164 +int
58165 +gr_check_crash_uid(const uid_t uid)
58166 +{
58167 + return 0;
58168 +}
58169 +
58170 +void
58171 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58172 + struct dentry *old_dentry,
58173 + struct dentry *new_dentry,
58174 + struct vfsmount *mnt, const __u8 replace)
58175 +{
58176 + return;
58177 +}
58178 +
58179 +int
58180 +gr_search_socket(const int family, const int type, const int protocol)
58181 +{
58182 + return 1;
58183 +}
58184 +
58185 +int
58186 +gr_search_connectbind(const int mode, const struct socket *sock,
58187 + const struct sockaddr_in *addr)
58188 +{
58189 + return 0;
58190 +}
58191 +
58192 +void
58193 +gr_handle_alertkill(struct task_struct *task)
58194 +{
58195 + return;
58196 +}
58197 +
58198 +__u32
58199 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58200 +{
58201 + return 1;
58202 +}
58203 +
58204 +__u32
58205 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58206 + const struct vfsmount * mnt)
58207 +{
58208 + return 1;
58209 +}
58210 +
58211 +__u32
58212 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58213 + int acc_mode)
58214 +{
58215 + return 1;
58216 +}
58217 +
58218 +__u32
58219 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58220 +{
58221 + return 1;
58222 +}
58223 +
58224 +__u32
58225 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58226 +{
58227 + return 1;
58228 +}
58229 +
58230 +int
58231 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58232 + unsigned int *vm_flags)
58233 +{
58234 + return 1;
58235 +}
58236 +
58237 +__u32
58238 +gr_acl_handle_truncate(const struct dentry * dentry,
58239 + const struct vfsmount * mnt)
58240 +{
58241 + return 1;
58242 +}
58243 +
58244 +__u32
58245 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58246 +{
58247 + return 1;
58248 +}
58249 +
58250 +__u32
58251 +gr_acl_handle_access(const struct dentry * dentry,
58252 + const struct vfsmount * mnt, const int fmode)
58253 +{
58254 + return 1;
58255 +}
58256 +
58257 +__u32
58258 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58259 + umode_t *mode)
58260 +{
58261 + return 1;
58262 +}
58263 +
58264 +__u32
58265 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58266 +{
58267 + return 1;
58268 +}
58269 +
58270 +__u32
58271 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58272 +{
58273 + return 1;
58274 +}
58275 +
58276 +void
58277 +grsecurity_init(void)
58278 +{
58279 + return;
58280 +}
58281 +
58282 +umode_t gr_acl_umask(void)
58283 +{
58284 + return 0;
58285 +}
58286 +
58287 +__u32
58288 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58289 + const struct dentry * parent_dentry,
58290 + const struct vfsmount * parent_mnt,
58291 + const int mode)
58292 +{
58293 + return 1;
58294 +}
58295 +
58296 +__u32
58297 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58298 + const struct dentry * parent_dentry,
58299 + const struct vfsmount * parent_mnt)
58300 +{
58301 + return 1;
58302 +}
58303 +
58304 +__u32
58305 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58306 + const struct dentry * parent_dentry,
58307 + const struct vfsmount * parent_mnt, const char *from)
58308 +{
58309 + return 1;
58310 +}
58311 +
58312 +__u32
58313 +gr_acl_handle_link(const struct dentry * new_dentry,
58314 + const struct dentry * parent_dentry,
58315 + const struct vfsmount * parent_mnt,
58316 + const struct dentry * old_dentry,
58317 + const struct vfsmount * old_mnt, const char *to)
58318 +{
58319 + return 1;
58320 +}
58321 +
58322 +int
58323 +gr_acl_handle_rename(const struct dentry *new_dentry,
58324 + const struct dentry *parent_dentry,
58325 + const struct vfsmount *parent_mnt,
58326 + const struct dentry *old_dentry,
58327 + const struct inode *old_parent_inode,
58328 + const struct vfsmount *old_mnt, const char *newname)
58329 +{
58330 + return 0;
58331 +}
58332 +
58333 +int
58334 +gr_acl_handle_filldir(const struct file *file, const char *name,
58335 + const int namelen, const ino_t ino)
58336 +{
58337 + return 1;
58338 +}
58339 +
58340 +int
58341 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58342 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58343 +{
58344 + return 1;
58345 +}
58346 +
58347 +int
58348 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58349 +{
58350 + return 0;
58351 +}
58352 +
58353 +int
58354 +gr_search_accept(const struct socket *sock)
58355 +{
58356 + return 0;
58357 +}
58358 +
58359 +int
58360 +gr_search_listen(const struct socket *sock)
58361 +{
58362 + return 0;
58363 +}
58364 +
58365 +int
58366 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58367 +{
58368 + return 0;
58369 +}
58370 +
58371 +__u32
58372 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58373 +{
58374 + return 1;
58375 +}
58376 +
58377 +__u32
58378 +gr_acl_handle_creat(const struct dentry * dentry,
58379 + const struct dentry * p_dentry,
58380 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58381 + const int imode)
58382 +{
58383 + return 1;
58384 +}
58385 +
58386 +void
58387 +gr_acl_handle_exit(void)
58388 +{
58389 + return;
58390 +}
58391 +
58392 +int
58393 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58394 +{
58395 + return 1;
58396 +}
58397 +
58398 +void
58399 +gr_set_role_label(const uid_t uid, const gid_t gid)
58400 +{
58401 + return;
58402 +}
58403 +
58404 +int
58405 +gr_acl_handle_procpidmem(const struct task_struct *task)
58406 +{
58407 + return 0;
58408 +}
58409 +
58410 +int
58411 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58412 +{
58413 + return 0;
58414 +}
58415 +
58416 +int
58417 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58418 +{
58419 + return 0;
58420 +}
58421 +
58422 +void
58423 +gr_set_kernel_label(struct task_struct *task)
58424 +{
58425 + return;
58426 +}
58427 +
58428 +int
58429 +gr_check_user_change(int real, int effective, int fs)
58430 +{
58431 + return 0;
58432 +}
58433 +
58434 +int
58435 +gr_check_group_change(int real, int effective, int fs)
58436 +{
58437 + return 0;
58438 +}
58439 +
58440 +int gr_acl_enable_at_secure(void)
58441 +{
58442 + return 0;
58443 +}
58444 +
58445 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58446 +{
58447 + return dentry->d_inode->i_sb->s_dev;
58448 +}
58449 +
58450 +EXPORT_SYMBOL(gr_learn_resource);
58451 +EXPORT_SYMBOL(gr_set_kernel_label);
58452 +#ifdef CONFIG_SECURITY
58453 +EXPORT_SYMBOL(gr_check_user_change);
58454 +EXPORT_SYMBOL(gr_check_group_change);
58455 +#endif
58456 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58457 new file mode 100644
58458 index 0000000..abfa971
58459 --- /dev/null
58460 +++ b/grsecurity/grsec_exec.c
58461 @@ -0,0 +1,174 @@
58462 +#include <linux/kernel.h>
58463 +#include <linux/sched.h>
58464 +#include <linux/file.h>
58465 +#include <linux/binfmts.h>
58466 +#include <linux/fs.h>
58467 +#include <linux/types.h>
58468 +#include <linux/grdefs.h>
58469 +#include <linux/grsecurity.h>
58470 +#include <linux/grinternal.h>
58471 +#include <linux/capability.h>
58472 +#include <linux/module.h>
58473 +
58474 +#include <asm/uaccess.h>
58475 +
58476 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58477 +static char gr_exec_arg_buf[132];
58478 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58479 +#endif
58480 +
58481 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58482 +
58483 +void
58484 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58485 +{
58486 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58487 + char *grarg = gr_exec_arg_buf;
58488 + unsigned int i, x, execlen = 0;
58489 + char c;
58490 +
58491 + if (!((grsec_enable_execlog && grsec_enable_group &&
58492 + in_group_p(grsec_audit_gid))
58493 + || (grsec_enable_execlog && !grsec_enable_group)))
58494 + return;
58495 +
58496 + mutex_lock(&gr_exec_arg_mutex);
58497 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58498 +
58499 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58500 + const char __user *p;
58501 + unsigned int len;
58502 +
58503 + p = get_user_arg_ptr(argv, i);
58504 + if (IS_ERR(p))
58505 + goto log;
58506 +
58507 + len = strnlen_user(p, 128 - execlen);
58508 + if (len > 128 - execlen)
58509 + len = 128 - execlen;
58510 + else if (len > 0)
58511 + len--;
58512 + if (copy_from_user(grarg + execlen, p, len))
58513 + goto log;
58514 +
58515 + /* rewrite unprintable characters */
58516 + for (x = 0; x < len; x++) {
58517 + c = *(grarg + execlen + x);
58518 + if (c < 32 || c > 126)
58519 + *(grarg + execlen + x) = ' ';
58520 + }
58521 +
58522 + execlen += len;
58523 + *(grarg + execlen) = ' ';
58524 + *(grarg + execlen + 1) = '\0';
58525 + execlen++;
58526 + }
58527 +
58528 + log:
58529 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58530 + bprm->file->f_path.mnt, grarg);
58531 + mutex_unlock(&gr_exec_arg_mutex);
58532 +#endif
58533 + return;
58534 +}
58535 +
58536 +#ifdef CONFIG_GRKERNSEC
58537 +extern int gr_acl_is_capable(const int cap);
58538 +extern int gr_acl_is_capable_nolog(const int cap);
58539 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58540 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58541 +extern int gr_chroot_is_capable(const int cap);
58542 +extern int gr_chroot_is_capable_nolog(const int cap);
58543 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58544 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58545 +#endif
58546 +
58547 +const char *captab_log[] = {
58548 + "CAP_CHOWN",
58549 + "CAP_DAC_OVERRIDE",
58550 + "CAP_DAC_READ_SEARCH",
58551 + "CAP_FOWNER",
58552 + "CAP_FSETID",
58553 + "CAP_KILL",
58554 + "CAP_SETGID",
58555 + "CAP_SETUID",
58556 + "CAP_SETPCAP",
58557 + "CAP_LINUX_IMMUTABLE",
58558 + "CAP_NET_BIND_SERVICE",
58559 + "CAP_NET_BROADCAST",
58560 + "CAP_NET_ADMIN",
58561 + "CAP_NET_RAW",
58562 + "CAP_IPC_LOCK",
58563 + "CAP_IPC_OWNER",
58564 + "CAP_SYS_MODULE",
58565 + "CAP_SYS_RAWIO",
58566 + "CAP_SYS_CHROOT",
58567 + "CAP_SYS_PTRACE",
58568 + "CAP_SYS_PACCT",
58569 + "CAP_SYS_ADMIN",
58570 + "CAP_SYS_BOOT",
58571 + "CAP_SYS_NICE",
58572 + "CAP_SYS_RESOURCE",
58573 + "CAP_SYS_TIME",
58574 + "CAP_SYS_TTY_CONFIG",
58575 + "CAP_MKNOD",
58576 + "CAP_LEASE",
58577 + "CAP_AUDIT_WRITE",
58578 + "CAP_AUDIT_CONTROL",
58579 + "CAP_SETFCAP",
58580 + "CAP_MAC_OVERRIDE",
58581 + "CAP_MAC_ADMIN",
58582 + "CAP_SYSLOG",
58583 + "CAP_WAKE_ALARM"
58584 +};
58585 +
58586 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58587 +
58588 +int gr_is_capable(const int cap)
58589 +{
58590 +#ifdef CONFIG_GRKERNSEC
58591 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58592 + return 1;
58593 + return 0;
58594 +#else
58595 + return 1;
58596 +#endif
58597 +}
58598 +
58599 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58600 +{
58601 +#ifdef CONFIG_GRKERNSEC
58602 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58603 + return 1;
58604 + return 0;
58605 +#else
58606 + return 1;
58607 +#endif
58608 +}
58609 +
58610 +int gr_is_capable_nolog(const int cap)
58611 +{
58612 +#ifdef CONFIG_GRKERNSEC
58613 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58614 + return 1;
58615 + return 0;
58616 +#else
58617 + return 1;
58618 +#endif
58619 +}
58620 +
58621 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58622 +{
58623 +#ifdef CONFIG_GRKERNSEC
58624 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58625 + return 1;
58626 + return 0;
58627 +#else
58628 + return 1;
58629 +#endif
58630 +}
58631 +
58632 +EXPORT_SYMBOL(gr_is_capable);
58633 +EXPORT_SYMBOL(gr_is_capable_nolog);
58634 +EXPORT_SYMBOL(gr_task_is_capable);
58635 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58636 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58637 new file mode 100644
58638 index 0000000..d3ee748
58639 --- /dev/null
58640 +++ b/grsecurity/grsec_fifo.c
58641 @@ -0,0 +1,24 @@
58642 +#include <linux/kernel.h>
58643 +#include <linux/sched.h>
58644 +#include <linux/fs.h>
58645 +#include <linux/file.h>
58646 +#include <linux/grinternal.h>
58647 +
58648 +int
58649 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58650 + const struct dentry *dir, const int flag, const int acc_mode)
58651 +{
58652 +#ifdef CONFIG_GRKERNSEC_FIFO
58653 + const struct cred *cred = current_cred();
58654 +
58655 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58656 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58657 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58658 + (cred->fsuid != dentry->d_inode->i_uid)) {
58659 + if (!inode_permission(dentry->d_inode, acc_mode))
58660 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58661 + return -EACCES;
58662 + }
58663 +#endif
58664 + return 0;
58665 +}
58666 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58667 new file mode 100644
58668 index 0000000..8ca18bf
58669 --- /dev/null
58670 +++ b/grsecurity/grsec_fork.c
58671 @@ -0,0 +1,23 @@
58672 +#include <linux/kernel.h>
58673 +#include <linux/sched.h>
58674 +#include <linux/grsecurity.h>
58675 +#include <linux/grinternal.h>
58676 +#include <linux/errno.h>
58677 +
58678 +void
58679 +gr_log_forkfail(const int retval)
58680 +{
58681 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58682 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58683 + switch (retval) {
58684 + case -EAGAIN:
58685 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58686 + break;
58687 + case -ENOMEM:
58688 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58689 + break;
58690 + }
58691 + }
58692 +#endif
58693 + return;
58694 +}
58695 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58696 new file mode 100644
58697 index 0000000..05a6015
58698 --- /dev/null
58699 +++ b/grsecurity/grsec_init.c
58700 @@ -0,0 +1,283 @@
58701 +#include <linux/kernel.h>
58702 +#include <linux/sched.h>
58703 +#include <linux/mm.h>
58704 +#include <linux/gracl.h>
58705 +#include <linux/slab.h>
58706 +#include <linux/vmalloc.h>
58707 +#include <linux/percpu.h>
58708 +#include <linux/module.h>
58709 +
58710 +int grsec_enable_ptrace_readexec;
58711 +int grsec_enable_setxid;
58712 +int grsec_enable_symlinkown;
58713 +int grsec_symlinkown_gid;
58714 +int grsec_enable_brute;
58715 +int grsec_enable_link;
58716 +int grsec_enable_dmesg;
58717 +int grsec_enable_harden_ptrace;
58718 +int grsec_enable_fifo;
58719 +int grsec_enable_execlog;
58720 +int grsec_enable_signal;
58721 +int grsec_enable_forkfail;
58722 +int grsec_enable_audit_ptrace;
58723 +int grsec_enable_time;
58724 +int grsec_enable_audit_textrel;
58725 +int grsec_enable_group;
58726 +int grsec_audit_gid;
58727 +int grsec_enable_chdir;
58728 +int grsec_enable_mount;
58729 +int grsec_enable_rofs;
58730 +int grsec_enable_chroot_findtask;
58731 +int grsec_enable_chroot_mount;
58732 +int grsec_enable_chroot_shmat;
58733 +int grsec_enable_chroot_fchdir;
58734 +int grsec_enable_chroot_double;
58735 +int grsec_enable_chroot_pivot;
58736 +int grsec_enable_chroot_chdir;
58737 +int grsec_enable_chroot_chmod;
58738 +int grsec_enable_chroot_mknod;
58739 +int grsec_enable_chroot_nice;
58740 +int grsec_enable_chroot_execlog;
58741 +int grsec_enable_chroot_caps;
58742 +int grsec_enable_chroot_sysctl;
58743 +int grsec_enable_chroot_unix;
58744 +int grsec_enable_tpe;
58745 +int grsec_tpe_gid;
58746 +int grsec_enable_blackhole;
58747 +#ifdef CONFIG_IPV6_MODULE
58748 +EXPORT_SYMBOL(grsec_enable_blackhole);
58749 +#endif
58750 +int grsec_lastack_retries;
58751 +int grsec_enable_tpe_all;
58752 +int grsec_enable_tpe_invert;
58753 +int grsec_enable_socket_all;
58754 +int grsec_socket_all_gid;
58755 +int grsec_enable_socket_client;
58756 +int grsec_socket_client_gid;
58757 +int grsec_enable_socket_server;
58758 +int grsec_socket_server_gid;
58759 +int grsec_resource_logging;
58760 +int grsec_disable_privio;
58761 +int grsec_enable_log_rwxmaps;
58762 +int grsec_lock;
58763 +
58764 +DEFINE_SPINLOCK(grsec_alert_lock);
58765 +unsigned long grsec_alert_wtime = 0;
58766 +unsigned long grsec_alert_fyet = 0;
58767 +
58768 +DEFINE_SPINLOCK(grsec_audit_lock);
58769 +
58770 +DEFINE_RWLOCK(grsec_exec_file_lock);
58771 +
58772 +char *gr_shared_page[4];
58773 +
58774 +char *gr_alert_log_fmt;
58775 +char *gr_audit_log_fmt;
58776 +char *gr_alert_log_buf;
58777 +char *gr_audit_log_buf;
58778 +
58779 +extern struct gr_arg *gr_usermode;
58780 +extern unsigned char *gr_system_salt;
58781 +extern unsigned char *gr_system_sum;
58782 +
58783 +void __init
58784 +grsecurity_init(void)
58785 +{
58786 + int j;
58787 + /* create the per-cpu shared pages */
58788 +
58789 +#ifdef CONFIG_X86
58790 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58791 +#endif
58792 +
58793 + for (j = 0; j < 4; j++) {
58794 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58795 + if (gr_shared_page[j] == NULL) {
58796 + panic("Unable to allocate grsecurity shared page");
58797 + return;
58798 + }
58799 + }
58800 +
58801 + /* allocate log buffers */
58802 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58803 + if (!gr_alert_log_fmt) {
58804 + panic("Unable to allocate grsecurity alert log format buffer");
58805 + return;
58806 + }
58807 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58808 + if (!gr_audit_log_fmt) {
58809 + panic("Unable to allocate grsecurity audit log format buffer");
58810 + return;
58811 + }
58812 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58813 + if (!gr_alert_log_buf) {
58814 + panic("Unable to allocate grsecurity alert log buffer");
58815 + return;
58816 + }
58817 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58818 + if (!gr_audit_log_buf) {
58819 + panic("Unable to allocate grsecurity audit log buffer");
58820 + return;
58821 + }
58822 +
58823 + /* allocate memory for authentication structure */
58824 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58825 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58826 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58827 +
58828 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58829 + panic("Unable to allocate grsecurity authentication structure");
58830 + return;
58831 + }
58832 +
58833 +
58834 +#ifdef CONFIG_GRKERNSEC_IO
58835 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58836 + grsec_disable_privio = 1;
58837 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58838 + grsec_disable_privio = 1;
58839 +#else
58840 + grsec_disable_privio = 0;
58841 +#endif
58842 +#endif
58843 +
58844 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58845 + /* for backward compatibility, tpe_invert always defaults to on if
58846 + enabled in the kernel
58847 + */
58848 + grsec_enable_tpe_invert = 1;
58849 +#endif
58850 +
58851 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58852 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58853 + grsec_lock = 1;
58854 +#endif
58855 +
58856 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58857 + grsec_enable_audit_textrel = 1;
58858 +#endif
58859 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58860 + grsec_enable_log_rwxmaps = 1;
58861 +#endif
58862 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58863 + grsec_enable_group = 1;
58864 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58865 +#endif
58866 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58867 + grsec_enable_ptrace_readexec = 1;
58868 +#endif
58869 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58870 + grsec_enable_chdir = 1;
58871 +#endif
58872 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58873 + grsec_enable_harden_ptrace = 1;
58874 +#endif
58875 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58876 + grsec_enable_mount = 1;
58877 +#endif
58878 +#ifdef CONFIG_GRKERNSEC_LINK
58879 + grsec_enable_link = 1;
58880 +#endif
58881 +#ifdef CONFIG_GRKERNSEC_BRUTE
58882 + grsec_enable_brute = 1;
58883 +#endif
58884 +#ifdef CONFIG_GRKERNSEC_DMESG
58885 + grsec_enable_dmesg = 1;
58886 +#endif
58887 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58888 + grsec_enable_blackhole = 1;
58889 + grsec_lastack_retries = 4;
58890 +#endif
58891 +#ifdef CONFIG_GRKERNSEC_FIFO
58892 + grsec_enable_fifo = 1;
58893 +#endif
58894 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58895 + grsec_enable_execlog = 1;
58896 +#endif
58897 +#ifdef CONFIG_GRKERNSEC_SETXID
58898 + grsec_enable_setxid = 1;
58899 +#endif
58900 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58901 + grsec_enable_signal = 1;
58902 +#endif
58903 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58904 + grsec_enable_forkfail = 1;
58905 +#endif
58906 +#ifdef CONFIG_GRKERNSEC_TIME
58907 + grsec_enable_time = 1;
58908 +#endif
58909 +#ifdef CONFIG_GRKERNSEC_RESLOG
58910 + grsec_resource_logging = 1;
58911 +#endif
58912 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58913 + grsec_enable_chroot_findtask = 1;
58914 +#endif
58915 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58916 + grsec_enable_chroot_unix = 1;
58917 +#endif
58918 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58919 + grsec_enable_chroot_mount = 1;
58920 +#endif
58921 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58922 + grsec_enable_chroot_fchdir = 1;
58923 +#endif
58924 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58925 + grsec_enable_chroot_shmat = 1;
58926 +#endif
58927 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58928 + grsec_enable_audit_ptrace = 1;
58929 +#endif
58930 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58931 + grsec_enable_chroot_double = 1;
58932 +#endif
58933 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58934 + grsec_enable_chroot_pivot = 1;
58935 +#endif
58936 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58937 + grsec_enable_chroot_chdir = 1;
58938 +#endif
58939 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58940 + grsec_enable_chroot_chmod = 1;
58941 +#endif
58942 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58943 + grsec_enable_chroot_mknod = 1;
58944 +#endif
58945 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58946 + grsec_enable_chroot_nice = 1;
58947 +#endif
58948 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58949 + grsec_enable_chroot_execlog = 1;
58950 +#endif
58951 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58952 + grsec_enable_chroot_caps = 1;
58953 +#endif
58954 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58955 + grsec_enable_chroot_sysctl = 1;
58956 +#endif
58957 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58958 + grsec_enable_symlinkown = 1;
58959 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58960 +#endif
58961 +#ifdef CONFIG_GRKERNSEC_TPE
58962 + grsec_enable_tpe = 1;
58963 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58964 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58965 + grsec_enable_tpe_all = 1;
58966 +#endif
58967 +#endif
58968 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58969 + grsec_enable_socket_all = 1;
58970 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58971 +#endif
58972 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58973 + grsec_enable_socket_client = 1;
58974 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58975 +#endif
58976 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58977 + grsec_enable_socket_server = 1;
58978 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58979 +#endif
58980 +#endif
58981 +
58982 + return;
58983 +}
58984 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58985 new file mode 100644
58986 index 0000000..589481f
58987 --- /dev/null
58988 +++ b/grsecurity/grsec_link.c
58989 @@ -0,0 +1,58 @@
58990 +#include <linux/kernel.h>
58991 +#include <linux/sched.h>
58992 +#include <linux/fs.h>
58993 +#include <linux/file.h>
58994 +#include <linux/grinternal.h>
58995 +
58996 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58997 +{
58998 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58999 + const struct inode *link_inode = link->dentry->d_inode;
59000 +
59001 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59002 + /* ignore root-owned links, e.g. /proc/self */
59003 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59004 + !uid_eq(link_inode->i_uid, target->i_uid)) {
59005 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59006 + return 1;
59007 + }
59008 +#endif
59009 + return 0;
59010 +}
59011 +
59012 +int
59013 +gr_handle_follow_link(const struct inode *parent,
59014 + const struct inode *inode,
59015 + const struct dentry *dentry, const struct vfsmount *mnt)
59016 +{
59017 +#ifdef CONFIG_GRKERNSEC_LINK
59018 + const struct cred *cred = current_cred();
59019 +
59020 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59021 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59022 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59023 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59024 + return -EACCES;
59025 + }
59026 +#endif
59027 + return 0;
59028 +}
59029 +
59030 +int
59031 +gr_handle_hardlink(const struct dentry *dentry,
59032 + const struct vfsmount *mnt,
59033 + struct inode *inode, const int mode, const char *to)
59034 +{
59035 +#ifdef CONFIG_GRKERNSEC_LINK
59036 + const struct cred *cred = current_cred();
59037 +
59038 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59039 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59040 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59041 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59042 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59043 + return -EPERM;
59044 + }
59045 +#endif
59046 + return 0;
59047 +}
59048 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59049 new file mode 100644
59050 index 0000000..a45d2e9
59051 --- /dev/null
59052 +++ b/grsecurity/grsec_log.c
59053 @@ -0,0 +1,322 @@
59054 +#include <linux/kernel.h>
59055 +#include <linux/sched.h>
59056 +#include <linux/file.h>
59057 +#include <linux/tty.h>
59058 +#include <linux/fs.h>
59059 +#include <linux/grinternal.h>
59060 +
59061 +#ifdef CONFIG_TREE_PREEMPT_RCU
59062 +#define DISABLE_PREEMPT() preempt_disable()
59063 +#define ENABLE_PREEMPT() preempt_enable()
59064 +#else
59065 +#define DISABLE_PREEMPT()
59066 +#define ENABLE_PREEMPT()
59067 +#endif
59068 +
59069 +#define BEGIN_LOCKS(x) \
59070 + DISABLE_PREEMPT(); \
59071 + rcu_read_lock(); \
59072 + read_lock(&tasklist_lock); \
59073 + read_lock(&grsec_exec_file_lock); \
59074 + if (x != GR_DO_AUDIT) \
59075 + spin_lock(&grsec_alert_lock); \
59076 + else \
59077 + spin_lock(&grsec_audit_lock)
59078 +
59079 +#define END_LOCKS(x) \
59080 + if (x != GR_DO_AUDIT) \
59081 + spin_unlock(&grsec_alert_lock); \
59082 + else \
59083 + spin_unlock(&grsec_audit_lock); \
59084 + read_unlock(&grsec_exec_file_lock); \
59085 + read_unlock(&tasklist_lock); \
59086 + rcu_read_unlock(); \
59087 + ENABLE_PREEMPT(); \
59088 + if (x == GR_DONT_AUDIT) \
59089 + gr_handle_alertkill(current)
59090 +
59091 +enum {
59092 + FLOODING,
59093 + NO_FLOODING
59094 +};
59095 +
59096 +extern char *gr_alert_log_fmt;
59097 +extern char *gr_audit_log_fmt;
59098 +extern char *gr_alert_log_buf;
59099 +extern char *gr_audit_log_buf;
59100 +
59101 +static int gr_log_start(int audit)
59102 +{
59103 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59104 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59105 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59106 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59107 + unsigned long curr_secs = get_seconds();
59108 +
59109 + if (audit == GR_DO_AUDIT)
59110 + goto set_fmt;
59111 +
59112 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59113 + grsec_alert_wtime = curr_secs;
59114 + grsec_alert_fyet = 0;
59115 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59116 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59117 + grsec_alert_fyet++;
59118 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59119 + grsec_alert_wtime = curr_secs;
59120 + grsec_alert_fyet++;
59121 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59122 + return FLOODING;
59123 + }
59124 + else return FLOODING;
59125 +
59126 +set_fmt:
59127 +#endif
59128 + memset(buf, 0, PAGE_SIZE);
59129 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59130 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59131 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59132 + } else if (current->signal->curr_ip) {
59133 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59134 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59135 + } else if (gr_acl_is_enabled()) {
59136 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59137 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59138 + } else {
59139 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59140 + strcpy(buf, fmt);
59141 + }
59142 +
59143 + return NO_FLOODING;
59144 +}
59145 +
59146 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59147 + __attribute__ ((format (printf, 2, 0)));
59148 +
59149 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59150 +{
59151 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59152 + unsigned int len = strlen(buf);
59153 +
59154 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59155 +
59156 + return;
59157 +}
59158 +
59159 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59160 + __attribute__ ((format (printf, 2, 3)));
59161 +
59162 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59163 +{
59164 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59165 + unsigned int len = strlen(buf);
59166 + va_list ap;
59167 +
59168 + va_start(ap, msg);
59169 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59170 + va_end(ap);
59171 +
59172 + return;
59173 +}
59174 +
59175 +static void gr_log_end(int audit, int append_default)
59176 +{
59177 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59178 +
59179 + if (append_default) {
59180 + unsigned int len = strlen(buf);
59181 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59182 + }
59183 +
59184 + printk("%s\n", buf);
59185 +
59186 + return;
59187 +}
59188 +
59189 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59190 +{
59191 + int logtype;
59192 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59193 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59194 + void *voidptr = NULL;
59195 + int num1 = 0, num2 = 0;
59196 + unsigned long ulong1 = 0, ulong2 = 0;
59197 + struct dentry *dentry = NULL;
59198 + struct vfsmount *mnt = NULL;
59199 + struct file *file = NULL;
59200 + struct task_struct *task = NULL;
59201 + const struct cred *cred, *pcred;
59202 + va_list ap;
59203 +
59204 + BEGIN_LOCKS(audit);
59205 + logtype = gr_log_start(audit);
59206 + if (logtype == FLOODING) {
59207 + END_LOCKS(audit);
59208 + return;
59209 + }
59210 + va_start(ap, argtypes);
59211 + switch (argtypes) {
59212 + case GR_TTYSNIFF:
59213 + task = va_arg(ap, struct task_struct *);
59214 + 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);
59215 + break;
59216 + case GR_SYSCTL_HIDDEN:
59217 + str1 = va_arg(ap, char *);
59218 + gr_log_middle_varargs(audit, msg, result, str1);
59219 + break;
59220 + case GR_RBAC:
59221 + dentry = va_arg(ap, struct dentry *);
59222 + mnt = va_arg(ap, struct vfsmount *);
59223 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59224 + break;
59225 + case GR_RBAC_STR:
59226 + dentry = va_arg(ap, struct dentry *);
59227 + mnt = va_arg(ap, struct vfsmount *);
59228 + str1 = va_arg(ap, char *);
59229 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59230 + break;
59231 + case GR_STR_RBAC:
59232 + str1 = va_arg(ap, char *);
59233 + dentry = va_arg(ap, struct dentry *);
59234 + mnt = va_arg(ap, struct vfsmount *);
59235 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59236 + break;
59237 + case GR_RBAC_MODE2:
59238 + dentry = va_arg(ap, struct dentry *);
59239 + mnt = va_arg(ap, struct vfsmount *);
59240 + str1 = va_arg(ap, char *);
59241 + str2 = va_arg(ap, char *);
59242 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59243 + break;
59244 + case GR_RBAC_MODE3:
59245 + dentry = va_arg(ap, struct dentry *);
59246 + mnt = va_arg(ap, struct vfsmount *);
59247 + str1 = va_arg(ap, char *);
59248 + str2 = va_arg(ap, char *);
59249 + str3 = va_arg(ap, char *);
59250 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59251 + break;
59252 + case GR_FILENAME:
59253 + dentry = va_arg(ap, struct dentry *);
59254 + mnt = va_arg(ap, struct vfsmount *);
59255 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59256 + break;
59257 + case GR_STR_FILENAME:
59258 + str1 = va_arg(ap, char *);
59259 + dentry = va_arg(ap, struct dentry *);
59260 + mnt = va_arg(ap, struct vfsmount *);
59261 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59262 + break;
59263 + case GR_FILENAME_STR:
59264 + dentry = va_arg(ap, struct dentry *);
59265 + mnt = va_arg(ap, struct vfsmount *);
59266 + str1 = va_arg(ap, char *);
59267 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59268 + break;
59269 + case GR_FILENAME_TWO_INT:
59270 + dentry = va_arg(ap, struct dentry *);
59271 + mnt = va_arg(ap, struct vfsmount *);
59272 + num1 = va_arg(ap, int);
59273 + num2 = va_arg(ap, int);
59274 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59275 + break;
59276 + case GR_FILENAME_TWO_INT_STR:
59277 + dentry = va_arg(ap, struct dentry *);
59278 + mnt = va_arg(ap, struct vfsmount *);
59279 + num1 = va_arg(ap, int);
59280 + num2 = va_arg(ap, int);
59281 + str1 = va_arg(ap, char *);
59282 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59283 + break;
59284 + case GR_TEXTREL:
59285 + file = va_arg(ap, struct file *);
59286 + ulong1 = va_arg(ap, unsigned long);
59287 + ulong2 = va_arg(ap, unsigned long);
59288 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59289 + break;
59290 + case GR_PTRACE:
59291 + task = va_arg(ap, struct task_struct *);
59292 + 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);
59293 + break;
59294 + case GR_RESOURCE:
59295 + task = va_arg(ap, struct task_struct *);
59296 + cred = __task_cred(task);
59297 + pcred = __task_cred(task->real_parent);
59298 + ulong1 = va_arg(ap, unsigned long);
59299 + str1 = va_arg(ap, char *);
59300 + ulong2 = va_arg(ap, unsigned long);
59301 + 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);
59302 + break;
59303 + case GR_CAP:
59304 + task = va_arg(ap, struct task_struct *);
59305 + cred = __task_cred(task);
59306 + pcred = __task_cred(task->real_parent);
59307 + str1 = va_arg(ap, char *);
59308 + 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);
59309 + break;
59310 + case GR_SIG:
59311 + str1 = va_arg(ap, char *);
59312 + voidptr = va_arg(ap, void *);
59313 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59314 + break;
59315 + case GR_SIG2:
59316 + task = va_arg(ap, struct task_struct *);
59317 + cred = __task_cred(task);
59318 + pcred = __task_cred(task->real_parent);
59319 + num1 = va_arg(ap, int);
59320 + 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);
59321 + break;
59322 + case GR_CRASH1:
59323 + task = va_arg(ap, struct task_struct *);
59324 + cred = __task_cred(task);
59325 + pcred = __task_cred(task->real_parent);
59326 + ulong1 = va_arg(ap, unsigned long);
59327 + 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);
59328 + break;
59329 + case GR_CRASH2:
59330 + task = va_arg(ap, struct task_struct *);
59331 + cred = __task_cred(task);
59332 + pcred = __task_cred(task->real_parent);
59333 + ulong1 = va_arg(ap, unsigned long);
59334 + 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);
59335 + break;
59336 + case GR_RWXMAP:
59337 + file = va_arg(ap, struct file *);
59338 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59339 + break;
59340 + case GR_PSACCT:
59341 + {
59342 + unsigned int wday, cday;
59343 + __u8 whr, chr;
59344 + __u8 wmin, cmin;
59345 + __u8 wsec, csec;
59346 + char cur_tty[64] = { 0 };
59347 + char parent_tty[64] = { 0 };
59348 +
59349 + task = va_arg(ap, struct task_struct *);
59350 + wday = va_arg(ap, unsigned int);
59351 + cday = va_arg(ap, unsigned int);
59352 + whr = va_arg(ap, int);
59353 + chr = va_arg(ap, int);
59354 + wmin = va_arg(ap, int);
59355 + cmin = va_arg(ap, int);
59356 + wsec = va_arg(ap, int);
59357 + csec = va_arg(ap, int);
59358 + ulong1 = va_arg(ap, unsigned long);
59359 + cred = __task_cred(task);
59360 + pcred = __task_cred(task->real_parent);
59361 +
59362 + 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);
59363 + }
59364 + break;
59365 + default:
59366 + gr_log_middle(audit, msg, ap);
59367 + }
59368 + va_end(ap);
59369 + // these don't need DEFAULTSECARGS printed on the end
59370 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59371 + gr_log_end(audit, 0);
59372 + else
59373 + gr_log_end(audit, 1);
59374 + END_LOCKS(audit);
59375 +}
59376 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59377 new file mode 100644
59378 index 0000000..f536303
59379 --- /dev/null
59380 +++ b/grsecurity/grsec_mem.c
59381 @@ -0,0 +1,40 @@
59382 +#include <linux/kernel.h>
59383 +#include <linux/sched.h>
59384 +#include <linux/mm.h>
59385 +#include <linux/mman.h>
59386 +#include <linux/grinternal.h>
59387 +
59388 +void
59389 +gr_handle_ioperm(void)
59390 +{
59391 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59392 + return;
59393 +}
59394 +
59395 +void
59396 +gr_handle_iopl(void)
59397 +{
59398 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59399 + return;
59400 +}
59401 +
59402 +void
59403 +gr_handle_mem_readwrite(u64 from, u64 to)
59404 +{
59405 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59406 + return;
59407 +}
59408 +
59409 +void
59410 +gr_handle_vm86(void)
59411 +{
59412 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59413 + return;
59414 +}
59415 +
59416 +void
59417 +gr_log_badprocpid(const char *entry)
59418 +{
59419 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59420 + return;
59421 +}
59422 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59423 new file mode 100644
59424 index 0000000..2131422
59425 --- /dev/null
59426 +++ b/grsecurity/grsec_mount.c
59427 @@ -0,0 +1,62 @@
59428 +#include <linux/kernel.h>
59429 +#include <linux/sched.h>
59430 +#include <linux/mount.h>
59431 +#include <linux/grsecurity.h>
59432 +#include <linux/grinternal.h>
59433 +
59434 +void
59435 +gr_log_remount(const char *devname, const int retval)
59436 +{
59437 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59438 + if (grsec_enable_mount && (retval >= 0))
59439 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59440 +#endif
59441 + return;
59442 +}
59443 +
59444 +void
59445 +gr_log_unmount(const char *devname, const int retval)
59446 +{
59447 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59448 + if (grsec_enable_mount && (retval >= 0))
59449 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59450 +#endif
59451 + return;
59452 +}
59453 +
59454 +void
59455 +gr_log_mount(const char *from, const char *to, const int retval)
59456 +{
59457 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59458 + if (grsec_enable_mount && (retval >= 0))
59459 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59460 +#endif
59461 + return;
59462 +}
59463 +
59464 +int
59465 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59466 +{
59467 +#ifdef CONFIG_GRKERNSEC_ROFS
59468 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59469 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59470 + return -EPERM;
59471 + } else
59472 + return 0;
59473 +#endif
59474 + return 0;
59475 +}
59476 +
59477 +int
59478 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59479 +{
59480 +#ifdef CONFIG_GRKERNSEC_ROFS
59481 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59482 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59483 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59484 + return -EPERM;
59485 + } else
59486 + return 0;
59487 +#endif
59488 + return 0;
59489 +}
59490 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59491 new file mode 100644
59492 index 0000000..a3b12a0
59493 --- /dev/null
59494 +++ b/grsecurity/grsec_pax.c
59495 @@ -0,0 +1,36 @@
59496 +#include <linux/kernel.h>
59497 +#include <linux/sched.h>
59498 +#include <linux/mm.h>
59499 +#include <linux/file.h>
59500 +#include <linux/grinternal.h>
59501 +#include <linux/grsecurity.h>
59502 +
59503 +void
59504 +gr_log_textrel(struct vm_area_struct * vma)
59505 +{
59506 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59507 + if (grsec_enable_audit_textrel)
59508 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59509 +#endif
59510 + return;
59511 +}
59512 +
59513 +void
59514 +gr_log_rwxmmap(struct file *file)
59515 +{
59516 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59517 + if (grsec_enable_log_rwxmaps)
59518 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59519 +#endif
59520 + return;
59521 +}
59522 +
59523 +void
59524 +gr_log_rwxmprotect(struct file *file)
59525 +{
59526 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59527 + if (grsec_enable_log_rwxmaps)
59528 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59529 +#endif
59530 + return;
59531 +}
59532 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59533 new file mode 100644
59534 index 0000000..f7f29aa
59535 --- /dev/null
59536 +++ b/grsecurity/grsec_ptrace.c
59537 @@ -0,0 +1,30 @@
59538 +#include <linux/kernel.h>
59539 +#include <linux/sched.h>
59540 +#include <linux/grinternal.h>
59541 +#include <linux/security.h>
59542 +
59543 +void
59544 +gr_audit_ptrace(struct task_struct *task)
59545 +{
59546 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59547 + if (grsec_enable_audit_ptrace)
59548 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59549 +#endif
59550 + return;
59551 +}
59552 +
59553 +int
59554 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59555 +{
59556 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59557 + const struct dentry *dentry = file->f_path.dentry;
59558 + const struct vfsmount *mnt = file->f_path.mnt;
59559 +
59560 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59561 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59562 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59563 + return -EACCES;
59564 + }
59565 +#endif
59566 + return 0;
59567 +}
59568 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59569 new file mode 100644
59570 index 0000000..b4ac94c
59571 --- /dev/null
59572 +++ b/grsecurity/grsec_sig.c
59573 @@ -0,0 +1,209 @@
59574 +#include <linux/kernel.h>
59575 +#include <linux/sched.h>
59576 +#include <linux/delay.h>
59577 +#include <linux/grsecurity.h>
59578 +#include <linux/grinternal.h>
59579 +#include <linux/hardirq.h>
59580 +
59581 +char *signames[] = {
59582 + [SIGSEGV] = "Segmentation fault",
59583 + [SIGILL] = "Illegal instruction",
59584 + [SIGABRT] = "Abort",
59585 + [SIGBUS] = "Invalid alignment/Bus error"
59586 +};
59587 +
59588 +void
59589 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59590 +{
59591 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59592 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59593 + (sig == SIGABRT) || (sig == SIGBUS))) {
59594 + if (t->pid == current->pid) {
59595 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59596 + } else {
59597 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59598 + }
59599 + }
59600 +#endif
59601 + return;
59602 +}
59603 +
59604 +int
59605 +gr_handle_signal(const struct task_struct *p, const int sig)
59606 +{
59607 +#ifdef CONFIG_GRKERNSEC
59608 + /* ignore the 0 signal for protected task checks */
59609 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59610 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59611 + return -EPERM;
59612 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59613 + return -EPERM;
59614 + }
59615 +#endif
59616 + return 0;
59617 +}
59618 +
59619 +#ifdef CONFIG_GRKERNSEC
59620 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59621 +
59622 +int gr_fake_force_sig(int sig, struct task_struct *t)
59623 +{
59624 + unsigned long int flags;
59625 + int ret, blocked, ignored;
59626 + struct k_sigaction *action;
59627 +
59628 + spin_lock_irqsave(&t->sighand->siglock, flags);
59629 + action = &t->sighand->action[sig-1];
59630 + ignored = action->sa.sa_handler == SIG_IGN;
59631 + blocked = sigismember(&t->blocked, sig);
59632 + if (blocked || ignored) {
59633 + action->sa.sa_handler = SIG_DFL;
59634 + if (blocked) {
59635 + sigdelset(&t->blocked, sig);
59636 + recalc_sigpending_and_wake(t);
59637 + }
59638 + }
59639 + if (action->sa.sa_handler == SIG_DFL)
59640 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59641 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59642 +
59643 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59644 +
59645 + return ret;
59646 +}
59647 +#endif
59648 +
59649 +#ifdef CONFIG_GRKERNSEC_BRUTE
59650 +#define GR_USER_BAN_TIME (15 * 60)
59651 +
59652 +static int __get_dumpable(unsigned long mm_flags)
59653 +{
59654 + int ret;
59655 +
59656 + ret = mm_flags & MMF_DUMPABLE_MASK;
59657 + return (ret >= 2) ? 2 : ret;
59658 +}
59659 +#endif
59660 +
59661 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59662 +{
59663 +#ifdef CONFIG_GRKERNSEC_BRUTE
59664 + kuid_t uid = GLOBAL_ROOT_UID;
59665 +
59666 + if (!grsec_enable_brute)
59667 + return;
59668 +
59669 + rcu_read_lock();
59670 + read_lock(&tasklist_lock);
59671 + read_lock(&grsec_exec_file_lock);
59672 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59673 + p->real_parent->brute = 1;
59674 + else {
59675 + const struct cred *cred = __task_cred(p), *cred2;
59676 + struct task_struct *tsk, *tsk2;
59677 +
59678 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59679 + struct user_struct *user;
59680 +
59681 + uid = cred->uid;
59682 +
59683 + /* this is put upon execution past expiration */
59684 + user = find_user(uid);
59685 + if (user == NULL)
59686 + goto unlock;
59687 + user->banned = 1;
59688 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59689 + if (user->ban_expires == ~0UL)
59690 + user->ban_expires--;
59691 +
59692 + do_each_thread(tsk2, tsk) {
59693 + cred2 = __task_cred(tsk);
59694 + if (tsk != p && uid_eq(cred2->uid, uid))
59695 + gr_fake_force_sig(SIGKILL, tsk);
59696 + } while_each_thread(tsk2, tsk);
59697 + }
59698 + }
59699 +unlock:
59700 + read_unlock(&grsec_exec_file_lock);
59701 + read_unlock(&tasklist_lock);
59702 + rcu_read_unlock();
59703 +
59704 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59705 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59706 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59707 +
59708 +#endif
59709 + return;
59710 +}
59711 +
59712 +void gr_handle_brute_check(void)
59713 +{
59714 +#ifdef CONFIG_GRKERNSEC_BRUTE
59715 + if (current->brute)
59716 + msleep(30 * 1000);
59717 +#endif
59718 + return;
59719 +}
59720 +
59721 +void gr_handle_kernel_exploit(void)
59722 +{
59723 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59724 + const struct cred *cred;
59725 + struct task_struct *tsk, *tsk2;
59726 + struct user_struct *user;
59727 + kuid_t uid;
59728 +
59729 + if (in_irq() || in_serving_softirq() || in_nmi())
59730 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59731 +
59732 + uid = current_uid();
59733 +
59734 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59735 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59736 + else {
59737 + /* kill all the processes of this user, hold a reference
59738 + to their creds struct, and prevent them from creating
59739 + another process until system reset
59740 + */
59741 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59742 + from_kuid_munged(&init_user_ns, uid));
59743 + /* we intentionally leak this ref */
59744 + user = get_uid(current->cred->user);
59745 + if (user) {
59746 + user->banned = 1;
59747 + user->ban_expires = ~0UL;
59748 + }
59749 +
59750 + read_lock(&tasklist_lock);
59751 + do_each_thread(tsk2, tsk) {
59752 + cred = __task_cred(tsk);
59753 + if (uid_eq(cred->uid, uid))
59754 + gr_fake_force_sig(SIGKILL, tsk);
59755 + } while_each_thread(tsk2, tsk);
59756 + read_unlock(&tasklist_lock);
59757 + }
59758 +#endif
59759 +}
59760 +
59761 +int __gr_process_user_ban(struct user_struct *user)
59762 +{
59763 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59764 + if (unlikely(user->banned)) {
59765 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59766 + user->banned = 0;
59767 + user->ban_expires = 0;
59768 + free_uid(user);
59769 + } else
59770 + return -EPERM;
59771 + }
59772 +#endif
59773 + return 0;
59774 +}
59775 +
59776 +int gr_process_user_ban(void)
59777 +{
59778 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59779 + return __gr_process_user_ban(current->cred->user);
59780 +#endif
59781 + return 0;
59782 +}
59783 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59784 new file mode 100644
59785 index 0000000..4030d57
59786 --- /dev/null
59787 +++ b/grsecurity/grsec_sock.c
59788 @@ -0,0 +1,244 @@
59789 +#include <linux/kernel.h>
59790 +#include <linux/module.h>
59791 +#include <linux/sched.h>
59792 +#include <linux/file.h>
59793 +#include <linux/net.h>
59794 +#include <linux/in.h>
59795 +#include <linux/ip.h>
59796 +#include <net/sock.h>
59797 +#include <net/inet_sock.h>
59798 +#include <linux/grsecurity.h>
59799 +#include <linux/grinternal.h>
59800 +#include <linux/gracl.h>
59801 +
59802 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59803 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59804 +
59805 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59806 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59807 +
59808 +#ifdef CONFIG_UNIX_MODULE
59809 +EXPORT_SYMBOL(gr_acl_handle_unix);
59810 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59811 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59812 +EXPORT_SYMBOL(gr_handle_create);
59813 +#endif
59814 +
59815 +#ifdef CONFIG_GRKERNSEC
59816 +#define gr_conn_table_size 32749
59817 +struct conn_table_entry {
59818 + struct conn_table_entry *next;
59819 + struct signal_struct *sig;
59820 +};
59821 +
59822 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59823 +DEFINE_SPINLOCK(gr_conn_table_lock);
59824 +
59825 +extern const char * gr_socktype_to_name(unsigned char type);
59826 +extern const char * gr_proto_to_name(unsigned char proto);
59827 +extern const char * gr_sockfamily_to_name(unsigned char family);
59828 +
59829 +static __inline__ int
59830 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59831 +{
59832 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59833 +}
59834 +
59835 +static __inline__ int
59836 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59837 + __u16 sport, __u16 dport)
59838 +{
59839 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59840 + sig->gr_sport == sport && sig->gr_dport == dport))
59841 + return 1;
59842 + else
59843 + return 0;
59844 +}
59845 +
59846 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59847 +{
59848 + struct conn_table_entry **match;
59849 + unsigned int index;
59850 +
59851 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59852 + sig->gr_sport, sig->gr_dport,
59853 + gr_conn_table_size);
59854 +
59855 + newent->sig = sig;
59856 +
59857 + match = &gr_conn_table[index];
59858 + newent->next = *match;
59859 + *match = newent;
59860 +
59861 + return;
59862 +}
59863 +
59864 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59865 +{
59866 + struct conn_table_entry *match, *last = NULL;
59867 + unsigned int index;
59868 +
59869 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59870 + sig->gr_sport, sig->gr_dport,
59871 + gr_conn_table_size);
59872 +
59873 + match = gr_conn_table[index];
59874 + while (match && !conn_match(match->sig,
59875 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59876 + sig->gr_dport)) {
59877 + last = match;
59878 + match = match->next;
59879 + }
59880 +
59881 + if (match) {
59882 + if (last)
59883 + last->next = match->next;
59884 + else
59885 + gr_conn_table[index] = NULL;
59886 + kfree(match);
59887 + }
59888 +
59889 + return;
59890 +}
59891 +
59892 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59893 + __u16 sport, __u16 dport)
59894 +{
59895 + struct conn_table_entry *match;
59896 + unsigned int index;
59897 +
59898 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59899 +
59900 + match = gr_conn_table[index];
59901 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59902 + match = match->next;
59903 +
59904 + if (match)
59905 + return match->sig;
59906 + else
59907 + return NULL;
59908 +}
59909 +
59910 +#endif
59911 +
59912 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59913 +{
59914 +#ifdef CONFIG_GRKERNSEC
59915 + struct signal_struct *sig = task->signal;
59916 + struct conn_table_entry *newent;
59917 +
59918 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59919 + if (newent == NULL)
59920 + return;
59921 + /* no bh lock needed since we are called with bh disabled */
59922 + spin_lock(&gr_conn_table_lock);
59923 + gr_del_task_from_ip_table_nolock(sig);
59924 + sig->gr_saddr = inet->inet_rcv_saddr;
59925 + sig->gr_daddr = inet->inet_daddr;
59926 + sig->gr_sport = inet->inet_sport;
59927 + sig->gr_dport = inet->inet_dport;
59928 + gr_add_to_task_ip_table_nolock(sig, newent);
59929 + spin_unlock(&gr_conn_table_lock);
59930 +#endif
59931 + return;
59932 +}
59933 +
59934 +void gr_del_task_from_ip_table(struct task_struct *task)
59935 +{
59936 +#ifdef CONFIG_GRKERNSEC
59937 + spin_lock_bh(&gr_conn_table_lock);
59938 + gr_del_task_from_ip_table_nolock(task->signal);
59939 + spin_unlock_bh(&gr_conn_table_lock);
59940 +#endif
59941 + return;
59942 +}
59943 +
59944 +void
59945 +gr_attach_curr_ip(const struct sock *sk)
59946 +{
59947 +#ifdef CONFIG_GRKERNSEC
59948 + struct signal_struct *p, *set;
59949 + const struct inet_sock *inet = inet_sk(sk);
59950 +
59951 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59952 + return;
59953 +
59954 + set = current->signal;
59955 +
59956 + spin_lock_bh(&gr_conn_table_lock);
59957 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59958 + inet->inet_dport, inet->inet_sport);
59959 + if (unlikely(p != NULL)) {
59960 + set->curr_ip = p->curr_ip;
59961 + set->used_accept = 1;
59962 + gr_del_task_from_ip_table_nolock(p);
59963 + spin_unlock_bh(&gr_conn_table_lock);
59964 + return;
59965 + }
59966 + spin_unlock_bh(&gr_conn_table_lock);
59967 +
59968 + set->curr_ip = inet->inet_daddr;
59969 + set->used_accept = 1;
59970 +#endif
59971 + return;
59972 +}
59973 +
59974 +int
59975 +gr_handle_sock_all(const int family, const int type, const int protocol)
59976 +{
59977 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59978 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59979 + (family != AF_UNIX)) {
59980 + if (family == AF_INET)
59981 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59982 + else
59983 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59984 + return -EACCES;
59985 + }
59986 +#endif
59987 + return 0;
59988 +}
59989 +
59990 +int
59991 +gr_handle_sock_server(const struct sockaddr *sck)
59992 +{
59993 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59994 + if (grsec_enable_socket_server &&
59995 + in_group_p(grsec_socket_server_gid) &&
59996 + sck && (sck->sa_family != AF_UNIX) &&
59997 + (sck->sa_family != AF_LOCAL)) {
59998 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59999 + return -EACCES;
60000 + }
60001 +#endif
60002 + return 0;
60003 +}
60004 +
60005 +int
60006 +gr_handle_sock_server_other(const struct sock *sck)
60007 +{
60008 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60009 + if (grsec_enable_socket_server &&
60010 + in_group_p(grsec_socket_server_gid) &&
60011 + sck && (sck->sk_family != AF_UNIX) &&
60012 + (sck->sk_family != AF_LOCAL)) {
60013 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60014 + return -EACCES;
60015 + }
60016 +#endif
60017 + return 0;
60018 +}
60019 +
60020 +int
60021 +gr_handle_sock_client(const struct sockaddr *sck)
60022 +{
60023 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60024 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60025 + sck && (sck->sa_family != AF_UNIX) &&
60026 + (sck->sa_family != AF_LOCAL)) {
60027 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60028 + return -EACCES;
60029 + }
60030 +#endif
60031 + return 0;
60032 +}
60033 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60034 new file mode 100644
60035 index 0000000..f55ef0f
60036 --- /dev/null
60037 +++ b/grsecurity/grsec_sysctl.c
60038 @@ -0,0 +1,469 @@
60039 +#include <linux/kernel.h>
60040 +#include <linux/sched.h>
60041 +#include <linux/sysctl.h>
60042 +#include <linux/grsecurity.h>
60043 +#include <linux/grinternal.h>
60044 +
60045 +int
60046 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60047 +{
60048 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60049 + if (dirname == NULL || name == NULL)
60050 + return 0;
60051 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60052 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60053 + return -EACCES;
60054 + }
60055 +#endif
60056 + return 0;
60057 +}
60058 +
60059 +#ifdef CONFIG_GRKERNSEC_ROFS
60060 +static int __maybe_unused one = 1;
60061 +#endif
60062 +
60063 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60064 +struct ctl_table grsecurity_table[] = {
60065 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60066 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60067 +#ifdef CONFIG_GRKERNSEC_IO
60068 + {
60069 + .procname = "disable_priv_io",
60070 + .data = &grsec_disable_privio,
60071 + .maxlen = sizeof(int),
60072 + .mode = 0600,
60073 + .proc_handler = &proc_dointvec,
60074 + },
60075 +#endif
60076 +#endif
60077 +#ifdef CONFIG_GRKERNSEC_LINK
60078 + {
60079 + .procname = "linking_restrictions",
60080 + .data = &grsec_enable_link,
60081 + .maxlen = sizeof(int),
60082 + .mode = 0600,
60083 + .proc_handler = &proc_dointvec,
60084 + },
60085 +#endif
60086 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60087 + {
60088 + .procname = "enforce_symlinksifowner",
60089 + .data = &grsec_enable_symlinkown,
60090 + .maxlen = sizeof(int),
60091 + .mode = 0600,
60092 + .proc_handler = &proc_dointvec,
60093 + },
60094 + {
60095 + .procname = "symlinkown_gid",
60096 + .data = &grsec_symlinkown_gid,
60097 + .maxlen = sizeof(int),
60098 + .mode = 0600,
60099 + .proc_handler = &proc_dointvec,
60100 + },
60101 +#endif
60102 +#ifdef CONFIG_GRKERNSEC_BRUTE
60103 + {
60104 + .procname = "deter_bruteforce",
60105 + .data = &grsec_enable_brute,
60106 + .maxlen = sizeof(int),
60107 + .mode = 0600,
60108 + .proc_handler = &proc_dointvec,
60109 + },
60110 +#endif
60111 +#ifdef CONFIG_GRKERNSEC_FIFO
60112 + {
60113 + .procname = "fifo_restrictions",
60114 + .data = &grsec_enable_fifo,
60115 + .maxlen = sizeof(int),
60116 + .mode = 0600,
60117 + .proc_handler = &proc_dointvec,
60118 + },
60119 +#endif
60120 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60121 + {
60122 + .procname = "ptrace_readexec",
60123 + .data = &grsec_enable_ptrace_readexec,
60124 + .maxlen = sizeof(int),
60125 + .mode = 0600,
60126 + .proc_handler = &proc_dointvec,
60127 + },
60128 +#endif
60129 +#ifdef CONFIG_GRKERNSEC_SETXID
60130 + {
60131 + .procname = "consistent_setxid",
60132 + .data = &grsec_enable_setxid,
60133 + .maxlen = sizeof(int),
60134 + .mode = 0600,
60135 + .proc_handler = &proc_dointvec,
60136 + },
60137 +#endif
60138 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60139 + {
60140 + .procname = "ip_blackhole",
60141 + .data = &grsec_enable_blackhole,
60142 + .maxlen = sizeof(int),
60143 + .mode = 0600,
60144 + .proc_handler = &proc_dointvec,
60145 + },
60146 + {
60147 + .procname = "lastack_retries",
60148 + .data = &grsec_lastack_retries,
60149 + .maxlen = sizeof(int),
60150 + .mode = 0600,
60151 + .proc_handler = &proc_dointvec,
60152 + },
60153 +#endif
60154 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60155 + {
60156 + .procname = "exec_logging",
60157 + .data = &grsec_enable_execlog,
60158 + .maxlen = sizeof(int),
60159 + .mode = 0600,
60160 + .proc_handler = &proc_dointvec,
60161 + },
60162 +#endif
60163 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60164 + {
60165 + .procname = "rwxmap_logging",
60166 + .data = &grsec_enable_log_rwxmaps,
60167 + .maxlen = sizeof(int),
60168 + .mode = 0600,
60169 + .proc_handler = &proc_dointvec,
60170 + },
60171 +#endif
60172 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60173 + {
60174 + .procname = "signal_logging",
60175 + .data = &grsec_enable_signal,
60176 + .maxlen = sizeof(int),
60177 + .mode = 0600,
60178 + .proc_handler = &proc_dointvec,
60179 + },
60180 +#endif
60181 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60182 + {
60183 + .procname = "forkfail_logging",
60184 + .data = &grsec_enable_forkfail,
60185 + .maxlen = sizeof(int),
60186 + .mode = 0600,
60187 + .proc_handler = &proc_dointvec,
60188 + },
60189 +#endif
60190 +#ifdef CONFIG_GRKERNSEC_TIME
60191 + {
60192 + .procname = "timechange_logging",
60193 + .data = &grsec_enable_time,
60194 + .maxlen = sizeof(int),
60195 + .mode = 0600,
60196 + .proc_handler = &proc_dointvec,
60197 + },
60198 +#endif
60199 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60200 + {
60201 + .procname = "chroot_deny_shmat",
60202 + .data = &grsec_enable_chroot_shmat,
60203 + .maxlen = sizeof(int),
60204 + .mode = 0600,
60205 + .proc_handler = &proc_dointvec,
60206 + },
60207 +#endif
60208 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60209 + {
60210 + .procname = "chroot_deny_unix",
60211 + .data = &grsec_enable_chroot_unix,
60212 + .maxlen = sizeof(int),
60213 + .mode = 0600,
60214 + .proc_handler = &proc_dointvec,
60215 + },
60216 +#endif
60217 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60218 + {
60219 + .procname = "chroot_deny_mount",
60220 + .data = &grsec_enable_chroot_mount,
60221 + .maxlen = sizeof(int),
60222 + .mode = 0600,
60223 + .proc_handler = &proc_dointvec,
60224 + },
60225 +#endif
60226 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60227 + {
60228 + .procname = "chroot_deny_fchdir",
60229 + .data = &grsec_enable_chroot_fchdir,
60230 + .maxlen = sizeof(int),
60231 + .mode = 0600,
60232 + .proc_handler = &proc_dointvec,
60233 + },
60234 +#endif
60235 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60236 + {
60237 + .procname = "chroot_deny_chroot",
60238 + .data = &grsec_enable_chroot_double,
60239 + .maxlen = sizeof(int),
60240 + .mode = 0600,
60241 + .proc_handler = &proc_dointvec,
60242 + },
60243 +#endif
60244 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60245 + {
60246 + .procname = "chroot_deny_pivot",
60247 + .data = &grsec_enable_chroot_pivot,
60248 + .maxlen = sizeof(int),
60249 + .mode = 0600,
60250 + .proc_handler = &proc_dointvec,
60251 + },
60252 +#endif
60253 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60254 + {
60255 + .procname = "chroot_enforce_chdir",
60256 + .data = &grsec_enable_chroot_chdir,
60257 + .maxlen = sizeof(int),
60258 + .mode = 0600,
60259 + .proc_handler = &proc_dointvec,
60260 + },
60261 +#endif
60262 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60263 + {
60264 + .procname = "chroot_deny_chmod",
60265 + .data = &grsec_enable_chroot_chmod,
60266 + .maxlen = sizeof(int),
60267 + .mode = 0600,
60268 + .proc_handler = &proc_dointvec,
60269 + },
60270 +#endif
60271 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60272 + {
60273 + .procname = "chroot_deny_mknod",
60274 + .data = &grsec_enable_chroot_mknod,
60275 + .maxlen = sizeof(int),
60276 + .mode = 0600,
60277 + .proc_handler = &proc_dointvec,
60278 + },
60279 +#endif
60280 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60281 + {
60282 + .procname = "chroot_restrict_nice",
60283 + .data = &grsec_enable_chroot_nice,
60284 + .maxlen = sizeof(int),
60285 + .mode = 0600,
60286 + .proc_handler = &proc_dointvec,
60287 + },
60288 +#endif
60289 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60290 + {
60291 + .procname = "chroot_execlog",
60292 + .data = &grsec_enable_chroot_execlog,
60293 + .maxlen = sizeof(int),
60294 + .mode = 0600,
60295 + .proc_handler = &proc_dointvec,
60296 + },
60297 +#endif
60298 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60299 + {
60300 + .procname = "chroot_caps",
60301 + .data = &grsec_enable_chroot_caps,
60302 + .maxlen = sizeof(int),
60303 + .mode = 0600,
60304 + .proc_handler = &proc_dointvec,
60305 + },
60306 +#endif
60307 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60308 + {
60309 + .procname = "chroot_deny_sysctl",
60310 + .data = &grsec_enable_chroot_sysctl,
60311 + .maxlen = sizeof(int),
60312 + .mode = 0600,
60313 + .proc_handler = &proc_dointvec,
60314 + },
60315 +#endif
60316 +#ifdef CONFIG_GRKERNSEC_TPE
60317 + {
60318 + .procname = "tpe",
60319 + .data = &grsec_enable_tpe,
60320 + .maxlen = sizeof(int),
60321 + .mode = 0600,
60322 + .proc_handler = &proc_dointvec,
60323 + },
60324 + {
60325 + .procname = "tpe_gid",
60326 + .data = &grsec_tpe_gid,
60327 + .maxlen = sizeof(int),
60328 + .mode = 0600,
60329 + .proc_handler = &proc_dointvec,
60330 + },
60331 +#endif
60332 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60333 + {
60334 + .procname = "tpe_invert",
60335 + .data = &grsec_enable_tpe_invert,
60336 + .maxlen = sizeof(int),
60337 + .mode = 0600,
60338 + .proc_handler = &proc_dointvec,
60339 + },
60340 +#endif
60341 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60342 + {
60343 + .procname = "tpe_restrict_all",
60344 + .data = &grsec_enable_tpe_all,
60345 + .maxlen = sizeof(int),
60346 + .mode = 0600,
60347 + .proc_handler = &proc_dointvec,
60348 + },
60349 +#endif
60350 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60351 + {
60352 + .procname = "socket_all",
60353 + .data = &grsec_enable_socket_all,
60354 + .maxlen = sizeof(int),
60355 + .mode = 0600,
60356 + .proc_handler = &proc_dointvec,
60357 + },
60358 + {
60359 + .procname = "socket_all_gid",
60360 + .data = &grsec_socket_all_gid,
60361 + .maxlen = sizeof(int),
60362 + .mode = 0600,
60363 + .proc_handler = &proc_dointvec,
60364 + },
60365 +#endif
60366 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60367 + {
60368 + .procname = "socket_client",
60369 + .data = &grsec_enable_socket_client,
60370 + .maxlen = sizeof(int),
60371 + .mode = 0600,
60372 + .proc_handler = &proc_dointvec,
60373 + },
60374 + {
60375 + .procname = "socket_client_gid",
60376 + .data = &grsec_socket_client_gid,
60377 + .maxlen = sizeof(int),
60378 + .mode = 0600,
60379 + .proc_handler = &proc_dointvec,
60380 + },
60381 +#endif
60382 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60383 + {
60384 + .procname = "socket_server",
60385 + .data = &grsec_enable_socket_server,
60386 + .maxlen = sizeof(int),
60387 + .mode = 0600,
60388 + .proc_handler = &proc_dointvec,
60389 + },
60390 + {
60391 + .procname = "socket_server_gid",
60392 + .data = &grsec_socket_server_gid,
60393 + .maxlen = sizeof(int),
60394 + .mode = 0600,
60395 + .proc_handler = &proc_dointvec,
60396 + },
60397 +#endif
60398 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60399 + {
60400 + .procname = "audit_group",
60401 + .data = &grsec_enable_group,
60402 + .maxlen = sizeof(int),
60403 + .mode = 0600,
60404 + .proc_handler = &proc_dointvec,
60405 + },
60406 + {
60407 + .procname = "audit_gid",
60408 + .data = &grsec_audit_gid,
60409 + .maxlen = sizeof(int),
60410 + .mode = 0600,
60411 + .proc_handler = &proc_dointvec,
60412 + },
60413 +#endif
60414 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60415 + {
60416 + .procname = "audit_chdir",
60417 + .data = &grsec_enable_chdir,
60418 + .maxlen = sizeof(int),
60419 + .mode = 0600,
60420 + .proc_handler = &proc_dointvec,
60421 + },
60422 +#endif
60423 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60424 + {
60425 + .procname = "audit_mount",
60426 + .data = &grsec_enable_mount,
60427 + .maxlen = sizeof(int),
60428 + .mode = 0600,
60429 + .proc_handler = &proc_dointvec,
60430 + },
60431 +#endif
60432 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60433 + {
60434 + .procname = "audit_textrel",
60435 + .data = &grsec_enable_audit_textrel,
60436 + .maxlen = sizeof(int),
60437 + .mode = 0600,
60438 + .proc_handler = &proc_dointvec,
60439 + },
60440 +#endif
60441 +#ifdef CONFIG_GRKERNSEC_DMESG
60442 + {
60443 + .procname = "dmesg",
60444 + .data = &grsec_enable_dmesg,
60445 + .maxlen = sizeof(int),
60446 + .mode = 0600,
60447 + .proc_handler = &proc_dointvec,
60448 + },
60449 +#endif
60450 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60451 + {
60452 + .procname = "chroot_findtask",
60453 + .data = &grsec_enable_chroot_findtask,
60454 + .maxlen = sizeof(int),
60455 + .mode = 0600,
60456 + .proc_handler = &proc_dointvec,
60457 + },
60458 +#endif
60459 +#ifdef CONFIG_GRKERNSEC_RESLOG
60460 + {
60461 + .procname = "resource_logging",
60462 + .data = &grsec_resource_logging,
60463 + .maxlen = sizeof(int),
60464 + .mode = 0600,
60465 + .proc_handler = &proc_dointvec,
60466 + },
60467 +#endif
60468 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60469 + {
60470 + .procname = "audit_ptrace",
60471 + .data = &grsec_enable_audit_ptrace,
60472 + .maxlen = sizeof(int),
60473 + .mode = 0600,
60474 + .proc_handler = &proc_dointvec,
60475 + },
60476 +#endif
60477 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60478 + {
60479 + .procname = "harden_ptrace",
60480 + .data = &grsec_enable_harden_ptrace,
60481 + .maxlen = sizeof(int),
60482 + .mode = 0600,
60483 + .proc_handler = &proc_dointvec,
60484 + },
60485 +#endif
60486 + {
60487 + .procname = "grsec_lock",
60488 + .data = &grsec_lock,
60489 + .maxlen = sizeof(int),
60490 + .mode = 0600,
60491 + .proc_handler = &proc_dointvec,
60492 + },
60493 +#endif
60494 +#ifdef CONFIG_GRKERNSEC_ROFS
60495 + {
60496 + .procname = "romount_protect",
60497 + .data = &grsec_enable_rofs,
60498 + .maxlen = sizeof(int),
60499 + .mode = 0600,
60500 + .proc_handler = &proc_dointvec_minmax,
60501 + .extra1 = &one,
60502 + .extra2 = &one,
60503 + },
60504 +#endif
60505 + { }
60506 +};
60507 +#endif
60508 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60509 new file mode 100644
60510 index 0000000..0dc13c3
60511 --- /dev/null
60512 +++ b/grsecurity/grsec_time.c
60513 @@ -0,0 +1,16 @@
60514 +#include <linux/kernel.h>
60515 +#include <linux/sched.h>
60516 +#include <linux/grinternal.h>
60517 +#include <linux/module.h>
60518 +
60519 +void
60520 +gr_log_timechange(void)
60521 +{
60522 +#ifdef CONFIG_GRKERNSEC_TIME
60523 + if (grsec_enable_time)
60524 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60525 +#endif
60526 + return;
60527 +}
60528 +
60529 +EXPORT_SYMBOL(gr_log_timechange);
60530 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60531 new file mode 100644
60532 index 0000000..07e0dc0
60533 --- /dev/null
60534 +++ b/grsecurity/grsec_tpe.c
60535 @@ -0,0 +1,73 @@
60536 +#include <linux/kernel.h>
60537 +#include <linux/sched.h>
60538 +#include <linux/file.h>
60539 +#include <linux/fs.h>
60540 +#include <linux/grinternal.h>
60541 +
60542 +extern int gr_acl_tpe_check(void);
60543 +
60544 +int
60545 +gr_tpe_allow(const struct file *file)
60546 +{
60547 +#ifdef CONFIG_GRKERNSEC
60548 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60549 + const struct cred *cred = current_cred();
60550 + char *msg = NULL;
60551 + char *msg2 = NULL;
60552 +
60553 + // never restrict root
60554 + if (!cred->uid)
60555 + return 1;
60556 +
60557 + if (grsec_enable_tpe) {
60558 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60559 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60560 + msg = "not being in trusted group";
60561 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60562 + msg = "being in untrusted group";
60563 +#else
60564 + if (in_group_p(grsec_tpe_gid))
60565 + msg = "being in untrusted group";
60566 +#endif
60567 + }
60568 + if (!msg && gr_acl_tpe_check())
60569 + msg = "being in untrusted role";
60570 +
60571 + // not in any affected group/role
60572 + if (!msg)
60573 + goto next_check;
60574 +
60575 + if (inode->i_uid)
60576 + msg2 = "file in non-root-owned directory";
60577 + else if (inode->i_mode & S_IWOTH)
60578 + msg2 = "file in world-writable directory";
60579 + else if (inode->i_mode & S_IWGRP)
60580 + msg2 = "file in group-writable directory";
60581 +
60582 + if (msg && msg2) {
60583 + char fullmsg[70] = {0};
60584 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60585 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60586 + return 0;
60587 + }
60588 + msg = NULL;
60589 +next_check:
60590 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60591 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60592 + return 1;
60593 +
60594 + if (inode->i_uid && (inode->i_uid != cred->uid))
60595 + msg = "directory not owned by user";
60596 + else if (inode->i_mode & S_IWOTH)
60597 + msg = "file in world-writable directory";
60598 + else if (inode->i_mode & S_IWGRP)
60599 + msg = "file in group-writable directory";
60600 +
60601 + if (msg) {
60602 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60603 + return 0;
60604 + }
60605 +#endif
60606 +#endif
60607 + return 1;
60608 +}
60609 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60610 new file mode 100644
60611 index 0000000..9f7b1ac
60612 --- /dev/null
60613 +++ b/grsecurity/grsum.c
60614 @@ -0,0 +1,61 @@
60615 +#include <linux/err.h>
60616 +#include <linux/kernel.h>
60617 +#include <linux/sched.h>
60618 +#include <linux/mm.h>
60619 +#include <linux/scatterlist.h>
60620 +#include <linux/crypto.h>
60621 +#include <linux/gracl.h>
60622 +
60623 +
60624 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60625 +#error "crypto and sha256 must be built into the kernel"
60626 +#endif
60627 +
60628 +int
60629 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60630 +{
60631 + char *p;
60632 + struct crypto_hash *tfm;
60633 + struct hash_desc desc;
60634 + struct scatterlist sg;
60635 + unsigned char temp_sum[GR_SHA_LEN];
60636 + volatile int retval = 0;
60637 + volatile int dummy = 0;
60638 + unsigned int i;
60639 +
60640 + sg_init_table(&sg, 1);
60641 +
60642 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60643 + if (IS_ERR(tfm)) {
60644 + /* should never happen, since sha256 should be built in */
60645 + return 1;
60646 + }
60647 +
60648 + desc.tfm = tfm;
60649 + desc.flags = 0;
60650 +
60651 + crypto_hash_init(&desc);
60652 +
60653 + p = salt;
60654 + sg_set_buf(&sg, p, GR_SALT_LEN);
60655 + crypto_hash_update(&desc, &sg, sg.length);
60656 +
60657 + p = entry->pw;
60658 + sg_set_buf(&sg, p, strlen(p));
60659 +
60660 + crypto_hash_update(&desc, &sg, sg.length);
60661 +
60662 + crypto_hash_final(&desc, temp_sum);
60663 +
60664 + memset(entry->pw, 0, GR_PW_LEN);
60665 +
60666 + for (i = 0; i < GR_SHA_LEN; i++)
60667 + if (sum[i] != temp_sum[i])
60668 + retval = 1;
60669 + else
60670 + dummy = 1; // waste a cycle
60671 +
60672 + crypto_free_hash(tfm);
60673 +
60674 + return retval;
60675 +}
60676 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60677 index bde976e..a1cc32a 100644
60678 --- a/include/acpi/acpi_bus.h
60679 +++ b/include/acpi/acpi_bus.h
60680 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60681 acpi_op_bind bind;
60682 acpi_op_unbind unbind;
60683 acpi_op_notify notify;
60684 -};
60685 +} __no_const;
60686
60687 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60688
60689 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60690 index 77ff547..181834f 100644
60691 --- a/include/asm-generic/4level-fixup.h
60692 +++ b/include/asm-generic/4level-fixup.h
60693 @@ -13,8 +13,10 @@
60694 #define pmd_alloc(mm, pud, address) \
60695 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60696 NULL: pmd_offset(pud, address))
60697 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60698
60699 #define pud_alloc(mm, pgd, address) (pgd)
60700 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60701 #define pud_offset(pgd, start) (pgd)
60702 #define pud_none(pud) 0
60703 #define pud_bad(pud) 0
60704 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60705 index b7babf0..3ba8aee 100644
60706 --- a/include/asm-generic/atomic-long.h
60707 +++ b/include/asm-generic/atomic-long.h
60708 @@ -22,6 +22,12 @@
60709
60710 typedef atomic64_t atomic_long_t;
60711
60712 +#ifdef CONFIG_PAX_REFCOUNT
60713 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60714 +#else
60715 +typedef atomic64_t atomic_long_unchecked_t;
60716 +#endif
60717 +
60718 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60719
60720 static inline long atomic_long_read(atomic_long_t *l)
60721 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60722 return (long)atomic64_read(v);
60723 }
60724
60725 +#ifdef CONFIG_PAX_REFCOUNT
60726 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60727 +{
60728 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60729 +
60730 + return (long)atomic64_read_unchecked(v);
60731 +}
60732 +#endif
60733 +
60734 static inline void atomic_long_set(atomic_long_t *l, long i)
60735 {
60736 atomic64_t *v = (atomic64_t *)l;
60737 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60738 atomic64_set(v, i);
60739 }
60740
60741 +#ifdef CONFIG_PAX_REFCOUNT
60742 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60743 +{
60744 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60745 +
60746 + atomic64_set_unchecked(v, i);
60747 +}
60748 +#endif
60749 +
60750 static inline void atomic_long_inc(atomic_long_t *l)
60751 {
60752 atomic64_t *v = (atomic64_t *)l;
60753 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60754 atomic64_inc(v);
60755 }
60756
60757 +#ifdef CONFIG_PAX_REFCOUNT
60758 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60759 +{
60760 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60761 +
60762 + atomic64_inc_unchecked(v);
60763 +}
60764 +#endif
60765 +
60766 static inline void atomic_long_dec(atomic_long_t *l)
60767 {
60768 atomic64_t *v = (atomic64_t *)l;
60769 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60770 atomic64_dec(v);
60771 }
60772
60773 +#ifdef CONFIG_PAX_REFCOUNT
60774 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60775 +{
60776 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60777 +
60778 + atomic64_dec_unchecked(v);
60779 +}
60780 +#endif
60781 +
60782 static inline void atomic_long_add(long i, atomic_long_t *l)
60783 {
60784 atomic64_t *v = (atomic64_t *)l;
60785 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60786 atomic64_add(i, v);
60787 }
60788
60789 +#ifdef CONFIG_PAX_REFCOUNT
60790 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60791 +{
60792 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60793 +
60794 + atomic64_add_unchecked(i, v);
60795 +}
60796 +#endif
60797 +
60798 static inline void atomic_long_sub(long i, atomic_long_t *l)
60799 {
60800 atomic64_t *v = (atomic64_t *)l;
60801 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60802 atomic64_sub(i, v);
60803 }
60804
60805 +#ifdef CONFIG_PAX_REFCOUNT
60806 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60807 +{
60808 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60809 +
60810 + atomic64_sub_unchecked(i, v);
60811 +}
60812 +#endif
60813 +
60814 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60815 {
60816 atomic64_t *v = (atomic64_t *)l;
60817 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60818 return (long)atomic64_inc_return(v);
60819 }
60820
60821 +#ifdef CONFIG_PAX_REFCOUNT
60822 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60823 +{
60824 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60825 +
60826 + return (long)atomic64_inc_return_unchecked(v);
60827 +}
60828 +#endif
60829 +
60830 static inline long atomic_long_dec_return(atomic_long_t *l)
60831 {
60832 atomic64_t *v = (atomic64_t *)l;
60833 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60834
60835 typedef atomic_t atomic_long_t;
60836
60837 +#ifdef CONFIG_PAX_REFCOUNT
60838 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60839 +#else
60840 +typedef atomic_t atomic_long_unchecked_t;
60841 +#endif
60842 +
60843 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60844 static inline long atomic_long_read(atomic_long_t *l)
60845 {
60846 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60847 return (long)atomic_read(v);
60848 }
60849
60850 +#ifdef CONFIG_PAX_REFCOUNT
60851 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60852 +{
60853 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60854 +
60855 + return (long)atomic_read_unchecked(v);
60856 +}
60857 +#endif
60858 +
60859 static inline void atomic_long_set(atomic_long_t *l, long i)
60860 {
60861 atomic_t *v = (atomic_t *)l;
60862 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60863 atomic_set(v, i);
60864 }
60865
60866 +#ifdef CONFIG_PAX_REFCOUNT
60867 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60868 +{
60869 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60870 +
60871 + atomic_set_unchecked(v, i);
60872 +}
60873 +#endif
60874 +
60875 static inline void atomic_long_inc(atomic_long_t *l)
60876 {
60877 atomic_t *v = (atomic_t *)l;
60878 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60879 atomic_inc(v);
60880 }
60881
60882 +#ifdef CONFIG_PAX_REFCOUNT
60883 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60884 +{
60885 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60886 +
60887 + atomic_inc_unchecked(v);
60888 +}
60889 +#endif
60890 +
60891 static inline void atomic_long_dec(atomic_long_t *l)
60892 {
60893 atomic_t *v = (atomic_t *)l;
60894 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60895 atomic_dec(v);
60896 }
60897
60898 +#ifdef CONFIG_PAX_REFCOUNT
60899 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60900 +{
60901 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60902 +
60903 + atomic_dec_unchecked(v);
60904 +}
60905 +#endif
60906 +
60907 static inline void atomic_long_add(long i, atomic_long_t *l)
60908 {
60909 atomic_t *v = (atomic_t *)l;
60910 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60911 atomic_add(i, v);
60912 }
60913
60914 +#ifdef CONFIG_PAX_REFCOUNT
60915 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60916 +{
60917 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60918 +
60919 + atomic_add_unchecked(i, v);
60920 +}
60921 +#endif
60922 +
60923 static inline void atomic_long_sub(long i, atomic_long_t *l)
60924 {
60925 atomic_t *v = (atomic_t *)l;
60926 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60927 atomic_sub(i, v);
60928 }
60929
60930 +#ifdef CONFIG_PAX_REFCOUNT
60931 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60932 +{
60933 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60934 +
60935 + atomic_sub_unchecked(i, v);
60936 +}
60937 +#endif
60938 +
60939 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60940 {
60941 atomic_t *v = (atomic_t *)l;
60942 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60943 return (long)atomic_inc_return(v);
60944 }
60945
60946 +#ifdef CONFIG_PAX_REFCOUNT
60947 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60948 +{
60949 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60950 +
60951 + return (long)atomic_inc_return_unchecked(v);
60952 +}
60953 +#endif
60954 +
60955 static inline long atomic_long_dec_return(atomic_long_t *l)
60956 {
60957 atomic_t *v = (atomic_t *)l;
60958 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60959
60960 #endif /* BITS_PER_LONG == 64 */
60961
60962 +#ifdef CONFIG_PAX_REFCOUNT
60963 +static inline void pax_refcount_needs_these_functions(void)
60964 +{
60965 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60966 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60967 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60968 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60969 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60970 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60971 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60972 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60973 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60974 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60975 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60976 +#ifdef CONFIG_X86
60977 + atomic_clear_mask_unchecked(0, NULL);
60978 + atomic_set_mask_unchecked(0, NULL);
60979 +#endif
60980 +
60981 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60982 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60983 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60984 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60985 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60986 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60987 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60988 +}
60989 +#else
60990 +#define atomic_read_unchecked(v) atomic_read(v)
60991 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60992 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60993 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60994 +#define atomic_inc_unchecked(v) atomic_inc(v)
60995 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60996 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60997 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60998 +#define atomic_dec_unchecked(v) atomic_dec(v)
60999 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61000 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61001 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61002 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61003 +
61004 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61005 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61006 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61007 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61008 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61009 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61010 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61011 +#endif
61012 +
61013 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61014 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61015 index 1ced641..c896ee8 100644
61016 --- a/include/asm-generic/atomic.h
61017 +++ b/include/asm-generic/atomic.h
61018 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61019 * Atomically clears the bits set in @mask from @v
61020 */
61021 #ifndef atomic_clear_mask
61022 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61023 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61024 {
61025 unsigned long flags;
61026
61027 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61028 index b18ce4f..2ee2843 100644
61029 --- a/include/asm-generic/atomic64.h
61030 +++ b/include/asm-generic/atomic64.h
61031 @@ -16,6 +16,8 @@ typedef struct {
61032 long long counter;
61033 } atomic64_t;
61034
61035 +typedef atomic64_t atomic64_unchecked_t;
61036 +
61037 #define ATOMIC64_INIT(i) { (i) }
61038
61039 extern long long atomic64_read(const atomic64_t *v);
61040 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61041 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61042 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61043
61044 +#define atomic64_read_unchecked(v) atomic64_read(v)
61045 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61046 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61047 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61048 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61049 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61050 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61051 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61052 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61053 +
61054 #endif /* _ASM_GENERIC_ATOMIC64_H */
61055 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61056 index 1bfcfe5..e04c5c9 100644
61057 --- a/include/asm-generic/cache.h
61058 +++ b/include/asm-generic/cache.h
61059 @@ -6,7 +6,7 @@
61060 * cache lines need to provide their own cache.h.
61061 */
61062
61063 -#define L1_CACHE_SHIFT 5
61064 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61065 +#define L1_CACHE_SHIFT 5UL
61066 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61067
61068 #endif /* __ASM_GENERIC_CACHE_H */
61069 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61070 index 0d68a1e..b74a761 100644
61071 --- a/include/asm-generic/emergency-restart.h
61072 +++ b/include/asm-generic/emergency-restart.h
61073 @@ -1,7 +1,7 @@
61074 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61075 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61076
61077 -static inline void machine_emergency_restart(void)
61078 +static inline __noreturn void machine_emergency_restart(void)
61079 {
61080 machine_restart(NULL);
61081 }
61082 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61083 index 90f99c7..00ce236 100644
61084 --- a/include/asm-generic/kmap_types.h
61085 +++ b/include/asm-generic/kmap_types.h
61086 @@ -2,9 +2,9 @@
61087 #define _ASM_GENERIC_KMAP_TYPES_H
61088
61089 #ifdef __WITH_KM_FENCE
61090 -# define KM_TYPE_NR 41
61091 +# define KM_TYPE_NR 42
61092 #else
61093 -# define KM_TYPE_NR 20
61094 +# define KM_TYPE_NR 21
61095 #endif
61096
61097 #endif
61098 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61099 index 9ceb03b..2efbcbd 100644
61100 --- a/include/asm-generic/local.h
61101 +++ b/include/asm-generic/local.h
61102 @@ -39,6 +39,7 @@ typedef struct
61103 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61104 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61105 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61106 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61107
61108 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61109 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61110 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61111 index 725612b..9cc513a 100644
61112 --- a/include/asm-generic/pgtable-nopmd.h
61113 +++ b/include/asm-generic/pgtable-nopmd.h
61114 @@ -1,14 +1,19 @@
61115 #ifndef _PGTABLE_NOPMD_H
61116 #define _PGTABLE_NOPMD_H
61117
61118 -#ifndef __ASSEMBLY__
61119 -
61120 #include <asm-generic/pgtable-nopud.h>
61121
61122 -struct mm_struct;
61123 -
61124 #define __PAGETABLE_PMD_FOLDED
61125
61126 +#define PMD_SHIFT PUD_SHIFT
61127 +#define PTRS_PER_PMD 1
61128 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61129 +#define PMD_MASK (~(PMD_SIZE-1))
61130 +
61131 +#ifndef __ASSEMBLY__
61132 +
61133 +struct mm_struct;
61134 +
61135 /*
61136 * Having the pmd type consist of a pud gets the size right, and allows
61137 * us to conceptually access the pud entry that this pmd is folded into
61138 @@ -16,11 +21,6 @@ struct mm_struct;
61139 */
61140 typedef struct { pud_t pud; } pmd_t;
61141
61142 -#define PMD_SHIFT PUD_SHIFT
61143 -#define PTRS_PER_PMD 1
61144 -#define PMD_SIZE (1UL << PMD_SHIFT)
61145 -#define PMD_MASK (~(PMD_SIZE-1))
61146 -
61147 /*
61148 * The "pud_xxx()" functions here are trivial for a folded two-level
61149 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61150 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61151 index 810431d..0ec4804f 100644
61152 --- a/include/asm-generic/pgtable-nopud.h
61153 +++ b/include/asm-generic/pgtable-nopud.h
61154 @@ -1,10 +1,15 @@
61155 #ifndef _PGTABLE_NOPUD_H
61156 #define _PGTABLE_NOPUD_H
61157
61158 -#ifndef __ASSEMBLY__
61159 -
61160 #define __PAGETABLE_PUD_FOLDED
61161
61162 +#define PUD_SHIFT PGDIR_SHIFT
61163 +#define PTRS_PER_PUD 1
61164 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61165 +#define PUD_MASK (~(PUD_SIZE-1))
61166 +
61167 +#ifndef __ASSEMBLY__
61168 +
61169 /*
61170 * Having the pud type consist of a pgd gets the size right, and allows
61171 * us to conceptually access the pgd entry that this pud is folded into
61172 @@ -12,11 +17,6 @@
61173 */
61174 typedef struct { pgd_t pgd; } pud_t;
61175
61176 -#define PUD_SHIFT PGDIR_SHIFT
61177 -#define PTRS_PER_PUD 1
61178 -#define PUD_SIZE (1UL << PUD_SHIFT)
61179 -#define PUD_MASK (~(PUD_SIZE-1))
61180 -
61181 /*
61182 * The "pgd_xxx()" functions here are trivial for a folded two-level
61183 * setup: the pud is never bad, and a pud always exists (as it's folded
61184 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61185 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61186
61187 #define pgd_populate(mm, pgd, pud) do { } while (0)
61188 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61189 /*
61190 * (puds are folded into pgds so this doesn't get actually called,
61191 * but the define is needed for a generic inline function.)
61192 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61193 index ff4947b..f48183f 100644
61194 --- a/include/asm-generic/pgtable.h
61195 +++ b/include/asm-generic/pgtable.h
61196 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61197 #endif
61198 }
61199
61200 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61201 +static inline unsigned long pax_open_kernel(void) { return 0; }
61202 +#endif
61203 +
61204 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61205 +static inline unsigned long pax_close_kernel(void) { return 0; }
61206 +#endif
61207 +
61208 #endif /* CONFIG_MMU */
61209
61210 #endif /* !__ASSEMBLY__ */
61211 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61212 index 4e2e1cc..12c266b 100644
61213 --- a/include/asm-generic/vmlinux.lds.h
61214 +++ b/include/asm-generic/vmlinux.lds.h
61215 @@ -218,6 +218,7 @@
61216 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61217 VMLINUX_SYMBOL(__start_rodata) = .; \
61218 *(.rodata) *(.rodata.*) \
61219 + *(.data..read_only) \
61220 *(__vermagic) /* Kernel version magic */ \
61221 . = ALIGN(8); \
61222 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61223 @@ -716,17 +717,18 @@
61224 * section in the linker script will go there too. @phdr should have
61225 * a leading colon.
61226 *
61227 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61228 + * Note that this macros defines per_cpu_load as an absolute symbol.
61229 * If there is no need to put the percpu section at a predetermined
61230 * address, use PERCPU_SECTION.
61231 */
61232 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61233 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61234 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61235 + per_cpu_load = .; \
61236 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61237 - LOAD_OFFSET) { \
61238 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61239 PERCPU_INPUT(cacheline) \
61240 } phdr \
61241 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61242 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61243
61244 /**
61245 * PERCPU_SECTION - define output section for percpu area, simple version
61246 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61247 index d6b67bb..a272c29 100644
61248 --- a/include/drm/drmP.h
61249 +++ b/include/drm/drmP.h
61250 @@ -72,6 +72,7 @@
61251 #include <linux/workqueue.h>
61252 #include <linux/poll.h>
61253 #include <asm/pgalloc.h>
61254 +#include <asm/local.h>
61255 #include "drm.h"
61256
61257 #include <linux/idr.h>
61258 @@ -1067,7 +1068,7 @@ struct drm_device {
61259
61260 /** \name Usage Counters */
61261 /*@{ */
61262 - int open_count; /**< Outstanding files open */
61263 + local_t open_count; /**< Outstanding files open */
61264 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61265 atomic_t vma_count; /**< Outstanding vma areas open */
61266 int buf_use; /**< Buffers in use -- cannot alloc */
61267 @@ -1078,7 +1079,7 @@ struct drm_device {
61268 /*@{ */
61269 unsigned long counters;
61270 enum drm_stat_type types[15];
61271 - atomic_t counts[15];
61272 + atomic_unchecked_t counts[15];
61273 /*@} */
61274
61275 struct list_head filelist;
61276 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61277 index e01cc80..319855d 100644
61278 --- a/include/drm/drm_crtc_helper.h
61279 +++ b/include/drm/drm_crtc_helper.h
61280 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61281
61282 /* disable crtc when not in use - more explicit than dpms off */
61283 void (*disable)(struct drm_crtc *crtc);
61284 -};
61285 +} __no_const;
61286
61287 /**
61288 * drm_encoder_helper_funcs - helper operations for encoders
61289 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61290 struct drm_connector *connector);
61291 /* disable encoder when not in use - more explicit than dpms off */
61292 void (*disable)(struct drm_encoder *encoder);
61293 -};
61294 +} __no_const;
61295
61296 /**
61297 * drm_connector_helper_funcs - helper operations for connectors
61298 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61299 index d6d1da4..fdd1ac5 100644
61300 --- a/include/drm/ttm/ttm_memory.h
61301 +++ b/include/drm/ttm/ttm_memory.h
61302 @@ -48,7 +48,7 @@
61303
61304 struct ttm_mem_shrink {
61305 int (*do_shrink) (struct ttm_mem_shrink *);
61306 -};
61307 +} __no_const;
61308
61309 /**
61310 * struct ttm_mem_global - Global memory accounting structure.
61311 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61312 index e86dfca..40cc55f 100644
61313 --- a/include/linux/a.out.h
61314 +++ b/include/linux/a.out.h
61315 @@ -39,6 +39,14 @@ enum machine_type {
61316 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61317 };
61318
61319 +/* Constants for the N_FLAGS field */
61320 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61321 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61322 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61323 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61324 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61325 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61326 +
61327 #if !defined (N_MAGIC)
61328 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61329 #endif
61330 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61331 index 06fd4bb..1caec0d 100644
61332 --- a/include/linux/atmdev.h
61333 +++ b/include/linux/atmdev.h
61334 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61335 #endif
61336
61337 struct k_atm_aal_stats {
61338 -#define __HANDLE_ITEM(i) atomic_t i
61339 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61340 __AAL_STAT_ITEMS
61341 #undef __HANDLE_ITEM
61342 };
61343 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61344 index 366422b..1fa7f84 100644
61345 --- a/include/linux/binfmts.h
61346 +++ b/include/linux/binfmts.h
61347 @@ -89,6 +89,7 @@ struct linux_binfmt {
61348 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61349 int (*load_shlib)(struct file *);
61350 int (*core_dump)(struct coredump_params *cprm);
61351 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61352 unsigned long min_coredump; /* minimal dump size */
61353 };
61354
61355 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61356 index 4a2ab7c..a2de7a8 100644
61357 --- a/include/linux/blkdev.h
61358 +++ b/include/linux/blkdev.h
61359 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61360 /* this callback is with swap_lock and sometimes page table lock held */
61361 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61362 struct module *owner;
61363 -};
61364 +} __do_const;
61365
61366 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61367 unsigned long);
61368 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61369 index 4d1a074..88f929a 100644
61370 --- a/include/linux/blktrace_api.h
61371 +++ b/include/linux/blktrace_api.h
61372 @@ -162,7 +162,7 @@ struct blk_trace {
61373 struct dentry *dir;
61374 struct dentry *dropped_file;
61375 struct dentry *msg_file;
61376 - atomic_t dropped;
61377 + atomic_unchecked_t dropped;
61378 };
61379
61380 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61381 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61382 index 83195fb..0b0f77d 100644
61383 --- a/include/linux/byteorder/little_endian.h
61384 +++ b/include/linux/byteorder/little_endian.h
61385 @@ -42,51 +42,51 @@
61386
61387 static inline __le64 __cpu_to_le64p(const __u64 *p)
61388 {
61389 - return (__force __le64)*p;
61390 + return (__force const __le64)*p;
61391 }
61392 static inline __u64 __le64_to_cpup(const __le64 *p)
61393 {
61394 - return (__force __u64)*p;
61395 + return (__force const __u64)*p;
61396 }
61397 static inline __le32 __cpu_to_le32p(const __u32 *p)
61398 {
61399 - return (__force __le32)*p;
61400 + return (__force const __le32)*p;
61401 }
61402 static inline __u32 __le32_to_cpup(const __le32 *p)
61403 {
61404 - return (__force __u32)*p;
61405 + return (__force const __u32)*p;
61406 }
61407 static inline __le16 __cpu_to_le16p(const __u16 *p)
61408 {
61409 - return (__force __le16)*p;
61410 + return (__force const __le16)*p;
61411 }
61412 static inline __u16 __le16_to_cpup(const __le16 *p)
61413 {
61414 - return (__force __u16)*p;
61415 + return (__force const __u16)*p;
61416 }
61417 static inline __be64 __cpu_to_be64p(const __u64 *p)
61418 {
61419 - return (__force __be64)__swab64p(p);
61420 + return (__force const __be64)__swab64p(p);
61421 }
61422 static inline __u64 __be64_to_cpup(const __be64 *p)
61423 {
61424 - return __swab64p((__u64 *)p);
61425 + return __swab64p((const __u64 *)p);
61426 }
61427 static inline __be32 __cpu_to_be32p(const __u32 *p)
61428 {
61429 - return (__force __be32)__swab32p(p);
61430 + return (__force const __be32)__swab32p(p);
61431 }
61432 static inline __u32 __be32_to_cpup(const __be32 *p)
61433 {
61434 - return __swab32p((__u32 *)p);
61435 + return __swab32p((const __u32 *)p);
61436 }
61437 static inline __be16 __cpu_to_be16p(const __u16 *p)
61438 {
61439 - return (__force __be16)__swab16p(p);
61440 + return (__force const __be16)__swab16p(p);
61441 }
61442 static inline __u16 __be16_to_cpup(const __be16 *p)
61443 {
61444 - return __swab16p((__u16 *)p);
61445 + return __swab16p((const __u16 *)p);
61446 }
61447 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61448 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61449 diff --git a/include/linux/cache.h b/include/linux/cache.h
61450 index 4c57065..4307975 100644
61451 --- a/include/linux/cache.h
61452 +++ b/include/linux/cache.h
61453 @@ -16,6 +16,10 @@
61454 #define __read_mostly
61455 #endif
61456
61457 +#ifndef __read_only
61458 +#define __read_only __read_mostly
61459 +#endif
61460 +
61461 #ifndef ____cacheline_aligned
61462 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61463 #endif
61464 diff --git a/include/linux/capability.h b/include/linux/capability.h
61465 index d10b7ed..0288b79 100644
61466 --- a/include/linux/capability.h
61467 +++ b/include/linux/capability.h
61468 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61469 extern bool ns_capable(struct user_namespace *ns, int cap);
61470 extern bool nsown_capable(int cap);
61471 extern bool inode_capable(const struct inode *inode, int cap);
61472 +extern bool capable_nolog(int cap);
61473 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61474 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61475
61476 /* audit system wants to get cap info from files as well */
61477 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61478
61479 +extern int is_privileged_binary(const struct dentry *dentry);
61480 +
61481 #endif /* __KERNEL__ */
61482
61483 #endif /* !_LINUX_CAPABILITY_H */
61484 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61485 index 42e55de..1cd0e66 100644
61486 --- a/include/linux/cleancache.h
61487 +++ b/include/linux/cleancache.h
61488 @@ -31,7 +31,7 @@ struct cleancache_ops {
61489 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61490 void (*invalidate_inode)(int, struct cleancache_filekey);
61491 void (*invalidate_fs)(int);
61492 -};
61493 +} __no_const;
61494
61495 extern struct cleancache_ops
61496 cleancache_register_ops(struct cleancache_ops *ops);
61497 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61498 index 77335fa..6cbe7dd 100644
61499 --- a/include/linux/clk-provider.h
61500 +++ b/include/linux/clk-provider.h
61501 @@ -111,6 +111,7 @@ struct clk_ops {
61502 unsigned long);
61503 void (*init)(struct clk_hw *hw);
61504 };
61505 +typedef struct clk_ops __no_const clk_ops_no_const;
61506
61507 /**
61508 * struct clk_init_data - holds init data that's common to all clocks and is
61509 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61510 index 934bc34..1b47129 100644
61511 --- a/include/linux/compiler-gcc4.h
61512 +++ b/include/linux/compiler-gcc4.h
61513 @@ -32,6 +32,21 @@
61514 #define __linktime_error(message) __attribute__((__error__(message)))
61515
61516 #if __GNUC_MINOR__ >= 5
61517 +
61518 +#ifdef CONSTIFY_PLUGIN
61519 +#define __no_const __attribute__((no_const))
61520 +#define __do_const __attribute__((do_const))
61521 +#endif
61522 +
61523 +#ifdef SIZE_OVERFLOW_PLUGIN
61524 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61525 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61526 +#endif
61527 +
61528 +#ifdef LATENT_ENTROPY_PLUGIN
61529 +#define __latent_entropy __attribute__((latent_entropy))
61530 +#endif
61531 +
61532 /*
61533 * Mark a position in code as unreachable. This can be used to
61534 * suppress control flow warnings after asm blocks that transfer
61535 @@ -47,6 +62,11 @@
61536 #define __noclone __attribute__((__noclone__))
61537
61538 #endif
61539 +
61540 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61541 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61542 +#define __bos0(ptr) __bos((ptr), 0)
61543 +#define __bos1(ptr) __bos((ptr), 1)
61544 #endif
61545
61546 #if __GNUC_MINOR__ >= 6
61547 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61548 index f430e41..38be90f 100644
61549 --- a/include/linux/compiler.h
61550 +++ b/include/linux/compiler.h
61551 @@ -5,31 +5,62 @@
61552
61553 #ifdef __CHECKER__
61554 # define __user __attribute__((noderef, address_space(1)))
61555 +# define __force_user __force __user
61556 # define __kernel __attribute__((address_space(0)))
61557 +# define __force_kernel __force __kernel
61558 # define __safe __attribute__((safe))
61559 # define __force __attribute__((force))
61560 # define __nocast __attribute__((nocast))
61561 # define __iomem __attribute__((noderef, address_space(2)))
61562 +# define __force_iomem __force __iomem
61563 # define __acquires(x) __attribute__((context(x,0,1)))
61564 # define __releases(x) __attribute__((context(x,1,0)))
61565 # define __acquire(x) __context__(x,1)
61566 # define __release(x) __context__(x,-1)
61567 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61568 # define __percpu __attribute__((noderef, address_space(3)))
61569 +# define __force_percpu __force __percpu
61570 #ifdef CONFIG_SPARSE_RCU_POINTER
61571 # define __rcu __attribute__((noderef, address_space(4)))
61572 +# define __force_rcu __force __rcu
61573 #else
61574 # define __rcu
61575 +# define __force_rcu
61576 #endif
61577 extern void __chk_user_ptr(const volatile void __user *);
61578 extern void __chk_io_ptr(const volatile void __iomem *);
61579 +#elif defined(CHECKER_PLUGIN)
61580 +//# define __user
61581 +//# define __force_user
61582 +//# define __kernel
61583 +//# define __force_kernel
61584 +# define __safe
61585 +# define __force
61586 +# define __nocast
61587 +# define __iomem
61588 +# define __force_iomem
61589 +# define __chk_user_ptr(x) (void)0
61590 +# define __chk_io_ptr(x) (void)0
61591 +# define __builtin_warning(x, y...) (1)
61592 +# define __acquires(x)
61593 +# define __releases(x)
61594 +# define __acquire(x) (void)0
61595 +# define __release(x) (void)0
61596 +# define __cond_lock(x,c) (c)
61597 +# define __percpu
61598 +# define __force_percpu
61599 +# define __rcu
61600 +# define __force_rcu
61601 #else
61602 # define __user
61603 +# define __force_user
61604 # define __kernel
61605 +# define __force_kernel
61606 # define __safe
61607 # define __force
61608 # define __nocast
61609 # define __iomem
61610 +# define __force_iomem
61611 # define __chk_user_ptr(x) (void)0
61612 # define __chk_io_ptr(x) (void)0
61613 # define __builtin_warning(x, y...) (1)
61614 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61615 # define __release(x) (void)0
61616 # define __cond_lock(x,c) (c)
61617 # define __percpu
61618 +# define __force_percpu
61619 # define __rcu
61620 +# define __force_rcu
61621 #endif
61622
61623 #ifdef __KERNEL__
61624 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61625 # define __attribute_const__ /* unimplemented */
61626 #endif
61627
61628 +#ifndef __no_const
61629 +# define __no_const
61630 +#endif
61631 +
61632 +#ifndef __do_const
61633 +# define __do_const
61634 +#endif
61635 +
61636 +#ifndef __size_overflow
61637 +# define __size_overflow(...)
61638 +#endif
61639 +
61640 +#ifndef __intentional_overflow
61641 +# define __intentional_overflow(...)
61642 +#endif
61643 +
61644 +#ifndef __latent_entropy
61645 +# define __latent_entropy
61646 +#endif
61647 +
61648 /*
61649 * Tell gcc if a function is cold. The compiler will assume any path
61650 * directly leading to the call is unlikely.
61651 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61652 #define __cold
61653 #endif
61654
61655 +#ifndef __alloc_size
61656 +#define __alloc_size(...)
61657 +#endif
61658 +
61659 +#ifndef __bos
61660 +#define __bos(ptr, arg)
61661 +#endif
61662 +
61663 +#ifndef __bos0
61664 +#define __bos0(ptr)
61665 +#endif
61666 +
61667 +#ifndef __bos1
61668 +#define __bos1(ptr)
61669 +#endif
61670 +
61671 /* Simple shorthand for a section definition */
61672 #ifndef __section
61673 # define __section(S) __attribute__ ((__section__(#S)))
61674 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61675 * use is to mediate communication between process-level code and irq/NMI
61676 * handlers, all running on the same CPU.
61677 */
61678 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61679 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61680 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61681
61682 #endif /* __LINUX_COMPILER_H */
61683 diff --git a/include/linux/cred.h b/include/linux/cred.h
61684 index ebbed2c..908cc2c 100644
61685 --- a/include/linux/cred.h
61686 +++ b/include/linux/cred.h
61687 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61688 static inline void validate_process_creds(void)
61689 {
61690 }
61691 +static inline void validate_task_creds(struct task_struct *task)
61692 +{
61693 +}
61694 #endif
61695
61696 /**
61697 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61698 index b92eadf..b4ecdc1 100644
61699 --- a/include/linux/crypto.h
61700 +++ b/include/linux/crypto.h
61701 @@ -373,7 +373,7 @@ struct cipher_tfm {
61702 const u8 *key, unsigned int keylen);
61703 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61704 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61705 -};
61706 +} __no_const;
61707
61708 struct hash_tfm {
61709 int (*init)(struct hash_desc *desc);
61710 @@ -394,13 +394,13 @@ struct compress_tfm {
61711 int (*cot_decompress)(struct crypto_tfm *tfm,
61712 const u8 *src, unsigned int slen,
61713 u8 *dst, unsigned int *dlen);
61714 -};
61715 +} __no_const;
61716
61717 struct rng_tfm {
61718 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61719 unsigned int dlen);
61720 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61721 -};
61722 +} __no_const;
61723
61724 #define crt_ablkcipher crt_u.ablkcipher
61725 #define crt_aead crt_u.aead
61726 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61727 index 7925bf0..d5143d2 100644
61728 --- a/include/linux/decompress/mm.h
61729 +++ b/include/linux/decompress/mm.h
61730 @@ -77,7 +77,7 @@ static void free(void *where)
61731 * warnings when not needed (indeed large_malloc / large_free are not
61732 * needed by inflate */
61733
61734 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61735 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61736 #define free(a) kfree(a)
61737
61738 #define large_malloc(a) vmalloc(a)
61739 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61740 index 94af418..b1ca7a2 100644
61741 --- a/include/linux/dma-mapping.h
61742 +++ b/include/linux/dma-mapping.h
61743 @@ -54,7 +54,7 @@ struct dma_map_ops {
61744 u64 (*get_required_mask)(struct device *dev);
61745 #endif
61746 int is_phys;
61747 -};
61748 +} __do_const;
61749
61750 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61751
61752 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61753 index 9c02a45..89fdd73 100644
61754 --- a/include/linux/dmaengine.h
61755 +++ b/include/linux/dmaengine.h
61756 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61757 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61758 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61759
61760 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61761 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61762 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61763 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61764 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61765 struct dma_pinned_list *pinned_list, struct page *page,
61766 unsigned int offset, size_t len);
61767
61768 diff --git a/include/linux/efi.h b/include/linux/efi.h
61769 index 5782114..e9b1ba1 100644
61770 --- a/include/linux/efi.h
61771 +++ b/include/linux/efi.h
61772 @@ -640,7 +640,7 @@ struct efivar_operations {
61773 efi_get_variable_t *get_variable;
61774 efi_get_next_variable_t *get_next_variable;
61775 efi_set_variable_t *set_variable;
61776 -};
61777 +} __no_const;
61778
61779 struct efivars {
61780 /*
61781 diff --git a/include/linux/elf.h b/include/linux/elf.h
61782 index 999b4f5..57753b4 100644
61783 --- a/include/linux/elf.h
61784 +++ b/include/linux/elf.h
61785 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61786 #define PT_GNU_EH_FRAME 0x6474e550
61787
61788 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61789 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61790 +
61791 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61792 +
61793 +/* Constants for the e_flags field */
61794 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61795 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61796 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61797 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61798 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61799 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61800
61801 /*
61802 * Extended Numbering
61803 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61804 #define DT_DEBUG 21
61805 #define DT_TEXTREL 22
61806 #define DT_JMPREL 23
61807 +#define DT_FLAGS 30
61808 + #define DF_TEXTREL 0x00000004
61809 #define DT_ENCODING 32
61810 #define OLD_DT_LOOS 0x60000000
61811 #define DT_LOOS 0x6000000d
61812 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61813 #define PF_W 0x2
61814 #define PF_X 0x1
61815
61816 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61817 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61818 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61819 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61820 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61821 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61822 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61823 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61824 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61825 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61826 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61827 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61828 +
61829 typedef struct elf32_phdr{
61830 Elf32_Word p_type;
61831 Elf32_Off p_offset;
61832 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61833 #define EI_OSABI 7
61834 #define EI_PAD 8
61835
61836 +#define EI_PAX 14
61837 +
61838 #define ELFMAG0 0x7f /* EI_MAG */
61839 #define ELFMAG1 'E'
61840 #define ELFMAG2 'L'
61841 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61842 #define elf_note elf32_note
61843 #define elf_addr_t Elf32_Off
61844 #define Elf_Half Elf32_Half
61845 +#define elf_dyn Elf32_Dyn
61846
61847 #else
61848
61849 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61850 #define elf_note elf64_note
61851 #define elf_addr_t Elf64_Off
61852 #define Elf_Half Elf64_Half
61853 +#define elf_dyn Elf64_Dyn
61854
61855 #endif
61856
61857 diff --git a/include/linux/filter.h b/include/linux/filter.h
61858 index 82b0135..917914d 100644
61859 --- a/include/linux/filter.h
61860 +++ b/include/linux/filter.h
61861 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61862
61863 struct sk_buff;
61864 struct sock;
61865 +struct bpf_jit_work;
61866
61867 struct sk_filter
61868 {
61869 @@ -153,6 +154,9 @@ struct sk_filter
61870 unsigned int len; /* Number of filter blocks */
61871 unsigned int (*bpf_func)(const struct sk_buff *skb,
61872 const struct sock_filter *filter);
61873 +#ifdef CONFIG_BPF_JIT
61874 + struct bpf_jit_work *work;
61875 +#endif
61876 struct rcu_head rcu;
61877 struct sock_filter insns[0];
61878 };
61879 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61880 index db04ec5..f6ed627 100644
61881 --- a/include/linux/firewire.h
61882 +++ b/include/linux/firewire.h
61883 @@ -430,7 +430,7 @@ struct fw_iso_context {
61884 union {
61885 fw_iso_callback_t sc;
61886 fw_iso_mc_callback_t mc;
61887 - } callback;
61888 + } __no_const callback;
61889 void *callback_data;
61890 };
61891
61892 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61893 index 0e4e2ee..4ff4312 100644
61894 --- a/include/linux/frontswap.h
61895 +++ b/include/linux/frontswap.h
61896 @@ -11,7 +11,7 @@ struct frontswap_ops {
61897 int (*load)(unsigned, pgoff_t, struct page *);
61898 void (*invalidate_page)(unsigned, pgoff_t);
61899 void (*invalidate_area)(unsigned);
61900 -};
61901 +} __no_const;
61902
61903 extern bool frontswap_enabled;
61904 extern struct frontswap_ops
61905 diff --git a/include/linux/fs.h b/include/linux/fs.h
61906 index aa11047..7d046d0 100644
61907 --- a/include/linux/fs.h
61908 +++ b/include/linux/fs.h
61909 @@ -1802,7 +1802,8 @@ struct file_operations {
61910 int (*setlease)(struct file *, long, struct file_lock **);
61911 long (*fallocate)(struct file *file, int mode, loff_t offset,
61912 loff_t len);
61913 -};
61914 +} __do_const;
61915 +typedef struct file_operations __no_const file_operations_no_const;
61916
61917 struct inode_operations {
61918 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61919 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61920 index 003dc0f..3c4ea97 100644
61921 --- a/include/linux/fs_struct.h
61922 +++ b/include/linux/fs_struct.h
61923 @@ -6,7 +6,7 @@
61924 #include <linux/seqlock.h>
61925
61926 struct fs_struct {
61927 - int users;
61928 + atomic_t users;
61929 spinlock_t lock;
61930 seqcount_t seq;
61931 int umask;
61932 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61933 index ce31408..b1ad003 100644
61934 --- a/include/linux/fscache-cache.h
61935 +++ b/include/linux/fscache-cache.h
61936 @@ -102,7 +102,7 @@ struct fscache_operation {
61937 fscache_operation_release_t release;
61938 };
61939
61940 -extern atomic_t fscache_op_debug_id;
61941 +extern atomic_unchecked_t fscache_op_debug_id;
61942 extern void fscache_op_work_func(struct work_struct *work);
61943
61944 extern void fscache_enqueue_operation(struct fscache_operation *);
61945 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61946 {
61947 INIT_WORK(&op->work, fscache_op_work_func);
61948 atomic_set(&op->usage, 1);
61949 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61950 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61951 op->processor = processor;
61952 op->release = release;
61953 INIT_LIST_HEAD(&op->pend_link);
61954 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61955 index a6dfe69..569586df 100644
61956 --- a/include/linux/fsnotify.h
61957 +++ b/include/linux/fsnotify.h
61958 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61959 */
61960 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61961 {
61962 - return kstrdup(name, GFP_KERNEL);
61963 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61964 }
61965
61966 /*
61967 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61968 index 63d966d..cdcb717 100644
61969 --- a/include/linux/fsnotify_backend.h
61970 +++ b/include/linux/fsnotify_backend.h
61971 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61972 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61973 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61974 };
61975 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61976
61977 /*
61978 * A group is a "thing" that wants to receive notification about filesystem
61979 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61980 index 642928c..e6c83a7 100644
61981 --- a/include/linux/ftrace_event.h
61982 +++ b/include/linux/ftrace_event.h
61983 @@ -97,7 +97,7 @@ struct trace_event_functions {
61984 trace_print_func raw;
61985 trace_print_func hex;
61986 trace_print_func binary;
61987 -};
61988 +} __no_const;
61989
61990 struct trace_event {
61991 struct hlist_node node;
61992 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61993 extern int trace_add_event_call(struct ftrace_event_call *call);
61994 extern void trace_remove_event_call(struct ftrace_event_call *call);
61995
61996 -#define is_signed_type(type) (((type)(-1)) < 0)
61997 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61998
61999 int trace_set_clr_event(const char *system, const char *event, int set);
62000
62001 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62002 index 4f440b3..342233a 100644
62003 --- a/include/linux/genhd.h
62004 +++ b/include/linux/genhd.h
62005 @@ -190,7 +190,7 @@ struct gendisk {
62006 struct kobject *slave_dir;
62007
62008 struct timer_rand_state *random;
62009 - atomic_t sync_io; /* RAID */
62010 + atomic_unchecked_t sync_io; /* RAID */
62011 struct disk_events *ev;
62012 #ifdef CONFIG_BLK_DEV_INTEGRITY
62013 struct blk_integrity *integrity;
62014 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62015 index 4883f39..26688a8 100644
62016 --- a/include/linux/gfp.h
62017 +++ b/include/linux/gfp.h
62018 @@ -39,6 +39,12 @@ struct vm_area_struct;
62019 #define ___GFP_OTHER_NODE 0x800000u
62020 #define ___GFP_WRITE 0x1000000u
62021
62022 +#ifdef CONFIG_PAX_USERCOPY_SLABS
62023 +#define ___GFP_USERCOPY 0x2000000u
62024 +#else
62025 +#define ___GFP_USERCOPY 0
62026 +#endif
62027 +
62028 /*
62029 * GFP bitmasks..
62030 *
62031 @@ -93,6 +99,7 @@ struct vm_area_struct;
62032 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62033 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62034 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62035 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62036
62037 /*
62038 * This may seem redundant, but it's a way of annotating false positives vs.
62039 @@ -100,7 +107,7 @@ struct vm_area_struct;
62040 */
62041 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62042
62043 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62044 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62045 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62046
62047 /* This equals 0, but use constants in case they ever change */
62048 @@ -154,6 +161,8 @@ struct vm_area_struct;
62049 /* 4GB DMA on some platforms */
62050 #define GFP_DMA32 __GFP_DMA32
62051
62052 +#define GFP_USERCOPY __GFP_USERCOPY
62053 +
62054 /* Convert GFP flags to their corresponding migrate type */
62055 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62056 {
62057 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62058 new file mode 100644
62059 index 0000000..c938b1f
62060 --- /dev/null
62061 +++ b/include/linux/gracl.h
62062 @@ -0,0 +1,319 @@
62063 +#ifndef GR_ACL_H
62064 +#define GR_ACL_H
62065 +
62066 +#include <linux/grdefs.h>
62067 +#include <linux/resource.h>
62068 +#include <linux/capability.h>
62069 +#include <linux/dcache.h>
62070 +#include <asm/resource.h>
62071 +
62072 +/* Major status information */
62073 +
62074 +#define GR_VERSION "grsecurity 2.9.1"
62075 +#define GRSECURITY_VERSION 0x2901
62076 +
62077 +enum {
62078 + GR_SHUTDOWN = 0,
62079 + GR_ENABLE = 1,
62080 + GR_SPROLE = 2,
62081 + GR_RELOAD = 3,
62082 + GR_SEGVMOD = 4,
62083 + GR_STATUS = 5,
62084 + GR_UNSPROLE = 6,
62085 + GR_PASSSET = 7,
62086 + GR_SPROLEPAM = 8,
62087 +};
62088 +
62089 +/* Password setup definitions
62090 + * kernel/grhash.c */
62091 +enum {
62092 + GR_PW_LEN = 128,
62093 + GR_SALT_LEN = 16,
62094 + GR_SHA_LEN = 32,
62095 +};
62096 +
62097 +enum {
62098 + GR_SPROLE_LEN = 64,
62099 +};
62100 +
62101 +enum {
62102 + GR_NO_GLOB = 0,
62103 + GR_REG_GLOB,
62104 + GR_CREATE_GLOB
62105 +};
62106 +
62107 +#define GR_NLIMITS 32
62108 +
62109 +/* Begin Data Structures */
62110 +
62111 +struct sprole_pw {
62112 + unsigned char *rolename;
62113 + unsigned char salt[GR_SALT_LEN];
62114 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62115 +};
62116 +
62117 +struct name_entry {
62118 + __u32 key;
62119 + ino_t inode;
62120 + dev_t device;
62121 + char *name;
62122 + __u16 len;
62123 + __u8 deleted;
62124 + struct name_entry *prev;
62125 + struct name_entry *next;
62126 +};
62127 +
62128 +struct inodev_entry {
62129 + struct name_entry *nentry;
62130 + struct inodev_entry *prev;
62131 + struct inodev_entry *next;
62132 +};
62133 +
62134 +struct acl_role_db {
62135 + struct acl_role_label **r_hash;
62136 + __u32 r_size;
62137 +};
62138 +
62139 +struct inodev_db {
62140 + struct inodev_entry **i_hash;
62141 + __u32 i_size;
62142 +};
62143 +
62144 +struct name_db {
62145 + struct name_entry **n_hash;
62146 + __u32 n_size;
62147 +};
62148 +
62149 +struct crash_uid {
62150 + uid_t uid;
62151 + unsigned long expires;
62152 +};
62153 +
62154 +struct gr_hash_struct {
62155 + void **table;
62156 + void **nametable;
62157 + void *first;
62158 + __u32 table_size;
62159 + __u32 used_size;
62160 + int type;
62161 +};
62162 +
62163 +/* Userspace Grsecurity ACL data structures */
62164 +
62165 +struct acl_subject_label {
62166 + char *filename;
62167 + ino_t inode;
62168 + dev_t device;
62169 + __u32 mode;
62170 + kernel_cap_t cap_mask;
62171 + kernel_cap_t cap_lower;
62172 + kernel_cap_t cap_invert_audit;
62173 +
62174 + struct rlimit res[GR_NLIMITS];
62175 + __u32 resmask;
62176 +
62177 + __u8 user_trans_type;
62178 + __u8 group_trans_type;
62179 + uid_t *user_transitions;
62180 + gid_t *group_transitions;
62181 + __u16 user_trans_num;
62182 + __u16 group_trans_num;
62183 +
62184 + __u32 sock_families[2];
62185 + __u32 ip_proto[8];
62186 + __u32 ip_type;
62187 + struct acl_ip_label **ips;
62188 + __u32 ip_num;
62189 + __u32 inaddr_any_override;
62190 +
62191 + __u32 crashes;
62192 + unsigned long expires;
62193 +
62194 + struct acl_subject_label *parent_subject;
62195 + struct gr_hash_struct *hash;
62196 + struct acl_subject_label *prev;
62197 + struct acl_subject_label *next;
62198 +
62199 + struct acl_object_label **obj_hash;
62200 + __u32 obj_hash_size;
62201 + __u16 pax_flags;
62202 +};
62203 +
62204 +struct role_allowed_ip {
62205 + __u32 addr;
62206 + __u32 netmask;
62207 +
62208 + struct role_allowed_ip *prev;
62209 + struct role_allowed_ip *next;
62210 +};
62211 +
62212 +struct role_transition {
62213 + char *rolename;
62214 +
62215 + struct role_transition *prev;
62216 + struct role_transition *next;
62217 +};
62218 +
62219 +struct acl_role_label {
62220 + char *rolename;
62221 + uid_t uidgid;
62222 + __u16 roletype;
62223 +
62224 + __u16 auth_attempts;
62225 + unsigned long expires;
62226 +
62227 + struct acl_subject_label *root_label;
62228 + struct gr_hash_struct *hash;
62229 +
62230 + struct acl_role_label *prev;
62231 + struct acl_role_label *next;
62232 +
62233 + struct role_transition *transitions;
62234 + struct role_allowed_ip *allowed_ips;
62235 + uid_t *domain_children;
62236 + __u16 domain_child_num;
62237 +
62238 + umode_t umask;
62239 +
62240 + struct acl_subject_label **subj_hash;
62241 + __u32 subj_hash_size;
62242 +};
62243 +
62244 +struct user_acl_role_db {
62245 + struct acl_role_label **r_table;
62246 + __u32 num_pointers; /* Number of allocations to track */
62247 + __u32 num_roles; /* Number of roles */
62248 + __u32 num_domain_children; /* Number of domain children */
62249 + __u32 num_subjects; /* Number of subjects */
62250 + __u32 num_objects; /* Number of objects */
62251 +};
62252 +
62253 +struct acl_object_label {
62254 + char *filename;
62255 + ino_t inode;
62256 + dev_t device;
62257 + __u32 mode;
62258 +
62259 + struct acl_subject_label *nested;
62260 + struct acl_object_label *globbed;
62261 +
62262 + /* next two structures not used */
62263 +
62264 + struct acl_object_label *prev;
62265 + struct acl_object_label *next;
62266 +};
62267 +
62268 +struct acl_ip_label {
62269 + char *iface;
62270 + __u32 addr;
62271 + __u32 netmask;
62272 + __u16 low, high;
62273 + __u8 mode;
62274 + __u32 type;
62275 + __u32 proto[8];
62276 +
62277 + /* next two structures not used */
62278 +
62279 + struct acl_ip_label *prev;
62280 + struct acl_ip_label *next;
62281 +};
62282 +
62283 +struct gr_arg {
62284 + struct user_acl_role_db role_db;
62285 + unsigned char pw[GR_PW_LEN];
62286 + unsigned char salt[GR_SALT_LEN];
62287 + unsigned char sum[GR_SHA_LEN];
62288 + unsigned char sp_role[GR_SPROLE_LEN];
62289 + struct sprole_pw *sprole_pws;
62290 + dev_t segv_device;
62291 + ino_t segv_inode;
62292 + uid_t segv_uid;
62293 + __u16 num_sprole_pws;
62294 + __u16 mode;
62295 +};
62296 +
62297 +struct gr_arg_wrapper {
62298 + struct gr_arg *arg;
62299 + __u32 version;
62300 + __u32 size;
62301 +};
62302 +
62303 +struct subject_map {
62304 + struct acl_subject_label *user;
62305 + struct acl_subject_label *kernel;
62306 + struct subject_map *prev;
62307 + struct subject_map *next;
62308 +};
62309 +
62310 +struct acl_subj_map_db {
62311 + struct subject_map **s_hash;
62312 + __u32 s_size;
62313 +};
62314 +
62315 +/* End Data Structures Section */
62316 +
62317 +/* Hash functions generated by empirical testing by Brad Spengler
62318 + Makes good use of the low bits of the inode. Generally 0-1 times
62319 + in loop for successful match. 0-3 for unsuccessful match.
62320 + Shift/add algorithm with modulus of table size and an XOR*/
62321 +
62322 +static __inline__ unsigned int
62323 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62324 +{
62325 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62326 +}
62327 +
62328 + static __inline__ unsigned int
62329 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62330 +{
62331 + return ((const unsigned long)userp % sz);
62332 +}
62333 +
62334 +static __inline__ unsigned int
62335 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62336 +{
62337 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62338 +}
62339 +
62340 +static __inline__ unsigned int
62341 +nhash(const char *name, const __u16 len, const unsigned int sz)
62342 +{
62343 + return full_name_hash((const unsigned char *)name, len) % sz;
62344 +}
62345 +
62346 +#define FOR_EACH_ROLE_START(role) \
62347 + role = role_list; \
62348 + while (role) {
62349 +
62350 +#define FOR_EACH_ROLE_END(role) \
62351 + role = role->prev; \
62352 + }
62353 +
62354 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62355 + subj = NULL; \
62356 + iter = 0; \
62357 + while (iter < role->subj_hash_size) { \
62358 + if (subj == NULL) \
62359 + subj = role->subj_hash[iter]; \
62360 + if (subj == NULL) { \
62361 + iter++; \
62362 + continue; \
62363 + }
62364 +
62365 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62366 + subj = subj->next; \
62367 + if (subj == NULL) \
62368 + iter++; \
62369 + }
62370 +
62371 +
62372 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62373 + subj = role->hash->first; \
62374 + while (subj != NULL) {
62375 +
62376 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62377 + subj = subj->next; \
62378 + }
62379 +
62380 +#endif
62381 +
62382 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62383 new file mode 100644
62384 index 0000000..323ecf2
62385 --- /dev/null
62386 +++ b/include/linux/gralloc.h
62387 @@ -0,0 +1,9 @@
62388 +#ifndef __GRALLOC_H
62389 +#define __GRALLOC_H
62390 +
62391 +void acl_free_all(void);
62392 +int acl_alloc_stack_init(unsigned long size);
62393 +void *acl_alloc(unsigned long len);
62394 +void *acl_alloc_num(unsigned long num, unsigned long len);
62395 +
62396 +#endif
62397 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62398 new file mode 100644
62399 index 0000000..b30e9bc
62400 --- /dev/null
62401 +++ b/include/linux/grdefs.h
62402 @@ -0,0 +1,140 @@
62403 +#ifndef GRDEFS_H
62404 +#define GRDEFS_H
62405 +
62406 +/* Begin grsecurity status declarations */
62407 +
62408 +enum {
62409 + GR_READY = 0x01,
62410 + GR_STATUS_INIT = 0x00 // disabled state
62411 +};
62412 +
62413 +/* Begin ACL declarations */
62414 +
62415 +/* Role flags */
62416 +
62417 +enum {
62418 + GR_ROLE_USER = 0x0001,
62419 + GR_ROLE_GROUP = 0x0002,
62420 + GR_ROLE_DEFAULT = 0x0004,
62421 + GR_ROLE_SPECIAL = 0x0008,
62422 + GR_ROLE_AUTH = 0x0010,
62423 + GR_ROLE_NOPW = 0x0020,
62424 + GR_ROLE_GOD = 0x0040,
62425 + GR_ROLE_LEARN = 0x0080,
62426 + GR_ROLE_TPE = 0x0100,
62427 + GR_ROLE_DOMAIN = 0x0200,
62428 + GR_ROLE_PAM = 0x0400,
62429 + GR_ROLE_PERSIST = 0x0800
62430 +};
62431 +
62432 +/* ACL Subject and Object mode flags */
62433 +enum {
62434 + GR_DELETED = 0x80000000
62435 +};
62436 +
62437 +/* ACL Object-only mode flags */
62438 +enum {
62439 + GR_READ = 0x00000001,
62440 + GR_APPEND = 0x00000002,
62441 + GR_WRITE = 0x00000004,
62442 + GR_EXEC = 0x00000008,
62443 + GR_FIND = 0x00000010,
62444 + GR_INHERIT = 0x00000020,
62445 + GR_SETID = 0x00000040,
62446 + GR_CREATE = 0x00000080,
62447 + GR_DELETE = 0x00000100,
62448 + GR_LINK = 0x00000200,
62449 + GR_AUDIT_READ = 0x00000400,
62450 + GR_AUDIT_APPEND = 0x00000800,
62451 + GR_AUDIT_WRITE = 0x00001000,
62452 + GR_AUDIT_EXEC = 0x00002000,
62453 + GR_AUDIT_FIND = 0x00004000,
62454 + GR_AUDIT_INHERIT= 0x00008000,
62455 + GR_AUDIT_SETID = 0x00010000,
62456 + GR_AUDIT_CREATE = 0x00020000,
62457 + GR_AUDIT_DELETE = 0x00040000,
62458 + GR_AUDIT_LINK = 0x00080000,
62459 + GR_PTRACERD = 0x00100000,
62460 + GR_NOPTRACE = 0x00200000,
62461 + GR_SUPPRESS = 0x00400000,
62462 + GR_NOLEARN = 0x00800000,
62463 + GR_INIT_TRANSFER= 0x01000000
62464 +};
62465 +
62466 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62467 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62468 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62469 +
62470 +/* ACL subject-only mode flags */
62471 +enum {
62472 + GR_KILL = 0x00000001,
62473 + GR_VIEW = 0x00000002,
62474 + GR_PROTECTED = 0x00000004,
62475 + GR_LEARN = 0x00000008,
62476 + GR_OVERRIDE = 0x00000010,
62477 + /* just a placeholder, this mode is only used in userspace */
62478 + GR_DUMMY = 0x00000020,
62479 + GR_PROTSHM = 0x00000040,
62480 + GR_KILLPROC = 0x00000080,
62481 + GR_KILLIPPROC = 0x00000100,
62482 + /* just a placeholder, this mode is only used in userspace */
62483 + GR_NOTROJAN = 0x00000200,
62484 + GR_PROTPROCFD = 0x00000400,
62485 + GR_PROCACCT = 0x00000800,
62486 + GR_RELAXPTRACE = 0x00001000,
62487 + GR_NESTED = 0x00002000,
62488 + GR_INHERITLEARN = 0x00004000,
62489 + GR_PROCFIND = 0x00008000,
62490 + GR_POVERRIDE = 0x00010000,
62491 + GR_KERNELAUTH = 0x00020000,
62492 + GR_ATSECURE = 0x00040000,
62493 + GR_SHMEXEC = 0x00080000
62494 +};
62495 +
62496 +enum {
62497 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62498 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62499 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62500 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62501 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62502 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62503 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62504 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62505 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62506 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62507 +};
62508 +
62509 +enum {
62510 + GR_ID_USER = 0x01,
62511 + GR_ID_GROUP = 0x02,
62512 +};
62513 +
62514 +enum {
62515 + GR_ID_ALLOW = 0x01,
62516 + GR_ID_DENY = 0x02,
62517 +};
62518 +
62519 +#define GR_CRASH_RES 31
62520 +#define GR_UIDTABLE_MAX 500
62521 +
62522 +/* begin resource learning section */
62523 +enum {
62524 + GR_RLIM_CPU_BUMP = 60,
62525 + GR_RLIM_FSIZE_BUMP = 50000,
62526 + GR_RLIM_DATA_BUMP = 10000,
62527 + GR_RLIM_STACK_BUMP = 1000,
62528 + GR_RLIM_CORE_BUMP = 10000,
62529 + GR_RLIM_RSS_BUMP = 500000,
62530 + GR_RLIM_NPROC_BUMP = 1,
62531 + GR_RLIM_NOFILE_BUMP = 5,
62532 + GR_RLIM_MEMLOCK_BUMP = 50000,
62533 + GR_RLIM_AS_BUMP = 500000,
62534 + GR_RLIM_LOCKS_BUMP = 2,
62535 + GR_RLIM_SIGPENDING_BUMP = 5,
62536 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62537 + GR_RLIM_NICE_BUMP = 1,
62538 + GR_RLIM_RTPRIO_BUMP = 1,
62539 + GR_RLIM_RTTIME_BUMP = 1000000
62540 +};
62541 +
62542 +#endif
62543 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62544 new file mode 100644
62545 index 0000000..c9292f7
62546 --- /dev/null
62547 +++ b/include/linux/grinternal.h
62548 @@ -0,0 +1,223 @@
62549 +#ifndef __GRINTERNAL_H
62550 +#define __GRINTERNAL_H
62551 +
62552 +#ifdef CONFIG_GRKERNSEC
62553 +
62554 +#include <linux/fs.h>
62555 +#include <linux/mnt_namespace.h>
62556 +#include <linux/nsproxy.h>
62557 +#include <linux/gracl.h>
62558 +#include <linux/grdefs.h>
62559 +#include <linux/grmsg.h>
62560 +
62561 +void gr_add_learn_entry(const char *fmt, ...)
62562 + __attribute__ ((format (printf, 1, 2)));
62563 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62564 + const struct vfsmount *mnt);
62565 +__u32 gr_check_create(const struct dentry *new_dentry,
62566 + const struct dentry *parent,
62567 + const struct vfsmount *mnt, const __u32 mode);
62568 +int gr_check_protected_task(const struct task_struct *task);
62569 +__u32 to_gr_audit(const __u32 reqmode);
62570 +int gr_set_acls(const int type);
62571 +int gr_apply_subject_to_task(struct task_struct *task);
62572 +int gr_acl_is_enabled(void);
62573 +char gr_roletype_to_char(void);
62574 +
62575 +void gr_handle_alertkill(struct task_struct *task);
62576 +char *gr_to_filename(const struct dentry *dentry,
62577 + const struct vfsmount *mnt);
62578 +char *gr_to_filename1(const struct dentry *dentry,
62579 + const struct vfsmount *mnt);
62580 +char *gr_to_filename2(const struct dentry *dentry,
62581 + const struct vfsmount *mnt);
62582 +char *gr_to_filename3(const struct dentry *dentry,
62583 + const struct vfsmount *mnt);
62584 +
62585 +extern int grsec_enable_ptrace_readexec;
62586 +extern int grsec_enable_harden_ptrace;
62587 +extern int grsec_enable_link;
62588 +extern int grsec_enable_fifo;
62589 +extern int grsec_enable_execve;
62590 +extern int grsec_enable_shm;
62591 +extern int grsec_enable_execlog;
62592 +extern int grsec_enable_signal;
62593 +extern int grsec_enable_audit_ptrace;
62594 +extern int grsec_enable_forkfail;
62595 +extern int grsec_enable_time;
62596 +extern int grsec_enable_rofs;
62597 +extern int grsec_enable_chroot_shmat;
62598 +extern int grsec_enable_chroot_mount;
62599 +extern int grsec_enable_chroot_double;
62600 +extern int grsec_enable_chroot_pivot;
62601 +extern int grsec_enable_chroot_chdir;
62602 +extern int grsec_enable_chroot_chmod;
62603 +extern int grsec_enable_chroot_mknod;
62604 +extern int grsec_enable_chroot_fchdir;
62605 +extern int grsec_enable_chroot_nice;
62606 +extern int grsec_enable_chroot_execlog;
62607 +extern int grsec_enable_chroot_caps;
62608 +extern int grsec_enable_chroot_sysctl;
62609 +extern int grsec_enable_chroot_unix;
62610 +extern int grsec_enable_symlinkown;
62611 +extern int grsec_symlinkown_gid;
62612 +extern int grsec_enable_tpe;
62613 +extern int grsec_tpe_gid;
62614 +extern int grsec_enable_tpe_all;
62615 +extern int grsec_enable_tpe_invert;
62616 +extern int grsec_enable_socket_all;
62617 +extern int grsec_socket_all_gid;
62618 +extern int grsec_enable_socket_client;
62619 +extern int grsec_socket_client_gid;
62620 +extern int grsec_enable_socket_server;
62621 +extern int grsec_socket_server_gid;
62622 +extern int grsec_audit_gid;
62623 +extern int grsec_enable_group;
62624 +extern int grsec_enable_audit_textrel;
62625 +extern int grsec_enable_log_rwxmaps;
62626 +extern int grsec_enable_mount;
62627 +extern int grsec_enable_chdir;
62628 +extern int grsec_resource_logging;
62629 +extern int grsec_enable_blackhole;
62630 +extern int grsec_lastack_retries;
62631 +extern int grsec_enable_brute;
62632 +extern int grsec_lock;
62633 +
62634 +extern spinlock_t grsec_alert_lock;
62635 +extern unsigned long grsec_alert_wtime;
62636 +extern unsigned long grsec_alert_fyet;
62637 +
62638 +extern spinlock_t grsec_audit_lock;
62639 +
62640 +extern rwlock_t grsec_exec_file_lock;
62641 +
62642 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62643 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62644 + (tsk)->exec_file->f_vfsmnt) : "/")
62645 +
62646 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62647 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62648 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62649 +
62650 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62651 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62652 + (tsk)->exec_file->f_vfsmnt) : "/")
62653 +
62654 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62655 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62656 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62657 +
62658 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62659 +
62660 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62661 +
62662 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62663 + (task)->pid, (cred)->uid, \
62664 + (cred)->euid, (cred)->gid, (cred)->egid, \
62665 + gr_parent_task_fullpath(task), \
62666 + (task)->real_parent->comm, (task)->real_parent->pid, \
62667 + (pcred)->uid, (pcred)->euid, \
62668 + (pcred)->gid, (pcred)->egid
62669 +
62670 +#define GR_CHROOT_CAPS {{ \
62671 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62672 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62673 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62674 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62675 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62676 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62677 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62678 +
62679 +#define security_learn(normal_msg,args...) \
62680 +({ \
62681 + read_lock(&grsec_exec_file_lock); \
62682 + gr_add_learn_entry(normal_msg "\n", ## args); \
62683 + read_unlock(&grsec_exec_file_lock); \
62684 +})
62685 +
62686 +enum {
62687 + GR_DO_AUDIT,
62688 + GR_DONT_AUDIT,
62689 + /* used for non-audit messages that we shouldn't kill the task on */
62690 + GR_DONT_AUDIT_GOOD
62691 +};
62692 +
62693 +enum {
62694 + GR_TTYSNIFF,
62695 + GR_RBAC,
62696 + GR_RBAC_STR,
62697 + GR_STR_RBAC,
62698 + GR_RBAC_MODE2,
62699 + GR_RBAC_MODE3,
62700 + GR_FILENAME,
62701 + GR_SYSCTL_HIDDEN,
62702 + GR_NOARGS,
62703 + GR_ONE_INT,
62704 + GR_ONE_INT_TWO_STR,
62705 + GR_ONE_STR,
62706 + GR_STR_INT,
62707 + GR_TWO_STR_INT,
62708 + GR_TWO_INT,
62709 + GR_TWO_U64,
62710 + GR_THREE_INT,
62711 + GR_FIVE_INT_TWO_STR,
62712 + GR_TWO_STR,
62713 + GR_THREE_STR,
62714 + GR_FOUR_STR,
62715 + GR_STR_FILENAME,
62716 + GR_FILENAME_STR,
62717 + GR_FILENAME_TWO_INT,
62718 + GR_FILENAME_TWO_INT_STR,
62719 + GR_TEXTREL,
62720 + GR_PTRACE,
62721 + GR_RESOURCE,
62722 + GR_CAP,
62723 + GR_SIG,
62724 + GR_SIG2,
62725 + GR_CRASH1,
62726 + GR_CRASH2,
62727 + GR_PSACCT,
62728 + GR_RWXMAP
62729 +};
62730 +
62731 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62732 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62733 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62734 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62735 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62736 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62737 +#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)
62738 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62739 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62740 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62741 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62742 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62743 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62744 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62745 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62746 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62747 +#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)
62748 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62749 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62750 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62751 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62752 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62753 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62754 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62755 +#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)
62756 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62757 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62758 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62759 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62760 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62761 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62762 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62763 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62764 +#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)
62765 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62766 +
62767 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62768 +
62769 +#endif
62770 +
62771 +#endif
62772 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62773 new file mode 100644
62774 index 0000000..54f4e85
62775 --- /dev/null
62776 +++ b/include/linux/grmsg.h
62777 @@ -0,0 +1,110 @@
62778 +#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"
62779 +#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"
62780 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62781 +#define GR_STOPMOD_MSG "denied modification of module state by "
62782 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62783 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62784 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62785 +#define GR_IOPL_MSG "denied use of iopl() by "
62786 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62787 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62788 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62789 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62790 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62791 +#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"
62792 +#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"
62793 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62794 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62795 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62796 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62797 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62798 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62799 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62800 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62801 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62802 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62803 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62804 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62805 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62806 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62807 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62808 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62809 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62810 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62811 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62812 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62813 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62814 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62815 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62816 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62817 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62818 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62819 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62820 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62821 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62822 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62823 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62824 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62825 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62826 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62827 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62828 +#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"
62829 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62830 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62831 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62832 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62833 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62834 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62835 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62836 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62837 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62838 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62839 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62840 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62841 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62842 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62843 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62844 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62845 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62846 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62847 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62848 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62849 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62850 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62851 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62852 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62853 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62854 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62855 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62856 +#define GR_TIME_MSG "time set by "
62857 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62858 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62859 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62860 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62861 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62862 +#define GR_BIND_MSG "denied bind() by "
62863 +#define GR_CONNECT_MSG "denied connect() by "
62864 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62865 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62866 +#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"
62867 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62868 +#define GR_CAP_ACL_MSG "use of %s denied for "
62869 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62870 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62871 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62872 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62873 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62874 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62875 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62876 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62877 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62878 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62879 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62880 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62881 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62882 +#define GR_VM86_MSG "denied use of vm86 by "
62883 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62884 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62885 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62886 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62887 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62888 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62889 new file mode 100644
62890 index 0000000..f9b9a21
62891 --- /dev/null
62892 +++ b/include/linux/grsecurity.h
62893 @@ -0,0 +1,238 @@
62894 +#ifndef GR_SECURITY_H
62895 +#define GR_SECURITY_H
62896 +#include <linux/fs.h>
62897 +#include <linux/fs_struct.h>
62898 +#include <linux/binfmts.h>
62899 +#include <linux/gracl.h>
62900 +
62901 +/* notify of brain-dead configs */
62902 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62903 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62904 +#endif
62905 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62906 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62907 +#endif
62908 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62909 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62910 +#endif
62911 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62912 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62913 +#endif
62914 +
62915 +#include <linux/compat.h>
62916 +
62917 +struct user_arg_ptr {
62918 +#ifdef CONFIG_COMPAT
62919 + bool is_compat;
62920 +#endif
62921 + union {
62922 + const char __user *const __user *native;
62923 +#ifdef CONFIG_COMPAT
62924 + compat_uptr_t __user *compat;
62925 +#endif
62926 + } ptr;
62927 +};
62928 +
62929 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62930 +void gr_handle_brute_check(void);
62931 +void gr_handle_kernel_exploit(void);
62932 +int gr_process_user_ban(void);
62933 +
62934 +char gr_roletype_to_char(void);
62935 +
62936 +int gr_acl_enable_at_secure(void);
62937 +
62938 +int gr_check_user_change(int real, int effective, int fs);
62939 +int gr_check_group_change(int real, int effective, int fs);
62940 +
62941 +void gr_del_task_from_ip_table(struct task_struct *p);
62942 +
62943 +int gr_pid_is_chrooted(struct task_struct *p);
62944 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62945 +int gr_handle_chroot_nice(void);
62946 +int gr_handle_chroot_sysctl(const int op);
62947 +int gr_handle_chroot_setpriority(struct task_struct *p,
62948 + const int niceval);
62949 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62950 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62951 + const struct vfsmount *mnt);
62952 +void gr_handle_chroot_chdir(struct path *path);
62953 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62954 + const struct vfsmount *mnt, const int mode);
62955 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62956 + const struct vfsmount *mnt, const int mode);
62957 +int gr_handle_chroot_mount(const struct dentry *dentry,
62958 + const struct vfsmount *mnt,
62959 + const char *dev_name);
62960 +int gr_handle_chroot_pivot(void);
62961 +int gr_handle_chroot_unix(const pid_t pid);
62962 +
62963 +int gr_handle_rawio(const struct inode *inode);
62964 +
62965 +void gr_handle_ioperm(void);
62966 +void gr_handle_iopl(void);
62967 +
62968 +umode_t gr_acl_umask(void);
62969 +
62970 +int gr_tpe_allow(const struct file *file);
62971 +
62972 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62973 +void gr_clear_chroot_entries(struct task_struct *task);
62974 +
62975 +void gr_log_forkfail(const int retval);
62976 +void gr_log_timechange(void);
62977 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62978 +void gr_log_chdir(const struct dentry *dentry,
62979 + const struct vfsmount *mnt);
62980 +void gr_log_chroot_exec(const struct dentry *dentry,
62981 + const struct vfsmount *mnt);
62982 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62983 +void gr_log_remount(const char *devname, const int retval);
62984 +void gr_log_unmount(const char *devname, const int retval);
62985 +void gr_log_mount(const char *from, const char *to, const int retval);
62986 +void gr_log_textrel(struct vm_area_struct *vma);
62987 +void gr_log_rwxmmap(struct file *file);
62988 +void gr_log_rwxmprotect(struct file *file);
62989 +
62990 +int gr_handle_follow_link(const struct inode *parent,
62991 + const struct inode *inode,
62992 + const struct dentry *dentry,
62993 + const struct vfsmount *mnt);
62994 +int gr_handle_fifo(const struct dentry *dentry,
62995 + const struct vfsmount *mnt,
62996 + const struct dentry *dir, const int flag,
62997 + const int acc_mode);
62998 +int gr_handle_hardlink(const struct dentry *dentry,
62999 + const struct vfsmount *mnt,
63000 + struct inode *inode,
63001 + const int mode, const char *to);
63002 +
63003 +int gr_is_capable(const int cap);
63004 +int gr_is_capable_nolog(const int cap);
63005 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63006 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63007 +
63008 +void gr_learn_resource(const struct task_struct *task, const int limit,
63009 + const unsigned long wanted, const int gt);
63010 +void gr_copy_label(struct task_struct *tsk);
63011 +void gr_handle_crash(struct task_struct *task, const int sig);
63012 +int gr_handle_signal(const struct task_struct *p, const int sig);
63013 +int gr_check_crash_uid(const uid_t uid);
63014 +int gr_check_protected_task(const struct task_struct *task);
63015 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63016 +int gr_acl_handle_mmap(const struct file *file,
63017 + const unsigned long prot);
63018 +int gr_acl_handle_mprotect(const struct file *file,
63019 + const unsigned long prot);
63020 +int gr_check_hidden_task(const struct task_struct *tsk);
63021 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63022 + const struct vfsmount *mnt);
63023 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63024 + const struct vfsmount *mnt);
63025 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63026 + const struct vfsmount *mnt, const int fmode);
63027 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63028 + const struct vfsmount *mnt, umode_t *mode);
63029 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63030 + const struct vfsmount *mnt);
63031 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63032 + const struct vfsmount *mnt);
63033 +int gr_handle_ptrace(struct task_struct *task, const long request);
63034 +int gr_handle_proc_ptrace(struct task_struct *task);
63035 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63036 + const struct vfsmount *mnt);
63037 +int gr_check_crash_exec(const struct file *filp);
63038 +int gr_acl_is_enabled(void);
63039 +void gr_set_kernel_label(struct task_struct *task);
63040 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63041 + const gid_t gid);
63042 +int gr_set_proc_label(const struct dentry *dentry,
63043 + const struct vfsmount *mnt,
63044 + const int unsafe_flags);
63045 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63046 + const struct vfsmount *mnt);
63047 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63048 + const struct vfsmount *mnt, int acc_mode);
63049 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63050 + const struct dentry *p_dentry,
63051 + const struct vfsmount *p_mnt,
63052 + int open_flags, int acc_mode, const int imode);
63053 +void gr_handle_create(const struct dentry *dentry,
63054 + const struct vfsmount *mnt);
63055 +void gr_handle_proc_create(const struct dentry *dentry,
63056 + const struct inode *inode);
63057 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63058 + const struct dentry *parent_dentry,
63059 + const struct vfsmount *parent_mnt,
63060 + const int mode);
63061 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63062 + const struct dentry *parent_dentry,
63063 + const struct vfsmount *parent_mnt);
63064 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63065 + const struct vfsmount *mnt);
63066 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63067 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63068 + const struct vfsmount *mnt);
63069 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63070 + const struct dentry *parent_dentry,
63071 + const struct vfsmount *parent_mnt,
63072 + const char *from);
63073 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63074 + const struct dentry *parent_dentry,
63075 + const struct vfsmount *parent_mnt,
63076 + const struct dentry *old_dentry,
63077 + const struct vfsmount *old_mnt, const char *to);
63078 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63079 +int gr_acl_handle_rename(struct dentry *new_dentry,
63080 + struct dentry *parent_dentry,
63081 + const struct vfsmount *parent_mnt,
63082 + struct dentry *old_dentry,
63083 + struct inode *old_parent_inode,
63084 + struct vfsmount *old_mnt, const char *newname);
63085 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63086 + struct dentry *old_dentry,
63087 + struct dentry *new_dentry,
63088 + struct vfsmount *mnt, const __u8 replace);
63089 +__u32 gr_check_link(const struct dentry *new_dentry,
63090 + const struct dentry *parent_dentry,
63091 + const struct vfsmount *parent_mnt,
63092 + const struct dentry *old_dentry,
63093 + const struct vfsmount *old_mnt);
63094 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63095 + const unsigned int namelen, const ino_t ino);
63096 +
63097 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63098 + const struct vfsmount *mnt);
63099 +void gr_acl_handle_exit(void);
63100 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63101 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63102 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63103 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63104 +void gr_audit_ptrace(struct task_struct *task);
63105 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63106 +
63107 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63108 +
63109 +#ifdef CONFIG_GRKERNSEC
63110 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63111 +void gr_handle_vm86(void);
63112 +void gr_handle_mem_readwrite(u64 from, u64 to);
63113 +
63114 +void gr_log_badprocpid(const char *entry);
63115 +
63116 +extern int grsec_enable_dmesg;
63117 +extern int grsec_disable_privio;
63118 +
63119 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63120 +extern int grsec_proc_gid;
63121 +#endif
63122 +
63123 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63124 +extern int grsec_enable_chroot_findtask;
63125 +#endif
63126 +#ifdef CONFIG_GRKERNSEC_SETXID
63127 +extern int grsec_enable_setxid;
63128 +#endif
63129 +#endif
63130 +
63131 +#endif
63132 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63133 new file mode 100644
63134 index 0000000..e7ffaaf
63135 --- /dev/null
63136 +++ b/include/linux/grsock.h
63137 @@ -0,0 +1,19 @@
63138 +#ifndef __GRSOCK_H
63139 +#define __GRSOCK_H
63140 +
63141 +extern void gr_attach_curr_ip(const struct sock *sk);
63142 +extern int gr_handle_sock_all(const int family, const int type,
63143 + const int protocol);
63144 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63145 +extern int gr_handle_sock_server_other(const struct sock *sck);
63146 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63147 +extern int gr_search_connect(struct socket * sock,
63148 + struct sockaddr_in * addr);
63149 +extern int gr_search_bind(struct socket * sock,
63150 + struct sockaddr_in * addr);
63151 +extern int gr_search_listen(struct socket * sock);
63152 +extern int gr_search_accept(struct socket * sock);
63153 +extern int gr_search_socket(const int domain, const int type,
63154 + const int protocol);
63155 +
63156 +#endif
63157 diff --git a/include/linux/hid.h b/include/linux/hid.h
63158 index 42970de..5db3c92 100644
63159 --- a/include/linux/hid.h
63160 +++ b/include/linux/hid.h
63161 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63162 unsigned int code, int value);
63163
63164 int (*parse)(struct hid_device *hdev);
63165 -};
63166 +} __no_const;
63167
63168 #define PM_HINT_FULLON 1<<5
63169 #define PM_HINT_NORMAL 1<<1
63170 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63171 index ef788b5..ac41b7b 100644
63172 --- a/include/linux/highmem.h
63173 +++ b/include/linux/highmem.h
63174 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63175 kunmap_atomic(kaddr);
63176 }
63177
63178 +static inline void sanitize_highpage(struct page *page)
63179 +{
63180 + void *kaddr;
63181 + unsigned long flags;
63182 +
63183 + local_irq_save(flags);
63184 + kaddr = kmap_atomic(page);
63185 + clear_page(kaddr);
63186 + kunmap_atomic(kaddr);
63187 + local_irq_restore(flags);
63188 +}
63189 +
63190 static inline void zero_user_segments(struct page *page,
63191 unsigned start1, unsigned end1,
63192 unsigned start2, unsigned end2)
63193 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63194 index 5970266..1c48c3b 100644
63195 --- a/include/linux/i2c.h
63196 +++ b/include/linux/i2c.h
63197 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63198 /* To determine what the adapter supports */
63199 u32 (*functionality) (struct i2c_adapter *);
63200 };
63201 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63202
63203 /*
63204 * i2c_adapter is the structure used to identify a physical i2c bus along
63205 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63206 index d23c3c2..eb63c81 100644
63207 --- a/include/linux/i2o.h
63208 +++ b/include/linux/i2o.h
63209 @@ -565,7 +565,7 @@ struct i2o_controller {
63210 struct i2o_device *exec; /* Executive */
63211 #if BITS_PER_LONG == 64
63212 spinlock_t context_list_lock; /* lock for context_list */
63213 - atomic_t context_list_counter; /* needed for unique contexts */
63214 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63215 struct list_head context_list; /* list of context id's
63216 and pointers */
63217 #endif
63218 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63219 index aa2e167..84024ce 100644
63220 --- a/include/linux/if_team.h
63221 +++ b/include/linux/if_team.h
63222 @@ -109,6 +109,7 @@ struct team_mode_ops {
63223 void (*port_enabled)(struct team *team, struct team_port *port);
63224 void (*port_disabled)(struct team *team, struct team_port *port);
63225 };
63226 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63227
63228 enum team_option_type {
63229 TEAM_OPTION_TYPE_U32,
63230 @@ -181,7 +182,7 @@ struct team {
63231 struct list_head option_inst_list; /* list of option instances */
63232
63233 const struct team_mode *mode;
63234 - struct team_mode_ops ops;
63235 + team_mode_ops_no_const ops;
63236 long mode_priv[TEAM_MODE_PRIV_LONGS];
63237 };
63238
63239 diff --git a/include/linux/init.h b/include/linux/init.h
63240 index 5e664f6..0a1225c 100644
63241 --- a/include/linux/init.h
63242 +++ b/include/linux/init.h
63243 @@ -39,9 +39,15 @@
63244 * Also note, that this data cannot be "const".
63245 */
63246
63247 +#ifdef MODULE
63248 +#define add_latent_entropy
63249 +#else
63250 +#define add_latent_entropy __latent_entropy
63251 +#endif
63252 +
63253 /* These are for everybody (although not all archs will actually
63254 discard it in modules) */
63255 -#define __init __section(.init.text) __cold notrace
63256 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63257 #define __initdata __section(.init.data)
63258 #define __initconst __section(.init.rodata)
63259 #define __exitdata __section(.exit.data)
63260 @@ -83,7 +89,7 @@
63261 #define __exit __section(.exit.text) __exitused __cold notrace
63262
63263 /* Used for HOTPLUG */
63264 -#define __devinit __section(.devinit.text) __cold notrace
63265 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63266 #define __devinitdata __section(.devinit.data)
63267 #define __devinitconst __section(.devinit.rodata)
63268 #define __devexit __section(.devexit.text) __exitused __cold notrace
63269 @@ -91,7 +97,7 @@
63270 #define __devexitconst __section(.devexit.rodata)
63271
63272 /* Used for HOTPLUG_CPU */
63273 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63274 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63275 #define __cpuinitdata __section(.cpuinit.data)
63276 #define __cpuinitconst __section(.cpuinit.rodata)
63277 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63278 @@ -99,7 +105,7 @@
63279 #define __cpuexitconst __section(.cpuexit.rodata)
63280
63281 /* Used for MEMORY_HOTPLUG */
63282 -#define __meminit __section(.meminit.text) __cold notrace
63283 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63284 #define __meminitdata __section(.meminit.data)
63285 #define __meminitconst __section(.meminit.rodata)
63286 #define __memexit __section(.memexit.text) __exitused __cold notrace
63287 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63288 index 89f1cb1..7986c0f 100644
63289 --- a/include/linux/init_task.h
63290 +++ b/include/linux/init_task.h
63291 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63292
63293 #define INIT_TASK_COMM "swapper"
63294
63295 +#ifdef CONFIG_X86
63296 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63297 +#else
63298 +#define INIT_TASK_THREAD_INFO
63299 +#endif
63300 +
63301 /*
63302 * INIT_TASK is used to set up the first task table, touch at
63303 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63304 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63305 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63306 .comm = INIT_TASK_COMM, \
63307 .thread = INIT_THREAD, \
63308 + INIT_TASK_THREAD_INFO \
63309 .fs = &init_fs, \
63310 .files = &init_files, \
63311 .signal = &init_signals, \
63312 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63313 index 78e2ada..745564d 100644
63314 --- a/include/linux/intel-iommu.h
63315 +++ b/include/linux/intel-iommu.h
63316 @@ -296,7 +296,7 @@ struct iommu_flush {
63317 u8 fm, u64 type);
63318 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63319 unsigned int size_order, u64 type);
63320 -};
63321 +} __no_const;
63322
63323 enum {
63324 SR_DMAR_FECTL_REG,
63325 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63326 index c5f856a..d29c117 100644
63327 --- a/include/linux/interrupt.h
63328 +++ b/include/linux/interrupt.h
63329 @@ -433,7 +433,7 @@ enum
63330 /* map softirq index to softirq name. update 'softirq_to_name' in
63331 * kernel/softirq.c when adding a new softirq.
63332 */
63333 -extern char *softirq_to_name[NR_SOFTIRQS];
63334 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63335
63336 /* softirq mask and active fields moved to irq_cpustat_t in
63337 * asm/hardirq.h to get better cache usage. KAO
63338 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63339
63340 struct softirq_action
63341 {
63342 - void (*action)(struct softirq_action *);
63343 + void (*action)(void);
63344 };
63345
63346 asmlinkage void do_softirq(void);
63347 asmlinkage void __do_softirq(void);
63348 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63349 +extern void open_softirq(int nr, void (*action)(void));
63350 extern void softirq_init(void);
63351 extern void __raise_softirq_irqoff(unsigned int nr);
63352
63353 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63354 index 6883e19..06992b1 100644
63355 --- a/include/linux/kallsyms.h
63356 +++ b/include/linux/kallsyms.h
63357 @@ -15,7 +15,8 @@
63358
63359 struct module;
63360
63361 -#ifdef CONFIG_KALLSYMS
63362 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63363 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63364 /* Lookup the address for a symbol. Returns 0 if not found. */
63365 unsigned long kallsyms_lookup_name(const char *name);
63366
63367 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63368 /* Stupid that this does nothing, but I didn't create this mess. */
63369 #define __print_symbol(fmt, addr)
63370 #endif /*CONFIG_KALLSYMS*/
63371 +#else /* when included by kallsyms.c, vsnprintf.c, or
63372 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63373 +extern void __print_symbol(const char *fmt, unsigned long address);
63374 +extern int sprint_backtrace(char *buffer, unsigned long address);
63375 +extern int sprint_symbol(char *buffer, unsigned long address);
63376 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63377 +const char *kallsyms_lookup(unsigned long addr,
63378 + unsigned long *symbolsize,
63379 + unsigned long *offset,
63380 + char **modname, char *namebuf);
63381 +#endif
63382
63383 /* This macro allows us to keep printk typechecking */
63384 static __printf(1, 2)
63385 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63386 index c4d2fc1..5df9c19 100644
63387 --- a/include/linux/kgdb.h
63388 +++ b/include/linux/kgdb.h
63389 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63390 extern int kgdb_io_module_registered;
63391
63392 extern atomic_t kgdb_setting_breakpoint;
63393 -extern atomic_t kgdb_cpu_doing_single_step;
63394 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63395
63396 extern struct task_struct *kgdb_usethread;
63397 extern struct task_struct *kgdb_contthread;
63398 @@ -252,7 +252,7 @@ struct kgdb_arch {
63399 void (*disable_hw_break)(struct pt_regs *regs);
63400 void (*remove_all_hw_break)(void);
63401 void (*correct_hw_break)(void);
63402 -};
63403 +} __do_const;
63404
63405 /**
63406 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63407 @@ -277,7 +277,7 @@ struct kgdb_io {
63408 void (*pre_exception) (void);
63409 void (*post_exception) (void);
63410 int is_console;
63411 -};
63412 +} __do_const;
63413
63414 extern struct kgdb_arch arch_kgdb_ops;
63415
63416 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63417 index 5398d58..5883a34 100644
63418 --- a/include/linux/kmod.h
63419 +++ b/include/linux/kmod.h
63420 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63421 * usually useless though. */
63422 extern __printf(2, 3)
63423 int __request_module(bool wait, const char *name, ...);
63424 +extern __printf(3, 4)
63425 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63426 #define request_module(mod...) __request_module(true, mod)
63427 #define request_module_nowait(mod...) __request_module(false, mod)
63428 #define try_then_request_module(x, mod...) \
63429 diff --git a/include/linux/kref.h b/include/linux/kref.h
63430 index 65af688..0592677 100644
63431 --- a/include/linux/kref.h
63432 +++ b/include/linux/kref.h
63433 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63434 static inline int kref_sub(struct kref *kref, unsigned int count,
63435 void (*release)(struct kref *kref))
63436 {
63437 - WARN_ON(release == NULL);
63438 + BUG_ON(release == NULL);
63439
63440 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63441 release(kref);
63442 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63443 index b70b48b..0d7153b 100644
63444 --- a/include/linux/kvm_host.h
63445 +++ b/include/linux/kvm_host.h
63446 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63447 void vcpu_load(struct kvm_vcpu *vcpu);
63448 void vcpu_put(struct kvm_vcpu *vcpu);
63449
63450 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63451 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63452 struct module *module);
63453 void kvm_exit(void);
63454
63455 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63456 struct kvm_guest_debug *dbg);
63457 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63458
63459 -int kvm_arch_init(void *opaque);
63460 +int kvm_arch_init(const void *opaque);
63461 void kvm_arch_exit(void);
63462
63463 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63464 diff --git a/include/linux/libata.h b/include/linux/libata.h
63465 index 64f90e1..32b945b 100644
63466 --- a/include/linux/libata.h
63467 +++ b/include/linux/libata.h
63468 @@ -909,7 +909,7 @@ struct ata_port_operations {
63469 * fields must be pointers.
63470 */
63471 const struct ata_port_operations *inherits;
63472 -};
63473 +} __do_const;
63474
63475 struct ata_port_info {
63476 unsigned long flags;
63477 diff --git a/include/linux/memory.h b/include/linux/memory.h
63478 index ff9a9f8..c715deb 100644
63479 --- a/include/linux/memory.h
63480 +++ b/include/linux/memory.h
63481 @@ -143,7 +143,7 @@ struct memory_accessor {
63482 size_t count);
63483 ssize_t (*write)(struct memory_accessor *, const char *buf,
63484 off_t offset, size_t count);
63485 -};
63486 +} __no_const;
63487
63488 /*
63489 * Kernel text modification mutex, used for code patching. Users of this lock
63490 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63491 index 1318ca6..7521340 100644
63492 --- a/include/linux/mfd/abx500.h
63493 +++ b/include/linux/mfd/abx500.h
63494 @@ -452,6 +452,7 @@ struct abx500_ops {
63495 int (*event_registers_startup_state_get) (struct device *, u8 *);
63496 int (*startup_irq_enabled) (struct device *, unsigned int);
63497 };
63498 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63499
63500 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63501 void abx500_remove_ops(struct device *dev);
63502 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63503 index 9b07725..3d55001 100644
63504 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63505 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63506 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63507 int (*enable) (struct ux500_charger *, int, int, int);
63508 int (*kick_wd) (struct ux500_charger *);
63509 int (*update_curr) (struct ux500_charger *, int);
63510 -};
63511 +} __no_const;
63512
63513 /**
63514 * struct ux500_charger - power supply ux500 charger sub class
63515 diff --git a/include/linux/mm.h b/include/linux/mm.h
63516 index 311be90..5f1638c 100644
63517 --- a/include/linux/mm.h
63518 +++ b/include/linux/mm.h
63519 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63520
63521 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63522 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63523 +
63524 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63525 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63526 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63527 +#else
63528 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63529 +#endif
63530 +
63531 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63532 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63533
63534 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63535 int set_page_dirty_lock(struct page *page);
63536 int clear_page_dirty_for_io(struct page *page);
63537
63538 -/* Is the vma a continuation of the stack vma above it? */
63539 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63540 -{
63541 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63542 -}
63543 -
63544 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63545 - unsigned long addr)
63546 -{
63547 - return (vma->vm_flags & VM_GROWSDOWN) &&
63548 - (vma->vm_start == addr) &&
63549 - !vma_growsdown(vma->vm_prev, addr);
63550 -}
63551 -
63552 -/* Is the vma a continuation of the stack vma below it? */
63553 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63554 -{
63555 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63556 -}
63557 -
63558 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63559 - unsigned long addr)
63560 -{
63561 - return (vma->vm_flags & VM_GROWSUP) &&
63562 - (vma->vm_end == addr) &&
63563 - !vma_growsup(vma->vm_next, addr);
63564 -}
63565 -
63566 extern pid_t
63567 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63568
63569 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63570 }
63571 #endif
63572
63573 +#ifdef CONFIG_MMU
63574 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63575 +#else
63576 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63577 +{
63578 + return __pgprot(0);
63579 +}
63580 +#endif
63581 +
63582 int vma_wants_writenotify(struct vm_area_struct *vma);
63583
63584 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63585 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63586 {
63587 return 0;
63588 }
63589 +
63590 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63591 + unsigned long address)
63592 +{
63593 + return 0;
63594 +}
63595 #else
63596 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63597 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63598 #endif
63599
63600 #ifdef __PAGETABLE_PMD_FOLDED
63601 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63602 {
63603 return 0;
63604 }
63605 +
63606 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63607 + unsigned long address)
63608 +{
63609 + return 0;
63610 +}
63611 #else
63612 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63613 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63614 #endif
63615
63616 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63617 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63618 NULL: pud_offset(pgd, address);
63619 }
63620
63621 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63622 +{
63623 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63624 + NULL: pud_offset(pgd, address);
63625 +}
63626 +
63627 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63628 {
63629 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63630 NULL: pmd_offset(pud, address);
63631 }
63632 +
63633 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63634 +{
63635 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63636 + NULL: pmd_offset(pud, address);
63637 +}
63638 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63639
63640 #if USE_SPLIT_PTLOCKS
63641 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63642 unsigned long, unsigned long,
63643 unsigned long, unsigned long);
63644 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63645 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63646
63647 /* These take the mm semaphore themselves */
63648 extern unsigned long vm_brk(unsigned long, unsigned long);
63649 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63650 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63651 struct vm_area_struct **pprev);
63652
63653 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63654 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63655 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63656 +
63657 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63658 NULL if none. Assume start_addr < end_addr. */
63659 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63660 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63661 return vma;
63662 }
63663
63664 -#ifdef CONFIG_MMU
63665 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63666 -#else
63667 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63668 -{
63669 - return __pgprot(0);
63670 -}
63671 -#endif
63672 -
63673 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63674 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63675 unsigned long pfn, unsigned long size, pgprot_t);
63676 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63677 extern int sysctl_memory_failure_early_kill;
63678 extern int sysctl_memory_failure_recovery;
63679 extern void shake_page(struct page *p, int access);
63680 -extern atomic_long_t mce_bad_pages;
63681 +extern atomic_long_unchecked_t mce_bad_pages;
63682 extern int soft_offline_page(struct page *page, int flags);
63683
63684 extern void dump_page(struct page *page);
63685 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63686 static inline bool page_is_guard(struct page *page) { return false; }
63687 #endif /* CONFIG_DEBUG_PAGEALLOC */
63688
63689 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63690 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63691 +#else
63692 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63693 +#endif
63694 +
63695 #endif /* __KERNEL__ */
63696 #endif /* _LINUX_MM_H */
63697 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63698 index bf78672..debc693 100644
63699 --- a/include/linux/mm_types.h
63700 +++ b/include/linux/mm_types.h
63701 @@ -279,6 +279,8 @@ struct vm_area_struct {
63702 #ifdef CONFIG_NUMA
63703 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63704 #endif
63705 +
63706 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63707 };
63708
63709 struct core_thread {
63710 @@ -353,7 +355,7 @@ struct mm_struct {
63711 unsigned long def_flags;
63712 unsigned long nr_ptes; /* Page table pages */
63713 unsigned long start_code, end_code, start_data, end_data;
63714 - unsigned long start_brk, brk, start_stack;
63715 + unsigned long brk_gap, start_brk, brk, start_stack;
63716 unsigned long arg_start, arg_end, env_start, env_end;
63717
63718 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63719 @@ -405,6 +407,24 @@ struct mm_struct {
63720 struct cpumask cpumask_allocation;
63721 #endif
63722 struct uprobes_state uprobes_state;
63723 +
63724 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63725 + unsigned long pax_flags;
63726 +#endif
63727 +
63728 +#ifdef CONFIG_PAX_DLRESOLVE
63729 + unsigned long call_dl_resolve;
63730 +#endif
63731 +
63732 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63733 + unsigned long call_syscall;
63734 +#endif
63735 +
63736 +#ifdef CONFIG_PAX_ASLR
63737 + unsigned long delta_mmap; /* randomized offset */
63738 + unsigned long delta_stack; /* randomized offset */
63739 +#endif
63740 +
63741 };
63742
63743 static inline void mm_init_cpumask(struct mm_struct *mm)
63744 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63745 index 1d1b1e1..2a13c78 100644
63746 --- a/include/linux/mmu_notifier.h
63747 +++ b/include/linux/mmu_notifier.h
63748 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63749 */
63750 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63751 ({ \
63752 - pte_t __pte; \
63753 + pte_t ___pte; \
63754 struct vm_area_struct *___vma = __vma; \
63755 unsigned long ___address = __address; \
63756 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63757 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63758 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63759 - __pte; \
63760 + ___pte; \
63761 })
63762
63763 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63764 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63765 index 2daa54f..bfdf2f5 100644
63766 --- a/include/linux/mmzone.h
63767 +++ b/include/linux/mmzone.h
63768 @@ -414,7 +414,7 @@ struct zone {
63769 unsigned long flags; /* zone flags, see below */
63770
63771 /* Zone statistics */
63772 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63773 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63774
63775 /*
63776 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63777 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63778 index 6955045..ebdb7cd 100644
63779 --- a/include/linux/mod_devicetable.h
63780 +++ b/include/linux/mod_devicetable.h
63781 @@ -12,7 +12,7 @@
63782 typedef unsigned long kernel_ulong_t;
63783 #endif
63784
63785 -#define PCI_ANY_ID (~0)
63786 +#define PCI_ANY_ID ((__u16)~0)
63787
63788 struct pci_device_id {
63789 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63790 @@ -139,7 +139,7 @@ struct usb_device_id {
63791 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63792 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63793
63794 -#define HID_ANY_ID (~0)
63795 +#define HID_ANY_ID (~0U)
63796 #define HID_BUS_ANY 0xffff
63797 #define HID_GROUP_ANY 0x0000
63798
63799 diff --git a/include/linux/module.h b/include/linux/module.h
63800 index fbcafe2..e5d9587 100644
63801 --- a/include/linux/module.h
63802 +++ b/include/linux/module.h
63803 @@ -17,6 +17,7 @@
63804 #include <linux/moduleparam.h>
63805 #include <linux/tracepoint.h>
63806 #include <linux/export.h>
63807 +#include <linux/fs.h>
63808
63809 #include <linux/percpu.h>
63810 #include <asm/module.h>
63811 @@ -273,19 +274,16 @@ struct module
63812 int (*init)(void);
63813
63814 /* If this is non-NULL, vfree after init() returns */
63815 - void *module_init;
63816 + void *module_init_rx, *module_init_rw;
63817
63818 /* Here is the actual code + data, vfree'd on unload. */
63819 - void *module_core;
63820 + void *module_core_rx, *module_core_rw;
63821
63822 /* Here are the sizes of the init and core sections */
63823 - unsigned int init_size, core_size;
63824 + unsigned int init_size_rw, core_size_rw;
63825
63826 /* The size of the executable code in each section. */
63827 - unsigned int init_text_size, core_text_size;
63828 -
63829 - /* Size of RO sections of the module (text+rodata) */
63830 - unsigned int init_ro_size, core_ro_size;
63831 + unsigned int init_size_rx, core_size_rx;
63832
63833 /* Arch-specific module values */
63834 struct mod_arch_specific arch;
63835 @@ -341,6 +339,10 @@ struct module
63836 #ifdef CONFIG_EVENT_TRACING
63837 struct ftrace_event_call **trace_events;
63838 unsigned int num_trace_events;
63839 + struct file_operations trace_id;
63840 + struct file_operations trace_enable;
63841 + struct file_operations trace_format;
63842 + struct file_operations trace_filter;
63843 #endif
63844 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63845 unsigned int num_ftrace_callsites;
63846 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63847 bool is_module_percpu_address(unsigned long addr);
63848 bool is_module_text_address(unsigned long addr);
63849
63850 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63851 +{
63852 +
63853 +#ifdef CONFIG_PAX_KERNEXEC
63854 + if (ktla_ktva(addr) >= (unsigned long)start &&
63855 + ktla_ktva(addr) < (unsigned long)start + size)
63856 + return 1;
63857 +#endif
63858 +
63859 + return ((void *)addr >= start && (void *)addr < start + size);
63860 +}
63861 +
63862 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63863 +{
63864 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63865 +}
63866 +
63867 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63868 +{
63869 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63870 +}
63871 +
63872 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63873 +{
63874 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63875 +}
63876 +
63877 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63878 +{
63879 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63880 +}
63881 +
63882 static inline int within_module_core(unsigned long addr, struct module *mod)
63883 {
63884 - return (unsigned long)mod->module_core <= addr &&
63885 - addr < (unsigned long)mod->module_core + mod->core_size;
63886 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63887 }
63888
63889 static inline int within_module_init(unsigned long addr, struct module *mod)
63890 {
63891 - return (unsigned long)mod->module_init <= addr &&
63892 - addr < (unsigned long)mod->module_init + mod->init_size;
63893 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63894 }
63895
63896 /* Search for module by name: must hold module_mutex. */
63897 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63898 index b2be02e..72d2f78 100644
63899 --- a/include/linux/moduleloader.h
63900 +++ b/include/linux/moduleloader.h
63901 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63902
63903 /* Allocator used for allocating struct module, core sections and init
63904 sections. Returns NULL on failure. */
63905 -void *module_alloc(unsigned long size);
63906 +void *module_alloc(unsigned long size) __size_overflow(1);
63907 +
63908 +#ifdef CONFIG_PAX_KERNEXEC
63909 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63910 +#else
63911 +#define module_alloc_exec(x) module_alloc(x)
63912 +#endif
63913
63914 /* Free memory returned from module_alloc. */
63915 void module_free(struct module *mod, void *module_region);
63916
63917 +#ifdef CONFIG_PAX_KERNEXEC
63918 +void module_free_exec(struct module *mod, void *module_region);
63919 +#else
63920 +#define module_free_exec(x, y) module_free((x), (y))
63921 +#endif
63922 +
63923 /* Apply the given relocation to the (simplified) ELF. Return -error
63924 or 0. */
63925 int apply_relocate(Elf_Shdr *sechdrs,
63926 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63927 index d6a5806..7c13347 100644
63928 --- a/include/linux/moduleparam.h
63929 +++ b/include/linux/moduleparam.h
63930 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63931 * @len is usually just sizeof(string).
63932 */
63933 #define module_param_string(name, string, len, perm) \
63934 - static const struct kparam_string __param_string_##name \
63935 + static const struct kparam_string __param_string_##name __used \
63936 = { len, string }; \
63937 __module_param_call(MODULE_PARAM_PREFIX, name, \
63938 &param_ops_string, \
63939 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63940 */
63941 #define module_param_array_named(name, array, type, nump, perm) \
63942 param_check_##type(name, &(array)[0]); \
63943 - static const struct kparam_array __param_arr_##name \
63944 + static const struct kparam_array __param_arr_##name __used \
63945 = { .max = ARRAY_SIZE(array), .num = nump, \
63946 .ops = &param_ops_##type, \
63947 .elemsize = sizeof(array[0]), .elem = array }; \
63948 diff --git a/include/linux/namei.h b/include/linux/namei.h
63949 index 4bf19d8..5268cea 100644
63950 --- a/include/linux/namei.h
63951 +++ b/include/linux/namei.h
63952 @@ -18,7 +18,7 @@ struct nameidata {
63953 unsigned seq;
63954 int last_type;
63955 unsigned depth;
63956 - char *saved_names[MAX_NESTED_LINKS + 1];
63957 + const char *saved_names[MAX_NESTED_LINKS + 1];
63958 };
63959
63960 /*
63961 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63962
63963 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63964
63965 -static inline void nd_set_link(struct nameidata *nd, char *path)
63966 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63967 {
63968 nd->saved_names[nd->depth] = path;
63969 }
63970
63971 -static inline char *nd_get_link(struct nameidata *nd)
63972 +static inline const char *nd_get_link(const struct nameidata *nd)
63973 {
63974 return nd->saved_names[nd->depth];
63975 }
63976 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63977 index 59dc05f3..c905a34 100644
63978 --- a/include/linux/netdevice.h
63979 +++ b/include/linux/netdevice.h
63980 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63981 struct net_device *dev,
63982 int idx);
63983 };
63984 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63985
63986 /*
63987 * The DEVICE structure.
63988 @@ -1087,7 +1088,7 @@ struct net_device {
63989 int iflink;
63990
63991 struct net_device_stats stats;
63992 - atomic_long_t rx_dropped; /* dropped packets by core network
63993 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63994 * Do not use this in drivers.
63995 */
63996
63997 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63998 new file mode 100644
63999 index 0000000..33f4af8
64000 --- /dev/null
64001 +++ b/include/linux/netfilter/xt_gradm.h
64002 @@ -0,0 +1,9 @@
64003 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64004 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64005 +
64006 +struct xt_gradm_mtinfo {
64007 + __u16 flags;
64008 + __u16 invflags;
64009 +};
64010 +
64011 +#endif
64012 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64013 index c65a18a..0c05f3a 100644
64014 --- a/include/linux/of_pdt.h
64015 +++ b/include/linux/of_pdt.h
64016 @@ -32,7 +32,7 @@ struct of_pdt_ops {
64017
64018 /* return 0 on success; fill in 'len' with number of bytes in path */
64019 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64020 -};
64021 +} __no_const;
64022
64023 extern void *prom_early_alloc(unsigned long size);
64024
64025 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64026 index a4c5624..79d6d88 100644
64027 --- a/include/linux/oprofile.h
64028 +++ b/include/linux/oprofile.h
64029 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64030 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64031 char const * name, ulong * val);
64032
64033 -/** Create a file for read-only access to an atomic_t. */
64034 +/** Create a file for read-only access to an atomic_unchecked_t. */
64035 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64036 - char const * name, atomic_t * val);
64037 + char const * name, atomic_unchecked_t * val);
64038
64039 /** create a directory */
64040 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64041 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64042 index bdb4161..f373d41 100644
64043 --- a/include/linux/perf_event.h
64044 +++ b/include/linux/perf_event.h
64045 @@ -882,8 +882,8 @@ struct perf_event {
64046
64047 enum perf_event_active_state state;
64048 unsigned int attach_state;
64049 - local64_t count;
64050 - atomic64_t child_count;
64051 + local64_t count; /* PaX: fix it one day */
64052 + atomic64_unchecked_t child_count;
64053
64054 /*
64055 * These are the total time in nanoseconds that the event
64056 @@ -934,8 +934,8 @@ struct perf_event {
64057 * These accumulate total time (in nanoseconds) that children
64058 * events have been enabled and running, respectively.
64059 */
64060 - atomic64_t child_total_time_enabled;
64061 - atomic64_t child_total_time_running;
64062 + atomic64_unchecked_t child_total_time_enabled;
64063 + atomic64_unchecked_t child_total_time_running;
64064
64065 /*
64066 * Protect attach/detach and child_list:
64067 diff --git a/include/linux/personality.h b/include/linux/personality.h
64068 index 8fc7dd1a..c19d89e 100644
64069 --- a/include/linux/personality.h
64070 +++ b/include/linux/personality.h
64071 @@ -44,6 +44,7 @@ enum {
64072 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64073 ADDR_NO_RANDOMIZE | \
64074 ADDR_COMPAT_LAYOUT | \
64075 + ADDR_LIMIT_3GB | \
64076 MMAP_PAGE_ZERO)
64077
64078 /*
64079 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64080 index ad1a427..6419649 100644
64081 --- a/include/linux/pipe_fs_i.h
64082 +++ b/include/linux/pipe_fs_i.h
64083 @@ -45,9 +45,9 @@ struct pipe_buffer {
64084 struct pipe_inode_info {
64085 wait_queue_head_t wait;
64086 unsigned int nrbufs, curbuf, buffers;
64087 - unsigned int readers;
64088 - unsigned int writers;
64089 - unsigned int waiting_writers;
64090 + atomic_t readers;
64091 + atomic_t writers;
64092 + atomic_t waiting_writers;
64093 unsigned int r_counter;
64094 unsigned int w_counter;
64095 struct page *tmp_page;
64096 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64097 index f271860..6b3bec5 100644
64098 --- a/include/linux/pm_runtime.h
64099 +++ b/include/linux/pm_runtime.h
64100 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64101
64102 static inline void pm_runtime_mark_last_busy(struct device *dev)
64103 {
64104 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64105 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64106 }
64107
64108 #else /* !CONFIG_PM_RUNTIME */
64109 diff --git a/include/linux/poison.h b/include/linux/poison.h
64110 index 2110a81..13a11bb 100644
64111 --- a/include/linux/poison.h
64112 +++ b/include/linux/poison.h
64113 @@ -19,8 +19,8 @@
64114 * under normal circumstances, used to verify that nobody uses
64115 * non-initialized list entries.
64116 */
64117 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64118 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64119 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64120 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64121
64122 /********** include/linux/timer.h **********/
64123 /*
64124 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64125 index 5a710b9..0b0dab9 100644
64126 --- a/include/linux/preempt.h
64127 +++ b/include/linux/preempt.h
64128 @@ -126,7 +126,7 @@ struct preempt_ops {
64129 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64130 void (*sched_out)(struct preempt_notifier *notifier,
64131 struct task_struct *next);
64132 -};
64133 +} __no_const;
64134
64135 /**
64136 * preempt_notifier - key for installing preemption notifiers
64137 diff --git a/include/linux/printk.h b/include/linux/printk.h
64138 index 9afc01e..92c32e8 100644
64139 --- a/include/linux/printk.h
64140 +++ b/include/linux/printk.h
64141 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64142 extern int printk_needs_cpu(int cpu);
64143 extern void printk_tick(void);
64144
64145 +extern int kptr_restrict;
64146 +
64147 #ifdef CONFIG_PRINTK
64148 asmlinkage __printf(5, 0)
64149 int vprintk_emit(int facility, int level,
64150 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64151
64152 extern int printk_delay_msec;
64153 extern int dmesg_restrict;
64154 -extern int kptr_restrict;
64155
64156 void log_buf_kexec_setup(void);
64157 void __init setup_log_buf(int early);
64158 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64159 index 3fd2e87..d93a721 100644
64160 --- a/include/linux/proc_fs.h
64161 +++ b/include/linux/proc_fs.h
64162 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64163 return proc_create_data(name, mode, parent, proc_fops, NULL);
64164 }
64165
64166 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64167 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64168 +{
64169 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64170 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64171 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64172 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64173 +#else
64174 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64175 +#endif
64176 +}
64177 +
64178 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64179 umode_t mode, struct proc_dir_entry *base,
64180 read_proc_t *read_proc, void * data)
64181 @@ -258,7 +270,7 @@ union proc_op {
64182 int (*proc_show)(struct seq_file *m,
64183 struct pid_namespace *ns, struct pid *pid,
64184 struct task_struct *task);
64185 -};
64186 +} __no_const;
64187
64188 struct ctl_table_header;
64189 struct ctl_table;
64190 diff --git a/include/linux/random.h b/include/linux/random.h
64191 index ac621ce..c1215f3 100644
64192 --- a/include/linux/random.h
64193 +++ b/include/linux/random.h
64194 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64195 unsigned int value);
64196 extern void add_interrupt_randomness(int irq, int irq_flags);
64197
64198 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64199 +extern void transfer_latent_entropy(void);
64200 +#endif
64201 +
64202 extern void get_random_bytes(void *buf, int nbytes);
64203 extern void get_random_bytes_arch(void *buf, int nbytes);
64204 void generate_random_uuid(unsigned char uuid_out[16]);
64205 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64206
64207 u32 prandom32(struct rnd_state *);
64208
64209 +static inline unsigned long pax_get_random_long(void)
64210 +{
64211 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64212 +}
64213 +
64214 /*
64215 * Handle minimum values for seeds
64216 */
64217 static inline u32 __seed(u32 x, u32 m)
64218 {
64219 - return (x < m) ? x + m : x;
64220 + return (x <= m) ? x + m + 1 : x;
64221 }
64222
64223 /**
64224 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64225 index e0879a7..a12f962 100644
64226 --- a/include/linux/reboot.h
64227 +++ b/include/linux/reboot.h
64228 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64229 * Architecture-specific implementations of sys_reboot commands.
64230 */
64231
64232 -extern void machine_restart(char *cmd);
64233 -extern void machine_halt(void);
64234 -extern void machine_power_off(void);
64235 +extern void machine_restart(char *cmd) __noreturn;
64236 +extern void machine_halt(void) __noreturn;
64237 +extern void machine_power_off(void) __noreturn;
64238
64239 extern void machine_shutdown(void);
64240 struct pt_regs;
64241 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64242 */
64243
64244 extern void kernel_restart_prepare(char *cmd);
64245 -extern void kernel_restart(char *cmd);
64246 -extern void kernel_halt(void);
64247 -extern void kernel_power_off(void);
64248 +extern void kernel_restart(char *cmd) __noreturn;
64249 +extern void kernel_halt(void) __noreturn;
64250 +extern void kernel_power_off(void) __noreturn;
64251
64252 extern int C_A_D; /* for sysctl */
64253 void ctrl_alt_del(void);
64254 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64255 * Emergency restart, callable from an interrupt handler.
64256 */
64257
64258 -extern void emergency_restart(void);
64259 +extern void emergency_restart(void) __noreturn;
64260 #include <asm/emergency-restart.h>
64261
64262 #endif
64263 diff --git a/include/linux/relay.h b/include/linux/relay.h
64264 index 91cacc3..b55ff74 100644
64265 --- a/include/linux/relay.h
64266 +++ b/include/linux/relay.h
64267 @@ -160,7 +160,7 @@ struct rchan_callbacks
64268 * The callback should return 0 if successful, negative if not.
64269 */
64270 int (*remove_buf_file)(struct dentry *dentry);
64271 -};
64272 +} __no_const;
64273
64274 /*
64275 * CONFIG_RELAY kernel API, kernel/relay.c
64276 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64277 index 6fdf027..ff72610 100644
64278 --- a/include/linux/rfkill.h
64279 +++ b/include/linux/rfkill.h
64280 @@ -147,6 +147,7 @@ struct rfkill_ops {
64281 void (*query)(struct rfkill *rfkill, void *data);
64282 int (*set_block)(void *data, bool blocked);
64283 };
64284 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64285
64286 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64287 /**
64288 diff --git a/include/linux/rio.h b/include/linux/rio.h
64289 index a90ebad..fd87b5d 100644
64290 --- a/include/linux/rio.h
64291 +++ b/include/linux/rio.h
64292 @@ -321,7 +321,7 @@ struct rio_ops {
64293 int mbox, void *buffer, size_t len);
64294 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64295 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64296 -};
64297 +} __no_const;
64298
64299 #define RIO_RESOURCE_MEM 0x00000100
64300 #define RIO_RESOURCE_DOORBELL 0x00000200
64301 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64302 index 3fce545..b4fed6e 100644
64303 --- a/include/linux/rmap.h
64304 +++ b/include/linux/rmap.h
64305 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64306 void anon_vma_init(void); /* create anon_vma_cachep */
64307 int anon_vma_prepare(struct vm_area_struct *);
64308 void unlink_anon_vmas(struct vm_area_struct *);
64309 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64310 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64311 void anon_vma_moveto_tail(struct vm_area_struct *);
64312 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64313 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64314
64315 static inline void anon_vma_merge(struct vm_area_struct *vma,
64316 struct vm_area_struct *next)
64317 diff --git a/include/linux/sched.h b/include/linux/sched.h
64318 index 23bddac..5976055 100644
64319 --- a/include/linux/sched.h
64320 +++ b/include/linux/sched.h
64321 @@ -101,6 +101,7 @@ struct bio_list;
64322 struct fs_struct;
64323 struct perf_event_context;
64324 struct blk_plug;
64325 +struct linux_binprm;
64326
64327 /*
64328 * List of flags we want to share for kernel threads,
64329 @@ -384,10 +385,13 @@ struct user_namespace;
64330 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64331
64332 extern int sysctl_max_map_count;
64333 +extern unsigned long sysctl_heap_stack_gap;
64334
64335 #include <linux/aio.h>
64336
64337 #ifdef CONFIG_MMU
64338 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64339 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64340 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64341 extern unsigned long
64342 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64343 @@ -651,6 +655,17 @@ struct signal_struct {
64344 #ifdef CONFIG_TASKSTATS
64345 struct taskstats *stats;
64346 #endif
64347 +
64348 +#ifdef CONFIG_GRKERNSEC
64349 + u32 curr_ip;
64350 + u32 saved_ip;
64351 + u32 gr_saddr;
64352 + u32 gr_daddr;
64353 + u16 gr_sport;
64354 + u16 gr_dport;
64355 + u8 used_accept:1;
64356 +#endif
64357 +
64358 #ifdef CONFIG_AUDIT
64359 unsigned audit_tty;
64360 struct tty_audit_buf *tty_audit_buf;
64361 @@ -734,6 +749,11 @@ struct user_struct {
64362 struct key *session_keyring; /* UID's default session keyring */
64363 #endif
64364
64365 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64366 + unsigned int banned;
64367 + unsigned long ban_expires;
64368 +#endif
64369 +
64370 /* Hash table maintenance information */
64371 struct hlist_node uidhash_node;
64372 kuid_t uid;
64373 @@ -1356,8 +1376,8 @@ struct task_struct {
64374 struct list_head thread_group;
64375
64376 struct completion *vfork_done; /* for vfork() */
64377 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64378 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64379 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64380 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64381
64382 cputime_t utime, stime, utimescaled, stimescaled;
64383 cputime_t gtime;
64384 @@ -1373,11 +1393,6 @@ struct task_struct {
64385 struct task_cputime cputime_expires;
64386 struct list_head cpu_timers[3];
64387
64388 -/* process credentials */
64389 - const struct cred __rcu *real_cred; /* objective and real subjective task
64390 - * credentials (COW) */
64391 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64392 - * credentials (COW) */
64393 char comm[TASK_COMM_LEN]; /* executable name excluding path
64394 - access with [gs]et_task_comm (which lock
64395 it with task_lock())
64396 @@ -1394,6 +1409,10 @@ struct task_struct {
64397 #endif
64398 /* CPU-specific state of this task */
64399 struct thread_struct thread;
64400 +/* thread_info moved to task_struct */
64401 +#ifdef CONFIG_X86
64402 + struct thread_info tinfo;
64403 +#endif
64404 /* filesystem information */
64405 struct fs_struct *fs;
64406 /* open file information */
64407 @@ -1467,6 +1486,10 @@ struct task_struct {
64408 gfp_t lockdep_reclaim_gfp;
64409 #endif
64410
64411 +/* process credentials */
64412 + const struct cred __rcu *real_cred; /* objective and real subjective task
64413 + * credentials (COW) */
64414 +
64415 /* journalling filesystem info */
64416 void *journal_info;
64417
64418 @@ -1505,6 +1528,10 @@ struct task_struct {
64419 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64420 struct list_head cg_list;
64421 #endif
64422 +
64423 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64424 + * credentials (COW) */
64425 +
64426 #ifdef CONFIG_FUTEX
64427 struct robust_list_head __user *robust_list;
64428 #ifdef CONFIG_COMPAT
64429 @@ -1589,8 +1616,74 @@ struct task_struct {
64430 #ifdef CONFIG_UPROBES
64431 struct uprobe_task *utask;
64432 #endif
64433 +
64434 +#ifdef CONFIG_GRKERNSEC
64435 + /* grsecurity */
64436 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64437 + u64 exec_id;
64438 +#endif
64439 +#ifdef CONFIG_GRKERNSEC_SETXID
64440 + const struct cred *delayed_cred;
64441 +#endif
64442 + struct dentry *gr_chroot_dentry;
64443 + struct acl_subject_label *acl;
64444 + struct acl_role_label *role;
64445 + struct file *exec_file;
64446 + u16 acl_role_id;
64447 + /* is this the task that authenticated to the special role */
64448 + u8 acl_sp_role;
64449 + u8 is_writable;
64450 + u8 brute;
64451 + u8 gr_is_chrooted;
64452 +#endif
64453 +
64454 };
64455
64456 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64457 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64458 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64459 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64460 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64461 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64462 +
64463 +#ifdef CONFIG_PAX_SOFTMODE
64464 +extern int pax_softmode;
64465 +#endif
64466 +
64467 +extern int pax_check_flags(unsigned long *);
64468 +
64469 +/* if tsk != current then task_lock must be held on it */
64470 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64471 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64472 +{
64473 + if (likely(tsk->mm))
64474 + return tsk->mm->pax_flags;
64475 + else
64476 + return 0UL;
64477 +}
64478 +
64479 +/* if tsk != current then task_lock must be held on it */
64480 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64481 +{
64482 + if (likely(tsk->mm)) {
64483 + tsk->mm->pax_flags = flags;
64484 + return 0;
64485 + }
64486 + return -EINVAL;
64487 +}
64488 +#endif
64489 +
64490 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64491 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64492 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64493 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64494 +#endif
64495 +
64496 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64497 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64498 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64499 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64500 +
64501 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64502 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64503
64504 @@ -2125,7 +2218,9 @@ void yield(void);
64505 extern struct exec_domain default_exec_domain;
64506
64507 union thread_union {
64508 +#ifndef CONFIG_X86
64509 struct thread_info thread_info;
64510 +#endif
64511 unsigned long stack[THREAD_SIZE/sizeof(long)];
64512 };
64513
64514 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64515 */
64516
64517 extern struct task_struct *find_task_by_vpid(pid_t nr);
64518 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64519 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64520 struct pid_namespace *ns);
64521
64522 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64523 extern void exit_itimers(struct signal_struct *);
64524 extern void flush_itimer_signals(void);
64525
64526 -extern void do_group_exit(int);
64527 +extern __noreturn void do_group_exit(int);
64528
64529 extern void daemonize(const char *, ...);
64530 extern int allow_signal(int);
64531 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64532
64533 #endif
64534
64535 -static inline int object_is_on_stack(void *obj)
64536 +static inline int object_starts_on_stack(void *obj)
64537 {
64538 - void *stack = task_stack_page(current);
64539 + const void *stack = task_stack_page(current);
64540
64541 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64542 }
64543 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64544 index 899fbb4..1cb4138 100644
64545 --- a/include/linux/screen_info.h
64546 +++ b/include/linux/screen_info.h
64547 @@ -43,7 +43,8 @@ struct screen_info {
64548 __u16 pages; /* 0x32 */
64549 __u16 vesa_attributes; /* 0x34 */
64550 __u32 capabilities; /* 0x36 */
64551 - __u8 _reserved[6]; /* 0x3a */
64552 + __u16 vesapm_size; /* 0x3a */
64553 + __u8 _reserved[4]; /* 0x3c */
64554 } __attribute__((packed));
64555
64556 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64557 diff --git a/include/linux/security.h b/include/linux/security.h
64558 index d143b8e..9f27b95 100644
64559 --- a/include/linux/security.h
64560 +++ b/include/linux/security.h
64561 @@ -26,6 +26,7 @@
64562 #include <linux/capability.h>
64563 #include <linux/slab.h>
64564 #include <linux/err.h>
64565 +#include <linux/grsecurity.h>
64566
64567 struct linux_binprm;
64568 struct cred;
64569 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64570 index 83c44ee..e8a9eba 100644
64571 --- a/include/linux/seq_file.h
64572 +++ b/include/linux/seq_file.h
64573 @@ -25,6 +25,9 @@ struct seq_file {
64574 struct mutex lock;
64575 const struct seq_operations *op;
64576 int poll_event;
64577 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64578 + u64 exec_id;
64579 +#endif
64580 void *private;
64581 };
64582
64583 @@ -34,6 +37,7 @@ struct seq_operations {
64584 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64585 int (*show) (struct seq_file *m, void *v);
64586 };
64587 +typedef struct seq_operations __no_const seq_operations_no_const;
64588
64589 #define SEQ_SKIP 1
64590
64591 diff --git a/include/linux/shm.h b/include/linux/shm.h
64592 index edd0868..f98feee 100644
64593 --- a/include/linux/shm.h
64594 +++ b/include/linux/shm.h
64595 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64596
64597 /* The task created the shm object. NULL if the task is dead. */
64598 struct task_struct *shm_creator;
64599 +#ifdef CONFIG_GRKERNSEC
64600 + time_t shm_createtime;
64601 + pid_t shm_lapid;
64602 +#endif
64603 };
64604
64605 /* shm_mode upper byte flags */
64606 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64607 index f3165d2..2cb3cb7 100644
64608 --- a/include/linux/skbuff.h
64609 +++ b/include/linux/skbuff.h
64610 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64611 extern struct sk_buff *__alloc_skb(unsigned int size,
64612 gfp_t priority, int flags, int node);
64613 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64614 -static inline struct sk_buff *alloc_skb(unsigned int size,
64615 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64616 gfp_t priority)
64617 {
64618 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64619 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64620 */
64621 static inline int skb_queue_empty(const struct sk_buff_head *list)
64622 {
64623 - return list->next == (struct sk_buff *)list;
64624 + return list->next == (const struct sk_buff *)list;
64625 }
64626
64627 /**
64628 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64629 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64630 const struct sk_buff *skb)
64631 {
64632 - return skb->next == (struct sk_buff *)list;
64633 + return skb->next == (const struct sk_buff *)list;
64634 }
64635
64636 /**
64637 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64638 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64639 const struct sk_buff *skb)
64640 {
64641 - return skb->prev == (struct sk_buff *)list;
64642 + return skb->prev == (const struct sk_buff *)list;
64643 }
64644
64645 /**
64646 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64647 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64648 */
64649 #ifndef NET_SKB_PAD
64650 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64651 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64652 #endif
64653
64654 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64655 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64656 int noblock, int *err);
64657 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64658 struct poll_table_struct *wait);
64659 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64660 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64661 int offset, struct iovec *to,
64662 int size);
64663 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64664 diff --git a/include/linux/slab.h b/include/linux/slab.h
64665 index 0dd2dfa..2b8677c 100644
64666 --- a/include/linux/slab.h
64667 +++ b/include/linux/slab.h
64668 @@ -11,12 +11,20 @@
64669
64670 #include <linux/gfp.h>
64671 #include <linux/types.h>
64672 +#include <linux/err.h>
64673
64674 /*
64675 * Flags to pass to kmem_cache_create().
64676 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64677 */
64678 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64679 +
64680 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64681 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64682 +#else
64683 +#define SLAB_USERCOPY 0x00000000UL
64684 +#endif
64685 +
64686 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64687 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64688 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64689 @@ -87,10 +95,13 @@
64690 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64691 * Both make kfree a no-op.
64692 */
64693 -#define ZERO_SIZE_PTR ((void *)16)
64694 +#define ZERO_SIZE_PTR \
64695 +({ \
64696 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64697 + (void *)(-MAX_ERRNO-1L); \
64698 +})
64699
64700 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64701 - (unsigned long)ZERO_SIZE_PTR)
64702 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64703
64704 /*
64705 * Common fields provided in kmem_cache by all slab allocators
64706 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64707 void kfree(const void *);
64708 void kzfree(const void *);
64709 size_t ksize(const void *);
64710 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64711 +bool is_usercopy_object(const void *ptr);
64712
64713 /*
64714 * Allocator specific definitions. These are mainly used to establish optimized
64715 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64716 */
64717 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64718 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64719 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64720 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64721 #define kmalloc_track_caller(size, flags) \
64722 __kmalloc_track_caller(size, flags, _RET_IP_)
64723 #else
64724 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64725 */
64726 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64727 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64728 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64729 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64730 #define kmalloc_node_track_caller(size, flags, node) \
64731 __kmalloc_node_track_caller(size, flags, node, \
64732 _RET_IP_)
64733 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64734 index 0c634fa..8616300 100644
64735 --- a/include/linux/slab_def.h
64736 +++ b/include/linux/slab_def.h
64737 @@ -69,10 +69,10 @@ struct kmem_cache {
64738 unsigned long node_allocs;
64739 unsigned long node_frees;
64740 unsigned long node_overflow;
64741 - atomic_t allochit;
64742 - atomic_t allocmiss;
64743 - atomic_t freehit;
64744 - atomic_t freemiss;
64745 + atomic_unchecked_t allochit;
64746 + atomic_unchecked_t allocmiss;
64747 + atomic_unchecked_t freehit;
64748 + atomic_unchecked_t freemiss;
64749
64750 /*
64751 * If debugging is enabled, then the allocator can add additional
64752 @@ -105,11 +105,16 @@ struct cache_sizes {
64753 #ifdef CONFIG_ZONE_DMA
64754 struct kmem_cache *cs_dmacachep;
64755 #endif
64756 +
64757 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64758 + struct kmem_cache *cs_usercopycachep;
64759 +#endif
64760 +
64761 };
64762 extern struct cache_sizes malloc_sizes[];
64763
64764 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64765 -void *__kmalloc(size_t size, gfp_t flags);
64766 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64767
64768 #ifdef CONFIG_TRACING
64769 extern void *kmem_cache_alloc_trace(size_t size,
64770 @@ -152,6 +157,13 @@ found:
64771 cachep = malloc_sizes[i].cs_dmacachep;
64772 else
64773 #endif
64774 +
64775 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64776 + if (flags & GFP_USERCOPY)
64777 + cachep = malloc_sizes[i].cs_usercopycachep;
64778 + else
64779 +#endif
64780 +
64781 cachep = malloc_sizes[i].cs_cachep;
64782
64783 ret = kmem_cache_alloc_trace(size, cachep, flags);
64784 @@ -162,7 +174,7 @@ found:
64785 }
64786
64787 #ifdef CONFIG_NUMA
64788 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64789 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64790 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64791
64792 #ifdef CONFIG_TRACING
64793 @@ -205,6 +217,13 @@ found:
64794 cachep = malloc_sizes[i].cs_dmacachep;
64795 else
64796 #endif
64797 +
64798 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64799 + if (flags & GFP_USERCOPY)
64800 + cachep = malloc_sizes[i].cs_usercopycachep;
64801 + else
64802 +#endif
64803 +
64804 cachep = malloc_sizes[i].cs_cachep;
64805
64806 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64807 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64808 index 0ec00b3..22b4715 100644
64809 --- a/include/linux/slob_def.h
64810 +++ b/include/linux/slob_def.h
64811 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64812 return kmem_cache_alloc_node(cachep, flags, -1);
64813 }
64814
64815 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64816 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64817
64818 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64819 {
64820 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64821 return __kmalloc_node(size, flags, -1);
64822 }
64823
64824 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64825 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64826 {
64827 return kmalloc(size, flags);
64828 }
64829 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64830 index df448ad..b99e7f6 100644
64831 --- a/include/linux/slub_def.h
64832 +++ b/include/linux/slub_def.h
64833 @@ -91,7 +91,7 @@ struct kmem_cache {
64834 struct kmem_cache_order_objects max;
64835 struct kmem_cache_order_objects min;
64836 gfp_t allocflags; /* gfp flags to use on each alloc */
64837 - int refcount; /* Refcount for slab cache destroy */
64838 + atomic_t refcount; /* Refcount for slab cache destroy */
64839 void (*ctor)(void *);
64840 int inuse; /* Offset to metadata */
64841 int align; /* Alignment */
64842 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64843 * Sorry that the following has to be that ugly but some versions of GCC
64844 * have trouble with constant propagation and loops.
64845 */
64846 -static __always_inline int kmalloc_index(size_t size)
64847 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64848 {
64849 if (!size)
64850 return 0;
64851 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64852 }
64853
64854 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64855 -void *__kmalloc(size_t size, gfp_t flags);
64856 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64857
64858 static __always_inline void *
64859 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64860 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64861 }
64862 #endif
64863
64864 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64865 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64866 {
64867 unsigned int order = get_order(size);
64868 return kmalloc_order_trace(size, flags, order);
64869 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64870 }
64871
64872 #ifdef CONFIG_NUMA
64873 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64874 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64875 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64876
64877 #ifdef CONFIG_TRACING
64878 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64879 index de8832d..0147b46 100644
64880 --- a/include/linux/sonet.h
64881 +++ b/include/linux/sonet.h
64882 @@ -61,7 +61,7 @@ struct sonet_stats {
64883 #include <linux/atomic.h>
64884
64885 struct k_sonet_stats {
64886 -#define __HANDLE_ITEM(i) atomic_t i
64887 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64888 __SONET_ITEMS
64889 #undef __HANDLE_ITEM
64890 };
64891 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64892 index 523547e..2cb7140 100644
64893 --- a/include/linux/sunrpc/clnt.h
64894 +++ b/include/linux/sunrpc/clnt.h
64895 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64896 {
64897 switch (sap->sa_family) {
64898 case AF_INET:
64899 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64900 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64901 case AF_INET6:
64902 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64903 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64904 }
64905 return 0;
64906 }
64907 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64908 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64909 const struct sockaddr *src)
64910 {
64911 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64912 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64913 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64914
64915 dsin->sin_family = ssin->sin_family;
64916 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64917 if (sa->sa_family != AF_INET6)
64918 return 0;
64919
64920 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64921 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64922 }
64923
64924 #endif /* __KERNEL__ */
64925 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64926 index dc0c3cc..8503fb6 100644
64927 --- a/include/linux/sunrpc/sched.h
64928 +++ b/include/linux/sunrpc/sched.h
64929 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64930 void (*rpc_count_stats)(struct rpc_task *, void *);
64931 void (*rpc_release)(void *);
64932 };
64933 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64934
64935 struct rpc_task_setup {
64936 struct rpc_task *task;
64937 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64938 index 0b8e3e6..33e0a01 100644
64939 --- a/include/linux/sunrpc/svc_rdma.h
64940 +++ b/include/linux/sunrpc/svc_rdma.h
64941 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64942 extern unsigned int svcrdma_max_requests;
64943 extern unsigned int svcrdma_max_req_size;
64944
64945 -extern atomic_t rdma_stat_recv;
64946 -extern atomic_t rdma_stat_read;
64947 -extern atomic_t rdma_stat_write;
64948 -extern atomic_t rdma_stat_sq_starve;
64949 -extern atomic_t rdma_stat_rq_starve;
64950 -extern atomic_t rdma_stat_rq_poll;
64951 -extern atomic_t rdma_stat_rq_prod;
64952 -extern atomic_t rdma_stat_sq_poll;
64953 -extern atomic_t rdma_stat_sq_prod;
64954 +extern atomic_unchecked_t rdma_stat_recv;
64955 +extern atomic_unchecked_t rdma_stat_read;
64956 +extern atomic_unchecked_t rdma_stat_write;
64957 +extern atomic_unchecked_t rdma_stat_sq_starve;
64958 +extern atomic_unchecked_t rdma_stat_rq_starve;
64959 +extern atomic_unchecked_t rdma_stat_rq_poll;
64960 +extern atomic_unchecked_t rdma_stat_rq_prod;
64961 +extern atomic_unchecked_t rdma_stat_sq_poll;
64962 +extern atomic_unchecked_t rdma_stat_sq_prod;
64963
64964 #define RPCRDMA_VERSION 1
64965
64966 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64967 index c34b4c8..a65b67d 100644
64968 --- a/include/linux/sysctl.h
64969 +++ b/include/linux/sysctl.h
64970 @@ -155,7 +155,11 @@ enum
64971 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64972 };
64973
64974 -
64975 +#ifdef CONFIG_PAX_SOFTMODE
64976 +enum {
64977 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64978 +};
64979 +#endif
64980
64981 /* CTL_VM names: */
64982 enum
64983 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64984
64985 extern int proc_dostring(struct ctl_table *, int,
64986 void __user *, size_t *, loff_t *);
64987 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64988 + void __user *, size_t *, loff_t *);
64989 extern int proc_dointvec(struct ctl_table *, int,
64990 void __user *, size_t *, loff_t *);
64991 extern int proc_dointvec_minmax(struct ctl_table *, int,
64992 diff --git a/include/linux/tty.h b/include/linux/tty.h
64993 index 9f47ab5..73da944 100644
64994 --- a/include/linux/tty.h
64995 +++ b/include/linux/tty.h
64996 @@ -225,7 +225,7 @@ struct tty_port {
64997 const struct tty_port_operations *ops; /* Port operations */
64998 spinlock_t lock; /* Lock protecting tty field */
64999 int blocked_open; /* Waiting to open */
65000 - int count; /* Usage count */
65001 + atomic_t count; /* Usage count */
65002 wait_queue_head_t open_wait; /* Open waiters */
65003 wait_queue_head_t close_wait; /* Close waiters */
65004 wait_queue_head_t delta_msr_wait; /* Modem status change */
65005 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65006 struct tty_struct *tty, struct file *filp);
65007 static inline int tty_port_users(struct tty_port *port)
65008 {
65009 - return port->count + port->blocked_open;
65010 + return atomic_read(&port->count) + port->blocked_open;
65011 }
65012
65013 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65014 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65015 index fb79dd8d..07d4773 100644
65016 --- a/include/linux/tty_ldisc.h
65017 +++ b/include/linux/tty_ldisc.h
65018 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65019
65020 struct module *owner;
65021
65022 - int refcount;
65023 + atomic_t refcount;
65024 };
65025
65026 struct tty_ldisc {
65027 diff --git a/include/linux/types.h b/include/linux/types.h
65028 index bf0dd75..a1f23aaa 100644
65029 --- a/include/linux/types.h
65030 +++ b/include/linux/types.h
65031 @@ -220,10 +220,26 @@ typedef struct {
65032 int counter;
65033 } atomic_t;
65034
65035 +#ifdef CONFIG_PAX_REFCOUNT
65036 +typedef struct {
65037 + int counter;
65038 +} atomic_unchecked_t;
65039 +#else
65040 +typedef atomic_t atomic_unchecked_t;
65041 +#endif
65042 +
65043 #ifdef CONFIG_64BIT
65044 typedef struct {
65045 long counter;
65046 } atomic64_t;
65047 +
65048 +#ifdef CONFIG_PAX_REFCOUNT
65049 +typedef struct {
65050 + long counter;
65051 +} atomic64_unchecked_t;
65052 +#else
65053 +typedef atomic64_t atomic64_unchecked_t;
65054 +#endif
65055 #endif
65056
65057 struct list_head {
65058 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65059 index 5ca0951..ab496a5 100644
65060 --- a/include/linux/uaccess.h
65061 +++ b/include/linux/uaccess.h
65062 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65063 long ret; \
65064 mm_segment_t old_fs = get_fs(); \
65065 \
65066 - set_fs(KERNEL_DS); \
65067 pagefault_disable(); \
65068 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65069 - pagefault_enable(); \
65070 + set_fs(KERNEL_DS); \
65071 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65072 set_fs(old_fs); \
65073 + pagefault_enable(); \
65074 ret; \
65075 })
65076
65077 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65078 index 99c1b4d..bb94261 100644
65079 --- a/include/linux/unaligned/access_ok.h
65080 +++ b/include/linux/unaligned/access_ok.h
65081 @@ -6,32 +6,32 @@
65082
65083 static inline u16 get_unaligned_le16(const void *p)
65084 {
65085 - return le16_to_cpup((__le16 *)p);
65086 + return le16_to_cpup((const __le16 *)p);
65087 }
65088
65089 static inline u32 get_unaligned_le32(const void *p)
65090 {
65091 - return le32_to_cpup((__le32 *)p);
65092 + return le32_to_cpup((const __le32 *)p);
65093 }
65094
65095 static inline u64 get_unaligned_le64(const void *p)
65096 {
65097 - return le64_to_cpup((__le64 *)p);
65098 + return le64_to_cpup((const __le64 *)p);
65099 }
65100
65101 static inline u16 get_unaligned_be16(const void *p)
65102 {
65103 - return be16_to_cpup((__be16 *)p);
65104 + return be16_to_cpup((const __be16 *)p);
65105 }
65106
65107 static inline u32 get_unaligned_be32(const void *p)
65108 {
65109 - return be32_to_cpup((__be32 *)p);
65110 + return be32_to_cpup((const __be32 *)p);
65111 }
65112
65113 static inline u64 get_unaligned_be64(const void *p)
65114 {
65115 - return be64_to_cpup((__be64 *)p);
65116 + return be64_to_cpup((const __be64 *)p);
65117 }
65118
65119 static inline void put_unaligned_le16(u16 val, void *p)
65120 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65121 index c5d36c6..8478c90 100644
65122 --- a/include/linux/usb/renesas_usbhs.h
65123 +++ b/include/linux/usb/renesas_usbhs.h
65124 @@ -39,7 +39,7 @@ enum {
65125 */
65126 struct renesas_usbhs_driver_callback {
65127 int (*notify_hotplug)(struct platform_device *pdev);
65128 -};
65129 +} __no_const;
65130
65131 /*
65132 * callback functions for platform
65133 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65134 * VBUS control is needed for Host
65135 */
65136 int (*set_vbus)(struct platform_device *pdev, int enable);
65137 -};
65138 +} __no_const;
65139
65140 /*
65141 * parameters for renesas usbhs
65142 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65143 index 6f8fbcf..8259001 100644
65144 --- a/include/linux/vermagic.h
65145 +++ b/include/linux/vermagic.h
65146 @@ -25,9 +25,35 @@
65147 #define MODULE_ARCH_VERMAGIC ""
65148 #endif
65149
65150 +#ifdef CONFIG_PAX_REFCOUNT
65151 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65152 +#else
65153 +#define MODULE_PAX_REFCOUNT ""
65154 +#endif
65155 +
65156 +#ifdef CONSTIFY_PLUGIN
65157 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65158 +#else
65159 +#define MODULE_CONSTIFY_PLUGIN ""
65160 +#endif
65161 +
65162 +#ifdef STACKLEAK_PLUGIN
65163 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65164 +#else
65165 +#define MODULE_STACKLEAK_PLUGIN ""
65166 +#endif
65167 +
65168 +#ifdef CONFIG_GRKERNSEC
65169 +#define MODULE_GRSEC "GRSEC "
65170 +#else
65171 +#define MODULE_GRSEC ""
65172 +#endif
65173 +
65174 #define VERMAGIC_STRING \
65175 UTS_RELEASE " " \
65176 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65177 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65178 - MODULE_ARCH_VERMAGIC
65179 + MODULE_ARCH_VERMAGIC \
65180 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65181 + MODULE_GRSEC
65182
65183 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65184 index 6071e91..ca6a489 100644
65185 --- a/include/linux/vmalloc.h
65186 +++ b/include/linux/vmalloc.h
65187 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65188 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65189 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65190 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65191 +
65192 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65193 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65194 +#endif
65195 +
65196 /* bits [20..32] reserved for arch specific ioremap internals */
65197
65198 /*
65199 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65200 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65201 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65202 unsigned long start, unsigned long end, gfp_t gfp_mask,
65203 - pgprot_t prot, int node, const void *caller);
65204 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65205 extern void vfree(const void *addr);
65206
65207 extern void *vmap(struct page **pages, unsigned int count,
65208 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65209 extern void free_vm_area(struct vm_struct *area);
65210
65211 /* for /dev/kmem */
65212 -extern long vread(char *buf, char *addr, unsigned long count);
65213 -extern long vwrite(char *buf, char *addr, unsigned long count);
65214 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65215 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65216
65217 /*
65218 * Internals. Dont't use..
65219 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65220 index ad2cfd5..74c94ad 100644
65221 --- a/include/linux/vmstat.h
65222 +++ b/include/linux/vmstat.h
65223 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65224 /*
65225 * Zone based page accounting with per cpu differentials.
65226 */
65227 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65228 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65229
65230 static inline void zone_page_state_add(long x, struct zone *zone,
65231 enum zone_stat_item item)
65232 {
65233 - atomic_long_add(x, &zone->vm_stat[item]);
65234 - atomic_long_add(x, &vm_stat[item]);
65235 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65236 + atomic_long_add_unchecked(x, &vm_stat[item]);
65237 }
65238
65239 static inline unsigned long global_page_state(enum zone_stat_item item)
65240 {
65241 - long x = atomic_long_read(&vm_stat[item]);
65242 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65243 #ifdef CONFIG_SMP
65244 if (x < 0)
65245 x = 0;
65246 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65247 static inline unsigned long zone_page_state(struct zone *zone,
65248 enum zone_stat_item item)
65249 {
65250 - long x = atomic_long_read(&zone->vm_stat[item]);
65251 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65252 #ifdef CONFIG_SMP
65253 if (x < 0)
65254 x = 0;
65255 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65256 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65257 enum zone_stat_item item)
65258 {
65259 - long x = atomic_long_read(&zone->vm_stat[item]);
65260 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65261
65262 #ifdef CONFIG_SMP
65263 int cpu;
65264 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65265
65266 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65267 {
65268 - atomic_long_inc(&zone->vm_stat[item]);
65269 - atomic_long_inc(&vm_stat[item]);
65270 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65271 + atomic_long_inc_unchecked(&vm_stat[item]);
65272 }
65273
65274 static inline void __inc_zone_page_state(struct page *page,
65275 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65276
65277 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65278 {
65279 - atomic_long_dec(&zone->vm_stat[item]);
65280 - atomic_long_dec(&vm_stat[item]);
65281 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65282 + atomic_long_dec_unchecked(&vm_stat[item]);
65283 }
65284
65285 static inline void __dec_zone_page_state(struct page *page,
65286 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65287 index e5d1220..ef6e406 100644
65288 --- a/include/linux/xattr.h
65289 +++ b/include/linux/xattr.h
65290 @@ -57,6 +57,11 @@
65291 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65292 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65293
65294 +/* User namespace */
65295 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65296 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65297 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65298 +
65299 #ifdef __KERNEL__
65300
65301 #include <linux/types.h>
65302 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65303 index 944ecdf..a3994fc 100644
65304 --- a/include/media/saa7146_vv.h
65305 +++ b/include/media/saa7146_vv.h
65306 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65307 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65308
65309 /* the extension can override this */
65310 - struct v4l2_ioctl_ops vid_ops;
65311 - struct v4l2_ioctl_ops vbi_ops;
65312 + v4l2_ioctl_ops_no_const vid_ops;
65313 + v4l2_ioctl_ops_no_const vbi_ops;
65314 /* pointer to the saa7146 core ops */
65315 const struct v4l2_ioctl_ops *core_ops;
65316
65317 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65318 index 5c416cd..20021aa 100644
65319 --- a/include/media/v4l2-dev.h
65320 +++ b/include/media/v4l2-dev.h
65321 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65322 int (*mmap) (struct file *, struct vm_area_struct *);
65323 int (*open) (struct file *);
65324 int (*release) (struct file *);
65325 -};
65326 +} __do_const;
65327 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65328
65329 /*
65330 * Newer version of video_device, handled by videodev2.c
65331 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65332 index e614c9c..20602b7 100644
65333 --- a/include/media/v4l2-ioctl.h
65334 +++ b/include/media/v4l2-ioctl.h
65335 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65336 long (*vidioc_default) (struct file *file, void *fh,
65337 bool valid_prio, int cmd, void *arg);
65338 };
65339 -
65340 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65341
65342 /* v4l debugging and diagnostics */
65343
65344 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65345 index bcb9cc3..f4ec722e 100644
65346 --- a/include/net/caif/caif_hsi.h
65347 +++ b/include/net/caif/caif_hsi.h
65348 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65349 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65350 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65351 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65352 -};
65353 +} __no_const;
65354
65355 /* Structure implemented by HSI device. */
65356 struct cfhsi_ops {
65357 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65358 index 9e5425b..8136ffc 100644
65359 --- a/include/net/caif/cfctrl.h
65360 +++ b/include/net/caif/cfctrl.h
65361 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65362 void (*radioset_rsp)(void);
65363 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65364 struct cflayer *client_layer);
65365 -};
65366 +} __no_const;
65367
65368 /* Link Setup Parameters for CAIF-Links. */
65369 struct cfctrl_link_param {
65370 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65371 struct cfctrl {
65372 struct cfsrvl serv;
65373 struct cfctrl_rsp res;
65374 - atomic_t req_seq_no;
65375 - atomic_t rsp_seq_no;
65376 + atomic_unchecked_t req_seq_no;
65377 + atomic_unchecked_t rsp_seq_no;
65378 struct list_head list;
65379 /* Protects from simultaneous access to first_req list */
65380 spinlock_t info_list_lock;
65381 diff --git a/include/net/flow.h b/include/net/flow.h
65382 index 628e11b..4c475df 100644
65383 --- a/include/net/flow.h
65384 +++ b/include/net/flow.h
65385 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65386
65387 extern void flow_cache_flush(void);
65388 extern void flow_cache_flush_deferred(void);
65389 -extern atomic_t flow_cache_genid;
65390 +extern atomic_unchecked_t flow_cache_genid;
65391
65392 #endif
65393 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65394 index 53f464d..ba76aaa 100644
65395 --- a/include/net/inetpeer.h
65396 +++ b/include/net/inetpeer.h
65397 @@ -47,8 +47,8 @@ struct inet_peer {
65398 */
65399 union {
65400 struct {
65401 - atomic_t rid; /* Frag reception counter */
65402 - atomic_t ip_id_count; /* IP ID for the next packet */
65403 + atomic_unchecked_t rid; /* Frag reception counter */
65404 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65405 };
65406 struct rcu_head rcu;
65407 struct inet_peer *gc_next;
65408 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65409 more++;
65410 inet_peer_refcheck(p);
65411 do {
65412 - old = atomic_read(&p->ip_id_count);
65413 + old = atomic_read_unchecked(&p->ip_id_count);
65414 new = old + more;
65415 if (!new)
65416 new = 1;
65417 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65418 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65419 return new;
65420 }
65421
65422 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65423 index 9497be1..5a4fafe 100644
65424 --- a/include/net/ip_fib.h
65425 +++ b/include/net/ip_fib.h
65426 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65427
65428 #define FIB_RES_SADDR(net, res) \
65429 ((FIB_RES_NH(res).nh_saddr_genid == \
65430 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65431 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65432 FIB_RES_NH(res).nh_saddr : \
65433 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65434 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65435 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65436 index 95374d1..2300e36 100644
65437 --- a/include/net/ip_vs.h
65438 +++ b/include/net/ip_vs.h
65439 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65440 struct ip_vs_conn *control; /* Master control connection */
65441 atomic_t n_control; /* Number of controlled ones */
65442 struct ip_vs_dest *dest; /* real server */
65443 - atomic_t in_pkts; /* incoming packet counter */
65444 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65445
65446 /* packet transmitter for different forwarding methods. If it
65447 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65448 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65449 __be16 port; /* port number of the server */
65450 union nf_inet_addr addr; /* IP address of the server */
65451 volatile unsigned int flags; /* dest status flags */
65452 - atomic_t conn_flags; /* flags to copy to conn */
65453 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65454 atomic_t weight; /* server weight */
65455
65456 atomic_t refcnt; /* reference counter */
65457 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65458 index 69b610a..fe3962c 100644
65459 --- a/include/net/irda/ircomm_core.h
65460 +++ b/include/net/irda/ircomm_core.h
65461 @@ -51,7 +51,7 @@ typedef struct {
65462 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65463 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65464 struct ircomm_info *);
65465 -} call_t;
65466 +} __no_const call_t;
65467
65468 struct ircomm_cb {
65469 irda_queue_t queue;
65470 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65471 index 59ba38bc..d515662 100644
65472 --- a/include/net/irda/ircomm_tty.h
65473 +++ b/include/net/irda/ircomm_tty.h
65474 @@ -35,6 +35,7 @@
65475 #include <linux/termios.h>
65476 #include <linux/timer.h>
65477 #include <linux/tty.h> /* struct tty_struct */
65478 +#include <asm/local.h>
65479
65480 #include <net/irda/irias_object.h>
65481 #include <net/irda/ircomm_core.h>
65482 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65483 unsigned short close_delay;
65484 unsigned short closing_wait; /* time to wait before closing */
65485
65486 - int open_count;
65487 - int blocked_open; /* # of blocked opens */
65488 + local_t open_count;
65489 + local_t blocked_open; /* # of blocked opens */
65490
65491 /* Protect concurent access to :
65492 * o self->open_count
65493 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65494 index cc7c197..9f2da2a 100644
65495 --- a/include/net/iucv/af_iucv.h
65496 +++ b/include/net/iucv/af_iucv.h
65497 @@ -141,7 +141,7 @@ struct iucv_sock {
65498 struct iucv_sock_list {
65499 struct hlist_head head;
65500 rwlock_t lock;
65501 - atomic_t autobind_name;
65502 + atomic_unchecked_t autobind_name;
65503 };
65504
65505 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65506 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65507 index 344d898..2ae1302 100644
65508 --- a/include/net/neighbour.h
65509 +++ b/include/net/neighbour.h
65510 @@ -123,7 +123,7 @@ struct neigh_ops {
65511 void (*error_report)(struct neighbour *, struct sk_buff *);
65512 int (*output)(struct neighbour *, struct sk_buff *);
65513 int (*connected_output)(struct neighbour *, struct sk_buff *);
65514 -};
65515 +} __do_const;
65516
65517 struct pneigh_entry {
65518 struct pneigh_entry *next;
65519 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65520 index fd87963..312a11f 100644
65521 --- a/include/net/net_namespace.h
65522 +++ b/include/net/net_namespace.h
65523 @@ -102,7 +102,7 @@ struct net {
65524 #endif
65525 struct netns_ipvs *ipvs;
65526 struct sock *diag_nlsk;
65527 - atomic_t rt_genid;
65528 + atomic_unchecked_t rt_genid;
65529 };
65530
65531
65532 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65533
65534 static inline int rt_genid(struct net *net)
65535 {
65536 - return atomic_read(&net->rt_genid);
65537 + return atomic_read_unchecked(&net->rt_genid);
65538 }
65539
65540 static inline void rt_genid_bump(struct net *net)
65541 {
65542 - atomic_inc(&net->rt_genid);
65543 + atomic_inc_unchecked(&net->rt_genid);
65544 }
65545
65546 #endif /* __NET_NET_NAMESPACE_H */
65547 diff --git a/include/net/netdma.h b/include/net/netdma.h
65548 index 8ba8ce2..99b7fff 100644
65549 --- a/include/net/netdma.h
65550 +++ b/include/net/netdma.h
65551 @@ -24,7 +24,7 @@
65552 #include <linux/dmaengine.h>
65553 #include <linux/skbuff.h>
65554
65555 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65556 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65557 struct sk_buff *skb, int offset, struct iovec *to,
65558 size_t len, struct dma_pinned_list *pinned_list);
65559
65560 diff --git a/include/net/netlink.h b/include/net/netlink.h
65561 index 785f37a..c81dc0c 100644
65562 --- a/include/net/netlink.h
65563 +++ b/include/net/netlink.h
65564 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65565 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65566 {
65567 if (mark)
65568 - skb_trim(skb, (unsigned char *) mark - skb->data);
65569 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65570 }
65571
65572 /**
65573 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65574 index eb24dbc..567d6ed 100644
65575 --- a/include/net/netns/ipv4.h
65576 +++ b/include/net/netns/ipv4.h
65577 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65578 unsigned int sysctl_ping_group_range[2];
65579 long sysctl_tcp_mem[3];
65580
65581 - atomic_t dev_addr_genid;
65582 + atomic_unchecked_t dev_addr_genid;
65583
65584 #ifdef CONFIG_IP_MROUTE
65585 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65586 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65587 index ff49964..1411fee 100644
65588 --- a/include/net/sctp/sctp.h
65589 +++ b/include/net/sctp/sctp.h
65590 @@ -320,9 +320,9 @@ do { \
65591
65592 #else /* SCTP_DEBUG */
65593
65594 -#define SCTP_DEBUG_PRINTK(whatever...)
65595 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65596 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65597 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65598 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65599 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65600 #define SCTP_ENABLE_DEBUG
65601 #define SCTP_DISABLE_DEBUG
65602 #define SCTP_ASSERT(expr, str, func)
65603 diff --git a/include/net/sock.h b/include/net/sock.h
65604 index adb7da2..1100002 100644
65605 --- a/include/net/sock.h
65606 +++ b/include/net/sock.h
65607 @@ -305,7 +305,7 @@ struct sock {
65608 #ifdef CONFIG_RPS
65609 __u32 sk_rxhash;
65610 #endif
65611 - atomic_t sk_drops;
65612 + atomic_unchecked_t sk_drops;
65613 int sk_rcvbuf;
65614
65615 struct sk_filter __rcu *sk_filter;
65616 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65617 }
65618
65619 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65620 - char __user *from, char *to,
65621 + char __user *from, unsigned char *to,
65622 int copy, int offset)
65623 {
65624 if (skb->ip_summed == CHECKSUM_NONE) {
65625 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65626 }
65627 }
65628
65629 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65630 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65631
65632 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65633 {
65634 diff --git a/include/net/tcp.h b/include/net/tcp.h
65635 index 1f000ff..e5a8dfb 100644
65636 --- a/include/net/tcp.h
65637 +++ b/include/net/tcp.h
65638 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65639 extern void tcp_xmit_retransmit_queue(struct sock *);
65640 extern void tcp_simple_retransmit(struct sock *);
65641 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65642 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65643 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65644
65645 extern void tcp_send_probe0(struct sock *);
65646 extern void tcp_send_partial(struct sock *);
65647 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65648 struct inet6_skb_parm h6;
65649 #endif
65650 } header; /* For incoming frames */
65651 - __u32 seq; /* Starting sequence number */
65652 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65653 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65654 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65655 __u32 when; /* used to compute rtt's */
65656 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65657
65658 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65659
65660 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65661 /* 1 byte hole */
65662 - __u32 ack_seq; /* Sequence number ACK'd */
65663 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65664 };
65665
65666 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65667 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65668 char *name;
65669 sa_family_t family;
65670 const struct file_operations *seq_fops;
65671 - struct seq_operations seq_ops;
65672 + seq_operations_no_const seq_ops;
65673 };
65674
65675 struct tcp_iter_state {
65676 diff --git a/include/net/udp.h b/include/net/udp.h
65677 index 065f379..b661b40 100644
65678 --- a/include/net/udp.h
65679 +++ b/include/net/udp.h
65680 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65681 sa_family_t family;
65682 struct udp_table *udp_table;
65683 const struct file_operations *seq_fops;
65684 - struct seq_operations seq_ops;
65685 + seq_operations_no_const seq_ops;
65686 };
65687
65688 struct udp_iter_state {
65689 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65690 index 639dd13..15b206c 100644
65691 --- a/include/net/xfrm.h
65692 +++ b/include/net/xfrm.h
65693 @@ -514,7 +514,7 @@ struct xfrm_policy {
65694 struct timer_list timer;
65695
65696 struct flow_cache_object flo;
65697 - atomic_t genid;
65698 + atomic_unchecked_t genid;
65699 u32 priority;
65700 u32 index;
65701 struct xfrm_mark mark;
65702 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65703 index 1a046b1..ee0bef0 100644
65704 --- a/include/rdma/iw_cm.h
65705 +++ b/include/rdma/iw_cm.h
65706 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65707 int backlog);
65708
65709 int (*destroy_listen)(struct iw_cm_id *cm_id);
65710 -};
65711 +} __no_const;
65712
65713 /**
65714 * iw_create_cm_id - Create an IW CM identifier.
65715 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65716 index 399162b..b337f1a 100644
65717 --- a/include/scsi/libfc.h
65718 +++ b/include/scsi/libfc.h
65719 @@ -762,6 +762,7 @@ struct libfc_function_template {
65720 */
65721 void (*disc_stop_final) (struct fc_lport *);
65722 };
65723 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65724
65725 /**
65726 * struct fc_disc - Discovery context
65727 @@ -866,7 +867,7 @@ struct fc_lport {
65728 struct fc_vport *vport;
65729
65730 /* Operational Information */
65731 - struct libfc_function_template tt;
65732 + libfc_function_template_no_const tt;
65733 u8 link_up;
65734 u8 qfull;
65735 enum fc_lport_state state;
65736 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65737 index 9895f69..f1418f0 100644
65738 --- a/include/scsi/scsi_device.h
65739 +++ b/include/scsi/scsi_device.h
65740 @@ -166,9 +166,9 @@ struct scsi_device {
65741 unsigned int max_device_blocked; /* what device_blocked counts down from */
65742 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65743
65744 - atomic_t iorequest_cnt;
65745 - atomic_t iodone_cnt;
65746 - atomic_t ioerr_cnt;
65747 + atomic_unchecked_t iorequest_cnt;
65748 + atomic_unchecked_t iodone_cnt;
65749 + atomic_unchecked_t ioerr_cnt;
65750
65751 struct device sdev_gendev,
65752 sdev_dev;
65753 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65754 index b797e8f..8e2c3aa 100644
65755 --- a/include/scsi/scsi_transport_fc.h
65756 +++ b/include/scsi/scsi_transport_fc.h
65757 @@ -751,7 +751,8 @@ struct fc_function_template {
65758 unsigned long show_host_system_hostname:1;
65759
65760 unsigned long disable_target_scan:1;
65761 -};
65762 +} __do_const;
65763 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65764
65765
65766 /**
65767 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65768 index 030b87c..98a6954 100644
65769 --- a/include/sound/ak4xxx-adda.h
65770 +++ b/include/sound/ak4xxx-adda.h
65771 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65772 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65773 unsigned char val);
65774 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65775 -};
65776 +} __no_const;
65777
65778 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65779
65780 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65781 index 8c05e47..2b5df97 100644
65782 --- a/include/sound/hwdep.h
65783 +++ b/include/sound/hwdep.h
65784 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65785 struct snd_hwdep_dsp_status *status);
65786 int (*dsp_load)(struct snd_hwdep *hw,
65787 struct snd_hwdep_dsp_image *image);
65788 -};
65789 +} __no_const;
65790
65791 struct snd_hwdep {
65792 struct snd_card *card;
65793 diff --git a/include/sound/info.h b/include/sound/info.h
65794 index 9ca1a49..aba1728 100644
65795 --- a/include/sound/info.h
65796 +++ b/include/sound/info.h
65797 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65798 struct snd_info_buffer *buffer);
65799 void (*write)(struct snd_info_entry *entry,
65800 struct snd_info_buffer *buffer);
65801 -};
65802 +} __no_const;
65803
65804 struct snd_info_entry_ops {
65805 int (*open)(struct snd_info_entry *entry,
65806 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65807 index cdca2ab..10bbe05 100644
65808 --- a/include/sound/pcm.h
65809 +++ b/include/sound/pcm.h
65810 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65811 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65812 int (*ack)(struct snd_pcm_substream *substream);
65813 };
65814 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65815
65816 /*
65817 *
65818 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65819 index af1b49e..a5d55a5 100644
65820 --- a/include/sound/sb16_csp.h
65821 +++ b/include/sound/sb16_csp.h
65822 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65823 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65824 int (*csp_stop) (struct snd_sb_csp * p);
65825 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65826 -};
65827 +} __no_const;
65828
65829 /*
65830 * CSP private data
65831 diff --git a/include/sound/soc.h b/include/sound/soc.h
65832 index e063380..e8077d5 100644
65833 --- a/include/sound/soc.h
65834 +++ b/include/sound/soc.h
65835 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65836 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65837 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65838 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65839 -};
65840 +} __do_const;
65841
65842 struct snd_soc_platform {
65843 const char *name;
65844 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65845 struct snd_soc_dai_link *dai_link;
65846 struct mutex pcm_mutex;
65847 enum snd_soc_pcm_subclass pcm_subclass;
65848 - struct snd_pcm_ops ops;
65849 + snd_pcm_ops_no_const ops;
65850
65851 unsigned int dev_registered:1;
65852
65853 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65854 index fe8590c..aaed363 100644
65855 --- a/include/sound/tea575x-tuner.h
65856 +++ b/include/sound/tea575x-tuner.h
65857 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65858
65859 struct snd_tea575x {
65860 struct v4l2_device *v4l2_dev;
65861 - struct v4l2_file_operations fops;
65862 + v4l2_file_operations_no_const fops;
65863 struct video_device vd; /* video device */
65864 int radio_nr; /* radio_nr */
65865 bool tea5759; /* 5759 chip is present */
65866 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65867 index 5be8937..a8e46e9 100644
65868 --- a/include/target/target_core_base.h
65869 +++ b/include/target/target_core_base.h
65870 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65871 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65872 int (*t10_pr_register)(struct se_cmd *);
65873 int (*t10_pr_clear)(struct se_cmd *);
65874 -};
65875 +} __no_const;
65876
65877 struct t10_reservation {
65878 /* Reservation effects all target ports */
65879 @@ -758,7 +758,7 @@ struct se_device {
65880 spinlock_t stats_lock;
65881 /* Active commands on this virtual SE device */
65882 atomic_t simple_cmds;
65883 - atomic_t dev_ordered_id;
65884 + atomic_unchecked_t dev_ordered_id;
65885 atomic_t dev_ordered_sync;
65886 atomic_t dev_qf_count;
65887 struct se_obj dev_obj;
65888 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65889 new file mode 100644
65890 index 0000000..2efe49d
65891 --- /dev/null
65892 +++ b/include/trace/events/fs.h
65893 @@ -0,0 +1,53 @@
65894 +#undef TRACE_SYSTEM
65895 +#define TRACE_SYSTEM fs
65896 +
65897 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65898 +#define _TRACE_FS_H
65899 +
65900 +#include <linux/fs.h>
65901 +#include <linux/tracepoint.h>
65902 +
65903 +TRACE_EVENT(do_sys_open,
65904 +
65905 + TP_PROTO(char *filename, int flags, int mode),
65906 +
65907 + TP_ARGS(filename, flags, mode),
65908 +
65909 + TP_STRUCT__entry(
65910 + __string( filename, filename )
65911 + __field( int, flags )
65912 + __field( int, mode )
65913 + ),
65914 +
65915 + TP_fast_assign(
65916 + __assign_str(filename, filename);
65917 + __entry->flags = flags;
65918 + __entry->mode = mode;
65919 + ),
65920 +
65921 + TP_printk("\"%s\" %x %o",
65922 + __get_str(filename), __entry->flags, __entry->mode)
65923 +);
65924 +
65925 +TRACE_EVENT(open_exec,
65926 +
65927 + TP_PROTO(const char *filename),
65928 +
65929 + TP_ARGS(filename),
65930 +
65931 + TP_STRUCT__entry(
65932 + __string( filename, filename )
65933 + ),
65934 +
65935 + TP_fast_assign(
65936 + __assign_str(filename, filename);
65937 + ),
65938 +
65939 + TP_printk("\"%s\"",
65940 + __get_str(filename))
65941 +);
65942 +
65943 +#endif /* _TRACE_FS_H */
65944 +
65945 +/* This part must be outside protection */
65946 +#include <trace/define_trace.h>
65947 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65948 index 1c09820..7f5ec79 100644
65949 --- a/include/trace/events/irq.h
65950 +++ b/include/trace/events/irq.h
65951 @@ -36,7 +36,7 @@ struct softirq_action;
65952 */
65953 TRACE_EVENT(irq_handler_entry,
65954
65955 - TP_PROTO(int irq, struct irqaction *action),
65956 + TP_PROTO(int irq, const struct irqaction *action),
65957
65958 TP_ARGS(irq, action),
65959
65960 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65961 */
65962 TRACE_EVENT(irq_handler_exit,
65963
65964 - TP_PROTO(int irq, struct irqaction *action, int ret),
65965 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65966
65967 TP_ARGS(irq, action, ret),
65968
65969 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65970 index f9466fa..f4e2b81 100644
65971 --- a/include/video/udlfb.h
65972 +++ b/include/video/udlfb.h
65973 @@ -53,10 +53,10 @@ struct dlfb_data {
65974 u32 pseudo_palette[256];
65975 int blank_mode; /*one of FB_BLANK_ */
65976 /* blit-only rendering path metrics, exposed through sysfs */
65977 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65978 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65979 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65980 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65981 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65982 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65983 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65984 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65985 };
65986
65987 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65988 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65989 index 0993a22..32ba2fe 100644
65990 --- a/include/video/uvesafb.h
65991 +++ b/include/video/uvesafb.h
65992 @@ -177,6 +177,7 @@ struct uvesafb_par {
65993 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65994 u8 pmi_setpal; /* PMI for palette changes */
65995 u16 *pmi_base; /* protected mode interface location */
65996 + u8 *pmi_code; /* protected mode code location */
65997 void *pmi_start;
65998 void *pmi_pal;
65999 u8 *vbe_state_orig; /*
66000 diff --git a/init/Kconfig b/init/Kconfig
66001 index af6c7f8..5c188f8 100644
66002 --- a/init/Kconfig
66003 +++ b/init/Kconfig
66004 @@ -850,6 +850,7 @@ endif # CGROUPS
66005
66006 config CHECKPOINT_RESTORE
66007 bool "Checkpoint/restore support" if EXPERT
66008 + depends on !GRKERNSEC
66009 default n
66010 help
66011 Enables additional kernel features in a sake of checkpoint/restore.
66012 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66013 # Security modules
66014 depends on SECURITY_TOMOYO = n
66015 depends on SECURITY_APPARMOR = n
66016 + depends on GRKERNSEC = n
66017
66018 config UIDGID_STRICT_TYPE_CHECKS
66019 bool "Require conversions between uid/gids and their internal representation"
66020 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66021
66022 config COMPAT_BRK
66023 bool "Disable heap randomization"
66024 - default y
66025 + default n
66026 help
66027 Randomizing heap placement makes heap exploits harder, but it
66028 also breaks ancient binaries (including anything libc5 based).
66029 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66030 config STOP_MACHINE
66031 bool
66032 default y
66033 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66034 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66035 help
66036 Need stop_machine() primitive.
66037
66038 diff --git a/init/Makefile b/init/Makefile
66039 index 7bc47ee..6da2dc7 100644
66040 --- a/init/Makefile
66041 +++ b/init/Makefile
66042 @@ -2,6 +2,9 @@
66043 # Makefile for the linux kernel.
66044 #
66045
66046 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66047 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66048 +
66049 obj-y := main.o version.o mounts.o
66050 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66051 obj-y += noinitramfs.o
66052 diff --git a/init/do_mounts.c b/init/do_mounts.c
66053 index d3f0aee..c9322f5 100644
66054 --- a/init/do_mounts.c
66055 +++ b/init/do_mounts.c
66056 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66057 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66058 {
66059 struct super_block *s;
66060 - int err = sys_mount(name, "/root", fs, flags, data);
66061 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66062 if (err)
66063 return err;
66064
66065 - sys_chdir("/root");
66066 + sys_chdir((const char __force_user *)"/root");
66067 s = current->fs->pwd.dentry->d_sb;
66068 ROOT_DEV = s->s_dev;
66069 printk(KERN_INFO
66070 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66071 va_start(args, fmt);
66072 vsprintf(buf, fmt, args);
66073 va_end(args);
66074 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66075 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66076 if (fd >= 0) {
66077 sys_ioctl(fd, FDEJECT, 0);
66078 sys_close(fd);
66079 }
66080 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66081 - fd = sys_open("/dev/console", O_RDWR, 0);
66082 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66083 if (fd >= 0) {
66084 sys_ioctl(fd, TCGETS, (long)&termios);
66085 termios.c_lflag &= ~ICANON;
66086 sys_ioctl(fd, TCSETSF, (long)&termios);
66087 - sys_read(fd, &c, 1);
66088 + sys_read(fd, (char __user *)&c, 1);
66089 termios.c_lflag |= ICANON;
66090 sys_ioctl(fd, TCSETSF, (long)&termios);
66091 sys_close(fd);
66092 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66093 mount_root();
66094 out:
66095 devtmpfs_mount("dev");
66096 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66097 - sys_chroot(".");
66098 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66099 + sys_chroot((const char __force_user *)".");
66100 }
66101 diff --git a/init/do_mounts.h b/init/do_mounts.h
66102 index f5b978a..69dbfe8 100644
66103 --- a/init/do_mounts.h
66104 +++ b/init/do_mounts.h
66105 @@ -15,15 +15,15 @@ extern int root_mountflags;
66106
66107 static inline int create_dev(char *name, dev_t dev)
66108 {
66109 - sys_unlink(name);
66110 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66111 + sys_unlink((char __force_user *)name);
66112 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66113 }
66114
66115 #if BITS_PER_LONG == 32
66116 static inline u32 bstat(char *name)
66117 {
66118 struct stat64 stat;
66119 - if (sys_stat64(name, &stat) != 0)
66120 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66121 return 0;
66122 if (!S_ISBLK(stat.st_mode))
66123 return 0;
66124 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66125 static inline u32 bstat(char *name)
66126 {
66127 struct stat stat;
66128 - if (sys_newstat(name, &stat) != 0)
66129 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66130 return 0;
66131 if (!S_ISBLK(stat.st_mode))
66132 return 0;
66133 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66134 index 135959a2..28a3f43 100644
66135 --- a/init/do_mounts_initrd.c
66136 +++ b/init/do_mounts_initrd.c
66137 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66138 create_dev("/dev/root.old", Root_RAM0);
66139 /* mount initrd on rootfs' /root */
66140 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66141 - sys_mkdir("/old", 0700);
66142 - root_fd = sys_open("/", 0, 0);
66143 - old_fd = sys_open("/old", 0, 0);
66144 + sys_mkdir((const char __force_user *)"/old", 0700);
66145 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66146 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66147 /* move initrd over / and chdir/chroot in initrd root */
66148 - sys_chdir("/root");
66149 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66150 - sys_chroot(".");
66151 + sys_chdir((const char __force_user *)"/root");
66152 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66153 + sys_chroot((const char __force_user *)".");
66154
66155 /*
66156 * In case that a resume from disk is carried out by linuxrc or one of
66157 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66158
66159 /* move initrd to rootfs' /old */
66160 sys_fchdir(old_fd);
66161 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66162 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66163 /* switch root and cwd back to / of rootfs */
66164 sys_fchdir(root_fd);
66165 - sys_chroot(".");
66166 + sys_chroot((const char __force_user *)".");
66167 sys_close(old_fd);
66168 sys_close(root_fd);
66169
66170 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66171 - sys_chdir("/old");
66172 + sys_chdir((const char __force_user *)"/old");
66173 return;
66174 }
66175
66176 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66177 mount_root();
66178
66179 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66180 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66181 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66182 if (!error)
66183 printk("okay\n");
66184 else {
66185 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66186 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66187 if (error == -ENOENT)
66188 printk("/initrd does not exist. Ignored.\n");
66189 else
66190 printk("failed\n");
66191 printk(KERN_NOTICE "Unmounting old root\n");
66192 - sys_umount("/old", MNT_DETACH);
66193 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66194 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66195 if (fd < 0) {
66196 error = fd;
66197 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66198 * mounted in the normal path.
66199 */
66200 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66201 - sys_unlink("/initrd.image");
66202 + sys_unlink((const char __force_user *)"/initrd.image");
66203 handle_initrd();
66204 return 1;
66205 }
66206 }
66207 - sys_unlink("/initrd.image");
66208 + sys_unlink((const char __force_user *)"/initrd.image");
66209 return 0;
66210 }
66211 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66212 index 8cb6db5..d729f50 100644
66213 --- a/init/do_mounts_md.c
66214 +++ b/init/do_mounts_md.c
66215 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66216 partitioned ? "_d" : "", minor,
66217 md_setup_args[ent].device_names);
66218
66219 - fd = sys_open(name, 0, 0);
66220 + fd = sys_open((char __force_user *)name, 0, 0);
66221 if (fd < 0) {
66222 printk(KERN_ERR "md: open failed - cannot start "
66223 "array %s\n", name);
66224 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66225 * array without it
66226 */
66227 sys_close(fd);
66228 - fd = sys_open(name, 0, 0);
66229 + fd = sys_open((char __force_user *)name, 0, 0);
66230 sys_ioctl(fd, BLKRRPART, 0);
66231 }
66232 sys_close(fd);
66233 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66234
66235 wait_for_device_probe();
66236
66237 - fd = sys_open("/dev/md0", 0, 0);
66238 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66239 if (fd >= 0) {
66240 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66241 sys_close(fd);
66242 diff --git a/init/init_task.c b/init/init_task.c
66243 index 8b2f399..f0797c9 100644
66244 --- a/init/init_task.c
66245 +++ b/init/init_task.c
66246 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66247 * Initial thread structure. Alignment of this is handled by a special
66248 * linker map entry.
66249 */
66250 +#ifdef CONFIG_X86
66251 +union thread_union init_thread_union __init_task_data;
66252 +#else
66253 union thread_union init_thread_union __init_task_data =
66254 { INIT_THREAD_INFO(init_task) };
66255 +#endif
66256 diff --git a/init/initramfs.c b/init/initramfs.c
66257 index 84c6bf1..8899338 100644
66258 --- a/init/initramfs.c
66259 +++ b/init/initramfs.c
66260 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66261 }
66262 }
66263
66264 -static long __init do_utime(char *filename, time_t mtime)
66265 +static long __init do_utime(char __force_user *filename, time_t mtime)
66266 {
66267 struct timespec t[2];
66268
66269 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66270 struct dir_entry *de, *tmp;
66271 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66272 list_del(&de->list);
66273 - do_utime(de->name, de->mtime);
66274 + do_utime((char __force_user *)de->name, de->mtime);
66275 kfree(de->name);
66276 kfree(de);
66277 }
66278 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66279 if (nlink >= 2) {
66280 char *old = find_link(major, minor, ino, mode, collected);
66281 if (old)
66282 - return (sys_link(old, collected) < 0) ? -1 : 1;
66283 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66284 }
66285 return 0;
66286 }
66287 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66288 {
66289 struct stat st;
66290
66291 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66292 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66293 if (S_ISDIR(st.st_mode))
66294 - sys_rmdir(path);
66295 + sys_rmdir((char __force_user *)path);
66296 else
66297 - sys_unlink(path);
66298 + sys_unlink((char __force_user *)path);
66299 }
66300 }
66301
66302 @@ -315,7 +315,7 @@ static int __init do_name(void)
66303 int openflags = O_WRONLY|O_CREAT;
66304 if (ml != 1)
66305 openflags |= O_TRUNC;
66306 - wfd = sys_open(collected, openflags, mode);
66307 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66308
66309 if (wfd >= 0) {
66310 sys_fchown(wfd, uid, gid);
66311 @@ -327,17 +327,17 @@ static int __init do_name(void)
66312 }
66313 }
66314 } else if (S_ISDIR(mode)) {
66315 - sys_mkdir(collected, mode);
66316 - sys_chown(collected, uid, gid);
66317 - sys_chmod(collected, mode);
66318 + sys_mkdir((char __force_user *)collected, mode);
66319 + sys_chown((char __force_user *)collected, uid, gid);
66320 + sys_chmod((char __force_user *)collected, mode);
66321 dir_add(collected, mtime);
66322 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66323 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66324 if (maybe_link() == 0) {
66325 - sys_mknod(collected, mode, rdev);
66326 - sys_chown(collected, uid, gid);
66327 - sys_chmod(collected, mode);
66328 - do_utime(collected, mtime);
66329 + sys_mknod((char __force_user *)collected, mode, rdev);
66330 + sys_chown((char __force_user *)collected, uid, gid);
66331 + sys_chmod((char __force_user *)collected, mode);
66332 + do_utime((char __force_user *)collected, mtime);
66333 }
66334 }
66335 return 0;
66336 @@ -346,15 +346,15 @@ static int __init do_name(void)
66337 static int __init do_copy(void)
66338 {
66339 if (count >= body_len) {
66340 - sys_write(wfd, victim, body_len);
66341 + sys_write(wfd, (char __force_user *)victim, body_len);
66342 sys_close(wfd);
66343 - do_utime(vcollected, mtime);
66344 + do_utime((char __force_user *)vcollected, mtime);
66345 kfree(vcollected);
66346 eat(body_len);
66347 state = SkipIt;
66348 return 0;
66349 } else {
66350 - sys_write(wfd, victim, count);
66351 + sys_write(wfd, (char __force_user *)victim, count);
66352 body_len -= count;
66353 eat(count);
66354 return 1;
66355 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66356 {
66357 collected[N_ALIGN(name_len) + body_len] = '\0';
66358 clean_path(collected, 0);
66359 - sys_symlink(collected + N_ALIGN(name_len), collected);
66360 - sys_lchown(collected, uid, gid);
66361 - do_utime(collected, mtime);
66362 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66363 + sys_lchown((char __force_user *)collected, uid, gid);
66364 + do_utime((char __force_user *)collected, mtime);
66365 state = SkipIt;
66366 next_state = Reset;
66367 return 0;
66368 diff --git a/init/main.c b/init/main.c
66369 index d61ec54..bd3144f 100644
66370 --- a/init/main.c
66371 +++ b/init/main.c
66372 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66373 extern void tc_init(void);
66374 #endif
66375
66376 +extern void grsecurity_init(void);
66377 +
66378 /*
66379 * Debug helper: via this flag we know that we are in 'early bootup code'
66380 * where only the boot processor is running with IRQ disabled. This means
66381 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66382
66383 __setup("reset_devices", set_reset_devices);
66384
66385 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66386 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66387 +static int __init setup_grsec_proc_gid(char *str)
66388 +{
66389 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66390 + return 1;
66391 +}
66392 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66393 +#endif
66394 +
66395 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66396 +extern char pax_enter_kernel_user[];
66397 +extern char pax_exit_kernel_user[];
66398 +extern pgdval_t clone_pgd_mask;
66399 +#endif
66400 +
66401 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66402 +static int __init setup_pax_nouderef(char *str)
66403 +{
66404 +#ifdef CONFIG_X86_32
66405 + unsigned int cpu;
66406 + struct desc_struct *gdt;
66407 +
66408 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66409 + gdt = get_cpu_gdt_table(cpu);
66410 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66411 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66412 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66413 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66414 + }
66415 + loadsegment(ds, __KERNEL_DS);
66416 + loadsegment(es, __KERNEL_DS);
66417 + loadsegment(ss, __KERNEL_DS);
66418 +#else
66419 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66420 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66421 + clone_pgd_mask = ~(pgdval_t)0UL;
66422 +#endif
66423 +
66424 + return 0;
66425 +}
66426 +early_param("pax_nouderef", setup_pax_nouderef);
66427 +#endif
66428 +
66429 +#ifdef CONFIG_PAX_SOFTMODE
66430 +int pax_softmode;
66431 +
66432 +static int __init setup_pax_softmode(char *str)
66433 +{
66434 + get_option(&str, &pax_softmode);
66435 + return 1;
66436 +}
66437 +__setup("pax_softmode=", setup_pax_softmode);
66438 +#endif
66439 +
66440 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66441 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66442 static const char *panic_later, *panic_param;
66443 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66444 {
66445 int count = preempt_count();
66446 int ret;
66447 + const char *msg1 = "", *msg2 = "";
66448
66449 if (initcall_debug)
66450 ret = do_one_initcall_debug(fn);
66451 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66452 sprintf(msgbuf, "error code %d ", ret);
66453
66454 if (preempt_count() != count) {
66455 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66456 + msg1 = " preemption imbalance";
66457 preempt_count() = count;
66458 }
66459 if (irqs_disabled()) {
66460 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66461 + msg2 = " disabled interrupts";
66462 local_irq_enable();
66463 }
66464 - if (msgbuf[0]) {
66465 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66466 + if (msgbuf[0] || *msg1 || *msg2) {
66467 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66468 }
66469
66470 return ret;
66471 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66472 level, level,
66473 &repair_env_string);
66474
66475 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66476 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66477 do_one_initcall(*fn);
66478 +
66479 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66480 + transfer_latent_entropy();
66481 +#endif
66482 +
66483 + }
66484 }
66485
66486 static void __init do_initcalls(void)
66487 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66488 {
66489 initcall_t *fn;
66490
66491 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66492 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66493 do_one_initcall(*fn);
66494 +
66495 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66496 + transfer_latent_entropy();
66497 +#endif
66498 +
66499 + }
66500 }
66501
66502 static void run_init_process(const char *init_filename)
66503 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66504 do_basic_setup();
66505
66506 /* Open the /dev/console on the rootfs, this should never fail */
66507 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66508 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66509 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66510
66511 (void) sys_dup(0);
66512 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66513 if (!ramdisk_execute_command)
66514 ramdisk_execute_command = "/init";
66515
66516 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66517 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66518 ramdisk_execute_command = NULL;
66519 prepare_namespace();
66520 }
66521
66522 + grsecurity_init();
66523 +
66524 /*
66525 * Ok, we have completed the initial bootup, and
66526 * we're essentially up and running. Get rid of the
66527 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66528 index 9a08acc..e65ebe7 100644
66529 --- a/ipc/mqueue.c
66530 +++ b/ipc/mqueue.c
66531 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66532 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66533 info->attr.mq_msgsize);
66534
66535 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66536 spin_lock(&mq_lock);
66537 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66538 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66539 diff --git a/ipc/msg.c b/ipc/msg.c
66540 index 7385de2..a8180e08 100644
66541 --- a/ipc/msg.c
66542 +++ b/ipc/msg.c
66543 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66544 return security_msg_queue_associate(msq, msgflg);
66545 }
66546
66547 +static struct ipc_ops msg_ops = {
66548 + .getnew = newque,
66549 + .associate = msg_security,
66550 + .more_checks = NULL
66551 +};
66552 +
66553 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66554 {
66555 struct ipc_namespace *ns;
66556 - struct ipc_ops msg_ops;
66557 struct ipc_params msg_params;
66558
66559 ns = current->nsproxy->ipc_ns;
66560
66561 - msg_ops.getnew = newque;
66562 - msg_ops.associate = msg_security;
66563 - msg_ops.more_checks = NULL;
66564 -
66565 msg_params.key = key;
66566 msg_params.flg = msgflg;
66567
66568 diff --git a/ipc/sem.c b/ipc/sem.c
66569 index 5215a81..cfc0cac 100644
66570 --- a/ipc/sem.c
66571 +++ b/ipc/sem.c
66572 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66573 return 0;
66574 }
66575
66576 +static struct ipc_ops sem_ops = {
66577 + .getnew = newary,
66578 + .associate = sem_security,
66579 + .more_checks = sem_more_checks
66580 +};
66581 +
66582 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66583 {
66584 struct ipc_namespace *ns;
66585 - struct ipc_ops sem_ops;
66586 struct ipc_params sem_params;
66587
66588 ns = current->nsproxy->ipc_ns;
66589 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66590 if (nsems < 0 || nsems > ns->sc_semmsl)
66591 return -EINVAL;
66592
66593 - sem_ops.getnew = newary;
66594 - sem_ops.associate = sem_security;
66595 - sem_ops.more_checks = sem_more_checks;
66596 -
66597 sem_params.key = key;
66598 sem_params.flg = semflg;
66599 sem_params.u.nsems = nsems;
66600 diff --git a/ipc/shm.c b/ipc/shm.c
66601 index 00faa05..7040960 100644
66602 --- a/ipc/shm.c
66603 +++ b/ipc/shm.c
66604 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66605 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66606 #endif
66607
66608 +#ifdef CONFIG_GRKERNSEC
66609 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66610 + const time_t shm_createtime, const uid_t cuid,
66611 + const int shmid);
66612 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66613 + const time_t shm_createtime);
66614 +#endif
66615 +
66616 void shm_init_ns(struct ipc_namespace *ns)
66617 {
66618 ns->shm_ctlmax = SHMMAX;
66619 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66620 shp->shm_lprid = 0;
66621 shp->shm_atim = shp->shm_dtim = 0;
66622 shp->shm_ctim = get_seconds();
66623 +#ifdef CONFIG_GRKERNSEC
66624 + {
66625 + struct timespec timeval;
66626 + do_posix_clock_monotonic_gettime(&timeval);
66627 +
66628 + shp->shm_createtime = timeval.tv_sec;
66629 + }
66630 +#endif
66631 shp->shm_segsz = size;
66632 shp->shm_nattch = 0;
66633 shp->shm_file = file;
66634 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66635 return 0;
66636 }
66637
66638 +static struct ipc_ops shm_ops = {
66639 + .getnew = newseg,
66640 + .associate = shm_security,
66641 + .more_checks = shm_more_checks
66642 +};
66643 +
66644 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66645 {
66646 struct ipc_namespace *ns;
66647 - struct ipc_ops shm_ops;
66648 struct ipc_params shm_params;
66649
66650 ns = current->nsproxy->ipc_ns;
66651
66652 - shm_ops.getnew = newseg;
66653 - shm_ops.associate = shm_security;
66654 - shm_ops.more_checks = shm_more_checks;
66655 -
66656 shm_params.key = key;
66657 shm_params.flg = shmflg;
66658 shm_params.u.size = size;
66659 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66660 f_mode = FMODE_READ | FMODE_WRITE;
66661 }
66662 if (shmflg & SHM_EXEC) {
66663 +
66664 +#ifdef CONFIG_PAX_MPROTECT
66665 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66666 + goto out;
66667 +#endif
66668 +
66669 prot |= PROT_EXEC;
66670 acc_mode |= S_IXUGO;
66671 }
66672 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66673 if (err)
66674 goto out_unlock;
66675
66676 +#ifdef CONFIG_GRKERNSEC
66677 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66678 + shp->shm_perm.cuid, shmid) ||
66679 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66680 + err = -EACCES;
66681 + goto out_unlock;
66682 + }
66683 +#endif
66684 +
66685 path = shp->shm_file->f_path;
66686 path_get(&path);
66687 shp->shm_nattch++;
66688 +#ifdef CONFIG_GRKERNSEC
66689 + shp->shm_lapid = current->pid;
66690 +#endif
66691 size = i_size_read(path.dentry->d_inode);
66692 shm_unlock(shp);
66693
66694 diff --git a/kernel/acct.c b/kernel/acct.c
66695 index 02e6167..54824f7 100644
66696 --- a/kernel/acct.c
66697 +++ b/kernel/acct.c
66698 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66699 */
66700 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66701 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66702 - file->f_op->write(file, (char *)&ac,
66703 + file->f_op->write(file, (char __force_user *)&ac,
66704 sizeof(acct_t), &file->f_pos);
66705 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66706 set_fs(fs);
66707 diff --git a/kernel/audit.c b/kernel/audit.c
66708 index a8c84be..8bd034c 100644
66709 --- a/kernel/audit.c
66710 +++ b/kernel/audit.c
66711 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66712 3) suppressed due to audit_rate_limit
66713 4) suppressed due to audit_backlog_limit
66714 */
66715 -static atomic_t audit_lost = ATOMIC_INIT(0);
66716 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66717
66718 /* The netlink socket. */
66719 static struct sock *audit_sock;
66720 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66721 unsigned long now;
66722 int print;
66723
66724 - atomic_inc(&audit_lost);
66725 + atomic_inc_unchecked(&audit_lost);
66726
66727 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66728
66729 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66730 printk(KERN_WARNING
66731 "audit: audit_lost=%d audit_rate_limit=%d "
66732 "audit_backlog_limit=%d\n",
66733 - atomic_read(&audit_lost),
66734 + atomic_read_unchecked(&audit_lost),
66735 audit_rate_limit,
66736 audit_backlog_limit);
66737 audit_panic(message);
66738 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66739 status_set.pid = audit_pid;
66740 status_set.rate_limit = audit_rate_limit;
66741 status_set.backlog_limit = audit_backlog_limit;
66742 - status_set.lost = atomic_read(&audit_lost);
66743 + status_set.lost = atomic_read_unchecked(&audit_lost);
66744 status_set.backlog = skb_queue_len(&audit_skb_queue);
66745 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66746 &status_set, sizeof(status_set));
66747 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66748 index 4b96415..d8c16ee 100644
66749 --- a/kernel/auditsc.c
66750 +++ b/kernel/auditsc.c
66751 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66752 }
66753
66754 /* global counter which is incremented every time something logs in */
66755 -static atomic_t session_id = ATOMIC_INIT(0);
66756 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66757
66758 /**
66759 * audit_set_loginuid - set current task's audit_context loginuid
66760 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66761 return -EPERM;
66762 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66763
66764 - sessionid = atomic_inc_return(&session_id);
66765 + sessionid = atomic_inc_return_unchecked(&session_id);
66766 if (context && context->in_syscall) {
66767 struct audit_buffer *ab;
66768
66769 diff --git a/kernel/capability.c b/kernel/capability.c
66770 index 493d972..ea17248 100644
66771 --- a/kernel/capability.c
66772 +++ b/kernel/capability.c
66773 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66774 * before modification is attempted and the application
66775 * fails.
66776 */
66777 + if (tocopy > ARRAY_SIZE(kdata))
66778 + return -EFAULT;
66779 +
66780 if (copy_to_user(dataptr, kdata, tocopy
66781 * sizeof(struct __user_cap_data_struct))) {
66782 return -EFAULT;
66783 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66784 int ret;
66785
66786 rcu_read_lock();
66787 - ret = security_capable(__task_cred(t), ns, cap);
66788 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66789 + gr_task_is_capable(t, __task_cred(t), cap);
66790 rcu_read_unlock();
66791
66792 - return (ret == 0);
66793 + return ret;
66794 }
66795
66796 /**
66797 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66798 int ret;
66799
66800 rcu_read_lock();
66801 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66802 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66803 rcu_read_unlock();
66804
66805 - return (ret == 0);
66806 + return ret;
66807 }
66808
66809 /**
66810 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66811 BUG();
66812 }
66813
66814 - if (security_capable(current_cred(), ns, cap) == 0) {
66815 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66816 current->flags |= PF_SUPERPRIV;
66817 return true;
66818 }
66819 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66820 }
66821 EXPORT_SYMBOL(ns_capable);
66822
66823 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66824 +{
66825 + if (unlikely(!cap_valid(cap))) {
66826 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66827 + BUG();
66828 + }
66829 +
66830 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66831 + current->flags |= PF_SUPERPRIV;
66832 + return true;
66833 + }
66834 + return false;
66835 +}
66836 +EXPORT_SYMBOL(ns_capable_nolog);
66837 +
66838 /**
66839 * capable - Determine if the current task has a superior capability in effect
66840 * @cap: The capability to be tested for
66841 @@ -408,6 +427,12 @@ bool capable(int cap)
66842 }
66843 EXPORT_SYMBOL(capable);
66844
66845 +bool capable_nolog(int cap)
66846 +{
66847 + return ns_capable_nolog(&init_user_ns, cap);
66848 +}
66849 +EXPORT_SYMBOL(capable_nolog);
66850 +
66851 /**
66852 * nsown_capable - Check superior capability to one's own user_ns
66853 * @cap: The capability in question
66854 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66855
66856 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66857 }
66858 +
66859 +bool inode_capable_nolog(const struct inode *inode, int cap)
66860 +{
66861 + struct user_namespace *ns = current_user_ns();
66862 +
66863 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66864 +}
66865 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66866 index ff2bce5..a41e8f9 100644
66867 --- a/kernel/cgroup.c
66868 +++ b/kernel/cgroup.c
66869 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66870 struct css_set *cg = link->cg;
66871 struct task_struct *task;
66872 int count = 0;
66873 - seq_printf(seq, "css_set %p\n", cg);
66874 + seq_printf(seq, "css_set %pK\n", cg);
66875 list_for_each_entry(task, &cg->tasks, cg_list) {
66876 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66877 seq_puts(seq, " ...\n");
66878 diff --git a/kernel/compat.c b/kernel/compat.c
66879 index c28a306..b4d0cf3 100644
66880 --- a/kernel/compat.c
66881 +++ b/kernel/compat.c
66882 @@ -13,6 +13,7 @@
66883
66884 #include <linux/linkage.h>
66885 #include <linux/compat.h>
66886 +#include <linux/module.h>
66887 #include <linux/errno.h>
66888 #include <linux/time.h>
66889 #include <linux/signal.h>
66890 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66891 mm_segment_t oldfs;
66892 long ret;
66893
66894 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66895 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66896 oldfs = get_fs();
66897 set_fs(KERNEL_DS);
66898 ret = hrtimer_nanosleep_restart(restart);
66899 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66900 oldfs = get_fs();
66901 set_fs(KERNEL_DS);
66902 ret = hrtimer_nanosleep(&tu,
66903 - rmtp ? (struct timespec __user *)&rmt : NULL,
66904 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66905 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66906 set_fs(oldfs);
66907
66908 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66909 mm_segment_t old_fs = get_fs();
66910
66911 set_fs(KERNEL_DS);
66912 - ret = sys_sigpending((old_sigset_t __user *) &s);
66913 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66914 set_fs(old_fs);
66915 if (ret == 0)
66916 ret = put_user(s, set);
66917 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66918 mm_segment_t old_fs = get_fs();
66919
66920 set_fs(KERNEL_DS);
66921 - ret = sys_old_getrlimit(resource, &r);
66922 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66923 set_fs(old_fs);
66924
66925 if (!ret) {
66926 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66927 mm_segment_t old_fs = get_fs();
66928
66929 set_fs(KERNEL_DS);
66930 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66931 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66932 set_fs(old_fs);
66933
66934 if (ret)
66935 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66936 set_fs (KERNEL_DS);
66937 ret = sys_wait4(pid,
66938 (stat_addr ?
66939 - (unsigned int __user *) &status : NULL),
66940 - options, (struct rusage __user *) &r);
66941 + (unsigned int __force_user *) &status : NULL),
66942 + options, (struct rusage __force_user *) &r);
66943 set_fs (old_fs);
66944
66945 if (ret > 0) {
66946 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66947 memset(&info, 0, sizeof(info));
66948
66949 set_fs(KERNEL_DS);
66950 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66951 - uru ? (struct rusage __user *)&ru : NULL);
66952 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66953 + uru ? (struct rusage __force_user *)&ru : NULL);
66954 set_fs(old_fs);
66955
66956 if ((ret < 0) || (info.si_signo == 0))
66957 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66958 oldfs = get_fs();
66959 set_fs(KERNEL_DS);
66960 err = sys_timer_settime(timer_id, flags,
66961 - (struct itimerspec __user *) &newts,
66962 - (struct itimerspec __user *) &oldts);
66963 + (struct itimerspec __force_user *) &newts,
66964 + (struct itimerspec __force_user *) &oldts);
66965 set_fs(oldfs);
66966 if (!err && old && put_compat_itimerspec(old, &oldts))
66967 return -EFAULT;
66968 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66969 oldfs = get_fs();
66970 set_fs(KERNEL_DS);
66971 err = sys_timer_gettime(timer_id,
66972 - (struct itimerspec __user *) &ts);
66973 + (struct itimerspec __force_user *) &ts);
66974 set_fs(oldfs);
66975 if (!err && put_compat_itimerspec(setting, &ts))
66976 return -EFAULT;
66977 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66978 oldfs = get_fs();
66979 set_fs(KERNEL_DS);
66980 err = sys_clock_settime(which_clock,
66981 - (struct timespec __user *) &ts);
66982 + (struct timespec __force_user *) &ts);
66983 set_fs(oldfs);
66984 return err;
66985 }
66986 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66987 oldfs = get_fs();
66988 set_fs(KERNEL_DS);
66989 err = sys_clock_gettime(which_clock,
66990 - (struct timespec __user *) &ts);
66991 + (struct timespec __force_user *) &ts);
66992 set_fs(oldfs);
66993 if (!err && put_compat_timespec(&ts, tp))
66994 return -EFAULT;
66995 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66996
66997 oldfs = get_fs();
66998 set_fs(KERNEL_DS);
66999 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67000 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67001 set_fs(oldfs);
67002
67003 err = compat_put_timex(utp, &txc);
67004 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67005 oldfs = get_fs();
67006 set_fs(KERNEL_DS);
67007 err = sys_clock_getres(which_clock,
67008 - (struct timespec __user *) &ts);
67009 + (struct timespec __force_user *) &ts);
67010 set_fs(oldfs);
67011 if (!err && tp && put_compat_timespec(&ts, tp))
67012 return -EFAULT;
67013 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67014 long err;
67015 mm_segment_t oldfs;
67016 struct timespec tu;
67017 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67018 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67019
67020 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67021 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67022 oldfs = get_fs();
67023 set_fs(KERNEL_DS);
67024 err = clock_nanosleep_restart(restart);
67025 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67026 oldfs = get_fs();
67027 set_fs(KERNEL_DS);
67028 err = sys_clock_nanosleep(which_clock, flags,
67029 - (struct timespec __user *) &in,
67030 - (struct timespec __user *) &out);
67031 + (struct timespec __force_user *) &in,
67032 + (struct timespec __force_user *) &out);
67033 set_fs(oldfs);
67034
67035 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67036 diff --git a/kernel/configs.c b/kernel/configs.c
67037 index 42e8fa0..9e7406b 100644
67038 --- a/kernel/configs.c
67039 +++ b/kernel/configs.c
67040 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67041 struct proc_dir_entry *entry;
67042
67043 /* create the current config file */
67044 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67045 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67046 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67047 + &ikconfig_file_ops);
67048 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67049 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67050 + &ikconfig_file_ops);
67051 +#endif
67052 +#else
67053 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67054 &ikconfig_file_ops);
67055 +#endif
67056 +
67057 if (!entry)
67058 return -ENOMEM;
67059
67060 diff --git a/kernel/cred.c b/kernel/cred.c
67061 index de728ac..e3c267c 100644
67062 --- a/kernel/cred.c
67063 +++ b/kernel/cred.c
67064 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67065 validate_creds(cred);
67066 alter_cred_subscribers(cred, -1);
67067 put_cred(cred);
67068 +
67069 +#ifdef CONFIG_GRKERNSEC_SETXID
67070 + cred = (struct cred *) tsk->delayed_cred;
67071 + if (cred != NULL) {
67072 + tsk->delayed_cred = NULL;
67073 + validate_creds(cred);
67074 + alter_cred_subscribers(cred, -1);
67075 + put_cred(cred);
67076 + }
67077 +#endif
67078 }
67079
67080 /**
67081 @@ -469,7 +479,7 @@ error_put:
67082 * Always returns 0 thus allowing this function to be tail-called at the end
67083 * of, say, sys_setgid().
67084 */
67085 -int commit_creds(struct cred *new)
67086 +static int __commit_creds(struct cred *new)
67087 {
67088 struct task_struct *task = current;
67089 const struct cred *old = task->real_cred;
67090 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67091
67092 get_cred(new); /* we will require a ref for the subj creds too */
67093
67094 + gr_set_role_label(task, new->uid, new->gid);
67095 +
67096 /* dumpability changes */
67097 if (!uid_eq(old->euid, new->euid) ||
67098 !gid_eq(old->egid, new->egid) ||
67099 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67100 put_cred(old);
67101 return 0;
67102 }
67103 +#ifdef CONFIG_GRKERNSEC_SETXID
67104 +extern int set_user(struct cred *new);
67105 +
67106 +void gr_delayed_cred_worker(void)
67107 +{
67108 + const struct cred *new = current->delayed_cred;
67109 + struct cred *ncred;
67110 +
67111 + current->delayed_cred = NULL;
67112 +
67113 + if (current_uid() && new != NULL) {
67114 + // from doing get_cred on it when queueing this
67115 + put_cred(new);
67116 + return;
67117 + } else if (new == NULL)
67118 + return;
67119 +
67120 + ncred = prepare_creds();
67121 + if (!ncred)
67122 + goto die;
67123 + // uids
67124 + ncred->uid = new->uid;
67125 + ncred->euid = new->euid;
67126 + ncred->suid = new->suid;
67127 + ncred->fsuid = new->fsuid;
67128 + // gids
67129 + ncred->gid = new->gid;
67130 + ncred->egid = new->egid;
67131 + ncred->sgid = new->sgid;
67132 + ncred->fsgid = new->fsgid;
67133 + // groups
67134 + if (set_groups(ncred, new->group_info) < 0) {
67135 + abort_creds(ncred);
67136 + goto die;
67137 + }
67138 + // caps
67139 + ncred->securebits = new->securebits;
67140 + ncred->cap_inheritable = new->cap_inheritable;
67141 + ncred->cap_permitted = new->cap_permitted;
67142 + ncred->cap_effective = new->cap_effective;
67143 + ncred->cap_bset = new->cap_bset;
67144 +
67145 + if (set_user(ncred)) {
67146 + abort_creds(ncred);
67147 + goto die;
67148 + }
67149 +
67150 + // from doing get_cred on it when queueing this
67151 + put_cred(new);
67152 +
67153 + __commit_creds(ncred);
67154 + return;
67155 +die:
67156 + // from doing get_cred on it when queueing this
67157 + put_cred(new);
67158 + do_group_exit(SIGKILL);
67159 +}
67160 +#endif
67161 +
67162 +int commit_creds(struct cred *new)
67163 +{
67164 +#ifdef CONFIG_GRKERNSEC_SETXID
67165 + int ret;
67166 + int schedule_it = 0;
67167 + struct task_struct *t;
67168 +
67169 + /* we won't get called with tasklist_lock held for writing
67170 + and interrupts disabled as the cred struct in that case is
67171 + init_cred
67172 + */
67173 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67174 + !current_uid() && new->uid) {
67175 + schedule_it = 1;
67176 + }
67177 + ret = __commit_creds(new);
67178 + if (schedule_it) {
67179 + rcu_read_lock();
67180 + read_lock(&tasklist_lock);
67181 + for (t = next_thread(current); t != current;
67182 + t = next_thread(t)) {
67183 + if (t->delayed_cred == NULL) {
67184 + t->delayed_cred = get_cred(new);
67185 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67186 + set_tsk_need_resched(t);
67187 + }
67188 + }
67189 + read_unlock(&tasklist_lock);
67190 + rcu_read_unlock();
67191 + }
67192 + return ret;
67193 +#else
67194 + return __commit_creds(new);
67195 +#endif
67196 +}
67197 +
67198 EXPORT_SYMBOL(commit_creds);
67199
67200 /**
67201 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67202 index 0557f24..1a00d9a 100644
67203 --- a/kernel/debug/debug_core.c
67204 +++ b/kernel/debug/debug_core.c
67205 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67206 */
67207 static atomic_t masters_in_kgdb;
67208 static atomic_t slaves_in_kgdb;
67209 -static atomic_t kgdb_break_tasklet_var;
67210 +static atomic_unchecked_t kgdb_break_tasklet_var;
67211 atomic_t kgdb_setting_breakpoint;
67212
67213 struct task_struct *kgdb_usethread;
67214 @@ -132,7 +132,7 @@ int kgdb_single_step;
67215 static pid_t kgdb_sstep_pid;
67216
67217 /* to keep track of the CPU which is doing the single stepping*/
67218 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67219 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67220
67221 /*
67222 * If you are debugging a problem where roundup (the collection of
67223 @@ -540,7 +540,7 @@ return_normal:
67224 * kernel will only try for the value of sstep_tries before
67225 * giving up and continuing on.
67226 */
67227 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67228 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67229 (kgdb_info[cpu].task &&
67230 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67231 atomic_set(&kgdb_active, -1);
67232 @@ -634,8 +634,8 @@ cpu_master_loop:
67233 }
67234
67235 kgdb_restore:
67236 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67237 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67238 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67239 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67240 if (kgdb_info[sstep_cpu].task)
67241 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67242 else
67243 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67244 static void kgdb_tasklet_bpt(unsigned long ing)
67245 {
67246 kgdb_breakpoint();
67247 - atomic_set(&kgdb_break_tasklet_var, 0);
67248 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67249 }
67250
67251 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67252
67253 void kgdb_schedule_breakpoint(void)
67254 {
67255 - if (atomic_read(&kgdb_break_tasklet_var) ||
67256 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67257 atomic_read(&kgdb_active) != -1 ||
67258 atomic_read(&kgdb_setting_breakpoint))
67259 return;
67260 - atomic_inc(&kgdb_break_tasklet_var);
67261 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67262 tasklet_schedule(&kgdb_tasklet_breakpoint);
67263 }
67264 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67265 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67266 index 31df170..bc98840 100644
67267 --- a/kernel/debug/kdb/kdb_main.c
67268 +++ b/kernel/debug/kdb/kdb_main.c
67269 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67270 list_for_each_entry(mod, kdb_modules, list) {
67271
67272 kdb_printf("%-20s%8u 0x%p ", mod->name,
67273 - mod->core_size, (void *)mod);
67274 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67275 #ifdef CONFIG_MODULE_UNLOAD
67276 kdb_printf("%4ld ", module_refcount(mod));
67277 #endif
67278 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67279 kdb_printf(" (Loading)");
67280 else
67281 kdb_printf(" (Live)");
67282 - kdb_printf(" 0x%p", mod->module_core);
67283 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67284
67285 #ifdef CONFIG_MODULE_UNLOAD
67286 {
67287 diff --git a/kernel/events/core.c b/kernel/events/core.c
67288 index 7fee567..8affa2c 100644
67289 --- a/kernel/events/core.c
67290 +++ b/kernel/events/core.c
67291 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67292 return 0;
67293 }
67294
67295 -static atomic64_t perf_event_id;
67296 +static atomic64_unchecked_t perf_event_id;
67297
67298 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67299 enum event_type_t event_type);
67300 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67301
67302 static inline u64 perf_event_count(struct perf_event *event)
67303 {
67304 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67305 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67306 }
67307
67308 static u64 perf_event_read(struct perf_event *event)
67309 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67310 mutex_lock(&event->child_mutex);
67311 total += perf_event_read(event);
67312 *enabled += event->total_time_enabled +
67313 - atomic64_read(&event->child_total_time_enabled);
67314 + atomic64_read_unchecked(&event->child_total_time_enabled);
67315 *running += event->total_time_running +
67316 - atomic64_read(&event->child_total_time_running);
67317 + atomic64_read_unchecked(&event->child_total_time_running);
67318
67319 list_for_each_entry(child, &event->child_list, child_list) {
67320 total += perf_event_read(child);
67321 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67322 userpg->offset -= local64_read(&event->hw.prev_count);
67323
67324 userpg->time_enabled = enabled +
67325 - atomic64_read(&event->child_total_time_enabled);
67326 + atomic64_read_unchecked(&event->child_total_time_enabled);
67327
67328 userpg->time_running = running +
67329 - atomic64_read(&event->child_total_time_running);
67330 + atomic64_read_unchecked(&event->child_total_time_running);
67331
67332 arch_perf_update_userpage(userpg, now);
67333
67334 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67335 values[n++] = perf_event_count(event);
67336 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67337 values[n++] = enabled +
67338 - atomic64_read(&event->child_total_time_enabled);
67339 + atomic64_read_unchecked(&event->child_total_time_enabled);
67340 }
67341 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67342 values[n++] = running +
67343 - atomic64_read(&event->child_total_time_running);
67344 + atomic64_read_unchecked(&event->child_total_time_running);
67345 }
67346 if (read_format & PERF_FORMAT_ID)
67347 values[n++] = primary_event_id(event);
67348 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67349 * need to add enough zero bytes after the string to handle
67350 * the 64bit alignment we do later.
67351 */
67352 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67353 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67354 if (!buf) {
67355 name = strncpy(tmp, "//enomem", sizeof(tmp));
67356 goto got_name;
67357 }
67358 - name = d_path(&file->f_path, buf, PATH_MAX);
67359 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67360 if (IS_ERR(name)) {
67361 name = strncpy(tmp, "//toolong", sizeof(tmp));
67362 goto got_name;
67363 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67364 event->parent = parent_event;
67365
67366 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67367 - event->id = atomic64_inc_return(&perf_event_id);
67368 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67369
67370 event->state = PERF_EVENT_STATE_INACTIVE;
67371
67372 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67373 /*
67374 * Add back the child's count to the parent's count:
67375 */
67376 - atomic64_add(child_val, &parent_event->child_count);
67377 - atomic64_add(child_event->total_time_enabled,
67378 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67379 + atomic64_add_unchecked(child_event->total_time_enabled,
67380 &parent_event->child_total_time_enabled);
67381 - atomic64_add(child_event->total_time_running,
67382 + atomic64_add_unchecked(child_event->total_time_running,
67383 &parent_event->child_total_time_running);
67384
67385 /*
67386 diff --git a/kernel/exit.c b/kernel/exit.c
67387 index f65345f9..9c28dab 100644
67388 --- a/kernel/exit.c
67389 +++ b/kernel/exit.c
67390 @@ -59,6 +59,10 @@
67391 #include <asm/pgtable.h>
67392 #include <asm/mmu_context.h>
67393
67394 +#ifdef CONFIG_GRKERNSEC
67395 +extern rwlock_t grsec_exec_file_lock;
67396 +#endif
67397 +
67398 static void exit_mm(struct task_struct * tsk);
67399
67400 static void __unhash_process(struct task_struct *p, bool group_dead)
67401 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67402 struct task_struct *leader;
67403 int zap_leader;
67404 repeat:
67405 +#ifdef CONFIG_NET
67406 + gr_del_task_from_ip_table(p);
67407 +#endif
67408 +
67409 /* don't need to get the RCU readlock here - the process is dead and
67410 * can't be modifying its own credentials. But shut RCU-lockdep up */
67411 rcu_read_lock();
67412 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67413 * know it'll be handled, so that they don't get converted to
67414 * SIGKILL or just silently dropped.
67415 */
67416 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67417 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67418 recalc_sigpending();
67419 spin_unlock_irq(&current->sighand->siglock);
67420 return 0;
67421 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67422 vsnprintf(current->comm, sizeof(current->comm), name, args);
67423 va_end(args);
67424
67425 +#ifdef CONFIG_GRKERNSEC
67426 + write_lock(&grsec_exec_file_lock);
67427 + if (current->exec_file) {
67428 + fput(current->exec_file);
67429 + current->exec_file = NULL;
67430 + }
67431 + write_unlock(&grsec_exec_file_lock);
67432 +#endif
67433 +
67434 + gr_set_kernel_label(current);
67435 +
67436 /*
67437 * If we were started as result of loading a module, close all of the
67438 * user space pages. We don't need them, and if we didn't close them
67439 @@ -907,6 +926,8 @@ void do_exit(long code)
67440 struct task_struct *tsk = current;
67441 int group_dead;
67442
67443 + set_fs(USER_DS);
67444 +
67445 profile_task_exit(tsk);
67446
67447 WARN_ON(blk_needs_flush_plug(tsk));
67448 @@ -923,7 +944,6 @@ void do_exit(long code)
67449 * mm_release()->clear_child_tid() from writing to a user-controlled
67450 * kernel address.
67451 */
67452 - set_fs(USER_DS);
67453
67454 ptrace_event(PTRACE_EVENT_EXIT, code);
67455
67456 @@ -982,6 +1002,9 @@ void do_exit(long code)
67457 tsk->exit_code = code;
67458 taskstats_exit(tsk, group_dead);
67459
67460 + gr_acl_handle_psacct(tsk, code);
67461 + gr_acl_handle_exit();
67462 +
67463 exit_mm(tsk);
67464
67465 if (group_dead)
67466 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67467 * Take down every thread in the group. This is called by fatal signals
67468 * as well as by sys_exit_group (below).
67469 */
67470 -void
67471 +__noreturn void
67472 do_group_exit(int exit_code)
67473 {
67474 struct signal_struct *sig = current->signal;
67475 diff --git a/kernel/fork.c b/kernel/fork.c
67476 index 2c8857e..288c9c7 100644
67477 --- a/kernel/fork.c
67478 +++ b/kernel/fork.c
67479 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67480 *stackend = STACK_END_MAGIC; /* for overflow detection */
67481
67482 #ifdef CONFIG_CC_STACKPROTECTOR
67483 - tsk->stack_canary = get_random_int();
67484 + tsk->stack_canary = pax_get_random_long();
67485 #endif
67486
67487 /*
67488 @@ -343,13 +343,78 @@ free_tsk:
67489 }
67490
67491 #ifdef CONFIG_MMU
67492 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67493 +{
67494 + struct vm_area_struct *tmp;
67495 + unsigned long charge;
67496 + struct mempolicy *pol;
67497 + struct file *file;
67498 +
67499 + charge = 0;
67500 + if (mpnt->vm_flags & VM_ACCOUNT) {
67501 + unsigned long len = vma_pages(mpnt);
67502 +
67503 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67504 + goto fail_nomem;
67505 + charge = len;
67506 + }
67507 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67508 + if (!tmp)
67509 + goto fail_nomem;
67510 + *tmp = *mpnt;
67511 + tmp->vm_mm = mm;
67512 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67513 + pol = mpol_dup(vma_policy(mpnt));
67514 + if (IS_ERR(pol))
67515 + goto fail_nomem_policy;
67516 + vma_set_policy(tmp, pol);
67517 + if (anon_vma_fork(tmp, mpnt))
67518 + goto fail_nomem_anon_vma_fork;
67519 + tmp->vm_flags &= ~VM_LOCKED;
67520 + tmp->vm_next = tmp->vm_prev = NULL;
67521 + tmp->vm_mirror = NULL;
67522 + file = tmp->vm_file;
67523 + if (file) {
67524 + struct inode *inode = file->f_path.dentry->d_inode;
67525 + struct address_space *mapping = file->f_mapping;
67526 +
67527 + get_file(file);
67528 + if (tmp->vm_flags & VM_DENYWRITE)
67529 + atomic_dec(&inode->i_writecount);
67530 + mutex_lock(&mapping->i_mmap_mutex);
67531 + if (tmp->vm_flags & VM_SHARED)
67532 + mapping->i_mmap_writable++;
67533 + flush_dcache_mmap_lock(mapping);
67534 + /* insert tmp into the share list, just after mpnt */
67535 + vma_prio_tree_add(tmp, mpnt);
67536 + flush_dcache_mmap_unlock(mapping);
67537 + mutex_unlock(&mapping->i_mmap_mutex);
67538 + }
67539 +
67540 + /*
67541 + * Clear hugetlb-related page reserves for children. This only
67542 + * affects MAP_PRIVATE mappings. Faults generated by the child
67543 + * are not guaranteed to succeed, even if read-only
67544 + */
67545 + if (is_vm_hugetlb_page(tmp))
67546 + reset_vma_resv_huge_pages(tmp);
67547 +
67548 + return tmp;
67549 +
67550 +fail_nomem_anon_vma_fork:
67551 + mpol_put(pol);
67552 +fail_nomem_policy:
67553 + kmem_cache_free(vm_area_cachep, tmp);
67554 +fail_nomem:
67555 + vm_unacct_memory(charge);
67556 + return NULL;
67557 +}
67558 +
67559 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67560 {
67561 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67562 struct rb_node **rb_link, *rb_parent;
67563 int retval;
67564 - unsigned long charge;
67565 - struct mempolicy *pol;
67566
67567 down_write(&oldmm->mmap_sem);
67568 flush_cache_dup_mm(oldmm);
67569 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67570 mm->locked_vm = 0;
67571 mm->mmap = NULL;
67572 mm->mmap_cache = NULL;
67573 - mm->free_area_cache = oldmm->mmap_base;
67574 - mm->cached_hole_size = ~0UL;
67575 + mm->free_area_cache = oldmm->free_area_cache;
67576 + mm->cached_hole_size = oldmm->cached_hole_size;
67577 mm->map_count = 0;
67578 cpumask_clear(mm_cpumask(mm));
67579 mm->mm_rb = RB_ROOT;
67580 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67581
67582 prev = NULL;
67583 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67584 - struct file *file;
67585 -
67586 if (mpnt->vm_flags & VM_DONTCOPY) {
67587 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67588 -vma_pages(mpnt));
67589 continue;
67590 }
67591 - charge = 0;
67592 - if (mpnt->vm_flags & VM_ACCOUNT) {
67593 - unsigned long len = vma_pages(mpnt);
67594 -
67595 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67596 - goto fail_nomem;
67597 - charge = len;
67598 - }
67599 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67600 - if (!tmp)
67601 - goto fail_nomem;
67602 - *tmp = *mpnt;
67603 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67604 - pol = mpol_dup(vma_policy(mpnt));
67605 - retval = PTR_ERR(pol);
67606 - if (IS_ERR(pol))
67607 - goto fail_nomem_policy;
67608 - vma_set_policy(tmp, pol);
67609 - tmp->vm_mm = mm;
67610 - if (anon_vma_fork(tmp, mpnt))
67611 - goto fail_nomem_anon_vma_fork;
67612 - tmp->vm_flags &= ~VM_LOCKED;
67613 - tmp->vm_next = tmp->vm_prev = NULL;
67614 - file = tmp->vm_file;
67615 - if (file) {
67616 - struct inode *inode = file->f_path.dentry->d_inode;
67617 - struct address_space *mapping = file->f_mapping;
67618 -
67619 - get_file(file);
67620 - if (tmp->vm_flags & VM_DENYWRITE)
67621 - atomic_dec(&inode->i_writecount);
67622 - mutex_lock(&mapping->i_mmap_mutex);
67623 - if (tmp->vm_flags & VM_SHARED)
67624 - mapping->i_mmap_writable++;
67625 - flush_dcache_mmap_lock(mapping);
67626 - /* insert tmp into the share list, just after mpnt */
67627 - vma_prio_tree_add(tmp, mpnt);
67628 - flush_dcache_mmap_unlock(mapping);
67629 - mutex_unlock(&mapping->i_mmap_mutex);
67630 + tmp = dup_vma(mm, oldmm, mpnt);
67631 + if (!tmp) {
67632 + retval = -ENOMEM;
67633 + goto out;
67634 }
67635
67636 /*
67637 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67638 if (retval)
67639 goto out;
67640
67641 - if (file)
67642 + if (tmp->vm_file)
67643 uprobe_mmap(tmp);
67644 }
67645 +
67646 +#ifdef CONFIG_PAX_SEGMEXEC
67647 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67648 + struct vm_area_struct *mpnt_m;
67649 +
67650 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67651 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67652 +
67653 + if (!mpnt->vm_mirror)
67654 + continue;
67655 +
67656 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67657 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67658 + mpnt->vm_mirror = mpnt_m;
67659 + } else {
67660 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67661 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67662 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67663 + mpnt->vm_mirror->vm_mirror = mpnt;
67664 + }
67665 + }
67666 + BUG_ON(mpnt_m);
67667 + }
67668 +#endif
67669 +
67670 /* a new mm has just been created */
67671 arch_dup_mmap(oldmm, mm);
67672 retval = 0;
67673 @@ -466,14 +519,6 @@ out:
67674 flush_tlb_mm(oldmm);
67675 up_write(&oldmm->mmap_sem);
67676 return retval;
67677 -fail_nomem_anon_vma_fork:
67678 - mpol_put(pol);
67679 -fail_nomem_policy:
67680 - kmem_cache_free(vm_area_cachep, tmp);
67681 -fail_nomem:
67682 - retval = -ENOMEM;
67683 - vm_unacct_memory(charge);
67684 - goto out;
67685 }
67686
67687 static inline int mm_alloc_pgd(struct mm_struct *mm)
67688 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67689 return ERR_PTR(err);
67690
67691 mm = get_task_mm(task);
67692 - if (mm && mm != current->mm &&
67693 - !ptrace_may_access(task, mode)) {
67694 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67695 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67696 mmput(mm);
67697 mm = ERR_PTR(-EACCES);
67698 }
67699 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67700 spin_unlock(&fs->lock);
67701 return -EAGAIN;
67702 }
67703 - fs->users++;
67704 + atomic_inc(&fs->users);
67705 spin_unlock(&fs->lock);
67706 return 0;
67707 }
67708 tsk->fs = copy_fs_struct(fs);
67709 if (!tsk->fs)
67710 return -ENOMEM;
67711 + /* Carry through gr_chroot_dentry and is_chrooted instead
67712 + of recomputing it here. Already copied when the task struct
67713 + is duplicated. This allows pivot_root to not be treated as
67714 + a chroot
67715 + */
67716 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67717 +
67718 return 0;
67719 }
67720
67721 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67722 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67723 #endif
67724 retval = -EAGAIN;
67725 +
67726 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67727 +
67728 if (atomic_read(&p->real_cred->user->processes) >=
67729 task_rlimit(p, RLIMIT_NPROC)) {
67730 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67731 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67732 /* Need tasklist lock for parent etc handling! */
67733 write_lock_irq(&tasklist_lock);
67734
67735 + /* synchronizes with gr_set_acls() */
67736 + gr_copy_label(p);
67737 +
67738 /* CLONE_PARENT re-uses the old parent */
67739 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67740 p->real_parent = current->real_parent;
67741 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67742 bad_fork_free:
67743 free_task(p);
67744 fork_out:
67745 + gr_log_forkfail(retval);
67746 +
67747 return ERR_PTR(retval);
67748 }
67749
67750 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67751 if (clone_flags & CLONE_PARENT_SETTID)
67752 put_user(nr, parent_tidptr);
67753
67754 + gr_handle_brute_check();
67755 +
67756 if (clone_flags & CLONE_VFORK) {
67757 p->vfork_done = &vfork;
67758 init_completion(&vfork);
67759 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67760 return 0;
67761
67762 /* don't need lock here; in the worst case we'll do useless copy */
67763 - if (fs->users == 1)
67764 + if (atomic_read(&fs->users) == 1)
67765 return 0;
67766
67767 *new_fsp = copy_fs_struct(fs);
67768 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67769 fs = current->fs;
67770 spin_lock(&fs->lock);
67771 current->fs = new_fs;
67772 - if (--fs->users)
67773 + gr_set_chroot_entries(current, &current->fs->root);
67774 + if (atomic_dec_return(&fs->users))
67775 new_fs = NULL;
67776 else
67777 new_fs = fs;
67778 diff --git a/kernel/futex.c b/kernel/futex.c
67779 index 20ef219..b3a0cb2 100644
67780 --- a/kernel/futex.c
67781 +++ b/kernel/futex.c
67782 @@ -54,6 +54,7 @@
67783 #include <linux/mount.h>
67784 #include <linux/pagemap.h>
67785 #include <linux/syscalls.h>
67786 +#include <linux/ptrace.h>
67787 #include <linux/signal.h>
67788 #include <linux/export.h>
67789 #include <linux/magic.h>
67790 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67791 struct page *page, *page_head;
67792 int err, ro = 0;
67793
67794 +#ifdef CONFIG_PAX_SEGMEXEC
67795 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67796 + return -EFAULT;
67797 +#endif
67798 +
67799 /*
67800 * The futex address must be "naturally" aligned.
67801 */
67802 @@ -2717,6 +2723,7 @@ static int __init futex_init(void)
67803 {
67804 u32 curval;
67805 int i;
67806 + mm_segment_t oldfs;
67807
67808 /*
67809 * This will fail and we want it. Some arch implementations do
67810 @@ -2728,8 +2735,11 @@ static int __init futex_init(void)
67811 * implementation, the non-functional ones will return
67812 * -ENOSYS.
67813 */
67814 + oldfs = get_fs();
67815 + set_fs(USER_DS);
67816 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67817 futex_cmpxchg_enabled = 1;
67818 + set_fs(oldfs);
67819
67820 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67821 plist_head_init(&futex_queues[i].chain);
67822 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67823 index 9b22d03..6295b62 100644
67824 --- a/kernel/gcov/base.c
67825 +++ b/kernel/gcov/base.c
67826 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67827 }
67828
67829 #ifdef CONFIG_MODULES
67830 -static inline int within(void *addr, void *start, unsigned long size)
67831 -{
67832 - return ((addr >= start) && (addr < start + size));
67833 -}
67834 -
67835 /* Update list and generate events when modules are unloaded. */
67836 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67837 void *data)
67838 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67839 prev = NULL;
67840 /* Remove entries located in module from linked list. */
67841 for (info = gcov_info_head; info; info = info->next) {
67842 - if (within(info, mod->module_core, mod->core_size)) {
67843 + if (within_module_core_rw((unsigned long)info, mod)) {
67844 if (prev)
67845 prev->next = info->next;
67846 else
67847 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67848 index 6db7a5e..25b6648 100644
67849 --- a/kernel/hrtimer.c
67850 +++ b/kernel/hrtimer.c
67851 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67852 local_irq_restore(flags);
67853 }
67854
67855 -static void run_hrtimer_softirq(struct softirq_action *h)
67856 +static void run_hrtimer_softirq(void)
67857 {
67858 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67859
67860 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67861 index 4304919..408c4c0 100644
67862 --- a/kernel/jump_label.c
67863 +++ b/kernel/jump_label.c
67864 @@ -13,6 +13,7 @@
67865 #include <linux/sort.h>
67866 #include <linux/err.h>
67867 #include <linux/static_key.h>
67868 +#include <linux/mm.h>
67869
67870 #ifdef HAVE_JUMP_LABEL
67871
67872 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67873
67874 size = (((unsigned long)stop - (unsigned long)start)
67875 / sizeof(struct jump_entry));
67876 + pax_open_kernel();
67877 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67878 + pax_close_kernel();
67879 }
67880
67881 static void jump_label_update(struct static_key *key, int enable);
67882 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67883 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67884 struct jump_entry *iter;
67885
67886 + pax_open_kernel();
67887 for (iter = iter_start; iter < iter_stop; iter++) {
67888 if (within_module_init(iter->code, mod))
67889 iter->code = 0;
67890 }
67891 + pax_close_kernel();
67892 }
67893
67894 static int
67895 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67896 index 2169fee..45c017a 100644
67897 --- a/kernel/kallsyms.c
67898 +++ b/kernel/kallsyms.c
67899 @@ -11,6 +11,9 @@
67900 * Changed the compression method from stem compression to "table lookup"
67901 * compression (see scripts/kallsyms.c for a more complete description)
67902 */
67903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67904 +#define __INCLUDED_BY_HIDESYM 1
67905 +#endif
67906 #include <linux/kallsyms.h>
67907 #include <linux/module.h>
67908 #include <linux/init.h>
67909 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67910
67911 static inline int is_kernel_inittext(unsigned long addr)
67912 {
67913 + if (system_state != SYSTEM_BOOTING)
67914 + return 0;
67915 +
67916 if (addr >= (unsigned long)_sinittext
67917 && addr <= (unsigned long)_einittext)
67918 return 1;
67919 return 0;
67920 }
67921
67922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67923 +#ifdef CONFIG_MODULES
67924 +static inline int is_module_text(unsigned long addr)
67925 +{
67926 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67927 + return 1;
67928 +
67929 + addr = ktla_ktva(addr);
67930 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67931 +}
67932 +#else
67933 +static inline int is_module_text(unsigned long addr)
67934 +{
67935 + return 0;
67936 +}
67937 +#endif
67938 +#endif
67939 +
67940 static inline int is_kernel_text(unsigned long addr)
67941 {
67942 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67943 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67944
67945 static inline int is_kernel(unsigned long addr)
67946 {
67947 +
67948 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67949 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67950 + return 1;
67951 +
67952 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67953 +#else
67954 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67955 +#endif
67956 +
67957 return 1;
67958 return in_gate_area_no_mm(addr);
67959 }
67960
67961 static int is_ksym_addr(unsigned long addr)
67962 {
67963 +
67964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67965 + if (is_module_text(addr))
67966 + return 0;
67967 +#endif
67968 +
67969 if (all_var)
67970 return is_kernel(addr);
67971
67972 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67973
67974 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67975 {
67976 - iter->name[0] = '\0';
67977 iter->nameoff = get_symbol_offset(new_pos);
67978 iter->pos = new_pos;
67979 }
67980 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67981 {
67982 struct kallsym_iter *iter = m->private;
67983
67984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67985 + if (current_uid())
67986 + return 0;
67987 +#endif
67988 +
67989 /* Some debugging symbols have no name. Ignore them. */
67990 if (!iter->name[0])
67991 return 0;
67992 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67993 */
67994 type = iter->exported ? toupper(iter->type) :
67995 tolower(iter->type);
67996 +
67997 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67998 type, iter->name, iter->module_name);
67999 } else
68000 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68001 struct kallsym_iter *iter;
68002 int ret;
68003
68004 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68005 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68006 if (!iter)
68007 return -ENOMEM;
68008 reset_iter(iter, 0);
68009 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68010 index 30b7b22..c726387 100644
68011 --- a/kernel/kcmp.c
68012 +++ b/kernel/kcmp.c
68013 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68014 struct task_struct *task1, *task2;
68015 int ret;
68016
68017 +#ifdef CONFIG_GRKERNSEC
68018 + return -ENOSYS;
68019 +#endif
68020 +
68021 rcu_read_lock();
68022
68023 /*
68024 diff --git a/kernel/kexec.c b/kernel/kexec.c
68025 index 0668d58..591b6fc 100644
68026 --- a/kernel/kexec.c
68027 +++ b/kernel/kexec.c
68028 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68029 unsigned long flags)
68030 {
68031 struct compat_kexec_segment in;
68032 - struct kexec_segment out, __user *ksegments;
68033 + struct kexec_segment out;
68034 + struct kexec_segment __user *ksegments;
68035 unsigned long i, result;
68036
68037 /* Don't allow clients that don't understand the native
68038 diff --git a/kernel/kmod.c b/kernel/kmod.c
68039 index 6f99aea..eb6e3a0 100644
68040 --- a/kernel/kmod.c
68041 +++ b/kernel/kmod.c
68042 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68043 kfree(info->argv);
68044 }
68045
68046 -static int call_modprobe(char *module_name, int wait)
68047 +static int call_modprobe(char *module_name, char *module_param, int wait)
68048 {
68049 static char *envp[] = {
68050 "HOME=/",
68051 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68052 NULL
68053 };
68054
68055 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68056 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68057 if (!argv)
68058 goto out;
68059
68060 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68061 argv[1] = "-q";
68062 argv[2] = "--";
68063 argv[3] = module_name; /* check free_modprobe_argv() */
68064 - argv[4] = NULL;
68065 + argv[4] = module_param;
68066 + argv[5] = NULL;
68067
68068 return call_usermodehelper_fns(modprobe_path, argv, envp,
68069 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68070 @@ -119,9 +120,8 @@ out:
68071 * If module auto-loading support is disabled then this function
68072 * becomes a no-operation.
68073 */
68074 -int __request_module(bool wait, const char *fmt, ...)
68075 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68076 {
68077 - va_list args;
68078 char module_name[MODULE_NAME_LEN];
68079 unsigned int max_modprobes;
68080 int ret;
68081 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68082 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68083 static int kmod_loop_msg;
68084
68085 - va_start(args, fmt);
68086 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68087 - va_end(args);
68088 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68089 if (ret >= MODULE_NAME_LEN)
68090 return -ENAMETOOLONG;
68091
68092 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68093 if (ret)
68094 return ret;
68095
68096 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68097 + if (!current_uid()) {
68098 + /* hack to workaround consolekit/udisks stupidity */
68099 + read_lock(&tasklist_lock);
68100 + if (!strcmp(current->comm, "mount") &&
68101 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68102 + read_unlock(&tasklist_lock);
68103 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68104 + return -EPERM;
68105 + }
68106 + read_unlock(&tasklist_lock);
68107 + }
68108 +#endif
68109 +
68110 /* If modprobe needs a service that is in a module, we get a recursive
68111 * loop. Limit the number of running kmod threads to max_threads/2 or
68112 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68113 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68114
68115 trace_module_request(module_name, wait, _RET_IP_);
68116
68117 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68118 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68119
68120 atomic_dec(&kmod_concurrent);
68121 return ret;
68122 }
68123 +
68124 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68125 +{
68126 + va_list args;
68127 + int ret;
68128 +
68129 + va_start(args, fmt);
68130 + ret = ____request_module(wait, module_param, fmt, args);
68131 + va_end(args);
68132 +
68133 + return ret;
68134 +}
68135 +
68136 +int __request_module(bool wait, const char *fmt, ...)
68137 +{
68138 + va_list args;
68139 + int ret;
68140 +
68141 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68142 + if (current_uid()) {
68143 + char module_param[MODULE_NAME_LEN];
68144 +
68145 + memset(module_param, 0, sizeof(module_param));
68146 +
68147 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68148 +
68149 + va_start(args, fmt);
68150 + ret = ____request_module(wait, module_param, fmt, args);
68151 + va_end(args);
68152 +
68153 + return ret;
68154 + }
68155 +#endif
68156 +
68157 + va_start(args, fmt);
68158 + ret = ____request_module(wait, NULL, fmt, args);
68159 + va_end(args);
68160 +
68161 + return ret;
68162 +}
68163 +
68164 EXPORT_SYMBOL(__request_module);
68165 #endif /* CONFIG_MODULES */
68166
68167 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68168 *
68169 * Thus the __user pointer cast is valid here.
68170 */
68171 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68172 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68173
68174 /*
68175 * If ret is 0, either ____call_usermodehelper failed and the
68176 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68177 index c62b854..6fc810d 100644
68178 --- a/kernel/kprobes.c
68179 +++ b/kernel/kprobes.c
68180 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68181 * kernel image and loaded module images reside. This is required
68182 * so x86_64 can correctly handle the %rip-relative fixups.
68183 */
68184 - kip->insns = module_alloc(PAGE_SIZE);
68185 + kip->insns = module_alloc_exec(PAGE_SIZE);
68186 if (!kip->insns) {
68187 kfree(kip);
68188 return NULL;
68189 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68190 */
68191 if (!list_is_singular(&kip->list)) {
68192 list_del(&kip->list);
68193 - module_free(NULL, kip->insns);
68194 + module_free_exec(NULL, kip->insns);
68195 kfree(kip);
68196 }
68197 return 1;
68198 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68199 {
68200 int i, err = 0;
68201 unsigned long offset = 0, size = 0;
68202 - char *modname, namebuf[128];
68203 + char *modname, namebuf[KSYM_NAME_LEN];
68204 const char *symbol_name;
68205 void *addr;
68206 struct kprobe_blackpoint *kb;
68207 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68208 kprobe_type = "k";
68209
68210 if (sym)
68211 - seq_printf(pi, "%p %s %s+0x%x %s ",
68212 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68213 p->addr, kprobe_type, sym, offset,
68214 (modname ? modname : " "));
68215 else
68216 - seq_printf(pi, "%p %s %p ",
68217 + seq_printf(pi, "%pK %s %pK ",
68218 p->addr, kprobe_type, p->addr);
68219
68220 if (!pp)
68221 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68222 const char *sym = NULL;
68223 unsigned int i = *(loff_t *) v;
68224 unsigned long offset = 0;
68225 - char *modname, namebuf[128];
68226 + char *modname, namebuf[KSYM_NAME_LEN];
68227
68228 head = &kprobe_table[i];
68229 preempt_disable();
68230 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68231 index 4e316e1..5501eef 100644
68232 --- a/kernel/ksysfs.c
68233 +++ b/kernel/ksysfs.c
68234 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68235 {
68236 if (count+1 > UEVENT_HELPER_PATH_LEN)
68237 return -ENOENT;
68238 + if (!capable(CAP_SYS_ADMIN))
68239 + return -EPERM;
68240 memcpy(uevent_helper, buf, count);
68241 uevent_helper[count] = '\0';
68242 if (count && uevent_helper[count-1] == '\n')
68243 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68244 index ea9ee45..67ebc8f 100644
68245 --- a/kernel/lockdep.c
68246 +++ b/kernel/lockdep.c
68247 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68248 end = (unsigned long) &_end,
68249 addr = (unsigned long) obj;
68250
68251 +#ifdef CONFIG_PAX_KERNEXEC
68252 + start = ktla_ktva(start);
68253 +#endif
68254 +
68255 /*
68256 * static variable?
68257 */
68258 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68259 if (!static_obj(lock->key)) {
68260 debug_locks_off();
68261 printk("INFO: trying to register non-static key.\n");
68262 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68263 printk("the code is fine but needs lockdep annotation.\n");
68264 printk("turning off the locking correctness validator.\n");
68265 dump_stack();
68266 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68267 if (!class)
68268 return 0;
68269 }
68270 - atomic_inc((atomic_t *)&class->ops);
68271 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68272 if (very_verbose(class)) {
68273 printk("\nacquire class [%p] %s", class->key, class->name);
68274 if (class->name_version > 1)
68275 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68276 index 91c32a0..7b88d63 100644
68277 --- a/kernel/lockdep_proc.c
68278 +++ b/kernel/lockdep_proc.c
68279 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68280
68281 static void print_name(struct seq_file *m, struct lock_class *class)
68282 {
68283 - char str[128];
68284 + char str[KSYM_NAME_LEN];
68285 const char *name = class->name;
68286
68287 if (!name) {
68288 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68289 return 0;
68290 }
68291
68292 - seq_printf(m, "%p", class->key);
68293 + seq_printf(m, "%pK", class->key);
68294 #ifdef CONFIG_DEBUG_LOCKDEP
68295 seq_printf(m, " OPS:%8ld", class->ops);
68296 #endif
68297 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68298
68299 list_for_each_entry(entry, &class->locks_after, entry) {
68300 if (entry->distance == 1) {
68301 - seq_printf(m, " -> [%p] ", entry->class->key);
68302 + seq_printf(m, " -> [%pK] ", entry->class->key);
68303 print_name(m, entry->class);
68304 seq_puts(m, "\n");
68305 }
68306 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68307 if (!class->key)
68308 continue;
68309
68310 - seq_printf(m, "[%p] ", class->key);
68311 + seq_printf(m, "[%pK] ", class->key);
68312 print_name(m, class);
68313 seq_puts(m, "\n");
68314 }
68315 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68316 if (!i)
68317 seq_line(m, '-', 40-namelen, namelen);
68318
68319 - snprintf(ip, sizeof(ip), "[<%p>]",
68320 + snprintf(ip, sizeof(ip), "[<%pK>]",
68321 (void *)class->contention_point[i]);
68322 seq_printf(m, "%40s %14lu %29s %pS\n",
68323 name, stats->contention_point[i],
68324 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68325 if (!i)
68326 seq_line(m, '-', 40-namelen, namelen);
68327
68328 - snprintf(ip, sizeof(ip), "[<%p>]",
68329 + snprintf(ip, sizeof(ip), "[<%pK>]",
68330 (void *)class->contending_point[i]);
68331 seq_printf(m, "%40s %14lu %29s %pS\n",
68332 name, stats->contending_point[i],
68333 diff --git a/kernel/module.c b/kernel/module.c
68334 index 9ad9ee9..731c128 100644
68335 --- a/kernel/module.c
68336 +++ b/kernel/module.c
68337 @@ -58,6 +58,7 @@
68338 #include <linux/jump_label.h>
68339 #include <linux/pfn.h>
68340 #include <linux/bsearch.h>
68341 +#include <linux/grsecurity.h>
68342
68343 #define CREATE_TRACE_POINTS
68344 #include <trace/events/module.h>
68345 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68346
68347 /* Bounds of module allocation, for speeding __module_address.
68348 * Protected by module_mutex. */
68349 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68350 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68351 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68352
68353 int register_module_notifier(struct notifier_block * nb)
68354 {
68355 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68356 return true;
68357
68358 list_for_each_entry_rcu(mod, &modules, list) {
68359 - struct symsearch arr[] = {
68360 + struct symsearch modarr[] = {
68361 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68362 NOT_GPL_ONLY, false },
68363 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68364 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68365 #endif
68366 };
68367
68368 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68369 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68370 return true;
68371 }
68372 return false;
68373 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68374 static int percpu_modalloc(struct module *mod,
68375 unsigned long size, unsigned long align)
68376 {
68377 - if (align > PAGE_SIZE) {
68378 + if (align-1 >= PAGE_SIZE) {
68379 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68380 mod->name, align, PAGE_SIZE);
68381 align = PAGE_SIZE;
68382 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68383 static ssize_t show_coresize(struct module_attribute *mattr,
68384 struct module_kobject *mk, char *buffer)
68385 {
68386 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68387 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68388 }
68389
68390 static struct module_attribute modinfo_coresize =
68391 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68392 static ssize_t show_initsize(struct module_attribute *mattr,
68393 struct module_kobject *mk, char *buffer)
68394 {
68395 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68396 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68397 }
68398
68399 static struct module_attribute modinfo_initsize =
68400 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68401 */
68402 #ifdef CONFIG_SYSFS
68403
68404 -#ifdef CONFIG_KALLSYMS
68405 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68406 static inline bool sect_empty(const Elf_Shdr *sect)
68407 {
68408 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68409 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68410
68411 static void unset_module_core_ro_nx(struct module *mod)
68412 {
68413 - set_page_attributes(mod->module_core + mod->core_text_size,
68414 - mod->module_core + mod->core_size,
68415 + set_page_attributes(mod->module_core_rw,
68416 + mod->module_core_rw + mod->core_size_rw,
68417 set_memory_x);
68418 - set_page_attributes(mod->module_core,
68419 - mod->module_core + mod->core_ro_size,
68420 + set_page_attributes(mod->module_core_rx,
68421 + mod->module_core_rx + mod->core_size_rx,
68422 set_memory_rw);
68423 }
68424
68425 static void unset_module_init_ro_nx(struct module *mod)
68426 {
68427 - set_page_attributes(mod->module_init + mod->init_text_size,
68428 - mod->module_init + mod->init_size,
68429 + set_page_attributes(mod->module_init_rw,
68430 + mod->module_init_rw + mod->init_size_rw,
68431 set_memory_x);
68432 - set_page_attributes(mod->module_init,
68433 - mod->module_init + mod->init_ro_size,
68434 + set_page_attributes(mod->module_init_rx,
68435 + mod->module_init_rx + mod->init_size_rx,
68436 set_memory_rw);
68437 }
68438
68439 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68440
68441 mutex_lock(&module_mutex);
68442 list_for_each_entry_rcu(mod, &modules, list) {
68443 - if ((mod->module_core) && (mod->core_text_size)) {
68444 - set_page_attributes(mod->module_core,
68445 - mod->module_core + mod->core_text_size,
68446 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68447 + set_page_attributes(mod->module_core_rx,
68448 + mod->module_core_rx + mod->core_size_rx,
68449 set_memory_rw);
68450 }
68451 - if ((mod->module_init) && (mod->init_text_size)) {
68452 - set_page_attributes(mod->module_init,
68453 - mod->module_init + mod->init_text_size,
68454 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68455 + set_page_attributes(mod->module_init_rx,
68456 + mod->module_init_rx + mod->init_size_rx,
68457 set_memory_rw);
68458 }
68459 }
68460 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68461
68462 mutex_lock(&module_mutex);
68463 list_for_each_entry_rcu(mod, &modules, list) {
68464 - if ((mod->module_core) && (mod->core_text_size)) {
68465 - set_page_attributes(mod->module_core,
68466 - mod->module_core + mod->core_text_size,
68467 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68468 + set_page_attributes(mod->module_core_rx,
68469 + mod->module_core_rx + mod->core_size_rx,
68470 set_memory_ro);
68471 }
68472 - if ((mod->module_init) && (mod->init_text_size)) {
68473 - set_page_attributes(mod->module_init,
68474 - mod->module_init + mod->init_text_size,
68475 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68476 + set_page_attributes(mod->module_init_rx,
68477 + mod->module_init_rx + mod->init_size_rx,
68478 set_memory_ro);
68479 }
68480 }
68481 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68482
68483 /* This may be NULL, but that's OK */
68484 unset_module_init_ro_nx(mod);
68485 - module_free(mod, mod->module_init);
68486 + module_free(mod, mod->module_init_rw);
68487 + module_free_exec(mod, mod->module_init_rx);
68488 kfree(mod->args);
68489 percpu_modfree(mod);
68490
68491 /* Free lock-classes: */
68492 - lockdep_free_key_range(mod->module_core, mod->core_size);
68493 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68494 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68495
68496 /* Finally, free the core (containing the module structure) */
68497 unset_module_core_ro_nx(mod);
68498 - module_free(mod, mod->module_core);
68499 + module_free_exec(mod, mod->module_core_rx);
68500 + module_free(mod, mod->module_core_rw);
68501
68502 #ifdef CONFIG_MPU
68503 update_protections(current->mm);
68504 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68505 int ret = 0;
68506 const struct kernel_symbol *ksym;
68507
68508 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68509 + int is_fs_load = 0;
68510 + int register_filesystem_found = 0;
68511 + char *p;
68512 +
68513 + p = strstr(mod->args, "grsec_modharden_fs");
68514 + if (p) {
68515 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68516 + /* copy \0 as well */
68517 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68518 + is_fs_load = 1;
68519 + }
68520 +#endif
68521 +
68522 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68523 const char *name = info->strtab + sym[i].st_name;
68524
68525 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68526 + /* it's a real shame this will never get ripped and copied
68527 + upstream! ;(
68528 + */
68529 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68530 + register_filesystem_found = 1;
68531 +#endif
68532 +
68533 switch (sym[i].st_shndx) {
68534 case SHN_COMMON:
68535 /* We compiled with -fno-common. These are not
68536 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68537 ksym = resolve_symbol_wait(mod, info, name);
68538 /* Ok if resolved. */
68539 if (ksym && !IS_ERR(ksym)) {
68540 + pax_open_kernel();
68541 sym[i].st_value = ksym->value;
68542 + pax_close_kernel();
68543 break;
68544 }
68545
68546 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68547 secbase = (unsigned long)mod_percpu(mod);
68548 else
68549 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68550 + pax_open_kernel();
68551 sym[i].st_value += secbase;
68552 + pax_close_kernel();
68553 break;
68554 }
68555 }
68556
68557 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68558 + if (is_fs_load && !register_filesystem_found) {
68559 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68560 + ret = -EPERM;
68561 + }
68562 +#endif
68563 +
68564 return ret;
68565 }
68566
68567 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68568 || s->sh_entsize != ~0UL
68569 || strstarts(sname, ".init"))
68570 continue;
68571 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68572 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68573 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68574 + else
68575 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68576 pr_debug("\t%s\n", sname);
68577 }
68578 - switch (m) {
68579 - case 0: /* executable */
68580 - mod->core_size = debug_align(mod->core_size);
68581 - mod->core_text_size = mod->core_size;
68582 - break;
68583 - case 1: /* RO: text and ro-data */
68584 - mod->core_size = debug_align(mod->core_size);
68585 - mod->core_ro_size = mod->core_size;
68586 - break;
68587 - case 3: /* whole core */
68588 - mod->core_size = debug_align(mod->core_size);
68589 - break;
68590 - }
68591 }
68592
68593 pr_debug("Init section allocation order:\n");
68594 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68595 || s->sh_entsize != ~0UL
68596 || !strstarts(sname, ".init"))
68597 continue;
68598 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68599 - | INIT_OFFSET_MASK);
68600 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68601 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68602 + else
68603 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68604 + s->sh_entsize |= INIT_OFFSET_MASK;
68605 pr_debug("\t%s\n", sname);
68606 }
68607 - switch (m) {
68608 - case 0: /* executable */
68609 - mod->init_size = debug_align(mod->init_size);
68610 - mod->init_text_size = mod->init_size;
68611 - break;
68612 - case 1: /* RO: text and ro-data */
68613 - mod->init_size = debug_align(mod->init_size);
68614 - mod->init_ro_size = mod->init_size;
68615 - break;
68616 - case 3: /* whole init */
68617 - mod->init_size = debug_align(mod->init_size);
68618 - break;
68619 - }
68620 }
68621 }
68622
68623 @@ -2266,28 +2284,33 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68624
68625 /* Put symbol section at end of init part of module. */
68626 symsect->sh_flags |= SHF_ALLOC;
68627 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68628 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68629 info->index.sym) | INIT_OFFSET_MASK;
68630 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68631
68632 src = (void *)info->hdr + symsect->sh_offset;
68633 nsrc = symsect->sh_size / sizeof(*src);
68634
68635 + /* strtab always starts with a nul, so offset 0 is the empty string. */
68636 + strtab_size = 1;
68637 +
68638 /* Compute total space required for the core symbols' strtab. */
68639 - for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
68640 - if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
68641 - strtab_size += strlen(&info->strtab[src->st_name]) + 1;
68642 + for (ndst = i = 0; i < nsrc; i++) {
68643 + if (i == 0 ||
68644 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68645 + strtab_size += strlen(&info->strtab[src[i].st_name])+1;
68646 ndst++;
68647 }
68648 + }
68649
68650 /* Append room for core symbols at end of core part. */
68651 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68652 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68653 - mod->core_size += strtab_size;
68654 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68655 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68656 + mod->core_size_rx += strtab_size;
68657
68658 /* Put string table section at end of init part of module. */
68659 strsect->sh_flags |= SHF_ALLOC;
68660 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68661 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68662 info->index.str) | INIT_OFFSET_MASK;
68663 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68664 }
68665 @@ -2305,24 +2328,28 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68666 /* Make sure we get permanent strtab: don't use info->strtab. */
68667 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68668
68669 + pax_open_kernel();
68670 +
68671 /* Set types up while we still have access to sections. */
68672 for (i = 0; i < mod->num_symtab; i++)
68673 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68674
68675 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68676 - mod->core_strtab = s = mod->module_core + info->stroffs;
68677 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68678 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68679 src = mod->symtab;
68680 - *dst = *src;
68681 *s++ = 0;
68682 - for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68683 - if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
68684 - continue;
68685 -
68686 - dst[ndst] = *src;
68687 - dst[ndst++].st_name = s - mod->core_strtab;
68688 - s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68689 + for (ndst = i = 0; i < mod->num_symtab; i++) {
68690 + if (i == 0 ||
68691 + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68692 + dst[ndst] = src[i];
68693 + dst[ndst++].st_name = s - mod->core_strtab;
68694 + s += strlcpy(s, &mod->strtab[src[i].st_name],
68695 + KSYM_NAME_LEN) + 1;
68696 + }
68697 }
68698 mod->core_num_syms = ndst;
68699 +
68700 + pax_close_kernel();
68701 }
68702 #else
68703 static inline void layout_symtab(struct module *mod, struct load_info *info)
68704 @@ -2356,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
68705 return size == 0 ? NULL : vmalloc_exec(size);
68706 }
68707
68708 -static void *module_alloc_update_bounds(unsigned long size)
68709 +static void *module_alloc_update_bounds_rw(unsigned long size)
68710 {
68711 void *ret = module_alloc(size);
68712
68713 if (ret) {
68714 mutex_lock(&module_mutex);
68715 /* Update module bounds. */
68716 - if ((unsigned long)ret < module_addr_min)
68717 - module_addr_min = (unsigned long)ret;
68718 - if ((unsigned long)ret + size > module_addr_max)
68719 - module_addr_max = (unsigned long)ret + size;
68720 + if ((unsigned long)ret < module_addr_min_rw)
68721 + module_addr_min_rw = (unsigned long)ret;
68722 + if ((unsigned long)ret + size > module_addr_max_rw)
68723 + module_addr_max_rw = (unsigned long)ret + size;
68724 + mutex_unlock(&module_mutex);
68725 + }
68726 + return ret;
68727 +}
68728 +
68729 +static void *module_alloc_update_bounds_rx(unsigned long size)
68730 +{
68731 + void *ret = module_alloc_exec(size);
68732 +
68733 + if (ret) {
68734 + mutex_lock(&module_mutex);
68735 + /* Update module bounds. */
68736 + if ((unsigned long)ret < module_addr_min_rx)
68737 + module_addr_min_rx = (unsigned long)ret;
68738 + if ((unsigned long)ret + size > module_addr_max_rx)
68739 + module_addr_max_rx = (unsigned long)ret + size;
68740 mutex_unlock(&module_mutex);
68741 }
68742 return ret;
68743 @@ -2544,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
68744 static int check_modinfo(struct module *mod, struct load_info *info)
68745 {
68746 const char *modmagic = get_modinfo(info, "vermagic");
68747 + const char *license = get_modinfo(info, "license");
68748 int err;
68749
68750 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68751 + if (!license || !license_is_gpl_compatible(license))
68752 + return -ENOEXEC;
68753 +#endif
68754 +
68755 /* This is allowed: modprobe --force will invalidate it. */
68756 if (!modmagic) {
68757 err = try_to_force_load(mod, "bad vermagic");
68758 @@ -2568,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68759 }
68760
68761 /* Set up license info based on the info section */
68762 - set_license(mod, get_modinfo(info, "license"));
68763 + set_license(mod, license);
68764
68765 return 0;
68766 }
68767 @@ -2662,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
68768 void *ptr;
68769
68770 /* Do the allocs. */
68771 - ptr = module_alloc_update_bounds(mod->core_size);
68772 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68773 /*
68774 * The pointer to this block is stored in the module structure
68775 * which is inside the block. Just mark it as not being a
68776 @@ -2672,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
68777 if (!ptr)
68778 return -ENOMEM;
68779
68780 - memset(ptr, 0, mod->core_size);
68781 - mod->module_core = ptr;
68782 + memset(ptr, 0, mod->core_size_rw);
68783 + mod->module_core_rw = ptr;
68784
68785 - ptr = module_alloc_update_bounds(mod->init_size);
68786 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68787 /*
68788 * The pointer to this block is stored in the module structure
68789 * which is inside the block. This block doesn't need to be
68790 * scanned as it contains data and code that will be freed
68791 * after the module is initialized.
68792 */
68793 - kmemleak_ignore(ptr);
68794 - if (!ptr && mod->init_size) {
68795 - module_free(mod, mod->module_core);
68796 + kmemleak_not_leak(ptr);
68797 + if (!ptr && mod->init_size_rw) {
68798 + module_free(mod, mod->module_core_rw);
68799 return -ENOMEM;
68800 }
68801 - memset(ptr, 0, mod->init_size);
68802 - mod->module_init = ptr;
68803 + memset(ptr, 0, mod->init_size_rw);
68804 + mod->module_init_rw = ptr;
68805 +
68806 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68807 + kmemleak_not_leak(ptr);
68808 + if (!ptr) {
68809 + module_free(mod, mod->module_init_rw);
68810 + module_free(mod, mod->module_core_rw);
68811 + return -ENOMEM;
68812 + }
68813 +
68814 + pax_open_kernel();
68815 + memset(ptr, 0, mod->core_size_rx);
68816 + pax_close_kernel();
68817 + mod->module_core_rx = ptr;
68818 +
68819 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68820 + kmemleak_not_leak(ptr);
68821 + if (!ptr && mod->init_size_rx) {
68822 + module_free_exec(mod, mod->module_core_rx);
68823 + module_free(mod, mod->module_init_rw);
68824 + module_free(mod, mod->module_core_rw);
68825 + return -ENOMEM;
68826 + }
68827 +
68828 + pax_open_kernel();
68829 + memset(ptr, 0, mod->init_size_rx);
68830 + pax_close_kernel();
68831 + mod->module_init_rx = ptr;
68832
68833 /* Transfer each section which specifies SHF_ALLOC */
68834 pr_debug("final section addresses:\n");
68835 @@ -2699,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
68836 if (!(shdr->sh_flags & SHF_ALLOC))
68837 continue;
68838
68839 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68840 - dest = mod->module_init
68841 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68842 - else
68843 - dest = mod->module_core + shdr->sh_entsize;
68844 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68845 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68846 + dest = mod->module_init_rw
68847 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68848 + else
68849 + dest = mod->module_init_rx
68850 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68851 + } else {
68852 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68853 + dest = mod->module_core_rw + shdr->sh_entsize;
68854 + else
68855 + dest = mod->module_core_rx + shdr->sh_entsize;
68856 + }
68857 +
68858 + if (shdr->sh_type != SHT_NOBITS) {
68859 +
68860 +#ifdef CONFIG_PAX_KERNEXEC
68861 +#ifdef CONFIG_X86_64
68862 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68863 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68864 +#endif
68865 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68866 + pax_open_kernel();
68867 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68868 + pax_close_kernel();
68869 + } else
68870 +#endif
68871
68872 - if (shdr->sh_type != SHT_NOBITS)
68873 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68874 + }
68875 /* Update sh_addr to point to copy in image. */
68876 - shdr->sh_addr = (unsigned long)dest;
68877 +
68878 +#ifdef CONFIG_PAX_KERNEXEC
68879 + if (shdr->sh_flags & SHF_EXECINSTR)
68880 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68881 + else
68882 +#endif
68883 +
68884 + shdr->sh_addr = (unsigned long)dest;
68885 pr_debug("\t0x%lx %s\n",
68886 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68887 }
68888 @@ -2763,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
68889 * Do it before processing of module parameters, so the module
68890 * can provide parameter accessor functions of its own.
68891 */
68892 - if (mod->module_init)
68893 - flush_icache_range((unsigned long)mod->module_init,
68894 - (unsigned long)mod->module_init
68895 - + mod->init_size);
68896 - flush_icache_range((unsigned long)mod->module_core,
68897 - (unsigned long)mod->module_core + mod->core_size);
68898 + if (mod->module_init_rx)
68899 + flush_icache_range((unsigned long)mod->module_init_rx,
68900 + (unsigned long)mod->module_init_rx
68901 + + mod->init_size_rx);
68902 + flush_icache_range((unsigned long)mod->module_core_rx,
68903 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68904
68905 set_fs(old_fs);
68906 }
68907 @@ -2838,8 +2943,10 @@ out:
68908 static void module_deallocate(struct module *mod, struct load_info *info)
68909 {
68910 percpu_modfree(mod);
68911 - module_free(mod, mod->module_init);
68912 - module_free(mod, mod->module_core);
68913 + module_free_exec(mod, mod->module_init_rx);
68914 + module_free_exec(mod, mod->module_core_rx);
68915 + module_free(mod, mod->module_init_rw);
68916 + module_free(mod, mod->module_core_rw);
68917 }
68918
68919 int __weak module_finalize(const Elf_Ehdr *hdr,
68920 @@ -2852,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68921 static int post_relocation(struct module *mod, const struct load_info *info)
68922 {
68923 /* Sort exception table now relocations are done. */
68924 + pax_open_kernel();
68925 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68926 + pax_close_kernel();
68927
68928 /* Copy relocated percpu area over. */
68929 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68930 @@ -2903,9 +3012,38 @@ static struct module *load_module(void __user *umod,
68931 if (err)
68932 goto free_unload;
68933
68934 + /* Now copy in args */
68935 + mod->args = strndup_user(uargs, ~0UL >> 1);
68936 + if (IS_ERR(mod->args)) {
68937 + err = PTR_ERR(mod->args);
68938 + goto free_unload;
68939 + }
68940 +
68941 /* Set up MODINFO_ATTR fields */
68942 setup_modinfo(mod, &info);
68943
68944 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68945 + {
68946 + char *p, *p2;
68947 +
68948 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68949 + 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);
68950 + err = -EPERM;
68951 + goto free_modinfo;
68952 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68953 + p += sizeof("grsec_modharden_normal") - 1;
68954 + p2 = strstr(p, "_");
68955 + if (p2) {
68956 + *p2 = '\0';
68957 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68958 + *p2 = '_';
68959 + }
68960 + err = -EPERM;
68961 + goto free_modinfo;
68962 + }
68963 + }
68964 +#endif
68965 +
68966 /* Fix up syms, so that st_value is a pointer to location. */
68967 err = simplify_symbols(mod, &info);
68968 if (err < 0)
68969 @@ -2921,13 +3059,6 @@ static struct module *load_module(void __user *umod,
68970
68971 flush_module_icache(mod);
68972
68973 - /* Now copy in args */
68974 - mod->args = strndup_user(uargs, ~0UL >> 1);
68975 - if (IS_ERR(mod->args)) {
68976 - err = PTR_ERR(mod->args);
68977 - goto free_arch_cleanup;
68978 - }
68979 -
68980 /* Mark state as coming so strong_try_module_get() ignores us. */
68981 mod->state = MODULE_STATE_COMING;
68982
68983 @@ -2985,11 +3116,10 @@ static struct module *load_module(void __user *umod,
68984 unlock:
68985 mutex_unlock(&module_mutex);
68986 synchronize_sched();
68987 - kfree(mod->args);
68988 - free_arch_cleanup:
68989 module_arch_cleanup(mod);
68990 free_modinfo:
68991 free_modinfo(mod);
68992 + kfree(mod->args);
68993 free_unload:
68994 module_unload_free(mod);
68995 free_module:
68996 @@ -3030,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68997 MODULE_STATE_COMING, mod);
68998
68999 /* Set RO and NX regions for core */
69000 - set_section_ro_nx(mod->module_core,
69001 - mod->core_text_size,
69002 - mod->core_ro_size,
69003 - mod->core_size);
69004 + set_section_ro_nx(mod->module_core_rx,
69005 + mod->core_size_rx,
69006 + mod->core_size_rx,
69007 + mod->core_size_rx);
69008
69009 /* Set RO and NX regions for init */
69010 - set_section_ro_nx(mod->module_init,
69011 - mod->init_text_size,
69012 - mod->init_ro_size,
69013 - mod->init_size);
69014 + set_section_ro_nx(mod->module_init_rx,
69015 + mod->init_size_rx,
69016 + mod->init_size_rx,
69017 + mod->init_size_rx);
69018
69019 do_mod_ctors(mod);
69020 /* Start the module */
69021 @@ -3085,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69022 mod->strtab = mod->core_strtab;
69023 #endif
69024 unset_module_init_ro_nx(mod);
69025 - module_free(mod, mod->module_init);
69026 - mod->module_init = NULL;
69027 - mod->init_size = 0;
69028 - mod->init_ro_size = 0;
69029 - mod->init_text_size = 0;
69030 + module_free(mod, mod->module_init_rw);
69031 + module_free_exec(mod, mod->module_init_rx);
69032 + mod->module_init_rw = NULL;
69033 + mod->module_init_rx = NULL;
69034 + mod->init_size_rw = 0;
69035 + mod->init_size_rx = 0;
69036 mutex_unlock(&module_mutex);
69037
69038 return 0;
69039 @@ -3120,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69040 unsigned long nextval;
69041
69042 /* At worse, next value is at end of module */
69043 - if (within_module_init(addr, mod))
69044 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69045 + if (within_module_init_rx(addr, mod))
69046 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69047 + else if (within_module_init_rw(addr, mod))
69048 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69049 + else if (within_module_core_rx(addr, mod))
69050 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69051 + else if (within_module_core_rw(addr, mod))
69052 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69053 else
69054 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69055 + return NULL;
69056
69057 /* Scan for closest preceding symbol, and next symbol. (ELF
69058 starts real symbols at 1). */
69059 @@ -3358,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69060 char buf[8];
69061
69062 seq_printf(m, "%s %u",
69063 - mod->name, mod->init_size + mod->core_size);
69064 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69065 print_unload_info(m, mod);
69066
69067 /* Informative for users. */
69068 @@ -3367,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69069 mod->state == MODULE_STATE_COMING ? "Loading":
69070 "Live");
69071 /* Used by oprofile and other similar tools. */
69072 - seq_printf(m, " 0x%pK", mod->module_core);
69073 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69074
69075 /* Taints info */
69076 if (mod->taints)
69077 @@ -3403,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69078
69079 static int __init proc_modules_init(void)
69080 {
69081 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69082 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69083 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69084 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69085 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69086 +#else
69087 proc_create("modules", 0, NULL, &proc_modules_operations);
69088 +#endif
69089 +#else
69090 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69091 +#endif
69092 return 0;
69093 }
69094 module_init(proc_modules_init);
69095 @@ -3462,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69096 {
69097 struct module *mod;
69098
69099 - if (addr < module_addr_min || addr > module_addr_max)
69100 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69101 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69102 return NULL;
69103
69104 list_for_each_entry_rcu(mod, &modules, list)
69105 - if (within_module_core(addr, mod)
69106 - || within_module_init(addr, mod))
69107 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69108 return mod;
69109 return NULL;
69110 }
69111 @@ -3501,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69112 */
69113 struct module *__module_text_address(unsigned long addr)
69114 {
69115 - struct module *mod = __module_address(addr);
69116 + struct module *mod;
69117 +
69118 +#ifdef CONFIG_X86_32
69119 + addr = ktla_ktva(addr);
69120 +#endif
69121 +
69122 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69123 + return NULL;
69124 +
69125 + mod = __module_address(addr);
69126 +
69127 if (mod) {
69128 /* Make sure it's within the text section. */
69129 - if (!within(addr, mod->module_init, mod->init_text_size)
69130 - && !within(addr, mod->module_core, mod->core_text_size))
69131 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69132 mod = NULL;
69133 }
69134 return mod;
69135 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69136 index 7e3443f..b2a1e6b 100644
69137 --- a/kernel/mutex-debug.c
69138 +++ b/kernel/mutex-debug.c
69139 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69140 }
69141
69142 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69143 - struct thread_info *ti)
69144 + struct task_struct *task)
69145 {
69146 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69147
69148 /* Mark the current thread as blocked on the lock: */
69149 - ti->task->blocked_on = waiter;
69150 + task->blocked_on = waiter;
69151 }
69152
69153 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69154 - struct thread_info *ti)
69155 + struct task_struct *task)
69156 {
69157 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69158 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69159 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69160 - ti->task->blocked_on = NULL;
69161 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69162 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69163 + task->blocked_on = NULL;
69164
69165 list_del_init(&waiter->list);
69166 waiter->task = NULL;
69167 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69168 index 0799fd3..d06ae3b 100644
69169 --- a/kernel/mutex-debug.h
69170 +++ b/kernel/mutex-debug.h
69171 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69172 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69173 extern void debug_mutex_add_waiter(struct mutex *lock,
69174 struct mutex_waiter *waiter,
69175 - struct thread_info *ti);
69176 + struct task_struct *task);
69177 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69178 - struct thread_info *ti);
69179 + struct task_struct *task);
69180 extern void debug_mutex_unlock(struct mutex *lock);
69181 extern void debug_mutex_init(struct mutex *lock, const char *name,
69182 struct lock_class_key *key);
69183 diff --git a/kernel/mutex.c b/kernel/mutex.c
69184 index a307cc9..27fd2e9 100644
69185 --- a/kernel/mutex.c
69186 +++ b/kernel/mutex.c
69187 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69188 spin_lock_mutex(&lock->wait_lock, flags);
69189
69190 debug_mutex_lock_common(lock, &waiter);
69191 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69192 + debug_mutex_add_waiter(lock, &waiter, task);
69193
69194 /* add waiting tasks to the end of the waitqueue (FIFO): */
69195 list_add_tail(&waiter.list, &lock->wait_list);
69196 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69197 * TASK_UNINTERRUPTIBLE case.)
69198 */
69199 if (unlikely(signal_pending_state(state, task))) {
69200 - mutex_remove_waiter(lock, &waiter,
69201 - task_thread_info(task));
69202 + mutex_remove_waiter(lock, &waiter, task);
69203 mutex_release(&lock->dep_map, 1, ip);
69204 spin_unlock_mutex(&lock->wait_lock, flags);
69205
69206 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69207 done:
69208 lock_acquired(&lock->dep_map, ip);
69209 /* got the lock - rejoice! */
69210 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69211 + mutex_remove_waiter(lock, &waiter, task);
69212 mutex_set_owner(lock);
69213
69214 /* set it to 0 if there are no waiters left: */
69215 diff --git a/kernel/panic.c b/kernel/panic.c
69216 index e1b2822..5edc1d9 100644
69217 --- a/kernel/panic.c
69218 +++ b/kernel/panic.c
69219 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69220 const char *board;
69221
69222 printk(KERN_WARNING "------------[ cut here ]------------\n");
69223 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69224 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69225 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69226 if (board)
69227 printk(KERN_WARNING "Hardware name: %s\n", board);
69228 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69229 */
69230 void __stack_chk_fail(void)
69231 {
69232 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69233 + dump_stack();
69234 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69235 __builtin_return_address(0));
69236 }
69237 EXPORT_SYMBOL(__stack_chk_fail);
69238 diff --git a/kernel/pid.c b/kernel/pid.c
69239 index e86b291a..e8b0fb5 100644
69240 --- a/kernel/pid.c
69241 +++ b/kernel/pid.c
69242 @@ -33,6 +33,7 @@
69243 #include <linux/rculist.h>
69244 #include <linux/bootmem.h>
69245 #include <linux/hash.h>
69246 +#include <linux/security.h>
69247 #include <linux/pid_namespace.h>
69248 #include <linux/init_task.h>
69249 #include <linux/syscalls.h>
69250 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69251
69252 int pid_max = PID_MAX_DEFAULT;
69253
69254 -#define RESERVED_PIDS 300
69255 +#define RESERVED_PIDS 500
69256
69257 int pid_max_min = RESERVED_PIDS + 1;
69258 int pid_max_max = PID_MAX_LIMIT;
69259 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69260 */
69261 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69262 {
69263 + struct task_struct *task;
69264 +
69265 rcu_lockdep_assert(rcu_read_lock_held(),
69266 "find_task_by_pid_ns() needs rcu_read_lock()"
69267 " protection");
69268 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69269 +
69270 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69271 +
69272 + if (gr_pid_is_chrooted(task))
69273 + return NULL;
69274 +
69275 + return task;
69276 }
69277
69278 struct task_struct *find_task_by_vpid(pid_t vnr)
69279 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69280 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69281 }
69282
69283 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69284 +{
69285 + rcu_lockdep_assert(rcu_read_lock_held(),
69286 + "find_task_by_pid_ns() needs rcu_read_lock()"
69287 + " protection");
69288 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69289 +}
69290 +
69291 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69292 {
69293 struct pid *pid;
69294 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69295 index 125cb67..a4d1c30 100644
69296 --- a/kernel/posix-cpu-timers.c
69297 +++ b/kernel/posix-cpu-timers.c
69298 @@ -6,6 +6,7 @@
69299 #include <linux/posix-timers.h>
69300 #include <linux/errno.h>
69301 #include <linux/math64.h>
69302 +#include <linux/security.h>
69303 #include <asm/uaccess.h>
69304 #include <linux/kernel_stat.h>
69305 #include <trace/events/timer.h>
69306 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69307
69308 static __init int init_posix_cpu_timers(void)
69309 {
69310 - struct k_clock process = {
69311 + static struct k_clock process = {
69312 .clock_getres = process_cpu_clock_getres,
69313 .clock_get = process_cpu_clock_get,
69314 .timer_create = process_cpu_timer_create,
69315 .nsleep = process_cpu_nsleep,
69316 .nsleep_restart = process_cpu_nsleep_restart,
69317 };
69318 - struct k_clock thread = {
69319 + static struct k_clock thread = {
69320 .clock_getres = thread_cpu_clock_getres,
69321 .clock_get = thread_cpu_clock_get,
69322 .timer_create = thread_cpu_timer_create,
69323 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69324 index 69185ae..cc2847a 100644
69325 --- a/kernel/posix-timers.c
69326 +++ b/kernel/posix-timers.c
69327 @@ -43,6 +43,7 @@
69328 #include <linux/idr.h>
69329 #include <linux/posix-clock.h>
69330 #include <linux/posix-timers.h>
69331 +#include <linux/grsecurity.h>
69332 #include <linux/syscalls.h>
69333 #include <linux/wait.h>
69334 #include <linux/workqueue.h>
69335 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69336 * which we beg off on and pass to do_sys_settimeofday().
69337 */
69338
69339 -static struct k_clock posix_clocks[MAX_CLOCKS];
69340 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69341
69342 /*
69343 * These ones are defined below.
69344 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69345 */
69346 static __init int init_posix_timers(void)
69347 {
69348 - struct k_clock clock_realtime = {
69349 + static struct k_clock clock_realtime = {
69350 .clock_getres = hrtimer_get_res,
69351 .clock_get = posix_clock_realtime_get,
69352 .clock_set = posix_clock_realtime_set,
69353 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69354 .timer_get = common_timer_get,
69355 .timer_del = common_timer_del,
69356 };
69357 - struct k_clock clock_monotonic = {
69358 + static struct k_clock clock_monotonic = {
69359 .clock_getres = hrtimer_get_res,
69360 .clock_get = posix_ktime_get_ts,
69361 .nsleep = common_nsleep,
69362 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69363 .timer_get = common_timer_get,
69364 .timer_del = common_timer_del,
69365 };
69366 - struct k_clock clock_monotonic_raw = {
69367 + static struct k_clock clock_monotonic_raw = {
69368 .clock_getres = hrtimer_get_res,
69369 .clock_get = posix_get_monotonic_raw,
69370 };
69371 - struct k_clock clock_realtime_coarse = {
69372 + static struct k_clock clock_realtime_coarse = {
69373 .clock_getres = posix_get_coarse_res,
69374 .clock_get = posix_get_realtime_coarse,
69375 };
69376 - struct k_clock clock_monotonic_coarse = {
69377 + static struct k_clock clock_monotonic_coarse = {
69378 .clock_getres = posix_get_coarse_res,
69379 .clock_get = posix_get_monotonic_coarse,
69380 };
69381 - struct k_clock clock_boottime = {
69382 + static struct k_clock clock_boottime = {
69383 .clock_getres = hrtimer_get_res,
69384 .clock_get = posix_get_boottime,
69385 .nsleep = common_nsleep,
69386 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69387 return;
69388 }
69389
69390 - posix_clocks[clock_id] = *new_clock;
69391 + posix_clocks[clock_id] = new_clock;
69392 }
69393 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69394
69395 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69396 return (id & CLOCKFD_MASK) == CLOCKFD ?
69397 &clock_posix_dynamic : &clock_posix_cpu;
69398
69399 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69400 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69401 return NULL;
69402 - return &posix_clocks[id];
69403 + return posix_clocks[id];
69404 }
69405
69406 static int common_timer_create(struct k_itimer *new_timer)
69407 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69408 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69409 return -EFAULT;
69410
69411 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69412 + have their clock_set fptr set to a nosettime dummy function
69413 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69414 + call common_clock_set, which calls do_sys_settimeofday, which
69415 + we hook
69416 + */
69417 +
69418 return kc->clock_set(which_clock, &new_tp);
69419 }
69420
69421 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69422 index d523593..68197a4 100644
69423 --- a/kernel/power/poweroff.c
69424 +++ b/kernel/power/poweroff.c
69425 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69426 .enable_mask = SYSRQ_ENABLE_BOOT,
69427 };
69428
69429 -static int pm_sysrq_init(void)
69430 +static int __init pm_sysrq_init(void)
69431 {
69432 register_sysrq_key('o', &sysrq_poweroff_op);
69433 return 0;
69434 diff --git a/kernel/power/process.c b/kernel/power/process.c
69435 index 19db29f..33b52b6 100644
69436 --- a/kernel/power/process.c
69437 +++ b/kernel/power/process.c
69438 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69439 u64 elapsed_csecs64;
69440 unsigned int elapsed_csecs;
69441 bool wakeup = false;
69442 + bool timedout = false;
69443
69444 do_gettimeofday(&start);
69445
69446 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69447
69448 while (true) {
69449 todo = 0;
69450 + if (time_after(jiffies, end_time))
69451 + timedout = true;
69452 read_lock(&tasklist_lock);
69453 do_each_thread(g, p) {
69454 if (p == current || !freeze_task(p))
69455 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69456 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69457 * transition can't race with task state testing here.
69458 */
69459 - if (!task_is_stopped_or_traced(p) &&
69460 - !freezer_should_skip(p))
69461 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69462 todo++;
69463 + if (timedout) {
69464 + printk(KERN_ERR "Task refusing to freeze:\n");
69465 + sched_show_task(p);
69466 + }
69467 + }
69468 } while_each_thread(g, p);
69469 read_unlock(&tasklist_lock);
69470
69471 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69472 todo += wq_busy;
69473 }
69474
69475 - if (!todo || time_after(jiffies, end_time))
69476 + if (!todo || timedout)
69477 break;
69478
69479 if (pm_wakeup_pending()) {
69480 diff --git a/kernel/printk.c b/kernel/printk.c
69481 index 66a2ea3..10f3a01 100644
69482 --- a/kernel/printk.c
69483 +++ b/kernel/printk.c
69484 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69485 if (from_file && type != SYSLOG_ACTION_OPEN)
69486 return 0;
69487
69488 +#ifdef CONFIG_GRKERNSEC_DMESG
69489 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69490 + return -EPERM;
69491 +#endif
69492 +
69493 if (syslog_action_restricted(type)) {
69494 if (capable(CAP_SYSLOG))
69495 return 0;
69496 diff --git a/kernel/profile.c b/kernel/profile.c
69497 index 76b8e77..a2930e8 100644
69498 --- a/kernel/profile.c
69499 +++ b/kernel/profile.c
69500 @@ -39,7 +39,7 @@ struct profile_hit {
69501 /* Oprofile timer tick hook */
69502 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69503
69504 -static atomic_t *prof_buffer;
69505 +static atomic_unchecked_t *prof_buffer;
69506 static unsigned long prof_len, prof_shift;
69507
69508 int prof_on __read_mostly;
69509 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69510 hits[i].pc = 0;
69511 continue;
69512 }
69513 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69514 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69515 hits[i].hits = hits[i].pc = 0;
69516 }
69517 }
69518 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69519 * Add the current hit(s) and flush the write-queue out
69520 * to the global buffer:
69521 */
69522 - atomic_add(nr_hits, &prof_buffer[pc]);
69523 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69524 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69525 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69526 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69527 hits[i].pc = hits[i].hits = 0;
69528 }
69529 out:
69530 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69531 {
69532 unsigned long pc;
69533 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69534 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69535 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69536 }
69537 #endif /* !CONFIG_SMP */
69538
69539 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69540 return -EFAULT;
69541 buf++; p++; count--; read++;
69542 }
69543 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69544 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69545 if (copy_to_user(buf, (void *)pnt, count))
69546 return -EFAULT;
69547 read += count;
69548 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69549 }
69550 #endif
69551 profile_discard_flip_buffers();
69552 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69553 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69554 return count;
69555 }
69556
69557 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69558 index a232bb5..2a65ef9 100644
69559 --- a/kernel/ptrace.c
69560 +++ b/kernel/ptrace.c
69561 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69562
69563 if (seize)
69564 flags |= PT_SEIZED;
69565 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69566 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69567 flags |= PT_PTRACE_CAP;
69568 task->ptrace = flags;
69569
69570 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69571 break;
69572 return -EIO;
69573 }
69574 - if (copy_to_user(dst, buf, retval))
69575 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69576 return -EFAULT;
69577 copied += retval;
69578 src += retval;
69579 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69580 bool seized = child->ptrace & PT_SEIZED;
69581 int ret = -EIO;
69582 siginfo_t siginfo, *si;
69583 - void __user *datavp = (void __user *) data;
69584 + void __user *datavp = (__force void __user *) data;
69585 unsigned long __user *datalp = datavp;
69586 unsigned long flags;
69587
69588 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69589 goto out;
69590 }
69591
69592 + if (gr_handle_ptrace(child, request)) {
69593 + ret = -EPERM;
69594 + goto out_put_task_struct;
69595 + }
69596 +
69597 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69598 ret = ptrace_attach(child, request, addr, data);
69599 /*
69600 * Some architectures need to do book-keeping after
69601 * a ptrace attach.
69602 */
69603 - if (!ret)
69604 + if (!ret) {
69605 arch_ptrace_attach(child);
69606 + gr_audit_ptrace(child);
69607 + }
69608 goto out_put_task_struct;
69609 }
69610
69611 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69612 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69613 if (copied != sizeof(tmp))
69614 return -EIO;
69615 - return put_user(tmp, (unsigned long __user *)data);
69616 + return put_user(tmp, (__force unsigned long __user *)data);
69617 }
69618
69619 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69620 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69621 goto out;
69622 }
69623
69624 + if (gr_handle_ptrace(child, request)) {
69625 + ret = -EPERM;
69626 + goto out_put_task_struct;
69627 + }
69628 +
69629 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69630 ret = ptrace_attach(child, request, addr, data);
69631 /*
69632 * Some architectures need to do book-keeping after
69633 * a ptrace attach.
69634 */
69635 - if (!ret)
69636 + if (!ret) {
69637 arch_ptrace_attach(child);
69638 + gr_audit_ptrace(child);
69639 + }
69640 goto out_put_task_struct;
69641 }
69642
69643 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69644 index 547b1fe..65e874e 100644
69645 --- a/kernel/rcutiny.c
69646 +++ b/kernel/rcutiny.c
69647 @@ -46,7 +46,7 @@
69648 struct rcu_ctrlblk;
69649 static void invoke_rcu_callbacks(void);
69650 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69651 -static void rcu_process_callbacks(struct softirq_action *unused);
69652 +static void rcu_process_callbacks(void);
69653 static void __call_rcu(struct rcu_head *head,
69654 void (*func)(struct rcu_head *rcu),
69655 struct rcu_ctrlblk *rcp);
69656 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69657 rcu_is_callbacks_kthread()));
69658 }
69659
69660 -static void rcu_process_callbacks(struct softirq_action *unused)
69661 +static void rcu_process_callbacks(void)
69662 {
69663 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69664 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69665 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69666 index 918fd1e..85089bb 100644
69667 --- a/kernel/rcutiny_plugin.h
69668 +++ b/kernel/rcutiny_plugin.h
69669 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69670 have_rcu_kthread_work = morework;
69671 local_irq_restore(flags);
69672 if (work)
69673 - rcu_process_callbacks(NULL);
69674 + rcu_process_callbacks();
69675 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69676 }
69677
69678 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69679 index 25b1503..1988a74 100644
69680 --- a/kernel/rcutorture.c
69681 +++ b/kernel/rcutorture.c
69682 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69683 { 0 };
69684 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69685 { 0 };
69686 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69687 -static atomic_t n_rcu_torture_alloc;
69688 -static atomic_t n_rcu_torture_alloc_fail;
69689 -static atomic_t n_rcu_torture_free;
69690 -static atomic_t n_rcu_torture_mberror;
69691 -static atomic_t n_rcu_torture_error;
69692 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69693 +static atomic_unchecked_t n_rcu_torture_alloc;
69694 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69695 +static atomic_unchecked_t n_rcu_torture_free;
69696 +static atomic_unchecked_t n_rcu_torture_mberror;
69697 +static atomic_unchecked_t n_rcu_torture_error;
69698 static long n_rcu_torture_barrier_error;
69699 static long n_rcu_torture_boost_ktrerror;
69700 static long n_rcu_torture_boost_rterror;
69701 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69702
69703 spin_lock_bh(&rcu_torture_lock);
69704 if (list_empty(&rcu_torture_freelist)) {
69705 - atomic_inc(&n_rcu_torture_alloc_fail);
69706 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69707 spin_unlock_bh(&rcu_torture_lock);
69708 return NULL;
69709 }
69710 - atomic_inc(&n_rcu_torture_alloc);
69711 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69712 p = rcu_torture_freelist.next;
69713 list_del_init(p);
69714 spin_unlock_bh(&rcu_torture_lock);
69715 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69716 static void
69717 rcu_torture_free(struct rcu_torture *p)
69718 {
69719 - atomic_inc(&n_rcu_torture_free);
69720 + atomic_inc_unchecked(&n_rcu_torture_free);
69721 spin_lock_bh(&rcu_torture_lock);
69722 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69723 spin_unlock_bh(&rcu_torture_lock);
69724 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69725 i = rp->rtort_pipe_count;
69726 if (i > RCU_TORTURE_PIPE_LEN)
69727 i = RCU_TORTURE_PIPE_LEN;
69728 - atomic_inc(&rcu_torture_wcount[i]);
69729 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69730 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69731 rp->rtort_mbtest = 0;
69732 rcu_torture_free(rp);
69733 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69734 i = rp->rtort_pipe_count;
69735 if (i > RCU_TORTURE_PIPE_LEN)
69736 i = RCU_TORTURE_PIPE_LEN;
69737 - atomic_inc(&rcu_torture_wcount[i]);
69738 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69739 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69740 rp->rtort_mbtest = 0;
69741 list_del(&rp->rtort_free);
69742 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69743 i = old_rp->rtort_pipe_count;
69744 if (i > RCU_TORTURE_PIPE_LEN)
69745 i = RCU_TORTURE_PIPE_LEN;
69746 - atomic_inc(&rcu_torture_wcount[i]);
69747 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69748 old_rp->rtort_pipe_count++;
69749 cur_ops->deferred_free(old_rp);
69750 }
69751 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69752 }
69753 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69754 if (p->rtort_mbtest == 0)
69755 - atomic_inc(&n_rcu_torture_mberror);
69756 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69757 spin_lock(&rand_lock);
69758 cur_ops->read_delay(&rand);
69759 n_rcu_torture_timers++;
69760 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69761 }
69762 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69763 if (p->rtort_mbtest == 0)
69764 - atomic_inc(&n_rcu_torture_mberror);
69765 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69766 cur_ops->read_delay(&rand);
69767 preempt_disable();
69768 pipe_count = p->rtort_pipe_count;
69769 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69770 rcu_torture_current,
69771 rcu_torture_current_version,
69772 list_empty(&rcu_torture_freelist),
69773 - atomic_read(&n_rcu_torture_alloc),
69774 - atomic_read(&n_rcu_torture_alloc_fail),
69775 - atomic_read(&n_rcu_torture_free));
69776 + atomic_read_unchecked(&n_rcu_torture_alloc),
69777 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69778 + atomic_read_unchecked(&n_rcu_torture_free));
69779 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69780 - atomic_read(&n_rcu_torture_mberror),
69781 + atomic_read_unchecked(&n_rcu_torture_mberror),
69782 n_rcu_torture_boost_ktrerror,
69783 n_rcu_torture_boost_rterror);
69784 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69785 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69786 n_barrier_attempts,
69787 n_rcu_torture_barrier_error);
69788 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69789 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69790 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69791 n_rcu_torture_barrier_error != 0 ||
69792 n_rcu_torture_boost_ktrerror != 0 ||
69793 n_rcu_torture_boost_rterror != 0 ||
69794 n_rcu_torture_boost_failure != 0 ||
69795 i > 1) {
69796 cnt += sprintf(&page[cnt], "!!! ");
69797 - atomic_inc(&n_rcu_torture_error);
69798 + atomic_inc_unchecked(&n_rcu_torture_error);
69799 WARN_ON_ONCE(1);
69800 }
69801 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69802 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69803 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69804 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69805 cnt += sprintf(&page[cnt], " %d",
69806 - atomic_read(&rcu_torture_wcount[i]));
69807 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69808 }
69809 cnt += sprintf(&page[cnt], "\n");
69810 if (cur_ops->stats)
69811 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69812
69813 if (cur_ops->cleanup)
69814 cur_ops->cleanup();
69815 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69816 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69817 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69818 else if (n_online_successes != n_online_attempts ||
69819 n_offline_successes != n_offline_attempts)
69820 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69821
69822 rcu_torture_current = NULL;
69823 rcu_torture_current_version = 0;
69824 - atomic_set(&n_rcu_torture_alloc, 0);
69825 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69826 - atomic_set(&n_rcu_torture_free, 0);
69827 - atomic_set(&n_rcu_torture_mberror, 0);
69828 - atomic_set(&n_rcu_torture_error, 0);
69829 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69830 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69831 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69832 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69833 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69834 n_rcu_torture_barrier_error = 0;
69835 n_rcu_torture_boost_ktrerror = 0;
69836 n_rcu_torture_boost_rterror = 0;
69837 n_rcu_torture_boost_failure = 0;
69838 n_rcu_torture_boosts = 0;
69839 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69840 - atomic_set(&rcu_torture_wcount[i], 0);
69841 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69842 for_each_possible_cpu(cpu) {
69843 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69844 per_cpu(rcu_torture_count, cpu)[i] = 0;
69845 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69846 index f7bcd9e..8973e14 100644
69847 --- a/kernel/rcutree.c
69848 +++ b/kernel/rcutree.c
69849 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69850 rcu_prepare_for_idle(smp_processor_id());
69851 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69852 smp_mb__before_atomic_inc(); /* See above. */
69853 - atomic_inc(&rdtp->dynticks);
69854 + atomic_inc_unchecked(&rdtp->dynticks);
69855 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69856 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69857 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69858
69859 /*
69860 * The idle task is not permitted to enter the idle loop while
69861 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69862 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69863 {
69864 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69865 - atomic_inc(&rdtp->dynticks);
69866 + atomic_inc_unchecked(&rdtp->dynticks);
69867 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69868 smp_mb__after_atomic_inc(); /* See above. */
69869 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69870 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69871 rcu_cleanup_after_idle(smp_processor_id());
69872 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69873 if (!is_idle_task(current)) {
69874 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69875 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69876
69877 if (rdtp->dynticks_nmi_nesting == 0 &&
69878 - (atomic_read(&rdtp->dynticks) & 0x1))
69879 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69880 return;
69881 rdtp->dynticks_nmi_nesting++;
69882 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69883 - atomic_inc(&rdtp->dynticks);
69884 + atomic_inc_unchecked(&rdtp->dynticks);
69885 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69886 smp_mb__after_atomic_inc(); /* See above. */
69887 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69888 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69889 }
69890
69891 /**
69892 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69893 return;
69894 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69895 smp_mb__before_atomic_inc(); /* See above. */
69896 - atomic_inc(&rdtp->dynticks);
69897 + atomic_inc_unchecked(&rdtp->dynticks);
69898 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69899 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69900 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69901 }
69902
69903 /**
69904 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69905 int ret;
69906
69907 preempt_disable();
69908 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69909 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69910 preempt_enable();
69911 return ret;
69912 }
69913 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69914 */
69915 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69916 {
69917 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69918 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69919 return (rdp->dynticks_snap & 0x1) == 0;
69920 }
69921
69922 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69923 unsigned int curr;
69924 unsigned int snap;
69925
69926 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69927 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69928 snap = (unsigned int)rdp->dynticks_snap;
69929
69930 /*
69931 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69932 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69933 */
69934 if (till_stall_check < 3) {
69935 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69936 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69937 till_stall_check = 3;
69938 } else if (till_stall_check > 300) {
69939 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69940 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69941 till_stall_check = 300;
69942 }
69943 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69944 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69945 rsp->qlen += rdp->qlen;
69946 rdp->n_cbs_orphaned += rdp->qlen;
69947 rdp->qlen_lazy = 0;
69948 - ACCESS_ONCE(rdp->qlen) = 0;
69949 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69950 }
69951
69952 /*
69953 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69954 }
69955 smp_mb(); /* List handling before counting for rcu_barrier(). */
69956 rdp->qlen_lazy -= count_lazy;
69957 - ACCESS_ONCE(rdp->qlen) -= count;
69958 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69959 rdp->n_cbs_invoked += count;
69960
69961 /* Reinstate batch limit if we have worked down the excess. */
69962 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69963 /*
69964 * Do RCU core processing for the current CPU.
69965 */
69966 -static void rcu_process_callbacks(struct softirq_action *unused)
69967 +static void rcu_process_callbacks(void)
69968 {
69969 struct rcu_state *rsp;
69970
69971 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69972 rdp = this_cpu_ptr(rsp->rda);
69973
69974 /* Add the callback to our list. */
69975 - ACCESS_ONCE(rdp->qlen)++;
69976 + ACCESS_ONCE_RW(rdp->qlen)++;
69977 if (lazy)
69978 rdp->qlen_lazy++;
69979 else
69980 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69981 }
69982 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69983
69984 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69985 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69986 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69987 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69988
69989 static int synchronize_sched_expedited_cpu_stop(void *data)
69990 {
69991 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69992 int firstsnap, s, snap, trycount = 0;
69993
69994 /* Note that atomic_inc_return() implies full memory barrier. */
69995 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69996 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69997 get_online_cpus();
69998 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69999
70000 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70001 }
70002
70003 /* Check to see if someone else did our work for us. */
70004 - s = atomic_read(&sync_sched_expedited_done);
70005 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70006 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70007 smp_mb(); /* ensure test happens before caller kfree */
70008 return;
70009 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70010 * grace period works for us.
70011 */
70012 get_online_cpus();
70013 - snap = atomic_read(&sync_sched_expedited_started);
70014 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70015 smp_mb(); /* ensure read is before try_stop_cpus(). */
70016 }
70017
70018 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70019 * than we did beat us to the punch.
70020 */
70021 do {
70022 - s = atomic_read(&sync_sched_expedited_done);
70023 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70024 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70025 smp_mb(); /* ensure test happens before caller kfree */
70026 break;
70027 }
70028 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70029 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70030
70031 put_online_cpus();
70032 }
70033 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70034 * ACCESS_ONCE() to prevent the compiler from speculating
70035 * the increment to precede the early-exit check.
70036 */
70037 - ACCESS_ONCE(rsp->n_barrier_done)++;
70038 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70039 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70040 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70041 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70042 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70043
70044 /* Increment ->n_barrier_done to prevent duplicate work. */
70045 smp_mb(); /* Keep increment after above mechanism. */
70046 - ACCESS_ONCE(rsp->n_barrier_done)++;
70047 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70048 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70049 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70050 smp_mb(); /* Keep increment before caller's subsequent code. */
70051 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70052 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70053 init_callback_list(rdp);
70054 rdp->qlen_lazy = 0;
70055 - ACCESS_ONCE(rdp->qlen) = 0;
70056 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70057 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70058 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70059 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70060 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70061 rdp->cpu = cpu;
70062 rdp->rsp = rsp;
70063 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70064 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70065 rdp->n_force_qs_snap = rsp->n_force_qs;
70066 rdp->blimit = blimit;
70067 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70068 - atomic_set(&rdp->dynticks->dynticks,
70069 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70070 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70071 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70072 rcu_prepare_for_idle_init(cpu);
70073 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70074
70075 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70076 index 4d29169..d104a3c 100644
70077 --- a/kernel/rcutree.h
70078 +++ b/kernel/rcutree.h
70079 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70080 long long dynticks_nesting; /* Track irq/process nesting level. */
70081 /* Process level is worth LLONG_MAX/2. */
70082 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70083 - atomic_t dynticks; /* Even value for idle, else odd. */
70084 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70085 #ifdef CONFIG_RCU_FAST_NO_HZ
70086 int dyntick_drain; /* Prepare-for-idle state variable. */
70087 unsigned long dyntick_holdoff;
70088 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70089 index 7f3244c..417d606 100644
70090 --- a/kernel/rcutree_plugin.h
70091 +++ b/kernel/rcutree_plugin.h
70092 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70093
70094 /* Clean up and exit. */
70095 smp_mb(); /* ensure expedited GP seen before counter increment. */
70096 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70097 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70098 unlock_mb_ret:
70099 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70100 mb_ret:
70101 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70102 index abffb48..cbfa6d3 100644
70103 --- a/kernel/rcutree_trace.c
70104 +++ b/kernel/rcutree_trace.c
70105 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70106 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70107 rdp->qs_pending);
70108 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70109 - atomic_read(&rdp->dynticks->dynticks),
70110 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70111 rdp->dynticks->dynticks_nesting,
70112 rdp->dynticks->dynticks_nmi_nesting,
70113 rdp->dynticks_fqs);
70114 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70115 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70116 rdp->qs_pending);
70117 seq_printf(m, ",%d,%llx,%d,%lu",
70118 - atomic_read(&rdp->dynticks->dynticks),
70119 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70120 rdp->dynticks->dynticks_nesting,
70121 rdp->dynticks->dynticks_nmi_nesting,
70122 rdp->dynticks_fqs);
70123 diff --git a/kernel/resource.c b/kernel/resource.c
70124 index 34d4588..10baa6a 100644
70125 --- a/kernel/resource.c
70126 +++ b/kernel/resource.c
70127 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70128
70129 static int __init ioresources_init(void)
70130 {
70131 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70133 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70134 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70135 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70136 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70137 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70138 +#endif
70139 +#else
70140 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70141 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70142 +#endif
70143 return 0;
70144 }
70145 __initcall(ioresources_init);
70146 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70147 index 98ec494..4241d6d 100644
70148 --- a/kernel/rtmutex-tester.c
70149 +++ b/kernel/rtmutex-tester.c
70150 @@ -20,7 +20,7 @@
70151 #define MAX_RT_TEST_MUTEXES 8
70152
70153 static spinlock_t rttest_lock;
70154 -static atomic_t rttest_event;
70155 +static atomic_unchecked_t rttest_event;
70156
70157 struct test_thread_data {
70158 int opcode;
70159 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70160
70161 case RTTEST_LOCKCONT:
70162 td->mutexes[td->opdata] = 1;
70163 - td->event = atomic_add_return(1, &rttest_event);
70164 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70165 return 0;
70166
70167 case RTTEST_RESET:
70168 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70169 return 0;
70170
70171 case RTTEST_RESETEVENT:
70172 - atomic_set(&rttest_event, 0);
70173 + atomic_set_unchecked(&rttest_event, 0);
70174 return 0;
70175
70176 default:
70177 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70178 return ret;
70179
70180 td->mutexes[id] = 1;
70181 - td->event = atomic_add_return(1, &rttest_event);
70182 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70183 rt_mutex_lock(&mutexes[id]);
70184 - td->event = atomic_add_return(1, &rttest_event);
70185 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70186 td->mutexes[id] = 4;
70187 return 0;
70188
70189 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70190 return ret;
70191
70192 td->mutexes[id] = 1;
70193 - td->event = atomic_add_return(1, &rttest_event);
70194 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70195 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70196 - td->event = atomic_add_return(1, &rttest_event);
70197 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70198 td->mutexes[id] = ret ? 0 : 4;
70199 return ret ? -EINTR : 0;
70200
70201 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70202 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70203 return ret;
70204
70205 - td->event = atomic_add_return(1, &rttest_event);
70206 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70207 rt_mutex_unlock(&mutexes[id]);
70208 - td->event = atomic_add_return(1, &rttest_event);
70209 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70210 td->mutexes[id] = 0;
70211 return 0;
70212
70213 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70214 break;
70215
70216 td->mutexes[dat] = 2;
70217 - td->event = atomic_add_return(1, &rttest_event);
70218 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70219 break;
70220
70221 default:
70222 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70223 return;
70224
70225 td->mutexes[dat] = 3;
70226 - td->event = atomic_add_return(1, &rttest_event);
70227 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70228 break;
70229
70230 case RTTEST_LOCKNOWAIT:
70231 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70232 return;
70233
70234 td->mutexes[dat] = 1;
70235 - td->event = atomic_add_return(1, &rttest_event);
70236 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70237 return;
70238
70239 default:
70240 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70241 index 0984a21..939f183 100644
70242 --- a/kernel/sched/auto_group.c
70243 +++ b/kernel/sched/auto_group.c
70244 @@ -11,7 +11,7 @@
70245
70246 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70247 static struct autogroup autogroup_default;
70248 -static atomic_t autogroup_seq_nr;
70249 +static atomic_unchecked_t autogroup_seq_nr;
70250
70251 void __init autogroup_init(struct task_struct *init_task)
70252 {
70253 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70254
70255 kref_init(&ag->kref);
70256 init_rwsem(&ag->lock);
70257 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70258 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70259 ag->tg = tg;
70260 #ifdef CONFIG_RT_GROUP_SCHED
70261 /*
70262 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70263 index 1a48cdb..d3949ff 100644
70264 --- a/kernel/sched/core.c
70265 +++ b/kernel/sched/core.c
70266 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70267 /* convert nice value [19,-20] to rlimit style value [1,40] */
70268 int nice_rlim = 20 - nice;
70269
70270 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70271 +
70272 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70273 capable(CAP_SYS_NICE));
70274 }
70275 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70276 if (nice > 19)
70277 nice = 19;
70278
70279 - if (increment < 0 && !can_nice(current, nice))
70280 + if (increment < 0 && (!can_nice(current, nice) ||
70281 + gr_handle_chroot_nice()))
70282 return -EPERM;
70283
70284 retval = security_task_setnice(current, nice);
70285 @@ -4290,6 +4293,7 @@ recheck:
70286 unsigned long rlim_rtprio =
70287 task_rlimit(p, RLIMIT_RTPRIO);
70288
70289 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70290 /* can't set/change the rt policy */
70291 if (policy != p->policy && !rlim_rtprio)
70292 return -EPERM;
70293 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70294 index 96e2b18..bb31eec 100644
70295 --- a/kernel/sched/fair.c
70296 +++ b/kernel/sched/fair.c
70297 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70298 * run_rebalance_domains is triggered when needed from the scheduler tick.
70299 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70300 */
70301 -static void run_rebalance_domains(struct softirq_action *h)
70302 +static void run_rebalance_domains(void)
70303 {
70304 int this_cpu = smp_processor_id();
70305 struct rq *this_rq = cpu_rq(this_cpu);
70306 diff --git a/kernel/signal.c b/kernel/signal.c
70307 index be4f856..453401c 100644
70308 --- a/kernel/signal.c
70309 +++ b/kernel/signal.c
70310 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70311
70312 int print_fatal_signals __read_mostly;
70313
70314 -static void __user *sig_handler(struct task_struct *t, int sig)
70315 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70316 {
70317 return t->sighand->action[sig - 1].sa.sa_handler;
70318 }
70319
70320 -static int sig_handler_ignored(void __user *handler, int sig)
70321 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70322 {
70323 /* Is it explicitly or implicitly ignored? */
70324 return handler == SIG_IGN ||
70325 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70326
70327 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70328 {
70329 - void __user *handler;
70330 + __sighandler_t handler;
70331
70332 handler = sig_handler(t, sig);
70333
70334 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70335 atomic_inc(&user->sigpending);
70336 rcu_read_unlock();
70337
70338 + if (!override_rlimit)
70339 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70340 +
70341 if (override_rlimit ||
70342 atomic_read(&user->sigpending) <=
70343 task_rlimit(t, RLIMIT_SIGPENDING)) {
70344 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70345
70346 int unhandled_signal(struct task_struct *tsk, int sig)
70347 {
70348 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70349 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70350 if (is_global_init(tsk))
70351 return 1;
70352 if (handler != SIG_IGN && handler != SIG_DFL)
70353 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70354 }
70355 }
70356
70357 + /* allow glibc communication via tgkill to other threads in our
70358 + thread group */
70359 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70360 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70361 + && gr_handle_signal(t, sig))
70362 + return -EPERM;
70363 +
70364 return security_task_kill(t, info, sig, 0);
70365 }
70366
70367 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70368 return send_signal(sig, info, p, 1);
70369 }
70370
70371 -static int
70372 +int
70373 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70374 {
70375 return send_signal(sig, info, t, 0);
70376 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70377 unsigned long int flags;
70378 int ret, blocked, ignored;
70379 struct k_sigaction *action;
70380 + int is_unhandled = 0;
70381
70382 spin_lock_irqsave(&t->sighand->siglock, flags);
70383 action = &t->sighand->action[sig-1];
70384 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70385 }
70386 if (action->sa.sa_handler == SIG_DFL)
70387 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70388 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70389 + is_unhandled = 1;
70390 ret = specific_send_sig_info(sig, info, t);
70391 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70392
70393 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70394 + normal operation */
70395 + if (is_unhandled) {
70396 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70397 + gr_handle_crash(t, sig);
70398 + }
70399 +
70400 return ret;
70401 }
70402
70403 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70404 ret = check_kill_permission(sig, info, p);
70405 rcu_read_unlock();
70406
70407 - if (!ret && sig)
70408 + if (!ret && sig) {
70409 ret = do_send_sig_info(sig, info, p, true);
70410 + if (!ret)
70411 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70412 + }
70413
70414 return ret;
70415 }
70416 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70417 int error = -ESRCH;
70418
70419 rcu_read_lock();
70420 - p = find_task_by_vpid(pid);
70421 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70422 + /* allow glibc communication via tgkill to other threads in our
70423 + thread group */
70424 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70425 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70426 + p = find_task_by_vpid_unrestricted(pid);
70427 + else
70428 +#endif
70429 + p = find_task_by_vpid(pid);
70430 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70431 error = check_kill_permission(sig, info, p);
70432 /*
70433 diff --git a/kernel/softirq.c b/kernel/softirq.c
70434 index b73e681..645ab62 100644
70435 --- a/kernel/softirq.c
70436 +++ b/kernel/softirq.c
70437 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70438
70439 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70440
70441 -char *softirq_to_name[NR_SOFTIRQS] = {
70442 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70443 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70444 "TASKLET", "SCHED", "HRTIMER", "RCU"
70445 };
70446 @@ -243,7 +243,7 @@ restart:
70447 kstat_incr_softirqs_this_cpu(vec_nr);
70448
70449 trace_softirq_entry(vec_nr);
70450 - h->action(h);
70451 + h->action();
70452 trace_softirq_exit(vec_nr);
70453 if (unlikely(prev_count != preempt_count())) {
70454 printk(KERN_ERR "huh, entered softirq %u %s %p"
70455 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70456 or_softirq_pending(1UL << nr);
70457 }
70458
70459 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70460 +void open_softirq(int nr, void (*action)(void))
70461 {
70462 - softirq_vec[nr].action = action;
70463 + pax_open_kernel();
70464 + *(void **)&softirq_vec[nr].action = action;
70465 + pax_close_kernel();
70466 }
70467
70468 /*
70469 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70470
70471 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70472
70473 -static void tasklet_action(struct softirq_action *a)
70474 +static void tasklet_action(void)
70475 {
70476 struct tasklet_struct *list;
70477
70478 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70479 }
70480 }
70481
70482 -static void tasklet_hi_action(struct softirq_action *a)
70483 +static void tasklet_hi_action(void)
70484 {
70485 struct tasklet_struct *list;
70486
70487 diff --git a/kernel/srcu.c b/kernel/srcu.c
70488 index 2095be3..9a5b89d 100644
70489 --- a/kernel/srcu.c
70490 +++ b/kernel/srcu.c
70491 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70492 preempt_disable();
70493 idx = rcu_dereference_index_check(sp->completed,
70494 rcu_read_lock_sched_held()) & 0x1;
70495 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70496 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70497 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70498 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70499 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70500 preempt_enable();
70501 return idx;
70502 }
70503 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70504 {
70505 preempt_disable();
70506 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70507 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70508 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70509 preempt_enable();
70510 }
70511 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70512 diff --git a/kernel/sys.c b/kernel/sys.c
70513 index 909148a..cd51acf 100644
70514 --- a/kernel/sys.c
70515 +++ b/kernel/sys.c
70516 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70517 error = -EACCES;
70518 goto out;
70519 }
70520 +
70521 + if (gr_handle_chroot_setpriority(p, niceval)) {
70522 + error = -EACCES;
70523 + goto out;
70524 + }
70525 +
70526 no_nice = security_task_setnice(p, niceval);
70527 if (no_nice) {
70528 error = no_nice;
70529 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70530 goto error;
70531 }
70532
70533 + if (gr_check_group_change(new->gid, new->egid, -1))
70534 + goto error;
70535 +
70536 if (rgid != (gid_t) -1 ||
70537 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70538 new->sgid = new->egid;
70539 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70540 old = current_cred();
70541
70542 retval = -EPERM;
70543 +
70544 + if (gr_check_group_change(kgid, kgid, kgid))
70545 + goto error;
70546 +
70547 if (nsown_capable(CAP_SETGID))
70548 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70549 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70550 @@ -647,7 +660,7 @@ error:
70551 /*
70552 * change the user struct in a credentials set to match the new UID
70553 */
70554 -static int set_user(struct cred *new)
70555 +int set_user(struct cred *new)
70556 {
70557 struct user_struct *new_user;
70558
70559 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70560 goto error;
70561 }
70562
70563 + if (gr_check_user_change(new->uid, new->euid, -1))
70564 + goto error;
70565 +
70566 if (!uid_eq(new->uid, old->uid)) {
70567 retval = set_user(new);
70568 if (retval < 0)
70569 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70570 old = current_cred();
70571
70572 retval = -EPERM;
70573 +
70574 + if (gr_check_crash_uid(kuid))
70575 + goto error;
70576 + if (gr_check_user_change(kuid, kuid, kuid))
70577 + goto error;
70578 +
70579 if (nsown_capable(CAP_SETUID)) {
70580 new->suid = new->uid = kuid;
70581 if (!uid_eq(kuid, old->uid)) {
70582 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70583 goto error;
70584 }
70585
70586 + if (gr_check_user_change(kruid, keuid, -1))
70587 + goto error;
70588 +
70589 if (ruid != (uid_t) -1) {
70590 new->uid = kruid;
70591 if (!uid_eq(kruid, old->uid)) {
70592 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70593 goto error;
70594 }
70595
70596 + if (gr_check_group_change(krgid, kegid, -1))
70597 + goto error;
70598 +
70599 if (rgid != (gid_t) -1)
70600 new->gid = krgid;
70601 if (egid != (gid_t) -1)
70602 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70603 if (!uid_valid(kuid))
70604 return old_fsuid;
70605
70606 + if (gr_check_user_change(-1, -1, kuid))
70607 + goto error;
70608 +
70609 new = prepare_creds();
70610 if (!new)
70611 return old_fsuid;
70612 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70613 }
70614 }
70615
70616 +error:
70617 abort_creds(new);
70618 return old_fsuid;
70619
70620 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70621 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70622 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70623 nsown_capable(CAP_SETGID)) {
70624 + if (gr_check_group_change(-1, -1, kgid))
70625 + goto error;
70626 +
70627 if (!gid_eq(kgid, old->fsgid)) {
70628 new->fsgid = kgid;
70629 goto change_okay;
70630 }
70631 }
70632
70633 +error:
70634 abort_creds(new);
70635 return old_fsgid;
70636
70637 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70638 return -EFAULT;
70639
70640 down_read(&uts_sem);
70641 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70642 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70643 __OLD_UTS_LEN);
70644 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70645 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70646 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70647 __OLD_UTS_LEN);
70648 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70649 - error |= __copy_to_user(&name->release, &utsname()->release,
70650 + error |= __copy_to_user(name->release, &utsname()->release,
70651 __OLD_UTS_LEN);
70652 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70653 - error |= __copy_to_user(&name->version, &utsname()->version,
70654 + error |= __copy_to_user(name->version, &utsname()->version,
70655 __OLD_UTS_LEN);
70656 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70657 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70658 + error |= __copy_to_user(name->machine, &utsname()->machine,
70659 __OLD_UTS_LEN);
70660 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70661 up_read(&uts_sem);
70662 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70663 error = get_dumpable(me->mm);
70664 break;
70665 case PR_SET_DUMPABLE:
70666 - if (arg2 < 0 || arg2 > 1) {
70667 + if (arg2 > 1) {
70668 error = -EINVAL;
70669 break;
70670 }
70671 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70672 index 87174ef..68cbb82 100644
70673 --- a/kernel/sysctl.c
70674 +++ b/kernel/sysctl.c
70675 @@ -92,7 +92,6 @@
70676
70677
70678 #if defined(CONFIG_SYSCTL)
70679 -
70680 /* External variables not in a header file. */
70681 extern int sysctl_overcommit_memory;
70682 extern int sysctl_overcommit_ratio;
70683 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70684 void __user *buffer, size_t *lenp, loff_t *ppos);
70685 #endif
70686
70687 -#ifdef CONFIG_PRINTK
70688 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70689 void __user *buffer, size_t *lenp, loff_t *ppos);
70690 -#endif
70691
70692 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70693 void __user *buffer, size_t *lenp, loff_t *ppos);
70694 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70695
70696 #endif
70697
70698 +extern struct ctl_table grsecurity_table[];
70699 +
70700 static struct ctl_table kern_table[];
70701 static struct ctl_table vm_table[];
70702 static struct ctl_table fs_table[];
70703 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70704 int sysctl_legacy_va_layout;
70705 #endif
70706
70707 +#ifdef CONFIG_PAX_SOFTMODE
70708 +static ctl_table pax_table[] = {
70709 + {
70710 + .procname = "softmode",
70711 + .data = &pax_softmode,
70712 + .maxlen = sizeof(unsigned int),
70713 + .mode = 0600,
70714 + .proc_handler = &proc_dointvec,
70715 + },
70716 +
70717 + { }
70718 +};
70719 +#endif
70720 +
70721 /* The default sysctl tables: */
70722
70723 static struct ctl_table sysctl_base_table[] = {
70724 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70725 #endif
70726
70727 static struct ctl_table kern_table[] = {
70728 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70729 + {
70730 + .procname = "grsecurity",
70731 + .mode = 0500,
70732 + .child = grsecurity_table,
70733 + },
70734 +#endif
70735 +
70736 +#ifdef CONFIG_PAX_SOFTMODE
70737 + {
70738 + .procname = "pax",
70739 + .mode = 0500,
70740 + .child = pax_table,
70741 + },
70742 +#endif
70743 +
70744 {
70745 .procname = "sched_child_runs_first",
70746 .data = &sysctl_sched_child_runs_first,
70747 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70748 .data = &modprobe_path,
70749 .maxlen = KMOD_PATH_LEN,
70750 .mode = 0644,
70751 - .proc_handler = proc_dostring,
70752 + .proc_handler = proc_dostring_modpriv,
70753 },
70754 {
70755 .procname = "modules_disabled",
70756 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70757 .extra1 = &zero,
70758 .extra2 = &one,
70759 },
70760 +#endif
70761 {
70762 .procname = "kptr_restrict",
70763 .data = &kptr_restrict,
70764 .maxlen = sizeof(int),
70765 .mode = 0644,
70766 .proc_handler = proc_dointvec_minmax_sysadmin,
70767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70768 + .extra1 = &two,
70769 +#else
70770 .extra1 = &zero,
70771 +#endif
70772 .extra2 = &two,
70773 },
70774 -#endif
70775 {
70776 .procname = "ngroups_max",
70777 .data = &ngroups_max,
70778 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70779 .proc_handler = proc_dointvec_minmax,
70780 .extra1 = &zero,
70781 },
70782 + {
70783 + .procname = "heap_stack_gap",
70784 + .data = &sysctl_heap_stack_gap,
70785 + .maxlen = sizeof(sysctl_heap_stack_gap),
70786 + .mode = 0644,
70787 + .proc_handler = proc_doulongvec_minmax,
70788 + },
70789 #else
70790 {
70791 .procname = "nr_trim_pages",
70792 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70793 buffer, lenp, ppos);
70794 }
70795
70796 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70797 + void __user *buffer, size_t *lenp, loff_t *ppos)
70798 +{
70799 + if (write && !capable(CAP_SYS_MODULE))
70800 + return -EPERM;
70801 +
70802 + return _proc_do_string(table->data, table->maxlen, write,
70803 + buffer, lenp, ppos);
70804 +}
70805 +
70806 static size_t proc_skip_spaces(char **buf)
70807 {
70808 size_t ret;
70809 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70810 len = strlen(tmp);
70811 if (len > *size)
70812 len = *size;
70813 + if (len > sizeof(tmp))
70814 + len = sizeof(tmp);
70815 if (copy_to_user(*buf, tmp, len))
70816 return -EFAULT;
70817 *size -= len;
70818 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70819 return err;
70820 }
70821
70822 -#ifdef CONFIG_PRINTK
70823 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70824 void __user *buffer, size_t *lenp, loff_t *ppos)
70825 {
70826 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70827
70828 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70829 }
70830 -#endif
70831
70832 struct do_proc_dointvec_minmax_conv_param {
70833 int *min;
70834 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70835 *i = val;
70836 } else {
70837 val = convdiv * (*i) / convmul;
70838 - if (!first)
70839 + if (!first) {
70840 err = proc_put_char(&buffer, &left, '\t');
70841 + if (err)
70842 + break;
70843 + }
70844 err = proc_put_long(&buffer, &left, val, false);
70845 if (err)
70846 break;
70847 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70848 return -ENOSYS;
70849 }
70850
70851 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70852 + void __user *buffer, size_t *lenp, loff_t *ppos)
70853 +{
70854 + return -ENOSYS;
70855 +}
70856 +
70857 int proc_dointvec(struct ctl_table *table, int write,
70858 void __user *buffer, size_t *lenp, loff_t *ppos)
70859 {
70860 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70861 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70862 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70863 EXPORT_SYMBOL(proc_dostring);
70864 +EXPORT_SYMBOL(proc_dostring_modpriv);
70865 EXPORT_SYMBOL(proc_doulongvec_minmax);
70866 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70867 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70868 index 65bdcf1..21eb831 100644
70869 --- a/kernel/sysctl_binary.c
70870 +++ b/kernel/sysctl_binary.c
70871 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70872 int i;
70873
70874 set_fs(KERNEL_DS);
70875 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70876 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70877 set_fs(old_fs);
70878 if (result < 0)
70879 goto out_kfree;
70880 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70881 }
70882
70883 set_fs(KERNEL_DS);
70884 - result = vfs_write(file, buffer, str - buffer, &pos);
70885 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70886 set_fs(old_fs);
70887 if (result < 0)
70888 goto out_kfree;
70889 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70890 int i;
70891
70892 set_fs(KERNEL_DS);
70893 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70894 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70895 set_fs(old_fs);
70896 if (result < 0)
70897 goto out_kfree;
70898 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70899 }
70900
70901 set_fs(KERNEL_DS);
70902 - result = vfs_write(file, buffer, str - buffer, &pos);
70903 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70904 set_fs(old_fs);
70905 if (result < 0)
70906 goto out_kfree;
70907 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70908 int i;
70909
70910 set_fs(KERNEL_DS);
70911 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70912 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70913 set_fs(old_fs);
70914 if (result < 0)
70915 goto out;
70916 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70917 __le16 dnaddr;
70918
70919 set_fs(KERNEL_DS);
70920 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70921 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70922 set_fs(old_fs);
70923 if (result < 0)
70924 goto out;
70925 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70926 le16_to_cpu(dnaddr) & 0x3ff);
70927
70928 set_fs(KERNEL_DS);
70929 - result = vfs_write(file, buf, len, &pos);
70930 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70931 set_fs(old_fs);
70932 if (result < 0)
70933 goto out;
70934 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70935 index d0a3279..db0ad99 100644
70936 --- a/kernel/taskstats.c
70937 +++ b/kernel/taskstats.c
70938 @@ -27,9 +27,12 @@
70939 #include <linux/cgroup.h>
70940 #include <linux/fs.h>
70941 #include <linux/file.h>
70942 +#include <linux/grsecurity.h>
70943 #include <net/genetlink.h>
70944 #include <linux/atomic.h>
70945
70946 +extern int gr_is_taskstats_denied(int pid);
70947 +
70948 /*
70949 * Maximum length of a cpumask that can be specified in
70950 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70951 @@ -561,6 +564,9 @@ err:
70952
70953 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70954 {
70955 + if (gr_is_taskstats_denied(current->pid))
70956 + return -EACCES;
70957 +
70958 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70959 return cmd_attr_register_cpumask(info);
70960 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70961 diff --git a/kernel/time.c b/kernel/time.c
70962 index ba744cf..267b7c5 100644
70963 --- a/kernel/time.c
70964 +++ b/kernel/time.c
70965 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70966 return error;
70967
70968 if (tz) {
70969 + /* we log in do_settimeofday called below, so don't log twice
70970 + */
70971 + if (!tv)
70972 + gr_log_timechange();
70973 +
70974 sys_tz = *tz;
70975 update_vsyscall_tz();
70976 if (firsttime) {
70977 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70978 index aa27d39..34d221c 100644
70979 --- a/kernel/time/alarmtimer.c
70980 +++ b/kernel/time/alarmtimer.c
70981 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70982 struct platform_device *pdev;
70983 int error = 0;
70984 int i;
70985 - struct k_clock alarm_clock = {
70986 + static struct k_clock alarm_clock = {
70987 .clock_getres = alarm_clock_getres,
70988 .clock_get = alarm_clock_get,
70989 .timer_create = alarm_timer_create,
70990 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70991 index f113755..ec24223 100644
70992 --- a/kernel/time/tick-broadcast.c
70993 +++ b/kernel/time/tick-broadcast.c
70994 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70995 * then clear the broadcast bit.
70996 */
70997 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70998 - int cpu = smp_processor_id();
70999 + cpu = smp_processor_id();
71000
71001 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71002 tick_broadcast_clear_oneshot(cpu);
71003 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71004 index f791637..00051de 100644
71005 --- a/kernel/time/timekeeping.c
71006 +++ b/kernel/time/timekeeping.c
71007 @@ -14,6 +14,7 @@
71008 #include <linux/init.h>
71009 #include <linux/mm.h>
71010 #include <linux/sched.h>
71011 +#include <linux/grsecurity.h>
71012 #include <linux/syscore_ops.h>
71013 #include <linux/clocksource.h>
71014 #include <linux/jiffies.h>
71015 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71016 if (!timespec_valid_strict(tv))
71017 return -EINVAL;
71018
71019 + gr_log_timechange();
71020 +
71021 write_seqlock_irqsave(&tk->lock, flags);
71022
71023 timekeeping_forward_now(tk);
71024 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71025 index af5a7e9..715611a 100644
71026 --- a/kernel/time/timer_list.c
71027 +++ b/kernel/time/timer_list.c
71028 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71029
71030 static void print_name_offset(struct seq_file *m, void *sym)
71031 {
71032 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71033 + SEQ_printf(m, "<%p>", NULL);
71034 +#else
71035 char symname[KSYM_NAME_LEN];
71036
71037 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71038 SEQ_printf(m, "<%pK>", sym);
71039 else
71040 SEQ_printf(m, "%s", symname);
71041 +#endif
71042 }
71043
71044 static void
71045 @@ -112,7 +116,11 @@ next_one:
71046 static void
71047 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71048 {
71049 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71050 + SEQ_printf(m, " .base: %p\n", NULL);
71051 +#else
71052 SEQ_printf(m, " .base: %pK\n", base);
71053 +#endif
71054 SEQ_printf(m, " .index: %d\n",
71055 base->index);
71056 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71057 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71058 {
71059 struct proc_dir_entry *pe;
71060
71061 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71062 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71063 +#else
71064 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71065 +#endif
71066 if (!pe)
71067 return -ENOMEM;
71068 return 0;
71069 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71070 index 0b537f2..40d6c20 100644
71071 --- a/kernel/time/timer_stats.c
71072 +++ b/kernel/time/timer_stats.c
71073 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71074 static unsigned long nr_entries;
71075 static struct entry entries[MAX_ENTRIES];
71076
71077 -static atomic_t overflow_count;
71078 +static atomic_unchecked_t overflow_count;
71079
71080 /*
71081 * The entries are in a hash-table, for fast lookup:
71082 @@ -140,7 +140,7 @@ static void reset_entries(void)
71083 nr_entries = 0;
71084 memset(entries, 0, sizeof(entries));
71085 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71086 - atomic_set(&overflow_count, 0);
71087 + atomic_set_unchecked(&overflow_count, 0);
71088 }
71089
71090 static struct entry *alloc_entry(void)
71091 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71092 if (likely(entry))
71093 entry->count++;
71094 else
71095 - atomic_inc(&overflow_count);
71096 + atomic_inc_unchecked(&overflow_count);
71097
71098 out_unlock:
71099 raw_spin_unlock_irqrestore(lock, flags);
71100 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71101
71102 static void print_name_offset(struct seq_file *m, unsigned long addr)
71103 {
71104 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71105 + seq_printf(m, "<%p>", NULL);
71106 +#else
71107 char symname[KSYM_NAME_LEN];
71108
71109 if (lookup_symbol_name(addr, symname) < 0)
71110 - seq_printf(m, "<%p>", (void *)addr);
71111 + seq_printf(m, "<%pK>", (void *)addr);
71112 else
71113 seq_printf(m, "%s", symname);
71114 +#endif
71115 }
71116
71117 static int tstats_show(struct seq_file *m, void *v)
71118 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71119
71120 seq_puts(m, "Timer Stats Version: v0.2\n");
71121 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71122 - if (atomic_read(&overflow_count))
71123 + if (atomic_read_unchecked(&overflow_count))
71124 seq_printf(m, "Overflow: %d entries\n",
71125 - atomic_read(&overflow_count));
71126 + atomic_read_unchecked(&overflow_count));
71127
71128 for (i = 0; i < nr_entries; i++) {
71129 entry = entries + i;
71130 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71131 {
71132 struct proc_dir_entry *pe;
71133
71134 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71135 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71136 +#else
71137 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71138 +#endif
71139 if (!pe)
71140 return -ENOMEM;
71141 return 0;
71142 diff --git a/kernel/timer.c b/kernel/timer.c
71143 index 46ef2b1..ad081f144 100644
71144 --- a/kernel/timer.c
71145 +++ b/kernel/timer.c
71146 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71147 /*
71148 * This function runs timers and the timer-tq in bottom half context.
71149 */
71150 -static void run_timer_softirq(struct softirq_action *h)
71151 +static void run_timer_softirq(void)
71152 {
71153 struct tvec_base *base = __this_cpu_read(tvec_bases);
71154
71155 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71156 index c0bd030..62a1927 100644
71157 --- a/kernel/trace/blktrace.c
71158 +++ b/kernel/trace/blktrace.c
71159 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71160 struct blk_trace *bt = filp->private_data;
71161 char buf[16];
71162
71163 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71164 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71165
71166 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71167 }
71168 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71169 return 1;
71170
71171 bt = buf->chan->private_data;
71172 - atomic_inc(&bt->dropped);
71173 + atomic_inc_unchecked(&bt->dropped);
71174 return 0;
71175 }
71176
71177 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71178
71179 bt->dir = dir;
71180 bt->dev = dev;
71181 - atomic_set(&bt->dropped, 0);
71182 + atomic_set_unchecked(&bt->dropped, 0);
71183
71184 ret = -EIO;
71185 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71186 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71187 index b4f20fb..483c5fa 100644
71188 --- a/kernel/trace/ftrace.c
71189 +++ b/kernel/trace/ftrace.c
71190 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71191 if (unlikely(ftrace_disabled))
71192 return 0;
71193
71194 + ret = ftrace_arch_code_modify_prepare();
71195 + FTRACE_WARN_ON(ret);
71196 + if (ret)
71197 + return 0;
71198 +
71199 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71200 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71201 if (ret) {
71202 ftrace_bug(ret, ip);
71203 - return 0;
71204 }
71205 - return 1;
71206 + return ret ? 0 : 1;
71207 }
71208
71209 /*
71210 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71211
71212 int
71213 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71214 - void *data)
71215 + void *data)
71216 {
71217 struct ftrace_func_probe *entry;
71218 struct ftrace_page *pg;
71219 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71220 if (!count)
71221 return 0;
71222
71223 + pax_open_kernel();
71224 sort(start, count, sizeof(*start),
71225 ftrace_cmp_ips, ftrace_swap_ips);
71226 + pax_close_kernel();
71227
71228 start_pg = ftrace_allocate_pages(count);
71229 if (!start_pg)
71230 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71231 index 5c38c81..88012af 100644
71232 --- a/kernel/trace/trace.c
71233 +++ b/kernel/trace/trace.c
71234 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71235 };
71236 #endif
71237
71238 -static struct dentry *d_tracer;
71239 -
71240 struct dentry *tracing_init_dentry(void)
71241 {
71242 + static struct dentry *d_tracer;
71243 static int once;
71244
71245 if (d_tracer)
71246 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71247 return d_tracer;
71248 }
71249
71250 -static struct dentry *d_percpu;
71251 -
71252 struct dentry *tracing_dentry_percpu(void)
71253 {
71254 + static struct dentry *d_percpu;
71255 static int once;
71256 struct dentry *d_tracer;
71257
71258 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71259 index 29111da..d190fe2 100644
71260 --- a/kernel/trace/trace_events.c
71261 +++ b/kernel/trace/trace_events.c
71262 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71263 struct ftrace_module_file_ops {
71264 struct list_head list;
71265 struct module *mod;
71266 - struct file_operations id;
71267 - struct file_operations enable;
71268 - struct file_operations format;
71269 - struct file_operations filter;
71270 };
71271
71272 static struct ftrace_module_file_ops *
71273 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71274
71275 file_ops->mod = mod;
71276
71277 - file_ops->id = ftrace_event_id_fops;
71278 - file_ops->id.owner = mod;
71279 -
71280 - file_ops->enable = ftrace_enable_fops;
71281 - file_ops->enable.owner = mod;
71282 -
71283 - file_ops->filter = ftrace_event_filter_fops;
71284 - file_ops->filter.owner = mod;
71285 -
71286 - file_ops->format = ftrace_event_format_fops;
71287 - file_ops->format.owner = mod;
71288 + pax_open_kernel();
71289 + *(void **)&mod->trace_id.owner = mod;
71290 + *(void **)&mod->trace_enable.owner = mod;
71291 + *(void **)&mod->trace_filter.owner = mod;
71292 + *(void **)&mod->trace_format.owner = mod;
71293 + pax_close_kernel();
71294
71295 list_add(&file_ops->list, &ftrace_module_file_list);
71296
71297 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71298
71299 for_each_event(call, start, end) {
71300 __trace_add_event_call(*call, mod,
71301 - &file_ops->id, &file_ops->enable,
71302 - &file_ops->filter, &file_ops->format);
71303 + &mod->trace_id, &mod->trace_enable,
71304 + &mod->trace_filter, &mod->trace_format);
71305 }
71306 }
71307
71308 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71309 index fd3c8aa..5f324a6 100644
71310 --- a/kernel/trace/trace_mmiotrace.c
71311 +++ b/kernel/trace/trace_mmiotrace.c
71312 @@ -24,7 +24,7 @@ struct header_iter {
71313 static struct trace_array *mmio_trace_array;
71314 static bool overrun_detected;
71315 static unsigned long prev_overruns;
71316 -static atomic_t dropped_count;
71317 +static atomic_unchecked_t dropped_count;
71318
71319 static void mmio_reset_data(struct trace_array *tr)
71320 {
71321 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71322
71323 static unsigned long count_overruns(struct trace_iterator *iter)
71324 {
71325 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71326 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71327 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71328
71329 if (over > prev_overruns)
71330 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71331 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71332 sizeof(*entry), 0, pc);
71333 if (!event) {
71334 - atomic_inc(&dropped_count);
71335 + atomic_inc_unchecked(&dropped_count);
71336 return;
71337 }
71338 entry = ring_buffer_event_data(event);
71339 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71340 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71341 sizeof(*entry), 0, pc);
71342 if (!event) {
71343 - atomic_inc(&dropped_count);
71344 + atomic_inc_unchecked(&dropped_count);
71345 return;
71346 }
71347 entry = ring_buffer_event_data(event);
71348 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71349 index 123b189..97b81f5 100644
71350 --- a/kernel/trace/trace_output.c
71351 +++ b/kernel/trace/trace_output.c
71352 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71353
71354 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71355 if (!IS_ERR(p)) {
71356 - p = mangle_path(s->buffer + s->len, p, "\n");
71357 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71358 if (p) {
71359 s->len = p - s->buffer;
71360 return 1;
71361 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71362 index d4545f4..a9010a1 100644
71363 --- a/kernel/trace/trace_stack.c
71364 +++ b/kernel/trace/trace_stack.c
71365 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71366 return;
71367
71368 /* we do not handle interrupt stacks yet */
71369 - if (!object_is_on_stack(&this_size))
71370 + if (!object_starts_on_stack(&this_size))
71371 return;
71372
71373 local_irq_save(flags);
71374 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71375 index 872bd6d..31601a2 100644
71376 --- a/kernel/workqueue.c
71377 +++ b/kernel/workqueue.c
71378 @@ -1422,7 +1422,7 @@ retry:
71379 /* morph UNBOUND to REBIND atomically */
71380 worker_flags &= ~WORKER_UNBOUND;
71381 worker_flags |= WORKER_REBIND;
71382 - ACCESS_ONCE(worker->flags) = worker_flags;
71383 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71384
71385 idle_rebind.cnt++;
71386 worker->idle_rebind = &idle_rebind;
71387 @@ -1448,7 +1448,7 @@ retry:
71388 /* morph UNBOUND to REBIND atomically */
71389 worker_flags &= ~WORKER_UNBOUND;
71390 worker_flags |= WORKER_REBIND;
71391 - ACCESS_ONCE(worker->flags) = worker_flags;
71392 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71393
71394 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71395 work_data_bits(rebind_work)))
71396 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71397 index 2403a63..5c4be4c 100644
71398 --- a/lib/Kconfig.debug
71399 +++ b/lib/Kconfig.debug
71400 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71401 depends on DEBUG_KERNEL
71402 depends on STACKTRACE_SUPPORT
71403 depends on PROC_FS
71404 + depends on !GRKERNSEC_HIDESYM
71405 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71406 select KALLSYMS
71407 select KALLSYMS_ALL
71408 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71409
71410 config PROVIDE_OHCI1394_DMA_INIT
71411 bool "Remote debugging over FireWire early on boot"
71412 - depends on PCI && X86
71413 + depends on PCI && X86 && !GRKERNSEC
71414 help
71415 If you want to debug problems which hang or crash the kernel early
71416 on boot and the crashing machine has a FireWire port, you can use
71417 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71418
71419 config FIREWIRE_OHCI_REMOTE_DMA
71420 bool "Remote debugging over FireWire with firewire-ohci"
71421 - depends on FIREWIRE_OHCI
71422 + depends on FIREWIRE_OHCI && !GRKERNSEC
71423 help
71424 This option lets you use the FireWire bus for remote debugging
71425 with help of the firewire-ohci driver. It enables unfiltered
71426 diff --git a/lib/bitmap.c b/lib/bitmap.c
71427 index 06fdfa1..97c5c7d 100644
71428 --- a/lib/bitmap.c
71429 +++ b/lib/bitmap.c
71430 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71431 {
71432 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71433 u32 chunk;
71434 - const char __user __force *ubuf = (const char __user __force *)buf;
71435 + const char __user *ubuf = (const char __force_user *)buf;
71436
71437 bitmap_zero(maskp, nmaskbits);
71438
71439 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71440 {
71441 if (!access_ok(VERIFY_READ, ubuf, ulen))
71442 return -EFAULT;
71443 - return __bitmap_parse((const char __force *)ubuf,
71444 + return __bitmap_parse((const char __force_kernel *)ubuf,
71445 ulen, 1, maskp, nmaskbits);
71446
71447 }
71448 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71449 {
71450 unsigned a, b;
71451 int c, old_c, totaldigits;
71452 - const char __user __force *ubuf = (const char __user __force *)buf;
71453 + const char __user *ubuf = (const char __force_user *)buf;
71454 int exp_digit, in_range;
71455
71456 totaldigits = c = 0;
71457 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71458 {
71459 if (!access_ok(VERIFY_READ, ubuf, ulen))
71460 return -EFAULT;
71461 - return __bitmap_parselist((const char __force *)ubuf,
71462 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71463 ulen, 1, maskp, nmaskbits);
71464 }
71465 EXPORT_SYMBOL(bitmap_parselist_user);
71466 diff --git a/lib/bug.c b/lib/bug.c
71467 index a28c141..2bd3d95 100644
71468 --- a/lib/bug.c
71469 +++ b/lib/bug.c
71470 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71471 return BUG_TRAP_TYPE_NONE;
71472
71473 bug = find_bug(bugaddr);
71474 + if (!bug)
71475 + return BUG_TRAP_TYPE_NONE;
71476
71477 file = NULL;
71478 line = 0;
71479 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71480 index d11808c..dc2d6f8 100644
71481 --- a/lib/debugobjects.c
71482 +++ b/lib/debugobjects.c
71483 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71484 if (limit > 4)
71485 return;
71486
71487 - is_on_stack = object_is_on_stack(addr);
71488 + is_on_stack = object_starts_on_stack(addr);
71489 if (is_on_stack == onstack)
71490 return;
71491
71492 diff --git a/lib/devres.c b/lib/devres.c
71493 index 80b9c76..9e32279 100644
71494 --- a/lib/devres.c
71495 +++ b/lib/devres.c
71496 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71497 void devm_iounmap(struct device *dev, void __iomem *addr)
71498 {
71499 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71500 - (void *)addr));
71501 + (void __force *)addr));
71502 iounmap(addr);
71503 }
71504 EXPORT_SYMBOL(devm_iounmap);
71505 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71506 {
71507 ioport_unmap(addr);
71508 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71509 - devm_ioport_map_match, (void *)addr));
71510 + devm_ioport_map_match, (void __force *)addr));
71511 }
71512 EXPORT_SYMBOL(devm_ioport_unmap);
71513
71514 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71515 index 66ce414..6f0a0dd 100644
71516 --- a/lib/dma-debug.c
71517 +++ b/lib/dma-debug.c
71518 @@ -924,7 +924,7 @@ out:
71519
71520 static void check_for_stack(struct device *dev, void *addr)
71521 {
71522 - if (object_is_on_stack(addr))
71523 + if (object_starts_on_stack(addr))
71524 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71525 "stack [addr=%p]\n", addr);
71526 }
71527 diff --git a/lib/inflate.c b/lib/inflate.c
71528 index 013a761..c28f3fc 100644
71529 --- a/lib/inflate.c
71530 +++ b/lib/inflate.c
71531 @@ -269,7 +269,7 @@ static void free(void *where)
71532 malloc_ptr = free_mem_ptr;
71533 }
71534 #else
71535 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71536 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71537 #define free(a) kfree(a)
71538 #endif
71539
71540 diff --git a/lib/ioremap.c b/lib/ioremap.c
71541 index 0c9216c..863bd89 100644
71542 --- a/lib/ioremap.c
71543 +++ b/lib/ioremap.c
71544 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71545 unsigned long next;
71546
71547 phys_addr -= addr;
71548 - pmd = pmd_alloc(&init_mm, pud, addr);
71549 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71550 if (!pmd)
71551 return -ENOMEM;
71552 do {
71553 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71554 unsigned long next;
71555
71556 phys_addr -= addr;
71557 - pud = pud_alloc(&init_mm, pgd, addr);
71558 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71559 if (!pud)
71560 return -ENOMEM;
71561 do {
71562 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71563 index bd2bea9..6b3c95e 100644
71564 --- a/lib/is_single_threaded.c
71565 +++ b/lib/is_single_threaded.c
71566 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71567 struct task_struct *p, *t;
71568 bool ret;
71569
71570 + if (!mm)
71571 + return true;
71572 +
71573 if (atomic_read(&task->signal->live) != 1)
71574 return false;
71575
71576 diff --git a/lib/list_debug.c b/lib/list_debug.c
71577 index c24c2f7..bef49ee 100644
71578 --- a/lib/list_debug.c
71579 +++ b/lib/list_debug.c
71580 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71581 struct list_head *prev,
71582 struct list_head *next)
71583 {
71584 - WARN(next->prev != prev,
71585 + if (WARN(next->prev != prev,
71586 "list_add corruption. next->prev should be "
71587 "prev (%p), but was %p. (next=%p).\n",
71588 - prev, next->prev, next);
71589 - WARN(prev->next != next,
71590 + prev, next->prev, next) ||
71591 + WARN(prev->next != next,
71592 "list_add corruption. prev->next should be "
71593 "next (%p), but was %p. (prev=%p).\n",
71594 - next, prev->next, prev);
71595 - WARN(new == prev || new == next,
71596 + next, prev->next, prev) ||
71597 + WARN(new == prev || new == next,
71598 "list_add double add: new=%p, prev=%p, next=%p.\n",
71599 - new, prev, next);
71600 + new, prev, next))
71601 + return;
71602 +
71603 next->prev = new;
71604 new->next = next;
71605 new->prev = prev;
71606 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71607 void __list_add_rcu(struct list_head *new,
71608 struct list_head *prev, struct list_head *next)
71609 {
71610 - WARN(next->prev != prev,
71611 + if (WARN(next->prev != prev,
71612 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71613 - prev, next->prev, next);
71614 - WARN(prev->next != next,
71615 + prev, next->prev, next) ||
71616 + WARN(prev->next != next,
71617 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71618 - next, prev->next, prev);
71619 + next, prev->next, prev))
71620 + return;
71621 +
71622 new->next = next;
71623 new->prev = prev;
71624 rcu_assign_pointer(list_next_rcu(prev), new);
71625 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71626 index e796429..6e38f9f 100644
71627 --- a/lib/radix-tree.c
71628 +++ b/lib/radix-tree.c
71629 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71630 int nr;
71631 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71632 };
71633 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71634 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71635
71636 static inline void *ptr_to_indirect(void *ptr)
71637 {
71638 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71639 index bb2b201..46abaf9 100644
71640 --- a/lib/strncpy_from_user.c
71641 +++ b/lib/strncpy_from_user.c
71642 @@ -21,7 +21,7 @@
71643 */
71644 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71645 {
71646 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71647 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71648 long res = 0;
71649
71650 /*
71651 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71652 index a28df52..3d55877 100644
71653 --- a/lib/strnlen_user.c
71654 +++ b/lib/strnlen_user.c
71655 @@ -26,7 +26,7 @@
71656 */
71657 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71658 {
71659 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71660 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71661 long align, res = 0;
71662 unsigned long c;
71663
71664 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71665 index 0e33754..50a0e63 100644
71666 --- a/lib/vsprintf.c
71667 +++ b/lib/vsprintf.c
71668 @@ -16,6 +16,9 @@
71669 * - scnprintf and vscnprintf
71670 */
71671
71672 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71673 +#define __INCLUDED_BY_HIDESYM 1
71674 +#endif
71675 #include <stdarg.h>
71676 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71677 #include <linux/types.h>
71678 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71679 char sym[KSYM_SYMBOL_LEN];
71680 if (ext == 'B')
71681 sprint_backtrace(sym, value);
71682 - else if (ext != 'f' && ext != 's')
71683 + else if (ext != 'f' && ext != 's' && ext != 'a')
71684 sprint_symbol(sym, value);
71685 else
71686 sprint_symbol_no_offset(sym, value);
71687 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71688 return number(buf, end, *(const netdev_features_t *)addr, spec);
71689 }
71690
71691 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71692 +int kptr_restrict __read_mostly = 2;
71693 +#else
71694 int kptr_restrict __read_mostly;
71695 +#endif
71696
71697 /*
71698 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71699 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71700 * - 'S' For symbolic direct pointers with offset
71701 * - 's' For symbolic direct pointers without offset
71702 * - 'B' For backtraced symbolic direct pointers with offset
71703 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71704 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71705 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71706 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71707 * - 'M' For a 6-byte MAC address, it prints the address in the
71708 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71709
71710 if (!ptr && *fmt != 'K') {
71711 /*
71712 - * Print (null) with the same width as a pointer so it makes
71713 + * Print (nil) with the same width as a pointer so it makes
71714 * tabular output look nice.
71715 */
71716 if (spec.field_width == -1)
71717 spec.field_width = default_width;
71718 - return string(buf, end, "(null)", spec);
71719 + return string(buf, end, "(nil)", spec);
71720 }
71721
71722 switch (*fmt) {
71723 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71724 /* Fallthrough */
71725 case 'S':
71726 case 's':
71727 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71728 + break;
71729 +#else
71730 + return symbol_string(buf, end, ptr, spec, *fmt);
71731 +#endif
71732 + case 'A':
71733 + case 'a':
71734 case 'B':
71735 return symbol_string(buf, end, ptr, spec, *fmt);
71736 case 'R':
71737 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71738 va_end(va);
71739 return buf;
71740 }
71741 + case 'P':
71742 + break;
71743 case 'K':
71744 /*
71745 * %pK cannot be used in IRQ context because its test
71746 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71747 }
71748 break;
71749 }
71750 +
71751 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71752 + /* 'P' = approved pointers to copy to userland,
71753 + as in the /proc/kallsyms case, as we make it display nothing
71754 + for non-root users, and the real contents for root users
71755 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71756 + above
71757 + */
71758 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71759 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71760 + dump_stack();
71761 + ptr = NULL;
71762 + }
71763 +#endif
71764 +
71765 spec.flags |= SMALL;
71766 if (spec.field_width == -1) {
71767 spec.field_width = default_width;
71768 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71769 typeof(type) value; \
71770 if (sizeof(type) == 8) { \
71771 args = PTR_ALIGN(args, sizeof(u32)); \
71772 - *(u32 *)&value = *(u32 *)args; \
71773 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71774 + *(u32 *)&value = *(const u32 *)args; \
71775 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71776 } else { \
71777 args = PTR_ALIGN(args, sizeof(type)); \
71778 - value = *(typeof(type) *)args; \
71779 + value = *(const typeof(type) *)args; \
71780 } \
71781 args += sizeof(type); \
71782 value; \
71783 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71784 case FORMAT_TYPE_STR: {
71785 const char *str_arg = args;
71786 args += strlen(str_arg) + 1;
71787 - str = string(str, end, (char *)str_arg, spec);
71788 + str = string(str, end, str_arg, spec);
71789 break;
71790 }
71791
71792 diff --git a/localversion-grsec b/localversion-grsec
71793 new file mode 100644
71794 index 0000000..7cd6065
71795 --- /dev/null
71796 +++ b/localversion-grsec
71797 @@ -0,0 +1 @@
71798 +-grsec
71799 diff --git a/mm/Kconfig b/mm/Kconfig
71800 index d5c8019..f513038 100644
71801 --- a/mm/Kconfig
71802 +++ b/mm/Kconfig
71803 @@ -251,10 +251,10 @@ config KSM
71804 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71805
71806 config DEFAULT_MMAP_MIN_ADDR
71807 - int "Low address space to protect from user allocation"
71808 + int "Low address space to protect from user allocation"
71809 depends on MMU
71810 - default 4096
71811 - help
71812 + default 65536
71813 + help
71814 This is the portion of low virtual memory which should be protected
71815 from userspace allocation. Keeping a user from writing to low pages
71816 can help reduce the impact of kernel NULL pointer bugs.
71817 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71818
71819 config HWPOISON_INJECT
71820 tristate "HWPoison pages injector"
71821 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71822 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71823 select PROC_PAGE_MONITOR
71824
71825 config NOMMU_INITIAL_TRIM_EXCESS
71826 diff --git a/mm/filemap.c b/mm/filemap.c
71827 index 3843445..4fe6833 100644
71828 --- a/mm/filemap.c
71829 +++ b/mm/filemap.c
71830 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71831 struct address_space *mapping = file->f_mapping;
71832
71833 if (!mapping->a_ops->readpage)
71834 - return -ENOEXEC;
71835 + return -ENODEV;
71836 file_accessed(file);
71837 vma->vm_ops = &generic_file_vm_ops;
71838 vma->vm_flags |= VM_CAN_NONLINEAR;
71839 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71840 *pos = i_size_read(inode);
71841
71842 if (limit != RLIM_INFINITY) {
71843 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71844 if (*pos >= limit) {
71845 send_sig(SIGXFSZ, current, 0);
71846 return -EFBIG;
71847 diff --git a/mm/fremap.c b/mm/fremap.c
71848 index 9ed4fd4..c42648d 100644
71849 --- a/mm/fremap.c
71850 +++ b/mm/fremap.c
71851 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71852 retry:
71853 vma = find_vma(mm, start);
71854
71855 +#ifdef CONFIG_PAX_SEGMEXEC
71856 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71857 + goto out;
71858 +#endif
71859 +
71860 /*
71861 * Make sure the vma is shared, that it supports prefaulting,
71862 * and that the remapped range is valid and fully within
71863 diff --git a/mm/highmem.c b/mm/highmem.c
71864 index d517cd1..006a1c5 100644
71865 --- a/mm/highmem.c
71866 +++ b/mm/highmem.c
71867 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71868 * So no dangers, even with speculative execution.
71869 */
71870 page = pte_page(pkmap_page_table[i]);
71871 + pax_open_kernel();
71872 pte_clear(&init_mm, (unsigned long)page_address(page),
71873 &pkmap_page_table[i]);
71874 -
71875 + pax_close_kernel();
71876 set_page_address(page, NULL);
71877 need_flush = 1;
71878 }
71879 @@ -198,9 +199,11 @@ start:
71880 }
71881 }
71882 vaddr = PKMAP_ADDR(last_pkmap_nr);
71883 +
71884 + pax_open_kernel();
71885 set_pte_at(&init_mm, vaddr,
71886 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71887 -
71888 + pax_close_kernel();
71889 pkmap_count[last_pkmap_nr] = 1;
71890 set_page_address(page, (void *)vaddr);
71891
71892 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71893 index 141dbb6..ebff057 100644
71894 --- a/mm/huge_memory.c
71895 +++ b/mm/huge_memory.c
71896 @@ -735,7 +735,7 @@ out:
71897 * run pte_offset_map on the pmd, if an huge pmd could
71898 * materialize from under us from a different thread.
71899 */
71900 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71901 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71902 return VM_FAULT_OOM;
71903 /* if an huge pmd materialized from under us just retry later */
71904 if (unlikely(pmd_trans_huge(*pmd)))
71905 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71906 index 3adceaf..dccfea3 100644
71907 --- a/mm/hugetlb.c
71908 +++ b/mm/hugetlb.c
71909 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71910 return 1;
71911 }
71912
71913 +#ifdef CONFIG_PAX_SEGMEXEC
71914 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71915 +{
71916 + struct mm_struct *mm = vma->vm_mm;
71917 + struct vm_area_struct *vma_m;
71918 + unsigned long address_m;
71919 + pte_t *ptep_m;
71920 +
71921 + vma_m = pax_find_mirror_vma(vma);
71922 + if (!vma_m)
71923 + return;
71924 +
71925 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71926 + address_m = address + SEGMEXEC_TASK_SIZE;
71927 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71928 + get_page(page_m);
71929 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71930 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71931 +}
71932 +#endif
71933 +
71934 /*
71935 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71936 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71937 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71938 make_huge_pte(vma, new_page, 1));
71939 page_remove_rmap(old_page);
71940 hugepage_add_new_anon_rmap(new_page, vma, address);
71941 +
71942 +#ifdef CONFIG_PAX_SEGMEXEC
71943 + pax_mirror_huge_pte(vma, address, new_page);
71944 +#endif
71945 +
71946 /* Make the old page be freed below */
71947 new_page = old_page;
71948 mmu_notifier_invalidate_range_end(mm,
71949 @@ -2786,6 +2812,10 @@ retry:
71950 && (vma->vm_flags & VM_SHARED)));
71951 set_huge_pte_at(mm, address, ptep, new_pte);
71952
71953 +#ifdef CONFIG_PAX_SEGMEXEC
71954 + pax_mirror_huge_pte(vma, address, page);
71955 +#endif
71956 +
71957 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71958 /* Optimization, do the COW without a second fault */
71959 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71960 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71961 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71962 struct hstate *h = hstate_vma(vma);
71963
71964 +#ifdef CONFIG_PAX_SEGMEXEC
71965 + struct vm_area_struct *vma_m;
71966 +#endif
71967 +
71968 address &= huge_page_mask(h);
71969
71970 ptep = huge_pte_offset(mm, address);
71971 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71972 VM_FAULT_SET_HINDEX(hstate_index(h));
71973 }
71974
71975 +#ifdef CONFIG_PAX_SEGMEXEC
71976 + vma_m = pax_find_mirror_vma(vma);
71977 + if (vma_m) {
71978 + unsigned long address_m;
71979 +
71980 + if (vma->vm_start > vma_m->vm_start) {
71981 + address_m = address;
71982 + address -= SEGMEXEC_TASK_SIZE;
71983 + vma = vma_m;
71984 + h = hstate_vma(vma);
71985 + } else
71986 + address_m = address + SEGMEXEC_TASK_SIZE;
71987 +
71988 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71989 + return VM_FAULT_OOM;
71990 + address_m &= HPAGE_MASK;
71991 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71992 + }
71993 +#endif
71994 +
71995 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71996 if (!ptep)
71997 return VM_FAULT_OOM;
71998 diff --git a/mm/internal.h b/mm/internal.h
71999 index b8c91b3..93e95a3 100644
72000 --- a/mm/internal.h
72001 +++ b/mm/internal.h
72002 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72003 * in mm/page_alloc.c
72004 */
72005 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72006 +extern void free_compound_page(struct page *page);
72007 extern void prep_compound_page(struct page *page, unsigned long order);
72008 #ifdef CONFIG_MEMORY_FAILURE
72009 extern bool is_free_buddy_page(struct page *page);
72010 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72011 index 45eb621..6ccd8ea 100644
72012 --- a/mm/kmemleak.c
72013 +++ b/mm/kmemleak.c
72014 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72015
72016 for (i = 0; i < object->trace_len; i++) {
72017 void *ptr = (void *)object->trace[i];
72018 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72019 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72020 }
72021 }
72022
72023 diff --git a/mm/maccess.c b/mm/maccess.c
72024 index d53adf9..03a24bf 100644
72025 --- a/mm/maccess.c
72026 +++ b/mm/maccess.c
72027 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72028 set_fs(KERNEL_DS);
72029 pagefault_disable();
72030 ret = __copy_from_user_inatomic(dst,
72031 - (__force const void __user *)src, size);
72032 + (const void __force_user *)src, size);
72033 pagefault_enable();
72034 set_fs(old_fs);
72035
72036 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72037
72038 set_fs(KERNEL_DS);
72039 pagefault_disable();
72040 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72041 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72042 pagefault_enable();
72043 set_fs(old_fs);
72044
72045 diff --git a/mm/madvise.c b/mm/madvise.c
72046 index 14d260f..b2a80fd 100644
72047 --- a/mm/madvise.c
72048 +++ b/mm/madvise.c
72049 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72050 pgoff_t pgoff;
72051 unsigned long new_flags = vma->vm_flags;
72052
72053 +#ifdef CONFIG_PAX_SEGMEXEC
72054 + struct vm_area_struct *vma_m;
72055 +#endif
72056 +
72057 switch (behavior) {
72058 case MADV_NORMAL:
72059 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72060 @@ -119,6 +123,13 @@ success:
72061 /*
72062 * vm_flags is protected by the mmap_sem held in write mode.
72063 */
72064 +
72065 +#ifdef CONFIG_PAX_SEGMEXEC
72066 + vma_m = pax_find_mirror_vma(vma);
72067 + if (vma_m)
72068 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72069 +#endif
72070 +
72071 vma->vm_flags = new_flags;
72072
72073 out:
72074 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72075 struct vm_area_struct ** prev,
72076 unsigned long start, unsigned long end)
72077 {
72078 +
72079 +#ifdef CONFIG_PAX_SEGMEXEC
72080 + struct vm_area_struct *vma_m;
72081 +#endif
72082 +
72083 *prev = vma;
72084 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72085 return -EINVAL;
72086 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72087 zap_page_range(vma, start, end - start, &details);
72088 } else
72089 zap_page_range(vma, start, end - start, NULL);
72090 +
72091 +#ifdef CONFIG_PAX_SEGMEXEC
72092 + vma_m = pax_find_mirror_vma(vma);
72093 + if (vma_m) {
72094 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72095 + struct zap_details details = {
72096 + .nonlinear_vma = vma_m,
72097 + .last_index = ULONG_MAX,
72098 + };
72099 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72100 + } else
72101 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72102 + }
72103 +#endif
72104 +
72105 return 0;
72106 }
72107
72108 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72109 if (end < start)
72110 goto out;
72111
72112 +#ifdef CONFIG_PAX_SEGMEXEC
72113 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72114 + if (end > SEGMEXEC_TASK_SIZE)
72115 + goto out;
72116 + } else
72117 +#endif
72118 +
72119 + if (end > TASK_SIZE)
72120 + goto out;
72121 +
72122 error = 0;
72123 if (end == start)
72124 goto out;
72125 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72126 index a6e2141..eaf5aad 100644
72127 --- a/mm/memory-failure.c
72128 +++ b/mm/memory-failure.c
72129 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72130
72131 int sysctl_memory_failure_recovery __read_mostly = 1;
72132
72133 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72134 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72135
72136 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72137
72138 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72139 pfn, t->comm, t->pid);
72140 si.si_signo = SIGBUS;
72141 si.si_errno = 0;
72142 - si.si_addr = (void *)addr;
72143 + si.si_addr = (void __user *)addr;
72144 #ifdef __ARCH_SI_TRAPNO
72145 si.si_trapno = trapno;
72146 #endif
72147 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72148 }
72149
72150 nr_pages = 1 << compound_trans_order(hpage);
72151 - atomic_long_add(nr_pages, &mce_bad_pages);
72152 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72153
72154 /*
72155 * We need/can do nothing about count=0 pages.
72156 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72157 if (!PageHWPoison(hpage)
72158 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72159 || (p != hpage && TestSetPageHWPoison(hpage))) {
72160 - atomic_long_sub(nr_pages, &mce_bad_pages);
72161 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72162 return 0;
72163 }
72164 set_page_hwpoison_huge_page(hpage);
72165 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72166 }
72167 if (hwpoison_filter(p)) {
72168 if (TestClearPageHWPoison(p))
72169 - atomic_long_sub(nr_pages, &mce_bad_pages);
72170 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72171 unlock_page(hpage);
72172 put_page(hpage);
72173 return 0;
72174 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72175 return 0;
72176 }
72177 if (TestClearPageHWPoison(p))
72178 - atomic_long_sub(nr_pages, &mce_bad_pages);
72179 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72180 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72181 return 0;
72182 }
72183 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72184 */
72185 if (TestClearPageHWPoison(page)) {
72186 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72187 - atomic_long_sub(nr_pages, &mce_bad_pages);
72188 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72189 freeit = 1;
72190 if (PageHuge(page))
72191 clear_page_hwpoison_huge_page(page);
72192 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72193 }
72194 done:
72195 if (!PageHWPoison(hpage))
72196 - atomic_long_add(1 << compound_trans_order(hpage),
72197 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72198 &mce_bad_pages);
72199 set_page_hwpoison_huge_page(hpage);
72200 dequeue_hwpoisoned_huge_page(hpage);
72201 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72202 return ret;
72203
72204 done:
72205 - atomic_long_add(1, &mce_bad_pages);
72206 + atomic_long_add_unchecked(1, &mce_bad_pages);
72207 SetPageHWPoison(page);
72208 /* keep elevated page count for bad page */
72209 return ret;
72210 diff --git a/mm/memory.c b/mm/memory.c
72211 index 5736170..8e04800 100644
72212 --- a/mm/memory.c
72213 +++ b/mm/memory.c
72214 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72215 free_pte_range(tlb, pmd, addr);
72216 } while (pmd++, addr = next, addr != end);
72217
72218 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72219 start &= PUD_MASK;
72220 if (start < floor)
72221 return;
72222 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72223 pmd = pmd_offset(pud, start);
72224 pud_clear(pud);
72225 pmd_free_tlb(tlb, pmd, start);
72226 +#endif
72227 +
72228 }
72229
72230 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72231 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72232 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72233 } while (pud++, addr = next, addr != end);
72234
72235 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72236 start &= PGDIR_MASK;
72237 if (start < floor)
72238 return;
72239 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72240 pud = pud_offset(pgd, start);
72241 pgd_clear(pgd);
72242 pud_free_tlb(tlb, pud, start);
72243 +#endif
72244 +
72245 }
72246
72247 /*
72248 @@ -1614,12 +1620,6 @@ no_page_table:
72249 return page;
72250 }
72251
72252 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72253 -{
72254 - return stack_guard_page_start(vma, addr) ||
72255 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72256 -}
72257 -
72258 /**
72259 * __get_user_pages() - pin user pages in memory
72260 * @tsk: task_struct of target task
72261 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72262 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72263 i = 0;
72264
72265 - do {
72266 + while (nr_pages) {
72267 struct vm_area_struct *vma;
72268
72269 - vma = find_extend_vma(mm, start);
72270 + vma = find_vma(mm, start);
72271 if (!vma && in_gate_area(mm, start)) {
72272 unsigned long pg = start & PAGE_MASK;
72273 pgd_t *pgd;
72274 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72275 goto next_page;
72276 }
72277
72278 - if (!vma ||
72279 + if (!vma || start < vma->vm_start ||
72280 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72281 !(vm_flags & vma->vm_flags))
72282 return i ? : -EFAULT;
72283 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72284 int ret;
72285 unsigned int fault_flags = 0;
72286
72287 - /* For mlock, just skip the stack guard page. */
72288 - if (foll_flags & FOLL_MLOCK) {
72289 - if (stack_guard_page(vma, start))
72290 - goto next_page;
72291 - }
72292 if (foll_flags & FOLL_WRITE)
72293 fault_flags |= FAULT_FLAG_WRITE;
72294 if (nonblocking)
72295 @@ -1848,7 +1843,7 @@ next_page:
72296 start += PAGE_SIZE;
72297 nr_pages--;
72298 } while (nr_pages && start < vma->vm_end);
72299 - } while (nr_pages);
72300 + }
72301 return i;
72302 }
72303 EXPORT_SYMBOL(__get_user_pages);
72304 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72305 page_add_file_rmap(page);
72306 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72307
72308 +#ifdef CONFIG_PAX_SEGMEXEC
72309 + pax_mirror_file_pte(vma, addr, page, ptl);
72310 +#endif
72311 +
72312 retval = 0;
72313 pte_unmap_unlock(pte, ptl);
72314 return retval;
72315 @@ -2089,10 +2088,22 @@ out:
72316 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72317 struct page *page)
72318 {
72319 +
72320 +#ifdef CONFIG_PAX_SEGMEXEC
72321 + struct vm_area_struct *vma_m;
72322 +#endif
72323 +
72324 if (addr < vma->vm_start || addr >= vma->vm_end)
72325 return -EFAULT;
72326 if (!page_count(page))
72327 return -EINVAL;
72328 +
72329 +#ifdef CONFIG_PAX_SEGMEXEC
72330 + vma_m = pax_find_mirror_vma(vma);
72331 + if (vma_m)
72332 + vma_m->vm_flags |= VM_INSERTPAGE;
72333 +#endif
72334 +
72335 vma->vm_flags |= VM_INSERTPAGE;
72336 return insert_page(vma, addr, page, vma->vm_page_prot);
72337 }
72338 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72339 unsigned long pfn)
72340 {
72341 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72342 + BUG_ON(vma->vm_mirror);
72343
72344 if (addr < vma->vm_start || addr >= vma->vm_end)
72345 return -EFAULT;
72346 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72347
72348 BUG_ON(pud_huge(*pud));
72349
72350 - pmd = pmd_alloc(mm, pud, addr);
72351 + pmd = (mm == &init_mm) ?
72352 + pmd_alloc_kernel(mm, pud, addr) :
72353 + pmd_alloc(mm, pud, addr);
72354 if (!pmd)
72355 return -ENOMEM;
72356 do {
72357 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72358 unsigned long next;
72359 int err;
72360
72361 - pud = pud_alloc(mm, pgd, addr);
72362 + pud = (mm == &init_mm) ?
72363 + pud_alloc_kernel(mm, pgd, addr) :
72364 + pud_alloc(mm, pgd, addr);
72365 if (!pud)
72366 return -ENOMEM;
72367 do {
72368 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72369 copy_user_highpage(dst, src, va, vma);
72370 }
72371
72372 +#ifdef CONFIG_PAX_SEGMEXEC
72373 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72374 +{
72375 + struct mm_struct *mm = vma->vm_mm;
72376 + spinlock_t *ptl;
72377 + pte_t *pte, entry;
72378 +
72379 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72380 + entry = *pte;
72381 + if (!pte_present(entry)) {
72382 + if (!pte_none(entry)) {
72383 + BUG_ON(pte_file(entry));
72384 + free_swap_and_cache(pte_to_swp_entry(entry));
72385 + pte_clear_not_present_full(mm, address, pte, 0);
72386 + }
72387 + } else {
72388 + struct page *page;
72389 +
72390 + flush_cache_page(vma, address, pte_pfn(entry));
72391 + entry = ptep_clear_flush(vma, address, pte);
72392 + BUG_ON(pte_dirty(entry));
72393 + page = vm_normal_page(vma, address, entry);
72394 + if (page) {
72395 + update_hiwater_rss(mm);
72396 + if (PageAnon(page))
72397 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72398 + else
72399 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72400 + page_remove_rmap(page);
72401 + page_cache_release(page);
72402 + }
72403 + }
72404 + pte_unmap_unlock(pte, ptl);
72405 +}
72406 +
72407 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72408 + *
72409 + * the ptl of the lower mapped page is held on entry and is not released on exit
72410 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72411 + */
72412 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72413 +{
72414 + struct mm_struct *mm = vma->vm_mm;
72415 + unsigned long address_m;
72416 + spinlock_t *ptl_m;
72417 + struct vm_area_struct *vma_m;
72418 + pmd_t *pmd_m;
72419 + pte_t *pte_m, entry_m;
72420 +
72421 + BUG_ON(!page_m || !PageAnon(page_m));
72422 +
72423 + vma_m = pax_find_mirror_vma(vma);
72424 + if (!vma_m)
72425 + return;
72426 +
72427 + BUG_ON(!PageLocked(page_m));
72428 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72429 + address_m = address + SEGMEXEC_TASK_SIZE;
72430 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72431 + pte_m = pte_offset_map(pmd_m, address_m);
72432 + ptl_m = pte_lockptr(mm, pmd_m);
72433 + if (ptl != ptl_m) {
72434 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72435 + if (!pte_none(*pte_m))
72436 + goto out;
72437 + }
72438 +
72439 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72440 + page_cache_get(page_m);
72441 + page_add_anon_rmap(page_m, vma_m, address_m);
72442 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72443 + set_pte_at(mm, address_m, pte_m, entry_m);
72444 + update_mmu_cache(vma_m, address_m, entry_m);
72445 +out:
72446 + if (ptl != ptl_m)
72447 + spin_unlock(ptl_m);
72448 + pte_unmap(pte_m);
72449 + unlock_page(page_m);
72450 +}
72451 +
72452 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72453 +{
72454 + struct mm_struct *mm = vma->vm_mm;
72455 + unsigned long address_m;
72456 + spinlock_t *ptl_m;
72457 + struct vm_area_struct *vma_m;
72458 + pmd_t *pmd_m;
72459 + pte_t *pte_m, entry_m;
72460 +
72461 + BUG_ON(!page_m || PageAnon(page_m));
72462 +
72463 + vma_m = pax_find_mirror_vma(vma);
72464 + if (!vma_m)
72465 + return;
72466 +
72467 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72468 + address_m = address + SEGMEXEC_TASK_SIZE;
72469 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72470 + pte_m = pte_offset_map(pmd_m, address_m);
72471 + ptl_m = pte_lockptr(mm, pmd_m);
72472 + if (ptl != ptl_m) {
72473 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72474 + if (!pte_none(*pte_m))
72475 + goto out;
72476 + }
72477 +
72478 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72479 + page_cache_get(page_m);
72480 + page_add_file_rmap(page_m);
72481 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72482 + set_pte_at(mm, address_m, pte_m, entry_m);
72483 + update_mmu_cache(vma_m, address_m, entry_m);
72484 +out:
72485 + if (ptl != ptl_m)
72486 + spin_unlock(ptl_m);
72487 + pte_unmap(pte_m);
72488 +}
72489 +
72490 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72491 +{
72492 + struct mm_struct *mm = vma->vm_mm;
72493 + unsigned long address_m;
72494 + spinlock_t *ptl_m;
72495 + struct vm_area_struct *vma_m;
72496 + pmd_t *pmd_m;
72497 + pte_t *pte_m, entry_m;
72498 +
72499 + vma_m = pax_find_mirror_vma(vma);
72500 + if (!vma_m)
72501 + return;
72502 +
72503 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72504 + address_m = address + SEGMEXEC_TASK_SIZE;
72505 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72506 + pte_m = pte_offset_map(pmd_m, address_m);
72507 + ptl_m = pte_lockptr(mm, pmd_m);
72508 + if (ptl != ptl_m) {
72509 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72510 + if (!pte_none(*pte_m))
72511 + goto out;
72512 + }
72513 +
72514 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72515 + set_pte_at(mm, address_m, pte_m, entry_m);
72516 +out:
72517 + if (ptl != ptl_m)
72518 + spin_unlock(ptl_m);
72519 + pte_unmap(pte_m);
72520 +}
72521 +
72522 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72523 +{
72524 + struct page *page_m;
72525 + pte_t entry;
72526 +
72527 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72528 + goto out;
72529 +
72530 + entry = *pte;
72531 + page_m = vm_normal_page(vma, address, entry);
72532 + if (!page_m)
72533 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72534 + else if (PageAnon(page_m)) {
72535 + if (pax_find_mirror_vma(vma)) {
72536 + pte_unmap_unlock(pte, ptl);
72537 + lock_page(page_m);
72538 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72539 + if (pte_same(entry, *pte))
72540 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72541 + else
72542 + unlock_page(page_m);
72543 + }
72544 + } else
72545 + pax_mirror_file_pte(vma, address, page_m, ptl);
72546 +
72547 +out:
72548 + pte_unmap_unlock(pte, ptl);
72549 +}
72550 +#endif
72551 +
72552 /*
72553 * This routine handles present pages, when users try to write
72554 * to a shared page. It is done by copying the page to a new address
72555 @@ -2703,6 +2899,12 @@ gotten:
72556 */
72557 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72558 if (likely(pte_same(*page_table, orig_pte))) {
72559 +
72560 +#ifdef CONFIG_PAX_SEGMEXEC
72561 + if (pax_find_mirror_vma(vma))
72562 + BUG_ON(!trylock_page(new_page));
72563 +#endif
72564 +
72565 if (old_page) {
72566 if (!PageAnon(old_page)) {
72567 dec_mm_counter_fast(mm, MM_FILEPAGES);
72568 @@ -2754,6 +2956,10 @@ gotten:
72569 page_remove_rmap(old_page);
72570 }
72571
72572 +#ifdef CONFIG_PAX_SEGMEXEC
72573 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72574 +#endif
72575 +
72576 /* Free the old page.. */
72577 new_page = old_page;
72578 ret |= VM_FAULT_WRITE;
72579 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72580 swap_free(entry);
72581 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72582 try_to_free_swap(page);
72583 +
72584 +#ifdef CONFIG_PAX_SEGMEXEC
72585 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72586 +#endif
72587 +
72588 unlock_page(page);
72589 if (swapcache) {
72590 /*
72591 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72592
72593 /* No need to invalidate - it was non-present before */
72594 update_mmu_cache(vma, address, page_table);
72595 +
72596 +#ifdef CONFIG_PAX_SEGMEXEC
72597 + pax_mirror_anon_pte(vma, address, page, ptl);
72598 +#endif
72599 +
72600 unlock:
72601 pte_unmap_unlock(page_table, ptl);
72602 out:
72603 @@ -3075,40 +3291,6 @@ out_release:
72604 }
72605
72606 /*
72607 - * This is like a special single-page "expand_{down|up}wards()",
72608 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72609 - * doesn't hit another vma.
72610 - */
72611 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72612 -{
72613 - address &= PAGE_MASK;
72614 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72615 - struct vm_area_struct *prev = vma->vm_prev;
72616 -
72617 - /*
72618 - * Is there a mapping abutting this one below?
72619 - *
72620 - * That's only ok if it's the same stack mapping
72621 - * that has gotten split..
72622 - */
72623 - if (prev && prev->vm_end == address)
72624 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72625 -
72626 - expand_downwards(vma, address - PAGE_SIZE);
72627 - }
72628 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72629 - struct vm_area_struct *next = vma->vm_next;
72630 -
72631 - /* As VM_GROWSDOWN but s/below/above/ */
72632 - if (next && next->vm_start == address + PAGE_SIZE)
72633 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72634 -
72635 - expand_upwards(vma, address + PAGE_SIZE);
72636 - }
72637 - return 0;
72638 -}
72639 -
72640 -/*
72641 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72642 * but allow concurrent faults), and pte mapped but not yet locked.
72643 * We return with mmap_sem still held, but pte unmapped and unlocked.
72644 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72645 unsigned long address, pte_t *page_table, pmd_t *pmd,
72646 unsigned int flags)
72647 {
72648 - struct page *page;
72649 + struct page *page = NULL;
72650 spinlock_t *ptl;
72651 pte_t entry;
72652
72653 - pte_unmap(page_table);
72654 -
72655 - /* Check if we need to add a guard page to the stack */
72656 - if (check_stack_guard_page(vma, address) < 0)
72657 - return VM_FAULT_SIGBUS;
72658 -
72659 - /* Use the zero-page for reads */
72660 if (!(flags & FAULT_FLAG_WRITE)) {
72661 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72662 vma->vm_page_prot));
72663 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72664 + ptl = pte_lockptr(mm, pmd);
72665 + spin_lock(ptl);
72666 if (!pte_none(*page_table))
72667 goto unlock;
72668 goto setpte;
72669 }
72670
72671 /* Allocate our own private page. */
72672 + pte_unmap(page_table);
72673 +
72674 if (unlikely(anon_vma_prepare(vma)))
72675 goto oom;
72676 page = alloc_zeroed_user_highpage_movable(vma, address);
72677 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72678 if (!pte_none(*page_table))
72679 goto release;
72680
72681 +#ifdef CONFIG_PAX_SEGMEXEC
72682 + if (pax_find_mirror_vma(vma))
72683 + BUG_ON(!trylock_page(page));
72684 +#endif
72685 +
72686 inc_mm_counter_fast(mm, MM_ANONPAGES);
72687 page_add_new_anon_rmap(page, vma, address);
72688 setpte:
72689 @@ -3163,6 +3346,12 @@ setpte:
72690
72691 /* No need to invalidate - it was non-present before */
72692 update_mmu_cache(vma, address, page_table);
72693 +
72694 +#ifdef CONFIG_PAX_SEGMEXEC
72695 + if (page)
72696 + pax_mirror_anon_pte(vma, address, page, ptl);
72697 +#endif
72698 +
72699 unlock:
72700 pte_unmap_unlock(page_table, ptl);
72701 return 0;
72702 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72703 */
72704 /* Only go through if we didn't race with anybody else... */
72705 if (likely(pte_same(*page_table, orig_pte))) {
72706 +
72707 +#ifdef CONFIG_PAX_SEGMEXEC
72708 + if (anon && pax_find_mirror_vma(vma))
72709 + BUG_ON(!trylock_page(page));
72710 +#endif
72711 +
72712 flush_icache_page(vma, page);
72713 entry = mk_pte(page, vma->vm_page_prot);
72714 if (flags & FAULT_FLAG_WRITE)
72715 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72716
72717 /* no need to invalidate: a not-present page won't be cached */
72718 update_mmu_cache(vma, address, page_table);
72719 +
72720 +#ifdef CONFIG_PAX_SEGMEXEC
72721 + if (anon)
72722 + pax_mirror_anon_pte(vma, address, page, ptl);
72723 + else
72724 + pax_mirror_file_pte(vma, address, page, ptl);
72725 +#endif
72726 +
72727 } else {
72728 if (cow_page)
72729 mem_cgroup_uncharge_page(cow_page);
72730 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72731 if (flags & FAULT_FLAG_WRITE)
72732 flush_tlb_fix_spurious_fault(vma, address);
72733 }
72734 +
72735 +#ifdef CONFIG_PAX_SEGMEXEC
72736 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72737 + return 0;
72738 +#endif
72739 +
72740 unlock:
72741 pte_unmap_unlock(pte, ptl);
72742 return 0;
72743 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72744 pmd_t *pmd;
72745 pte_t *pte;
72746
72747 +#ifdef CONFIG_PAX_SEGMEXEC
72748 + struct vm_area_struct *vma_m;
72749 +#endif
72750 +
72751 __set_current_state(TASK_RUNNING);
72752
72753 count_vm_event(PGFAULT);
72754 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72755 if (unlikely(is_vm_hugetlb_page(vma)))
72756 return hugetlb_fault(mm, vma, address, flags);
72757
72758 +#ifdef CONFIG_PAX_SEGMEXEC
72759 + vma_m = pax_find_mirror_vma(vma);
72760 + if (vma_m) {
72761 + unsigned long address_m;
72762 + pgd_t *pgd_m;
72763 + pud_t *pud_m;
72764 + pmd_t *pmd_m;
72765 +
72766 + if (vma->vm_start > vma_m->vm_start) {
72767 + address_m = address;
72768 + address -= SEGMEXEC_TASK_SIZE;
72769 + vma = vma_m;
72770 + } else
72771 + address_m = address + SEGMEXEC_TASK_SIZE;
72772 +
72773 + pgd_m = pgd_offset(mm, address_m);
72774 + pud_m = pud_alloc(mm, pgd_m, address_m);
72775 + if (!pud_m)
72776 + return VM_FAULT_OOM;
72777 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72778 + if (!pmd_m)
72779 + return VM_FAULT_OOM;
72780 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72781 + return VM_FAULT_OOM;
72782 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72783 + }
72784 +#endif
72785 +
72786 retry:
72787 pgd = pgd_offset(mm, address);
72788 pud = pud_alloc(mm, pgd, address);
72789 @@ -3547,7 +3788,7 @@ retry:
72790 * run pte_offset_map on the pmd, if an huge pmd could
72791 * materialize from under us from a different thread.
72792 */
72793 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72794 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72795 return VM_FAULT_OOM;
72796 /* if an huge pmd materialized from under us just retry later */
72797 if (unlikely(pmd_trans_huge(*pmd)))
72798 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72799 spin_unlock(&mm->page_table_lock);
72800 return 0;
72801 }
72802 +
72803 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72804 +{
72805 + pud_t *new = pud_alloc_one(mm, address);
72806 + if (!new)
72807 + return -ENOMEM;
72808 +
72809 + smp_wmb(); /* See comment in __pte_alloc */
72810 +
72811 + spin_lock(&mm->page_table_lock);
72812 + if (pgd_present(*pgd)) /* Another has populated it */
72813 + pud_free(mm, new);
72814 + else
72815 + pgd_populate_kernel(mm, pgd, new);
72816 + spin_unlock(&mm->page_table_lock);
72817 + return 0;
72818 +}
72819 #endif /* __PAGETABLE_PUD_FOLDED */
72820
72821 #ifndef __PAGETABLE_PMD_FOLDED
72822 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72823 spin_unlock(&mm->page_table_lock);
72824 return 0;
72825 }
72826 +
72827 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72828 +{
72829 + pmd_t *new = pmd_alloc_one(mm, address);
72830 + if (!new)
72831 + return -ENOMEM;
72832 +
72833 + smp_wmb(); /* See comment in __pte_alloc */
72834 +
72835 + spin_lock(&mm->page_table_lock);
72836 +#ifndef __ARCH_HAS_4LEVEL_HACK
72837 + if (pud_present(*pud)) /* Another has populated it */
72838 + pmd_free(mm, new);
72839 + else
72840 + pud_populate_kernel(mm, pud, new);
72841 +#else
72842 + if (pgd_present(*pud)) /* Another has populated it */
72843 + pmd_free(mm, new);
72844 + else
72845 + pgd_populate_kernel(mm, pud, new);
72846 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72847 + spin_unlock(&mm->page_table_lock);
72848 + return 0;
72849 +}
72850 #endif /* __PAGETABLE_PMD_FOLDED */
72851
72852 int make_pages_present(unsigned long addr, unsigned long end)
72853 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72854 gate_vma.vm_start = FIXADDR_USER_START;
72855 gate_vma.vm_end = FIXADDR_USER_END;
72856 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72857 - gate_vma.vm_page_prot = __P101;
72858 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72859
72860 return 0;
72861 }
72862 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72863 index 3d64b36..c6ab69c 100644
72864 --- a/mm/mempolicy.c
72865 +++ b/mm/mempolicy.c
72866 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72867 unsigned long vmstart;
72868 unsigned long vmend;
72869
72870 +#ifdef CONFIG_PAX_SEGMEXEC
72871 + struct vm_area_struct *vma_m;
72872 +#endif
72873 +
72874 vma = find_vma(mm, start);
72875 if (!vma || vma->vm_start > start)
72876 return -EFAULT;
72877 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72878 if (err)
72879 goto out;
72880 }
72881 +
72882 err = vma_replace_policy(vma, new_pol);
72883 if (err)
72884 goto out;
72885 +
72886 +#ifdef CONFIG_PAX_SEGMEXEC
72887 + vma_m = pax_find_mirror_vma(vma);
72888 + if (vma_m) {
72889 + err = vma_replace_policy(vma_m, new_pol);
72890 + if (err)
72891 + goto out;
72892 + }
72893 +#endif
72894 +
72895 }
72896
72897 out:
72898 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72899
72900 if (end < start)
72901 return -EINVAL;
72902 +
72903 +#ifdef CONFIG_PAX_SEGMEXEC
72904 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72905 + if (end > SEGMEXEC_TASK_SIZE)
72906 + return -EINVAL;
72907 + } else
72908 +#endif
72909 +
72910 + if (end > TASK_SIZE)
72911 + return -EINVAL;
72912 +
72913 if (end == start)
72914 return 0;
72915
72916 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72917 */
72918 tcred = __task_cred(task);
72919 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72920 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72921 - !capable(CAP_SYS_NICE)) {
72922 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72923 rcu_read_unlock();
72924 err = -EPERM;
72925 goto out_put;
72926 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72927 goto out;
72928 }
72929
72930 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72931 + if (mm != current->mm &&
72932 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72933 + mmput(mm);
72934 + err = -EPERM;
72935 + goto out;
72936 + }
72937 +#endif
72938 +
72939 err = do_migrate_pages(mm, old, new,
72940 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72941
72942 diff --git a/mm/migrate.c b/mm/migrate.c
72943 index 77ed2d7..317d528 100644
72944 --- a/mm/migrate.c
72945 +++ b/mm/migrate.c
72946 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72947 */
72948 tcred = __task_cred(task);
72949 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72950 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72951 - !capable(CAP_SYS_NICE)) {
72952 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72953 rcu_read_unlock();
72954 err = -EPERM;
72955 goto out;
72956 diff --git a/mm/mlock.c b/mm/mlock.c
72957 index ef726e8..cd7f1ec 100644
72958 --- a/mm/mlock.c
72959 +++ b/mm/mlock.c
72960 @@ -13,6 +13,7 @@
72961 #include <linux/pagemap.h>
72962 #include <linux/mempolicy.h>
72963 #include <linux/syscalls.h>
72964 +#include <linux/security.h>
72965 #include <linux/sched.h>
72966 #include <linux/export.h>
72967 #include <linux/rmap.h>
72968 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72969 {
72970 unsigned long nstart, end, tmp;
72971 struct vm_area_struct * vma, * prev;
72972 - int error;
72973 + int error = 0;
72974
72975 VM_BUG_ON(start & ~PAGE_MASK);
72976 VM_BUG_ON(len != PAGE_ALIGN(len));
72977 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72978 return -EINVAL;
72979 if (end == start)
72980 return 0;
72981 + if (end > TASK_SIZE)
72982 + return -EINVAL;
72983 +
72984 vma = find_vma(current->mm, start);
72985 if (!vma || vma->vm_start > start)
72986 return -ENOMEM;
72987 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72988 for (nstart = start ; ; ) {
72989 vm_flags_t newflags;
72990
72991 +#ifdef CONFIG_PAX_SEGMEXEC
72992 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72993 + break;
72994 +#endif
72995 +
72996 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72997
72998 newflags = vma->vm_flags | VM_LOCKED;
72999 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73000 lock_limit >>= PAGE_SHIFT;
73001
73002 /* check against resource limits */
73003 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73004 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73005 error = do_mlock(start, len, 1);
73006 up_write(&current->mm->mmap_sem);
73007 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73008 static int do_mlockall(int flags)
73009 {
73010 struct vm_area_struct * vma, * prev = NULL;
73011 - unsigned int def_flags = 0;
73012
73013 if (flags & MCL_FUTURE)
73014 - def_flags = VM_LOCKED;
73015 - current->mm->def_flags = def_flags;
73016 + current->mm->def_flags |= VM_LOCKED;
73017 + else
73018 + current->mm->def_flags &= ~VM_LOCKED;
73019 if (flags == MCL_FUTURE)
73020 goto out;
73021
73022 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73023 vm_flags_t newflags;
73024
73025 +#ifdef CONFIG_PAX_SEGMEXEC
73026 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73027 + break;
73028 +#endif
73029 +
73030 + BUG_ON(vma->vm_end > TASK_SIZE);
73031 newflags = vma->vm_flags | VM_LOCKED;
73032 if (!(flags & MCL_CURRENT))
73033 newflags &= ~VM_LOCKED;
73034 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73035 lock_limit >>= PAGE_SHIFT;
73036
73037 ret = -ENOMEM;
73038 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73039 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73040 capable(CAP_IPC_LOCK))
73041 ret = do_mlockall(flags);
73042 diff --git a/mm/mmap.c b/mm/mmap.c
73043 index ae18a48..86cf99e 100644
73044 --- a/mm/mmap.c
73045 +++ b/mm/mmap.c
73046 @@ -47,6 +47,16 @@
73047 #define arch_rebalance_pgtables(addr, len) (addr)
73048 #endif
73049
73050 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73051 +{
73052 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73053 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73054 + up_read(&mm->mmap_sem);
73055 + BUG();
73056 + }
73057 +#endif
73058 +}
73059 +
73060 static void unmap_region(struct mm_struct *mm,
73061 struct vm_area_struct *vma, struct vm_area_struct *prev,
73062 unsigned long start, unsigned long end);
73063 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73064 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73065 *
73066 */
73067 -pgprot_t protection_map[16] = {
73068 +pgprot_t protection_map[16] __read_only = {
73069 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73070 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73071 };
73072
73073 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73074 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73075 {
73076 - return __pgprot(pgprot_val(protection_map[vm_flags &
73077 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73078 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73079 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73080 +
73081 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73082 + if (!(__supported_pte_mask & _PAGE_NX) &&
73083 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73084 + (vm_flags & (VM_READ | VM_WRITE)))
73085 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73086 +#endif
73087 +
73088 + return prot;
73089 }
73090 EXPORT_SYMBOL(vm_get_page_prot);
73091
73092 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73093 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73094 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73095 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73096 /*
73097 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73098 * other variables. It can be updated by several CPUs frequently.
73099 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73100 struct vm_area_struct *next = vma->vm_next;
73101
73102 might_sleep();
73103 + BUG_ON(vma->vm_mirror);
73104 if (vma->vm_ops && vma->vm_ops->close)
73105 vma->vm_ops->close(vma);
73106 if (vma->vm_file) {
73107 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73108 * not page aligned -Ram Gupta
73109 */
73110 rlim = rlimit(RLIMIT_DATA);
73111 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73112 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73113 (mm->end_data - mm->start_data) > rlim)
73114 goto out;
73115 @@ -708,6 +730,12 @@ static int
73116 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73117 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73118 {
73119 +
73120 +#ifdef CONFIG_PAX_SEGMEXEC
73121 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73122 + return 0;
73123 +#endif
73124 +
73125 if (is_mergeable_vma(vma, file, vm_flags) &&
73126 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73127 if (vma->vm_pgoff == vm_pgoff)
73128 @@ -727,6 +755,12 @@ static int
73129 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73130 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73131 {
73132 +
73133 +#ifdef CONFIG_PAX_SEGMEXEC
73134 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73135 + return 0;
73136 +#endif
73137 +
73138 if (is_mergeable_vma(vma, file, vm_flags) &&
73139 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73140 pgoff_t vm_pglen;
73141 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73142 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73143 struct vm_area_struct *prev, unsigned long addr,
73144 unsigned long end, unsigned long vm_flags,
73145 - struct anon_vma *anon_vma, struct file *file,
73146 + struct anon_vma *anon_vma, struct file *file,
73147 pgoff_t pgoff, struct mempolicy *policy)
73148 {
73149 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73150 struct vm_area_struct *area, *next;
73151 int err;
73152
73153 +#ifdef CONFIG_PAX_SEGMEXEC
73154 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73155 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73156 +
73157 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73158 +#endif
73159 +
73160 /*
73161 * We later require that vma->vm_flags == vm_flags,
73162 * so this tests vma->vm_flags & VM_SPECIAL, too.
73163 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73164 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73165 next = next->vm_next;
73166
73167 +#ifdef CONFIG_PAX_SEGMEXEC
73168 + if (prev)
73169 + prev_m = pax_find_mirror_vma(prev);
73170 + if (area)
73171 + area_m = pax_find_mirror_vma(area);
73172 + if (next)
73173 + next_m = pax_find_mirror_vma(next);
73174 +#endif
73175 +
73176 /*
73177 * Can it merge with the predecessor?
73178 */
73179 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73180 /* cases 1, 6 */
73181 err = vma_adjust(prev, prev->vm_start,
73182 next->vm_end, prev->vm_pgoff, NULL);
73183 - } else /* cases 2, 5, 7 */
73184 +
73185 +#ifdef CONFIG_PAX_SEGMEXEC
73186 + if (!err && prev_m)
73187 + err = vma_adjust(prev_m, prev_m->vm_start,
73188 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73189 +#endif
73190 +
73191 + } else { /* cases 2, 5, 7 */
73192 err = vma_adjust(prev, prev->vm_start,
73193 end, prev->vm_pgoff, NULL);
73194 +
73195 +#ifdef CONFIG_PAX_SEGMEXEC
73196 + if (!err && prev_m)
73197 + err = vma_adjust(prev_m, prev_m->vm_start,
73198 + end_m, prev_m->vm_pgoff, NULL);
73199 +#endif
73200 +
73201 + }
73202 if (err)
73203 return NULL;
73204 khugepaged_enter_vma_merge(prev);
73205 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73206 mpol_equal(policy, vma_policy(next)) &&
73207 can_vma_merge_before(next, vm_flags,
73208 anon_vma, file, pgoff+pglen)) {
73209 - if (prev && addr < prev->vm_end) /* case 4 */
73210 + if (prev && addr < prev->vm_end) { /* case 4 */
73211 err = vma_adjust(prev, prev->vm_start,
73212 addr, prev->vm_pgoff, NULL);
73213 - else /* cases 3, 8 */
73214 +
73215 +#ifdef CONFIG_PAX_SEGMEXEC
73216 + if (!err && prev_m)
73217 + err = vma_adjust(prev_m, prev_m->vm_start,
73218 + addr_m, prev_m->vm_pgoff, NULL);
73219 +#endif
73220 +
73221 + } else { /* cases 3, 8 */
73222 err = vma_adjust(area, addr, next->vm_end,
73223 next->vm_pgoff - pglen, NULL);
73224 +
73225 +#ifdef CONFIG_PAX_SEGMEXEC
73226 + if (!err && area_m)
73227 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73228 + next_m->vm_pgoff - pglen, NULL);
73229 +#endif
73230 +
73231 + }
73232 if (err)
73233 return NULL;
73234 khugepaged_enter_vma_merge(area);
73235 @@ -940,16 +1020,13 @@ none:
73236 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73237 struct file *file, long pages)
73238 {
73239 - const unsigned long stack_flags
73240 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73241 -
73242 mm->total_vm += pages;
73243
73244 if (file) {
73245 mm->shared_vm += pages;
73246 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73247 mm->exec_vm += pages;
73248 - } else if (flags & stack_flags)
73249 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73250 mm->stack_vm += pages;
73251 if (flags & (VM_RESERVED|VM_IO))
73252 mm->reserved_vm += pages;
73253 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73254 * (the exception is when the underlying filesystem is noexec
73255 * mounted, in which case we dont add PROT_EXEC.)
73256 */
73257 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73258 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73259 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73260 prot |= PROT_EXEC;
73261
73262 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73263 /* Obtain the address to map to. we verify (or select) it and ensure
73264 * that it represents a valid section of the address space.
73265 */
73266 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73267 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73268 if (addr & ~PAGE_MASK)
73269 return addr;
73270
73271 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73272 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73273 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73274
73275 +#ifdef CONFIG_PAX_MPROTECT
73276 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73277 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73278 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73279 + gr_log_rwxmmap(file);
73280 +
73281 +#ifdef CONFIG_PAX_EMUPLT
73282 + vm_flags &= ~VM_EXEC;
73283 +#else
73284 + return -EPERM;
73285 +#endif
73286 +
73287 + }
73288 +
73289 + if (!(vm_flags & VM_EXEC))
73290 + vm_flags &= ~VM_MAYEXEC;
73291 +#else
73292 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73293 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73294 +#endif
73295 + else
73296 + vm_flags &= ~VM_MAYWRITE;
73297 + }
73298 +#endif
73299 +
73300 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73301 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73302 + vm_flags &= ~VM_PAGEEXEC;
73303 +#endif
73304 +
73305 if (flags & MAP_LOCKED)
73306 if (!can_do_mlock())
73307 return -EPERM;
73308 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73309 locked += mm->locked_vm;
73310 lock_limit = rlimit(RLIMIT_MEMLOCK);
73311 lock_limit >>= PAGE_SHIFT;
73312 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73313 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73314 return -EAGAIN;
73315 }
73316 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73317 }
73318 }
73319
73320 + if (!gr_acl_handle_mmap(file, prot))
73321 + return -EACCES;
73322 +
73323 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73324 }
73325
73326 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73327 vm_flags_t vm_flags = vma->vm_flags;
73328
73329 /* If it was private or non-writable, the write bit is already clear */
73330 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73331 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73332 return 0;
73333
73334 /* The backer wishes to know when pages are first written to? */
73335 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73336 unsigned long charged = 0;
73337 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73338
73339 +#ifdef CONFIG_PAX_SEGMEXEC
73340 + struct vm_area_struct *vma_m = NULL;
73341 +#endif
73342 +
73343 + /*
73344 + * mm->mmap_sem is required to protect against another thread
73345 + * changing the mappings in case we sleep.
73346 + */
73347 + verify_mm_writelocked(mm);
73348 +
73349 /* Clear old maps */
73350 error = -ENOMEM;
73351 -munmap_back:
73352 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73353 if (vma && vma->vm_start < addr + len) {
73354 if (do_munmap(mm, addr, len))
73355 return -ENOMEM;
73356 - goto munmap_back;
73357 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73358 + BUG_ON(vma && vma->vm_start < addr + len);
73359 }
73360
73361 /* Check against address space limit. */
73362 @@ -1282,6 +1403,16 @@ munmap_back:
73363 goto unacct_error;
73364 }
73365
73366 +#ifdef CONFIG_PAX_SEGMEXEC
73367 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73368 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73369 + if (!vma_m) {
73370 + error = -ENOMEM;
73371 + goto free_vma;
73372 + }
73373 + }
73374 +#endif
73375 +
73376 vma->vm_mm = mm;
73377 vma->vm_start = addr;
73378 vma->vm_end = addr + len;
73379 @@ -1306,6 +1437,19 @@ munmap_back:
73380 error = file->f_op->mmap(file, vma);
73381 if (error)
73382 goto unmap_and_free_vma;
73383 +
73384 +#ifdef CONFIG_PAX_SEGMEXEC
73385 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73386 + added_exe_file_vma(mm);
73387 +#endif
73388 +
73389 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73390 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73391 + vma->vm_flags |= VM_PAGEEXEC;
73392 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73393 + }
73394 +#endif
73395 +
73396 if (vm_flags & VM_EXECUTABLE)
73397 added_exe_file_vma(mm);
73398
73399 @@ -1343,6 +1487,11 @@ munmap_back:
73400 vma_link(mm, vma, prev, rb_link, rb_parent);
73401 file = vma->vm_file;
73402
73403 +#ifdef CONFIG_PAX_SEGMEXEC
73404 + if (vma_m)
73405 + BUG_ON(pax_mirror_vma(vma_m, vma));
73406 +#endif
73407 +
73408 /* Once vma denies write, undo our temporary denial count */
73409 if (correct_wcount)
73410 atomic_inc(&inode->i_writecount);
73411 @@ -1350,6 +1499,7 @@ out:
73412 perf_event_mmap(vma);
73413
73414 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73415 + track_exec_limit(mm, addr, addr + len, vm_flags);
73416 if (vm_flags & VM_LOCKED) {
73417 if (!mlock_vma_pages_range(vma, addr, addr + len))
73418 mm->locked_vm += (len >> PAGE_SHIFT);
73419 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73420 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73421 charged = 0;
73422 free_vma:
73423 +
73424 +#ifdef CONFIG_PAX_SEGMEXEC
73425 + if (vma_m)
73426 + kmem_cache_free(vm_area_cachep, vma_m);
73427 +#endif
73428 +
73429 kmem_cache_free(vm_area_cachep, vma);
73430 unacct_error:
73431 if (charged)
73432 @@ -1378,6 +1534,44 @@ unacct_error:
73433 return error;
73434 }
73435
73436 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73437 +{
73438 + if (!vma) {
73439 +#ifdef CONFIG_STACK_GROWSUP
73440 + if (addr > sysctl_heap_stack_gap)
73441 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73442 + else
73443 + vma = find_vma(current->mm, 0);
73444 + if (vma && (vma->vm_flags & VM_GROWSUP))
73445 + return false;
73446 +#endif
73447 + return true;
73448 + }
73449 +
73450 + if (addr + len > vma->vm_start)
73451 + return false;
73452 +
73453 + if (vma->vm_flags & VM_GROWSDOWN)
73454 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73455 +#ifdef CONFIG_STACK_GROWSUP
73456 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73457 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73458 +#endif
73459 +
73460 + return true;
73461 +}
73462 +
73463 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73464 +{
73465 + if (vma->vm_start < len)
73466 + return -ENOMEM;
73467 + if (!(vma->vm_flags & VM_GROWSDOWN))
73468 + return vma->vm_start - len;
73469 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73470 + return vma->vm_start - len - sysctl_heap_stack_gap;
73471 + return -ENOMEM;
73472 +}
73473 +
73474 /* Get an address range which is currently unmapped.
73475 * For shmat() with addr=0.
73476 *
73477 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73478 if (flags & MAP_FIXED)
73479 return addr;
73480
73481 +#ifdef CONFIG_PAX_RANDMMAP
73482 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73483 +#endif
73484 +
73485 if (addr) {
73486 addr = PAGE_ALIGN(addr);
73487 - vma = find_vma(mm, addr);
73488 - if (TASK_SIZE - len >= addr &&
73489 - (!vma || addr + len <= vma->vm_start))
73490 - return addr;
73491 + if (TASK_SIZE - len >= addr) {
73492 + vma = find_vma(mm, addr);
73493 + if (check_heap_stack_gap(vma, addr, len))
73494 + return addr;
73495 + }
73496 }
73497 if (len > mm->cached_hole_size) {
73498 - start_addr = addr = mm->free_area_cache;
73499 + start_addr = addr = mm->free_area_cache;
73500 } else {
73501 - start_addr = addr = TASK_UNMAPPED_BASE;
73502 - mm->cached_hole_size = 0;
73503 + start_addr = addr = mm->mmap_base;
73504 + mm->cached_hole_size = 0;
73505 }
73506
73507 full_search:
73508 @@ -1426,34 +1625,40 @@ full_search:
73509 * Start a new search - just in case we missed
73510 * some holes.
73511 */
73512 - if (start_addr != TASK_UNMAPPED_BASE) {
73513 - addr = TASK_UNMAPPED_BASE;
73514 - start_addr = addr;
73515 + if (start_addr != mm->mmap_base) {
73516 + start_addr = addr = mm->mmap_base;
73517 mm->cached_hole_size = 0;
73518 goto full_search;
73519 }
73520 return -ENOMEM;
73521 }
73522 - if (!vma || addr + len <= vma->vm_start) {
73523 - /*
73524 - * Remember the place where we stopped the search:
73525 - */
73526 - mm->free_area_cache = addr + len;
73527 - return addr;
73528 - }
73529 + if (check_heap_stack_gap(vma, addr, len))
73530 + break;
73531 if (addr + mm->cached_hole_size < vma->vm_start)
73532 mm->cached_hole_size = vma->vm_start - addr;
73533 addr = vma->vm_end;
73534 }
73535 +
73536 + /*
73537 + * Remember the place where we stopped the search:
73538 + */
73539 + mm->free_area_cache = addr + len;
73540 + return addr;
73541 }
73542 #endif
73543
73544 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73545 {
73546 +
73547 +#ifdef CONFIG_PAX_SEGMEXEC
73548 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73549 + return;
73550 +#endif
73551 +
73552 /*
73553 * Is this a new hole at the lowest possible address?
73554 */
73555 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73556 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73557 mm->free_area_cache = addr;
73558 }
73559
73560 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73561 {
73562 struct vm_area_struct *vma;
73563 struct mm_struct *mm = current->mm;
73564 - unsigned long addr = addr0, start_addr;
73565 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73566
73567 /* requested length too big for entire address space */
73568 if (len > TASK_SIZE)
73569 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73570 if (flags & MAP_FIXED)
73571 return addr;
73572
73573 +#ifdef CONFIG_PAX_RANDMMAP
73574 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73575 +#endif
73576 +
73577 /* requesting a specific address */
73578 if (addr) {
73579 addr = PAGE_ALIGN(addr);
73580 - vma = find_vma(mm, addr);
73581 - if (TASK_SIZE - len >= addr &&
73582 - (!vma || addr + len <= vma->vm_start))
73583 - return addr;
73584 + if (TASK_SIZE - len >= addr) {
73585 + vma = find_vma(mm, addr);
73586 + if (check_heap_stack_gap(vma, addr, len))
73587 + return addr;
73588 + }
73589 }
73590
73591 /* check if free_area_cache is useful for us */
73592 @@ -1508,7 +1718,7 @@ try_again:
73593 * return with success:
73594 */
73595 vma = find_vma(mm, addr);
73596 - if (!vma || addr+len <= vma->vm_start)
73597 + if (check_heap_stack_gap(vma, addr, len))
73598 /* remember the address as a hint for next time */
73599 return (mm->free_area_cache = addr);
73600
73601 @@ -1517,8 +1727,8 @@ try_again:
73602 mm->cached_hole_size = vma->vm_start - addr;
73603
73604 /* try just below the current vma->vm_start */
73605 - addr = vma->vm_start-len;
73606 - } while (len < vma->vm_start);
73607 + addr = skip_heap_stack_gap(vma, len);
73608 + } while (!IS_ERR_VALUE(addr));
73609
73610 fail:
73611 /*
73612 @@ -1541,13 +1751,21 @@ fail:
73613 * can happen with large stack limits and large mmap()
73614 * allocations.
73615 */
73616 + mm->mmap_base = TASK_UNMAPPED_BASE;
73617 +
73618 +#ifdef CONFIG_PAX_RANDMMAP
73619 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73620 + mm->mmap_base += mm->delta_mmap;
73621 +#endif
73622 +
73623 + mm->free_area_cache = mm->mmap_base;
73624 mm->cached_hole_size = ~0UL;
73625 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73626 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73627 /*
73628 * Restore the topdown base:
73629 */
73630 - mm->free_area_cache = mm->mmap_base;
73631 + mm->mmap_base = base;
73632 + mm->free_area_cache = base;
73633 mm->cached_hole_size = ~0UL;
73634
73635 return addr;
73636 @@ -1556,6 +1774,12 @@ fail:
73637
73638 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73639 {
73640 +
73641 +#ifdef CONFIG_PAX_SEGMEXEC
73642 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73643 + return;
73644 +#endif
73645 +
73646 /*
73647 * Is this a new hole at the highest possible address?
73648 */
73649 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73650 mm->free_area_cache = addr;
73651
73652 /* dont allow allocations above current base */
73653 - if (mm->free_area_cache > mm->mmap_base)
73654 + if (mm->free_area_cache > mm->mmap_base) {
73655 mm->free_area_cache = mm->mmap_base;
73656 + mm->cached_hole_size = ~0UL;
73657 + }
73658 }
73659
73660 unsigned long
73661 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73662 return vma;
73663 }
73664
73665 +#ifdef CONFIG_PAX_SEGMEXEC
73666 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73667 +{
73668 + struct vm_area_struct *vma_m;
73669 +
73670 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73671 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73672 + BUG_ON(vma->vm_mirror);
73673 + return NULL;
73674 + }
73675 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73676 + vma_m = vma->vm_mirror;
73677 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73678 + BUG_ON(vma->vm_file != vma_m->vm_file);
73679 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73680 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73681 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73682 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73683 + return vma_m;
73684 +}
73685 +#endif
73686 +
73687 /*
73688 * Verify that the stack growth is acceptable and
73689 * update accounting. This is shared with both the
73690 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73691 return -ENOMEM;
73692
73693 /* Stack limit test */
73694 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73695 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73696 return -ENOMEM;
73697
73698 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73699 locked = mm->locked_vm + grow;
73700 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73701 limit >>= PAGE_SHIFT;
73702 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73703 if (locked > limit && !capable(CAP_IPC_LOCK))
73704 return -ENOMEM;
73705 }
73706 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73707 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73708 * vma is the last one with address > vma->vm_end. Have to extend vma.
73709 */
73710 +#ifndef CONFIG_IA64
73711 +static
73712 +#endif
73713 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73714 {
73715 int error;
73716 + bool locknext;
73717
73718 if (!(vma->vm_flags & VM_GROWSUP))
73719 return -EFAULT;
73720
73721 + /* Also guard against wrapping around to address 0. */
73722 + if (address < PAGE_ALIGN(address+1))
73723 + address = PAGE_ALIGN(address+1);
73724 + else
73725 + return -ENOMEM;
73726 +
73727 /*
73728 * We must make sure the anon_vma is allocated
73729 * so that the anon_vma locking is not a noop.
73730 */
73731 if (unlikely(anon_vma_prepare(vma)))
73732 return -ENOMEM;
73733 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73734 + if (locknext && anon_vma_prepare(vma->vm_next))
73735 + return -ENOMEM;
73736 vma_lock_anon_vma(vma);
73737 + if (locknext)
73738 + vma_lock_anon_vma(vma->vm_next);
73739
73740 /*
73741 * vma->vm_start/vm_end cannot change under us because the caller
73742 * is required to hold the mmap_sem in read mode. We need the
73743 - * anon_vma lock to serialize against concurrent expand_stacks.
73744 - * Also guard against wrapping around to address 0.
73745 + * anon_vma locks to serialize against concurrent expand_stacks
73746 + * and expand_upwards.
73747 */
73748 - if (address < PAGE_ALIGN(address+4))
73749 - address = PAGE_ALIGN(address+4);
73750 - else {
73751 - vma_unlock_anon_vma(vma);
73752 - return -ENOMEM;
73753 - }
73754 error = 0;
73755
73756 /* Somebody else might have raced and expanded it already */
73757 - if (address > vma->vm_end) {
73758 + 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)
73759 + error = -ENOMEM;
73760 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73761 unsigned long size, grow;
73762
73763 size = address - vma->vm_start;
73764 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73765 }
73766 }
73767 }
73768 + if (locknext)
73769 + vma_unlock_anon_vma(vma->vm_next);
73770 vma_unlock_anon_vma(vma);
73771 khugepaged_enter_vma_merge(vma);
73772 return error;
73773 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73774 unsigned long address)
73775 {
73776 int error;
73777 + bool lockprev = false;
73778 + struct vm_area_struct *prev;
73779
73780 /*
73781 * We must make sure the anon_vma is allocated
73782 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73783 if (error)
73784 return error;
73785
73786 + prev = vma->vm_prev;
73787 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73788 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73789 +#endif
73790 + if (lockprev && anon_vma_prepare(prev))
73791 + return -ENOMEM;
73792 + if (lockprev)
73793 + vma_lock_anon_vma(prev);
73794 +
73795 vma_lock_anon_vma(vma);
73796
73797 /*
73798 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73799 */
73800
73801 /* Somebody else might have raced and expanded it already */
73802 - if (address < vma->vm_start) {
73803 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73804 + error = -ENOMEM;
73805 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73806 unsigned long size, grow;
73807
73808 +#ifdef CONFIG_PAX_SEGMEXEC
73809 + struct vm_area_struct *vma_m;
73810 +
73811 + vma_m = pax_find_mirror_vma(vma);
73812 +#endif
73813 +
73814 size = vma->vm_end - address;
73815 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73816
73817 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73818 if (!error) {
73819 vma->vm_start = address;
73820 vma->vm_pgoff -= grow;
73821 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73822 +
73823 +#ifdef CONFIG_PAX_SEGMEXEC
73824 + if (vma_m) {
73825 + vma_m->vm_start -= grow << PAGE_SHIFT;
73826 + vma_m->vm_pgoff -= grow;
73827 + }
73828 +#endif
73829 +
73830 perf_event_mmap(vma);
73831 }
73832 }
73833 }
73834 vma_unlock_anon_vma(vma);
73835 + if (lockprev)
73836 + vma_unlock_anon_vma(prev);
73837 khugepaged_enter_vma_merge(vma);
73838 return error;
73839 }
73840 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73841 do {
73842 long nrpages = vma_pages(vma);
73843
73844 +#ifdef CONFIG_PAX_SEGMEXEC
73845 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73846 + vma = remove_vma(vma);
73847 + continue;
73848 + }
73849 +#endif
73850 +
73851 if (vma->vm_flags & VM_ACCOUNT)
73852 nr_accounted += nrpages;
73853 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73854 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73855 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73856 vma->vm_prev = NULL;
73857 do {
73858 +
73859 +#ifdef CONFIG_PAX_SEGMEXEC
73860 + if (vma->vm_mirror) {
73861 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73862 + vma->vm_mirror->vm_mirror = NULL;
73863 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73864 + vma->vm_mirror = NULL;
73865 + }
73866 +#endif
73867 +
73868 rb_erase(&vma->vm_rb, &mm->mm_rb);
73869 mm->map_count--;
73870 tail_vma = vma;
73871 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73872 struct vm_area_struct *new;
73873 int err = -ENOMEM;
73874
73875 +#ifdef CONFIG_PAX_SEGMEXEC
73876 + struct vm_area_struct *vma_m, *new_m = NULL;
73877 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73878 +#endif
73879 +
73880 if (is_vm_hugetlb_page(vma) && (addr &
73881 ~(huge_page_mask(hstate_vma(vma)))))
73882 return -EINVAL;
73883
73884 +#ifdef CONFIG_PAX_SEGMEXEC
73885 + vma_m = pax_find_mirror_vma(vma);
73886 +#endif
73887 +
73888 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73889 if (!new)
73890 goto out_err;
73891
73892 +#ifdef CONFIG_PAX_SEGMEXEC
73893 + if (vma_m) {
73894 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73895 + if (!new_m) {
73896 + kmem_cache_free(vm_area_cachep, new);
73897 + goto out_err;
73898 + }
73899 + }
73900 +#endif
73901 +
73902 /* most fields are the same, copy all, and then fixup */
73903 *new = *vma;
73904
73905 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73906 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73907 }
73908
73909 +#ifdef CONFIG_PAX_SEGMEXEC
73910 + if (vma_m) {
73911 + *new_m = *vma_m;
73912 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73913 + new_m->vm_mirror = new;
73914 + new->vm_mirror = new_m;
73915 +
73916 + if (new_below)
73917 + new_m->vm_end = addr_m;
73918 + else {
73919 + new_m->vm_start = addr_m;
73920 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73921 + }
73922 + }
73923 +#endif
73924 +
73925 pol = mpol_dup(vma_policy(vma));
73926 if (IS_ERR(pol)) {
73927 err = PTR_ERR(pol);
73928 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73929 else
73930 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73931
73932 +#ifdef CONFIG_PAX_SEGMEXEC
73933 + if (!err && vma_m) {
73934 + if (anon_vma_clone(new_m, vma_m))
73935 + goto out_free_mpol;
73936 +
73937 + mpol_get(pol);
73938 + vma_set_policy(new_m, pol);
73939 +
73940 + if (new_m->vm_file) {
73941 + get_file(new_m->vm_file);
73942 + if (vma_m->vm_flags & VM_EXECUTABLE)
73943 + added_exe_file_vma(mm);
73944 + }
73945 +
73946 + if (new_m->vm_ops && new_m->vm_ops->open)
73947 + new_m->vm_ops->open(new_m);
73948 +
73949 + if (new_below)
73950 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73951 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73952 + else
73953 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73954 +
73955 + if (err) {
73956 + if (new_m->vm_ops && new_m->vm_ops->close)
73957 + new_m->vm_ops->close(new_m);
73958 + if (new_m->vm_file) {
73959 + if (vma_m->vm_flags & VM_EXECUTABLE)
73960 + removed_exe_file_vma(mm);
73961 + fput(new_m->vm_file);
73962 + }
73963 + mpol_put(pol);
73964 + }
73965 + }
73966 +#endif
73967 +
73968 /* Success. */
73969 if (!err)
73970 return 0;
73971 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73972 removed_exe_file_vma(mm);
73973 fput(new->vm_file);
73974 }
73975 - unlink_anon_vmas(new);
73976 out_free_mpol:
73977 mpol_put(pol);
73978 out_free_vma:
73979 +
73980 +#ifdef CONFIG_PAX_SEGMEXEC
73981 + if (new_m) {
73982 + unlink_anon_vmas(new_m);
73983 + kmem_cache_free(vm_area_cachep, new_m);
73984 + }
73985 +#endif
73986 +
73987 + unlink_anon_vmas(new);
73988 kmem_cache_free(vm_area_cachep, new);
73989 out_err:
73990 return err;
73991 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73992 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73993 unsigned long addr, int new_below)
73994 {
73995 +
73996 +#ifdef CONFIG_PAX_SEGMEXEC
73997 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73998 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73999 + if (mm->map_count >= sysctl_max_map_count-1)
74000 + return -ENOMEM;
74001 + } else
74002 +#endif
74003 +
74004 if (mm->map_count >= sysctl_max_map_count)
74005 return -ENOMEM;
74006
74007 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74008 * work. This now handles partial unmappings.
74009 * Jeremy Fitzhardinge <jeremy@goop.org>
74010 */
74011 +#ifdef CONFIG_PAX_SEGMEXEC
74012 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74013 {
74014 + int ret = __do_munmap(mm, start, len);
74015 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74016 + return ret;
74017 +
74018 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74019 +}
74020 +
74021 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74022 +#else
74023 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74024 +#endif
74025 +{
74026 unsigned long end;
74027 struct vm_area_struct *vma, *prev, *last;
74028
74029 + /*
74030 + * mm->mmap_sem is required to protect against another thread
74031 + * changing the mappings in case we sleep.
74032 + */
74033 + verify_mm_writelocked(mm);
74034 +
74035 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74036 return -EINVAL;
74037
74038 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74039 /* Fix up all other VM information */
74040 remove_vma_list(mm, vma);
74041
74042 + track_exec_limit(mm, start, end, 0UL);
74043 +
74044 return 0;
74045 }
74046
74047 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74048 int ret;
74049 struct mm_struct *mm = current->mm;
74050
74051 +
74052 +#ifdef CONFIG_PAX_SEGMEXEC
74053 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74054 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74055 + return -EINVAL;
74056 +#endif
74057 +
74058 down_write(&mm->mmap_sem);
74059 ret = do_munmap(mm, start, len);
74060 up_write(&mm->mmap_sem);
74061 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74062 return vm_munmap(addr, len);
74063 }
74064
74065 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74066 -{
74067 -#ifdef CONFIG_DEBUG_VM
74068 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74069 - WARN_ON(1);
74070 - up_read(&mm->mmap_sem);
74071 - }
74072 -#endif
74073 -}
74074 -
74075 /*
74076 * this is really a simplified "do_mmap". it only handles
74077 * anonymous maps. eventually we may be able to do some
74078 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74079 struct rb_node ** rb_link, * rb_parent;
74080 pgoff_t pgoff = addr >> PAGE_SHIFT;
74081 int error;
74082 + unsigned long charged;
74083
74084 len = PAGE_ALIGN(len);
74085 if (!len)
74086 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74087
74088 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74089
74090 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74091 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74092 + flags &= ~VM_EXEC;
74093 +
74094 +#ifdef CONFIG_PAX_MPROTECT
74095 + if (mm->pax_flags & MF_PAX_MPROTECT)
74096 + flags &= ~VM_MAYEXEC;
74097 +#endif
74098 +
74099 + }
74100 +#endif
74101 +
74102 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74103 if (error & ~PAGE_MASK)
74104 return error;
74105
74106 + charged = len >> PAGE_SHIFT;
74107 +
74108 /*
74109 * mlock MCL_FUTURE?
74110 */
74111 if (mm->def_flags & VM_LOCKED) {
74112 unsigned long locked, lock_limit;
74113 - locked = len >> PAGE_SHIFT;
74114 + locked = charged;
74115 locked += mm->locked_vm;
74116 lock_limit = rlimit(RLIMIT_MEMLOCK);
74117 lock_limit >>= PAGE_SHIFT;
74118 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74119 /*
74120 * Clear old maps. this also does some error checking for us
74121 */
74122 - munmap_back:
74123 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74124 if (vma && vma->vm_start < addr + len) {
74125 if (do_munmap(mm, addr, len))
74126 return -ENOMEM;
74127 - goto munmap_back;
74128 - }
74129 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74130 + BUG_ON(vma && vma->vm_start < addr + len);
74131 + }
74132
74133 /* Check against address space limits *after* clearing old maps... */
74134 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74135 + if (!may_expand_vm(mm, charged))
74136 return -ENOMEM;
74137
74138 if (mm->map_count > sysctl_max_map_count)
74139 return -ENOMEM;
74140
74141 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74142 + if (security_vm_enough_memory_mm(mm, charged))
74143 return -ENOMEM;
74144
74145 /* Can we just expand an old private anonymous mapping? */
74146 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74147 */
74148 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74149 if (!vma) {
74150 - vm_unacct_memory(len >> PAGE_SHIFT);
74151 + vm_unacct_memory(charged);
74152 return -ENOMEM;
74153 }
74154
74155 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74156 vma_link(mm, vma, prev, rb_link, rb_parent);
74157 out:
74158 perf_event_mmap(vma);
74159 - mm->total_vm += len >> PAGE_SHIFT;
74160 + mm->total_vm += charged;
74161 if (flags & VM_LOCKED) {
74162 if (!mlock_vma_pages_range(vma, addr, addr + len))
74163 - mm->locked_vm += (len >> PAGE_SHIFT);
74164 + mm->locked_vm += charged;
74165 }
74166 + track_exec_limit(mm, addr, addr + len, flags);
74167 return addr;
74168 }
74169
74170 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74171 while (vma) {
74172 if (vma->vm_flags & VM_ACCOUNT)
74173 nr_accounted += vma_pages(vma);
74174 + vma->vm_mirror = NULL;
74175 vma = remove_vma(vma);
74176 }
74177 vm_unacct_memory(nr_accounted);
74178 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74179 struct vm_area_struct * __vma, * prev;
74180 struct rb_node ** rb_link, * rb_parent;
74181
74182 +#ifdef CONFIG_PAX_SEGMEXEC
74183 + struct vm_area_struct *vma_m = NULL;
74184 +#endif
74185 +
74186 + if (security_mmap_addr(vma->vm_start))
74187 + return -EPERM;
74188 +
74189 /*
74190 * The vm_pgoff of a purely anonymous vma should be irrelevant
74191 * until its first write fault, when page's anon_vma and index
74192 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74193 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74194 return -ENOMEM;
74195
74196 +#ifdef CONFIG_PAX_SEGMEXEC
74197 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74198 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74199 + if (!vma_m)
74200 + return -ENOMEM;
74201 + }
74202 +#endif
74203 +
74204 vma_link(mm, vma, prev, rb_link, rb_parent);
74205 +
74206 +#ifdef CONFIG_PAX_SEGMEXEC
74207 + if (vma_m)
74208 + BUG_ON(pax_mirror_vma(vma_m, vma));
74209 +#endif
74210 +
74211 return 0;
74212 }
74213
74214 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74215 struct mempolicy *pol;
74216 bool faulted_in_anon_vma = true;
74217
74218 + BUG_ON(vma->vm_mirror);
74219 +
74220 /*
74221 * If anonymous vma has not yet been faulted, update new pgoff
74222 * to match new location, to increase its chance of merging.
74223 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74224 return NULL;
74225 }
74226
74227 +#ifdef CONFIG_PAX_SEGMEXEC
74228 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74229 +{
74230 + struct vm_area_struct *prev_m;
74231 + struct rb_node **rb_link_m, *rb_parent_m;
74232 + struct mempolicy *pol_m;
74233 +
74234 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74235 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74236 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74237 + *vma_m = *vma;
74238 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74239 + if (anon_vma_clone(vma_m, vma))
74240 + return -ENOMEM;
74241 + pol_m = vma_policy(vma_m);
74242 + mpol_get(pol_m);
74243 + vma_set_policy(vma_m, pol_m);
74244 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74245 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74246 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74247 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74248 + if (vma_m->vm_file)
74249 + get_file(vma_m->vm_file);
74250 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74251 + vma_m->vm_ops->open(vma_m);
74252 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74253 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74254 + vma_m->vm_mirror = vma;
74255 + vma->vm_mirror = vma_m;
74256 + return 0;
74257 +}
74258 +#endif
74259 +
74260 /*
74261 * Return true if the calling process may expand its vm space by the passed
74262 * number of pages
74263 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74264
74265 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74266
74267 +#ifdef CONFIG_PAX_RANDMMAP
74268 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74269 + cur -= mm->brk_gap;
74270 +#endif
74271 +
74272 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74273 if (cur + npages > lim)
74274 return 0;
74275 return 1;
74276 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74277 vma->vm_start = addr;
74278 vma->vm_end = addr + len;
74279
74280 +#ifdef CONFIG_PAX_MPROTECT
74281 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74282 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74283 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74284 + return -EPERM;
74285 + if (!(vm_flags & VM_EXEC))
74286 + vm_flags &= ~VM_MAYEXEC;
74287 +#else
74288 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74289 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74290 +#endif
74291 + else
74292 + vm_flags &= ~VM_MAYWRITE;
74293 + }
74294 +#endif
74295 +
74296 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74297 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74298
74299 diff --git a/mm/mprotect.c b/mm/mprotect.c
74300 index a409926..8b32e6d 100644
74301 --- a/mm/mprotect.c
74302 +++ b/mm/mprotect.c
74303 @@ -23,10 +23,17 @@
74304 #include <linux/mmu_notifier.h>
74305 #include <linux/migrate.h>
74306 #include <linux/perf_event.h>
74307 +
74308 +#ifdef CONFIG_PAX_MPROTECT
74309 +#include <linux/elf.h>
74310 +#include <linux/binfmts.h>
74311 +#endif
74312 +
74313 #include <asm/uaccess.h>
74314 #include <asm/pgtable.h>
74315 #include <asm/cacheflush.h>
74316 #include <asm/tlbflush.h>
74317 +#include <asm/mmu_context.h>
74318
74319 #ifndef pgprot_modify
74320 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74321 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74322 flush_tlb_range(vma, start, end);
74323 }
74324
74325 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74326 +/* called while holding the mmap semaphor for writing except stack expansion */
74327 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74328 +{
74329 + unsigned long oldlimit, newlimit = 0UL;
74330 +
74331 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74332 + return;
74333 +
74334 + spin_lock(&mm->page_table_lock);
74335 + oldlimit = mm->context.user_cs_limit;
74336 + if ((prot & VM_EXEC) && oldlimit < end)
74337 + /* USER_CS limit moved up */
74338 + newlimit = end;
74339 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74340 + /* USER_CS limit moved down */
74341 + newlimit = start;
74342 +
74343 + if (newlimit) {
74344 + mm->context.user_cs_limit = newlimit;
74345 +
74346 +#ifdef CONFIG_SMP
74347 + wmb();
74348 + cpus_clear(mm->context.cpu_user_cs_mask);
74349 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74350 +#endif
74351 +
74352 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74353 + }
74354 + spin_unlock(&mm->page_table_lock);
74355 + if (newlimit == end) {
74356 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74357 +
74358 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74359 + if (is_vm_hugetlb_page(vma))
74360 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74361 + else
74362 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74363 + }
74364 +}
74365 +#endif
74366 +
74367 int
74368 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74369 unsigned long start, unsigned long end, unsigned long newflags)
74370 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74371 int error;
74372 int dirty_accountable = 0;
74373
74374 +#ifdef CONFIG_PAX_SEGMEXEC
74375 + struct vm_area_struct *vma_m = NULL;
74376 + unsigned long start_m, end_m;
74377 +
74378 + start_m = start + SEGMEXEC_TASK_SIZE;
74379 + end_m = end + SEGMEXEC_TASK_SIZE;
74380 +#endif
74381 +
74382 if (newflags == oldflags) {
74383 *pprev = vma;
74384 return 0;
74385 }
74386
74387 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74388 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74389 +
74390 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74391 + return -ENOMEM;
74392 +
74393 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74394 + return -ENOMEM;
74395 + }
74396 +
74397 /*
74398 * If we make a private mapping writable we increase our commit;
74399 * but (without finer accounting) cannot reduce our commit if we
74400 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74401 }
74402 }
74403
74404 +#ifdef CONFIG_PAX_SEGMEXEC
74405 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74406 + if (start != vma->vm_start) {
74407 + error = split_vma(mm, vma, start, 1);
74408 + if (error)
74409 + goto fail;
74410 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74411 + *pprev = (*pprev)->vm_next;
74412 + }
74413 +
74414 + if (end != vma->vm_end) {
74415 + error = split_vma(mm, vma, end, 0);
74416 + if (error)
74417 + goto fail;
74418 + }
74419 +
74420 + if (pax_find_mirror_vma(vma)) {
74421 + error = __do_munmap(mm, start_m, end_m - start_m);
74422 + if (error)
74423 + goto fail;
74424 + } else {
74425 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74426 + if (!vma_m) {
74427 + error = -ENOMEM;
74428 + goto fail;
74429 + }
74430 + vma->vm_flags = newflags;
74431 + error = pax_mirror_vma(vma_m, vma);
74432 + if (error) {
74433 + vma->vm_flags = oldflags;
74434 + goto fail;
74435 + }
74436 + }
74437 + }
74438 +#endif
74439 +
74440 /*
74441 * First try to merge with previous and/or next vma.
74442 */
74443 @@ -204,9 +307,21 @@ success:
74444 * vm_flags and vm_page_prot are protected by the mmap_sem
74445 * held in write mode.
74446 */
74447 +
74448 +#ifdef CONFIG_PAX_SEGMEXEC
74449 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74450 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74451 +#endif
74452 +
74453 vma->vm_flags = newflags;
74454 +
74455 +#ifdef CONFIG_PAX_MPROTECT
74456 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74457 + mm->binfmt->handle_mprotect(vma, newflags);
74458 +#endif
74459 +
74460 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74461 - vm_get_page_prot(newflags));
74462 + vm_get_page_prot(vma->vm_flags));
74463
74464 if (vma_wants_writenotify(vma)) {
74465 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74466 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74467 end = start + len;
74468 if (end <= start)
74469 return -ENOMEM;
74470 +
74471 +#ifdef CONFIG_PAX_SEGMEXEC
74472 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74473 + if (end > SEGMEXEC_TASK_SIZE)
74474 + return -EINVAL;
74475 + } else
74476 +#endif
74477 +
74478 + if (end > TASK_SIZE)
74479 + return -EINVAL;
74480 +
74481 if (!arch_validate_prot(prot))
74482 return -EINVAL;
74483
74484 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74485 /*
74486 * Does the application expect PROT_READ to imply PROT_EXEC:
74487 */
74488 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74489 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74490 prot |= PROT_EXEC;
74491
74492 vm_flags = calc_vm_prot_bits(prot);
74493 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74494 if (start > vma->vm_start)
74495 prev = vma;
74496
74497 +#ifdef CONFIG_PAX_MPROTECT
74498 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74499 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74500 +#endif
74501 +
74502 for (nstart = start ; ; ) {
74503 unsigned long newflags;
74504
74505 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74506
74507 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74508 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74509 + if (prot & (PROT_WRITE | PROT_EXEC))
74510 + gr_log_rwxmprotect(vma->vm_file);
74511 +
74512 + error = -EACCES;
74513 + goto out;
74514 + }
74515 +
74516 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74517 error = -EACCES;
74518 goto out;
74519 }
74520 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74521 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74522 if (error)
74523 goto out;
74524 +
74525 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74526 +
74527 nstart = tmp;
74528
74529 if (nstart < prev->vm_end)
74530 diff --git a/mm/mremap.c b/mm/mremap.c
74531 index cc06d0e..40b5d18 100644
74532 --- a/mm/mremap.c
74533 +++ b/mm/mremap.c
74534 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74535 continue;
74536 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74537 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74538 +
74539 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74540 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74541 + pte = pte_exprotect(pte);
74542 +#endif
74543 +
74544 set_pte_at(mm, new_addr, new_pte, pte);
74545 }
74546
74547 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74548 if (is_vm_hugetlb_page(vma))
74549 goto Einval;
74550
74551 +#ifdef CONFIG_PAX_SEGMEXEC
74552 + if (pax_find_mirror_vma(vma))
74553 + goto Einval;
74554 +#endif
74555 +
74556 /* We can't remap across vm area boundaries */
74557 if (old_len > vma->vm_end - addr)
74558 goto Efault;
74559 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74560 unsigned long ret = -EINVAL;
74561 unsigned long charged = 0;
74562 unsigned long map_flags;
74563 + unsigned long pax_task_size = TASK_SIZE;
74564
74565 if (new_addr & ~PAGE_MASK)
74566 goto out;
74567
74568 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74569 +#ifdef CONFIG_PAX_SEGMEXEC
74570 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74571 + pax_task_size = SEGMEXEC_TASK_SIZE;
74572 +#endif
74573 +
74574 + pax_task_size -= PAGE_SIZE;
74575 +
74576 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74577 goto out;
74578
74579 /* Check if the location we're moving into overlaps the
74580 * old location at all, and fail if it does.
74581 */
74582 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74583 - goto out;
74584 -
74585 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74586 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74587 goto out;
74588
74589 ret = do_munmap(mm, new_addr, new_len);
74590 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74591 struct vm_area_struct *vma;
74592 unsigned long ret = -EINVAL;
74593 unsigned long charged = 0;
74594 + unsigned long pax_task_size = TASK_SIZE;
74595
74596 down_write(&current->mm->mmap_sem);
74597
74598 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74599 if (!new_len)
74600 goto out;
74601
74602 +#ifdef CONFIG_PAX_SEGMEXEC
74603 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74604 + pax_task_size = SEGMEXEC_TASK_SIZE;
74605 +#endif
74606 +
74607 + pax_task_size -= PAGE_SIZE;
74608 +
74609 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74610 + old_len > pax_task_size || addr > pax_task_size-old_len)
74611 + goto out;
74612 +
74613 if (flags & MREMAP_FIXED) {
74614 if (flags & MREMAP_MAYMOVE)
74615 ret = mremap_to(addr, old_len, new_addr, new_len);
74616 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74617 addr + new_len);
74618 }
74619 ret = addr;
74620 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74621 goto out;
74622 }
74623 }
74624 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74625 goto out;
74626 }
74627
74628 + map_flags = vma->vm_flags;
74629 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74630 + if (!(ret & ~PAGE_MASK)) {
74631 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74632 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74633 + }
74634 }
74635 out:
74636 if (ret & ~PAGE_MASK)
74637 diff --git a/mm/nommu.c b/mm/nommu.c
74638 index d4b0c10..ed421b5 100644
74639 --- a/mm/nommu.c
74640 +++ b/mm/nommu.c
74641 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74642 int sysctl_overcommit_ratio = 50; /* default is 50% */
74643 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74644 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74645 -int heap_stack_gap = 0;
74646
74647 atomic_long_t mmap_pages_allocated;
74648
74649 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74650 EXPORT_SYMBOL(find_vma);
74651
74652 /*
74653 - * find a VMA
74654 - * - we don't extend stack VMAs under NOMMU conditions
74655 - */
74656 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74657 -{
74658 - return find_vma(mm, addr);
74659 -}
74660 -
74661 -/*
74662 * expand a stack to a given address
74663 * - not supported under NOMMU conditions
74664 */
74665 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74666
74667 /* most fields are the same, copy all, and then fixup */
74668 *new = *vma;
74669 + INIT_LIST_HEAD(&new->anon_vma_chain);
74670 *region = *vma->vm_region;
74671 new->vm_region = region;
74672
74673 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74674 index c13ea75..081ab2c 100644
74675 --- a/mm/page_alloc.c
74676 +++ b/mm/page_alloc.c
74677 @@ -340,7 +340,7 @@ out:
74678 * This usage means that zero-order pages may not be compound.
74679 */
74680
74681 -static void free_compound_page(struct page *page)
74682 +void free_compound_page(struct page *page)
74683 {
74684 __free_pages_ok(page, compound_order(page));
74685 }
74686 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74687 int i;
74688 int bad = 0;
74689
74690 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74691 + unsigned long index = 1UL << order;
74692 +#endif
74693 +
74694 trace_mm_page_free(page, order);
74695 kmemcheck_free_shadow(page, order);
74696
74697 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74698 debug_check_no_obj_freed(page_address(page),
74699 PAGE_SIZE << order);
74700 }
74701 +
74702 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74703 + for (; index; --index)
74704 + sanitize_highpage(page + index - 1);
74705 +#endif
74706 +
74707 arch_free_page(page, order);
74708 kernel_map_pages(page, 1 << order, 0);
74709
74710 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74711 arch_alloc_page(page, order);
74712 kernel_map_pages(page, 1 << order, 1);
74713
74714 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74715 if (gfp_flags & __GFP_ZERO)
74716 prep_zero_page(page, order, gfp_flags);
74717 +#endif
74718
74719 if (order && (gfp_flags & __GFP_COMP))
74720 prep_compound_page(page, order);
74721 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74722 unsigned long pfn;
74723
74724 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74725 +#ifdef CONFIG_X86_32
74726 + /* boot failures in VMware 8 on 32bit vanilla since
74727 + this change */
74728 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74729 +#else
74730 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74731 +#endif
74732 return 1;
74733 }
74734 return 0;
74735 diff --git a/mm/percpu.c b/mm/percpu.c
74736 index bb4be74..a43ea85 100644
74737 --- a/mm/percpu.c
74738 +++ b/mm/percpu.c
74739 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74740 static unsigned int pcpu_high_unit_cpu __read_mostly;
74741
74742 /* the address of the first chunk which starts with the kernel static area */
74743 -void *pcpu_base_addr __read_mostly;
74744 +void *pcpu_base_addr __read_only;
74745 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74746
74747 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74748 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74749 index 926b466..b23df53 100644
74750 --- a/mm/process_vm_access.c
74751 +++ b/mm/process_vm_access.c
74752 @@ -13,6 +13,7 @@
74753 #include <linux/uio.h>
74754 #include <linux/sched.h>
74755 #include <linux/highmem.h>
74756 +#include <linux/security.h>
74757 #include <linux/ptrace.h>
74758 #include <linux/slab.h>
74759 #include <linux/syscalls.h>
74760 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74761 size_t iov_l_curr_offset = 0;
74762 ssize_t iov_len;
74763
74764 + return -ENOSYS; // PaX: until properly audited
74765 +
74766 /*
74767 * Work out how many pages of struct pages we're going to need
74768 * when eventually calling get_user_pages
74769 */
74770 for (i = 0; i < riovcnt; i++) {
74771 iov_len = rvec[i].iov_len;
74772 - if (iov_len > 0) {
74773 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74774 - + iov_len)
74775 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74776 - / PAGE_SIZE + 1;
74777 - nr_pages = max(nr_pages, nr_pages_iov);
74778 - }
74779 + if (iov_len <= 0)
74780 + continue;
74781 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74782 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74783 + nr_pages = max(nr_pages, nr_pages_iov);
74784 }
74785
74786 if (nr_pages == 0)
74787 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74788 goto free_proc_pages;
74789 }
74790
74791 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74792 + rc = -EPERM;
74793 + goto put_task_struct;
74794 + }
74795 +
74796 mm = mm_access(task, PTRACE_MODE_ATTACH);
74797 if (!mm || IS_ERR(mm)) {
74798 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74799 diff --git a/mm/rmap.c b/mm/rmap.c
74800 index aa95e59..b681a63 100644
74801 --- a/mm/rmap.c
74802 +++ b/mm/rmap.c
74803 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74804 struct anon_vma *anon_vma = vma->anon_vma;
74805 struct anon_vma_chain *avc;
74806
74807 +#ifdef CONFIG_PAX_SEGMEXEC
74808 + struct anon_vma_chain *avc_m = NULL;
74809 +#endif
74810 +
74811 might_sleep();
74812 if (unlikely(!anon_vma)) {
74813 struct mm_struct *mm = vma->vm_mm;
74814 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74815 if (!avc)
74816 goto out_enomem;
74817
74818 +#ifdef CONFIG_PAX_SEGMEXEC
74819 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74820 + if (!avc_m)
74821 + goto out_enomem_free_avc;
74822 +#endif
74823 +
74824 anon_vma = find_mergeable_anon_vma(vma);
74825 allocated = NULL;
74826 if (!anon_vma) {
74827 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74828 /* page_table_lock to protect against threads */
74829 spin_lock(&mm->page_table_lock);
74830 if (likely(!vma->anon_vma)) {
74831 +
74832 +#ifdef CONFIG_PAX_SEGMEXEC
74833 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74834 +
74835 + if (vma_m) {
74836 + BUG_ON(vma_m->anon_vma);
74837 + vma_m->anon_vma = anon_vma;
74838 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74839 + avc_m = NULL;
74840 + }
74841 +#endif
74842 +
74843 vma->anon_vma = anon_vma;
74844 anon_vma_chain_link(vma, avc, anon_vma);
74845 allocated = NULL;
74846 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74847
74848 if (unlikely(allocated))
74849 put_anon_vma(allocated);
74850 +
74851 +#ifdef CONFIG_PAX_SEGMEXEC
74852 + if (unlikely(avc_m))
74853 + anon_vma_chain_free(avc_m);
74854 +#endif
74855 +
74856 if (unlikely(avc))
74857 anon_vma_chain_free(avc);
74858 }
74859 return 0;
74860
74861 out_enomem_free_avc:
74862 +
74863 +#ifdef CONFIG_PAX_SEGMEXEC
74864 + if (avc_m)
74865 + anon_vma_chain_free(avc_m);
74866 +#endif
74867 +
74868 anon_vma_chain_free(avc);
74869 out_enomem:
74870 return -ENOMEM;
74871 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74872 * Attach the anon_vmas from src to dst.
74873 * Returns 0 on success, -ENOMEM on failure.
74874 */
74875 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74876 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74877 {
74878 struct anon_vma_chain *avc, *pavc;
74879 struct anon_vma *root = NULL;
74880 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74881 * the corresponding VMA in the parent process is attached to.
74882 * Returns 0 on success, non-zero on failure.
74883 */
74884 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74885 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74886 {
74887 struct anon_vma_chain *avc;
74888 struct anon_vma *anon_vma;
74889 diff --git a/mm/shmem.c b/mm/shmem.c
74890 index d2eeca1..92f3123 100644
74891 --- a/mm/shmem.c
74892 +++ b/mm/shmem.c
74893 @@ -31,7 +31,7 @@
74894 #include <linux/export.h>
74895 #include <linux/swap.h>
74896
74897 -static struct vfsmount *shm_mnt;
74898 +struct vfsmount *shm_mnt;
74899
74900 #ifdef CONFIG_SHMEM
74901 /*
74902 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74903 #define BOGO_DIRENT_SIZE 20
74904
74905 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74906 -#define SHORT_SYMLINK_LEN 128
74907 +#define SHORT_SYMLINK_LEN 64
74908
74909 struct shmem_xattr {
74910 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74911 @@ -2207,6 +2207,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
74912 static int shmem_xattr_validate(const char *name)
74913 {
74914 struct { const char *prefix; size_t len; } arr[] = {
74915 +
74916 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
74917 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
74918 +#endif
74919 +
74920 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
74921 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
74922 };
74923 @@ -2260,6 +2265,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
74924 if (err)
74925 return err;
74926
74927 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
74928 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
74929 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
74930 + return -EOPNOTSUPP;
74931 + if (size > 8)
74932 + return -EINVAL;
74933 + }
74934 +#endif
74935 +
74936 if (size == 0)
74937 value = ""; /* empty EA, do not remove */
74938
74939 @@ -2594,8 +2608,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74940 int err = -ENOMEM;
74941
74942 /* Round up to L1_CACHE_BYTES to resist false sharing */
74943 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74944 - L1_CACHE_BYTES), GFP_KERNEL);
74945 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74946 if (!sbinfo)
74947 return -ENOMEM;
74948
74949 diff --git a/mm/slab.c b/mm/slab.c
74950 index d066037..5bb78d9 100644
74951 --- a/mm/slab.c
74952 +++ b/mm/slab.c
74953 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74954
74955 /* Legal flag mask for kmem_cache_create(). */
74956 #if DEBUG
74957 -# define CREATE_MASK (SLAB_RED_ZONE | \
74958 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74959 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74960 SLAB_CACHE_DMA | \
74961 SLAB_STORE_USER | \
74962 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74963 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74964 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74965 #else
74966 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74967 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74968 SLAB_CACHE_DMA | \
74969 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74970 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74971 @@ -322,7 +322,7 @@ struct kmem_list3 {
74972 * Need this for bootstrapping a per node allocator.
74973 */
74974 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74975 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74976 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74977 #define CACHE_CACHE 0
74978 #define SIZE_AC MAX_NUMNODES
74979 #define SIZE_L3 (2 * MAX_NUMNODES)
74980 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74981 if ((x)->max_freeable < i) \
74982 (x)->max_freeable = i; \
74983 } while (0)
74984 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74985 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74986 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74987 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74988 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74989 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74990 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74991 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74992 #else
74993 #define STATS_INC_ACTIVE(x) do { } while (0)
74994 #define STATS_DEC_ACTIVE(x) do { } while (0)
74995 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74996 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74997 */
74998 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74999 - const struct slab *slab, void *obj)
75000 + const struct slab *slab, const void *obj)
75001 {
75002 u32 offset = (obj - slab->s_mem);
75003 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75004 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75005 struct cache_names {
75006 char *name;
75007 char *name_dma;
75008 + char *name_usercopy;
75009 };
75010
75011 static struct cache_names __initdata cache_names[] = {
75012 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75013 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75014 #include <linux/kmalloc_sizes.h>
75015 - {NULL,}
75016 + {NULL}
75017 #undef CACHE
75018 };
75019
75020 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75021 if (unlikely(gfpflags & GFP_DMA))
75022 return csizep->cs_dmacachep;
75023 #endif
75024 +
75025 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75026 + if (unlikely(gfpflags & GFP_USERCOPY))
75027 + return csizep->cs_usercopycachep;
75028 +#endif
75029 +
75030 return csizep->cs_cachep;
75031 }
75032
75033 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75034 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75035 sizes[INDEX_AC].cs_size,
75036 ARCH_KMALLOC_MINALIGN,
75037 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75038 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75039 NULL);
75040
75041 if (INDEX_AC != INDEX_L3) {
75042 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75043 __kmem_cache_create(names[INDEX_L3].name,
75044 sizes[INDEX_L3].cs_size,
75045 ARCH_KMALLOC_MINALIGN,
75046 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75047 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75048 NULL);
75049 }
75050
75051 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75052 sizes->cs_cachep = __kmem_cache_create(names->name,
75053 sizes->cs_size,
75054 ARCH_KMALLOC_MINALIGN,
75055 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75056 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75057 NULL);
75058 }
75059 #ifdef CONFIG_ZONE_DMA
75060 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75061 SLAB_PANIC,
75062 NULL);
75063 #endif
75064 +
75065 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75066 + sizes->cs_usercopycachep = kmem_cache_create(
75067 + names->name_usercopy,
75068 + sizes->cs_size,
75069 + ARCH_KMALLOC_MINALIGN,
75070 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75071 + NULL);
75072 +#endif
75073 +
75074 sizes++;
75075 names++;
75076 }
75077 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75078 }
75079 /* cpu stats */
75080 {
75081 - unsigned long allochit = atomic_read(&cachep->allochit);
75082 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75083 - unsigned long freehit = atomic_read(&cachep->freehit);
75084 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75085 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75086 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75087 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75088 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75089
75090 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75091 allochit, allocmiss, freehit, freemiss);
75092 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75093 {
75094 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75095 #ifdef CONFIG_DEBUG_SLAB_LEAK
75096 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75097 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75098 #endif
75099 return 0;
75100 }
75101 module_init(slab_proc_init);
75102 #endif
75103
75104 +bool is_usercopy_object(const void *ptr)
75105 +{
75106 + struct page *page;
75107 + struct kmem_cache *cachep;
75108 +
75109 + if (ZERO_OR_NULL_PTR(ptr))
75110 + return false;
75111 +
75112 + if (!slab_is_available())
75113 + return false;
75114 +
75115 + if (!virt_addr_valid(ptr))
75116 + return false;
75117 +
75118 + page = virt_to_head_page(ptr);
75119 +
75120 + if (!PageSlab(page))
75121 + return false;
75122 +
75123 + cachep = page_get_cache(page);
75124 + return cachep->flags & SLAB_USERCOPY;
75125 +}
75126 +
75127 +#ifdef CONFIG_PAX_USERCOPY
75128 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75129 +{
75130 + struct page *page;
75131 + struct kmem_cache *cachep;
75132 + struct slab *slabp;
75133 + unsigned int objnr;
75134 + unsigned long offset;
75135 +
75136 + if (ZERO_OR_NULL_PTR(ptr))
75137 + return "<null>";
75138 +
75139 + if (!virt_addr_valid(ptr))
75140 + return NULL;
75141 +
75142 + page = virt_to_head_page(ptr);
75143 +
75144 + if (!PageSlab(page))
75145 + return NULL;
75146 +
75147 + cachep = page_get_cache(page);
75148 + if (!(cachep->flags & SLAB_USERCOPY))
75149 + return cachep->name;
75150 +
75151 + slabp = page->slab_page;
75152 + objnr = obj_to_index(cachep, slabp, ptr);
75153 + BUG_ON(objnr >= cachep->num);
75154 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75155 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75156 + return NULL;
75157 +
75158 + return cachep->name;
75159 +}
75160 +#endif
75161 +
75162 /**
75163 * ksize - get the actual amount of memory allocated for a given object
75164 * @objp: Pointer to the object
75165 diff --git a/mm/slob.c b/mm/slob.c
75166 index 45d4ca7..88943c1 100644
75167 --- a/mm/slob.c
75168 +++ b/mm/slob.c
75169 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75170 /*
75171 * Return the size of a slob block.
75172 */
75173 -static slobidx_t slob_units(slob_t *s)
75174 +static slobidx_t slob_units(const slob_t *s)
75175 {
75176 if (s->units > 0)
75177 return s->units;
75178 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75179 /*
75180 * Return the next free slob block pointer after this one.
75181 */
75182 -static slob_t *slob_next(slob_t *s)
75183 +static slob_t *slob_next(const slob_t *s)
75184 {
75185 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75186 slobidx_t next;
75187 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75188 /*
75189 * Returns true if s is the last free block in its page.
75190 */
75191 -static int slob_last(slob_t *s)
75192 +static int slob_last(const slob_t *s)
75193 {
75194 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75195 }
75196
75197 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75198 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75199 {
75200 - void *page;
75201 + struct page *page;
75202
75203 #ifdef CONFIG_NUMA
75204 if (node != -1)
75205 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75206 if (!page)
75207 return NULL;
75208
75209 - return page_address(page);
75210 + __SetPageSlab(page);
75211 + return page;
75212 }
75213
75214 -static void slob_free_pages(void *b, int order)
75215 +static void slob_free_pages(struct page *sp, int order)
75216 {
75217 if (current->reclaim_state)
75218 current->reclaim_state->reclaimed_slab += 1 << order;
75219 - free_pages((unsigned long)b, order);
75220 + __ClearPageSlab(sp);
75221 + reset_page_mapcount(sp);
75222 + sp->private = 0;
75223 + __free_pages(sp, order);
75224 }
75225
75226 /*
75227 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75228
75229 /* Not enough space: must allocate a new page */
75230 if (!b) {
75231 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75232 - if (!b)
75233 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75234 + if (!sp)
75235 return NULL;
75236 - sp = virt_to_page(b);
75237 - __SetPageSlab(sp);
75238 + b = page_address(sp);
75239
75240 spin_lock_irqsave(&slob_lock, flags);
75241 sp->units = SLOB_UNITS(PAGE_SIZE);
75242 sp->freelist = b;
75243 + sp->private = 0;
75244 INIT_LIST_HEAD(&sp->list);
75245 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75246 set_slob_page_free(sp, slob_list);
75247 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75248 if (slob_page_free(sp))
75249 clear_slob_page_free(sp);
75250 spin_unlock_irqrestore(&slob_lock, flags);
75251 - __ClearPageSlab(sp);
75252 - reset_page_mapcount(sp);
75253 - slob_free_pages(b, 0);
75254 + slob_free_pages(sp, 0);
75255 return;
75256 }
75257
75258 @@ -425,11 +427,10 @@ out:
75259 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75260 */
75261
75262 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75263 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75264 {
75265 - unsigned int *m;
75266 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75267 - void *ret;
75268 + slob_t *m;
75269 + void *ret = NULL;
75270
75271 gfp &= gfp_allowed_mask;
75272
75273 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75274
75275 if (!m)
75276 return NULL;
75277 - *m = size;
75278 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75279 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75280 + m[0].units = size;
75281 + m[1].units = align;
75282 ret = (void *)m + align;
75283
75284 trace_kmalloc_node(_RET_IP_, ret,
75285 size, size + align, gfp, node);
75286 } else {
75287 unsigned int order = get_order(size);
75288 + struct page *page;
75289
75290 if (likely(order))
75291 gfp |= __GFP_COMP;
75292 - ret = slob_new_pages(gfp, order, node);
75293 - if (ret) {
75294 - struct page *page;
75295 - page = virt_to_page(ret);
75296 + page = slob_new_pages(gfp, order, node);
75297 + if (page) {
75298 + ret = page_address(page);
75299 page->private = size;
75300 }
75301
75302 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75303 size, PAGE_SIZE << order, gfp, node);
75304 }
75305
75306 - kmemleak_alloc(ret, size, 1, gfp);
75307 + return ret;
75308 +}
75309 +
75310 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75311 +{
75312 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75313 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75314 +
75315 + if (!ZERO_OR_NULL_PTR(ret))
75316 + kmemleak_alloc(ret, size, 1, gfp);
75317 return ret;
75318 }
75319 EXPORT_SYMBOL(__kmalloc_node);
75320 @@ -480,15 +493,91 @@ void kfree(const void *block)
75321 kmemleak_free(block);
75322
75323 sp = virt_to_page(block);
75324 - if (PageSlab(sp)) {
75325 + VM_BUG_ON(!PageSlab(sp));
75326 + if (!sp->private) {
75327 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75328 - unsigned int *m = (unsigned int *)(block - align);
75329 - slob_free(m, *m + align);
75330 - } else
75331 + slob_t *m = (slob_t *)(block - align);
75332 + slob_free(m, m[0].units + align);
75333 + } else {
75334 + __ClearPageSlab(sp);
75335 + reset_page_mapcount(sp);
75336 + sp->private = 0;
75337 put_page(sp);
75338 + }
75339 }
75340 EXPORT_SYMBOL(kfree);
75341
75342 +bool is_usercopy_object(const void *ptr)
75343 +{
75344 + if (!slab_is_available())
75345 + return false;
75346 +
75347 + // PAX: TODO
75348 +
75349 + return false;
75350 +}
75351 +
75352 +#ifdef CONFIG_PAX_USERCOPY
75353 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75354 +{
75355 + struct page *page;
75356 + const slob_t *free;
75357 + const void *base;
75358 + unsigned long flags;
75359 +
75360 + if (ZERO_OR_NULL_PTR(ptr))
75361 + return "<null>";
75362 +
75363 + if (!virt_addr_valid(ptr))
75364 + return NULL;
75365 +
75366 + page = virt_to_head_page(ptr);
75367 + if (!PageSlab(page))
75368 + return NULL;
75369 +
75370 + if (page->private) {
75371 + base = page;
75372 + if (base <= ptr && n <= page->private - (ptr - base))
75373 + return NULL;
75374 + return "<slob>";
75375 + }
75376 +
75377 + /* some tricky double walking to find the chunk */
75378 + spin_lock_irqsave(&slob_lock, flags);
75379 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75380 + free = page->freelist;
75381 +
75382 + while (!slob_last(free) && (void *)free <= ptr) {
75383 + base = free + slob_units(free);
75384 + free = slob_next(free);
75385 + }
75386 +
75387 + while (base < (void *)free) {
75388 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75389 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75390 + int offset;
75391 +
75392 + if (ptr < base + align)
75393 + break;
75394 +
75395 + offset = ptr - base - align;
75396 + if (offset >= m) {
75397 + base += size;
75398 + continue;
75399 + }
75400 +
75401 + if (n > m - offset)
75402 + break;
75403 +
75404 + spin_unlock_irqrestore(&slob_lock, flags);
75405 + return NULL;
75406 + }
75407 +
75408 + spin_unlock_irqrestore(&slob_lock, flags);
75409 + return "<slob>";
75410 +}
75411 +#endif
75412 +
75413 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75414 size_t ksize(const void *block)
75415 {
75416 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75417 return 0;
75418
75419 sp = virt_to_page(block);
75420 - if (PageSlab(sp)) {
75421 + VM_BUG_ON(!PageSlab(sp));
75422 + if (!sp->private) {
75423 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75424 - unsigned int *m = (unsigned int *)(block - align);
75425 - return SLOB_UNITS(*m) * SLOB_UNIT;
75426 + slob_t *m = (slob_t *)(block - align);
75427 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75428 } else
75429 return sp->private;
75430 }
75431 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75432 {
75433 struct kmem_cache *c;
75434
75435 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75436 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75437 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75438 +#else
75439 c = slob_alloc(sizeof(struct kmem_cache),
75440 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75441 +#endif
75442
75443 if (c) {
75444 c->name = name;
75445 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75446
75447 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75448 {
75449 - void *b;
75450 + void *b = NULL;
75451
75452 flags &= gfp_allowed_mask;
75453
75454 lockdep_trace_alloc(flags);
75455
75456 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75457 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75458 +#else
75459 if (c->size < PAGE_SIZE) {
75460 b = slob_alloc(c->size, flags, c->align, node);
75461 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75462 SLOB_UNITS(c->size) * SLOB_UNIT,
75463 flags, node);
75464 } else {
75465 - b = slob_new_pages(flags, get_order(c->size), node);
75466 + struct page *sp;
75467 +
75468 + sp = slob_new_pages(flags, get_order(c->size), node);
75469 + if (sp) {
75470 + b = page_address(sp);
75471 + sp->private = c->size;
75472 + }
75473 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75474 PAGE_SIZE << get_order(c->size),
75475 flags, node);
75476 }
75477 +#endif
75478
75479 if (c->ctor)
75480 c->ctor(b);
75481 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75482
75483 static void __kmem_cache_free(void *b, int size)
75484 {
75485 - if (size < PAGE_SIZE)
75486 + struct page *sp;
75487 +
75488 + sp = virt_to_page(b);
75489 + BUG_ON(!PageSlab(sp));
75490 + if (!sp->private)
75491 slob_free(b, size);
75492 else
75493 - slob_free_pages(b, get_order(size));
75494 + slob_free_pages(sp, get_order(size));
75495 }
75496
75497 static void kmem_rcu_free(struct rcu_head *head)
75498 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75499
75500 void kmem_cache_free(struct kmem_cache *c, void *b)
75501 {
75502 + int size = c->size;
75503 +
75504 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75505 + if (size + c->align < PAGE_SIZE) {
75506 + size += c->align;
75507 + b -= c->align;
75508 + }
75509 +#endif
75510 +
75511 kmemleak_free_recursive(b, c->flags);
75512 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75513 struct slob_rcu *slob_rcu;
75514 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75515 - slob_rcu->size = c->size;
75516 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75517 + slob_rcu->size = size;
75518 call_rcu(&slob_rcu->head, kmem_rcu_free);
75519 } else {
75520 - __kmem_cache_free(b, c->size);
75521 + __kmem_cache_free(b, size);
75522 }
75523
75524 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75525 + trace_kfree(_RET_IP_, b);
75526 +#else
75527 trace_kmem_cache_free(_RET_IP_, b);
75528 +#endif
75529 +
75530 }
75531 EXPORT_SYMBOL(kmem_cache_free);
75532
75533 diff --git a/mm/slub.c b/mm/slub.c
75534 index 2fdd96f..1e2f893 100644
75535 --- a/mm/slub.c
75536 +++ b/mm/slub.c
75537 @@ -201,7 +201,7 @@ struct track {
75538
75539 enum track_item { TRACK_ALLOC, TRACK_FREE };
75540
75541 -#ifdef CONFIG_SYSFS
75542 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75543 static int sysfs_slab_add(struct kmem_cache *);
75544 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75545 static void sysfs_slab_remove(struct kmem_cache *);
75546 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75547 if (!t->addr)
75548 return;
75549
75550 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75551 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75552 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75553 #ifdef CONFIG_STACKTRACE
75554 {
75555 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75556
75557 page = virt_to_head_page(x);
75558
75559 + BUG_ON(!PageSlab(page));
75560 +
75561 slab_free(s, page, x, _RET_IP_);
75562
75563 trace_kmem_cache_free(_RET_IP_, x);
75564 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75565 * Merge control. If this is set then no merging of slab caches will occur.
75566 * (Could be removed. This was introduced to pacify the merge skeptics.)
75567 */
75568 -static int slub_nomerge;
75569 +static int slub_nomerge = 1;
75570
75571 /*
75572 * Calculate the order of allocation given an slab object size.
75573 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75574 else
75575 s->cpu_partial = 30;
75576
75577 - s->refcount = 1;
75578 + atomic_set(&s->refcount, 1);
75579 #ifdef CONFIG_NUMA
75580 s->remote_node_defrag_ratio = 1000;
75581 #endif
75582 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75583 void kmem_cache_destroy(struct kmem_cache *s)
75584 {
75585 mutex_lock(&slab_mutex);
75586 - s->refcount--;
75587 - if (!s->refcount) {
75588 + if (atomic_dec_and_test(&s->refcount)) {
75589 list_del(&s->list);
75590 mutex_unlock(&slab_mutex);
75591 if (kmem_cache_close(s)) {
75592 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75593 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75594 #endif
75595
75596 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75597 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75598 +#endif
75599 +
75600 static int __init setup_slub_min_order(char *str)
75601 {
75602 get_option(&str, &slub_min_order);
75603 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75604 return kmalloc_dma_caches[index];
75605
75606 #endif
75607 +
75608 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75609 + if (flags & SLAB_USERCOPY)
75610 + return kmalloc_usercopy_caches[index];
75611 +
75612 +#endif
75613 +
75614 return kmalloc_caches[index];
75615 }
75616
75617 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75618 EXPORT_SYMBOL(__kmalloc_node);
75619 #endif
75620
75621 +bool is_usercopy_object(const void *ptr)
75622 +{
75623 + struct page *page;
75624 + struct kmem_cache *s;
75625 +
75626 + if (ZERO_OR_NULL_PTR(ptr))
75627 + return false;
75628 +
75629 + if (!slab_is_available())
75630 + return false;
75631 +
75632 + if (!virt_addr_valid(ptr))
75633 + return false;
75634 +
75635 + page = virt_to_head_page(ptr);
75636 +
75637 + if (!PageSlab(page))
75638 + return false;
75639 +
75640 + s = page->slab;
75641 + return s->flags & SLAB_USERCOPY;
75642 +}
75643 +
75644 +#ifdef CONFIG_PAX_USERCOPY
75645 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75646 +{
75647 + struct page *page;
75648 + struct kmem_cache *s;
75649 + unsigned long offset;
75650 +
75651 + if (ZERO_OR_NULL_PTR(ptr))
75652 + return "<null>";
75653 +
75654 + if (!virt_addr_valid(ptr))
75655 + return NULL;
75656 +
75657 + page = virt_to_head_page(ptr);
75658 +
75659 + if (!PageSlab(page))
75660 + return NULL;
75661 +
75662 + s = page->slab;
75663 + if (!(s->flags & SLAB_USERCOPY))
75664 + return s->name;
75665 +
75666 + offset = (ptr - page_address(page)) % s->size;
75667 + if (offset <= s->object_size && n <= s->object_size - offset)
75668 + return NULL;
75669 +
75670 + return s->name;
75671 +}
75672 +#endif
75673 +
75674 size_t ksize(const void *object)
75675 {
75676 struct page *page;
75677 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75678 int node;
75679
75680 list_add(&s->list, &slab_caches);
75681 - s->refcount = -1;
75682 + atomic_set(&s->refcount, -1);
75683
75684 for_each_node_state(node, N_NORMAL_MEMORY) {
75685 struct kmem_cache_node *n = get_node(s, node);
75686 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75687
75688 /* Caches that are not of the two-to-the-power-of size */
75689 if (KMALLOC_MIN_SIZE <= 32) {
75690 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75691 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75692 caches++;
75693 }
75694
75695 if (KMALLOC_MIN_SIZE <= 64) {
75696 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75697 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75698 caches++;
75699 }
75700
75701 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75702 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75703 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75704 caches++;
75705 }
75706
75707 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75708 }
75709 }
75710 #endif
75711 +
75712 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75713 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75714 + struct kmem_cache *s = kmalloc_caches[i];
75715 +
75716 + if (s && s->size) {
75717 + char *name = kasprintf(GFP_NOWAIT,
75718 + "usercopy-kmalloc-%d", s->object_size);
75719 +
75720 + BUG_ON(!name);
75721 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75722 + s->object_size, SLAB_USERCOPY);
75723 + }
75724 + }
75725 +#endif
75726 +
75727 printk(KERN_INFO
75728 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75729 " CPUs=%d, Nodes=%d\n",
75730 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75731 /*
75732 * We may have set a slab to be unmergeable during bootstrap.
75733 */
75734 - if (s->refcount < 0)
75735 + if (atomic_read(&s->refcount) < 0)
75736 return 1;
75737
75738 return 0;
75739 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75740
75741 s = find_mergeable(size, align, flags, name, ctor);
75742 if (s) {
75743 - s->refcount++;
75744 + atomic_inc(&s->refcount);
75745 /*
75746 * Adjust the object sizes so that we clear
75747 * the complete object on kzalloc.
75748 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75749 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75750
75751 if (sysfs_slab_alias(s, name)) {
75752 - s->refcount--;
75753 + atomic_dec(&s->refcount);
75754 return NULL;
75755 }
75756 return s;
75757 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75758 }
75759 #endif
75760
75761 -#ifdef CONFIG_SYSFS
75762 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75763 static int count_inuse(struct page *page)
75764 {
75765 return page->inuse;
75766 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75767 validate_slab_cache(kmalloc_caches[9]);
75768 }
75769 #else
75770 -#ifdef CONFIG_SYSFS
75771 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75772 static void resiliency_test(void) {};
75773 #endif
75774 #endif
75775
75776 -#ifdef CONFIG_SYSFS
75777 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75778 enum slab_stat_type {
75779 SL_ALL, /* All slabs */
75780 SL_PARTIAL, /* Only partially allocated slabs */
75781 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75782
75783 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75784 {
75785 - return sprintf(buf, "%d\n", s->refcount - 1);
75786 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75787 }
75788 SLAB_ATTR_RO(aliases);
75789
75790 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75791 return name;
75792 }
75793
75794 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75795 static int sysfs_slab_add(struct kmem_cache *s)
75796 {
75797 int err;
75798 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75799 kobject_del(&s->kobj);
75800 kobject_put(&s->kobj);
75801 }
75802 +#endif
75803
75804 /*
75805 * Need to buffer aliases during bootup until sysfs becomes
75806 @@ -5354,6 +5437,7 @@ struct saved_alias {
75807
75808 static struct saved_alias *alias_list;
75809
75810 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75811 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75812 {
75813 struct saved_alias *al;
75814 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75815 alias_list = al;
75816 return 0;
75817 }
75818 +#endif
75819
75820 static int __init slab_sysfs_init(void)
75821 {
75822 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75823 index 1b7e22a..3fcd4f3 100644
75824 --- a/mm/sparse-vmemmap.c
75825 +++ b/mm/sparse-vmemmap.c
75826 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75827 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75828 if (!p)
75829 return NULL;
75830 - pud_populate(&init_mm, pud, p);
75831 + pud_populate_kernel(&init_mm, pud, p);
75832 }
75833 return pud;
75834 }
75835 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75836 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75837 if (!p)
75838 return NULL;
75839 - pgd_populate(&init_mm, pgd, p);
75840 + pgd_populate_kernel(&init_mm, pgd, p);
75841 }
75842 return pgd;
75843 }
75844 diff --git a/mm/swap.c b/mm/swap.c
75845 index 7782588..228c784 100644
75846 --- a/mm/swap.c
75847 +++ b/mm/swap.c
75848 @@ -30,6 +30,7 @@
75849 #include <linux/backing-dev.h>
75850 #include <linux/memcontrol.h>
75851 #include <linux/gfp.h>
75852 +#include <linux/hugetlb.h>
75853
75854 #include "internal.h"
75855
75856 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75857
75858 __page_cache_release(page);
75859 dtor = get_compound_page_dtor(page);
75860 + if (!PageHuge(page))
75861 + BUG_ON(dtor != free_compound_page);
75862 (*dtor)(page);
75863 }
75864
75865 diff --git a/mm/swapfile.c b/mm/swapfile.c
75866 index 14e254c..a6af32c 100644
75867 --- a/mm/swapfile.c
75868 +++ b/mm/swapfile.c
75869 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75870
75871 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75872 /* Activity counter to indicate that a swapon or swapoff has occurred */
75873 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75874 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75875
75876 static inline unsigned char swap_count(unsigned char ent)
75877 {
75878 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75879 }
75880 filp_close(swap_file, NULL);
75881 err = 0;
75882 - atomic_inc(&proc_poll_event);
75883 + atomic_inc_unchecked(&proc_poll_event);
75884 wake_up_interruptible(&proc_poll_wait);
75885
75886 out_dput:
75887 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75888
75889 poll_wait(file, &proc_poll_wait, wait);
75890
75891 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75892 - seq->poll_event = atomic_read(&proc_poll_event);
75893 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75894 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75895 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75896 }
75897
75898 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75899 return ret;
75900
75901 seq = file->private_data;
75902 - seq->poll_event = atomic_read(&proc_poll_event);
75903 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75904 return 0;
75905 }
75906
75907 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75908 (frontswap_map) ? "FS" : "");
75909
75910 mutex_unlock(&swapon_mutex);
75911 - atomic_inc(&proc_poll_event);
75912 + atomic_inc_unchecked(&proc_poll_event);
75913 wake_up_interruptible(&proc_poll_wait);
75914
75915 if (S_ISREG(inode->i_mode))
75916 diff --git a/mm/util.c b/mm/util.c
75917 index 8c7265a..c96d884 100644
75918 --- a/mm/util.c
75919 +++ b/mm/util.c
75920 @@ -285,6 +285,12 @@ done:
75921 void arch_pick_mmap_layout(struct mm_struct *mm)
75922 {
75923 mm->mmap_base = TASK_UNMAPPED_BASE;
75924 +
75925 +#ifdef CONFIG_PAX_RANDMMAP
75926 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75927 + mm->mmap_base += mm->delta_mmap;
75928 +#endif
75929 +
75930 mm->get_unmapped_area = arch_get_unmapped_area;
75931 mm->unmap_area = arch_unmap_area;
75932 }
75933 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75934 index 2bb90b1..3795e47 100644
75935 --- a/mm/vmalloc.c
75936 +++ b/mm/vmalloc.c
75937 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75938
75939 pte = pte_offset_kernel(pmd, addr);
75940 do {
75941 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75942 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75943 +
75944 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75945 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75946 + BUG_ON(!pte_exec(*pte));
75947 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75948 + continue;
75949 + }
75950 +#endif
75951 +
75952 + {
75953 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75954 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75955 + }
75956 } while (pte++, addr += PAGE_SIZE, addr != end);
75957 }
75958
75959 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75960 pte = pte_alloc_kernel(pmd, addr);
75961 if (!pte)
75962 return -ENOMEM;
75963 +
75964 + pax_open_kernel();
75965 do {
75966 struct page *page = pages[*nr];
75967
75968 - if (WARN_ON(!pte_none(*pte)))
75969 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75970 + if (pgprot_val(prot) & _PAGE_NX)
75971 +#endif
75972 +
75973 + if (!pte_none(*pte)) {
75974 + pax_close_kernel();
75975 + WARN_ON(1);
75976 return -EBUSY;
75977 - if (WARN_ON(!page))
75978 + }
75979 + if (!page) {
75980 + pax_close_kernel();
75981 + WARN_ON(1);
75982 return -ENOMEM;
75983 + }
75984 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75985 (*nr)++;
75986 } while (pte++, addr += PAGE_SIZE, addr != end);
75987 + pax_close_kernel();
75988 return 0;
75989 }
75990
75991 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75992 pmd_t *pmd;
75993 unsigned long next;
75994
75995 - pmd = pmd_alloc(&init_mm, pud, addr);
75996 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75997 if (!pmd)
75998 return -ENOMEM;
75999 do {
76000 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76001 pud_t *pud;
76002 unsigned long next;
76003
76004 - pud = pud_alloc(&init_mm, pgd, addr);
76005 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76006 if (!pud)
76007 return -ENOMEM;
76008 do {
76009 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76010 * and fall back on vmalloc() if that fails. Others
76011 * just put it in the vmalloc space.
76012 */
76013 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76014 +#ifdef CONFIG_MODULES
76015 +#ifdef MODULES_VADDR
76016 unsigned long addr = (unsigned long)x;
76017 if (addr >= MODULES_VADDR && addr < MODULES_END)
76018 return 1;
76019 #endif
76020 +
76021 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76022 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76023 + return 1;
76024 +#endif
76025 +
76026 +#endif
76027 +
76028 return is_vmalloc_addr(x);
76029 }
76030
76031 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76032
76033 if (!pgd_none(*pgd)) {
76034 pud_t *pud = pud_offset(pgd, addr);
76035 +#ifdef CONFIG_X86
76036 + if (!pud_large(*pud))
76037 +#endif
76038 if (!pud_none(*pud)) {
76039 pmd_t *pmd = pmd_offset(pud, addr);
76040 +#ifdef CONFIG_X86
76041 + if (!pmd_large(*pmd))
76042 +#endif
76043 if (!pmd_none(*pmd)) {
76044 pte_t *ptep, pte;
76045
76046 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76047 * Allocate a region of KVA of the specified size and alignment, within the
76048 * vstart and vend.
76049 */
76050 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76051 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76052 unsigned long align,
76053 unsigned long vstart, unsigned long vend,
76054 int node, gfp_t gfp_mask)
76055 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76056 struct vm_struct *area;
76057
76058 BUG_ON(in_interrupt());
76059 +
76060 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76061 + if (flags & VM_KERNEXEC) {
76062 + if (start != VMALLOC_START || end != VMALLOC_END)
76063 + return NULL;
76064 + start = (unsigned long)MODULES_EXEC_VADDR;
76065 + end = (unsigned long)MODULES_EXEC_END;
76066 + }
76067 +#endif
76068 +
76069 if (flags & VM_IOREMAP) {
76070 int bit = fls(size);
76071
76072 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76073 if (count > totalram_pages)
76074 return NULL;
76075
76076 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76077 + if (!(pgprot_val(prot) & _PAGE_NX))
76078 + flags |= VM_KERNEXEC;
76079 +#endif
76080 +
76081 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76082 __builtin_return_address(0));
76083 if (!area)
76084 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76085 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76086 goto fail;
76087
76088 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76089 + if (!(pgprot_val(prot) & _PAGE_NX))
76090 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76091 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76092 + else
76093 +#endif
76094 +
76095 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76096 start, end, node, gfp_mask, caller);
76097 if (!area)
76098 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76099 * For tight control over page level allocator and protection flags
76100 * use __vmalloc() instead.
76101 */
76102 -
76103 void *vmalloc_exec(unsigned long size)
76104 {
76105 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76106 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76107 -1, __builtin_return_address(0));
76108 }
76109
76110 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76111 unsigned long uaddr = vma->vm_start;
76112 unsigned long usize = vma->vm_end - vma->vm_start;
76113
76114 + BUG_ON(vma->vm_mirror);
76115 +
76116 if ((PAGE_SIZE-1) & (unsigned long)addr)
76117 return -EINVAL;
76118
76119 @@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76120 {
76121 struct vm_struct *v = p;
76122
76123 - seq_printf(m, "0x%p-0x%p %7ld",
76124 + seq_printf(m, "0x%pK-0x%pK %7ld",
76125 v->addr, v->addr + v->size, v->size);
76126
76127 if (v->caller)
76128 diff --git a/mm/vmscan.c b/mm/vmscan.c
76129 index 99b434b..a018dfc 100644
76130 --- a/mm/vmscan.c
76131 +++ b/mm/vmscan.c
76132 @@ -2953,6 +2953,8 @@ static int kswapd(void *p)
76133 &balanced_classzone_idx);
76134 }
76135 }
76136 +
76137 + current->reclaim_state = NULL;
76138 return 0;
76139 }
76140
76141 diff --git a/mm/vmstat.c b/mm/vmstat.c
76142 index df7a674..8b4a4f3 100644
76143 --- a/mm/vmstat.c
76144 +++ b/mm/vmstat.c
76145 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76146 *
76147 * vm_stat contains the global counters
76148 */
76149 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76150 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76151 EXPORT_SYMBOL(vm_stat);
76152
76153 #ifdef CONFIG_SMP
76154 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76155 v = p->vm_stat_diff[i];
76156 p->vm_stat_diff[i] = 0;
76157 local_irq_restore(flags);
76158 - atomic_long_add(v, &zone->vm_stat[i]);
76159 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76160 global_diff[i] += v;
76161 #ifdef CONFIG_NUMA
76162 /* 3 seconds idle till flush */
76163 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76164
76165 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76166 if (global_diff[i])
76167 - atomic_long_add(global_diff[i], &vm_stat[i]);
76168 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76169 }
76170
76171 #endif
76172 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76173 start_cpu_timer(cpu);
76174 #endif
76175 #ifdef CONFIG_PROC_FS
76176 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76177 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76178 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76179 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76180 + {
76181 + mode_t gr_mode = S_IRUGO;
76182 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76183 + gr_mode = S_IRUSR;
76184 +#endif
76185 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76186 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76187 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76188 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76189 +#else
76190 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76191 +#endif
76192 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76193 + }
76194 #endif
76195 return 0;
76196 }
76197 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76198 index 9096bcb..43ed7bb 100644
76199 --- a/net/8021q/vlan.c
76200 +++ b/net/8021q/vlan.c
76201 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76202 err = -EPERM;
76203 if (!capable(CAP_NET_ADMIN))
76204 break;
76205 - if ((args.u.name_type >= 0) &&
76206 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76207 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76208 struct vlan_net *vn;
76209
76210 vn = net_generic(net, vlan_net_id);
76211 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76212 index 6449bae..8c1f454 100644
76213 --- a/net/9p/trans_fd.c
76214 +++ b/net/9p/trans_fd.c
76215 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76216 oldfs = get_fs();
76217 set_fs(get_ds());
76218 /* The cast to a user pointer is valid due to the set_fs() */
76219 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76220 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76221 set_fs(oldfs);
76222
76223 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76224 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76225 index 876fbe8..8bbea9f 100644
76226 --- a/net/atm/atm_misc.c
76227 +++ b/net/atm/atm_misc.c
76228 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76229 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76230 return 1;
76231 atm_return(vcc, truesize);
76232 - atomic_inc(&vcc->stats->rx_drop);
76233 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76234 return 0;
76235 }
76236 EXPORT_SYMBOL(atm_charge);
76237 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76238 }
76239 }
76240 atm_return(vcc, guess);
76241 - atomic_inc(&vcc->stats->rx_drop);
76242 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76243 return NULL;
76244 }
76245 EXPORT_SYMBOL(atm_alloc_charge);
76246 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76247
76248 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76249 {
76250 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76251 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76252 __SONET_ITEMS
76253 #undef __HANDLE_ITEM
76254 }
76255 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76256
76257 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76258 {
76259 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76260 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76261 __SONET_ITEMS
76262 #undef __HANDLE_ITEM
76263 }
76264 diff --git a/net/atm/lec.h b/net/atm/lec.h
76265 index a86aff9..3a0d6f6 100644
76266 --- a/net/atm/lec.h
76267 +++ b/net/atm/lec.h
76268 @@ -48,7 +48,7 @@ struct lane2_ops {
76269 const u8 *tlvs, u32 sizeoftlvs);
76270 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76271 const u8 *tlvs, u32 sizeoftlvs);
76272 -};
76273 +} __no_const;
76274
76275 /*
76276 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76277 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76278 index 0919a88..a23d54e 100644
76279 --- a/net/atm/mpc.h
76280 +++ b/net/atm/mpc.h
76281 @@ -33,7 +33,7 @@ struct mpoa_client {
76282 struct mpc_parameters parameters; /* parameters for this client */
76283
76284 const struct net_device_ops *old_ops;
76285 - struct net_device_ops new_ops;
76286 + net_device_ops_no_const new_ops;
76287 };
76288
76289
76290 diff --git a/net/atm/proc.c b/net/atm/proc.c
76291 index 0d020de..011c7bb 100644
76292 --- a/net/atm/proc.c
76293 +++ b/net/atm/proc.c
76294 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76295 const struct k_atm_aal_stats *stats)
76296 {
76297 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76298 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76299 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76300 - atomic_read(&stats->rx_drop));
76301 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76302 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76303 + atomic_read_unchecked(&stats->rx_drop));
76304 }
76305
76306 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76307 diff --git a/net/atm/resources.c b/net/atm/resources.c
76308 index 23f45ce..c748f1a 100644
76309 --- a/net/atm/resources.c
76310 +++ b/net/atm/resources.c
76311 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76312 static void copy_aal_stats(struct k_atm_aal_stats *from,
76313 struct atm_aal_stats *to)
76314 {
76315 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76316 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76317 __AAL_STAT_ITEMS
76318 #undef __HANDLE_ITEM
76319 }
76320 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76321 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76322 struct atm_aal_stats *to)
76323 {
76324 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76325 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76326 __AAL_STAT_ITEMS
76327 #undef __HANDLE_ITEM
76328 }
76329 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76330 index 469daab..262851c 100644
76331 --- a/net/batman-adv/bat_iv_ogm.c
76332 +++ b/net/batman-adv/bat_iv_ogm.c
76333 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76334
76335 /* randomize initial seqno to avoid collision */
76336 get_random_bytes(&random_seqno, sizeof(random_seqno));
76337 - atomic_set(&hard_iface->seqno, random_seqno);
76338 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76339
76340 hard_iface->packet_len = BATADV_OGM_HLEN;
76341 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76342 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76343
76344 /* change sequence number to network order */
76345 batadv_ogm_packet->seqno =
76346 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76347 - atomic_inc(&hard_iface->seqno);
76348 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76349 + atomic_inc_unchecked(&hard_iface->seqno);
76350
76351 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76352 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76353 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76354 return;
76355
76356 /* could be changed by schedule_own_packet() */
76357 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76358 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76359
76360 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76361 has_directlink_flag = 1;
76362 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76363 index 282bf6e..4b2603d 100644
76364 --- a/net/batman-adv/hard-interface.c
76365 +++ b/net/batman-adv/hard-interface.c
76366 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76367 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76368 dev_add_pack(&hard_iface->batman_adv_ptype);
76369
76370 - atomic_set(&hard_iface->frag_seqno, 1);
76371 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76372 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76373 hard_iface->net_dev->name);
76374
76375 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76376 /* This can't be called via a bat_priv callback because
76377 * we have no bat_priv yet.
76378 */
76379 - atomic_set(&hard_iface->seqno, 1);
76380 + atomic_set_unchecked(&hard_iface->seqno, 1);
76381 hard_iface->packet_buff = NULL;
76382
76383 return hard_iface;
76384 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76385 index 21c5357..768be1a 100644
76386 --- a/net/batman-adv/soft-interface.c
76387 +++ b/net/batman-adv/soft-interface.c
76388 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76389
76390 /* set broadcast sequence number */
76391 bcast_packet->seqno =
76392 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76393 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76394
76395 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76396
76397 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76398 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76399
76400 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76401 - atomic_set(&bat_priv->bcast_seqno, 1);
76402 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76403 atomic_set(&bat_priv->ttvn, 0);
76404 atomic_set(&bat_priv->tt_local_changes, 0);
76405 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76406 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76407 index 12635fd..d99d837 100644
76408 --- a/net/batman-adv/types.h
76409 +++ b/net/batman-adv/types.h
76410 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76411 int16_t if_num;
76412 char if_status;
76413 struct net_device *net_dev;
76414 - atomic_t seqno;
76415 - atomic_t frag_seqno;
76416 + atomic_unchecked_t seqno;
76417 + atomic_unchecked_t frag_seqno;
76418 unsigned char *packet_buff;
76419 int packet_len;
76420 struct kobject *hardif_obj;
76421 @@ -176,7 +176,7 @@ struct batadv_priv {
76422 atomic_t orig_interval; /* uint */
76423 atomic_t hop_penalty; /* uint */
76424 atomic_t log_level; /* uint */
76425 - atomic_t bcast_seqno;
76426 + atomic_unchecked_t bcast_seqno;
76427 atomic_t bcast_queue_left;
76428 atomic_t batman_queue_left;
76429 atomic_t ttvn; /* translation table version number */
76430 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76431 index 0016464..0ef3e53 100644
76432 --- a/net/batman-adv/unicast.c
76433 +++ b/net/batman-adv/unicast.c
76434 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76435 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76436 frag2->flags = large_tail;
76437
76438 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76439 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76440 frag1->seqno = htons(seqno - 1);
76441 frag2->seqno = htons(seqno);
76442
76443 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76444 index d5ace1e..231c4bf 100644
76445 --- a/net/bluetooth/hci_sock.c
76446 +++ b/net/bluetooth/hci_sock.c
76447 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76448 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76449 }
76450
76451 - len = min_t(unsigned int, len, sizeof(uf));
76452 + len = min((size_t)len, sizeof(uf));
76453 if (copy_from_user(&uf, optval, len)) {
76454 err = -EFAULT;
76455 break;
76456 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76457 index 38c00f1..e9d566e 100644
76458 --- a/net/bluetooth/l2cap_core.c
76459 +++ b/net/bluetooth/l2cap_core.c
76460 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76461 break;
76462
76463 case L2CAP_CONF_RFC:
76464 - if (olen == sizeof(rfc))
76465 - memcpy(&rfc, (void *)val, olen);
76466 + if (olen != sizeof(rfc))
76467 + break;
76468 +
76469 + memcpy(&rfc, (void *)val, olen);
76470
76471 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76472 rfc.mode != chan->mode)
76473 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76474 index 34bbe1c..451c19b 100644
76475 --- a/net/bluetooth/l2cap_sock.c
76476 +++ b/net/bluetooth/l2cap_sock.c
76477 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76478 struct sock *sk = sock->sk;
76479 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76480 struct l2cap_options opts;
76481 - int len, err = 0;
76482 + int err = 0;
76483 + size_t len = optlen;
76484 u32 opt;
76485
76486 BT_DBG("sk %p", sk);
76487 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76488 opts.max_tx = chan->max_tx;
76489 opts.txwin_size = chan->tx_win;
76490
76491 - len = min_t(unsigned int, sizeof(opts), optlen);
76492 + len = min(sizeof(opts), len);
76493 if (copy_from_user((char *) &opts, optval, len)) {
76494 err = -EFAULT;
76495 break;
76496 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76497 struct bt_security sec;
76498 struct bt_power pwr;
76499 struct l2cap_conn *conn;
76500 - int len, err = 0;
76501 + int err = 0;
76502 + size_t len = optlen;
76503 u32 opt;
76504
76505 BT_DBG("sk %p", sk);
76506 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76507
76508 sec.level = BT_SECURITY_LOW;
76509
76510 - len = min_t(unsigned int, sizeof(sec), optlen);
76511 + len = min(sizeof(sec), len);
76512 if (copy_from_user((char *) &sec, optval, len)) {
76513 err = -EFAULT;
76514 break;
76515 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76516
76517 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76518
76519 - len = min_t(unsigned int, sizeof(pwr), optlen);
76520 + len = min(sizeof(pwr), len);
76521 if (copy_from_user((char *) &pwr, optval, len)) {
76522 err = -EFAULT;
76523 break;
76524 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76525 index 1a17850..65a3129 100644
76526 --- a/net/bluetooth/rfcomm/sock.c
76527 +++ b/net/bluetooth/rfcomm/sock.c
76528 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76529 struct sock *sk = sock->sk;
76530 struct bt_security sec;
76531 int err = 0;
76532 - size_t len;
76533 + size_t len = optlen;
76534 u32 opt;
76535
76536 BT_DBG("sk %p", sk);
76537 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76538
76539 sec.level = BT_SECURITY_LOW;
76540
76541 - len = min_t(unsigned int, sizeof(sec), optlen);
76542 + len = min(sizeof(sec), len);
76543 if (copy_from_user((char *) &sec, optval, len)) {
76544 err = -EFAULT;
76545 break;
76546 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76547 index 56f1823..da44330 100644
76548 --- a/net/bluetooth/rfcomm/tty.c
76549 +++ b/net/bluetooth/rfcomm/tty.c
76550 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76551 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76552
76553 spin_lock_irqsave(&dev->port.lock, flags);
76554 - if (dev->port.count > 0) {
76555 + if (atomic_read(&dev->port.count) > 0) {
76556 spin_unlock_irqrestore(&dev->port.lock, flags);
76557 return;
76558 }
76559 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76560 return -ENODEV;
76561
76562 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76563 - dev->channel, dev->port.count);
76564 + dev->channel, atomic_read(&dev->port.count));
76565
76566 spin_lock_irqsave(&dev->port.lock, flags);
76567 - if (++dev->port.count > 1) {
76568 + if (atomic_inc_return(&dev->port.count) > 1) {
76569 spin_unlock_irqrestore(&dev->port.lock, flags);
76570 return 0;
76571 }
76572 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76573 return;
76574
76575 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76576 - dev->port.count);
76577 + atomic_read(&dev->port.count));
76578
76579 spin_lock_irqsave(&dev->port.lock, flags);
76580 - if (!--dev->port.count) {
76581 + if (!atomic_dec_return(&dev->port.count)) {
76582 spin_unlock_irqrestore(&dev->port.lock, flags);
76583 if (dev->tty_dev->parent)
76584 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76585 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76586 index 5fe2ff3..121d696 100644
76587 --- a/net/bridge/netfilter/ebtables.c
76588 +++ b/net/bridge/netfilter/ebtables.c
76589 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76590 tmp.valid_hooks = t->table->valid_hooks;
76591 }
76592 mutex_unlock(&ebt_mutex);
76593 - if (copy_to_user(user, &tmp, *len) != 0){
76594 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76595 BUGPRINT("c2u Didn't work\n");
76596 ret = -EFAULT;
76597 break;
76598 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76599 goto out;
76600 tmp.valid_hooks = t->valid_hooks;
76601
76602 - if (copy_to_user(user, &tmp, *len) != 0) {
76603 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76604 ret = -EFAULT;
76605 break;
76606 }
76607 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76608 tmp.entries_size = t->table->entries_size;
76609 tmp.valid_hooks = t->table->valid_hooks;
76610
76611 - if (copy_to_user(user, &tmp, *len) != 0) {
76612 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76613 ret = -EFAULT;
76614 break;
76615 }
76616 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76617 index 44f270f..1f5602d 100644
76618 --- a/net/caif/cfctrl.c
76619 +++ b/net/caif/cfctrl.c
76620 @@ -10,6 +10,7 @@
76621 #include <linux/spinlock.h>
76622 #include <linux/slab.h>
76623 #include <linux/pkt_sched.h>
76624 +#include <linux/sched.h>
76625 #include <net/caif/caif_layer.h>
76626 #include <net/caif/cfpkt.h>
76627 #include <net/caif/cfctrl.h>
76628 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76629 memset(&dev_info, 0, sizeof(dev_info));
76630 dev_info.id = 0xff;
76631 cfsrvl_init(&this->serv, 0, &dev_info, false);
76632 - atomic_set(&this->req_seq_no, 1);
76633 - atomic_set(&this->rsp_seq_no, 1);
76634 + atomic_set_unchecked(&this->req_seq_no, 1);
76635 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76636 this->serv.layer.receive = cfctrl_recv;
76637 sprintf(this->serv.layer.name, "ctrl");
76638 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76639 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76640 struct cfctrl_request_info *req)
76641 {
76642 spin_lock_bh(&ctrl->info_list_lock);
76643 - atomic_inc(&ctrl->req_seq_no);
76644 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76645 + atomic_inc_unchecked(&ctrl->req_seq_no);
76646 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76647 list_add_tail(&req->list, &ctrl->list);
76648 spin_unlock_bh(&ctrl->info_list_lock);
76649 }
76650 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76651 if (p != first)
76652 pr_warn("Requests are not received in order\n");
76653
76654 - atomic_set(&ctrl->rsp_seq_no,
76655 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76656 p->sequence_no);
76657 list_del(&p->list);
76658 goto out;
76659 diff --git a/net/can/gw.c b/net/can/gw.c
76660 index b54d5e6..91c3b25 100644
76661 --- a/net/can/gw.c
76662 +++ b/net/can/gw.c
76663 @@ -96,7 +96,7 @@ struct cf_mod {
76664 struct {
76665 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76666 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76667 - } csumfunc;
76668 + } __no_const csumfunc;
76669 };
76670
76671
76672 diff --git a/net/compat.c b/net/compat.c
76673 index 74ed1d7..3695bd9 100644
76674 --- a/net/compat.c
76675 +++ b/net/compat.c
76676 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76677 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76678 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76679 return -EFAULT;
76680 - kmsg->msg_name = compat_ptr(tmp1);
76681 - kmsg->msg_iov = compat_ptr(tmp2);
76682 - kmsg->msg_control = compat_ptr(tmp3);
76683 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76684 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76685 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76686 return 0;
76687 }
76688
76689 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76690
76691 if (kern_msg->msg_namelen) {
76692 if (mode == VERIFY_READ) {
76693 - int err = move_addr_to_kernel(kern_msg->msg_name,
76694 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76695 kern_msg->msg_namelen,
76696 kern_address);
76697 if (err < 0)
76698 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76699 kern_msg->msg_name = NULL;
76700
76701 tot_len = iov_from_user_compat_to_kern(kern_iov,
76702 - (struct compat_iovec __user *)kern_msg->msg_iov,
76703 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76704 kern_msg->msg_iovlen);
76705 if (tot_len >= 0)
76706 kern_msg->msg_iov = kern_iov;
76707 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76708
76709 #define CMSG_COMPAT_FIRSTHDR(msg) \
76710 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76711 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76712 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76713 (struct compat_cmsghdr __user *)NULL)
76714
76715 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76716 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76717 (ucmlen) <= (unsigned long) \
76718 ((mhdr)->msg_controllen - \
76719 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76720 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76721
76722 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76723 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76724 {
76725 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76726 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76727 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76728 msg->msg_controllen)
76729 return NULL;
76730 return (struct compat_cmsghdr __user *)ptr;
76731 @@ -219,7 +219,7 @@ Efault:
76732
76733 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76734 {
76735 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76736 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76737 struct compat_cmsghdr cmhdr;
76738 struct compat_timeval ctv;
76739 struct compat_timespec cts[3];
76740 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76741
76742 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76743 {
76744 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76745 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76746 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76747 int fdnum = scm->fp->count;
76748 struct file **fp = scm->fp->fp;
76749 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76750 return -EFAULT;
76751 old_fs = get_fs();
76752 set_fs(KERNEL_DS);
76753 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76754 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76755 set_fs(old_fs);
76756
76757 return err;
76758 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76759 len = sizeof(ktime);
76760 old_fs = get_fs();
76761 set_fs(KERNEL_DS);
76762 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76763 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76764 set_fs(old_fs);
76765
76766 if (!err) {
76767 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76768 case MCAST_JOIN_GROUP:
76769 case MCAST_LEAVE_GROUP:
76770 {
76771 - struct compat_group_req __user *gr32 = (void *)optval;
76772 + struct compat_group_req __user *gr32 = (void __user *)optval;
76773 struct group_req __user *kgr =
76774 compat_alloc_user_space(sizeof(struct group_req));
76775 u32 interface;
76776 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76777 case MCAST_BLOCK_SOURCE:
76778 case MCAST_UNBLOCK_SOURCE:
76779 {
76780 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76781 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76782 struct group_source_req __user *kgsr = compat_alloc_user_space(
76783 sizeof(struct group_source_req));
76784 u32 interface;
76785 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76786 }
76787 case MCAST_MSFILTER:
76788 {
76789 - struct compat_group_filter __user *gf32 = (void *)optval;
76790 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76791 struct group_filter __user *kgf;
76792 u32 interface, fmode, numsrc;
76793
76794 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76795 char __user *optval, int __user *optlen,
76796 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76797 {
76798 - struct compat_group_filter __user *gf32 = (void *)optval;
76799 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76800 struct group_filter __user *kgf;
76801 int __user *koptlen;
76802 u32 interface, fmode, numsrc;
76803 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76804
76805 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76806 return -EINVAL;
76807 - if (copy_from_user(a, args, nas[call]))
76808 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76809 return -EFAULT;
76810 a0 = a[0];
76811 a1 = a[1];
76812 diff --git a/net/core/datagram.c b/net/core/datagram.c
76813 index 0337e2b..47914a0 100644
76814 --- a/net/core/datagram.c
76815 +++ b/net/core/datagram.c
76816 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76817 }
76818
76819 kfree_skb(skb);
76820 - atomic_inc(&sk->sk_drops);
76821 + atomic_inc_unchecked(&sk->sk_drops);
76822 sk_mem_reclaim_partial(sk);
76823
76824 return err;
76825 diff --git a/net/core/dev.c b/net/core/dev.c
76826 index aed87a4..72cc526 100644
76827 --- a/net/core/dev.c
76828 +++ b/net/core/dev.c
76829 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76830 if (no_module && capable(CAP_NET_ADMIN))
76831 no_module = request_module("netdev-%s", name);
76832 if (no_module && capable(CAP_SYS_MODULE)) {
76833 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76834 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76835 +#else
76836 if (!request_module("%s", name))
76837 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76838 name);
76839 +#endif
76840 }
76841 }
76842 EXPORT_SYMBOL(dev_load);
76843 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76844 {
76845 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76846 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76847 - atomic_long_inc(&dev->rx_dropped);
76848 + atomic_long_inc_unchecked(&dev->rx_dropped);
76849 kfree_skb(skb);
76850 return NET_RX_DROP;
76851 }
76852 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76853 nf_reset(skb);
76854
76855 if (unlikely(!is_skb_forwardable(dev, skb))) {
76856 - atomic_long_inc(&dev->rx_dropped);
76857 + atomic_long_inc_unchecked(&dev->rx_dropped);
76858 kfree_skb(skb);
76859 return NET_RX_DROP;
76860 }
76861 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76862
76863 struct dev_gso_cb {
76864 void (*destructor)(struct sk_buff *skb);
76865 -};
76866 +} __no_const;
76867
76868 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76869
76870 @@ -2928,7 +2932,7 @@ enqueue:
76871
76872 local_irq_restore(flags);
76873
76874 - atomic_long_inc(&skb->dev->rx_dropped);
76875 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76876 kfree_skb(skb);
76877 return NET_RX_DROP;
76878 }
76879 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76880 }
76881 EXPORT_SYMBOL(netif_rx_ni);
76882
76883 -static void net_tx_action(struct softirq_action *h)
76884 +static void net_tx_action(void)
76885 {
76886 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76887
76888 @@ -3331,7 +3335,7 @@ ncls:
76889 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76890 } else {
76891 drop:
76892 - atomic_long_inc(&skb->dev->rx_dropped);
76893 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76894 kfree_skb(skb);
76895 /* Jamal, now you will not able to escape explaining
76896 * me how you were going to use this. :-)
76897 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76898 }
76899 EXPORT_SYMBOL(netif_napi_del);
76900
76901 -static void net_rx_action(struct softirq_action *h)
76902 +static void net_rx_action(void)
76903 {
76904 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76905 unsigned long time_limit = jiffies + 2;
76906 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76907 else
76908 seq_printf(seq, "%04x", ntohs(pt->type));
76909
76910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76911 + seq_printf(seq, " %-8s %p\n",
76912 + pt->dev ? pt->dev->name : "", NULL);
76913 +#else
76914 seq_printf(seq, " %-8s %pF\n",
76915 pt->dev ? pt->dev->name : "", pt->func);
76916 +#endif
76917 }
76918
76919 return 0;
76920 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76921 } else {
76922 netdev_stats_to_stats64(storage, &dev->stats);
76923 }
76924 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76925 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76926 return storage;
76927 }
76928 EXPORT_SYMBOL(dev_get_stats);
76929 diff --git a/net/core/flow.c b/net/core/flow.c
76930 index e318c7e..168b1d0 100644
76931 --- a/net/core/flow.c
76932 +++ b/net/core/flow.c
76933 @@ -61,7 +61,7 @@ struct flow_cache {
76934 struct timer_list rnd_timer;
76935 };
76936
76937 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76938 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76939 EXPORT_SYMBOL(flow_cache_genid);
76940 static struct flow_cache flow_cache_global;
76941 static struct kmem_cache *flow_cachep __read_mostly;
76942 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76943
76944 static int flow_entry_valid(struct flow_cache_entry *fle)
76945 {
76946 - if (atomic_read(&flow_cache_genid) != fle->genid)
76947 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76948 return 0;
76949 if (fle->object && !fle->object->ops->check(fle->object))
76950 return 0;
76951 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76952 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76953 fcp->hash_count++;
76954 }
76955 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76956 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76957 flo = fle->object;
76958 if (!flo)
76959 goto ret_object;
76960 @@ -280,7 +280,7 @@ nocache:
76961 }
76962 flo = resolver(net, key, family, dir, flo, ctx);
76963 if (fle) {
76964 - fle->genid = atomic_read(&flow_cache_genid);
76965 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76966 if (!IS_ERR(flo))
76967 fle->object = flo;
76968 else
76969 diff --git a/net/core/iovec.c b/net/core/iovec.c
76970 index 7e7aeb0..2a998cb 100644
76971 --- a/net/core/iovec.c
76972 +++ b/net/core/iovec.c
76973 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76974 if (m->msg_namelen) {
76975 if (mode == VERIFY_READ) {
76976 void __user *namep;
76977 - namep = (void __user __force *) m->msg_name;
76978 + namep = (void __force_user *) m->msg_name;
76979 err = move_addr_to_kernel(namep, m->msg_namelen,
76980 address);
76981 if (err < 0)
76982 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76983 }
76984
76985 size = m->msg_iovlen * sizeof(struct iovec);
76986 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76987 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76988 return -EFAULT;
76989
76990 m->msg_iov = iov;
76991 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76992 index 2c5a0a0..a45f90c 100644
76993 --- a/net/core/rtnetlink.c
76994 +++ b/net/core/rtnetlink.c
76995 @@ -58,7 +58,7 @@ struct rtnl_link {
76996 rtnl_doit_func doit;
76997 rtnl_dumpit_func dumpit;
76998 rtnl_calcit_func calcit;
76999 -};
77000 +} __no_const;
77001
77002 static DEFINE_MUTEX(rtnl_mutex);
77003
77004 diff --git a/net/core/scm.c b/net/core/scm.c
77005 index 040cebe..5b1e312 100644
77006 --- a/net/core/scm.c
77007 +++ b/net/core/scm.c
77008 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77009 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77010 {
77011 struct cmsghdr __user *cm
77012 - = (__force struct cmsghdr __user *)msg->msg_control;
77013 + = (struct cmsghdr __force_user *)msg->msg_control;
77014 struct cmsghdr cmhdr;
77015 int cmlen = CMSG_LEN(len);
77016 int err;
77017 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77018 err = -EFAULT;
77019 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77020 goto out;
77021 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77022 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77023 goto out;
77024 cmlen = CMSG_SPACE(len);
77025 if (msg->msg_controllen < cmlen)
77026 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77027 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77028 {
77029 struct cmsghdr __user *cm
77030 - = (__force struct cmsghdr __user*)msg->msg_control;
77031 + = (struct cmsghdr __force_user *)msg->msg_control;
77032
77033 int fdmax = 0;
77034 int fdnum = scm->fp->count;
77035 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77036 if (fdnum < fdmax)
77037 fdmax = fdnum;
77038
77039 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77040 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77041 i++, cmfptr++)
77042 {
77043 struct socket *sock;
77044 diff --git a/net/core/sock.c b/net/core/sock.c
77045 index a6000fb..d4aee72 100644
77046 --- a/net/core/sock.c
77047 +++ b/net/core/sock.c
77048 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77049 struct sk_buff_head *list = &sk->sk_receive_queue;
77050
77051 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77052 - atomic_inc(&sk->sk_drops);
77053 + atomic_inc_unchecked(&sk->sk_drops);
77054 trace_sock_rcvqueue_full(sk, skb);
77055 return -ENOMEM;
77056 }
77057 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77058 return err;
77059
77060 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77061 - atomic_inc(&sk->sk_drops);
77062 + atomic_inc_unchecked(&sk->sk_drops);
77063 return -ENOBUFS;
77064 }
77065
77066 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77067 skb_dst_force(skb);
77068
77069 spin_lock_irqsave(&list->lock, flags);
77070 - skb->dropcount = atomic_read(&sk->sk_drops);
77071 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77072 __skb_queue_tail(list, skb);
77073 spin_unlock_irqrestore(&list->lock, flags);
77074
77075 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77076 skb->dev = NULL;
77077
77078 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77079 - atomic_inc(&sk->sk_drops);
77080 + atomic_inc_unchecked(&sk->sk_drops);
77081 goto discard_and_relse;
77082 }
77083 if (nested)
77084 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77085 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77086 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77087 bh_unlock_sock(sk);
77088 - atomic_inc(&sk->sk_drops);
77089 + atomic_inc_unchecked(&sk->sk_drops);
77090 goto discard_and_relse;
77091 }
77092
77093 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77094 struct timeval tm;
77095 } v;
77096
77097 - int lv = sizeof(int);
77098 - int len;
77099 + unsigned int lv = sizeof(int);
77100 + unsigned int len;
77101
77102 if (get_user(len, optlen))
77103 return -EFAULT;
77104 - if (len < 0)
77105 + if (len > INT_MAX)
77106 return -EINVAL;
77107
77108 memset(&v, 0, sizeof(v));
77109 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77110
77111 case SO_PEERNAME:
77112 {
77113 - char address[128];
77114 + char address[_K_SS_MAXSIZE];
77115
77116 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77117 return -ENOTCONN;
77118 - if (lv < len)
77119 + if (lv < len || sizeof address < len)
77120 return -EINVAL;
77121 if (copy_to_user(optval, address, len))
77122 return -EFAULT;
77123 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77124
77125 if (len > lv)
77126 len = lv;
77127 - if (copy_to_user(optval, &v, len))
77128 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77129 return -EFAULT;
77130 lenout:
77131 if (put_user(len, optlen))
77132 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77133 */
77134 smp_wmb();
77135 atomic_set(&sk->sk_refcnt, 1);
77136 - atomic_set(&sk->sk_drops, 0);
77137 + atomic_set_unchecked(&sk->sk_drops, 0);
77138 }
77139 EXPORT_SYMBOL(sock_init_data);
77140
77141 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77142 index 9d8755e..26de8bc 100644
77143 --- a/net/core/sock_diag.c
77144 +++ b/net/core/sock_diag.c
77145 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77146
77147 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77148 {
77149 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77150 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77151 cookie[1] != INET_DIAG_NOCOOKIE) &&
77152 ((u32)(unsigned long)sk != cookie[0] ||
77153 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77154 return -ESTALE;
77155 else
77156 +#endif
77157 return 0;
77158 }
77159 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77160
77161 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77162 {
77163 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77164 + cookie[0] = 0;
77165 + cookie[1] = 0;
77166 +#else
77167 cookie[0] = (u32)(unsigned long)sk;
77168 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77169 +#endif
77170 }
77171 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77172
77173 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77174 index a55eecc..dd8428c 100644
77175 --- a/net/decnet/sysctl_net_decnet.c
77176 +++ b/net/decnet/sysctl_net_decnet.c
77177 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77178
77179 if (len > *lenp) len = *lenp;
77180
77181 - if (copy_to_user(buffer, addr, len))
77182 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77183 return -EFAULT;
77184
77185 *lenp = len;
77186 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77187
77188 if (len > *lenp) len = *lenp;
77189
77190 - if (copy_to_user(buffer, devname, len))
77191 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77192 return -EFAULT;
77193
77194 *lenp = len;
77195 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77196 index f444ac7..b7bdda9 100644
77197 --- a/net/ipv4/fib_frontend.c
77198 +++ b/net/ipv4/fib_frontend.c
77199 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77200 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77201 fib_sync_up(dev);
77202 #endif
77203 - atomic_inc(&net->ipv4.dev_addr_genid);
77204 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77205 rt_cache_flush(dev_net(dev));
77206 break;
77207 case NETDEV_DOWN:
77208 fib_del_ifaddr(ifa, NULL);
77209 - atomic_inc(&net->ipv4.dev_addr_genid);
77210 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77211 if (ifa->ifa_dev->ifa_list == NULL) {
77212 /* Last address was deleted from this interface.
77213 * Disable IP.
77214 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77215 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77216 fib_sync_up(dev);
77217 #endif
77218 - atomic_inc(&net->ipv4.dev_addr_genid);
77219 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77220 rt_cache_flush(dev_net(dev));
77221 break;
77222 case NETDEV_DOWN:
77223 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77224 index 9633661..4e0bc08 100644
77225 --- a/net/ipv4/fib_semantics.c
77226 +++ b/net/ipv4/fib_semantics.c
77227 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77228 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77229 nh->nh_gw,
77230 nh->nh_parent->fib_scope);
77231 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77232 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77233
77234 return nh->nh_saddr;
77235 }
77236 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77237 index 7880af9..70f92a3 100644
77238 --- a/net/ipv4/inet_hashtables.c
77239 +++ b/net/ipv4/inet_hashtables.c
77240 @@ -18,12 +18,15 @@
77241 #include <linux/sched.h>
77242 #include <linux/slab.h>
77243 #include <linux/wait.h>
77244 +#include <linux/security.h>
77245
77246 #include <net/inet_connection_sock.h>
77247 #include <net/inet_hashtables.h>
77248 #include <net/secure_seq.h>
77249 #include <net/ip.h>
77250
77251 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77252 +
77253 /*
77254 * Allocate and initialize a new local port bind bucket.
77255 * The bindhash mutex for snum's hash chain must be held here.
77256 @@ -530,6 +533,8 @@ ok:
77257 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77258 spin_unlock(&head->lock);
77259
77260 + gr_update_task_in_ip_table(current, inet_sk(sk));
77261 +
77262 if (tw) {
77263 inet_twsk_deschedule(tw, death_row);
77264 while (twrefcnt) {
77265 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77266 index c7527f6..d8bba61 100644
77267 --- a/net/ipv4/inetpeer.c
77268 +++ b/net/ipv4/inetpeer.c
77269 @@ -503,8 +503,8 @@ relookup:
77270 if (p) {
77271 p->daddr = *daddr;
77272 atomic_set(&p->refcnt, 1);
77273 - atomic_set(&p->rid, 0);
77274 - atomic_set(&p->ip_id_count,
77275 + atomic_set_unchecked(&p->rid, 0);
77276 + atomic_set_unchecked(&p->ip_id_count,
77277 (daddr->family == AF_INET) ?
77278 secure_ip_id(daddr->addr.a4) :
77279 secure_ipv6_id(daddr->addr.a6));
77280 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77281 index 8d07c97..d0812ef 100644
77282 --- a/net/ipv4/ip_fragment.c
77283 +++ b/net/ipv4/ip_fragment.c
77284 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77285 return 0;
77286
77287 start = qp->rid;
77288 - end = atomic_inc_return(&peer->rid);
77289 + end = atomic_inc_return_unchecked(&peer->rid);
77290 qp->rid = end;
77291
77292 rc = qp->q.fragments && (end - start) > max;
77293 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77294 index 5eea4a8..49819c2 100644
77295 --- a/net/ipv4/ip_sockglue.c
77296 +++ b/net/ipv4/ip_sockglue.c
77297 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77298 len = min_t(unsigned int, len, opt->optlen);
77299 if (put_user(len, optlen))
77300 return -EFAULT;
77301 - if (copy_to_user(optval, opt->__data, len))
77302 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77303 + copy_to_user(optval, opt->__data, len))
77304 return -EFAULT;
77305 return 0;
77306 }
77307 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77308 if (sk->sk_type != SOCK_STREAM)
77309 return -ENOPROTOOPT;
77310
77311 - msg.msg_control = optval;
77312 + msg.msg_control = (void __force_kernel *)optval;
77313 msg.msg_controllen = len;
77314 msg.msg_flags = flags;
77315
77316 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77317 index 67e8a6b..386764d 100644
77318 --- a/net/ipv4/ipconfig.c
77319 +++ b/net/ipv4/ipconfig.c
77320 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77321
77322 mm_segment_t oldfs = get_fs();
77323 set_fs(get_ds());
77324 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77325 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77326 set_fs(oldfs);
77327 return res;
77328 }
77329 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77330
77331 mm_segment_t oldfs = get_fs();
77332 set_fs(get_ds());
77333 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77334 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77335 set_fs(oldfs);
77336 return res;
77337 }
77338 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77339
77340 mm_segment_t oldfs = get_fs();
77341 set_fs(get_ds());
77342 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77343 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77344 set_fs(oldfs);
77345 return res;
77346 }
77347 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77348 index 97e61ea..cac1bbb 100644
77349 --- a/net/ipv4/netfilter/arp_tables.c
77350 +++ b/net/ipv4/netfilter/arp_tables.c
77351 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77352 #endif
77353
77354 static int get_info(struct net *net, void __user *user,
77355 - const int *len, int compat)
77356 + int len, int compat)
77357 {
77358 char name[XT_TABLE_MAXNAMELEN];
77359 struct xt_table *t;
77360 int ret;
77361
77362 - if (*len != sizeof(struct arpt_getinfo)) {
77363 - duprintf("length %u != %Zu\n", *len,
77364 + if (len != sizeof(struct arpt_getinfo)) {
77365 + duprintf("length %u != %Zu\n", len,
77366 sizeof(struct arpt_getinfo));
77367 return -EINVAL;
77368 }
77369 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77370 info.size = private->size;
77371 strcpy(info.name, name);
77372
77373 - if (copy_to_user(user, &info, *len) != 0)
77374 + if (copy_to_user(user, &info, len) != 0)
77375 ret = -EFAULT;
77376 else
77377 ret = 0;
77378 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77379
77380 switch (cmd) {
77381 case ARPT_SO_GET_INFO:
77382 - ret = get_info(sock_net(sk), user, len, 1);
77383 + ret = get_info(sock_net(sk), user, *len, 1);
77384 break;
77385 case ARPT_SO_GET_ENTRIES:
77386 ret = compat_get_entries(sock_net(sk), user, len);
77387 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77388
77389 switch (cmd) {
77390 case ARPT_SO_GET_INFO:
77391 - ret = get_info(sock_net(sk), user, len, 0);
77392 + ret = get_info(sock_net(sk), user, *len, 0);
77393 break;
77394
77395 case ARPT_SO_GET_ENTRIES:
77396 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77397 index 170b1fd..6105b91 100644
77398 --- a/net/ipv4/netfilter/ip_tables.c
77399 +++ b/net/ipv4/netfilter/ip_tables.c
77400 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77401 #endif
77402
77403 static int get_info(struct net *net, void __user *user,
77404 - const int *len, int compat)
77405 + int len, int compat)
77406 {
77407 char name[XT_TABLE_MAXNAMELEN];
77408 struct xt_table *t;
77409 int ret;
77410
77411 - if (*len != sizeof(struct ipt_getinfo)) {
77412 - duprintf("length %u != %zu\n", *len,
77413 + if (len != sizeof(struct ipt_getinfo)) {
77414 + duprintf("length %u != %zu\n", len,
77415 sizeof(struct ipt_getinfo));
77416 return -EINVAL;
77417 }
77418 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77419 info.size = private->size;
77420 strcpy(info.name, name);
77421
77422 - if (copy_to_user(user, &info, *len) != 0)
77423 + if (copy_to_user(user, &info, len) != 0)
77424 ret = -EFAULT;
77425 else
77426 ret = 0;
77427 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77428
77429 switch (cmd) {
77430 case IPT_SO_GET_INFO:
77431 - ret = get_info(sock_net(sk), user, len, 1);
77432 + ret = get_info(sock_net(sk), user, *len, 1);
77433 break;
77434 case IPT_SO_GET_ENTRIES:
77435 ret = compat_get_entries(sock_net(sk), user, len);
77436 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77437
77438 switch (cmd) {
77439 case IPT_SO_GET_INFO:
77440 - ret = get_info(sock_net(sk), user, len, 0);
77441 + ret = get_info(sock_net(sk), user, *len, 0);
77442 break;
77443
77444 case IPT_SO_GET_ENTRIES:
77445 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77446 index 6232d47..6b88607 100644
77447 --- a/net/ipv4/ping.c
77448 +++ b/net/ipv4/ping.c
77449 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77450 sk_rmem_alloc_get(sp),
77451 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77452 atomic_read(&sp->sk_refcnt), sp,
77453 - atomic_read(&sp->sk_drops), len);
77454 + atomic_read_unchecked(&sp->sk_drops), len);
77455 }
77456
77457 static int ping_seq_show(struct seq_file *seq, void *v)
77458 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77459 index d23c657..cb69cc2 100644
77460 --- a/net/ipv4/raw.c
77461 +++ b/net/ipv4/raw.c
77462 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77463 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77464 {
77465 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77466 - atomic_inc(&sk->sk_drops);
77467 + atomic_inc_unchecked(&sk->sk_drops);
77468 kfree_skb(skb);
77469 return NET_RX_DROP;
77470 }
77471 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77472
77473 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77474 {
77475 + struct icmp_filter filter;
77476 +
77477 if (optlen > sizeof(struct icmp_filter))
77478 optlen = sizeof(struct icmp_filter);
77479 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77480 + if (copy_from_user(&filter, optval, optlen))
77481 return -EFAULT;
77482 + raw_sk(sk)->filter = filter;
77483 return 0;
77484 }
77485
77486 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77487 {
77488 int len, ret = -EFAULT;
77489 + struct icmp_filter filter;
77490
77491 if (get_user(len, optlen))
77492 goto out;
77493 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77494 if (len > sizeof(struct icmp_filter))
77495 len = sizeof(struct icmp_filter);
77496 ret = -EFAULT;
77497 - if (put_user(len, optlen) ||
77498 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77499 + filter = raw_sk(sk)->filter;
77500 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77501 goto out;
77502 ret = 0;
77503 out: return ret;
77504 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77505 sk_wmem_alloc_get(sp),
77506 sk_rmem_alloc_get(sp),
77507 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77508 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77509 + atomic_read(&sp->sk_refcnt),
77510 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77511 + NULL,
77512 +#else
77513 + sp,
77514 +#endif
77515 + atomic_read_unchecked(&sp->sk_drops));
77516 }
77517
77518 static int raw_seq_show(struct seq_file *seq, void *v)
77519 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77520 index c017cb1..9eb15b7d 100644
77521 --- a/net/ipv4/route.c
77522 +++ b/net/ipv4/route.c
77523 @@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77524
77525 static __net_init int rt_genid_init(struct net *net)
77526 {
77527 - atomic_set(&net->rt_genid, 0);
77528 + atomic_set_unchecked(&net->rt_genid, 0);
77529 get_random_bytes(&net->ipv4.dev_addr_genid,
77530 sizeof(net->ipv4.dev_addr_genid));
77531 return 0;
77532 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77533 index c92c4da..f19e3ec 100644
77534 --- a/net/ipv4/tcp_input.c
77535 +++ b/net/ipv4/tcp_input.c
77536 @@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77537 * simplifies code)
77538 */
77539 static void
77540 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77541 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77542 struct sk_buff *head, struct sk_buff *tail,
77543 u32 start, u32 end)
77544 {
77545 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77546 index db7bfad..bfea796 100644
77547 --- a/net/ipv4/tcp_ipv4.c
77548 +++ b/net/ipv4/tcp_ipv4.c
77549 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77550 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77551
77552
77553 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77554 +extern int grsec_enable_blackhole;
77555 +#endif
77556 +
77557 #ifdef CONFIG_TCP_MD5SIG
77558 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77559 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77560 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77561 return 0;
77562
77563 reset:
77564 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77565 + if (!grsec_enable_blackhole)
77566 +#endif
77567 tcp_v4_send_reset(rsk, skb);
77568 discard:
77569 kfree_skb(skb);
77570 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77571 TCP_SKB_CB(skb)->sacked = 0;
77572
77573 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77574 - if (!sk)
77575 + if (!sk) {
77576 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77577 + ret = 1;
77578 +#endif
77579 goto no_tcp_socket;
77580 -
77581 + }
77582 process:
77583 - if (sk->sk_state == TCP_TIME_WAIT)
77584 + if (sk->sk_state == TCP_TIME_WAIT) {
77585 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77586 + ret = 2;
77587 +#endif
77588 goto do_time_wait;
77589 + }
77590
77591 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77592 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77593 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77594 bad_packet:
77595 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77596 } else {
77597 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77598 + if (!grsec_enable_blackhole || (ret == 1 &&
77599 + (skb->dev->flags & IFF_LOOPBACK)))
77600 +#endif
77601 tcp_v4_send_reset(NULL, skb);
77602 }
77603
77604 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77605 0, /* non standard timer */
77606 0, /* open_requests have no inode */
77607 atomic_read(&sk->sk_refcnt),
77608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77609 + NULL,
77610 +#else
77611 req,
77612 +#endif
77613 len);
77614 }
77615
77616 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77617 sock_i_uid(sk),
77618 icsk->icsk_probes_out,
77619 sock_i_ino(sk),
77620 - atomic_read(&sk->sk_refcnt), sk,
77621 + atomic_read(&sk->sk_refcnt),
77622 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77623 + NULL,
77624 +#else
77625 + sk,
77626 +#endif
77627 jiffies_to_clock_t(icsk->icsk_rto),
77628 jiffies_to_clock_t(icsk->icsk_ack.ato),
77629 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77630 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77631 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77632 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77633 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77634 - atomic_read(&tw->tw_refcnt), tw, len);
77635 + atomic_read(&tw->tw_refcnt),
77636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77637 + NULL,
77638 +#else
77639 + tw,
77640 +#endif
77641 + len);
77642 }
77643
77644 #define TMPSZ 150
77645 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77646 index 6ff7f10..38de56e 100644
77647 --- a/net/ipv4/tcp_minisocks.c
77648 +++ b/net/ipv4/tcp_minisocks.c
77649 @@ -27,6 +27,10 @@
77650 #include <net/inet_common.h>
77651 #include <net/xfrm.h>
77652
77653 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77654 +extern int grsec_enable_blackhole;
77655 +#endif
77656 +
77657 int sysctl_tcp_syncookies __read_mostly = 1;
77658 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77659
77660 @@ -707,6 +711,10 @@ listen_overflow:
77661
77662 embryonic_reset:
77663 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77664 +
77665 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77666 + if (!grsec_enable_blackhole)
77667 +#endif
77668 if (!(flg & TCP_FLAG_RST))
77669 req->rsk_ops->send_reset(sk, skb);
77670
77671 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77672 index 4526fe6..1a34e43 100644
77673 --- a/net/ipv4/tcp_probe.c
77674 +++ b/net/ipv4/tcp_probe.c
77675 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77676 if (cnt + width >= len)
77677 break;
77678
77679 - if (copy_to_user(buf + cnt, tbuf, width))
77680 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77681 return -EFAULT;
77682 cnt += width;
77683 }
77684 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77685 index b774a03..3873efe 100644
77686 --- a/net/ipv4/tcp_timer.c
77687 +++ b/net/ipv4/tcp_timer.c
77688 @@ -22,6 +22,10 @@
77689 #include <linux/gfp.h>
77690 #include <net/tcp.h>
77691
77692 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77693 +extern int grsec_lastack_retries;
77694 +#endif
77695 +
77696 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77697 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77698 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77699 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77700 }
77701 }
77702
77703 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77704 + if ((sk->sk_state == TCP_LAST_ACK) &&
77705 + (grsec_lastack_retries > 0) &&
77706 + (grsec_lastack_retries < retry_until))
77707 + retry_until = grsec_lastack_retries;
77708 +#endif
77709 +
77710 if (retransmits_timed_out(sk, retry_until,
77711 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77712 /* Has it gone just too far? */
77713 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77714 index 2814f66..fa2b223 100644
77715 --- a/net/ipv4/udp.c
77716 +++ b/net/ipv4/udp.c
77717 @@ -87,6 +87,7 @@
77718 #include <linux/types.h>
77719 #include <linux/fcntl.h>
77720 #include <linux/module.h>
77721 +#include <linux/security.h>
77722 #include <linux/socket.h>
77723 #include <linux/sockios.h>
77724 #include <linux/igmp.h>
77725 @@ -111,6 +112,10 @@
77726 #include <trace/events/skb.h>
77727 #include "udp_impl.h"
77728
77729 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77730 +extern int grsec_enable_blackhole;
77731 +#endif
77732 +
77733 struct udp_table udp_table __read_mostly;
77734 EXPORT_SYMBOL(udp_table);
77735
77736 @@ -569,6 +574,9 @@ found:
77737 return s;
77738 }
77739
77740 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77741 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77742 +
77743 /*
77744 * This routine is called by the ICMP module when it gets some
77745 * sort of error condition. If err < 0 then the socket should
77746 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77747 dport = usin->sin_port;
77748 if (dport == 0)
77749 return -EINVAL;
77750 +
77751 + err = gr_search_udp_sendmsg(sk, usin);
77752 + if (err)
77753 + return err;
77754 } else {
77755 if (sk->sk_state != TCP_ESTABLISHED)
77756 return -EDESTADDRREQ;
77757 +
77758 + err = gr_search_udp_sendmsg(sk, NULL);
77759 + if (err)
77760 + return err;
77761 +
77762 daddr = inet->inet_daddr;
77763 dport = inet->inet_dport;
77764 /* Open fast path for connected socket.
77765 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77766 udp_lib_checksum_complete(skb)) {
77767 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77768 IS_UDPLITE(sk));
77769 - atomic_inc(&sk->sk_drops);
77770 + atomic_inc_unchecked(&sk->sk_drops);
77771 __skb_unlink(skb, rcvq);
77772 __skb_queue_tail(&list_kill, skb);
77773 }
77774 @@ -1194,6 +1211,10 @@ try_again:
77775 if (!skb)
77776 goto out;
77777
77778 + err = gr_search_udp_recvmsg(sk, skb);
77779 + if (err)
77780 + goto out_free;
77781 +
77782 ulen = skb->len - sizeof(struct udphdr);
77783 copied = len;
77784 if (copied > ulen)
77785 @@ -1227,7 +1248,7 @@ try_again:
77786 if (unlikely(err)) {
77787 trace_kfree_skb(skb, udp_recvmsg);
77788 if (!peeked) {
77789 - atomic_inc(&sk->sk_drops);
77790 + atomic_inc_unchecked(&sk->sk_drops);
77791 UDP_INC_STATS_USER(sock_net(sk),
77792 UDP_MIB_INERRORS, is_udplite);
77793 }
77794 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77795
77796 drop:
77797 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77798 - atomic_inc(&sk->sk_drops);
77799 + atomic_inc_unchecked(&sk->sk_drops);
77800 kfree_skb(skb);
77801 return -1;
77802 }
77803 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77804 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77805
77806 if (!skb1) {
77807 - atomic_inc(&sk->sk_drops);
77808 + atomic_inc_unchecked(&sk->sk_drops);
77809 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77810 IS_UDPLITE(sk));
77811 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77812 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77813 goto csum_error;
77814
77815 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77816 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77817 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77818 +#endif
77819 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77820
77821 /*
77822 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77823 sk_wmem_alloc_get(sp),
77824 sk_rmem_alloc_get(sp),
77825 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77826 - atomic_read(&sp->sk_refcnt), sp,
77827 - atomic_read(&sp->sk_drops), len);
77828 + atomic_read(&sp->sk_refcnt),
77829 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77830 + NULL,
77831 +#else
77832 + sp,
77833 +#endif
77834 + atomic_read_unchecked(&sp->sk_drops), len);
77835 }
77836
77837 int udp4_seq_show(struct seq_file *seq, void *v)
77838 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77839 index b10374d..0baa1f9 100644
77840 --- a/net/ipv6/addrconf.c
77841 +++ b/net/ipv6/addrconf.c
77842 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77843 p.iph.ihl = 5;
77844 p.iph.protocol = IPPROTO_IPV6;
77845 p.iph.ttl = 64;
77846 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77847 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77848
77849 if (ops->ndo_do_ioctl) {
77850 mm_segment_t oldfs = get_fs();
77851 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77852 index ba6d13d..6899122 100644
77853 --- a/net/ipv6/ipv6_sockglue.c
77854 +++ b/net/ipv6/ipv6_sockglue.c
77855 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77856 if (sk->sk_type != SOCK_STREAM)
77857 return -ENOPROTOOPT;
77858
77859 - msg.msg_control = optval;
77860 + msg.msg_control = (void __force_kernel *)optval;
77861 msg.msg_controllen = len;
77862 msg.msg_flags = flags;
77863
77864 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77865 index d7cb045..8c0ded6 100644
77866 --- a/net/ipv6/netfilter/ip6_tables.c
77867 +++ b/net/ipv6/netfilter/ip6_tables.c
77868 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77869 #endif
77870
77871 static int get_info(struct net *net, void __user *user,
77872 - const int *len, int compat)
77873 + int len, int compat)
77874 {
77875 char name[XT_TABLE_MAXNAMELEN];
77876 struct xt_table *t;
77877 int ret;
77878
77879 - if (*len != sizeof(struct ip6t_getinfo)) {
77880 - duprintf("length %u != %zu\n", *len,
77881 + if (len != sizeof(struct ip6t_getinfo)) {
77882 + duprintf("length %u != %zu\n", len,
77883 sizeof(struct ip6t_getinfo));
77884 return -EINVAL;
77885 }
77886 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77887 info.size = private->size;
77888 strcpy(info.name, name);
77889
77890 - if (copy_to_user(user, &info, *len) != 0)
77891 + if (copy_to_user(user, &info, len) != 0)
77892 ret = -EFAULT;
77893 else
77894 ret = 0;
77895 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77896
77897 switch (cmd) {
77898 case IP6T_SO_GET_INFO:
77899 - ret = get_info(sock_net(sk), user, len, 1);
77900 + ret = get_info(sock_net(sk), user, *len, 1);
77901 break;
77902 case IP6T_SO_GET_ENTRIES:
77903 ret = compat_get_entries(sock_net(sk), user, len);
77904 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77905
77906 switch (cmd) {
77907 case IP6T_SO_GET_INFO:
77908 - ret = get_info(sock_net(sk), user, len, 0);
77909 + ret = get_info(sock_net(sk), user, *len, 0);
77910 break;
77911
77912 case IP6T_SO_GET_ENTRIES:
77913 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77914 index 4a5f78b..3f22ebe 100644
77915 --- a/net/ipv6/raw.c
77916 +++ b/net/ipv6/raw.c
77917 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77918 {
77919 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77920 skb_checksum_complete(skb)) {
77921 - atomic_inc(&sk->sk_drops);
77922 + atomic_inc_unchecked(&sk->sk_drops);
77923 kfree_skb(skb);
77924 return NET_RX_DROP;
77925 }
77926 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77927 struct raw6_sock *rp = raw6_sk(sk);
77928
77929 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77930 - atomic_inc(&sk->sk_drops);
77931 + atomic_inc_unchecked(&sk->sk_drops);
77932 kfree_skb(skb);
77933 return NET_RX_DROP;
77934 }
77935 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77936
77937 if (inet->hdrincl) {
77938 if (skb_checksum_complete(skb)) {
77939 - atomic_inc(&sk->sk_drops);
77940 + atomic_inc_unchecked(&sk->sk_drops);
77941 kfree_skb(skb);
77942 return NET_RX_DROP;
77943 }
77944 @@ -604,7 +604,7 @@ out:
77945 return err;
77946 }
77947
77948 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77949 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77950 struct flowi6 *fl6, struct dst_entry **dstp,
77951 unsigned int flags)
77952 {
77953 @@ -916,12 +916,15 @@ do_confirm:
77954 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77955 char __user *optval, int optlen)
77956 {
77957 + struct icmp6_filter filter;
77958 +
77959 switch (optname) {
77960 case ICMPV6_FILTER:
77961 if (optlen > sizeof(struct icmp6_filter))
77962 optlen = sizeof(struct icmp6_filter);
77963 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77964 + if (copy_from_user(&filter, optval, optlen))
77965 return -EFAULT;
77966 + raw6_sk(sk)->filter = filter;
77967 return 0;
77968 default:
77969 return -ENOPROTOOPT;
77970 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77971 char __user *optval, int __user *optlen)
77972 {
77973 int len;
77974 + struct icmp6_filter filter;
77975
77976 switch (optname) {
77977 case ICMPV6_FILTER:
77978 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77979 len = sizeof(struct icmp6_filter);
77980 if (put_user(len, optlen))
77981 return -EFAULT;
77982 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77983 + filter = raw6_sk(sk)->filter;
77984 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77985 return -EFAULT;
77986 return 0;
77987 default:
77988 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77989 0, 0L, 0,
77990 sock_i_uid(sp), 0,
77991 sock_i_ino(sp),
77992 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77993 + atomic_read(&sp->sk_refcnt),
77994 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77995 + NULL,
77996 +#else
77997 + sp,
77998 +#endif
77999 + atomic_read_unchecked(&sp->sk_drops));
78000 }
78001
78002 static int raw6_seq_show(struct seq_file *seq, void *v)
78003 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78004 index 7e32d42..5d975ba 100644
78005 --- a/net/ipv6/tcp_ipv6.c
78006 +++ b/net/ipv6/tcp_ipv6.c
78007 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78008 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78009 }
78010
78011 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78012 +extern int grsec_enable_blackhole;
78013 +#endif
78014 +
78015 static void tcp_v6_hash(struct sock *sk)
78016 {
78017 if (sk->sk_state != TCP_CLOSE) {
78018 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78019 return 0;
78020
78021 reset:
78022 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78023 + if (!grsec_enable_blackhole)
78024 +#endif
78025 tcp_v6_send_reset(sk, skb);
78026 discard:
78027 if (opt_skb)
78028 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78029 TCP_SKB_CB(skb)->sacked = 0;
78030
78031 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78032 - if (!sk)
78033 + if (!sk) {
78034 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78035 + ret = 1;
78036 +#endif
78037 goto no_tcp_socket;
78038 + }
78039
78040 process:
78041 - if (sk->sk_state == TCP_TIME_WAIT)
78042 + if (sk->sk_state == TCP_TIME_WAIT) {
78043 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78044 + ret = 2;
78045 +#endif
78046 goto do_time_wait;
78047 + }
78048
78049 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78050 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78051 @@ -1646,6 +1661,10 @@ no_tcp_socket:
78052 bad_packet:
78053 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78054 } else {
78055 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78056 + if (!grsec_enable_blackhole || (ret == 1 &&
78057 + (skb->dev->flags & IFF_LOOPBACK)))
78058 +#endif
78059 tcp_v6_send_reset(NULL, skb);
78060 }
78061
78062 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78063 uid,
78064 0, /* non standard timer */
78065 0, /* open_requests have no inode */
78066 - 0, req);
78067 + 0,
78068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78069 + NULL
78070 +#else
78071 + req
78072 +#endif
78073 + );
78074 }
78075
78076 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78077 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78078 sock_i_uid(sp),
78079 icsk->icsk_probes_out,
78080 sock_i_ino(sp),
78081 - atomic_read(&sp->sk_refcnt), sp,
78082 + atomic_read(&sp->sk_refcnt),
78083 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78084 + NULL,
78085 +#else
78086 + sp,
78087 +#endif
78088 jiffies_to_clock_t(icsk->icsk_rto),
78089 jiffies_to_clock_t(icsk->icsk_ack.ato),
78090 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78091 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78092 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78093 tw->tw_substate, 0, 0,
78094 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78095 - atomic_read(&tw->tw_refcnt), tw);
78096 + atomic_read(&tw->tw_refcnt),
78097 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78098 + NULL
78099 +#else
78100 + tw
78101 +#endif
78102 + );
78103 }
78104
78105 static int tcp6_seq_show(struct seq_file *seq, void *v)
78106 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78107 index 07e2bfe..328dae8 100644
78108 --- a/net/ipv6/udp.c
78109 +++ b/net/ipv6/udp.c
78110 @@ -51,6 +51,10 @@
78111 #include <trace/events/skb.h>
78112 #include "udp_impl.h"
78113
78114 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78115 +extern int grsec_enable_blackhole;
78116 +#endif
78117 +
78118 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78119 {
78120 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78121 @@ -395,7 +399,7 @@ try_again:
78122 if (unlikely(err)) {
78123 trace_kfree_skb(skb, udpv6_recvmsg);
78124 if (!peeked) {
78125 - atomic_inc(&sk->sk_drops);
78126 + atomic_inc_unchecked(&sk->sk_drops);
78127 if (is_udp4)
78128 UDP_INC_STATS_USER(sock_net(sk),
78129 UDP_MIB_INERRORS,
78130 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78131 return rc;
78132 drop:
78133 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78134 - atomic_inc(&sk->sk_drops);
78135 + atomic_inc_unchecked(&sk->sk_drops);
78136 kfree_skb(skb);
78137 return -1;
78138 }
78139 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78140 if (likely(skb1 == NULL))
78141 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78142 if (!skb1) {
78143 - atomic_inc(&sk->sk_drops);
78144 + atomic_inc_unchecked(&sk->sk_drops);
78145 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78146 IS_UDPLITE(sk));
78147 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78148 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78149 goto discard;
78150
78151 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78152 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78153 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78154 +#endif
78155 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78156
78157 kfree_skb(skb);
78158 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78159 0, 0L, 0,
78160 sock_i_uid(sp), 0,
78161 sock_i_ino(sp),
78162 - atomic_read(&sp->sk_refcnt), sp,
78163 - atomic_read(&sp->sk_drops));
78164 + atomic_read(&sp->sk_refcnt),
78165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78166 + NULL,
78167 +#else
78168 + sp,
78169 +#endif
78170 + atomic_read_unchecked(&sp->sk_drops));
78171 }
78172
78173 int udp6_seq_show(struct seq_file *seq, void *v)
78174 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78175 index 6b9d5a0..4dffaf1 100644
78176 --- a/net/irda/ircomm/ircomm_tty.c
78177 +++ b/net/irda/ircomm/ircomm_tty.c
78178 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78179 add_wait_queue(&self->open_wait, &wait);
78180
78181 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78182 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78183 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78184
78185 /* As far as I can see, we protect open_count - Jean II */
78186 spin_lock_irqsave(&self->spinlock, flags);
78187 if (!tty_hung_up_p(filp)) {
78188 extra_count = 1;
78189 - self->open_count--;
78190 + local_dec(&self->open_count);
78191 }
78192 spin_unlock_irqrestore(&self->spinlock, flags);
78193 - self->blocked_open++;
78194 + local_inc(&self->blocked_open);
78195
78196 while (1) {
78197 if (tty->termios->c_cflag & CBAUD) {
78198 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78199 }
78200
78201 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78202 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78203 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78204
78205 schedule();
78206 }
78207 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78208 if (extra_count) {
78209 /* ++ is not atomic, so this should be protected - Jean II */
78210 spin_lock_irqsave(&self->spinlock, flags);
78211 - self->open_count++;
78212 + local_inc(&self->open_count);
78213 spin_unlock_irqrestore(&self->spinlock, flags);
78214 }
78215 - self->blocked_open--;
78216 + local_dec(&self->blocked_open);
78217
78218 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78219 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78220 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78221
78222 if (!retval)
78223 self->flags |= ASYNC_NORMAL_ACTIVE;
78224 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78225 }
78226 /* ++ is not atomic, so this should be protected - Jean II */
78227 spin_lock_irqsave(&self->spinlock, flags);
78228 - self->open_count++;
78229 + local_inc(&self->open_count);
78230
78231 tty->driver_data = self;
78232 self->tty = tty;
78233 spin_unlock_irqrestore(&self->spinlock, flags);
78234
78235 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78236 - self->line, self->open_count);
78237 + self->line, local_read(&self->open_count));
78238
78239 /* Not really used by us, but lets do it anyway */
78240 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78241 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78242 return;
78243 }
78244
78245 - if ((tty->count == 1) && (self->open_count != 1)) {
78246 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78247 /*
78248 * Uh, oh. tty->count is 1, which means that the tty
78249 * structure will be freed. state->count should always
78250 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78251 */
78252 IRDA_DEBUG(0, "%s(), bad serial port count; "
78253 "tty->count is 1, state->count is %d\n", __func__ ,
78254 - self->open_count);
78255 - self->open_count = 1;
78256 + local_read(&self->open_count));
78257 + local_set(&self->open_count, 1);
78258 }
78259
78260 - if (--self->open_count < 0) {
78261 + if (local_dec_return(&self->open_count) < 0) {
78262 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78263 - __func__, self->line, self->open_count);
78264 - self->open_count = 0;
78265 + __func__, self->line, local_read(&self->open_count));
78266 + local_set(&self->open_count, 0);
78267 }
78268 - if (self->open_count) {
78269 + if (local_read(&self->open_count)) {
78270 spin_unlock_irqrestore(&self->spinlock, flags);
78271
78272 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78273 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78274 tty->closing = 0;
78275 self->tty = NULL;
78276
78277 - if (self->blocked_open) {
78278 + if (local_read(&self->blocked_open)) {
78279 if (self->close_delay)
78280 schedule_timeout_interruptible(self->close_delay);
78281 wake_up_interruptible(&self->open_wait);
78282 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78283 spin_lock_irqsave(&self->spinlock, flags);
78284 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78285 self->tty = NULL;
78286 - self->open_count = 0;
78287 + local_set(&self->open_count, 0);
78288 spin_unlock_irqrestore(&self->spinlock, flags);
78289
78290 wake_up_interruptible(&self->open_wait);
78291 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78292 seq_putc(m, '\n');
78293
78294 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78295 - seq_printf(m, "Open count: %d\n", self->open_count);
78296 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78297 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78298 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78299
78300 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78301 index cd6f7a9..e63fe89 100644
78302 --- a/net/iucv/af_iucv.c
78303 +++ b/net/iucv/af_iucv.c
78304 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78305
78306 write_lock_bh(&iucv_sk_list.lock);
78307
78308 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78309 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78310 while (__iucv_get_sock_by_name(name)) {
78311 sprintf(name, "%08x",
78312 - atomic_inc_return(&iucv_sk_list.autobind_name));
78313 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78314 }
78315
78316 write_unlock_bh(&iucv_sk_list.lock);
78317 diff --git a/net/key/af_key.c b/net/key/af_key.c
78318 index 34e4185..8823368 100644
78319 --- a/net/key/af_key.c
78320 +++ b/net/key/af_key.c
78321 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78322 static u32 get_acqseq(void)
78323 {
78324 u32 res;
78325 - static atomic_t acqseq;
78326 + static atomic_unchecked_t acqseq;
78327
78328 do {
78329 - res = atomic_inc_return(&acqseq);
78330 + res = atomic_inc_return_unchecked(&acqseq);
78331 } while (!res);
78332 return res;
78333 }
78334 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78335 index bb61f77..3788d63 100644
78336 --- a/net/mac80211/ieee80211_i.h
78337 +++ b/net/mac80211/ieee80211_i.h
78338 @@ -28,6 +28,7 @@
78339 #include <net/ieee80211_radiotap.h>
78340 #include <net/cfg80211.h>
78341 #include <net/mac80211.h>
78342 +#include <asm/local.h>
78343 #include "key.h"
78344 #include "sta_info.h"
78345 #include "debug.h"
78346 @@ -840,7 +841,7 @@ struct ieee80211_local {
78347 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78348 spinlock_t queue_stop_reason_lock;
78349
78350 - int open_count;
78351 + local_t open_count;
78352 int monitors, cooked_mntrs;
78353 /* number of interfaces with corresponding FIF_ flags */
78354 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78355 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78356 index c93d395..a305570 100644
78357 --- a/net/mac80211/iface.c
78358 +++ b/net/mac80211/iface.c
78359 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78360 break;
78361 }
78362
78363 - if (local->open_count == 0) {
78364 + if (local_read(&local->open_count) == 0) {
78365 res = drv_start(local);
78366 if (res)
78367 goto err_del_bss;
78368 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78369 break;
78370 }
78371
78372 - if (local->monitors == 0 && local->open_count == 0) {
78373 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78374 res = ieee80211_add_virtual_monitor(local);
78375 if (res)
78376 goto err_stop;
78377 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78378 mutex_unlock(&local->mtx);
78379
78380 if (coming_up)
78381 - local->open_count++;
78382 + local_inc(&local->open_count);
78383
78384 if (hw_reconf_flags)
78385 ieee80211_hw_config(local, hw_reconf_flags);
78386 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78387 err_del_interface:
78388 drv_remove_interface(local, sdata);
78389 err_stop:
78390 - if (!local->open_count)
78391 + if (!local_read(&local->open_count))
78392 drv_stop(local);
78393 err_del_bss:
78394 sdata->bss = NULL;
78395 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78396 }
78397
78398 if (going_down)
78399 - local->open_count--;
78400 + local_dec(&local->open_count);
78401
78402 switch (sdata->vif.type) {
78403 case NL80211_IFTYPE_AP_VLAN:
78404 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78405
78406 ieee80211_recalc_ps(local, -1);
78407
78408 - if (local->open_count == 0) {
78409 + if (local_read(&local->open_count) == 0) {
78410 if (local->ops->napi_poll)
78411 napi_disable(&local->napi);
78412 ieee80211_clear_tx_pending(local);
78413 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78414 }
78415 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78416
78417 - if (local->monitors == local->open_count && local->monitors > 0)
78418 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78419 ieee80211_add_virtual_monitor(local);
78420 }
78421
78422 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78423 index c26e231..8916637 100644
78424 --- a/net/mac80211/main.c
78425 +++ b/net/mac80211/main.c
78426 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78427 local->hw.conf.power_level = power;
78428 }
78429
78430 - if (changed && local->open_count) {
78431 + if (changed && local_read(&local->open_count)) {
78432 ret = drv_config(local, changed);
78433 /*
78434 * Goal:
78435 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78436 index 5c572e7..ecf75ce 100644
78437 --- a/net/mac80211/pm.c
78438 +++ b/net/mac80211/pm.c
78439 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78440 struct ieee80211_sub_if_data *sdata;
78441 struct sta_info *sta;
78442
78443 - if (!local->open_count)
78444 + if (!local_read(&local->open_count))
78445 goto suspend;
78446
78447 ieee80211_scan_cancel(local);
78448 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78449 cancel_work_sync(&local->dynamic_ps_enable_work);
78450 del_timer_sync(&local->dynamic_ps_timer);
78451
78452 - local->wowlan = wowlan && local->open_count;
78453 + local->wowlan = wowlan && local_read(&local->open_count);
78454 if (local->wowlan) {
78455 int err = drv_suspend(local, wowlan);
78456 if (err < 0) {
78457 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78458 drv_remove_interface(local, sdata);
78459
78460 /* stop hardware - this must stop RX */
78461 - if (local->open_count)
78462 + if (local_read(&local->open_count))
78463 ieee80211_stop_device(local);
78464
78465 suspend:
78466 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78467 index 3313c11..bec9f17 100644
78468 --- a/net/mac80211/rate.c
78469 +++ b/net/mac80211/rate.c
78470 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78471
78472 ASSERT_RTNL();
78473
78474 - if (local->open_count)
78475 + if (local_read(&local->open_count))
78476 return -EBUSY;
78477
78478 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78479 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78480 index c97a065..ff61928 100644
78481 --- a/net/mac80211/rc80211_pid_debugfs.c
78482 +++ b/net/mac80211/rc80211_pid_debugfs.c
78483 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78484
78485 spin_unlock_irqrestore(&events->lock, status);
78486
78487 - if (copy_to_user(buf, pb, p))
78488 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78489 return -EFAULT;
78490
78491 return p;
78492 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78493 index 1cfe6d5..c428ba3 100644
78494 --- a/net/mac80211/util.c
78495 +++ b/net/mac80211/util.c
78496 @@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78497 }
78498 #endif
78499 /* everything else happens only if HW was up & running */
78500 - if (!local->open_count)
78501 + if (!local_read(&local->open_count))
78502 goto wake_up;
78503
78504 /*
78505 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78506 index c19b214..471fad1 100644
78507 --- a/net/netfilter/Kconfig
78508 +++ b/net/netfilter/Kconfig
78509 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78510
78511 To compile it as a module, choose M here. If unsure, say N.
78512
78513 +config NETFILTER_XT_MATCH_GRADM
78514 + tristate '"gradm" match support'
78515 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78516 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78517 + ---help---
78518 + The gradm match allows to match on grsecurity RBAC being enabled.
78519 + It is useful when iptables rules are applied early on bootup to
78520 + prevent connections to the machine (except from a trusted host)
78521 + while the RBAC system is disabled.
78522 +
78523 config NETFILTER_XT_MATCH_HASHLIMIT
78524 tristate '"hashlimit" match support'
78525 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78526 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78527 index 1c5160f..145ae21 100644
78528 --- a/net/netfilter/Makefile
78529 +++ b/net/netfilter/Makefile
78530 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78531 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78532 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78533 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78534 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78535 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78536 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78537 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78538 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78539 index 1548df9..98ad9b4 100644
78540 --- a/net/netfilter/ipvs/ip_vs_conn.c
78541 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78542 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78543 /* Increase the refcnt counter of the dest */
78544 atomic_inc(&dest->refcnt);
78545
78546 - conn_flags = atomic_read(&dest->conn_flags);
78547 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78548 if (cp->protocol != IPPROTO_UDP)
78549 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78550 flags = cp->flags;
78551 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78552 atomic_set(&cp->refcnt, 1);
78553
78554 atomic_set(&cp->n_control, 0);
78555 - atomic_set(&cp->in_pkts, 0);
78556 + atomic_set_unchecked(&cp->in_pkts, 0);
78557
78558 atomic_inc(&ipvs->conn_count);
78559 if (flags & IP_VS_CONN_F_NO_CPORT)
78560 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78561
78562 /* Don't drop the entry if its number of incoming packets is not
78563 located in [0, 8] */
78564 - i = atomic_read(&cp->in_pkts);
78565 + i = atomic_read_unchecked(&cp->in_pkts);
78566 if (i > 8 || i < 0) return 0;
78567
78568 if (!todrop_rate[i]) return 0;
78569 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78570 index b54ecce..fc5f6cf 100644
78571 --- a/net/netfilter/ipvs/ip_vs_core.c
78572 +++ b/net/netfilter/ipvs/ip_vs_core.c
78573 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78574 ret = cp->packet_xmit(skb, cp, pd->pp);
78575 /* do not touch skb anymore */
78576
78577 - atomic_inc(&cp->in_pkts);
78578 + atomic_inc_unchecked(&cp->in_pkts);
78579 ip_vs_conn_put(cp);
78580 return ret;
78581 }
78582 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78583 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78584 pkts = sysctl_sync_threshold(ipvs);
78585 else
78586 - pkts = atomic_add_return(1, &cp->in_pkts);
78587 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78588
78589 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78590 ip_vs_sync_conn(net, cp, pkts);
78591 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78592 index f51013c..c99ee52 100644
78593 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78594 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78595 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78596 ip_vs_rs_hash(ipvs, dest);
78597 write_unlock_bh(&ipvs->rs_lock);
78598 }
78599 - atomic_set(&dest->conn_flags, conn_flags);
78600 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78601
78602 /* bind the service */
78603 if (!dest->svc) {
78604 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78605 " %-7s %-6d %-10d %-10d\n",
78606 &dest->addr.in6,
78607 ntohs(dest->port),
78608 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78609 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78610 atomic_read(&dest->weight),
78611 atomic_read(&dest->activeconns),
78612 atomic_read(&dest->inactconns));
78613 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78614 "%-7s %-6d %-10d %-10d\n",
78615 ntohl(dest->addr.ip),
78616 ntohs(dest->port),
78617 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78618 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78619 atomic_read(&dest->weight),
78620 atomic_read(&dest->activeconns),
78621 atomic_read(&dest->inactconns));
78622 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78623
78624 entry.addr = dest->addr.ip;
78625 entry.port = dest->port;
78626 - entry.conn_flags = atomic_read(&dest->conn_flags);
78627 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78628 entry.weight = atomic_read(&dest->weight);
78629 entry.u_threshold = dest->u_threshold;
78630 entry.l_threshold = dest->l_threshold;
78631 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78632 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78633 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78634 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78635 - (atomic_read(&dest->conn_flags) &
78636 + (atomic_read_unchecked(&dest->conn_flags) &
78637 IP_VS_CONN_F_FWD_MASK)) ||
78638 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78639 atomic_read(&dest->weight)) ||
78640 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78641 index effa10c..9058928 100644
78642 --- a/net/netfilter/ipvs/ip_vs_sync.c
78643 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78644 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78645 cp = cp->control;
78646 if (cp) {
78647 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78648 - pkts = atomic_add_return(1, &cp->in_pkts);
78649 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78650 else
78651 pkts = sysctl_sync_threshold(ipvs);
78652 ip_vs_sync_conn(net, cp->control, pkts);
78653 @@ -758,7 +758,7 @@ control:
78654 if (!cp)
78655 return;
78656 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78657 - pkts = atomic_add_return(1, &cp->in_pkts);
78658 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78659 else
78660 pkts = sysctl_sync_threshold(ipvs);
78661 goto sloop;
78662 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78663
78664 if (opt)
78665 memcpy(&cp->in_seq, opt, sizeof(*opt));
78666 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78667 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78668 cp->state = state;
78669 cp->old_state = cp->state;
78670 /*
78671 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78672 index c3c6291..3376d73 100644
78673 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78674 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78675 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78676 else
78677 rc = NF_ACCEPT;
78678 /* do not touch skb anymore */
78679 - atomic_inc(&cp->in_pkts);
78680 + atomic_inc_unchecked(&cp->in_pkts);
78681 goto out;
78682 }
78683
78684 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78685 else
78686 rc = NF_ACCEPT;
78687 /* do not touch skb anymore */
78688 - atomic_inc(&cp->in_pkts);
78689 + atomic_inc_unchecked(&cp->in_pkts);
78690 goto out;
78691 }
78692
78693 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78694 index 2ceec64..a5b8a61 100644
78695 --- a/net/netfilter/nf_conntrack_core.c
78696 +++ b/net/netfilter/nf_conntrack_core.c
78697 @@ -1529,6 +1529,10 @@ err_extend:
78698 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78699 #define DYING_NULLS_VAL ((1<<30)+1)
78700
78701 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78702 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78703 +#endif
78704 +
78705 static int nf_conntrack_init_net(struct net *net)
78706 {
78707 int ret;
78708 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78709 goto err_stat;
78710 }
78711
78712 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78713 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78714 +#else
78715 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78716 +#endif
78717 if (!net->ct.slabname) {
78718 ret = -ENOMEM;
78719 goto err_slabname;
78720 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78721 index 5cfb5be..217c6d8 100644
78722 --- a/net/netfilter/nfnetlink_log.c
78723 +++ b/net/netfilter/nfnetlink_log.c
78724 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78725 };
78726
78727 static DEFINE_SPINLOCK(instances_lock);
78728 -static atomic_t global_seq;
78729 +static atomic_unchecked_t global_seq;
78730
78731 #define INSTANCE_BUCKETS 16
78732 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78733 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78734 /* global sequence number */
78735 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78736 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78737 - htonl(atomic_inc_return(&global_seq))))
78738 + htonl(atomic_inc_return_unchecked(&global_seq))))
78739 goto nla_put_failure;
78740
78741 if (data_len) {
78742 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78743 new file mode 100644
78744 index 0000000..c566332
78745 --- /dev/null
78746 +++ b/net/netfilter/xt_gradm.c
78747 @@ -0,0 +1,51 @@
78748 +/*
78749 + * gradm match for netfilter
78750 + * Copyright © Zbigniew Krzystolik, 2010
78751 + *
78752 + * This program is free software; you can redistribute it and/or modify
78753 + * it under the terms of the GNU General Public License; either version
78754 + * 2 or 3 as published by the Free Software Foundation.
78755 + */
78756 +#include <linux/module.h>
78757 +#include <linux/moduleparam.h>
78758 +#include <linux/skbuff.h>
78759 +#include <linux/netfilter/x_tables.h>
78760 +#include <linux/grsecurity.h>
78761 +#include <linux/netfilter/xt_gradm.h>
78762 +
78763 +static bool
78764 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78765 +{
78766 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78767 + bool retval = false;
78768 + if (gr_acl_is_enabled())
78769 + retval = true;
78770 + return retval ^ info->invflags;
78771 +}
78772 +
78773 +static struct xt_match gradm_mt_reg __read_mostly = {
78774 + .name = "gradm",
78775 + .revision = 0,
78776 + .family = NFPROTO_UNSPEC,
78777 + .match = gradm_mt,
78778 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78779 + .me = THIS_MODULE,
78780 +};
78781 +
78782 +static int __init gradm_mt_init(void)
78783 +{
78784 + return xt_register_match(&gradm_mt_reg);
78785 +}
78786 +
78787 +static void __exit gradm_mt_exit(void)
78788 +{
78789 + xt_unregister_match(&gradm_mt_reg);
78790 +}
78791 +
78792 +module_init(gradm_mt_init);
78793 +module_exit(gradm_mt_exit);
78794 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78795 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78796 +MODULE_LICENSE("GPL");
78797 +MODULE_ALIAS("ipt_gradm");
78798 +MODULE_ALIAS("ip6t_gradm");
78799 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78800 index 4fe4fb4..87a89e5 100644
78801 --- a/net/netfilter/xt_statistic.c
78802 +++ b/net/netfilter/xt_statistic.c
78803 @@ -19,7 +19,7 @@
78804 #include <linux/module.h>
78805
78806 struct xt_statistic_priv {
78807 - atomic_t count;
78808 + atomic_unchecked_t count;
78809 } ____cacheline_aligned_in_smp;
78810
78811 MODULE_LICENSE("GPL");
78812 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78813 break;
78814 case XT_STATISTIC_MODE_NTH:
78815 do {
78816 - oval = atomic_read(&info->master->count);
78817 + oval = atomic_read_unchecked(&info->master->count);
78818 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78819 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78820 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78821 if (nval == 0)
78822 ret = !ret;
78823 break;
78824 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78825 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78826 if (info->master == NULL)
78827 return -ENOMEM;
78828 - atomic_set(&info->master->count, info->u.nth.count);
78829 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78830
78831 return 0;
78832 }
78833 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78834 index 0426b67..d6ddaca 100644
78835 --- a/net/netlink/af_netlink.c
78836 +++ b/net/netlink/af_netlink.c
78837 @@ -780,7 +780,7 @@ static void netlink_overrun(struct sock *sk)
78838 sk->sk_error_report(sk);
78839 }
78840 }
78841 - atomic_inc(&sk->sk_drops);
78842 + atomic_inc_unchecked(&sk->sk_drops);
78843 }
78844
78845 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78846 @@ -2070,7 +2070,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78847 sk_wmem_alloc_get(s),
78848 nlk->cb,
78849 atomic_read(&s->sk_refcnt),
78850 - atomic_read(&s->sk_drops),
78851 + atomic_read_unchecked(&s->sk_drops),
78852 sock_i_ino(s)
78853 );
78854
78855 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78856 index 7261eb8..44e8ac6 100644
78857 --- a/net/netrom/af_netrom.c
78858 +++ b/net/netrom/af_netrom.c
78859 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78860 struct sock *sk = sock->sk;
78861 struct nr_sock *nr = nr_sk(sk);
78862
78863 + memset(sax, 0, sizeof(*sax));
78864 lock_sock(sk);
78865 if (peer != 0) {
78866 if (sk->sk_state != TCP_ESTABLISHED) {
78867 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78868 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78869 } else {
78870 sax->fsa_ax25.sax25_family = AF_NETROM;
78871 - sax->fsa_ax25.sax25_ndigis = 0;
78872 sax->fsa_ax25.sax25_call = nr->source_addr;
78873 *uaddr_len = sizeof(struct sockaddr_ax25);
78874 }
78875 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
78876 index ddeb9aa..e18fffd 100644
78877 --- a/net/nfc/llcp/sock.c
78878 +++ b/net/nfc/llcp/sock.c
78879 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
78880 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
78881
78882 if (!addr || len < sizeof(struct sockaddr_nfc) ||
78883 - addr->sa_family != AF_NFC) {
78884 - pr_err("Invalid socket\n");
78885 + addr->sa_family != AF_NFC)
78886 return -EINVAL;
78887 - }
78888
78889 - if (addr->service_name_len == 0 && addr->dsap == 0) {
78890 - pr_err("Missing service name or dsap\n");
78891 + if (addr->service_name_len == 0 && addr->dsap == 0)
78892 return -EINVAL;
78893 - }
78894
78895 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
78896 addr->target_idx, addr->nfc_protocol);
78897 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78898 index c5c9e2a..4814ab1 100644
78899 --- a/net/packet/af_packet.c
78900 +++ b/net/packet/af_packet.c
78901 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78902
78903 spin_lock(&sk->sk_receive_queue.lock);
78904 po->stats.tp_packets++;
78905 - skb->dropcount = atomic_read(&sk->sk_drops);
78906 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78907 __skb_queue_tail(&sk->sk_receive_queue, skb);
78908 spin_unlock(&sk->sk_receive_queue.lock);
78909 sk->sk_data_ready(sk, skb->len);
78910 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78911 drop_n_acct:
78912 spin_lock(&sk->sk_receive_queue.lock);
78913 po->stats.tp_drops++;
78914 - atomic_inc(&sk->sk_drops);
78915 + atomic_inc_unchecked(&sk->sk_drops);
78916 spin_unlock(&sk->sk_receive_queue.lock);
78917
78918 drop_n_restore:
78919 @@ -2642,6 +2642,7 @@ out:
78920
78921 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78922 {
78923 + struct sock_extended_err ee;
78924 struct sock_exterr_skb *serr;
78925 struct sk_buff *skb, *skb2;
78926 int copied, err;
78927 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78928 sock_recv_timestamp(msg, sk, skb);
78929
78930 serr = SKB_EXT_ERR(skb);
78931 + ee = serr->ee;
78932 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78933 - sizeof(serr->ee), &serr->ee);
78934 + sizeof ee, &ee);
78935
78936 msg->msg_flags |= MSG_ERRQUEUE;
78937 err = copied;
78938 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78939 case PACKET_HDRLEN:
78940 if (len > sizeof(int))
78941 len = sizeof(int);
78942 - if (copy_from_user(&val, optval, len))
78943 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78944 return -EFAULT;
78945 switch (val) {
78946 case TPACKET_V1:
78947 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78948 len = lv;
78949 if (put_user(len, optlen))
78950 return -EFAULT;
78951 - if (copy_to_user(optval, data, len))
78952 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78953 return -EFAULT;
78954 return 0;
78955 }
78956 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78957 index 5a940db..f0b9c12 100644
78958 --- a/net/phonet/af_phonet.c
78959 +++ b/net/phonet/af_phonet.c
78960 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78961 {
78962 struct phonet_protocol *pp;
78963
78964 - if (protocol >= PHONET_NPROTO)
78965 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78966 return NULL;
78967
78968 rcu_read_lock();
78969 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78970 {
78971 int err = 0;
78972
78973 - if (protocol >= PHONET_NPROTO)
78974 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78975 return -EINVAL;
78976
78977 err = proto_register(pp->prot, 1);
78978 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78979 index 576f22c..bc7a71b 100644
78980 --- a/net/phonet/pep.c
78981 +++ b/net/phonet/pep.c
78982 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78983
78984 case PNS_PEP_CTRL_REQ:
78985 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78986 - atomic_inc(&sk->sk_drops);
78987 + atomic_inc_unchecked(&sk->sk_drops);
78988 break;
78989 }
78990 __skb_pull(skb, 4);
78991 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78992 }
78993
78994 if (pn->rx_credits == 0) {
78995 - atomic_inc(&sk->sk_drops);
78996 + atomic_inc_unchecked(&sk->sk_drops);
78997 err = -ENOBUFS;
78998 break;
78999 }
79000 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
79001 }
79002
79003 if (pn->rx_credits == 0) {
79004 - atomic_inc(&sk->sk_drops);
79005 + atomic_inc_unchecked(&sk->sk_drops);
79006 err = NET_RX_DROP;
79007 break;
79008 }
79009 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
79010 index 0acc943..c727611 100644
79011 --- a/net/phonet/socket.c
79012 +++ b/net/phonet/socket.c
79013 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
79014 pn->resource, sk->sk_state,
79015 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
79016 sock_i_uid(sk), sock_i_ino(sk),
79017 - atomic_read(&sk->sk_refcnt), sk,
79018 - atomic_read(&sk->sk_drops), &len);
79019 + atomic_read(&sk->sk_refcnt),
79020 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79021 + NULL,
79022 +#else
79023 + sk,
79024 +#endif
79025 + atomic_read_unchecked(&sk->sk_drops), &len);
79026 }
79027 seq_printf(seq, "%*s\n", 127 - len, "");
79028 return 0;
79029 diff --git a/net/rds/cong.c b/net/rds/cong.c
79030 index e5b65ac..f3b6fb7 100644
79031 --- a/net/rds/cong.c
79032 +++ b/net/rds/cong.c
79033 @@ -78,7 +78,7 @@
79034 * finds that the saved generation number is smaller than the global generation
79035 * number, it wakes up the process.
79036 */
79037 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
79038 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
79039
79040 /*
79041 * Congestion monitoring
79042 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
79043 rdsdebug("waking map %p for %pI4\n",
79044 map, &map->m_addr);
79045 rds_stats_inc(s_cong_update_received);
79046 - atomic_inc(&rds_cong_generation);
79047 + atomic_inc_unchecked(&rds_cong_generation);
79048 if (waitqueue_active(&map->m_waitq))
79049 wake_up(&map->m_waitq);
79050 if (waitqueue_active(&rds_poll_waitq))
79051 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
79052
79053 int rds_cong_updated_since(unsigned long *recent)
79054 {
79055 - unsigned long gen = atomic_read(&rds_cong_generation);
79056 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
79057
79058 if (likely(*recent == gen))
79059 return 0;
79060 diff --git a/net/rds/ib.h b/net/rds/ib.h
79061 index 8d2b3d5..227ec5b 100644
79062 --- a/net/rds/ib.h
79063 +++ b/net/rds/ib.h
79064 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79065 /* sending acks */
79066 unsigned long i_ack_flags;
79067 #ifdef KERNEL_HAS_ATOMIC64
79068 - atomic64_t i_ack_next; /* next ACK to send */
79069 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79070 #else
79071 spinlock_t i_ack_lock; /* protect i_ack_next */
79072 u64 i_ack_next; /* next ACK to send */
79073 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79074 index a1e1162..265e129 100644
79075 --- a/net/rds/ib_cm.c
79076 +++ b/net/rds/ib_cm.c
79077 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79078 /* Clear the ACK state */
79079 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79080 #ifdef KERNEL_HAS_ATOMIC64
79081 - atomic64_set(&ic->i_ack_next, 0);
79082 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79083 #else
79084 ic->i_ack_next = 0;
79085 #endif
79086 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79087 index 8d19491..05a3e65 100644
79088 --- a/net/rds/ib_recv.c
79089 +++ b/net/rds/ib_recv.c
79090 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79091 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79092 int ack_required)
79093 {
79094 - atomic64_set(&ic->i_ack_next, seq);
79095 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79096 if (ack_required) {
79097 smp_mb__before_clear_bit();
79098 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79099 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79100 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79101 smp_mb__after_clear_bit();
79102
79103 - return atomic64_read(&ic->i_ack_next);
79104 + return atomic64_read_unchecked(&ic->i_ack_next);
79105 }
79106 #endif
79107
79108 diff --git a/net/rds/iw.h b/net/rds/iw.h
79109 index 04ce3b1..48119a6 100644
79110 --- a/net/rds/iw.h
79111 +++ b/net/rds/iw.h
79112 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79113 /* sending acks */
79114 unsigned long i_ack_flags;
79115 #ifdef KERNEL_HAS_ATOMIC64
79116 - atomic64_t i_ack_next; /* next ACK to send */
79117 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79118 #else
79119 spinlock_t i_ack_lock; /* protect i_ack_next */
79120 u64 i_ack_next; /* next ACK to send */
79121 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79122 index a91e1db..cf3053f 100644
79123 --- a/net/rds/iw_cm.c
79124 +++ b/net/rds/iw_cm.c
79125 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79126 /* Clear the ACK state */
79127 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79128 #ifdef KERNEL_HAS_ATOMIC64
79129 - atomic64_set(&ic->i_ack_next, 0);
79130 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79131 #else
79132 ic->i_ack_next = 0;
79133 #endif
79134 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79135 index 4503335..db566b4 100644
79136 --- a/net/rds/iw_recv.c
79137 +++ b/net/rds/iw_recv.c
79138 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79139 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79140 int ack_required)
79141 {
79142 - atomic64_set(&ic->i_ack_next, seq);
79143 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79144 if (ack_required) {
79145 smp_mb__before_clear_bit();
79146 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79147 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79148 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79149 smp_mb__after_clear_bit();
79150
79151 - return atomic64_read(&ic->i_ack_next);
79152 + return atomic64_read_unchecked(&ic->i_ack_next);
79153 }
79154 #endif
79155
79156 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79157 index edac9ef..16bcb98 100644
79158 --- a/net/rds/tcp.c
79159 +++ b/net/rds/tcp.c
79160 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79161 int val = 1;
79162
79163 set_fs(KERNEL_DS);
79164 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79165 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79166 sizeof(val));
79167 set_fs(oldfs);
79168 }
79169 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79170 index 1b4fd68..2234175 100644
79171 --- a/net/rds/tcp_send.c
79172 +++ b/net/rds/tcp_send.c
79173 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79174
79175 oldfs = get_fs();
79176 set_fs(KERNEL_DS);
79177 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79178 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79179 sizeof(val));
79180 set_fs(oldfs);
79181 }
79182 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79183 index 05996d0..5a1dfe0 100644
79184 --- a/net/rxrpc/af_rxrpc.c
79185 +++ b/net/rxrpc/af_rxrpc.c
79186 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79187 __be32 rxrpc_epoch;
79188
79189 /* current debugging ID */
79190 -atomic_t rxrpc_debug_id;
79191 +atomic_unchecked_t rxrpc_debug_id;
79192
79193 /* count of skbs currently in use */
79194 atomic_t rxrpc_n_skbs;
79195 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79196 index e4d9cbc..b229649 100644
79197 --- a/net/rxrpc/ar-ack.c
79198 +++ b/net/rxrpc/ar-ack.c
79199 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79200
79201 _enter("{%d,%d,%d,%d},",
79202 call->acks_hard, call->acks_unacked,
79203 - atomic_read(&call->sequence),
79204 + atomic_read_unchecked(&call->sequence),
79205 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79206
79207 stop = 0;
79208 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79209
79210 /* each Tx packet has a new serial number */
79211 sp->hdr.serial =
79212 - htonl(atomic_inc_return(&call->conn->serial));
79213 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79214
79215 hdr = (struct rxrpc_header *) txb->head;
79216 hdr->serial = sp->hdr.serial;
79217 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79218 */
79219 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79220 {
79221 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79222 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79223 }
79224
79225 /*
79226 @@ -629,7 +629,7 @@ process_further:
79227
79228 latest = ntohl(sp->hdr.serial);
79229 hard = ntohl(ack.firstPacket);
79230 - tx = atomic_read(&call->sequence);
79231 + tx = atomic_read_unchecked(&call->sequence);
79232
79233 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79234 latest,
79235 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79236 goto maybe_reschedule;
79237
79238 send_ACK_with_skew:
79239 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79240 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79241 ntohl(ack.serial));
79242 send_ACK:
79243 mtu = call->conn->trans->peer->if_mtu;
79244 @@ -1173,7 +1173,7 @@ send_ACK:
79245 ackinfo.rxMTU = htonl(5692);
79246 ackinfo.jumbo_max = htonl(4);
79247
79248 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79249 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79250 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79251 ntohl(hdr.serial),
79252 ntohs(ack.maxSkew),
79253 @@ -1191,7 +1191,7 @@ send_ACK:
79254 send_message:
79255 _debug("send message");
79256
79257 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79258 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79259 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79260 send_message_2:
79261
79262 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79263 index a3bbb36..3341fb9 100644
79264 --- a/net/rxrpc/ar-call.c
79265 +++ b/net/rxrpc/ar-call.c
79266 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79267 spin_lock_init(&call->lock);
79268 rwlock_init(&call->state_lock);
79269 atomic_set(&call->usage, 1);
79270 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79271 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79272 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79273
79274 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79275 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79276 index 4106ca9..a338d7a 100644
79277 --- a/net/rxrpc/ar-connection.c
79278 +++ b/net/rxrpc/ar-connection.c
79279 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79280 rwlock_init(&conn->lock);
79281 spin_lock_init(&conn->state_lock);
79282 atomic_set(&conn->usage, 1);
79283 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79284 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79285 conn->avail_calls = RXRPC_MAXCALLS;
79286 conn->size_align = 4;
79287 conn->header_size = sizeof(struct rxrpc_header);
79288 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79289 index e7ed43a..6afa140 100644
79290 --- a/net/rxrpc/ar-connevent.c
79291 +++ b/net/rxrpc/ar-connevent.c
79292 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79293
79294 len = iov[0].iov_len + iov[1].iov_len;
79295
79296 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79297 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79298 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79299
79300 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79301 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79302 index 529572f..c758ca7 100644
79303 --- a/net/rxrpc/ar-input.c
79304 +++ b/net/rxrpc/ar-input.c
79305 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79306 /* track the latest serial number on this connection for ACK packet
79307 * information */
79308 serial = ntohl(sp->hdr.serial);
79309 - hi_serial = atomic_read(&call->conn->hi_serial);
79310 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79311 while (serial > hi_serial)
79312 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79313 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79314 serial);
79315
79316 /* request ACK generation for any ACK or DATA packet that requests
79317 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79318 index a693aca..81e7293 100644
79319 --- a/net/rxrpc/ar-internal.h
79320 +++ b/net/rxrpc/ar-internal.h
79321 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79322 int error; /* error code for local abort */
79323 int debug_id; /* debug ID for printks */
79324 unsigned int call_counter; /* call ID counter */
79325 - atomic_t serial; /* packet serial number counter */
79326 - atomic_t hi_serial; /* highest serial number received */
79327 + atomic_unchecked_t serial; /* packet serial number counter */
79328 + atomic_unchecked_t hi_serial; /* highest serial number received */
79329 u8 avail_calls; /* number of calls available */
79330 u8 size_align; /* data size alignment (for security) */
79331 u8 header_size; /* rxrpc + security header size */
79332 @@ -346,7 +346,7 @@ struct rxrpc_call {
79333 spinlock_t lock;
79334 rwlock_t state_lock; /* lock for state transition */
79335 atomic_t usage;
79336 - atomic_t sequence; /* Tx data packet sequence counter */
79337 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79338 u32 abort_code; /* local/remote abort code */
79339 enum { /* current state of call */
79340 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79341 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79342 */
79343 extern atomic_t rxrpc_n_skbs;
79344 extern __be32 rxrpc_epoch;
79345 -extern atomic_t rxrpc_debug_id;
79346 +extern atomic_unchecked_t rxrpc_debug_id;
79347 extern struct workqueue_struct *rxrpc_workqueue;
79348
79349 /*
79350 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79351 index 87f7135..74d3703 100644
79352 --- a/net/rxrpc/ar-local.c
79353 +++ b/net/rxrpc/ar-local.c
79354 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79355 spin_lock_init(&local->lock);
79356 rwlock_init(&local->services_lock);
79357 atomic_set(&local->usage, 1);
79358 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79359 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79360 memcpy(&local->srx, srx, sizeof(*srx));
79361 }
79362
79363 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79364 index e1ac183..b43e10e 100644
79365 --- a/net/rxrpc/ar-output.c
79366 +++ b/net/rxrpc/ar-output.c
79367 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79368 sp->hdr.cid = call->cid;
79369 sp->hdr.callNumber = call->call_id;
79370 sp->hdr.seq =
79371 - htonl(atomic_inc_return(&call->sequence));
79372 + htonl(atomic_inc_return_unchecked(&call->sequence));
79373 sp->hdr.serial =
79374 - htonl(atomic_inc_return(&conn->serial));
79375 + htonl(atomic_inc_return_unchecked(&conn->serial));
79376 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79377 sp->hdr.userStatus = 0;
79378 sp->hdr.securityIndex = conn->security_ix;
79379 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79380 index bebaa43..2644591 100644
79381 --- a/net/rxrpc/ar-peer.c
79382 +++ b/net/rxrpc/ar-peer.c
79383 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79384 INIT_LIST_HEAD(&peer->error_targets);
79385 spin_lock_init(&peer->lock);
79386 atomic_set(&peer->usage, 1);
79387 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79388 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79389 memcpy(&peer->srx, srx, sizeof(*srx));
79390
79391 rxrpc_assess_MTU_size(peer);
79392 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79393 index 38047f7..9f48511 100644
79394 --- a/net/rxrpc/ar-proc.c
79395 +++ b/net/rxrpc/ar-proc.c
79396 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79397 atomic_read(&conn->usage),
79398 rxrpc_conn_states[conn->state],
79399 key_serial(conn->key),
79400 - atomic_read(&conn->serial),
79401 - atomic_read(&conn->hi_serial));
79402 + atomic_read_unchecked(&conn->serial),
79403 + atomic_read_unchecked(&conn->hi_serial));
79404
79405 return 0;
79406 }
79407 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79408 index 92df566..87ec1bf 100644
79409 --- a/net/rxrpc/ar-transport.c
79410 +++ b/net/rxrpc/ar-transport.c
79411 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79412 spin_lock_init(&trans->client_lock);
79413 rwlock_init(&trans->conn_lock);
79414 atomic_set(&trans->usage, 1);
79415 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79416 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79417
79418 if (peer->srx.transport.family == AF_INET) {
79419 switch (peer->srx.transport_type) {
79420 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79421 index f226709..0e735a8 100644
79422 --- a/net/rxrpc/rxkad.c
79423 +++ b/net/rxrpc/rxkad.c
79424 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79425
79426 len = iov[0].iov_len + iov[1].iov_len;
79427
79428 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79429 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79430 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79431
79432 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79433 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79434
79435 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79436
79437 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79438 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79439 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79440
79441 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79442 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79443 index 1e2eee8..ce3967e 100644
79444 --- a/net/sctp/proc.c
79445 +++ b/net/sctp/proc.c
79446 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79447 seq_printf(seq,
79448 "%8pK %8pK %-3d %-3d %-2d %-4d "
79449 "%4d %8d %8d %7d %5lu %-5d %5d ",
79450 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79451 + assoc, sk,
79452 + sctp_sk(sk)->type, sk->sk_state,
79453 assoc->state, hash,
79454 assoc->assoc_id,
79455 assoc->sndbuf_used,
79456 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79457 index 5e25981..dbda919 100644
79458 --- a/net/sctp/socket.c
79459 +++ b/net/sctp/socket.c
79460 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79461 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79462 if (space_left < addrlen)
79463 return -ENOMEM;
79464 + if (addrlen > sizeof(temp) || addrlen < 0)
79465 + return -EFAULT;
79466 if (copy_to_user(to, &temp, addrlen))
79467 return -EFAULT;
79468 to += addrlen;
79469 diff --git a/net/socket.c b/net/socket.c
79470 index edc3c4a..4b4e4a8 100644
79471 --- a/net/socket.c
79472 +++ b/net/socket.c
79473 @@ -88,6 +88,7 @@
79474 #include <linux/nsproxy.h>
79475 #include <linux/magic.h>
79476 #include <linux/slab.h>
79477 +#include <linux/in.h>
79478
79479 #include <asm/uaccess.h>
79480 #include <asm/unistd.h>
79481 @@ -105,6 +106,8 @@
79482 #include <linux/sockios.h>
79483 #include <linux/atalk.h>
79484
79485 +#include <linux/grsock.h>
79486 +
79487 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79488 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79489 unsigned long nr_segs, loff_t pos);
79490 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79491 &sockfs_dentry_operations, SOCKFS_MAGIC);
79492 }
79493
79494 -static struct vfsmount *sock_mnt __read_mostly;
79495 +struct vfsmount *sock_mnt __read_mostly;
79496
79497 static struct file_system_type sock_fs_type = {
79498 .name = "sockfs",
79499 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79500 return -EAFNOSUPPORT;
79501 if (type < 0 || type >= SOCK_MAX)
79502 return -EINVAL;
79503 + if (protocol < 0)
79504 + return -EINVAL;
79505
79506 /* Compatibility.
79507
79508 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79509 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79510 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79511
79512 + if(!gr_search_socket(family, type, protocol)) {
79513 + retval = -EACCES;
79514 + goto out;
79515 + }
79516 +
79517 + if (gr_handle_sock_all(family, type, protocol)) {
79518 + retval = -EACCES;
79519 + goto out;
79520 + }
79521 +
79522 retval = sock_create(family, type, protocol, &sock);
79523 if (retval < 0)
79524 goto out;
79525 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79526 if (sock) {
79527 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79528 if (err >= 0) {
79529 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79530 + err = -EACCES;
79531 + goto error;
79532 + }
79533 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79534 + if (err)
79535 + goto error;
79536 +
79537 err = security_socket_bind(sock,
79538 (struct sockaddr *)&address,
79539 addrlen);
79540 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79541 (struct sockaddr *)
79542 &address, addrlen);
79543 }
79544 +error:
79545 fput_light(sock->file, fput_needed);
79546 }
79547 return err;
79548 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79549 if ((unsigned int)backlog > somaxconn)
79550 backlog = somaxconn;
79551
79552 + if (gr_handle_sock_server_other(sock->sk)) {
79553 + err = -EPERM;
79554 + goto error;
79555 + }
79556 +
79557 + err = gr_search_listen(sock);
79558 + if (err)
79559 + goto error;
79560 +
79561 err = security_socket_listen(sock, backlog);
79562 if (!err)
79563 err = sock->ops->listen(sock, backlog);
79564
79565 +error:
79566 fput_light(sock->file, fput_needed);
79567 }
79568 return err;
79569 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79570 newsock->type = sock->type;
79571 newsock->ops = sock->ops;
79572
79573 + if (gr_handle_sock_server_other(sock->sk)) {
79574 + err = -EPERM;
79575 + sock_release(newsock);
79576 + goto out_put;
79577 + }
79578 +
79579 + err = gr_search_accept(sock);
79580 + if (err) {
79581 + sock_release(newsock);
79582 + goto out_put;
79583 + }
79584 +
79585 /*
79586 * We don't need try_module_get here, as the listening socket (sock)
79587 * has the protocol module (sock->ops->owner) held.
79588 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79589 fd_install(newfd, newfile);
79590 err = newfd;
79591
79592 + gr_attach_curr_ip(newsock->sk);
79593 +
79594 out_put:
79595 fput_light(sock->file, fput_needed);
79596 out:
79597 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79598 int, addrlen)
79599 {
79600 struct socket *sock;
79601 + struct sockaddr *sck;
79602 struct sockaddr_storage address;
79603 int err, fput_needed;
79604
79605 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79606 if (err < 0)
79607 goto out_put;
79608
79609 + sck = (struct sockaddr *)&address;
79610 +
79611 + if (gr_handle_sock_client(sck)) {
79612 + err = -EACCES;
79613 + goto out_put;
79614 + }
79615 +
79616 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79617 + if (err)
79618 + goto out_put;
79619 +
79620 err =
79621 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79622 if (err)
79623 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79624 * checking falls down on this.
79625 */
79626 if (copy_from_user(ctl_buf,
79627 - (void __user __force *)msg_sys->msg_control,
79628 + (void __force_user *)msg_sys->msg_control,
79629 ctl_len))
79630 goto out_freectl;
79631 msg_sys->msg_control = ctl_buf;
79632 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79633 * kernel msghdr to use the kernel address space)
79634 */
79635
79636 - uaddr = (__force void __user *)msg_sys->msg_name;
79637 + uaddr = (void __force_user *)msg_sys->msg_name;
79638 uaddr_len = COMPAT_NAMELEN(msg);
79639 if (MSG_CMSG_COMPAT & flags) {
79640 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79641 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79642 }
79643
79644 ifr = compat_alloc_user_space(buf_size);
79645 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79646 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79647
79648 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79649 return -EFAULT;
79650 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79651 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79652
79653 if (copy_in_user(rxnfc, compat_rxnfc,
79654 - (void *)(&rxnfc->fs.m_ext + 1) -
79655 - (void *)rxnfc) ||
79656 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79657 + (void __user *)rxnfc) ||
79658 copy_in_user(&rxnfc->fs.ring_cookie,
79659 &compat_rxnfc->fs.ring_cookie,
79660 - (void *)(&rxnfc->fs.location + 1) -
79661 - (void *)&rxnfc->fs.ring_cookie) ||
79662 + (void __user *)(&rxnfc->fs.location + 1) -
79663 + (void __user *)&rxnfc->fs.ring_cookie) ||
79664 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79665 sizeof(rxnfc->rule_cnt)))
79666 return -EFAULT;
79667 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79668
79669 if (convert_out) {
79670 if (copy_in_user(compat_rxnfc, rxnfc,
79671 - (const void *)(&rxnfc->fs.m_ext + 1) -
79672 - (const void *)rxnfc) ||
79673 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79674 + (const void __user *)rxnfc) ||
79675 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79676 &rxnfc->fs.ring_cookie,
79677 - (const void *)(&rxnfc->fs.location + 1) -
79678 - (const void *)&rxnfc->fs.ring_cookie) ||
79679 + (const void __user *)(&rxnfc->fs.location + 1) -
79680 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79681 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79682 sizeof(rxnfc->rule_cnt)))
79683 return -EFAULT;
79684 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79685 old_fs = get_fs();
79686 set_fs(KERNEL_DS);
79687 err = dev_ioctl(net, cmd,
79688 - (struct ifreq __user __force *) &kifr);
79689 + (struct ifreq __force_user *) &kifr);
79690 set_fs(old_fs);
79691
79692 return err;
79693 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79694
79695 old_fs = get_fs();
79696 set_fs(KERNEL_DS);
79697 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79698 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79699 set_fs(old_fs);
79700
79701 if (cmd == SIOCGIFMAP && !err) {
79702 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79703 ret |= __get_user(rtdev, &(ur4->rt_dev));
79704 if (rtdev) {
79705 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79706 - r4.rt_dev = (char __user __force *)devname;
79707 + r4.rt_dev = (char __force_user *)devname;
79708 devname[15] = 0;
79709 } else
79710 r4.rt_dev = NULL;
79711 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79712 int __user *uoptlen;
79713 int err;
79714
79715 - uoptval = (char __user __force *) optval;
79716 - uoptlen = (int __user __force *) optlen;
79717 + uoptval = (char __force_user *) optval;
79718 + uoptlen = (int __force_user *) optlen;
79719
79720 set_fs(KERNEL_DS);
79721 if (level == SOL_SOCKET)
79722 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79723 char __user *uoptval;
79724 int err;
79725
79726 - uoptval = (char __user __force *) optval;
79727 + uoptval = (char __force_user *) optval;
79728
79729 set_fs(KERNEL_DS);
79730 if (level == SOL_SOCKET)
79731 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79732 index 128494e..775d0e0 100644
79733 --- a/net/sunrpc/sched.c
79734 +++ b/net/sunrpc/sched.c
79735 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79736 #ifdef RPC_DEBUG
79737 static void rpc_task_set_debuginfo(struct rpc_task *task)
79738 {
79739 - static atomic_t rpc_pid;
79740 + static atomic_unchecked_t rpc_pid;
79741
79742 - task->tk_pid = atomic_inc_return(&rpc_pid);
79743 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79744 }
79745 #else
79746 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79747 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79748 index 8343737..677025e 100644
79749 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79750 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79751 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79752 static unsigned int min_max_inline = 4096;
79753 static unsigned int max_max_inline = 65536;
79754
79755 -atomic_t rdma_stat_recv;
79756 -atomic_t rdma_stat_read;
79757 -atomic_t rdma_stat_write;
79758 -atomic_t rdma_stat_sq_starve;
79759 -atomic_t rdma_stat_rq_starve;
79760 -atomic_t rdma_stat_rq_poll;
79761 -atomic_t rdma_stat_rq_prod;
79762 -atomic_t rdma_stat_sq_poll;
79763 -atomic_t rdma_stat_sq_prod;
79764 +atomic_unchecked_t rdma_stat_recv;
79765 +atomic_unchecked_t rdma_stat_read;
79766 +atomic_unchecked_t rdma_stat_write;
79767 +atomic_unchecked_t rdma_stat_sq_starve;
79768 +atomic_unchecked_t rdma_stat_rq_starve;
79769 +atomic_unchecked_t rdma_stat_rq_poll;
79770 +atomic_unchecked_t rdma_stat_rq_prod;
79771 +atomic_unchecked_t rdma_stat_sq_poll;
79772 +atomic_unchecked_t rdma_stat_sq_prod;
79773
79774 /* Temporary NFS request map and context caches */
79775 struct kmem_cache *svc_rdma_map_cachep;
79776 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79777 len -= *ppos;
79778 if (len > *lenp)
79779 len = *lenp;
79780 - if (len && copy_to_user(buffer, str_buf, len))
79781 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79782 return -EFAULT;
79783 *lenp = len;
79784 *ppos += len;
79785 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79786 {
79787 .procname = "rdma_stat_read",
79788 .data = &rdma_stat_read,
79789 - .maxlen = sizeof(atomic_t),
79790 + .maxlen = sizeof(atomic_unchecked_t),
79791 .mode = 0644,
79792 .proc_handler = read_reset_stat,
79793 },
79794 {
79795 .procname = "rdma_stat_recv",
79796 .data = &rdma_stat_recv,
79797 - .maxlen = sizeof(atomic_t),
79798 + .maxlen = sizeof(atomic_unchecked_t),
79799 .mode = 0644,
79800 .proc_handler = read_reset_stat,
79801 },
79802 {
79803 .procname = "rdma_stat_write",
79804 .data = &rdma_stat_write,
79805 - .maxlen = sizeof(atomic_t),
79806 + .maxlen = sizeof(atomic_unchecked_t),
79807 .mode = 0644,
79808 .proc_handler = read_reset_stat,
79809 },
79810 {
79811 .procname = "rdma_stat_sq_starve",
79812 .data = &rdma_stat_sq_starve,
79813 - .maxlen = sizeof(atomic_t),
79814 + .maxlen = sizeof(atomic_unchecked_t),
79815 .mode = 0644,
79816 .proc_handler = read_reset_stat,
79817 },
79818 {
79819 .procname = "rdma_stat_rq_starve",
79820 .data = &rdma_stat_rq_starve,
79821 - .maxlen = sizeof(atomic_t),
79822 + .maxlen = sizeof(atomic_unchecked_t),
79823 .mode = 0644,
79824 .proc_handler = read_reset_stat,
79825 },
79826 {
79827 .procname = "rdma_stat_rq_poll",
79828 .data = &rdma_stat_rq_poll,
79829 - .maxlen = sizeof(atomic_t),
79830 + .maxlen = sizeof(atomic_unchecked_t),
79831 .mode = 0644,
79832 .proc_handler = read_reset_stat,
79833 },
79834 {
79835 .procname = "rdma_stat_rq_prod",
79836 .data = &rdma_stat_rq_prod,
79837 - .maxlen = sizeof(atomic_t),
79838 + .maxlen = sizeof(atomic_unchecked_t),
79839 .mode = 0644,
79840 .proc_handler = read_reset_stat,
79841 },
79842 {
79843 .procname = "rdma_stat_sq_poll",
79844 .data = &rdma_stat_sq_poll,
79845 - .maxlen = sizeof(atomic_t),
79846 + .maxlen = sizeof(atomic_unchecked_t),
79847 .mode = 0644,
79848 .proc_handler = read_reset_stat,
79849 },
79850 {
79851 .procname = "rdma_stat_sq_prod",
79852 .data = &rdma_stat_sq_prod,
79853 - .maxlen = sizeof(atomic_t),
79854 + .maxlen = sizeof(atomic_unchecked_t),
79855 .mode = 0644,
79856 .proc_handler = read_reset_stat,
79857 },
79858 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79859 index 41cb63b..c4a1489 100644
79860 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79861 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79862 @@ -501,7 +501,7 @@ next_sge:
79863 svc_rdma_put_context(ctxt, 0);
79864 goto out;
79865 }
79866 - atomic_inc(&rdma_stat_read);
79867 + atomic_inc_unchecked(&rdma_stat_read);
79868
79869 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79870 chl_map->ch[ch_no].count -= read_wr.num_sge;
79871 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79872 dto_q);
79873 list_del_init(&ctxt->dto_q);
79874 } else {
79875 - atomic_inc(&rdma_stat_rq_starve);
79876 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79877 clear_bit(XPT_DATA, &xprt->xpt_flags);
79878 ctxt = NULL;
79879 }
79880 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79881 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79882 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79883 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79884 - atomic_inc(&rdma_stat_recv);
79885 + atomic_inc_unchecked(&rdma_stat_recv);
79886
79887 /* Build up the XDR from the receive buffers. */
79888 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79889 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79890 index 42eb7ba..c887c45 100644
79891 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79892 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79893 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79894 write_wr.wr.rdma.remote_addr = to;
79895
79896 /* Post It */
79897 - atomic_inc(&rdma_stat_write);
79898 + atomic_inc_unchecked(&rdma_stat_write);
79899 if (svc_rdma_send(xprt, &write_wr))
79900 goto err;
79901 return 0;
79902 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79903 index 73b428b..5f3f8f3 100644
79904 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79905 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79906 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79907 return;
79908
79909 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79910 - atomic_inc(&rdma_stat_rq_poll);
79911 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79912
79913 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79914 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79915 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79916 }
79917
79918 if (ctxt)
79919 - atomic_inc(&rdma_stat_rq_prod);
79920 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79921
79922 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79923 /*
79924 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79925 return;
79926
79927 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79928 - atomic_inc(&rdma_stat_sq_poll);
79929 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79930 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79931 if (wc.status != IB_WC_SUCCESS)
79932 /* Close the transport */
79933 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79934 }
79935
79936 if (ctxt)
79937 - atomic_inc(&rdma_stat_sq_prod);
79938 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79939 }
79940
79941 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79942 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79943 spin_lock_bh(&xprt->sc_lock);
79944 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79945 spin_unlock_bh(&xprt->sc_lock);
79946 - atomic_inc(&rdma_stat_sq_starve);
79947 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79948
79949 /* See if we can opportunistically reap SQ WR to make room */
79950 sq_cq_reap(xprt);
79951 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79952 index e3a6e37..be2ea77 100644
79953 --- a/net/sysctl_net.c
79954 +++ b/net/sysctl_net.c
79955 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79956 struct ctl_table *table)
79957 {
79958 /* Allow network administrator to have same access as root. */
79959 - if (capable(CAP_NET_ADMIN)) {
79960 + if (capable_nolog(CAP_NET_ADMIN)) {
79961 int mode = (table->mode >> 6) & 7;
79962 return (mode << 6) | (mode << 3) | mode;
79963 }
79964 diff --git a/net/tipc/link.c b/net/tipc/link.c
79965 index 1c1e615..113e0ae 100644
79966 --- a/net/tipc/link.c
79967 +++ b/net/tipc/link.c
79968 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79969 struct tipc_msg fragm_hdr;
79970 struct sk_buff *buf, *buf_chain, *prev;
79971 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79972 - const unchar *sect_crs;
79973 + const unchar __user *sect_crs;
79974 int curr_sect;
79975 u32 fragm_no;
79976
79977 @@ -1212,7 +1212,7 @@ again:
79978
79979 if (!sect_rest) {
79980 sect_rest = msg_sect[++curr_sect].iov_len;
79981 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79982 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79983 }
79984
79985 if (sect_rest < fragm_rest)
79986 @@ -1231,7 +1231,7 @@ error:
79987 }
79988 } else
79989 skb_copy_to_linear_data_offset(buf, fragm_crs,
79990 - sect_crs, sz);
79991 + (const void __force_kernel *)sect_crs, sz);
79992 sect_crs += sz;
79993 sect_rest -= sz;
79994 fragm_crs += sz;
79995 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79996 index f2db8a8..9245aa4 100644
79997 --- a/net/tipc/msg.c
79998 +++ b/net/tipc/msg.c
79999 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
80000 msg_sect[cnt].iov_len);
80001 else
80002 skb_copy_to_linear_data_offset(*buf, pos,
80003 - msg_sect[cnt].iov_base,
80004 + (const void __force_kernel *)msg_sect[cnt].iov_base,
80005 msg_sect[cnt].iov_len);
80006 pos += msg_sect[cnt].iov_len;
80007 }
80008 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
80009 index 5ed5965..90abe34 100644
80010 --- a/net/tipc/subscr.c
80011 +++ b/net/tipc/subscr.c
80012 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
80013 {
80014 struct iovec msg_sect;
80015
80016 - msg_sect.iov_base = (void *)&sub->evt;
80017 + msg_sect.iov_base = (void __force_user *)&sub->evt;
80018 msg_sect.iov_len = sizeof(struct tipc_event);
80019
80020 sub->evt.event = htohl(event, sub->swap);
80021 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
80022 index c5ee4ff..e905948 100644
80023 --- a/net/unix/af_unix.c
80024 +++ b/net/unix/af_unix.c
80025 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
80026 err = -ECONNREFUSED;
80027 if (!S_ISSOCK(inode->i_mode))
80028 goto put_fail;
80029 +
80030 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
80031 + err = -EACCES;
80032 + goto put_fail;
80033 + }
80034 +
80035 u = unix_find_socket_byinode(inode);
80036 if (!u)
80037 goto put_fail;
80038 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
80039 if (u) {
80040 struct dentry *dentry;
80041 dentry = unix_sk(u)->path.dentry;
80042 +
80043 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
80044 + err = -EPERM;
80045 + sock_put(u);
80046 + goto fail;
80047 + }
80048 +
80049 if (dentry)
80050 touch_atime(&unix_sk(u)->path);
80051 } else
80052 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
80053 */
80054 err = security_path_mknod(&path, dentry, mode, 0);
80055 if (!err) {
80056 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
80057 + err = -EACCES;
80058 + goto out;
80059 + }
80060 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
80061 if (!err) {
80062 res->mnt = mntget(path.mnt);
80063 res->dentry = dget(dentry);
80064 + gr_handle_create(dentry, path.mnt);
80065 }
80066 }
80067 +out:
80068 done_path_create(&path, dentry);
80069 return err;
80070 }
80071 diff --git a/net/wireless/core.h b/net/wireless/core.h
80072 index bc7430b..35349de 100644
80073 --- a/net/wireless/core.h
80074 +++ b/net/wireless/core.h
80075 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80076 struct mutex mtx;
80077
80078 /* rfkill support */
80079 - struct rfkill_ops rfkill_ops;
80080 + rfkill_ops_no_const rfkill_ops;
80081 struct rfkill *rfkill;
80082 struct work_struct rfkill_sync;
80083
80084 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80085 index b0eb7aa..7d73e82 100644
80086 --- a/net/wireless/wext-core.c
80087 +++ b/net/wireless/wext-core.c
80088 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80089 */
80090
80091 /* Support for very large requests */
80092 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80093 - (user_length > descr->max_tokens)) {
80094 + if (user_length > descr->max_tokens) {
80095 /* Allow userspace to GET more than max so
80096 * we can support any size GET requests.
80097 * There is still a limit : -ENOMEM.
80098 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80099 }
80100 }
80101
80102 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80103 - /*
80104 - * If this is a GET, but not NOMAX, it means that the extra
80105 - * data is not bounded by userspace, but by max_tokens. Thus
80106 - * set the length to max_tokens. This matches the extra data
80107 - * allocation.
80108 - * The driver should fill it with the number of tokens it
80109 - * provided, and it may check iwp->length rather than having
80110 - * knowledge of max_tokens. If the driver doesn't change the
80111 - * iwp->length, this ioctl just copies back max_token tokens
80112 - * filled with zeroes. Hopefully the driver isn't claiming
80113 - * them to be valid data.
80114 - */
80115 - iwp->length = descr->max_tokens;
80116 - }
80117 -
80118 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80119
80120 iwp->length += essid_compat;
80121 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80122 index 387848e..a6667a2 100644
80123 --- a/net/xfrm/xfrm_policy.c
80124 +++ b/net/xfrm/xfrm_policy.c
80125 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80126 {
80127 policy->walk.dead = 1;
80128
80129 - atomic_inc(&policy->genid);
80130 + atomic_inc_unchecked(&policy->genid);
80131
80132 if (del_timer(&policy->timer))
80133 xfrm_pol_put(policy);
80134 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80135 hlist_add_head(&policy->bydst, chain);
80136 xfrm_pol_hold(policy);
80137 net->xfrm.policy_count[dir]++;
80138 - atomic_inc(&flow_cache_genid);
80139 + atomic_inc_unchecked(&flow_cache_genid);
80140 rt_genid_bump(net);
80141 if (delpol)
80142 __xfrm_policy_unlink(delpol, dir);
80143 @@ -1533,7 +1533,7 @@ free_dst:
80144 goto out;
80145 }
80146
80147 -static int inline
80148 +static inline int
80149 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80150 {
80151 if (!*target) {
80152 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80153 return 0;
80154 }
80155
80156 -static int inline
80157 +static inline int
80158 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80159 {
80160 #ifdef CONFIG_XFRM_SUB_POLICY
80161 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80162 #endif
80163 }
80164
80165 -static int inline
80166 +static inline int
80167 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80168 {
80169 #ifdef CONFIG_XFRM_SUB_POLICY
80170 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80171
80172 xdst->num_pols = num_pols;
80173 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80174 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80175 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80176
80177 return xdst;
80178 }
80179 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80180 if (xdst->xfrm_genid != dst->xfrm->genid)
80181 return 0;
80182 if (xdst->num_pols > 0 &&
80183 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80184 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80185 return 0;
80186
80187 mtu = dst_mtu(dst->child);
80188 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80189 sizeof(pol->xfrm_vec[i].saddr));
80190 pol->xfrm_vec[i].encap_family = mp->new_family;
80191 /* flush bundles */
80192 - atomic_inc(&pol->genid);
80193 + atomic_inc_unchecked(&pol->genid);
80194 }
80195 }
80196
80197 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80198 index ff1720d..ed8475e 100644
80199 --- a/scripts/Makefile.build
80200 +++ b/scripts/Makefile.build
80201 @@ -111,7 +111,7 @@ endif
80202 endif
80203
80204 # Do not include host rules unless needed
80205 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80206 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80207 include scripts/Makefile.host
80208 endif
80209
80210 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80211 index 686cb0d..9d653bf 100644
80212 --- a/scripts/Makefile.clean
80213 +++ b/scripts/Makefile.clean
80214 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80215 __clean-files := $(extra-y) $(always) \
80216 $(targets) $(clean-files) \
80217 $(host-progs) \
80218 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80219 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80220 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80221
80222 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80223
80224 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80225 index 1ac414f..38575f7 100644
80226 --- a/scripts/Makefile.host
80227 +++ b/scripts/Makefile.host
80228 @@ -31,6 +31,8 @@
80229 # Note: Shared libraries consisting of C++ files are not supported
80230
80231 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80232 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80233 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80234
80235 # C code
80236 # Executables compiled from a single .c file
80237 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80238 # Shared libaries (only .c supported)
80239 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80240 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80241 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80242 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80243 # Remove .so files from "xxx-objs"
80244 host-cobjs := $(filter-out %.so,$(host-cobjs))
80245 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80246
80247 -#Object (.o) files used by the shared libaries
80248 +# Object (.o) files used by the shared libaries
80249 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80250 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80251
80252 # output directory for programs/.o files
80253 # hostprogs-y := tools/build may have been specified. Retrieve directory
80254 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80255 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80256 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80257 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80258 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80259 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80260 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80261 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80262
80263 obj-dirs += $(host-objdirs)
80264 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80265 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80266 $(call if_changed_dep,host-cshobjs)
80267
80268 +# Compile .c file, create position independent .o file
80269 +# host-cxxshobjs -> .o
80270 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80271 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80272 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80273 + $(call if_changed_dep,host-cxxshobjs)
80274 +
80275 # Link a shared library, based on position independent .o files
80276 # *.o -> .so shared library (host-cshlib)
80277 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80278 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80279 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80280 $(call if_changed,host-cshlib)
80281
80282 +# Link a shared library, based on position independent .o files
80283 +# *.o -> .so shared library (host-cxxshlib)
80284 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80285 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80286 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80287 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80288 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80289 + $(call if_changed,host-cxxshlib)
80290 +
80291 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80292 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80293 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80294
80295 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80296 index cb1f50c..cef2a7c 100644
80297 --- a/scripts/basic/fixdep.c
80298 +++ b/scripts/basic/fixdep.c
80299 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80300 /*
80301 * Lookup a value in the configuration string.
80302 */
80303 -static int is_defined_config(const char *name, int len, unsigned int hash)
80304 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80305 {
80306 struct item *aux;
80307
80308 @@ -211,10 +211,10 @@ static void clear_config(void)
80309 /*
80310 * Record the use of a CONFIG_* word.
80311 */
80312 -static void use_config(const char *m, int slen)
80313 +static void use_config(const char *m, unsigned int slen)
80314 {
80315 unsigned int hash = strhash(m, slen);
80316 - int c, i;
80317 + unsigned int c, i;
80318
80319 if (is_defined_config(m, slen, hash))
80320 return;
80321 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80322
80323 static void parse_config_file(const char *map, size_t len)
80324 {
80325 - const int *end = (const int *) (map + len);
80326 + const unsigned int *end = (const unsigned int *) (map + len);
80327 /* start at +1, so that p can never be < map */
80328 - const int *m = (const int *) map + 1;
80329 + const unsigned int *m = (const unsigned int *) map + 1;
80330 const char *p, *q;
80331
80332 for (; m < end; m++) {
80333 @@ -406,7 +406,7 @@ static void print_deps(void)
80334 static void traps(void)
80335 {
80336 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80337 - int *p = (int *)test;
80338 + unsigned int *p = (unsigned int *)test;
80339
80340 if (*p != INT_CONF) {
80341 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80342 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80343 new file mode 100644
80344 index 0000000..008ac1a
80345 --- /dev/null
80346 +++ b/scripts/gcc-plugin.sh
80347 @@ -0,0 +1,17 @@
80348 +#!/bin/bash
80349 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80350 +#include "gcc-plugin.h"
80351 +#include "tree.h"
80352 +#include "tm.h"
80353 +#include "rtl.h"
80354 +#ifdef ENABLE_BUILD_WITH_CXX
80355 +#warning $2
80356 +#else
80357 +#warning $1
80358 +#endif
80359 +EOF`
80360 +if [ $? -eq 0 ]
80361 +then
80362 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80363 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80364 +fi
80365 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80366 index b3d907e..a4782ab 100644
80367 --- a/scripts/link-vmlinux.sh
80368 +++ b/scripts/link-vmlinux.sh
80369 @@ -152,7 +152,7 @@ else
80370 fi;
80371
80372 # final build of init/
80373 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80374 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80375
80376 kallsymso=""
80377 kallsyms_vmlinux=""
80378 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80379 index 7ed6864..b6e90e6 100644
80380 --- a/scripts/mod/file2alias.c
80381 +++ b/scripts/mod/file2alias.c
80382 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80383 unsigned long size, unsigned long id_size,
80384 void *symval)
80385 {
80386 - int i;
80387 + unsigned int i;
80388
80389 if (size % id_size || size < id_size) {
80390 if (cross_build != 0)
80391 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80392 /* USB is special because the bcdDevice can be matched against a numeric range */
80393 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80394 static void do_usb_entry(struct usb_device_id *id,
80395 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80396 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80397 unsigned char range_lo, unsigned char range_hi,
80398 unsigned char max, struct module *mod)
80399 {
80400 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80401 {
80402 unsigned int devlo, devhi;
80403 unsigned char chi, clo, max;
80404 - int ndigits;
80405 + unsigned int ndigits;
80406
80407 id->match_flags = TO_NATIVE(id->match_flags);
80408 id->idVendor = TO_NATIVE(id->idVendor);
80409 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80410 for (i = 0; i < count; i++) {
80411 const char *id = (char *)devs[i].id;
80412 char acpi_id[sizeof(devs[0].id)];
80413 - int j;
80414 + unsigned int j;
80415
80416 buf_printf(&mod->dev_table_buf,
80417 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80418 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80419
80420 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80421 const char *id = (char *)card->devs[j].id;
80422 - int i2, j2;
80423 + unsigned int i2, j2;
80424 int dup = 0;
80425
80426 if (!id[0])
80427 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80428 /* add an individual alias for every device entry */
80429 if (!dup) {
80430 char acpi_id[sizeof(card->devs[0].id)];
80431 - int k;
80432 + unsigned int k;
80433
80434 buf_printf(&mod->dev_table_buf,
80435 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80436 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80437 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80438 char *alias)
80439 {
80440 - int i, j;
80441 + unsigned int i, j;
80442
80443 sprintf(alias, "dmi*");
80444
80445 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80446 index 68e9f5e..ac7759b 100644
80447 --- a/scripts/mod/modpost.c
80448 +++ b/scripts/mod/modpost.c
80449 @@ -930,6 +930,7 @@ enum mismatch {
80450 ANY_INIT_TO_ANY_EXIT,
80451 ANY_EXIT_TO_ANY_INIT,
80452 EXPORT_TO_INIT_EXIT,
80453 + DATA_TO_TEXT
80454 };
80455
80456 struct sectioncheck {
80457 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80458 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80459 .mismatch = EXPORT_TO_INIT_EXIT,
80460 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80461 +},
80462 +/* Do not reference code from writable data */
80463 +{
80464 + .fromsec = { DATA_SECTIONS, NULL },
80465 + .tosec = { TEXT_SECTIONS, NULL },
80466 + .mismatch = DATA_TO_TEXT
80467 }
80468 };
80469
80470 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80471 continue;
80472 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80473 continue;
80474 - if (sym->st_value == addr)
80475 - return sym;
80476 /* Find a symbol nearby - addr are maybe negative */
80477 d = sym->st_value - addr;
80478 + if (d == 0)
80479 + return sym;
80480 if (d < 0)
80481 d = addr - sym->st_value;
80482 if (d < distance) {
80483 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80484 tosym, prl_to, prl_to, tosym);
80485 free(prl_to);
80486 break;
80487 + case DATA_TO_TEXT:
80488 +#if 0
80489 + fprintf(stderr,
80490 + "The %s %s:%s references\n"
80491 + "the %s %s:%s%s\n",
80492 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80493 +#endif
80494 + break;
80495 }
80496 fprintf(stderr, "\n");
80497 }
80498 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80499 static void check_sec_ref(struct module *mod, const char *modname,
80500 struct elf_info *elf)
80501 {
80502 - int i;
80503 + unsigned int i;
80504 Elf_Shdr *sechdrs = elf->sechdrs;
80505
80506 /* Walk through all sections */
80507 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80508 va_end(ap);
80509 }
80510
80511 -void buf_write(struct buffer *buf, const char *s, int len)
80512 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80513 {
80514 if (buf->size - buf->pos < len) {
80515 buf->size += len + SZ;
80516 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80517 if (fstat(fileno(file), &st) < 0)
80518 goto close_write;
80519
80520 - if (st.st_size != b->pos)
80521 + if (st.st_size != (off_t)b->pos)
80522 goto close_write;
80523
80524 tmp = NOFAIL(malloc(b->pos));
80525 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80526 index 51207e4..f7d603d 100644
80527 --- a/scripts/mod/modpost.h
80528 +++ b/scripts/mod/modpost.h
80529 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80530
80531 struct buffer {
80532 char *p;
80533 - int pos;
80534 - int size;
80535 + unsigned int pos;
80536 + unsigned int size;
80537 };
80538
80539 void __attribute__((format(printf, 2, 3)))
80540 buf_printf(struct buffer *buf, const char *fmt, ...);
80541
80542 void
80543 -buf_write(struct buffer *buf, const char *s, int len);
80544 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80545
80546 struct module {
80547 struct module *next;
80548 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80549 index 9dfcd6d..099068e 100644
80550 --- a/scripts/mod/sumversion.c
80551 +++ b/scripts/mod/sumversion.c
80552 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80553 goto out;
80554 }
80555
80556 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80557 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80558 warn("writing sum in %s failed: %s\n",
80559 filename, strerror(errno));
80560 goto out;
80561 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80562 index 5c11312..72742b5 100644
80563 --- a/scripts/pnmtologo.c
80564 +++ b/scripts/pnmtologo.c
80565 @@ -237,14 +237,14 @@ static void write_header(void)
80566 fprintf(out, " * Linux logo %s\n", logoname);
80567 fputs(" */\n\n", out);
80568 fputs("#include <linux/linux_logo.h>\n\n", out);
80569 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80570 + fprintf(out, "static unsigned char %s_data[] = {\n",
80571 logoname);
80572 }
80573
80574 static void write_footer(void)
80575 {
80576 fputs("\n};\n\n", out);
80577 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80578 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80579 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80580 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80581 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80582 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80583 fputs("\n};\n\n", out);
80584
80585 /* write logo clut */
80586 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80587 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80588 logoname);
80589 write_hex_cnt = 0;
80590 for (i = 0; i < logo_clutsize; i++) {
80591 diff --git a/security/Kconfig b/security/Kconfig
80592 index e9c6ac7..e7feb0d 100644
80593 --- a/security/Kconfig
80594 +++ b/security/Kconfig
80595 @@ -4,6 +4,896 @@
80596
80597 menu "Security options"
80598
80599 +menu "Grsecurity"
80600 +
80601 + config ARCH_TRACK_EXEC_LIMIT
80602 + bool
80603 +
80604 + config PAX_KERNEXEC_PLUGIN
80605 + bool
80606 +
80607 + config PAX_PER_CPU_PGD
80608 + bool
80609 +
80610 + config TASK_SIZE_MAX_SHIFT
80611 + int
80612 + depends on X86_64
80613 + default 47 if !PAX_PER_CPU_PGD
80614 + default 42 if PAX_PER_CPU_PGD
80615 +
80616 + config PAX_ENABLE_PAE
80617 + bool
80618 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80619 +
80620 + config PAX_USERCOPY_SLABS
80621 + bool
80622 +
80623 +config GRKERNSEC
80624 + bool "Grsecurity"
80625 + select CRYPTO
80626 + select CRYPTO_SHA256
80627 + select PROC_FS
80628 + select STOP_MACHINE
80629 + help
80630 + If you say Y here, you will be able to configure many features
80631 + that will enhance the security of your system. It is highly
80632 + recommended that you say Y here and read through the help
80633 + for each option so that you fully understand the features and
80634 + can evaluate their usefulness for your machine.
80635 +
80636 +choice
80637 + prompt "Configuration Method"
80638 + depends on GRKERNSEC
80639 + default GRKERNSEC_CONFIG_CUSTOM
80640 + help
80641 +
80642 +config GRKERNSEC_CONFIG_AUTO
80643 + bool "Automatic"
80644 + help
80645 + If you choose this configuration method, you'll be able to answer a small
80646 + number of simple questions about how you plan to use this kernel.
80647 + The settings of grsecurity and PaX will be automatically configured for
80648 + the highest commonly-used settings within the provided constraints.
80649 +
80650 + If you require additional configuration, custom changes can still be made
80651 + from the "custom configuration" menu.
80652 +
80653 +config GRKERNSEC_CONFIG_CUSTOM
80654 + bool "Custom"
80655 + help
80656 + If you choose this configuration method, you'll be able to configure all
80657 + grsecurity and PaX settings manually. Via this method, no options are
80658 + automatically enabled.
80659 +
80660 +endchoice
80661 +
80662 +choice
80663 + prompt "Usage Type"
80664 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80665 + default GRKERNSEC_CONFIG_SERVER
80666 + help
80667 +
80668 +config GRKERNSEC_CONFIG_SERVER
80669 + bool "Server"
80670 + help
80671 + Choose this option if you plan to use this kernel on a server.
80672 +
80673 +config GRKERNSEC_CONFIG_DESKTOP
80674 + bool "Desktop"
80675 + help
80676 + Choose this option if you plan to use this kernel on a desktop.
80677 +
80678 +endchoice
80679 +
80680 +choice
80681 + prompt "Virtualization Type"
80682 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80683 + default GRKERNSEC_CONFIG_VIRT_NONE
80684 + help
80685 +
80686 +config GRKERNSEC_CONFIG_VIRT_NONE
80687 + bool "None"
80688 + help
80689 + Choose this option if this kernel will be run on bare metal.
80690 +
80691 +config GRKERNSEC_CONFIG_VIRT_GUEST
80692 + bool "Guest"
80693 + help
80694 + Choose this option if this kernel will be run as a VM guest.
80695 +
80696 +config GRKERNSEC_CONFIG_VIRT_HOST
80697 + bool "Host"
80698 + help
80699 + Choose this option if this kernel will be run as a VM host.
80700 +
80701 +endchoice
80702 +
80703 +choice
80704 + prompt "Virtualization Hardware"
80705 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80706 + help
80707 +
80708 +config GRKERNSEC_CONFIG_VIRT_EPT
80709 + bool "EPT/RVI Processor Support"
80710 + depends on X86
80711 + help
80712 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80713 + hardware virtualization. This allows for additional kernel hardening protections
80714 + to operate without additional performance impact.
80715 +
80716 + To see if your Intel processor supports EPT, see:
80717 + http://ark.intel.com/Products/VirtualizationTechnology
80718 + (Most Core i3/5/7 support EPT)
80719 +
80720 + To see if your AMD processor supports RVI, see:
80721 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80722 +
80723 +config GRKERNSEC_CONFIG_VIRT_SOFT
80724 + bool "First-gen/No Hardware Virtualization"
80725 + help
80726 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80727 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80728 +
80729 +endchoice
80730 +
80731 +choice
80732 + prompt "Virtualization Software"
80733 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80734 + help
80735 +
80736 +config GRKERNSEC_CONFIG_VIRT_XEN
80737 + bool "Xen"
80738 + help
80739 + Choose this option if this kernel is running as a Xen guest or host.
80740 +
80741 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80742 + bool "VMWare"
80743 + help
80744 + Choose this option if this kernel is running as a VMWare guest or host.
80745 +
80746 +config GRKERNSEC_CONFIG_VIRT_KVM
80747 + bool "KVM"
80748 + help
80749 + Choose this option if this kernel is running as a KVM guest or host.
80750 +
80751 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80752 + bool "VirtualBox"
80753 + help
80754 + Choose this option if this kernel is running as a VirtualBox guest or host.
80755 +
80756 +endchoice
80757 +
80758 +choice
80759 + prompt "Required Priorities"
80760 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80761 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80762 + help
80763 +
80764 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80765 + bool "Performance"
80766 + help
80767 + Choose this option if performance is of highest priority for this deployment
80768 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80769 + and freed memory sanitizing will be disabled.
80770 +
80771 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80772 + bool "Security"
80773 + help
80774 + Choose this option if security is of highest priority for this deployment of
80775 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80776 + be enabled for this kernel. In a worst-case scenario, these features can
80777 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80778 +
80779 +endchoice
80780 +
80781 +menu "Default Special Groups"
80782 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80783 +
80784 +config GRKERNSEC_PROC_GID
80785 + int "GID exempted from /proc restrictions"
80786 + default 1001
80787 + help
80788 + Setting this GID determines which group will be exempted from
80789 + grsecurity's /proc restrictions, allowing users of the specified
80790 + group to view network statistics and the existence of other users'
80791 + processes on the system. This GID may also be chosen at boot time
80792 + via "grsec_proc_gid=" on the kernel commandline.
80793 +
80794 +config GRKERNSEC_TPE_UNTRUSTED_GID
80795 + int "GID for TPE-untrusted users"
80796 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80797 + default 1005
80798 + help
80799 + Setting this GID determines which group untrusted users should
80800 + be added to. These users will be placed under grsecurity's Trusted Path
80801 + Execution mechanism, preventing them from executing their own binaries.
80802 + The users will only be able to execute binaries in directories owned and
80803 + writable only by the root user. If the sysctl option is enabled, a sysctl
80804 + option with name "tpe_gid" is created.
80805 +
80806 +config GRKERNSEC_TPE_TRUSTED_GID
80807 + int "GID for TPE-trusted users"
80808 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80809 + default 1005
80810 + help
80811 + Setting this GID determines what group TPE restrictions will be
80812 + *disabled* for. If the sysctl option is enabled, a sysctl option
80813 + with name "tpe_gid" is created.
80814 +
80815 +config GRKERNSEC_SYMLINKOWN_GID
80816 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80817 + depends on GRKERNSEC_CONFIG_SERVER
80818 + default 1006
80819 + help
80820 + Setting this GID determines what group kernel-enforced
80821 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80822 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80823 +
80824 +
80825 +endmenu
80826 +
80827 +menu "Customize Configuration"
80828 +depends on GRKERNSEC
80829 +
80830 +menu "PaX"
80831 +
80832 +config PAX
80833 + bool "Enable various PaX features"
80834 + default y if GRKERNSEC_CONFIG_AUTO
80835 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80836 + help
80837 + This allows you to enable various PaX features. PaX adds
80838 + intrusion prevention mechanisms to the kernel that reduce
80839 + the risks posed by exploitable memory corruption bugs.
80840 +
80841 +menu "PaX Control"
80842 + depends on PAX
80843 +
80844 +config PAX_SOFTMODE
80845 + bool 'Support soft mode'
80846 + help
80847 + Enabling this option will allow you to run PaX in soft mode, that
80848 + is, PaX features will not be enforced by default, only on executables
80849 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80850 + support as they are the only way to mark executables for soft mode use.
80851 +
80852 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80853 + line option on boot. Furthermore you can control various PaX features
80854 + at runtime via the entries in /proc/sys/kernel/pax.
80855 +
80856 +config PAX_EI_PAX
80857 + bool 'Use legacy ELF header marking'
80858 + default y if GRKERNSEC_CONFIG_AUTO
80859 + help
80860 + Enabling this option will allow you to control PaX features on
80861 + a per executable basis via the 'chpax' utility available at
80862 + http://pax.grsecurity.net/. The control flags will be read from
80863 + an otherwise reserved part of the ELF header. This marking has
80864 + numerous drawbacks (no support for soft-mode, toolchain does not
80865 + know about the non-standard use of the ELF header) therefore it
80866 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80867 + support.
80868 +
80869 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80870 + support as well, they will override the legacy EI_PAX marks.
80871 +
80872 + If you enable none of the marking options then all applications
80873 + will run with PaX enabled on them by default.
80874 +
80875 +config PAX_PT_PAX_FLAGS
80876 + bool 'Use ELF program header marking'
80877 + default y if GRKERNSEC_CONFIG_AUTO
80878 + help
80879 + Enabling this option will allow you to control PaX features on
80880 + a per executable basis via the 'paxctl' utility available at
80881 + http://pax.grsecurity.net/. The control flags will be read from
80882 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80883 + has the benefits of supporting both soft mode and being fully
80884 + integrated into the toolchain (the binutils patch is available
80885 + from http://pax.grsecurity.net).
80886 +
80887 + Note that if you enable the legacy EI_PAX marking support as well,
80888 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80889 +
80890 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80891 + must make sure that the marks are the same if a binary has both marks.
80892 +
80893 + If you enable none of the marking options then all applications
80894 + will run with PaX enabled on them by default.
80895 +
80896 +config PAX_XATTR_PAX_FLAGS
80897 + bool 'Use filesystem extended attributes marking'
80898 + default y if GRKERNSEC_CONFIG_AUTO
80899 + select CIFS_XATTR if CIFS
80900 + select EXT2_FS_XATTR if EXT2_FS
80901 + select EXT3_FS_XATTR if EXT3_FS
80902 + select EXT4_FS_XATTR if EXT4_FS
80903 + select JFFS2_FS_XATTR if JFFS2_FS
80904 + select REISERFS_FS_XATTR if REISERFS_FS
80905 + select SQUASHFS_XATTR if SQUASHFS
80906 + select TMPFS_XATTR if TMPFS
80907 + select UBIFS_FS_XATTR if UBIFS_FS
80908 + help
80909 + Enabling this option will allow you to control PaX features on
80910 + a per executable basis via the 'setfattr' utility. The control
80911 + flags will be read from the user.pax.flags extended attribute of
80912 + the file. This marking has the benefit of supporting binary-only
80913 + applications that self-check themselves (e.g., skype) and would
80914 + not tolerate chpax/paxctl changes. The main drawback is that
80915 + extended attributes are not supported by some filesystems (e.g.,
80916 + isofs, udf, vfat) so copying files through such filesystems will
80917 + lose the extended attributes and these PaX markings.
80918 +
80919 + Note that if you enable the legacy EI_PAX marking support as well,
80920 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80921 +
80922 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80923 + must make sure that the marks are the same if a binary has both marks.
80924 +
80925 + If you enable none of the marking options then all applications
80926 + will run with PaX enabled on them by default.
80927 +
80928 +choice
80929 + prompt 'MAC system integration'
80930 + default PAX_HAVE_ACL_FLAGS
80931 + help
80932 + Mandatory Access Control systems have the option of controlling
80933 + PaX flags on a per executable basis, choose the method supported
80934 + by your particular system.
80935 +
80936 + - "none": if your MAC system does not interact with PaX,
80937 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80938 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80939 +
80940 + NOTE: this option is for developers/integrators only.
80941 +
80942 + config PAX_NO_ACL_FLAGS
80943 + bool 'none'
80944 +
80945 + config PAX_HAVE_ACL_FLAGS
80946 + bool 'direct'
80947 +
80948 + config PAX_HOOK_ACL_FLAGS
80949 + bool 'hook'
80950 +endchoice
80951 +
80952 +endmenu
80953 +
80954 +menu "Non-executable pages"
80955 + depends on PAX
80956 +
80957 +config PAX_NOEXEC
80958 + bool "Enforce non-executable pages"
80959 + default y if GRKERNSEC_CONFIG_AUTO
80960 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80961 + help
80962 + By design some architectures do not allow for protecting memory
80963 + pages against execution or even if they do, Linux does not make
80964 + use of this feature. In practice this means that if a page is
80965 + readable (such as the stack or heap) it is also executable.
80966 +
80967 + There is a well known exploit technique that makes use of this
80968 + fact and a common programming mistake where an attacker can
80969 + introduce code of his choice somewhere in the attacked program's
80970 + memory (typically the stack or the heap) and then execute it.
80971 +
80972 + If the attacked program was running with different (typically
80973 + higher) privileges than that of the attacker, then he can elevate
80974 + his own privilege level (e.g. get a root shell, write to files for
80975 + which he does not have write access to, etc).
80976 +
80977 + Enabling this option will let you choose from various features
80978 + that prevent the injection and execution of 'foreign' code in
80979 + a program.
80980 +
80981 + This will also break programs that rely on the old behaviour and
80982 + expect that dynamically allocated memory via the malloc() family
80983 + of functions is executable (which it is not). Notable examples
80984 + are the XFree86 4.x server, the java runtime and wine.
80985 +
80986 +config PAX_PAGEEXEC
80987 + bool "Paging based non-executable pages"
80988 + default y if GRKERNSEC_CONFIG_AUTO
80989 + 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)
80990 + select S390_SWITCH_AMODE if S390
80991 + select S390_EXEC_PROTECT if S390
80992 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80993 + help
80994 + This implementation is based on the paging feature of the CPU.
80995 + On i386 without hardware non-executable bit support there is a
80996 + variable but usually low performance impact, however on Intel's
80997 + P4 core based CPUs it is very high so you should not enable this
80998 + for kernels meant to be used on such CPUs.
80999 +
81000 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
81001 + with hardware non-executable bit support there is no performance
81002 + impact, on ppc the impact is negligible.
81003 +
81004 + Note that several architectures require various emulations due to
81005 + badly designed userland ABIs, this will cause a performance impact
81006 + but will disappear as soon as userland is fixed. For example, ppc
81007 + userland MUST have been built with secure-plt by a recent toolchain.
81008 +
81009 +config PAX_SEGMEXEC
81010 + bool "Segmentation based non-executable pages"
81011 + default y if GRKERNSEC_CONFIG_AUTO
81012 + depends on PAX_NOEXEC && X86_32
81013 + help
81014 + This implementation is based on the segmentation feature of the
81015 + CPU and has a very small performance impact, however applications
81016 + will be limited to a 1.5 GB address space instead of the normal
81017 + 3 GB.
81018 +
81019 +config PAX_EMUTRAMP
81020 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
81021 + default y if PARISC
81022 + help
81023 + There are some programs and libraries that for one reason or
81024 + another attempt to execute special small code snippets from
81025 + non-executable memory pages. Most notable examples are the
81026 + signal handler return code generated by the kernel itself and
81027 + the GCC trampolines.
81028 +
81029 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
81030 + such programs will no longer work under your kernel.
81031 +
81032 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
81033 + utilities to enable trampoline emulation for the affected programs
81034 + yet still have the protection provided by the non-executable pages.
81035 +
81036 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
81037 + your system will not even boot.
81038 +
81039 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
81040 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
81041 + for the affected files.
81042 +
81043 + NOTE: enabling this feature *may* open up a loophole in the
81044 + protection provided by non-executable pages that an attacker
81045 + could abuse. Therefore the best solution is to not have any
81046 + files on your system that would require this option. This can
81047 + be achieved by not using libc5 (which relies on the kernel
81048 + signal handler return code) and not using or rewriting programs
81049 + that make use of the nested function implementation of GCC.
81050 + Skilled users can just fix GCC itself so that it implements
81051 + nested function calls in a way that does not interfere with PaX.
81052 +
81053 +config PAX_EMUSIGRT
81054 + bool "Automatically emulate sigreturn trampolines"
81055 + depends on PAX_EMUTRAMP && PARISC
81056 + default y
81057 + help
81058 + Enabling this option will have the kernel automatically detect
81059 + and emulate signal return trampolines executing on the stack
81060 + that would otherwise lead to task termination.
81061 +
81062 + This solution is intended as a temporary one for users with
81063 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81064 + Modula-3 runtime, etc) or executables linked to such, basically
81065 + everything that does not specify its own SA_RESTORER function in
81066 + normal executable memory like glibc 2.1+ does.
81067 +
81068 + On parisc you MUST enable this option, otherwise your system will
81069 + not even boot.
81070 +
81071 + NOTE: this feature cannot be disabled on a per executable basis
81072 + and since it *does* open up a loophole in the protection provided
81073 + by non-executable pages, the best solution is to not have any
81074 + files on your system that would require this option.
81075 +
81076 +config PAX_MPROTECT
81077 + bool "Restrict mprotect()"
81078 + default y if GRKERNSEC_CONFIG_AUTO
81079 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81080 + help
81081 + Enabling this option will prevent programs from
81082 + - changing the executable status of memory pages that were
81083 + not originally created as executable,
81084 + - making read-only executable pages writable again,
81085 + - creating executable pages from anonymous memory,
81086 + - making read-only-after-relocations (RELRO) data pages writable again.
81087 +
81088 + You should say Y here to complete the protection provided by
81089 + the enforcement of non-executable pages.
81090 +
81091 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81092 + this feature on a per file basis.
81093 +
81094 +config PAX_MPROTECT_COMPAT
81095 + bool "Use legacy/compat protection demoting (read help)"
81096 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81097 + depends on PAX_MPROTECT
81098 + help
81099 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81100 + by sending the proper error code to the application. For some broken
81101 + userland, this can cause problems with Python or other applications. The
81102 + current implementation however allows for applications like clamav to
81103 + detect if JIT compilation/execution is allowed and to fall back gracefully
81104 + to an interpreter-based mode if it does not. While we encourage everyone
81105 + to use the current implementation as-is and push upstream to fix broken
81106 + userland (note that the RWX logging option can assist with this), in some
81107 + environments this may not be possible. Having to disable MPROTECT
81108 + completely on certain binaries reduces the security benefit of PaX,
81109 + so this option is provided for those environments to revert to the old
81110 + behavior.
81111 +
81112 +config PAX_ELFRELOCS
81113 + bool "Allow ELF text relocations (read help)"
81114 + depends on PAX_MPROTECT
81115 + default n
81116 + help
81117 + Non-executable pages and mprotect() restrictions are effective
81118 + in preventing the introduction of new executable code into an
81119 + attacked task's address space. There remain only two venues
81120 + for this kind of attack: if the attacker can execute already
81121 + existing code in the attacked task then he can either have it
81122 + create and mmap() a file containing his code or have it mmap()
81123 + an already existing ELF library that does not have position
81124 + independent code in it and use mprotect() on it to make it
81125 + writable and copy his code there. While protecting against
81126 + the former approach is beyond PaX, the latter can be prevented
81127 + by having only PIC ELF libraries on one's system (which do not
81128 + need to relocate their code). If you are sure this is your case,
81129 + as is the case with all modern Linux distributions, then leave
81130 + this option disabled. You should say 'n' here.
81131 +
81132 +config PAX_ETEXECRELOCS
81133 + bool "Allow ELF ET_EXEC text relocations"
81134 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81135 + select PAX_ELFRELOCS
81136 + default y
81137 + help
81138 + On some architectures there are incorrectly created applications
81139 + that require text relocations and would not work without enabling
81140 + this option. If you are an alpha, ia64 or parisc user, you should
81141 + enable this option and disable it once you have made sure that
81142 + none of your applications need it.
81143 +
81144 +config PAX_EMUPLT
81145 + bool "Automatically emulate ELF PLT"
81146 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81147 + default y
81148 + help
81149 + Enabling this option will have the kernel automatically detect
81150 + and emulate the Procedure Linkage Table entries in ELF files.
81151 + On some architectures such entries are in writable memory, and
81152 + become non-executable leading to task termination. Therefore
81153 + it is mandatory that you enable this option on alpha, parisc,
81154 + sparc and sparc64, otherwise your system would not even boot.
81155 +
81156 + NOTE: this feature *does* open up a loophole in the protection
81157 + provided by the non-executable pages, therefore the proper
81158 + solution is to modify the toolchain to produce a PLT that does
81159 + not need to be writable.
81160 +
81161 +config PAX_DLRESOLVE
81162 + bool 'Emulate old glibc resolver stub'
81163 + depends on PAX_EMUPLT && SPARC
81164 + default n
81165 + help
81166 + This option is needed if userland has an old glibc (before 2.4)
81167 + that puts a 'save' instruction into the runtime generated resolver
81168 + stub that needs special emulation.
81169 +
81170 +config PAX_KERNEXEC
81171 + bool "Enforce non-executable kernel pages"
81172 + 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))
81173 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81174 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81175 + select PAX_KERNEXEC_PLUGIN if X86_64
81176 + help
81177 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81178 + that is, enabling this option will make it harder to inject
81179 + and execute 'foreign' code in kernel memory itself.
81180 +
81181 +choice
81182 + prompt "Return Address Instrumentation Method"
81183 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81184 + depends on PAX_KERNEXEC_PLUGIN
81185 + help
81186 + Select the method used to instrument function pointer dereferences.
81187 + Note that binary modules cannot be instrumented by this approach.
81188 +
81189 + Note that the implementation requires a gcc with plugin support,
81190 + i.e., gcc 4.5 or newer. You may need to install the supporting
81191 + headers explicitly in addition to the normal gcc package.
81192 +
81193 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81194 + bool "bts"
81195 + help
81196 + This method is compatible with binary only modules but has
81197 + a higher runtime overhead.
81198 +
81199 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81200 + bool "or"
81201 + depends on !PARAVIRT
81202 + help
81203 + This method is incompatible with binary only modules but has
81204 + a lower runtime overhead.
81205 +endchoice
81206 +
81207 +config PAX_KERNEXEC_PLUGIN_METHOD
81208 + string
81209 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81210 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81211 + default ""
81212 +
81213 +config PAX_KERNEXEC_MODULE_TEXT
81214 + int "Minimum amount of memory reserved for module code"
81215 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81216 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81217 + depends on PAX_KERNEXEC && X86_32 && MODULES
81218 + help
81219 + Due to implementation details the kernel must reserve a fixed
81220 + amount of memory for module code at compile time that cannot be
81221 + changed at runtime. Here you can specify the minimum amount
81222 + in MB that will be reserved. Due to the same implementation
81223 + details this size will always be rounded up to the next 2/4 MB
81224 + boundary (depends on PAE) so the actually available memory for
81225 + module code will usually be more than this minimum.
81226 +
81227 + The default 4 MB should be enough for most users but if you have
81228 + an excessive number of modules (e.g., most distribution configs
81229 + compile many drivers as modules) or use huge modules such as
81230 + nvidia's kernel driver, you will need to adjust this amount.
81231 + A good rule of thumb is to look at your currently loaded kernel
81232 + modules and add up their sizes.
81233 +
81234 +endmenu
81235 +
81236 +menu "Address Space Layout Randomization"
81237 + depends on PAX
81238 +
81239 +config PAX_ASLR
81240 + bool "Address Space Layout Randomization"
81241 + default y if GRKERNSEC_CONFIG_AUTO
81242 + help
81243 + Many if not most exploit techniques rely on the knowledge of
81244 + certain addresses in the attacked program. The following options
81245 + will allow the kernel to apply a certain amount of randomization
81246 + to specific parts of the program thereby forcing an attacker to
81247 + guess them in most cases. Any failed guess will most likely crash
81248 + the attacked program which allows the kernel to detect such attempts
81249 + and react on them. PaX itself provides no reaction mechanisms,
81250 + instead it is strongly encouraged that you make use of Nergal's
81251 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81252 + (http://www.grsecurity.net/) built-in crash detection features or
81253 + develop one yourself.
81254 +
81255 + By saying Y here you can choose to randomize the following areas:
81256 + - top of the task's kernel stack
81257 + - top of the task's userland stack
81258 + - base address for mmap() requests that do not specify one
81259 + (this includes all libraries)
81260 + - base address of the main executable
81261 +
81262 + It is strongly recommended to say Y here as address space layout
81263 + randomization has negligible impact on performance yet it provides
81264 + a very effective protection.
81265 +
81266 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81267 + this feature on a per file basis.
81268 +
81269 +config PAX_RANDKSTACK
81270 + bool "Randomize kernel stack base"
81271 + default y if GRKERNSEC_CONFIG_AUTO
81272 + depends on X86_TSC && X86
81273 + help
81274 + By saying Y here the kernel will randomize every task's kernel
81275 + stack on every system call. This will not only force an attacker
81276 + to guess it but also prevent him from making use of possible
81277 + leaked information about it.
81278 +
81279 + Since the kernel stack is a rather scarce resource, randomization
81280 + may cause unexpected stack overflows, therefore you should very
81281 + carefully test your system. Note that once enabled in the kernel
81282 + configuration, this feature cannot be disabled on a per file basis.
81283 +
81284 +config PAX_RANDUSTACK
81285 + bool "Randomize user stack base"
81286 + default y if GRKERNSEC_CONFIG_AUTO
81287 + depends on PAX_ASLR
81288 + help
81289 + By saying Y here the kernel will randomize every task's userland
81290 + stack. The randomization is done in two steps where the second
81291 + one may apply a big amount of shift to the top of the stack and
81292 + cause problems for programs that want to use lots of memory (more
81293 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81294 + For this reason the second step can be controlled by 'chpax' or
81295 + 'paxctl' on a per file basis.
81296 +
81297 +config PAX_RANDMMAP
81298 + bool "Randomize mmap() base"
81299 + default y if GRKERNSEC_CONFIG_AUTO
81300 + depends on PAX_ASLR
81301 + help
81302 + By saying Y here the kernel will use a randomized base address for
81303 + mmap() requests that do not specify one themselves. As a result
81304 + all dynamically loaded libraries will appear at random addresses
81305 + and therefore be harder to exploit by a technique where an attacker
81306 + attempts to execute library code for his purposes (e.g. spawn a
81307 + shell from an exploited program that is running at an elevated
81308 + privilege level).
81309 +
81310 + Furthermore, if a program is relinked as a dynamic ELF file, its
81311 + base address will be randomized as well, completing the full
81312 + randomization of the address space layout. Attacking such programs
81313 + becomes a guess game. You can find an example of doing this at
81314 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81315 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81316 +
81317 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81318 + feature on a per file basis.
81319 +
81320 +endmenu
81321 +
81322 +menu "Miscellaneous hardening features"
81323 +
81324 +config PAX_MEMORY_SANITIZE
81325 + bool "Sanitize all freed memory"
81326 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81327 + depends on !HIBERNATION
81328 + help
81329 + By saying Y here the kernel will erase memory pages as soon as they
81330 + are freed. This in turn reduces the lifetime of data stored in the
81331 + pages, making it less likely that sensitive information such as
81332 + passwords, cryptographic secrets, etc stay in memory for too long.
81333 +
81334 + This is especially useful for programs whose runtime is short, long
81335 + lived processes and the kernel itself benefit from this as long as
81336 + they operate on whole memory pages and ensure timely freeing of pages
81337 + that may hold sensitive information.
81338 +
81339 + The tradeoff is performance impact, on a single CPU system kernel
81340 + compilation sees a 3% slowdown, other systems and workloads may vary
81341 + and you are advised to test this feature on your expected workload
81342 + before deploying it.
81343 +
81344 + Note that this feature does not protect data stored in live pages,
81345 + e.g., process memory swapped to disk may stay there for a long time.
81346 +
81347 +config PAX_MEMORY_STACKLEAK
81348 + bool "Sanitize kernel stack"
81349 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81350 + depends on X86
81351 + help
81352 + By saying Y here the kernel will erase the kernel stack before it
81353 + returns from a system call. This in turn reduces the information
81354 + that a kernel stack leak bug can reveal.
81355 +
81356 + Note that such a bug can still leak information that was put on
81357 + the stack by the current system call (the one eventually triggering
81358 + the bug) but traces of earlier system calls on the kernel stack
81359 + cannot leak anymore.
81360 +
81361 + The tradeoff is performance impact: on a single CPU system kernel
81362 + compilation sees a 1% slowdown, other systems and workloads may vary
81363 + and you are advised to test this feature on your expected workload
81364 + before deploying it.
81365 +
81366 + Note that the full feature requires a gcc with plugin support,
81367 + i.e., gcc 4.5 or newer. You may need to install the supporting
81368 + headers explicitly in addition to the normal gcc package. Using
81369 + older gcc versions means that functions with large enough stack
81370 + frames may leave uninitialized memory behind that may be exposed
81371 + to a later syscall leaking the stack.
81372 +
81373 +config PAX_MEMORY_UDEREF
81374 + bool "Prevent invalid userland pointer dereference"
81375 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81376 + depends on X86 && !UML_X86 && !XEN
81377 + select PAX_PER_CPU_PGD if X86_64
81378 + help
81379 + By saying Y here the kernel will be prevented from dereferencing
81380 + userland pointers in contexts where the kernel expects only kernel
81381 + pointers. This is both a useful runtime debugging feature and a
81382 + security measure that prevents exploiting a class of kernel bugs.
81383 +
81384 + The tradeoff is that some virtualization solutions may experience
81385 + a huge slowdown and therefore you should not enable this feature
81386 + for kernels meant to run in such environments. Whether a given VM
81387 + solution is affected or not is best determined by simply trying it
81388 + out, the performance impact will be obvious right on boot as this
81389 + mechanism engages from very early on. A good rule of thumb is that
81390 + VMs running on CPUs without hardware virtualization support (i.e.,
81391 + the majority of IA-32 CPUs) will likely experience the slowdown.
81392 +
81393 +config PAX_REFCOUNT
81394 + bool "Prevent various kernel object reference counter overflows"
81395 + default y if GRKERNSEC_CONFIG_AUTO
81396 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81397 + help
81398 + By saying Y here the kernel will detect and prevent overflowing
81399 + various (but not all) kinds of object reference counters. Such
81400 + overflows can normally occur due to bugs only and are often, if
81401 + not always, exploitable.
81402 +
81403 + The tradeoff is that data structures protected by an overflowed
81404 + refcount will never be freed and therefore will leak memory. Note
81405 + that this leak also happens even without this protection but in
81406 + that case the overflow can eventually trigger the freeing of the
81407 + data structure while it is still being used elsewhere, resulting
81408 + in the exploitable situation that this feature prevents.
81409 +
81410 + Since this has a negligible performance impact, you should enable
81411 + this feature.
81412 +
81413 +config PAX_USERCOPY
81414 + bool "Harden heap object copies between kernel and userland"
81415 + default y if GRKERNSEC_CONFIG_AUTO
81416 + depends on X86 || PPC || SPARC || ARM
81417 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81418 + select PAX_USERCOPY_SLABS
81419 + help
81420 + By saying Y here the kernel will enforce the size of heap objects
81421 + when they are copied in either direction between the kernel and
81422 + userland, even if only a part of the heap object is copied.
81423 +
81424 + Specifically, this checking prevents information leaking from the
81425 + kernel heap during kernel to userland copies (if the kernel heap
81426 + object is otherwise fully initialized) and prevents kernel heap
81427 + overflows during userland to kernel copies.
81428 +
81429 + Note that the current implementation provides the strictest bounds
81430 + checks for the SLUB allocator.
81431 +
81432 + Enabling this option also enables per-slab cache protection against
81433 + data in a given cache being copied into/out of via userland
81434 + accessors. Though the whitelist of regions will be reduced over
81435 + time, it notably protects important data structures like task structs.
81436 +
81437 + If frame pointers are enabled on x86, this option will also restrict
81438 + copies into and out of the kernel stack to local variables within a
81439 + single frame.
81440 +
81441 + Since this has a negligible performance impact, you should enable
81442 + this feature.
81443 +
81444 +config PAX_SIZE_OVERFLOW
81445 + bool "Prevent various integer overflows in function size parameters"
81446 + default y if GRKERNSEC_CONFIG_AUTO
81447 + depends on X86
81448 + help
81449 + By saying Y here the kernel recomputes expressions of function
81450 + arguments marked by a size_overflow attribute with double integer
81451 + precision (DImode/TImode for 32/64 bit integer types).
81452 +
81453 + The recomputed argument is checked against TYPE_MAX and an event
81454 + is logged on overflow and the triggering process is killed.
81455 +
81456 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81457 +
81458 + Note that the implementation requires a gcc with plugin support,
81459 + i.e., gcc 4.5 or newer. You may need to install the supporting
81460 + headers explicitly in addition to the normal gcc package.
81461 +
81462 +config PAX_LATENT_ENTROPY
81463 + bool "Generate some entropy during boot"
81464 + default y if GRKERNSEC_CONFIG_AUTO
81465 + help
81466 + By saying Y here the kernel will instrument early boot code to
81467 + extract some entropy from both original and artificially created
81468 + program state. This will help especially embedded systems where
81469 + there is little 'natural' source of entropy normally. The cost
81470 + is some slowdown of the boot process.
81471 +
81472 + Note that the implementation requires a gcc with plugin support,
81473 + i.e., gcc 4.5 or newer. You may need to install the supporting
81474 + headers explicitly in addition to the normal gcc package.
81475 +
81476 + Note that entropy extracted this way is not cryptographically
81477 + secure!
81478 +
81479 +endmenu
81480 +
81481 +endmenu
81482 +
81483 +source grsecurity/Kconfig
81484 +
81485 +endmenu
81486 +
81487 +endmenu
81488 +
81489 source security/keys/Kconfig
81490
81491 config SECURITY_DMESG_RESTRICT
81492 @@ -103,7 +993,7 @@ config INTEL_TXT
81493 config LSM_MMAP_MIN_ADDR
81494 int "Low address space for LSM to protect from user allocation"
81495 depends on SECURITY && SECURITY_SELINUX
81496 - default 32768 if ARM
81497 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81498 default 65536
81499 help
81500 This is the portion of low virtual memory which should be protected
81501 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81502 index 8ea39aa..8569ac5 100644
81503 --- a/security/apparmor/lsm.c
81504 +++ b/security/apparmor/lsm.c
81505 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81506 return error;
81507 }
81508
81509 -static struct security_operations apparmor_ops = {
81510 +static struct security_operations apparmor_ops __read_only = {
81511 .name = "apparmor",
81512
81513 .ptrace_access_check = apparmor_ptrace_access_check,
81514 diff --git a/security/commoncap.c b/security/commoncap.c
81515 index 6dbae46..d5611fd 100644
81516 --- a/security/commoncap.c
81517 +++ b/security/commoncap.c
81518 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81519 return 0;
81520 }
81521
81522 +/* returns:
81523 + 1 for suid privilege
81524 + 2 for sgid privilege
81525 + 3 for fscap privilege
81526 +*/
81527 +int is_privileged_binary(const struct dentry *dentry)
81528 +{
81529 + struct cpu_vfs_cap_data capdata;
81530 + struct inode *inode = dentry->d_inode;
81531 +
81532 + if (!inode || S_ISDIR(inode->i_mode))
81533 + return 0;
81534 +
81535 + if (inode->i_mode & S_ISUID)
81536 + return 1;
81537 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81538 + return 2;
81539 +
81540 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81541 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81542 + return 3;
81543 + }
81544 +
81545 + return 0;
81546 +}
81547 +
81548 /*
81549 * Attempt to get the on-exec apply capability sets for an executable file from
81550 * its xattrs and, if present, apply them to the proposed credentials being
81551 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81552 const struct cred *cred = current_cred();
81553 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81554
81555 + if (gr_acl_enable_at_secure())
81556 + return 1;
81557 +
81558 if (!uid_eq(cred->uid, root_uid)) {
81559 if (bprm->cap_effective)
81560 return 1;
81561 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81562 index e7c99fd..5b2fa24 100644
81563 --- a/security/integrity/ima/ima.h
81564 +++ b/security/integrity/ima/ima.h
81565 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81566 extern spinlock_t ima_queue_lock;
81567
81568 struct ima_h_table {
81569 - atomic_long_t len; /* number of stored measurements in the list */
81570 - atomic_long_t violations;
81571 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81572 + atomic_long_unchecked_t violations;
81573 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81574 };
81575 extern struct ima_h_table ima_htable;
81576 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81577 index 032ff03..c428a74 100644
81578 --- a/security/integrity/ima/ima_api.c
81579 +++ b/security/integrity/ima/ima_api.c
81580 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81581 int result;
81582
81583 /* can overflow, only indicator */
81584 - atomic_long_inc(&ima_htable.violations);
81585 + atomic_long_inc_unchecked(&ima_htable.violations);
81586
81587 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81588 if (!entry) {
81589 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81590 index 38477c9..87a60c7 100644
81591 --- a/security/integrity/ima/ima_fs.c
81592 +++ b/security/integrity/ima/ima_fs.c
81593 @@ -28,12 +28,12 @@
81594 static int valid_policy = 1;
81595 #define TMPBUFLEN 12
81596 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81597 - loff_t *ppos, atomic_long_t *val)
81598 + loff_t *ppos, atomic_long_unchecked_t *val)
81599 {
81600 char tmpbuf[TMPBUFLEN];
81601 ssize_t len;
81602
81603 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81604 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81605 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81606 }
81607
81608 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81609 index 55a6271..ad829c3 100644
81610 --- a/security/integrity/ima/ima_queue.c
81611 +++ b/security/integrity/ima/ima_queue.c
81612 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81613 INIT_LIST_HEAD(&qe->later);
81614 list_add_tail_rcu(&qe->later, &ima_measurements);
81615
81616 - atomic_long_inc(&ima_htable.len);
81617 + atomic_long_inc_unchecked(&ima_htable.len);
81618 key = ima_hash_key(entry->digest);
81619 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81620 return 0;
81621 diff --git a/security/keys/compat.c b/security/keys/compat.c
81622 index 1c26176..64a1ba2 100644
81623 --- a/security/keys/compat.c
81624 +++ b/security/keys/compat.c
81625 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81626 if (ret == 0)
81627 goto no_payload_free;
81628
81629 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81630 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81631
81632 if (iov != iovstack)
81633 kfree(iov);
81634 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81635 index 3364fbf..1f10f31 100644
81636 --- a/security/keys/keyctl.c
81637 +++ b/security/keys/keyctl.c
81638 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81639 /*
81640 * Copy the iovec data from userspace
81641 */
81642 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81643 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81644 unsigned ioc)
81645 {
81646 for (; ioc > 0; ioc--) {
81647 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81648 * If successful, 0 will be returned.
81649 */
81650 long keyctl_instantiate_key_common(key_serial_t id,
81651 - const struct iovec *payload_iov,
81652 + const struct iovec __user *payload_iov,
81653 unsigned ioc,
81654 size_t plen,
81655 key_serial_t ringid)
81656 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81657 [0].iov_len = plen
81658 };
81659
81660 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81661 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81662 }
81663
81664 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81665 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81666 if (ret == 0)
81667 goto no_payload_free;
81668
81669 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81670 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81671
81672 if (iov != iovstack)
81673 kfree(iov);
81674 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81675 index 81e7852..2b2ecc3 100644
81676 --- a/security/keys/keyring.c
81677 +++ b/security/keys/keyring.c
81678 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81679 ret = -EFAULT;
81680
81681 for (loop = 0; loop < klist->nkeys; loop++) {
81682 + key_serial_t serial;
81683 key = rcu_deref_link_locked(klist, loop,
81684 keyring);
81685 + serial = key->serial;
81686
81687 tmp = sizeof(key_serial_t);
81688 if (tmp > buflen)
81689 tmp = buflen;
81690
81691 - if (copy_to_user(buffer,
81692 - &key->serial,
81693 - tmp) != 0)
81694 + if (copy_to_user(buffer, &serial, tmp))
81695 goto error;
81696
81697 buflen -= tmp;
81698 diff --git a/security/min_addr.c b/security/min_addr.c
81699 index f728728..6457a0c 100644
81700 --- a/security/min_addr.c
81701 +++ b/security/min_addr.c
81702 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81703 */
81704 static void update_mmap_min_addr(void)
81705 {
81706 +#ifndef SPARC
81707 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81708 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81709 mmap_min_addr = dac_mmap_min_addr;
81710 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81711 #else
81712 mmap_min_addr = dac_mmap_min_addr;
81713 #endif
81714 +#endif
81715 }
81716
81717 /*
81718 diff --git a/security/security.c b/security/security.c
81719 index 860aeb3..45765c0 100644
81720 --- a/security/security.c
81721 +++ b/security/security.c
81722 @@ -20,6 +20,7 @@
81723 #include <linux/ima.h>
81724 #include <linux/evm.h>
81725 #include <linux/fsnotify.h>
81726 +#include <linux/mm.h>
81727 #include <linux/mman.h>
81728 #include <linux/mount.h>
81729 #include <linux/personality.h>
81730 @@ -32,8 +33,8 @@
81731 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81732 CONFIG_DEFAULT_SECURITY;
81733
81734 -static struct security_operations *security_ops;
81735 -static struct security_operations default_security_ops = {
81736 +static struct security_operations *security_ops __read_only;
81737 +static struct security_operations default_security_ops __read_only = {
81738 .name = "default",
81739 };
81740
81741 @@ -74,7 +75,9 @@ int __init security_init(void)
81742
81743 void reset_security_ops(void)
81744 {
81745 + pax_open_kernel();
81746 security_ops = &default_security_ops;
81747 + pax_close_kernel();
81748 }
81749
81750 /* Save user chosen LSM */
81751 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81752 index 6c77f63..7496c76 100644
81753 --- a/security/selinux/hooks.c
81754 +++ b/security/selinux/hooks.c
81755 @@ -95,8 +95,6 @@
81756
81757 #define NUM_SEL_MNT_OPTS 5
81758
81759 -extern struct security_operations *security_ops;
81760 -
81761 /* SECMARK reference count */
81762 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81763
81764 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81765
81766 #endif
81767
81768 -static struct security_operations selinux_ops = {
81769 +static struct security_operations selinux_ops __read_only = {
81770 .name = "selinux",
81771
81772 .ptrace_access_check = selinux_ptrace_access_check,
81773 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81774 index 65f67cb..3f141ef 100644
81775 --- a/security/selinux/include/xfrm.h
81776 +++ b/security/selinux/include/xfrm.h
81777 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81778
81779 static inline void selinux_xfrm_notify_policyload(void)
81780 {
81781 - atomic_inc(&flow_cache_genid);
81782 + atomic_inc_unchecked(&flow_cache_genid);
81783 rt_genid_bump(&init_net);
81784 }
81785 #else
81786 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81787 index 8221514..5c4775f 100644
81788 --- a/security/smack/smack_lsm.c
81789 +++ b/security/smack/smack_lsm.c
81790 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81791 return 0;
81792 }
81793
81794 -struct security_operations smack_ops = {
81795 +struct security_operations smack_ops __read_only = {
81796 .name = "smack",
81797
81798 .ptrace_access_check = smack_ptrace_access_check,
81799 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81800 index c2d04a5..e6a1aeb 100644
81801 --- a/security/tomoyo/tomoyo.c
81802 +++ b/security/tomoyo/tomoyo.c
81803 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81804 * tomoyo_security_ops is a "struct security_operations" which is used for
81805 * registering TOMOYO.
81806 */
81807 -static struct security_operations tomoyo_security_ops = {
81808 +static struct security_operations tomoyo_security_ops __read_only = {
81809 .name = "tomoyo",
81810 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81811 .cred_prepare = tomoyo_cred_prepare,
81812 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81813 index 51d6709..1f3dbe2 100644
81814 --- a/security/yama/Kconfig
81815 +++ b/security/yama/Kconfig
81816 @@ -1,6 +1,6 @@
81817 config SECURITY_YAMA
81818 bool "Yama support"
81819 - depends on SECURITY
81820 + depends on SECURITY && !GRKERNSEC
81821 select SECURITYFS
81822 select SECURITY_PATH
81823 default n
81824 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81825 index 4cedc69..e59d8a3 100644
81826 --- a/sound/aoa/codecs/onyx.c
81827 +++ b/sound/aoa/codecs/onyx.c
81828 @@ -54,7 +54,7 @@ struct onyx {
81829 spdif_locked:1,
81830 analog_locked:1,
81831 original_mute:2;
81832 - int open_count;
81833 + local_t open_count;
81834 struct codec_info *codec_info;
81835
81836 /* mutex serializes concurrent access to the device
81837 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81838 struct onyx *onyx = cii->codec_data;
81839
81840 mutex_lock(&onyx->mutex);
81841 - onyx->open_count++;
81842 + local_inc(&onyx->open_count);
81843 mutex_unlock(&onyx->mutex);
81844
81845 return 0;
81846 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81847 struct onyx *onyx = cii->codec_data;
81848
81849 mutex_lock(&onyx->mutex);
81850 - onyx->open_count--;
81851 - if (!onyx->open_count)
81852 + if (local_dec_and_test(&onyx->open_count))
81853 onyx->spdif_locked = onyx->analog_locked = 0;
81854 mutex_unlock(&onyx->mutex);
81855
81856 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81857 index ffd2025..df062c9 100644
81858 --- a/sound/aoa/codecs/onyx.h
81859 +++ b/sound/aoa/codecs/onyx.h
81860 @@ -11,6 +11,7 @@
81861 #include <linux/i2c.h>
81862 #include <asm/pmac_low_i2c.h>
81863 #include <asm/prom.h>
81864 +#include <asm/local.h>
81865
81866 /* PCM3052 register definitions */
81867
81868 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81869 index 4c1cc51..16040040 100644
81870 --- a/sound/core/oss/pcm_oss.c
81871 +++ b/sound/core/oss/pcm_oss.c
81872 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81873 if (in_kernel) {
81874 mm_segment_t fs;
81875 fs = snd_enter_user();
81876 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81877 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81878 snd_leave_user(fs);
81879 } else {
81880 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81881 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81882 }
81883 if (ret != -EPIPE && ret != -ESTRPIPE)
81884 break;
81885 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81886 if (in_kernel) {
81887 mm_segment_t fs;
81888 fs = snd_enter_user();
81889 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81890 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81891 snd_leave_user(fs);
81892 } else {
81893 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81894 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81895 }
81896 if (ret == -EPIPE) {
81897 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81898 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81899 struct snd_pcm_plugin_channel *channels;
81900 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81901 if (!in_kernel) {
81902 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81903 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81904 return -EFAULT;
81905 buf = runtime->oss.buffer;
81906 }
81907 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81908 }
81909 } else {
81910 tmp = snd_pcm_oss_write2(substream,
81911 - (const char __force *)buf,
81912 + (const char __force_kernel *)buf,
81913 runtime->oss.period_bytes, 0);
81914 if (tmp <= 0)
81915 goto err;
81916 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81917 struct snd_pcm_runtime *runtime = substream->runtime;
81918 snd_pcm_sframes_t frames, frames1;
81919 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81920 - char __user *final_dst = (char __force __user *)buf;
81921 + char __user *final_dst = (char __force_user *)buf;
81922 if (runtime->oss.plugin_first) {
81923 struct snd_pcm_plugin_channel *channels;
81924 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81925 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81926 xfer += tmp;
81927 runtime->oss.buffer_used -= tmp;
81928 } else {
81929 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81930 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81931 runtime->oss.period_bytes, 0);
81932 if (tmp <= 0)
81933 goto err;
81934 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81935 size1);
81936 size1 /= runtime->channels; /* frames */
81937 fs = snd_enter_user();
81938 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81939 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81940 snd_leave_user(fs);
81941 }
81942 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81943 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81944 index 91cdf94..4085161 100644
81945 --- a/sound/core/pcm_compat.c
81946 +++ b/sound/core/pcm_compat.c
81947 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81948 int err;
81949
81950 fs = snd_enter_user();
81951 - err = snd_pcm_delay(substream, &delay);
81952 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81953 snd_leave_user(fs);
81954 if (err < 0)
81955 return err;
81956 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81957 index bf3bf43..3826cbc 100644
81958 --- a/sound/core/pcm_native.c
81959 +++ b/sound/core/pcm_native.c
81960 @@ -2803,11 +2803,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81961 switch (substream->stream) {
81962 case SNDRV_PCM_STREAM_PLAYBACK:
81963 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81964 - (void __user *)arg);
81965 + (void __force_user *)arg);
81966 break;
81967 case SNDRV_PCM_STREAM_CAPTURE:
81968 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81969 - (void __user *)arg);
81970 + (void __force_user *)arg);
81971 break;
81972 default:
81973 result = -EINVAL;
81974 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81975 index 5cf8d65..912a79c 100644
81976 --- a/sound/core/seq/seq_device.c
81977 +++ b/sound/core/seq/seq_device.c
81978 @@ -64,7 +64,7 @@ struct ops_list {
81979 int argsize; /* argument size */
81980
81981 /* operators */
81982 - struct snd_seq_dev_ops ops;
81983 + struct snd_seq_dev_ops *ops;
81984
81985 /* registred devices */
81986 struct list_head dev_list; /* list of devices */
81987 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81988
81989 mutex_lock(&ops->reg_mutex);
81990 /* copy driver operators */
81991 - ops->ops = *entry;
81992 + ops->ops = entry;
81993 ops->driver |= DRIVER_LOADED;
81994 ops->argsize = argsize;
81995
81996 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81997 dev->name, ops->id, ops->argsize, dev->argsize);
81998 return -EINVAL;
81999 }
82000 - if (ops->ops.init_device(dev) >= 0) {
82001 + if (ops->ops->init_device(dev) >= 0) {
82002 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
82003 ops->num_init_devices++;
82004 } else {
82005 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
82006 dev->name, ops->id, ops->argsize, dev->argsize);
82007 return -EINVAL;
82008 }
82009 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
82010 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
82011 dev->status = SNDRV_SEQ_DEVICE_FREE;
82012 dev->driver_data = NULL;
82013 ops->num_init_devices--;
82014 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
82015 index 2d5514b..3afae9c 100644
82016 --- a/sound/drivers/mts64.c
82017 +++ b/sound/drivers/mts64.c
82018 @@ -29,6 +29,7 @@
82019 #include <sound/initval.h>
82020 #include <sound/rawmidi.h>
82021 #include <sound/control.h>
82022 +#include <asm/local.h>
82023
82024 #define CARD_NAME "Miditerminal 4140"
82025 #define DRIVER_NAME "MTS64"
82026 @@ -67,7 +68,7 @@ struct mts64 {
82027 struct pardevice *pardev;
82028 int pardev_claimed;
82029
82030 - int open_count;
82031 + local_t open_count;
82032 int current_midi_output_port;
82033 int current_midi_input_port;
82034 u8 mode[MTS64_NUM_INPUT_PORTS];
82035 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82036 {
82037 struct mts64 *mts = substream->rmidi->private_data;
82038
82039 - if (mts->open_count == 0) {
82040 + if (local_read(&mts->open_count) == 0) {
82041 /* We don't need a spinlock here, because this is just called
82042 if the device has not been opened before.
82043 So there aren't any IRQs from the device */
82044 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82045
82046 msleep(50);
82047 }
82048 - ++(mts->open_count);
82049 + local_inc(&mts->open_count);
82050
82051 return 0;
82052 }
82053 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82054 struct mts64 *mts = substream->rmidi->private_data;
82055 unsigned long flags;
82056
82057 - --(mts->open_count);
82058 - if (mts->open_count == 0) {
82059 + if (local_dec_return(&mts->open_count) == 0) {
82060 /* We need the spinlock_irqsave here because we can still
82061 have IRQs at this point */
82062 spin_lock_irqsave(&mts->lock, flags);
82063 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82064
82065 msleep(500);
82066
82067 - } else if (mts->open_count < 0)
82068 - mts->open_count = 0;
82069 + } else if (local_read(&mts->open_count) < 0)
82070 + local_set(&mts->open_count, 0);
82071
82072 return 0;
82073 }
82074 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82075 index b953fb4..1999c01 100644
82076 --- a/sound/drivers/opl4/opl4_lib.c
82077 +++ b/sound/drivers/opl4/opl4_lib.c
82078 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82079 MODULE_DESCRIPTION("OPL4 driver");
82080 MODULE_LICENSE("GPL");
82081
82082 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82083 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82084 {
82085 int timeout = 10;
82086 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82087 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82088 index 8364855..59f2e2b 100644
82089 --- a/sound/drivers/portman2x4.c
82090 +++ b/sound/drivers/portman2x4.c
82091 @@ -48,6 +48,7 @@
82092 #include <sound/initval.h>
82093 #include <sound/rawmidi.h>
82094 #include <sound/control.h>
82095 +#include <asm/local.h>
82096
82097 #define CARD_NAME "Portman 2x4"
82098 #define DRIVER_NAME "portman"
82099 @@ -85,7 +86,7 @@ struct portman {
82100 struct pardevice *pardev;
82101 int pardev_claimed;
82102
82103 - int open_count;
82104 + local_t open_count;
82105 int mode[PORTMAN_NUM_INPUT_PORTS];
82106 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82107 };
82108 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82109 index ea995af..f1bfa37 100644
82110 --- a/sound/firewire/amdtp.c
82111 +++ b/sound/firewire/amdtp.c
82112 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82113 ptr = s->pcm_buffer_pointer + data_blocks;
82114 if (ptr >= pcm->runtime->buffer_size)
82115 ptr -= pcm->runtime->buffer_size;
82116 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82117 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82118
82119 s->pcm_period_pointer += data_blocks;
82120 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82121 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82122 */
82123 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82124 {
82125 - ACCESS_ONCE(s->source_node_id_field) =
82126 + ACCESS_ONCE_RW(s->source_node_id_field) =
82127 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82128 }
82129 EXPORT_SYMBOL(amdtp_out_stream_update);
82130 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82131 index b680c5e..061b7a0 100644
82132 --- a/sound/firewire/amdtp.h
82133 +++ b/sound/firewire/amdtp.h
82134 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82135 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82136 struct snd_pcm_substream *pcm)
82137 {
82138 - ACCESS_ONCE(s->pcm) = pcm;
82139 + ACCESS_ONCE_RW(s->pcm) = pcm;
82140 }
82141
82142 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82143 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82144 index d428ffe..751ef78 100644
82145 --- a/sound/firewire/isight.c
82146 +++ b/sound/firewire/isight.c
82147 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82148 ptr += count;
82149 if (ptr >= runtime->buffer_size)
82150 ptr -= runtime->buffer_size;
82151 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82152 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82153
82154 isight->period_counter += count;
82155 if (isight->period_counter >= runtime->period_size) {
82156 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82157 if (err < 0)
82158 return err;
82159
82160 - ACCESS_ONCE(isight->pcm_active) = true;
82161 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82162
82163 return 0;
82164 }
82165 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82166 {
82167 struct isight *isight = substream->private_data;
82168
82169 - ACCESS_ONCE(isight->pcm_active) = false;
82170 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82171
82172 mutex_lock(&isight->mutex);
82173 isight_stop_streaming(isight);
82174 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82175
82176 switch (cmd) {
82177 case SNDRV_PCM_TRIGGER_START:
82178 - ACCESS_ONCE(isight->pcm_running) = true;
82179 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82180 break;
82181 case SNDRV_PCM_TRIGGER_STOP:
82182 - ACCESS_ONCE(isight->pcm_running) = false;
82183 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82184 break;
82185 default:
82186 return -EINVAL;
82187 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82188 index 7bd5e33..1fcab12 100644
82189 --- a/sound/isa/cmi8330.c
82190 +++ b/sound/isa/cmi8330.c
82191 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82192
82193 struct snd_pcm *pcm;
82194 struct snd_cmi8330_stream {
82195 - struct snd_pcm_ops ops;
82196 + snd_pcm_ops_no_const ops;
82197 snd_pcm_open_callback_t open;
82198 void *private_data; /* sb or wss */
82199 } streams[2];
82200 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82201 index b2b3c01..e1c1e1f 100644
82202 --- a/sound/oss/sb_audio.c
82203 +++ b/sound/oss/sb_audio.c
82204 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82205 buf16 = (signed short *)(localbuf + localoffs);
82206 while (c)
82207 {
82208 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82209 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82210 if (copy_from_user(lbuf8,
82211 userbuf+useroffs + p,
82212 locallen))
82213 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82214 index 7d8803a..559f8d0 100644
82215 --- a/sound/oss/swarm_cs4297a.c
82216 +++ b/sound/oss/swarm_cs4297a.c
82217 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82218 {
82219 struct cs4297a_state *s;
82220 u32 pwr, id;
82221 - mm_segment_t fs;
82222 int rval;
82223 #ifndef CONFIG_BCM_CS4297A_CSWARM
82224 u64 cfg;
82225 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82226 if (!rval) {
82227 char *sb1250_duart_present;
82228
82229 +#if 0
82230 + mm_segment_t fs;
82231 fs = get_fs();
82232 set_fs(KERNEL_DS);
82233 -#if 0
82234 val = SOUND_MASK_LINE;
82235 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82236 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82237 val = initvol[i].vol;
82238 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82239 }
82240 + set_fs(fs);
82241 // cs4297a_write_ac97(s, 0x18, 0x0808);
82242 #else
82243 // cs4297a_write_ac97(s, 0x5e, 0x180);
82244 cs4297a_write_ac97(s, 0x02, 0x0808);
82245 cs4297a_write_ac97(s, 0x18, 0x0808);
82246 #endif
82247 - set_fs(fs);
82248
82249 list_add(&s->list, &cs4297a_devs);
82250
82251 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82252 index e5a7e19..4049063 100644
82253 --- a/sound/pci/hda/hda_codec.h
82254 +++ b/sound/pci/hda/hda_codec.h
82255 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82256 /* notify power-up/down from codec to controller */
82257 void (*pm_notify)(struct hda_bus *bus);
82258 #endif
82259 -};
82260 +} __no_const;
82261
82262 /* template to pass to the bus constructor */
82263 struct hda_bus_template {
82264 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82265 #endif
82266 void (*reboot_notify)(struct hda_codec *codec);
82267 };
82268 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82269
82270 /* record for amp information cache */
82271 struct hda_cache_head {
82272 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82273 struct snd_pcm_substream *substream);
82274 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82275 struct snd_pcm_substream *substream);
82276 -};
82277 +} __no_const;
82278
82279 /* PCM information for each substream */
82280 struct hda_pcm_stream {
82281 @@ -802,7 +803,7 @@ struct hda_codec {
82282 const char *modelname; /* model name for preset */
82283
82284 /* set by patch */
82285 - struct hda_codec_ops patch_ops;
82286 + hda_codec_ops_no_const patch_ops;
82287
82288 /* PCM to create, set by patch_ops.build_pcms callback */
82289 unsigned int num_pcms;
82290 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82291 index 0da778a..bc38b84 100644
82292 --- a/sound/pci/ice1712/ice1712.h
82293 +++ b/sound/pci/ice1712/ice1712.h
82294 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82295 unsigned int mask_flags; /* total mask bits */
82296 struct snd_akm4xxx_ops {
82297 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82298 - } ops;
82299 + } __no_const ops;
82300 };
82301
82302 struct snd_ice1712_spdif {
82303 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82304 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82305 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82306 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82307 - } ops;
82308 + } __no_const ops;
82309 };
82310
82311
82312 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82313 index bddc405..2c0733c 100644
82314 --- a/sound/pci/ymfpci/ymfpci.h
82315 +++ b/sound/pci/ymfpci/ymfpci.h
82316 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82317 spinlock_t reg_lock;
82318 spinlock_t voice_lock;
82319 wait_queue_head_t interrupt_sleep;
82320 - atomic_t interrupt_sleep_count;
82321 + atomic_unchecked_t interrupt_sleep_count;
82322 struct snd_info_entry *proc_entry;
82323 const struct firmware *dsp_microcode;
82324 const struct firmware *controller_microcode;
82325 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82326 index 62b2363..ee77972 100644
82327 --- a/sound/pci/ymfpci/ymfpci_main.c
82328 +++ b/sound/pci/ymfpci/ymfpci_main.c
82329 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82330 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82331 break;
82332 }
82333 - if (atomic_read(&chip->interrupt_sleep_count)) {
82334 - atomic_set(&chip->interrupt_sleep_count, 0);
82335 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82336 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82337 wake_up(&chip->interrupt_sleep);
82338 }
82339 __end:
82340 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82341 continue;
82342 init_waitqueue_entry(&wait, current);
82343 add_wait_queue(&chip->interrupt_sleep, &wait);
82344 - atomic_inc(&chip->interrupt_sleep_count);
82345 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82346 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82347 remove_wait_queue(&chip->interrupt_sleep, &wait);
82348 }
82349 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82350 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82351 spin_unlock(&chip->reg_lock);
82352
82353 - if (atomic_read(&chip->interrupt_sleep_count)) {
82354 - atomic_set(&chip->interrupt_sleep_count, 0);
82355 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82356 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82357 wake_up(&chip->interrupt_sleep);
82358 }
82359 }
82360 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82361 spin_lock_init(&chip->reg_lock);
82362 spin_lock_init(&chip->voice_lock);
82363 init_waitqueue_head(&chip->interrupt_sleep);
82364 - atomic_set(&chip->interrupt_sleep_count, 0);
82365 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82366 chip->card = card;
82367 chip->pci = pci;
82368 chip->irq = -1;
82369 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82370 new file mode 100644
82371 index 0000000..50f2f2f
82372 --- /dev/null
82373 +++ b/tools/gcc/.gitignore
82374 @@ -0,0 +1 @@
82375 +size_overflow_hash.h
82376 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82377 new file mode 100644
82378 index 0000000..1d09b7e
82379 --- /dev/null
82380 +++ b/tools/gcc/Makefile
82381 @@ -0,0 +1,43 @@
82382 +#CC := gcc
82383 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82384 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82385 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82386 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82387 +
82388 +ifeq ($(PLUGINCC),$(HOSTCC))
82389 +HOSTLIBS := hostlibs
82390 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82391 +else
82392 +HOSTLIBS := hostcxxlibs
82393 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82394 +endif
82395 +
82396 +$(HOSTLIBS)-y := constify_plugin.so
82397 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82398 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82399 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82400 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82401 +$(HOSTLIBS)-y += colorize_plugin.so
82402 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82403 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82404 +
82405 +always := $($(HOSTLIBS)-y)
82406 +
82407 +constify_plugin-objs := constify_plugin.o
82408 +stackleak_plugin-objs := stackleak_plugin.o
82409 +kallocstat_plugin-objs := kallocstat_plugin.o
82410 +kernexec_plugin-objs := kernexec_plugin.o
82411 +checker_plugin-objs := checker_plugin.o
82412 +colorize_plugin-objs := colorize_plugin.o
82413 +size_overflow_plugin-objs := size_overflow_plugin.o
82414 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82415 +
82416 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82417 +
82418 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82419 + cmd_build_size_overflow_hash = \
82420 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82421 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82422 + $(call if_changed,build_size_overflow_hash)
82423 +
82424 +targets += size_overflow_hash.h
82425 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82426 new file mode 100644
82427 index 0000000..d41b5af
82428 --- /dev/null
82429 +++ b/tools/gcc/checker_plugin.c
82430 @@ -0,0 +1,171 @@
82431 +/*
82432 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82433 + * Licensed under the GPL v2
82434 + *
82435 + * Note: the choice of the license means that the compilation process is
82436 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82437 + * but for the kernel it doesn't matter since it doesn't link against
82438 + * any of the gcc libraries
82439 + *
82440 + * gcc plugin to implement various sparse (source code checker) features
82441 + *
82442 + * TODO:
82443 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82444 + *
82445 + * BUGS:
82446 + * - none known
82447 + */
82448 +#include "gcc-plugin.h"
82449 +#include "config.h"
82450 +#include "system.h"
82451 +#include "coretypes.h"
82452 +#include "tree.h"
82453 +#include "tree-pass.h"
82454 +#include "flags.h"
82455 +#include "intl.h"
82456 +#include "toplev.h"
82457 +#include "plugin.h"
82458 +//#include "expr.h" where are you...
82459 +#include "diagnostic.h"
82460 +#include "plugin-version.h"
82461 +#include "tm.h"
82462 +#include "function.h"
82463 +#include "basic-block.h"
82464 +#include "gimple.h"
82465 +#include "rtl.h"
82466 +#include "emit-rtl.h"
82467 +#include "tree-flow.h"
82468 +#include "target.h"
82469 +
82470 +extern void c_register_addr_space (const char *str, addr_space_t as);
82471 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82472 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82473 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82474 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82475 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82476 +
82477 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82478 +extern rtx emit_move_insn(rtx x, rtx y);
82479 +
82480 +int plugin_is_GPL_compatible;
82481 +
82482 +static struct plugin_info checker_plugin_info = {
82483 + .version = "201111150100",
82484 +};
82485 +
82486 +#define ADDR_SPACE_KERNEL 0
82487 +#define ADDR_SPACE_FORCE_KERNEL 1
82488 +#define ADDR_SPACE_USER 2
82489 +#define ADDR_SPACE_FORCE_USER 3
82490 +#define ADDR_SPACE_IOMEM 0
82491 +#define ADDR_SPACE_FORCE_IOMEM 0
82492 +#define ADDR_SPACE_PERCPU 0
82493 +#define ADDR_SPACE_FORCE_PERCPU 0
82494 +#define ADDR_SPACE_RCU 0
82495 +#define ADDR_SPACE_FORCE_RCU 0
82496 +
82497 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82498 +{
82499 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82500 +}
82501 +
82502 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82503 +{
82504 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82505 +}
82506 +
82507 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82508 +{
82509 + return default_addr_space_valid_pointer_mode(mode, as);
82510 +}
82511 +
82512 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82513 +{
82514 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82515 +}
82516 +
82517 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82518 +{
82519 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82520 +}
82521 +
82522 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82523 +{
82524 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82525 + return true;
82526 +
82527 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82528 + return true;
82529 +
82530 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82531 + return true;
82532 +
82533 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82534 + return true;
82535 +
82536 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82537 + return true;
82538 +
82539 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82540 + return true;
82541 +
82542 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82543 + return true;
82544 +
82545 + return subset == superset;
82546 +}
82547 +
82548 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82549 +{
82550 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82551 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82552 +
82553 + return op;
82554 +}
82555 +
82556 +static void register_checker_address_spaces(void *event_data, void *data)
82557 +{
82558 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82559 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82560 + c_register_addr_space("__user", ADDR_SPACE_USER);
82561 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82562 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82563 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82564 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82565 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82566 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82567 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82568 +
82569 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82570 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82571 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82572 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82573 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82574 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82575 + targetm.addr_space.convert = checker_addr_space_convert;
82576 +}
82577 +
82578 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82579 +{
82580 + const char * const plugin_name = plugin_info->base_name;
82581 + const int argc = plugin_info->argc;
82582 + const struct plugin_argument * const argv = plugin_info->argv;
82583 + int i;
82584 +
82585 + if (!plugin_default_version_check(version, &gcc_version)) {
82586 + error(G_("incompatible gcc/plugin versions"));
82587 + return 1;
82588 + }
82589 +
82590 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82591 +
82592 + for (i = 0; i < argc; ++i)
82593 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82594 +
82595 + if (TARGET_64BIT == 0)
82596 + return 0;
82597 +
82598 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82599 +
82600 + return 0;
82601 +}
82602 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82603 new file mode 100644
82604 index 0000000..846aeb0
82605 --- /dev/null
82606 +++ b/tools/gcc/colorize_plugin.c
82607 @@ -0,0 +1,148 @@
82608 +/*
82609 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82610 + * Licensed under the GPL v2
82611 + *
82612 + * Note: the choice of the license means that the compilation process is
82613 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82614 + * but for the kernel it doesn't matter since it doesn't link against
82615 + * any of the gcc libraries
82616 + *
82617 + * gcc plugin to colorize diagnostic output
82618 + *
82619 + */
82620 +
82621 +#include "gcc-plugin.h"
82622 +#include "config.h"
82623 +#include "system.h"
82624 +#include "coretypes.h"
82625 +#include "tree.h"
82626 +#include "tree-pass.h"
82627 +#include "flags.h"
82628 +#include "intl.h"
82629 +#include "toplev.h"
82630 +#include "plugin.h"
82631 +#include "diagnostic.h"
82632 +#include "plugin-version.h"
82633 +#include "tm.h"
82634 +
82635 +int plugin_is_GPL_compatible;
82636 +
82637 +static struct plugin_info colorize_plugin_info = {
82638 + .version = "201203092200",
82639 + .help = NULL,
82640 +};
82641 +
82642 +#define GREEN "\033[32m\033[2m"
82643 +#define LIGHTGREEN "\033[32m\033[1m"
82644 +#define YELLOW "\033[33m\033[2m"
82645 +#define LIGHTYELLOW "\033[33m\033[1m"
82646 +#define RED "\033[31m\033[2m"
82647 +#define LIGHTRED "\033[31m\033[1m"
82648 +#define BLUE "\033[34m\033[2m"
82649 +#define LIGHTBLUE "\033[34m\033[1m"
82650 +#define BRIGHT "\033[m\033[1m"
82651 +#define NORMAL "\033[m"
82652 +
82653 +static diagnostic_starter_fn old_starter;
82654 +static diagnostic_finalizer_fn old_finalizer;
82655 +
82656 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82657 +{
82658 + const char *color;
82659 + char *newprefix;
82660 +
82661 + switch (diagnostic->kind) {
82662 + case DK_NOTE:
82663 + color = LIGHTBLUE;
82664 + break;
82665 +
82666 + case DK_PEDWARN:
82667 + case DK_WARNING:
82668 + color = LIGHTYELLOW;
82669 + break;
82670 +
82671 + case DK_ERROR:
82672 + case DK_FATAL:
82673 + case DK_ICE:
82674 + case DK_PERMERROR:
82675 + case DK_SORRY:
82676 + color = LIGHTRED;
82677 + break;
82678 +
82679 + default:
82680 + color = NORMAL;
82681 + }
82682 +
82683 + old_starter(context, diagnostic);
82684 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82685 + return;
82686 + pp_destroy_prefix(context->printer);
82687 + pp_set_prefix(context->printer, newprefix);
82688 +}
82689 +
82690 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82691 +{
82692 + old_finalizer(context, diagnostic);
82693 +}
82694 +
82695 +static void colorize_arm(void)
82696 +{
82697 + old_starter = diagnostic_starter(global_dc);
82698 + old_finalizer = diagnostic_finalizer(global_dc);
82699 +
82700 + diagnostic_starter(global_dc) = start_colorize;
82701 + diagnostic_finalizer(global_dc) = finalize_colorize;
82702 +}
82703 +
82704 +static unsigned int execute_colorize_rearm(void)
82705 +{
82706 + if (diagnostic_starter(global_dc) == start_colorize)
82707 + return 0;
82708 +
82709 + colorize_arm();
82710 + return 0;
82711 +}
82712 +
82713 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82714 + .pass = {
82715 + .type = SIMPLE_IPA_PASS,
82716 + .name = "colorize_rearm",
82717 + .gate = NULL,
82718 + .execute = execute_colorize_rearm,
82719 + .sub = NULL,
82720 + .next = NULL,
82721 + .static_pass_number = 0,
82722 + .tv_id = TV_NONE,
82723 + .properties_required = 0,
82724 + .properties_provided = 0,
82725 + .properties_destroyed = 0,
82726 + .todo_flags_start = 0,
82727 + .todo_flags_finish = 0
82728 + }
82729 +};
82730 +
82731 +static void colorize_start_unit(void *gcc_data, void *user_data)
82732 +{
82733 + colorize_arm();
82734 +}
82735 +
82736 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82737 +{
82738 + const char * const plugin_name = plugin_info->base_name;
82739 + struct register_pass_info colorize_rearm_pass_info = {
82740 + .pass = &pass_ipa_colorize_rearm.pass,
82741 + .reference_pass_name = "*free_lang_data",
82742 + .ref_pass_instance_number = 1,
82743 + .pos_op = PASS_POS_INSERT_AFTER
82744 + };
82745 +
82746 + if (!plugin_default_version_check(version, &gcc_version)) {
82747 + error(G_("incompatible gcc/plugin versions"));
82748 + return 1;
82749 + }
82750 +
82751 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82752 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82753 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82754 + return 0;
82755 +}
82756 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82757 new file mode 100644
82758 index 0000000..92ed719
82759 --- /dev/null
82760 +++ b/tools/gcc/constify_plugin.c
82761 @@ -0,0 +1,331 @@
82762 +/*
82763 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82764 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82765 + * Licensed under the GPL v2, or (at your option) v3
82766 + *
82767 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82768 + *
82769 + * Homepage:
82770 + * http://www.grsecurity.net/~ephox/const_plugin/
82771 + *
82772 + * Usage:
82773 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82774 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82775 + */
82776 +
82777 +#include "gcc-plugin.h"
82778 +#include "config.h"
82779 +#include "system.h"
82780 +#include "coretypes.h"
82781 +#include "tree.h"
82782 +#include "tree-pass.h"
82783 +#include "flags.h"
82784 +#include "intl.h"
82785 +#include "toplev.h"
82786 +#include "plugin.h"
82787 +#include "diagnostic.h"
82788 +#include "plugin-version.h"
82789 +#include "tm.h"
82790 +#include "function.h"
82791 +#include "basic-block.h"
82792 +#include "gimple.h"
82793 +#include "rtl.h"
82794 +#include "emit-rtl.h"
82795 +#include "tree-flow.h"
82796 +
82797 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82798 +
82799 +int plugin_is_GPL_compatible;
82800 +
82801 +static struct plugin_info const_plugin_info = {
82802 + .version = "201205300030",
82803 + .help = "no-constify\tturn off constification\n",
82804 +};
82805 +
82806 +static void deconstify_tree(tree node);
82807 +
82808 +static void deconstify_type(tree type)
82809 +{
82810 + tree field;
82811 +
82812 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82813 + tree type = TREE_TYPE(field);
82814 +
82815 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82816 + continue;
82817 + if (!TYPE_READONLY(type))
82818 + continue;
82819 +
82820 + deconstify_tree(field);
82821 + }
82822 + TYPE_READONLY(type) = 0;
82823 + C_TYPE_FIELDS_READONLY(type) = 0;
82824 +}
82825 +
82826 +static void deconstify_tree(tree node)
82827 +{
82828 + tree old_type, new_type, field;
82829 +
82830 + old_type = TREE_TYPE(node);
82831 +
82832 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82833 +
82834 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82835 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82836 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82837 + DECL_FIELD_CONTEXT(field) = new_type;
82838 +
82839 + deconstify_type(new_type);
82840 +
82841 + TREE_READONLY(node) = 0;
82842 + TREE_TYPE(node) = new_type;
82843 +}
82844 +
82845 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82846 +{
82847 + tree type;
82848 +
82849 + *no_add_attrs = true;
82850 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82851 + error("%qE attribute does not apply to functions", name);
82852 + return NULL_TREE;
82853 + }
82854 +
82855 + if (TREE_CODE(*node) == VAR_DECL) {
82856 + error("%qE attribute does not apply to variables", name);
82857 + return NULL_TREE;
82858 + }
82859 +
82860 + if (TYPE_P(*node)) {
82861 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82862 + *no_add_attrs = false;
82863 + else
82864 + error("%qE attribute applies to struct and union types only", name);
82865 + return NULL_TREE;
82866 + }
82867 +
82868 + type = TREE_TYPE(*node);
82869 +
82870 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82871 + error("%qE attribute applies to struct and union types only", name);
82872 + return NULL_TREE;
82873 + }
82874 +
82875 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82876 + error("%qE attribute is already applied to the type", name);
82877 + return NULL_TREE;
82878 + }
82879 +
82880 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82881 + error("%qE attribute used on type that is not constified", name);
82882 + return NULL_TREE;
82883 + }
82884 +
82885 + if (TREE_CODE(*node) == TYPE_DECL) {
82886 + deconstify_tree(*node);
82887 + return NULL_TREE;
82888 + }
82889 +
82890 + return NULL_TREE;
82891 +}
82892 +
82893 +static void constify_type(tree type)
82894 +{
82895 + TYPE_READONLY(type) = 1;
82896 + C_TYPE_FIELDS_READONLY(type) = 1;
82897 +}
82898 +
82899 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82900 +{
82901 + *no_add_attrs = true;
82902 + if (!TYPE_P(*node)) {
82903 + error("%qE attribute applies to types only", name);
82904 + return NULL_TREE;
82905 + }
82906 +
82907 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82908 + error("%qE attribute applies to struct and union types only", name);
82909 + return NULL_TREE;
82910 + }
82911 +
82912 + *no_add_attrs = false;
82913 + constify_type(*node);
82914 + return NULL_TREE;
82915 +}
82916 +
82917 +static struct attribute_spec no_const_attr = {
82918 + .name = "no_const",
82919 + .min_length = 0,
82920 + .max_length = 0,
82921 + .decl_required = false,
82922 + .type_required = false,
82923 + .function_type_required = false,
82924 + .handler = handle_no_const_attribute,
82925 +#if BUILDING_GCC_VERSION >= 4007
82926 + .affects_type_identity = true
82927 +#endif
82928 +};
82929 +
82930 +static struct attribute_spec do_const_attr = {
82931 + .name = "do_const",
82932 + .min_length = 0,
82933 + .max_length = 0,
82934 + .decl_required = false,
82935 + .type_required = false,
82936 + .function_type_required = false,
82937 + .handler = handle_do_const_attribute,
82938 +#if BUILDING_GCC_VERSION >= 4007
82939 + .affects_type_identity = true
82940 +#endif
82941 +};
82942 +
82943 +static void register_attributes(void *event_data, void *data)
82944 +{
82945 + register_attribute(&no_const_attr);
82946 + register_attribute(&do_const_attr);
82947 +}
82948 +
82949 +static bool is_fptr(tree field)
82950 +{
82951 + tree ptr = TREE_TYPE(field);
82952 +
82953 + if (TREE_CODE(ptr) != POINTER_TYPE)
82954 + return false;
82955 +
82956 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82957 +}
82958 +
82959 +static bool walk_struct(tree node)
82960 +{
82961 + tree field;
82962 +
82963 + if (TYPE_FIELDS(node) == NULL_TREE)
82964 + return false;
82965 +
82966 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82967 + gcc_assert(!TYPE_READONLY(node));
82968 + deconstify_type(node);
82969 + return false;
82970 + }
82971 +
82972 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82973 + tree type = TREE_TYPE(field);
82974 + enum tree_code code = TREE_CODE(type);
82975 +
82976 + if (node == type)
82977 + return false;
82978 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82979 + if (!(walk_struct(type)))
82980 + return false;
82981 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82982 + return false;
82983 + }
82984 + return true;
82985 +}
82986 +
82987 +static void finish_type(void *event_data, void *data)
82988 +{
82989 + tree type = (tree)event_data;
82990 +
82991 + if (type == NULL_TREE || type == error_mark_node)
82992 + return;
82993 +
82994 + if (TYPE_READONLY(type))
82995 + return;
82996 +
82997 + if (walk_struct(type))
82998 + constify_type(type);
82999 +}
83000 +
83001 +static unsigned int check_local_variables(void);
83002 +
83003 +struct gimple_opt_pass pass_local_variable = {
83004 + {
83005 + .type = GIMPLE_PASS,
83006 + .name = "check_local_variables",
83007 + .gate = NULL,
83008 + .execute = check_local_variables,
83009 + .sub = NULL,
83010 + .next = NULL,
83011 + .static_pass_number = 0,
83012 + .tv_id = TV_NONE,
83013 + .properties_required = 0,
83014 + .properties_provided = 0,
83015 + .properties_destroyed = 0,
83016 + .todo_flags_start = 0,
83017 + .todo_flags_finish = 0
83018 + }
83019 +};
83020 +
83021 +static unsigned int check_local_variables(void)
83022 +{
83023 + tree var;
83024 + referenced_var_iterator rvi;
83025 +
83026 +#if BUILDING_GCC_VERSION == 4005
83027 + FOR_EACH_REFERENCED_VAR(var, rvi) {
83028 +#else
83029 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
83030 +#endif
83031 + tree type = TREE_TYPE(var);
83032 +
83033 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
83034 + continue;
83035 +
83036 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83037 + continue;
83038 +
83039 + if (!TYPE_READONLY(type))
83040 + continue;
83041 +
83042 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
83043 +// continue;
83044 +
83045 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
83046 +// continue;
83047 +
83048 + if (walk_struct(type)) {
83049 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83050 + return 1;
83051 + }
83052 + }
83053 + return 0;
83054 +}
83055 +
83056 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83057 +{
83058 + const char * const plugin_name = plugin_info->base_name;
83059 + const int argc = plugin_info->argc;
83060 + const struct plugin_argument * const argv = plugin_info->argv;
83061 + int i;
83062 + bool constify = true;
83063 +
83064 + struct register_pass_info local_variable_pass_info = {
83065 + .pass = &pass_local_variable.pass,
83066 + .reference_pass_name = "*referenced_vars",
83067 + .ref_pass_instance_number = 1,
83068 + .pos_op = PASS_POS_INSERT_AFTER
83069 + };
83070 +
83071 + if (!plugin_default_version_check(version, &gcc_version)) {
83072 + error(G_("incompatible gcc/plugin versions"));
83073 + return 1;
83074 + }
83075 +
83076 + for (i = 0; i < argc; ++i) {
83077 + if (!(strcmp(argv[i].key, "no-constify"))) {
83078 + constify = false;
83079 + continue;
83080 + }
83081 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83082 + }
83083 +
83084 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83085 + if (constify) {
83086 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83087 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83088 + }
83089 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83090 +
83091 + return 0;
83092 +}
83093 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83094 new file mode 100644
83095 index 0000000..02c6bec
83096 --- /dev/null
83097 +++ b/tools/gcc/generate_size_overflow_hash.sh
83098 @@ -0,0 +1,94 @@
83099 +#!/bin/bash
83100 +
83101 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83102 +
83103 +header1="size_overflow_hash.h"
83104 +database="size_overflow_hash.data"
83105 +n=65536
83106 +
83107 +usage() {
83108 +cat <<EOF
83109 +usage: $0 options
83110 +OPTIONS:
83111 + -h|--help help
83112 + -o header file
83113 + -d database file
83114 + -n hash array size
83115 +EOF
83116 + return 0
83117 +}
83118 +
83119 +while true
83120 +do
83121 + case "$1" in
83122 + -h|--help) usage && exit 0;;
83123 + -n) n=$2; shift 2;;
83124 + -o) header1="$2"; shift 2;;
83125 + -d) database="$2"; shift 2;;
83126 + --) shift 1; break ;;
83127 + *) break ;;
83128 + esac
83129 +done
83130 +
83131 +create_defines() {
83132 + for i in `seq 1 32`
83133 + do
83134 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83135 + done
83136 + echo >> "$header1"
83137 +}
83138 +
83139 +create_structs () {
83140 + rm -f "$header1"
83141 +
83142 + create_defines
83143 +
83144 + cat "$database" | while read data
83145 + do
83146 + data_array=($data)
83147 + struct_hash_name="${data_array[0]}"
83148 + funcn="${data_array[1]}"
83149 + params="${data_array[2]}"
83150 + next="${data_array[5]}"
83151 +
83152 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83153 +
83154 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83155 + echo -en "\t.param\t= " >> "$header1"
83156 + line=
83157 + for param_num in ${params//-/ };
83158 + do
83159 + line="${line}PARAM"$param_num"|"
83160 + done
83161 +
83162 + echo -e "${line%?},\n};\n" >> "$header1"
83163 + done
83164 +}
83165 +
83166 +create_headers () {
83167 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83168 +}
83169 +
83170 +create_array_elements () {
83171 + index=0
83172 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83173 + do
83174 + data_array=($data)
83175 + i="${data_array[3]}"
83176 + hash="${data_array[4]}"
83177 + while [[ $index -lt $i ]]
83178 + do
83179 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83180 + index=$(($index + 1))
83181 + done
83182 + index=$(($index + 1))
83183 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83184 + done
83185 + echo '};' >> $header1
83186 +}
83187 +
83188 +create_structs
83189 +create_headers
83190 +create_array_elements
83191 +
83192 +exit 0
83193 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83194 new file mode 100644
83195 index 0000000..a86e422
83196 --- /dev/null
83197 +++ b/tools/gcc/kallocstat_plugin.c
83198 @@ -0,0 +1,167 @@
83199 +/*
83200 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83201 + * Licensed under the GPL v2
83202 + *
83203 + * Note: the choice of the license means that the compilation process is
83204 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83205 + * but for the kernel it doesn't matter since it doesn't link against
83206 + * any of the gcc libraries
83207 + *
83208 + * gcc plugin to find the distribution of k*alloc sizes
83209 + *
83210 + * TODO:
83211 + *
83212 + * BUGS:
83213 + * - none known
83214 + */
83215 +#include "gcc-plugin.h"
83216 +#include "config.h"
83217 +#include "system.h"
83218 +#include "coretypes.h"
83219 +#include "tree.h"
83220 +#include "tree-pass.h"
83221 +#include "flags.h"
83222 +#include "intl.h"
83223 +#include "toplev.h"
83224 +#include "plugin.h"
83225 +//#include "expr.h" where are you...
83226 +#include "diagnostic.h"
83227 +#include "plugin-version.h"
83228 +#include "tm.h"
83229 +#include "function.h"
83230 +#include "basic-block.h"
83231 +#include "gimple.h"
83232 +#include "rtl.h"
83233 +#include "emit-rtl.h"
83234 +
83235 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83236 +
83237 +int plugin_is_GPL_compatible;
83238 +
83239 +static const char * const kalloc_functions[] = {
83240 + "__kmalloc",
83241 + "kmalloc",
83242 + "kmalloc_large",
83243 + "kmalloc_node",
83244 + "kmalloc_order",
83245 + "kmalloc_order_trace",
83246 + "kmalloc_slab",
83247 + "kzalloc",
83248 + "kzalloc_node",
83249 +};
83250 +
83251 +static struct plugin_info kallocstat_plugin_info = {
83252 + .version = "201111150100",
83253 +};
83254 +
83255 +static unsigned int execute_kallocstat(void);
83256 +
83257 +static struct gimple_opt_pass kallocstat_pass = {
83258 + .pass = {
83259 + .type = GIMPLE_PASS,
83260 + .name = "kallocstat",
83261 + .gate = NULL,
83262 + .execute = execute_kallocstat,
83263 + .sub = NULL,
83264 + .next = NULL,
83265 + .static_pass_number = 0,
83266 + .tv_id = TV_NONE,
83267 + .properties_required = 0,
83268 + .properties_provided = 0,
83269 + .properties_destroyed = 0,
83270 + .todo_flags_start = 0,
83271 + .todo_flags_finish = 0
83272 + }
83273 +};
83274 +
83275 +static bool is_kalloc(const char *fnname)
83276 +{
83277 + size_t i;
83278 +
83279 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83280 + if (!strcmp(fnname, kalloc_functions[i]))
83281 + return true;
83282 + return false;
83283 +}
83284 +
83285 +static unsigned int execute_kallocstat(void)
83286 +{
83287 + basic_block bb;
83288 +
83289 + // 1. loop through BBs and GIMPLE statements
83290 + FOR_EACH_BB(bb) {
83291 + gimple_stmt_iterator gsi;
83292 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83293 + // gimple match:
83294 + tree fndecl, size;
83295 + gimple call_stmt;
83296 + const char *fnname;
83297 +
83298 + // is it a call
83299 + call_stmt = gsi_stmt(gsi);
83300 + if (!is_gimple_call(call_stmt))
83301 + continue;
83302 + fndecl = gimple_call_fndecl(call_stmt);
83303 + if (fndecl == NULL_TREE)
83304 + continue;
83305 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83306 + continue;
83307 +
83308 + // is it a call to k*alloc
83309 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83310 + if (!is_kalloc(fnname))
83311 + continue;
83312 +
83313 + // is the size arg the result of a simple const assignment
83314 + size = gimple_call_arg(call_stmt, 0);
83315 + while (true) {
83316 + gimple def_stmt;
83317 + expanded_location xloc;
83318 + size_t size_val;
83319 +
83320 + if (TREE_CODE(size) != SSA_NAME)
83321 + break;
83322 + def_stmt = SSA_NAME_DEF_STMT(size);
83323 + if (!def_stmt || !is_gimple_assign(def_stmt))
83324 + break;
83325 + if (gimple_num_ops(def_stmt) != 2)
83326 + break;
83327 + size = gimple_assign_rhs1(def_stmt);
83328 + if (!TREE_CONSTANT(size))
83329 + continue;
83330 + xloc = expand_location(gimple_location(def_stmt));
83331 + if (!xloc.file)
83332 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83333 + size_val = TREE_INT_CST_LOW(size);
83334 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83335 + break;
83336 + }
83337 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83338 +//debug_tree(gimple_call_fn(call_stmt));
83339 +//print_node(stderr, "pax", fndecl, 4);
83340 + }
83341 + }
83342 +
83343 + return 0;
83344 +}
83345 +
83346 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83347 +{
83348 + const char * const plugin_name = plugin_info->base_name;
83349 + struct register_pass_info kallocstat_pass_info = {
83350 + .pass = &kallocstat_pass.pass,
83351 + .reference_pass_name = "ssa",
83352 + .ref_pass_instance_number = 1,
83353 + .pos_op = PASS_POS_INSERT_AFTER
83354 + };
83355 +
83356 + if (!plugin_default_version_check(version, &gcc_version)) {
83357 + error(G_("incompatible gcc/plugin versions"));
83358 + return 1;
83359 + }
83360 +
83361 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83362 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83363 +
83364 + return 0;
83365 +}
83366 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83367 new file mode 100644
83368 index 0000000..98011fa
83369 --- /dev/null
83370 +++ b/tools/gcc/kernexec_plugin.c
83371 @@ -0,0 +1,427 @@
83372 +/*
83373 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83374 + * Licensed under the GPL v2
83375 + *
83376 + * Note: the choice of the license means that the compilation process is
83377 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83378 + * but for the kernel it doesn't matter since it doesn't link against
83379 + * any of the gcc libraries
83380 + *
83381 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83382 + *
83383 + * TODO:
83384 + *
83385 + * BUGS:
83386 + * - none known
83387 + */
83388 +#include "gcc-plugin.h"
83389 +#include "config.h"
83390 +#include "system.h"
83391 +#include "coretypes.h"
83392 +#include "tree.h"
83393 +#include "tree-pass.h"
83394 +#include "flags.h"
83395 +#include "intl.h"
83396 +#include "toplev.h"
83397 +#include "plugin.h"
83398 +//#include "expr.h" where are you...
83399 +#include "diagnostic.h"
83400 +#include "plugin-version.h"
83401 +#include "tm.h"
83402 +#include "function.h"
83403 +#include "basic-block.h"
83404 +#include "gimple.h"
83405 +#include "rtl.h"
83406 +#include "emit-rtl.h"
83407 +#include "tree-flow.h"
83408 +
83409 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83410 +extern rtx emit_move_insn(rtx x, rtx y);
83411 +
83412 +int plugin_is_GPL_compatible;
83413 +
83414 +static struct plugin_info kernexec_plugin_info = {
83415 + .version = "201111291120",
83416 + .help = "method=[bts|or]\tinstrumentation method\n"
83417 +};
83418 +
83419 +static unsigned int execute_kernexec_reload(void);
83420 +static unsigned int execute_kernexec_fptr(void);
83421 +static unsigned int execute_kernexec_retaddr(void);
83422 +static bool kernexec_cmodel_check(void);
83423 +
83424 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83425 +static void (*kernexec_instrument_retaddr)(rtx);
83426 +
83427 +static struct gimple_opt_pass kernexec_reload_pass = {
83428 + .pass = {
83429 + .type = GIMPLE_PASS,
83430 + .name = "kernexec_reload",
83431 + .gate = kernexec_cmodel_check,
83432 + .execute = execute_kernexec_reload,
83433 + .sub = NULL,
83434 + .next = NULL,
83435 + .static_pass_number = 0,
83436 + .tv_id = TV_NONE,
83437 + .properties_required = 0,
83438 + .properties_provided = 0,
83439 + .properties_destroyed = 0,
83440 + .todo_flags_start = 0,
83441 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83442 + }
83443 +};
83444 +
83445 +static struct gimple_opt_pass kernexec_fptr_pass = {
83446 + .pass = {
83447 + .type = GIMPLE_PASS,
83448 + .name = "kernexec_fptr",
83449 + .gate = kernexec_cmodel_check,
83450 + .execute = execute_kernexec_fptr,
83451 + .sub = NULL,
83452 + .next = NULL,
83453 + .static_pass_number = 0,
83454 + .tv_id = TV_NONE,
83455 + .properties_required = 0,
83456 + .properties_provided = 0,
83457 + .properties_destroyed = 0,
83458 + .todo_flags_start = 0,
83459 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83460 + }
83461 +};
83462 +
83463 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83464 + .pass = {
83465 + .type = RTL_PASS,
83466 + .name = "kernexec_retaddr",
83467 + .gate = kernexec_cmodel_check,
83468 + .execute = execute_kernexec_retaddr,
83469 + .sub = NULL,
83470 + .next = NULL,
83471 + .static_pass_number = 0,
83472 + .tv_id = TV_NONE,
83473 + .properties_required = 0,
83474 + .properties_provided = 0,
83475 + .properties_destroyed = 0,
83476 + .todo_flags_start = 0,
83477 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83478 + }
83479 +};
83480 +
83481 +static bool kernexec_cmodel_check(void)
83482 +{
83483 + tree section;
83484 +
83485 + if (ix86_cmodel != CM_KERNEL)
83486 + return false;
83487 +
83488 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83489 + if (!section || !TREE_VALUE(section))
83490 + return true;
83491 +
83492 + section = TREE_VALUE(TREE_VALUE(section));
83493 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83494 + return true;
83495 +
83496 + return false;
83497 +}
83498 +
83499 +/*
83500 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83501 + */
83502 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83503 +{
83504 + gimple asm_movabs_stmt;
83505 +
83506 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83507 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83508 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83509 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83510 + update_stmt(asm_movabs_stmt);
83511 +}
83512 +
83513 +/*
83514 + * find all asm() stmts that clobber r10 and add a reload of r10
83515 + */
83516 +static unsigned int execute_kernexec_reload(void)
83517 +{
83518 + basic_block bb;
83519 +
83520 + // 1. loop through BBs and GIMPLE statements
83521 + FOR_EACH_BB(bb) {
83522 + gimple_stmt_iterator gsi;
83523 +
83524 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83525 + // gimple match: __asm__ ("" : : : "r10");
83526 + gimple asm_stmt;
83527 + size_t nclobbers;
83528 +
83529 + // is it an asm ...
83530 + asm_stmt = gsi_stmt(gsi);
83531 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83532 + continue;
83533 +
83534 + // ... clobbering r10
83535 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83536 + while (nclobbers--) {
83537 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83538 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83539 + continue;
83540 + kernexec_reload_fptr_mask(&gsi);
83541 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83542 + break;
83543 + }
83544 + }
83545 + }
83546 +
83547 + return 0;
83548 +}
83549 +
83550 +/*
83551 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83552 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83553 + */
83554 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83555 +{
83556 + gimple assign_intptr, assign_new_fptr, call_stmt;
83557 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83558 +
83559 + call_stmt = gsi_stmt(*gsi);
83560 + old_fptr = gimple_call_fn(call_stmt);
83561 +
83562 + // create temporary unsigned long variable used for bitops and cast fptr to it
83563 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83564 + add_referenced_var(intptr);
83565 + mark_sym_for_renaming(intptr);
83566 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83567 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83568 + update_stmt(assign_intptr);
83569 +
83570 + // apply logical or to temporary unsigned long and bitmask
83571 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83572 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83573 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83574 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83575 + update_stmt(assign_intptr);
83576 +
83577 + // cast temporary unsigned long back to a temporary fptr variable
83578 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83579 + add_referenced_var(new_fptr);
83580 + mark_sym_for_renaming(new_fptr);
83581 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83582 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83583 + update_stmt(assign_new_fptr);
83584 +
83585 + // replace call stmt fn with the new fptr
83586 + gimple_call_set_fn(call_stmt, new_fptr);
83587 + update_stmt(call_stmt);
83588 +}
83589 +
83590 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83591 +{
83592 + gimple asm_or_stmt, call_stmt;
83593 + tree old_fptr, new_fptr, input, output;
83594 + VEC(tree, gc) *inputs = NULL;
83595 + VEC(tree, gc) *outputs = NULL;
83596 +
83597 + call_stmt = gsi_stmt(*gsi);
83598 + old_fptr = gimple_call_fn(call_stmt);
83599 +
83600 + // create temporary fptr variable
83601 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83602 + add_referenced_var(new_fptr);
83603 + mark_sym_for_renaming(new_fptr);
83604 +
83605 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83606 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83607 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83608 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83609 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83610 + VEC_safe_push(tree, gc, inputs, input);
83611 + VEC_safe_push(tree, gc, outputs, output);
83612 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83613 + gimple_asm_set_volatile(asm_or_stmt, true);
83614 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83615 + update_stmt(asm_or_stmt);
83616 +
83617 + // replace call stmt fn with the new fptr
83618 + gimple_call_set_fn(call_stmt, new_fptr);
83619 + update_stmt(call_stmt);
83620 +}
83621 +
83622 +/*
83623 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83624 + */
83625 +static unsigned int execute_kernexec_fptr(void)
83626 +{
83627 + basic_block bb;
83628 +
83629 + // 1. loop through BBs and GIMPLE statements
83630 + FOR_EACH_BB(bb) {
83631 + gimple_stmt_iterator gsi;
83632 +
83633 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83634 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83635 + tree fn;
83636 + gimple call_stmt;
83637 +
83638 + // is it a call ...
83639 + call_stmt = gsi_stmt(gsi);
83640 + if (!is_gimple_call(call_stmt))
83641 + continue;
83642 + fn = gimple_call_fn(call_stmt);
83643 + if (TREE_CODE(fn) == ADDR_EXPR)
83644 + continue;
83645 + if (TREE_CODE(fn) != SSA_NAME)
83646 + gcc_unreachable();
83647 +
83648 + // ... through a function pointer
83649 + fn = SSA_NAME_VAR(fn);
83650 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83651 + continue;
83652 + fn = TREE_TYPE(fn);
83653 + if (TREE_CODE(fn) != POINTER_TYPE)
83654 + continue;
83655 + fn = TREE_TYPE(fn);
83656 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83657 + continue;
83658 +
83659 + kernexec_instrument_fptr(&gsi);
83660 +
83661 +//debug_tree(gimple_call_fn(call_stmt));
83662 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83663 + }
83664 + }
83665 +
83666 + return 0;
83667 +}
83668 +
83669 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83670 +static void kernexec_instrument_retaddr_bts(rtx insn)
83671 +{
83672 + rtx btsq;
83673 + rtvec argvec, constraintvec, labelvec;
83674 + int line;
83675 +
83676 + // create asm volatile("btsq $63,(%%rsp)":::)
83677 + argvec = rtvec_alloc(0);
83678 + constraintvec = rtvec_alloc(0);
83679 + labelvec = rtvec_alloc(0);
83680 + line = expand_location(RTL_LOCATION(insn)).line;
83681 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83682 + MEM_VOLATILE_P(btsq) = 1;
83683 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83684 + emit_insn_before(btsq, insn);
83685 +}
83686 +
83687 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83688 +static void kernexec_instrument_retaddr_or(rtx insn)
83689 +{
83690 + rtx orq;
83691 + rtvec argvec, constraintvec, labelvec;
83692 + int line;
83693 +
83694 + // create asm volatile("orq %%r10,(%%rsp)":::)
83695 + argvec = rtvec_alloc(0);
83696 + constraintvec = rtvec_alloc(0);
83697 + labelvec = rtvec_alloc(0);
83698 + line = expand_location(RTL_LOCATION(insn)).line;
83699 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83700 + MEM_VOLATILE_P(orq) = 1;
83701 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83702 + emit_insn_before(orq, insn);
83703 +}
83704 +
83705 +/*
83706 + * find all asm level function returns and forcibly set the highest bit of the return address
83707 + */
83708 +static unsigned int execute_kernexec_retaddr(void)
83709 +{
83710 + rtx insn;
83711 +
83712 + // 1. find function returns
83713 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83714 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83715 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83716 + rtx body;
83717 +
83718 + // is it a retn
83719 + if (!JUMP_P(insn))
83720 + continue;
83721 + body = PATTERN(insn);
83722 + if (GET_CODE(body) == PARALLEL)
83723 + body = XVECEXP(body, 0, 0);
83724 + if (GET_CODE(body) != RETURN)
83725 + continue;
83726 + kernexec_instrument_retaddr(insn);
83727 + }
83728 +
83729 +// print_simple_rtl(stderr, get_insns());
83730 +// print_rtl(stderr, get_insns());
83731 +
83732 + return 0;
83733 +}
83734 +
83735 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83736 +{
83737 + const char * const plugin_name = plugin_info->base_name;
83738 + const int argc = plugin_info->argc;
83739 + const struct plugin_argument * const argv = plugin_info->argv;
83740 + int i;
83741 + struct register_pass_info kernexec_reload_pass_info = {
83742 + .pass = &kernexec_reload_pass.pass,
83743 + .reference_pass_name = "ssa",
83744 + .ref_pass_instance_number = 1,
83745 + .pos_op = PASS_POS_INSERT_AFTER
83746 + };
83747 + struct register_pass_info kernexec_fptr_pass_info = {
83748 + .pass = &kernexec_fptr_pass.pass,
83749 + .reference_pass_name = "ssa",
83750 + .ref_pass_instance_number = 1,
83751 + .pos_op = PASS_POS_INSERT_AFTER
83752 + };
83753 + struct register_pass_info kernexec_retaddr_pass_info = {
83754 + .pass = &kernexec_retaddr_pass.pass,
83755 + .reference_pass_name = "pro_and_epilogue",
83756 + .ref_pass_instance_number = 1,
83757 + .pos_op = PASS_POS_INSERT_AFTER
83758 + };
83759 +
83760 + if (!plugin_default_version_check(version, &gcc_version)) {
83761 + error(G_("incompatible gcc/plugin versions"));
83762 + return 1;
83763 + }
83764 +
83765 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83766 +
83767 + if (TARGET_64BIT == 0)
83768 + return 0;
83769 +
83770 + for (i = 0; i < argc; ++i) {
83771 + if (!strcmp(argv[i].key, "method")) {
83772 + if (!argv[i].value) {
83773 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83774 + continue;
83775 + }
83776 + if (!strcmp(argv[i].value, "bts")) {
83777 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83778 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83779 + } else if (!strcmp(argv[i].value, "or")) {
83780 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83781 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83782 + fix_register("r10", 1, 1);
83783 + } else
83784 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83785 + continue;
83786 + }
83787 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83788 + }
83789 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83790 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83791 +
83792 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83793 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83794 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83795 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83796 +
83797 + return 0;
83798 +}
83799 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83800 new file mode 100644
83801 index 0000000..b8008f7
83802 --- /dev/null
83803 +++ b/tools/gcc/latent_entropy_plugin.c
83804 @@ -0,0 +1,295 @@
83805 +/*
83806 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83807 + * Licensed under the GPL v2
83808 + *
83809 + * Note: the choice of the license means that the compilation process is
83810 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83811 + * but for the kernel it doesn't matter since it doesn't link against
83812 + * any of the gcc libraries
83813 + *
83814 + * gcc plugin to help generate a little bit of entropy from program state,
83815 + * used during boot in the kernel
83816 + *
83817 + * TODO:
83818 + * - add ipa pass to identify not explicitly marked candidate functions
83819 + * - mix in more program state (function arguments/return values, loop variables, etc)
83820 + * - more instrumentation control via attribute parameters
83821 + *
83822 + * BUGS:
83823 + * - LTO needs -flto-partition=none for now
83824 + */
83825 +#include "gcc-plugin.h"
83826 +#include "config.h"
83827 +#include "system.h"
83828 +#include "coretypes.h"
83829 +#include "tree.h"
83830 +#include "tree-pass.h"
83831 +#include "flags.h"
83832 +#include "intl.h"
83833 +#include "toplev.h"
83834 +#include "plugin.h"
83835 +//#include "expr.h" where are you...
83836 +#include "diagnostic.h"
83837 +#include "plugin-version.h"
83838 +#include "tm.h"
83839 +#include "function.h"
83840 +#include "basic-block.h"
83841 +#include "gimple.h"
83842 +#include "rtl.h"
83843 +#include "emit-rtl.h"
83844 +#include "tree-flow.h"
83845 +
83846 +int plugin_is_GPL_compatible;
83847 +
83848 +static tree latent_entropy_decl;
83849 +
83850 +static struct plugin_info latent_entropy_plugin_info = {
83851 + .version = "201207271820",
83852 + .help = NULL
83853 +};
83854 +
83855 +static unsigned int execute_latent_entropy(void);
83856 +static bool gate_latent_entropy(void);
83857 +
83858 +static struct gimple_opt_pass latent_entropy_pass = {
83859 + .pass = {
83860 + .type = GIMPLE_PASS,
83861 + .name = "latent_entropy",
83862 + .gate = gate_latent_entropy,
83863 + .execute = execute_latent_entropy,
83864 + .sub = NULL,
83865 + .next = NULL,
83866 + .static_pass_number = 0,
83867 + .tv_id = TV_NONE,
83868 + .properties_required = PROP_gimple_leh | PROP_cfg,
83869 + .properties_provided = 0,
83870 + .properties_destroyed = 0,
83871 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83872 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83873 + }
83874 +};
83875 +
83876 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83877 +{
83878 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83879 + *no_add_attrs = true;
83880 + error("%qE attribute only applies to functions", name);
83881 + }
83882 + return NULL_TREE;
83883 +}
83884 +
83885 +static struct attribute_spec latent_entropy_attr = {
83886 + .name = "latent_entropy",
83887 + .min_length = 0,
83888 + .max_length = 0,
83889 + .decl_required = true,
83890 + .type_required = false,
83891 + .function_type_required = false,
83892 + .handler = handle_latent_entropy_attribute,
83893 +#if BUILDING_GCC_VERSION >= 4007
83894 + .affects_type_identity = false
83895 +#endif
83896 +};
83897 +
83898 +static void register_attributes(void *event_data, void *data)
83899 +{
83900 + register_attribute(&latent_entropy_attr);
83901 +}
83902 +
83903 +static bool gate_latent_entropy(void)
83904 +{
83905 + tree latent_entropy_attr;
83906 +
83907 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83908 + return latent_entropy_attr != NULL_TREE;
83909 +}
83910 +
83911 +static unsigned HOST_WIDE_INT seed;
83912 +static unsigned HOST_WIDE_INT get_random_const(void)
83913 +{
83914 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83915 + return seed;
83916 +}
83917 +
83918 +static enum tree_code get_op(tree *rhs)
83919 +{
83920 + static enum tree_code op;
83921 + unsigned HOST_WIDE_INT random_const;
83922 +
83923 + random_const = get_random_const();
83924 +
83925 + switch (op) {
83926 + case BIT_XOR_EXPR:
83927 + op = PLUS_EXPR;
83928 + break;
83929 +
83930 + case PLUS_EXPR:
83931 + if (rhs) {
83932 + op = LROTATE_EXPR;
83933 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83934 + break;
83935 + }
83936 +
83937 + case LROTATE_EXPR:
83938 + default:
83939 + op = BIT_XOR_EXPR;
83940 + break;
83941 + }
83942 + if (rhs)
83943 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83944 + return op;
83945 +}
83946 +
83947 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83948 +{
83949 + gimple_stmt_iterator gsi;
83950 + gimple assign;
83951 + tree addxorrol, rhs;
83952 + enum tree_code op;
83953 +
83954 + op = get_op(&rhs);
83955 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83956 + assign = gimple_build_assign(local_entropy, addxorrol);
83957 + find_referenced_vars_in(assign);
83958 +//debug_bb(bb);
83959 + gsi = gsi_after_labels(bb);
83960 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83961 + update_stmt(assign);
83962 +}
83963 +
83964 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83965 +{
83966 + gimple_stmt_iterator gsi;
83967 + gimple assign;
83968 + tree addxorrol, temp;
83969 +
83970 + // 1. create temporary copy of latent_entropy
83971 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83972 + add_referenced_var(temp);
83973 + mark_sym_for_renaming(temp);
83974 +
83975 + // 2. read...
83976 + assign = gimple_build_assign(temp, latent_entropy_decl);
83977 + find_referenced_vars_in(assign);
83978 + gsi = gsi_after_labels(bb);
83979 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83980 + update_stmt(assign);
83981 +
83982 + // 3. ...modify...
83983 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83984 + assign = gimple_build_assign(temp, addxorrol);
83985 + find_referenced_vars_in(assign);
83986 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83987 + update_stmt(assign);
83988 +
83989 + // 4. ...write latent_entropy
83990 + assign = gimple_build_assign(latent_entropy_decl, temp);
83991 + find_referenced_vars_in(assign);
83992 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83993 + update_stmt(assign);
83994 +}
83995 +
83996 +static unsigned int execute_latent_entropy(void)
83997 +{
83998 + basic_block bb;
83999 + gimple assign;
84000 + gimple_stmt_iterator gsi;
84001 + tree local_entropy;
84002 +
84003 + if (!latent_entropy_decl) {
84004 + struct varpool_node *node;
84005 +
84006 + for (node = varpool_nodes; node; node = node->next) {
84007 + tree var = node->decl;
84008 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
84009 + continue;
84010 + latent_entropy_decl = var;
84011 +// debug_tree(var);
84012 + break;
84013 + }
84014 + if (!latent_entropy_decl) {
84015 +// debug_tree(current_function_decl);
84016 + return 0;
84017 + }
84018 + }
84019 +
84020 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
84021 +
84022 + // 1. create local entropy variable
84023 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
84024 + add_referenced_var(local_entropy);
84025 + mark_sym_for_renaming(local_entropy);
84026 +
84027 + // 2. initialize local entropy variable
84028 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84029 + if (dom_info_available_p(CDI_DOMINATORS))
84030 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84031 + gsi = gsi_start_bb(bb);
84032 +
84033 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
84034 +// gimple_set_location(assign, loc);
84035 + find_referenced_vars_in(assign);
84036 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84037 + update_stmt(assign);
84038 + bb = bb->next_bb;
84039 +
84040 + // 3. instrument each BB with an operation on the local entropy variable
84041 + while (bb != EXIT_BLOCK_PTR) {
84042 + perturb_local_entropy(bb, local_entropy);
84043 + bb = bb->next_bb;
84044 + };
84045 +
84046 + // 4. mix local entropy into the global entropy variable
84047 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84048 + return 0;
84049 +}
84050 +
84051 +static void start_unit_callback(void *gcc_data, void *user_data)
84052 +{
84053 +#if BUILDING_GCC_VERSION >= 4007
84054 + seed = get_random_seed(false);
84055 +#else
84056 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84057 + seed *= seed;
84058 +#endif
84059 +
84060 + if (in_lto_p)
84061 + return;
84062 +
84063 + // extern u64 latent_entropy
84064 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84065 +
84066 + TREE_STATIC(latent_entropy_decl) = 1;
84067 + TREE_PUBLIC(latent_entropy_decl) = 1;
84068 + TREE_USED(latent_entropy_decl) = 1;
84069 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84070 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84071 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84072 + DECL_INITIAL(latent_entropy_decl) = NULL;
84073 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84074 +// varpool_finalize_decl(latent_entropy_decl);
84075 +// varpool_mark_needed_node(latent_entropy_decl);
84076 +}
84077 +
84078 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84079 +{
84080 + const char * const plugin_name = plugin_info->base_name;
84081 + struct register_pass_info latent_entropy_pass_info = {
84082 + .pass = &latent_entropy_pass.pass,
84083 + .reference_pass_name = "optimized",
84084 + .ref_pass_instance_number = 1,
84085 + .pos_op = PASS_POS_INSERT_BEFORE
84086 + };
84087 +
84088 + if (!plugin_default_version_check(version, &gcc_version)) {
84089 + error(G_("incompatible gcc/plugin versions"));
84090 + return 1;
84091 + }
84092 +
84093 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84094 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84095 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84096 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84097 +
84098 + return 0;
84099 +}
84100 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84101 new file mode 100644
84102 index 0000000..9332f17
84103 --- /dev/null
84104 +++ b/tools/gcc/size_overflow_hash.data
84105 @@ -0,0 +1,3597 @@
84106 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84107 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84108 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84109 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84110 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84111 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84112 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84113 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84114 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84115 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84116 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84117 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84118 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84119 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84120 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84121 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84122 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84123 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84124 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84125 +_000021_hash read_zero 3 19366 _000021_hash NULL
84126 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84127 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84128 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84129 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84130 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84131 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84132 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84133 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84134 +_000031_hash adu_write 3 30487 _000031_hash NULL
84135 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84136 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84137 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84138 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84139 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84140 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84141 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84142 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84143 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84144 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84145 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84146 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84147 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84148 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84149 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84150 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84151 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84152 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84153 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84154 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84155 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84156 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84157 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84158 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84159 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84160 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84161 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84162 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84163 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84164 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84165 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84166 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84167 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84168 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84169 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84170 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84171 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84172 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84173 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84174 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84175 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84176 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84177 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84178 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84179 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84180 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84181 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84182 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84183 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84184 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84185 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84186 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84187 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84188 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84189 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84190 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84191 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84192 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84193 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84194 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84195 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84196 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84197 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84198 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84199 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84200 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84201 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84202 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84203 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84204 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84205 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84206 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84207 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84208 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84209 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84210 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84211 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84212 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84213 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84214 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84215 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84216 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84217 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84218 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84219 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84220 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84221 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84222 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84223 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84224 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84225 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84226 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84227 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84228 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84229 +_000134_hash cm_write 3 36858 _000134_hash NULL
84230 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84231 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84232 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84233 +_000138_hash command_write 3 58841 _000138_hash NULL
84234 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84235 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84236 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84237 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84238 +_000143_hash copy_items 6 50140 _000143_hash NULL
84239 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84240 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84241 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84242 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84243 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84244 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84245 +_000150_hash create_entry 2 33479 _000150_hash NULL
84246 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84247 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84248 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84249 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84250 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84251 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84252 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84253 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84254 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84255 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84256 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84257 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84258 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84259 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84260 +_000168_hash dev_config 3 8506 _000168_hash NULL
84261 +_000169_hash device_write 3 45156 _000169_hash NULL
84262 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84263 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84264 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84265 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84266 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84267 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84268 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84269 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84270 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84271 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84272 +_000180_hash dm_read 3 15674 _000180_hash NULL
84273 +_000181_hash dm_write 3 2513 _000181_hash NULL
84274 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84275 +_000183_hash dns_query 3 9676 _000183_hash NULL
84276 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84277 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84278 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84279 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84280 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84281 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84282 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84283 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84284 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84285 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84286 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84287 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84288 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84289 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84290 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84291 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84292 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84293 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84294 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84295 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84296 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84297 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84298 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84299 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84300 +_000208_hash ep_read 3 58813 _000208_hash NULL
84301 +_000209_hash ep_write 3 59008 _000209_hash NULL
84302 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84303 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84304 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84305 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84306 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84307 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84308 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84309 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84310 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84311 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84312 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84313 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84314 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84315 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84316 +_000225_hash fl_create 5 56435 _000225_hash NULL
84317 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84318 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84319 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84320 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84321 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84322 +_000231_hash get_arg 3 5694 _000231_hash NULL
84323 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84324 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84325 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84326 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84327 +_000236_hash get_registers 3 26187 _000236_hash NULL
84328 +_000237_hash get_scq 2 10897 _000237_hash NULL
84329 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84330 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84331 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84332 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84333 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84334 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84335 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84336 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84337 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84338 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84339 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84340 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84341 +_000250_hash handle_request 9 10024 _000250_hash NULL
84342 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84343 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84344 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84345 +_000254_hash heap_init 2 49617 _000254_hash NULL
84346 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84347 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84348 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84349 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84350 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84351 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84352 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84353 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84354 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84355 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84356 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84357 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84358 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84359 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84360 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84361 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84362 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84363 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84364 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84365 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84366 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84367 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84368 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84369 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84370 +_000279_hash if_write 3 51756 _000279_hash NULL
84371 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84372 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84373 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84374 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84375 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84376 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84377 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84378 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84379 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84380 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84381 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84382 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84383 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84384 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84385 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84386 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84387 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84388 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84389 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84390 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84391 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84392 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84393 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84394 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84395 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84396 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84397 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84398 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84399 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84400 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84401 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84402 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84403 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84404 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84405 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84406 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84407 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84408 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84409 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84410 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84411 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84412 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84413 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84414 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84415 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84416 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84417 +_000329_hash kone_send 4 63435 _000329_hash NULL
84418 +_000330_hash krealloc 2 14908 _000330_hash NULL
84419 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84420 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84421 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84422 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84423 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84424 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84425 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84426 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84427 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84428 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84429 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84430 +_000342_hash __lgread 4 31668 _000342_hash NULL
84431 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84432 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84433 +_000345_hash listxattr 3 12769 _000345_hash NULL
84434 +_000346_hash load_msg 2 95 _000346_hash NULL
84435 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84436 +_000348_hash lp_write 3 9511 _000348_hash NULL
84437 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84438 +_000350_hash mce_write 3 26201 _000350_hash NULL
84439 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84440 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84441 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84442 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84443 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84444 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84445 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84446 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84447 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84448 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84449 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84450 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84451 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84452 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84453 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84454 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84455 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84456 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84457 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84458 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84459 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84460 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84461 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84462 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84463 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84464 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84465 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84466 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84467 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84468 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84469 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84470 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84471 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84472 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84473 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84474 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84475 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84476 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84477 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84478 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84479 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84480 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84481 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84482 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84483 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84484 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84485 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84486 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84487 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84488 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84489 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84490 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84491 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84492 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84493 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84494 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84495 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84496 +_000415_hash parse_command 2 37079 _000415_hash NULL
84497 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84498 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84499 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84500 +_000419_hash pg_write 3 40766 _000419_hash NULL
84501 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84502 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84503 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84504 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84505 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84506 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84507 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84508 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84509 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84510 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84511 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84512 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84513 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84514 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84515 +_000434_hash pp_read 3 33210 _000434_hash NULL
84516 +_000435_hash pp_write 3 39554 _000435_hash NULL
84517 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84518 +_000437_hash printer_write 3 60276 _000437_hash NULL
84519 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84520 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84521 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84522 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84523 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84524 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84525 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84526 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84527 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84528 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84529 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84530 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84531 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84532 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84533 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84534 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84535 +_000456_hash pt_write 3 40159 _000456_hash NULL
84536 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84537 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84538 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84539 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84540 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84541 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84542 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84543 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84544 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84545 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84546 +_000467_hash read 3 9397 _000467_hash NULL
84547 +_000468_hash read_buf 2 20469 _000468_hash NULL
84548 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84549 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84550 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84551 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84552 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84553 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84554 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84555 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84556 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84557 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84558 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84559 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84560 +_000481_hash revalidate 2 19043 _000481_hash NULL
84561 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84562 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84563 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84564 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84565 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84566 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84567 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84568 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84569 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84570 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84571 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84572 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84573 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84574 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84575 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84576 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84577 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84578 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84579 +_000500_hash savemem 3 58129 _000500_hash NULL
84580 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84581 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84582 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84583 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84584 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84585 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84586 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84587 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84588 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84589 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84590 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84591 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84592 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84593 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84594 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84595 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84596 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84597 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84598 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84599 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84600 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84601 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84602 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84603 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84604 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84605 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84606 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84607 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84608 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84609 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84610 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84611 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84612 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84613 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84614 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84615 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84616 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84617 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84618 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84619 +_000542_hash set_registers 3 53582 _000542_hash NULL
84620 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84621 +_000544_hash setup_req 3 5848 _000544_hash NULL
84622 +_000545_hash setxattr 4 37006 _000545_hash NULL
84623 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84624 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84625 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84626 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84627 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84628 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84629 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84630 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84631 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84632 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84633 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84634 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84635 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84636 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84637 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84638 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84639 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84640 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84641 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84642 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84643 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84644 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84645 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84646 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84647 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84648 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84649 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84650 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84651 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84652 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84653 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84654 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84655 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84656 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84657 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84658 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84659 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84660 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84661 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84662 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84663 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84664 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84665 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84666 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84667 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84668 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84669 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84670 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84671 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84672 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84673 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84674 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84675 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84676 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84677 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84678 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84679 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84680 +_000606_hash tower_write 3 8580 _000606_hash NULL
84681 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84682 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84683 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84684 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84685 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84686 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84687 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84688 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84689 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84690 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84691 +_000617_hash uea_request 4 47613 _000617_hash NULL
84692 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84693 +_000619_hash uio_write 3 43202 _000619_hash NULL
84694 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84695 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84696 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84697 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84698 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84699 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84700 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84701 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84702 +_000629_hash user_update 3 41332 _000629_hash NULL
84703 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84704 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84705 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84706 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84707 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84708 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84709 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84710 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84711 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84712 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84713 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84714 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84715 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84716 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84717 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84718 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84719 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84720 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84721 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84722 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84723 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84724 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84725 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84726 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84727 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84728 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84729 +_000659_hash write 3 62671 _000659_hash NULL
84730 +_000660_hash write_flush 3 50803 _000660_hash NULL
84731 +_000661_hash write_rio 3 54837 _000661_hash NULL
84732 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84733 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84734 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84735 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84736 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84737 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84738 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84739 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84740 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84741 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84742 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84743 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84744 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84745 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84746 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84747 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84748 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84749 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84750 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84751 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84752 +_000684_hash addtgt 3 54703 _000684_hash NULL
84753 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84754 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84755 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84756 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84757 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84758 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84759 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84760 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84761 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84762 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84763 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84764 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84765 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84766 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84767 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84768 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84769 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84770 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84771 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84772 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84773 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84774 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84775 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84776 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84777 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84778 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84779 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84780 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84781 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84782 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84783 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84784 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84785 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84786 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84787 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84788 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84789 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84790 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84791 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84792 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84793 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84794 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84795 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84796 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84797 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84798 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84799 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84800 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84801 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84802 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84803 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84804 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84805 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84806 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84807 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84808 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84809 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84810 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84811 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84812 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84813 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84814 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84815 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84816 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84817 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84818 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84819 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84820 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84821 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84822 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84823 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84824 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84825 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84826 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84827 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84828 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84829 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84830 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84831 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84832 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84833 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84834 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84835 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84836 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84837 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84838 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84839 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84840 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84841 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84842 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84843 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84844 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84845 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84846 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84847 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84848 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84849 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84850 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84851 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84852 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84853 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84854 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84855 +_000799_hash construct_key 3 11329 _000799_hash NULL
84856 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84857 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84858 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84859 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84860 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84861 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84862 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84863 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84864 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84865 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84866 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84867 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84868 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84869 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84870 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84871 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84872 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84873 +_000819_hash depth_write 3 3021 _000819_hash NULL
84874 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84875 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84876 +_000822_hash dev_write 3 7708 _000822_hash NULL
84877 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84878 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84879 +_000825_hash disconnect 4 32521 _000825_hash NULL
84880 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84881 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84882 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84883 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84884 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84885 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84886 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84887 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84888 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84889 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84890 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84891 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84892 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84893 +_000840_hash do_sync 1 9604 _000840_hash NULL
84894 +_000841_hash dup_array 3 33551 _000841_hash NULL
84895 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84896 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84897 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84898 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84899 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84900 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84901 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84902 +_000849_hash enable_write 3 30456 _000849_hash NULL
84903 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84904 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84905 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84906 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84907 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84908 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84909 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84910 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84911 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84912 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84913 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84914 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84915 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84916 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84917 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84918 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84919 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84920 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84921 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84922 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84923 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84924 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84925 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84926 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84927 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84928 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84929 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84930 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84931 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84932 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84933 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84934 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84935 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84936 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84937 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84938 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84939 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84940 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84941 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84942 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84943 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84944 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84945 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84946 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84947 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84948 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84949 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84950 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84951 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84952 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84953 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84954 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84955 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84956 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84957 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84958 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84959 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84960 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84961 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84962 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84963 +_000915_hash init_q 4 132 _000915_hash NULL
84964 +_000916_hash init_state 2 60165 _000916_hash NULL
84965 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84966 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84967 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84968 +_000920_hash interfaces 2 38859 _000920_hash NULL
84969 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84970 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84971 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84972 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84973 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84974 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84975 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84976 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84977 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84978 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84979 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84980 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84981 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84982 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84983 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84984 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84985 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84986 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84987 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84988 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84989 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84990 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84991 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84992 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84993 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84994 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84995 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84996 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84997 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84998 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84999 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
85000 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
85001 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
85002 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
85003 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
85004 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
85005 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
85006 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
85007 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
85008 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
85009 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
85010 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
85011 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
85012 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
85013 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
85014 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
85015 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
85016 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
85017 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
85018 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
85019 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
85020 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
85021 +_000977_hash lc_create 3 48662 _000977_hash NULL
85022 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
85023 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
85024 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
85025 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
85026 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
85027 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
85028 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
85029 +_000985_hash mem_read 3 57631 _000985_hash NULL
85030 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
85031 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
85032 +_000988_hash mem_write 3 22232 _000988_hash NULL
85033 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
85034 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
85035 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
85036 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
85037 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
85038 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
85039 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
85040 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
85041 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
85042 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
85043 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
85044 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
85045 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
85046 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
85047 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
85048 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
85049 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
85050 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
85051 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
85052 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
85053 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
85054 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
85055 +_001014_hash new_dir 3 31919 _001014_hash NULL
85056 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
85057 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
85058 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
85059 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
85060 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
85061 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85062 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85063 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85064 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85065 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85066 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85067 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85068 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85069 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85070 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85071 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85072 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85073 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85074 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85075 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85076 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85077 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85078 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85079 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85080 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85081 +_001046_hash osst_write 3 31581 _001046_hash NULL
85082 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85083 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85084 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85085 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85086 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85087 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85088 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85089 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85090 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85091 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85092 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85093 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85094 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85095 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85096 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85097 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85098 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85099 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85100 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85101 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85102 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85103 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85104 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85105 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85106 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85107 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85108 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85109 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85110 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85111 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85112 +_001083_hash proc_write 3 51003 _001083_hash NULL
85113 +_001084_hash profile_load 3 58267 _001084_hash NULL
85114 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85115 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85116 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85117 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85118 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85119 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85120 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85121 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85122 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85123 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85124 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85125 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85126 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85127 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85128 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85129 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85130 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85131 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85132 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85133 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85134 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85135 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85136 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85137 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85138 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85139 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85140 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85141 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85142 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85143 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85144 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85145 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85146 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85147 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85148 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85149 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85150 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85151 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85152 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85153 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85154 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85155 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85156 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85157 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85158 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85159 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85160 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85161 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85162 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85163 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85164 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85165 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85166 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85167 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85168 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85169 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85170 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85171 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85172 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85173 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85174 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85175 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85176 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85177 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85178 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85179 +_001152_hash setkey 3 14987 _001152_hash NULL
85180 +_001153_hash set_le 4 30581 _001153_hash NULL
85181 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85182 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85183 +_001156_hash set_powered 4 12129 _001156_hash NULL
85184 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85185 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85186 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85187 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85188 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85189 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85190 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85191 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85192 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85193 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85194 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85195 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85196 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85197 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85198 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85199 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85200 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85201 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85202 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85203 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85204 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85205 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85206 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85207 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85208 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85209 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85210 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85211 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85212 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85213 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85214 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85215 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85216 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85217 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85218 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85219 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85220 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85221 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85222 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85223 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85224 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85225 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85226 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85227 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85228 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85229 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85230 +_001208_hash sound_write 3 5102 _001208_hash NULL
85231 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85232 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85233 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85234 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85235 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85236 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85237 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85238 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85239 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85240 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85241 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85242 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85243 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85244 +_001227_hash st_write 3 16874 _001227_hash NULL
85245 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85246 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85247 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85248 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85249 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85250 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85251 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85252 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85253 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85254 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85255 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85256 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85257 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85258 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85259 +_001242_hash sys_select 1 38827 _001242_hash NULL
85260 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85261 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85262 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85263 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85264 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85265 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85266 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85267 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85268 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85269 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85270 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85271 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85272 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85273 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85274 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85275 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85276 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85277 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85278 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85279 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85280 +_001264_hash tty_write 3 5494 _001264_hash NULL
85281 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85282 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85283 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85284 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85285 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85286 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85287 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85288 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85289 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85290 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85291 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85292 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85293 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85294 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85295 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85296 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85297 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85298 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85299 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85300 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85301 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85302 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85303 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85304 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85305 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85306 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85307 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85308 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85309 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85310 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85311 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85312 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85313 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85314 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85315 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85316 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85317 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85318 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85319 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85320 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85321 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85322 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85323 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85324 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85325 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85326 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85327 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85328 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85329 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85330 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85331 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85332 +_001319_hash add_child 4 45201 _001319_hash NULL
85333 +_001320_hash add_port 2 54941 _001320_hash NULL
85334 +_001321_hash adu_read 3 24177 _001321_hash NULL
85335 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85336 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85337 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85338 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85339 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85340 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85341 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85342 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85343 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85344 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85345 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85346 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85347 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85348 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85349 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85350 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85351 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85352 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85353 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85354 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85355 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85356 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85357 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85358 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85359 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85360 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85361 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85362 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85363 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85364 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85365 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85366 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85367 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85368 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85369 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85370 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85371 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85372 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85373 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85374 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85375 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85376 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85377 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85378 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85379 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85380 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85381 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85382 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85383 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85384 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85385 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85386 +_001380_hash bm_init 2 13529 _001380_hash NULL
85387 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85388 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85389 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85390 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85391 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85392 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85393 +_001387_hash cache_read 3 24790 _001387_hash NULL
85394 +_001388_hash cache_write 3 13589 _001388_hash NULL
85395 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85396 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85397 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85398 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85399 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85400 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85401 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85402 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85403 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85404 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85405 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85406 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85407 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85408 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85409 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85410 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85411 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85412 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85413 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85414 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85415 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85416 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85417 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85418 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85419 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85420 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85421 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85422 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85423 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85424 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85425 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85426 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85427 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85428 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85429 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85430 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85431 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85432 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85433 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85434 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85435 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85436 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85437 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85438 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85439 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85440 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85441 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85442 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85443 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85444 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85445 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85446 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85447 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85448 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85449 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85450 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85451 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85452 +_001451_hash filldir 3 55137 _001451_hash NULL
85453 +_001452_hash filldir64 3 46469 _001452_hash NULL
85454 +_001453_hash find_skb 2 20431 _001453_hash NULL
85455 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85456 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85457 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85458 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85459 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85460 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85461 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85462 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85463 +_001462_hash get_packet 3 41914 _001462_hash NULL
85464 +_001463_hash get_packet 3 5747 _001463_hash NULL
85465 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85466 +_001465_hash get_skb 2 63008 _001465_hash NULL
85467 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85468 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85469 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85470 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85471 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85472 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85473 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85474 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85475 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85476 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85477 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85478 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85479 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85480 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85481 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85482 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85483 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85484 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85485 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85486 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85487 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85488 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85489 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85490 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85491 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85492 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85493 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85494 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85495 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85496 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85497 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85498 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85499 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85500 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85501 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85502 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85503 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85504 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85505 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85506 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85507 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85508 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85509 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85510 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85511 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85512 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85513 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85514 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85515 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85516 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85517 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85518 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85519 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85520 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85521 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85522 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85523 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85524 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85525 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85526 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85527 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85528 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85529 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85530 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85531 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85532 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85533 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85534 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85535 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85536 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85537 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85538 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85539 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85540 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85541 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85542 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85543 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85544 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85545 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85546 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85547 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85548 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85549 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85550 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85551 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85552 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85553 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85554 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85555 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85556 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85557 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85558 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85559 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85560 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85561 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85562 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85563 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85564 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85565 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85566 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85567 +_001575_hash new_skb 1 21148 _001575_hash NULL
85568 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85569 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85570 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85571 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85572 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85573 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85574 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85575 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85576 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85577 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85578 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85579 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85580 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85581 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85582 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85583 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85584 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85585 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85586 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85587 +_001599_hash override_release 2 52032 _001599_hash NULL
85588 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85589 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85590 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85591 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85592 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85593 +_001605_hash pg_read 3 17276 _001605_hash NULL
85594 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85595 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85596 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85597 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85598 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85599 +_001611_hash printer_read 3 54851 _001611_hash NULL
85600 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85601 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85602 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85603 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85604 +_001616_hash pt_read 3 49136 _001616_hash NULL
85605 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85606 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85607 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85608 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85609 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85610 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85611 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85612 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85613 +_001625_hash read_flush 3 43851 _001625_hash NULL
85614 +_001626_hash read_profile 3 27859 _001626_hash NULL
85615 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85616 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85617 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85618 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85619 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85620 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85621 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85622 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85623 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85624 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85625 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85626 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85627 +_001640_hash rx 4 57944 _001640_hash NULL
85628 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85629 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85630 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85631 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85632 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85633 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85634 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85635 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85636 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85637 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85638 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85639 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85640 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85641 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85642 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85643 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85644 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85645 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85646 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85647 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85648 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85649 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85650 +_001663_hash send_command 4 10832 _001663_hash NULL
85651 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85652 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85653 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85654 +_001667_hash set_arg 3 42824 _001667_hash NULL
85655 +_001668_hash sg_read 3 25799 _001668_hash NULL
85656 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85657 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85658 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85659 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85660 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85661 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85662 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85663 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85664 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85665 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85666 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85667 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85668 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85669 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85670 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85671 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85672 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85673 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85674 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85675 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85676 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85677 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85678 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85679 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85680 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85681 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85682 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85683 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85684 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85685 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85686 +_001704_hash store_msg 3 56417 _001704_hash NULL
85687 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85688 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85689 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85690 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85691 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85692 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85693 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85694 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85695 +_001713_hash syslog_print 2 307 _001713_hash NULL
85696 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85697 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85698 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85699 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85700 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85701 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85702 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85703 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85704 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85705 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85706 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85707 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85708 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85709 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85710 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85711 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85712 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85713 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85714 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85715 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85716 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85717 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85718 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85719 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85720 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85721 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85722 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85723 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85724 +_001746_hash uio_read 3 49300 _001746_hash NULL
85725 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85726 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85727 +_001749_hash unlink1 3 63059 _001749_hash NULL
85728 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85729 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85730 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85731 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85732 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85733 +_001756_hash user_read 3 51881 _001756_hash NULL
85734 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85735 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85736 +_001759_hash venus_create 4 20555 _001759_hash NULL
85737 +_001760_hash venus_link 5 32165 _001760_hash NULL
85738 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85739 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85740 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85741 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85742 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85743 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85744 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85745 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85746 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85747 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85748 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85749 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85750 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85751 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85752 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85753 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85754 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85755 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85756 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85757 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85758 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85759 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85760 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85761 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85762 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85763 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85764 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85765 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85766 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85767 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85768 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85769 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85770 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85771 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85772 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85773 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85774 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85775 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85776 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85777 +_001803_hash add_partition 2 55588 _001803_hash NULL
85778 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85779 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85780 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85781 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85782 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85783 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85784 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85785 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85786 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85787 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85788 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85789 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85790 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85791 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85792 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85793 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85794 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85795 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85796 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85797 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85798 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85799 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85800 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85801 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85802 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85803 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85804 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85805 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85806 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85807 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85808 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85809 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85810 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85811 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85812 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85813 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85814 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85815 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85816 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85817 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85818 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85819 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85820 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85821 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85822 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85823 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85824 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85825 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85826 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85827 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85828 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85829 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85830 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85831 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85832 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85833 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85834 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85835 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85836 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85837 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85838 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85839 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85840 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85841 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85842 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85843 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85844 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85845 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85846 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85847 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85848 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85849 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85850 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85851 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85852 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85853 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85854 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85855 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85856 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85857 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85858 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85859 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85860 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85861 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85862 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85863 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85864 +_001892_hash check_header 2 56930 _001892_hash NULL
85865 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85866 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85867 +_001895_hash console_store 4 36007 _001895_hash NULL
85868 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85869 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85870 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85871 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85872 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85873 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85874 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85875 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85876 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85877 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85878 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85879 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85880 +_001912_hash debug_output 3 18575 _001912_hash NULL
85881 +_001913_hash debug_read 3 19322 _001913_hash NULL
85882 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85883 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85884 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85885 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85886 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85887 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85888 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85889 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85890 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85891 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85892 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85893 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85894 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85895 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85896 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85897 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85898 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85899 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85900 +_001933_hash filter_read 3 61692 _001933_hash NULL
85901 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85902 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85903 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85904 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85905 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85906 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85907 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85908 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85909 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85910 +_001943_hash handle_response 5 55951 _001943_hash NULL
85911 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85912 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85913 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85914 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85915 +_001948_hash help 4 14971 _001948_hash NULL
85916 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85917 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85918 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85919 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85920 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85921 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85922 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85923 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85924 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85925 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85926 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85927 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85928 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85929 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85930 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85931 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85932 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85933 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85934 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85935 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85936 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85937 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85938 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85939 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85940 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85941 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85942 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85943 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85944 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85945 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85946 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85947 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85948 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85949 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85950 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85951 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85952 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85953 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85954 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85955 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85956 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85957 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85958 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85959 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85960 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85961 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85962 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85963 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85964 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85965 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85966 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85967 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85968 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85969 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85970 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85971 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85972 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85973 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85974 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85975 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85976 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85977 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85978 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85979 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85980 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85981 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85982 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85983 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85984 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85985 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85986 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85987 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85988 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85989 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85990 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85991 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85992 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85993 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85994 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85995 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85996 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85997 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85998 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85999 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
86000 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
86001 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
86002 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
86003 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
86004 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
86005 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
86006 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
86007 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
86008 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
86009 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
86010 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
86011 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
86012 +_002046_hash key_key_read 3 3241 _002046_hash NULL
86013 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
86014 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
86015 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
86016 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
86017 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
86018 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
86019 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
86020 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
86021 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
86022 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
86023 +_002058_hash l2down_create 4 21755 _002058_hash NULL
86024 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
86025 +_002060_hash l2up_create 3 6430 _002060_hash NULL
86026 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
86027 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
86028 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
86029 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
86030 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
86031 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
86032 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
86033 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
86034 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
86035 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
86036 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
86037 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
86038 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
86039 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
86040 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
86041 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
86042 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
86043 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
86044 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
86045 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
86046 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
86047 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
86048 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
86049 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
86050 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
86051 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
86052 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
86053 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
86054 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
86055 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
86056 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
86057 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
86058 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
86059 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
86060 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
86061 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86062 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86063 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86064 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86065 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86066 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86067 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86068 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86069 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86070 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86071 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86072 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86073 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86074 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86075 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86076 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86077 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86078 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86079 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86080 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86081 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86082 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86083 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86084 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86085 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86086 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86087 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86088 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86089 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86090 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86091 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86092 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86093 +_002136_hash osst_read 3 40237 _002136_hash NULL
86094 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86095 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86096 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86097 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86098 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86099 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86100 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86101 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86102 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86103 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86104 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86105 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86106 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86107 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86108 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86109 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86110 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86111 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86112 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86113 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86114 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86115 +_002161_hash proc_read 3 43614 _002161_hash NULL
86116 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86117 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86118 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86119 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86120 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86121 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86122 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86123 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86124 +_002170_hash queues_read 3 24877 _002170_hash NULL
86125 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86126 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86127 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86128 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86129 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86130 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86131 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86132 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86133 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86134 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86135 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86136 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86137 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86138 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86139 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86140 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86141 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86142 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86143 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86144 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86145 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86146 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86147 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86148 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86149 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86150 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86151 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86152 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86153 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86154 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86155 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86156 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86157 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86158 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86159 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86160 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86161 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86162 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86163 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86164 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86165 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86166 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86167 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86168 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86169 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86170 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86171 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86172 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86173 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86174 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86175 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86176 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86177 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86178 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86179 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86180 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86181 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86182 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86183 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86184 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86185 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86186 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86187 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86188 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86189 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86190 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86191 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86192 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86193 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86194 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86195 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86196 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86197 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86198 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86199 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86200 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86201 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86202 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86203 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86204 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86205 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86206 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86207 +_002254_hash send_msg 4 37323 _002254_hash NULL
86208 +_002255_hash send_packet 4 52960 _002255_hash NULL
86209 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86210 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86211 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86212 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86213 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86214 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86215 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86216 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86217 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86218 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86219 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86220 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86221 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86222 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86223 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86224 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86225 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86226 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86227 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86228 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86229 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86230 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86231 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86232 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86233 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86234 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86235 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86236 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86237 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86238 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86239 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86240 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86241 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86242 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86243 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86244 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86245 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86246 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86247 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86248 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86249 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86250 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86251 +_002306_hash st_read 3 51251 _002306_hash NULL
86252 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86253 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86254 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86255 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86256 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86257 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86258 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86259 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86260 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86261 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86262 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86263 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86264 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86265 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86266 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86267 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86268 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86269 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86270 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86271 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86272 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86273 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86274 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86275 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86276 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86277 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86278 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86279 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86280 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86281 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86282 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86283 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86284 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86285 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86286 +_002345_hash use_pool 2 64607 _002345_hash NULL
86287 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86288 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86289 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86290 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86291 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86292 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86293 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86294 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86295 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86296 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86297 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86298 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86299 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86300 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86301 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86302 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86303 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86304 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86305 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86306 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86307 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86308 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86309 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86310 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86311 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86312 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86313 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86314 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86315 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86316 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86317 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86318 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86319 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86320 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86321 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86322 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86323 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86324 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86325 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86326 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86327 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86328 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86329 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86330 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86331 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86332 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86333 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86334 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86335 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86336 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86337 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86338 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86339 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86340 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86341 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86342 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86343 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86344 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86345 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86346 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86347 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86348 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86349 +_002411_hash depth_read 3 31112 _002411_hash NULL
86350 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86351 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86352 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86353 +_002415_hash divas_write 3 63901 _002415_hash NULL
86354 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86355 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86356 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86357 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86358 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86359 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86360 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86361 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86362 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86363 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86364 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86365 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86366 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86367 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86368 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86369 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86370 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86371 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86372 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86373 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86374 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86375 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86376 +_002439_hash got_frame 2 16028 _002439_hash NULL
86377 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86378 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86379 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86380 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86381 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86382 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86383 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86384 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86385 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86386 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86387 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86388 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86389 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86390 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86391 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86392 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86393 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86394 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86395 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86396 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86397 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86398 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86399 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86400 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86401 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86402 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86403 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86404 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86405 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86406 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86407 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86408 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86409 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86410 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86411 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86412 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86413 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86414 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86415 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86416 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86417 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86418 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86419 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86420 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86421 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86422 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86423 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86424 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86425 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86426 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86427 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86428 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86429 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86430 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86431 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86432 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86433 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86434 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86435 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86436 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86437 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86438 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86439 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86440 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86441 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86442 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86443 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86444 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86445 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86446 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86447 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86448 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86449 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86450 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86451 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86452 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86453 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86454 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86455 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86456 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86457 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86458 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86459 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86460 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86461 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86462 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86463 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86464 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86465 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86466 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86467 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86468 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86469 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86470 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86471 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86472 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86473 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86474 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86475 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86476 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86477 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86478 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86479 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86480 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86481 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86482 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86483 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86484 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86485 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86486 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86487 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86488 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86489 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86490 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86491 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86492 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86493 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86494 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86495 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86496 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86497 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86498 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86499 +_002570_hash map_addr 6 4666 _002570_hash NULL
86500 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86501 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86502 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86503 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86504 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86505 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86506 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86507 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86508 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86509 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86510 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86511 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86512 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86513 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86514 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86515 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86516 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86517 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86518 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86519 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86520 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86521 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86522 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86523 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86524 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86525 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86526 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86527 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86528 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86529 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86530 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86531 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86532 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86533 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86534 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86535 +_002612_hash power_read 3 15939 _002612_hash NULL
86536 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86537 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86538 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86539 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86540 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86541 +_002618_hash prison_create 1 43623 _002618_hash NULL
86542 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86543 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86544 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86545 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86546 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86547 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86548 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86549 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86550 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86551 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86552 +_002629_hash read_dma 3 55086 _002629_hash NULL
86553 +_002630_hash read_fifo 3 826 _002630_hash NULL
86554 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86555 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86556 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86557 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86558 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86559 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86560 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86561 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86562 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86563 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86564 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86565 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86566 +_002644_hash rx_data 4 60442 _002644_hash NULL
86567 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86568 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86569 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86570 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86571 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86572 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86573 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86574 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86575 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86576 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86577 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86578 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86579 +_002658_hash send_stream 4 3397 _002658_hash NULL
86580 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86581 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86582 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86583 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86584 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86585 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86586 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86587 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86588 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86589 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86590 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86591 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86592 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86593 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86594 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86595 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86596 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86597 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86598 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86599 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86600 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86601 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86602 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86603 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86604 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86605 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86606 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86607 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86608 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86609 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86610 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86611 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86612 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86613 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86614 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86615 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86616 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86617 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86618 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86619 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86620 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86621 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86622 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86623 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86624 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86625 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86626 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86627 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86628 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86629 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86630 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86631 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86632 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86633 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86634 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86635 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86636 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86637 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86638 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86639 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86640 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86641 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86642 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86643 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86644 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86645 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86646 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86647 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86648 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86649 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86650 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86651 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86652 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86653 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86654 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86655 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86656 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86657 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86658 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86659 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86660 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86661 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86662 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86663 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86664 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86665 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86666 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86667 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86668 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86669 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86670 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86671 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86672 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86673 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86674 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86675 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86676 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86677 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86678 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86679 +_002770_hash push_rx 3 28939 _002770_hash NULL
86680 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86681 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86682 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86683 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86684 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86685 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86686 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86687 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86688 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86689 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86690 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86691 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86692 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86693 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86694 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86695 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86696 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86697 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86698 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86699 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86700 +_002794_hash write_leb 5 36957 _002794_hash NULL
86701 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86702 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86703 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86704 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86705 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86706 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86707 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86708 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86709 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86710 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86711 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86712 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86713 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86714 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86715 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86716 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86717 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86718 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86719 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86720 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86721 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86722 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86723 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86724 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86725 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86726 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86727 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86728 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86729 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86730 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86731 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86732 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86733 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86734 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86735 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86736 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86737 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86738 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86739 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86740 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86741 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86742 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86743 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86744 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86745 +_002846_hash recover_head 3 17904 _002846_hash NULL
86746 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86747 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86748 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86749 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86750 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86751 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86752 +_002853_hash write_head 4 30481 _002853_hash NULL
86753 +_002854_hash write_node 4 33121 _002854_hash NULL
86754 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86755 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86756 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86757 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86758 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86759 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86760 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86761 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86762 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86763 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86764 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86765 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86766 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86767 +_002869_hash create_log 2 8225 _002869_hash NULL
86768 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86769 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86770 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86771 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86772 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86773 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86774 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86775 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86776 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86777 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86778 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86779 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86780 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86781 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86782 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86783 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86784 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86785 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86786 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86787 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86788 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86789 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86790 +_002893_hash _malloc 1 54077 _002893_hash NULL
86791 +_002894_hash mei_read 3 6507 _002894_hash NULL
86792 +_002895_hash mei_write 3 4005 _002895_hash NULL
86793 +_002896_hash msg_set 3 51725 _002896_hash NULL
86794 +_002897_hash newpart 6 47485 _002897_hash NULL
86795 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86796 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86797 +_002900_hash packet_came 3 18072 _002900_hash NULL
86798 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86799 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86800 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86801 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86802 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86803 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86804 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86805 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86806 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86807 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86808 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86809 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86810 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86811 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86812 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86813 +_002923_hash sep_read 3 17161 _002923_hash NULL
86814 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86815 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86816 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86817 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86818 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86819 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86820 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86821 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86822 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86823 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86824 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86825 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86826 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86827 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86828 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86829 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86830 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86831 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86832 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86833 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86834 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86835 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86836 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86837 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86838 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86839 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86840 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86841 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86842 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86843 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86844 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86845 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86846 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86847 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86848 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86849 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86850 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86851 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86852 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86853 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86854 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86855 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86856 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86857 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86858 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86859 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86860 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86861 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86862 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86863 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86864 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86865 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86866 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86867 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86868 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86869 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86870 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86871 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86872 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86873 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86874 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86875 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86876 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86877 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86878 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86879 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86880 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86881 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86882 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86883 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86884 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86885 +_003003_hash flash_read 3 57843 _003003_hash NULL
86886 +_003004_hash flash_write 3 62354 _003004_hash NULL
86887 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86888 +_003006_hash gather_array 3 56641 _003006_hash NULL
86889 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86890 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86891 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86892 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86893 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86894 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86895 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86896 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86897 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86898 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86899 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86900 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86901 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86902 +_003021_hash options_write 3 47243 _003021_hash NULL
86903 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86904 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86905 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86906 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86907 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86908 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86909 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86910 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86911 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86912 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86913 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86914 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86915 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86916 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86917 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86918 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86919 +_003038_hash split 2 11691 _003038_hash NULL
86920 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86921 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86922 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86923 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86924 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86925 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86926 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86927 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86928 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86929 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86930 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86931 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86932 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86933 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86934 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86935 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86936 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86937 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86938 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86939 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86940 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86941 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86942 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86943 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86944 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86945 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86946 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86947 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86948 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86949 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86950 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86951 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86952 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86953 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86954 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86955 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86956 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86957 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86958 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86959 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86960 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86961 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86962 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86963 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86964 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86965 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86966 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86967 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86968 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86969 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86970 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86971 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86972 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86973 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86974 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86975 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86976 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86977 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86978 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86979 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86980 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86981 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86982 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86983 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86984 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86985 +_003108_hash conf_read 3 55786 _003108_hash NULL
86986 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86987 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86988 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86989 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86990 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86991 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86992 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86993 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86994 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86995 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86996 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86997 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86998 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86999 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
87000 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
87001 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
87002 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
87003 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
87004 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
87005 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
87006 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
87007 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
87008 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
87009 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
87010 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
87011 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
87012 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
87013 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
87014 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
87015 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
87016 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
87017 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
87018 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
87019 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
87020 +_003146_hash dvb_play 3 50814 _003146_hash NULL
87021 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
87022 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
87023 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
87024 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
87025 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
87026 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
87027 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
87028 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
87029 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
87030 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
87031 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
87032 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
87033 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
87034 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
87035 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
87036 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
87037 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
87038 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
87039 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
87040 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
87041 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
87042 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
87043 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
87044 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
87045 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
87046 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
87047 +_003175_hash get_info 3 55681 _003175_hash NULL
87048 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
87049 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
87050 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
87051 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
87052 +_003180_hash hsc_write 3 55875 _003180_hash NULL
87053 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
87054 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
87055 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
87056 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
87057 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
87058 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
87059 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
87060 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
87061 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87062 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87063 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87064 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87065 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87066 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87067 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87068 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87069 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87070 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87071 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87072 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87073 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87074 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87075 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87076 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87077 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87078 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87079 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87080 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87081 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87082 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87083 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87084 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87085 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87086 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87087 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87088 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87089 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87090 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87091 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87092 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87093 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87094 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87095 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87096 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87097 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87098 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87099 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87100 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87101 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87102 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87103 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87104 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87105 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87106 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87107 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87108 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87109 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87110 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87111 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87112 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87113 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87114 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87115 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87116 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87117 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87118 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87119 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87120 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87121 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87122 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87123 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87124 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87125 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87126 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87127 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87128 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87129 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87130 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87131 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87132 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87133 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87134 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87135 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87136 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87137 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87138 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87139 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87140 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87141 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87142 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87143 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87144 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87145 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87146 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87147 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87148 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87149 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87150 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87151 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87152 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87153 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87154 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87155 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87156 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87157 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87158 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87159 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87160 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87161 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87162 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87163 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87164 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87165 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87166 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87167 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87168 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87169 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87170 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87171 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87172 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87173 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87174 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87175 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87176 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87177 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87178 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87179 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87180 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87181 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87182 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87183 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87184 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87185 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87186 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87187 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87188 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87189 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87190 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87191 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87192 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87193 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87194 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87195 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87196 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87197 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87198 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87199 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87200 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87201 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87202 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87203 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87204 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87205 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87206 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87207 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87208 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87209 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87210 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87211 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87212 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87213 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87214 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87215 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87216 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87217 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87218 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87219 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87220 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87221 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87222 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87223 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87224 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87225 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87226 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87227 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87228 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87229 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87230 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87231 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87232 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87233 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87234 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87235 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87236 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87237 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87238 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87239 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87240 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87241 +_003377_hash dev_read 3 56369 _003377_hash NULL
87242 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87243 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87244 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87245 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87246 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87247 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87248 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87249 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87250 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87251 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87252 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87253 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87254 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87255 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87256 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87257 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87258 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87259 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87260 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87261 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87262 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87263 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87264 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87265 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87266 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87267 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87268 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87269 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87270 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87271 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87272 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87273 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87274 +_003412_hash fb_read 3 33506 _003412_hash NULL
87275 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87276 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87277 +_003415_hash fb_write 3 46924 _003415_hash NULL
87278 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87279 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87280 +_003418_hash fops_read 3 40672 _003418_hash NULL
87281 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87282 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87283 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87284 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87285 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87286 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87287 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87288 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87289 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87290 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87291 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87292 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87293 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87294 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87295 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87296 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87297 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87298 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87299 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87300 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87301 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87302 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87303 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87304 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87305 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87306 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87307 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87308 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87309 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87310 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87311 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87312 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87313 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87314 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87315 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87316 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87317 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87318 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87319 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87320 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87321 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87322 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87323 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87324 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87325 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87326 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87327 +_003468_hash odev_update 2 50169 _003468_hash NULL
87328 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87329 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87330 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87331 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87332 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87333 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87334 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87335 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87336 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87337 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87338 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87339 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87340 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87341 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87342 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87343 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87344 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87345 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87346 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87347 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87348 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87349 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87350 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87351 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87352 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87353 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87354 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87355 +_003498_hash probes_write 3 29711 _003498_hash NULL
87356 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87357 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87358 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87359 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87360 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87361 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87362 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87363 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87364 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87365 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87366 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87367 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87368 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87369 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87370 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87371 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87372 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87373 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87374 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87375 +_003518_hash Realloc 2 34961 _003518_hash NULL
87376 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87377 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87378 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87379 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87380 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87381 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87382 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87383 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87384 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87385 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87386 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87387 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87388 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87389 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87390 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87391 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87392 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87393 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87394 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87395 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87396 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87397 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87398 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87399 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87400 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87401 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87402 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87403 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87404 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87405 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87406 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87407 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87408 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87409 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87410 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87411 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87412 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87413 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87414 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87415 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87416 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87417 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87418 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87419 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87420 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87421 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87422 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87423 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87424 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87425 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87426 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87427 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87428 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87429 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87430 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87431 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87432 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87433 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87434 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87435 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87436 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87437 +_003584_hash ts_read 3 44687 _003584_hash NULL
87438 +_003585_hash ts_write 3 64336 _003585_hash NULL
87439 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87440 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87441 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87442 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87443 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87444 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87445 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87446 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87447 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87448 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87449 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87450 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87451 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87452 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87453 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87454 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87455 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87456 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87457 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87458 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87459 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87460 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87461 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87462 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87463 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87464 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87465 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87466 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87467 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87468 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87469 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87470 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87471 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87472 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87473 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87474 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87475 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87476 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87477 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87478 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87479 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87480 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87481 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87482 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87483 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87484 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87485 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87486 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87487 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87488 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87489 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87490 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87491 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87492 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87493 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87494 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87495 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87496 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87497 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87498 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87499 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87500 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87501 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87502 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87503 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87504 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87505 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87506 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87507 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87508 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87509 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87510 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87511 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87512 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87513 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87514 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87515 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87516 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87517 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87518 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87519 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87520 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87521 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87522 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87523 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87524 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87525 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87526 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87527 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87528 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87529 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87530 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87531 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87532 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87533 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87534 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87535 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87536 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87537 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87538 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87539 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87540 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87541 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87542 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87543 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87544 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87545 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87546 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87547 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87548 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87549 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87550 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87551 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87552 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87553 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87554 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87555 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87556 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87557 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87558 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87559 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87560 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87561 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87562 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87563 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87564 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87565 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87566 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87567 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87568 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87569 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87570 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87571 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87572 +_003729_hash vmap 2 15025 _003729_hash NULL
87573 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87574 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87575 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87576 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87577 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87578 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87579 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87580 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87581 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87582 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87583 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87584 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87585 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87586 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87587 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87588 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87589 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87590 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87591 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87592 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87593 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87594 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87595 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87596 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87597 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87598 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87599 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87600 +_003766_hash video_read 3 28148 _003766_hash NULL
87601 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87602 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87603 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87604 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87605 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87606 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87607 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87608 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87609 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87610 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87611 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87612 +_003783_hash do_test 1 15766 _003783_hash NULL
87613 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87614 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87615 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87616 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87617 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87618 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87619 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87620 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87621 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87622 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87623 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87624 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87625 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87626 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87627 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87628 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87629 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87630 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87631 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87632 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87633 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87634 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87635 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87636 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87637 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87638 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87639 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87640 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87641 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87642 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87643 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87644 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87645 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87646 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87647 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87648 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87649 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87650 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87651 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87652 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87653 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87654 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87655 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87656 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87657 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87658 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87659 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87660 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87661 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87662 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87663 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87664 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87665 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87666 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87667 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87668 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87669 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87670 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87671 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87672 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87673 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87674 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87675 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87676 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87677 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87678 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87679 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87680 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87681 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87682 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87683 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87684 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87685 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87686 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87687 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87688 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87689 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87690 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87691 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87692 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87693 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87694 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87695 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87696 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87697 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87698 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87699 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87700 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87701 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87702 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87703 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87704 new file mode 100644
87705 index 0000000..1aa0dce
87706 --- /dev/null
87707 +++ b/tools/gcc/size_overflow_plugin.c
87708 @@ -0,0 +1,1865 @@
87709 +/*
87710 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87711 + * Licensed under the GPL v2, or (at your option) v3
87712 + *
87713 + * Homepage:
87714 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87715 + *
87716 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87717 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87718 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87719 + *
87720 + * Usage:
87721 + * $ 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
87722 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87723 + */
87724 +
87725 +#include "gcc-plugin.h"
87726 +#include "config.h"
87727 +#include "system.h"
87728 +#include "coretypes.h"
87729 +#include "tree.h"
87730 +#include "tree-pass.h"
87731 +#include "intl.h"
87732 +#include "plugin-version.h"
87733 +#include "tm.h"
87734 +#include "toplev.h"
87735 +#include "function.h"
87736 +#include "tree-flow.h"
87737 +#include "plugin.h"
87738 +#include "gimple.h"
87739 +#include "c-common.h"
87740 +#include "diagnostic.h"
87741 +#include "cfgloop.h"
87742 +
87743 +#if BUILDING_GCC_VERSION >= 4007
87744 +#include "c-tree.h"
87745 +#else
87746 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87747 +#endif
87748 +
87749 +struct size_overflow_hash {
87750 + const struct size_overflow_hash * const next;
87751 + const char * const name;
87752 + const unsigned int param;
87753 +};
87754 +
87755 +#include "size_overflow_hash.h"
87756 +
87757 +enum marked {
87758 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87759 +};
87760 +
87761 +#define __unused __attribute__((__unused__))
87762 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87763 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87764 +#define BEFORE_STMT true
87765 +#define AFTER_STMT false
87766 +#define CREATE_NEW_VAR NULL_TREE
87767 +#define CODES_LIMIT 32
87768 +#define MAX_PARAM 32
87769 +#define MY_STMT GF_PLF_1
87770 +#define NO_CAST_CHECK GF_PLF_2
87771 +
87772 +#if BUILDING_GCC_VERSION == 4005
87773 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87774 +#endif
87775 +
87776 +int plugin_is_GPL_compatible;
87777 +void debug_gimple_stmt(gimple gs);
87778 +
87779 +static tree expand(struct pointer_set_t *visited, tree lhs);
87780 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87781 +static tree report_size_overflow_decl;
87782 +static const_tree const_char_ptr_type_node;
87783 +static unsigned int handle_function(void);
87784 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87785 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87786 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
87787 +
87788 +static struct plugin_info size_overflow_plugin_info = {
87789 + .version = "20121113beta",
87790 + .help = "no-size-overflow\tturn off size overflow checking\n",
87791 +};
87792 +
87793 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87794 +{
87795 + unsigned int arg_count;
87796 + enum tree_code code = TREE_CODE(*node);
87797 +
87798 + switch (code) {
87799 + case FUNCTION_DECL:
87800 + arg_count = type_num_arguments(TREE_TYPE(*node));
87801 + break;
87802 + case FUNCTION_TYPE:
87803 + case METHOD_TYPE:
87804 + arg_count = type_num_arguments(*node);
87805 + break;
87806 + default:
87807 + *no_add_attrs = true;
87808 + error("%s: %qE attribute only applies to functions", __func__, name);
87809 + return NULL_TREE;
87810 + }
87811 +
87812 + for (; args; args = TREE_CHAIN(args)) {
87813 + tree position = TREE_VALUE(args);
87814 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87815 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87816 + *no_add_attrs = true;
87817 + }
87818 + }
87819 + return NULL_TREE;
87820 +}
87821 +
87822 +static const char* get_asm_name(tree node)
87823 +{
87824 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87825 +}
87826 +
87827 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87828 +{
87829 + unsigned int arg_count, arg_num;
87830 + enum tree_code code = TREE_CODE(*node);
87831 +
87832 + switch (code) {
87833 + case FUNCTION_DECL:
87834 + arg_count = type_num_arguments(TREE_TYPE(*node));
87835 + break;
87836 + case FUNCTION_TYPE:
87837 + case METHOD_TYPE:
87838 + arg_count = type_num_arguments(*node);
87839 + break;
87840 + case FIELD_DECL:
87841 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87842 + if (arg_num != 0) {
87843 + *no_add_attrs = true;
87844 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87845 + }
87846 + return NULL_TREE;
87847 + default:
87848 + *no_add_attrs = true;
87849 + error("%qE attribute only applies to functions", name);
87850 + return NULL_TREE;
87851 + }
87852 +
87853 + for (; args; args = TREE_CHAIN(args)) {
87854 + tree position = TREE_VALUE(args);
87855 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87856 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87857 + *no_add_attrs = true;
87858 + }
87859 + }
87860 + return NULL_TREE;
87861 +}
87862 +
87863 +static struct attribute_spec size_overflow_attr = {
87864 + .name = "size_overflow",
87865 + .min_length = 1,
87866 + .max_length = -1,
87867 + .decl_required = true,
87868 + .type_required = false,
87869 + .function_type_required = false,
87870 + .handler = handle_size_overflow_attribute,
87871 +#if BUILDING_GCC_VERSION >= 4007
87872 + .affects_type_identity = false
87873 +#endif
87874 +};
87875 +
87876 +static struct attribute_spec intentional_overflow_attr = {
87877 + .name = "intentional_overflow",
87878 + .min_length = 1,
87879 + .max_length = -1,
87880 + .decl_required = true,
87881 + .type_required = false,
87882 + .function_type_required = false,
87883 + .handler = handle_intentional_overflow_attribute,
87884 +#if BUILDING_GCC_VERSION >= 4007
87885 + .affects_type_identity = false
87886 +#endif
87887 +};
87888 +
87889 +static void register_attributes(void __unused *event_data, void __unused *data)
87890 +{
87891 + register_attribute(&size_overflow_attr);
87892 + register_attribute(&intentional_overflow_attr);
87893 +}
87894 +
87895 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87896 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87897 +{
87898 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87899 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87900 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87901 +
87902 + unsigned int m = 0x57559429;
87903 + unsigned int n = 0x5052acdb;
87904 + const unsigned int *key4 = (const unsigned int *)key;
87905 + unsigned int h = len;
87906 + unsigned int k = len + seed + n;
87907 + unsigned long long p;
87908 +
87909 + while (len >= 8) {
87910 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87911 + len -= 8;
87912 + }
87913 + if (len >= 4) {
87914 + cwmixb(key4[0]) key4 += 1;
87915 + len -= 4;
87916 + }
87917 + if (len)
87918 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87919 + cwmixb(h ^ (k + n));
87920 + return k ^ h;
87921 +
87922 +#undef cwfold
87923 +#undef cwmixa
87924 +#undef cwmixb
87925 +}
87926 +
87927 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87928 +{
87929 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87930 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87931 + return fn ^ codes;
87932 +}
87933 +
87934 +static inline tree get_original_function_decl(tree fndecl)
87935 +{
87936 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87937 + return DECL_ABSTRACT_ORIGIN(fndecl);
87938 + return fndecl;
87939 +}
87940 +
87941 +static inline gimple get_def_stmt(const_tree node)
87942 +{
87943 + gcc_assert(node != NULL_TREE);
87944 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87945 + return SSA_NAME_DEF_STMT(node);
87946 +}
87947 +
87948 +static unsigned char get_tree_code(const_tree type)
87949 +{
87950 + switch (TREE_CODE(type)) {
87951 + case ARRAY_TYPE:
87952 + return 0;
87953 + case BOOLEAN_TYPE:
87954 + return 1;
87955 + case ENUMERAL_TYPE:
87956 + return 2;
87957 + case FUNCTION_TYPE:
87958 + return 3;
87959 + case INTEGER_TYPE:
87960 + return 4;
87961 + case POINTER_TYPE:
87962 + return 5;
87963 + case RECORD_TYPE:
87964 + return 6;
87965 + case UNION_TYPE:
87966 + return 7;
87967 + case VOID_TYPE:
87968 + return 8;
87969 + case REAL_TYPE:
87970 + return 9;
87971 + case VECTOR_TYPE:
87972 + return 10;
87973 + case REFERENCE_TYPE:
87974 + return 11;
87975 + case OFFSET_TYPE:
87976 + return 12;
87977 + case COMPLEX_TYPE:
87978 + return 13;
87979 + default:
87980 + debug_tree((tree)type);
87981 + gcc_unreachable();
87982 + }
87983 +}
87984 +
87985 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87986 +{
87987 + gcc_assert(type != NULL_TREE);
87988 +
87989 + while (type && len < CODES_LIMIT) {
87990 + tree_codes[len] = get_tree_code(type);
87991 + len++;
87992 + type = TREE_TYPE(type);
87993 + }
87994 + return len;
87995 +}
87996 +
87997 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87998 +{
87999 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88000 + enum tree_code code = TREE_CODE(type);
88001 + size_t len = 0;
88002 +
88003 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88004 +
88005 + arg = TYPE_ARG_TYPES(type);
88006 + // skip builtins __builtin_constant_p
88007 + if (!arg && DECL_BUILT_IN(fndecl))
88008 + return 0;
88009 +
88010 + if (TREE_CODE_CLASS(code) == tcc_type)
88011 + result = type;
88012 + else
88013 + result = DECL_RESULT(fndecl);
88014 +
88015 + gcc_assert(result != NULL_TREE);
88016 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88017 +
88018 + if (arg == NULL_TREE) {
88019 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88020 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88021 + if (arg_field == NULL_TREE)
88022 + return 0;
88023 + arg = TREE_TYPE(arg_field);
88024 + len = add_type_codes(arg, tree_codes, len);
88025 + gcc_assert(len != 0);
88026 + return len;
88027 + }
88028 +
88029 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88030 + while (arg && len < CODES_LIMIT) {
88031 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88032 + arg = TREE_CHAIN(arg);
88033 + }
88034 +
88035 + gcc_assert(len != 0);
88036 + return len;
88037 +}
88038 +
88039 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88040 +{
88041 + unsigned int hash;
88042 + const struct size_overflow_hash *entry;
88043 + unsigned char tree_codes[CODES_LIMIT];
88044 + size_t len;
88045 + const char *func_name = get_asm_name(fndecl);
88046 +
88047 + len = get_function_decl(fndecl, tree_codes);
88048 + if (len == 0)
88049 + return NULL;
88050 +
88051 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88052 +
88053 + entry = size_overflow_hash[hash];
88054 + while (entry) {
88055 + if (!strcmp(entry->name, func_name))
88056 + return entry;
88057 + entry = entry->next;
88058 + }
88059 +
88060 + return NULL;
88061 +}
88062 +
88063 +static void check_arg_type(const_tree arg)
88064 +{
88065 + const_tree type = TREE_TYPE(arg);
88066 + enum tree_code code = TREE_CODE(type);
88067 +
88068 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88069 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88070 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88071 +}
88072 +
88073 +static int find_arg_number(const_tree arg, tree func)
88074 +{
88075 + tree var;
88076 + unsigned int argnum = 1;
88077 +
88078 + if (TREE_CODE(arg) == SSA_NAME)
88079 + arg = SSA_NAME_VAR(arg);
88080 +
88081 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88082 + if (strcmp(NAME(arg), NAME(var))) {
88083 + argnum++;
88084 + continue;
88085 + }
88086 + check_arg_type(var);
88087 + return argnum;
88088 + }
88089 + gcc_unreachable();
88090 +}
88091 +
88092 +static tree create_new_var(tree type)
88093 +{
88094 + tree new_var = create_tmp_var(type, "cicus");
88095 +
88096 + add_referenced_var(new_var);
88097 + mark_sym_for_renaming(new_var);
88098 + return new_var;
88099 +}
88100 +
88101 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88102 +{
88103 + gimple assign;
88104 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88105 + tree type = TREE_TYPE(rhs1);
88106 + tree lhs = create_new_var(type);
88107 +
88108 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88109 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88110 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88111 +
88112 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88113 + update_stmt(assign);
88114 + gimple_set_plf(assign, MY_STMT, true);
88115 + return assign;
88116 +}
88117 +
88118 +static bool is_bool(const_tree node)
88119 +{
88120 + const_tree type;
88121 +
88122 + if (node == NULL_TREE)
88123 + return false;
88124 +
88125 + type = TREE_TYPE(node);
88126 + if (!INTEGRAL_TYPE_P(type))
88127 + return false;
88128 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88129 + return true;
88130 + if (TYPE_PRECISION(type) == 1)
88131 + return true;
88132 + return false;
88133 +}
88134 +
88135 +static tree cast_a_tree(tree type, tree var)
88136 +{
88137 + gcc_assert(type != NULL_TREE);
88138 + gcc_assert(var != NULL_TREE);
88139 + gcc_assert(fold_convertible_p(type, var));
88140 +
88141 + return fold_convert(type, var);
88142 +}
88143 +
88144 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88145 +{
88146 + gimple assign;
88147 +
88148 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88149 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88150 + gcc_unreachable();
88151 +
88152 + if (lhs == CREATE_NEW_VAR)
88153 + lhs = create_new_var(dst_type);
88154 +
88155 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88156 +
88157 + if (!gsi_end_p(*gsi)) {
88158 + location_t loc = gimple_location(gsi_stmt(*gsi));
88159 + gimple_set_location(assign, loc);
88160 + }
88161 +
88162 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88163 +
88164 + if (before)
88165 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88166 + else
88167 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88168 + update_stmt(assign);
88169 + gimple_set_plf(assign, MY_STMT, true);
88170 +
88171 + return assign;
88172 +}
88173 +
88174 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88175 +{
88176 + gimple assign;
88177 + gimple_stmt_iterator gsi;
88178 +
88179 + if (rhs == NULL_TREE)
88180 + return NULL_TREE;
88181 +
88182 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88183 + return rhs;
88184 +
88185 + gsi = gsi_for_stmt(stmt);
88186 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88187 + gimple_set_plf(assign, MY_STMT, true);
88188 + return gimple_get_lhs(assign);
88189 +}
88190 +
88191 +static tree cast_to_TI_type(gimple stmt, tree node)
88192 +{
88193 + gimple_stmt_iterator gsi;
88194 + gimple cast_stmt;
88195 + tree type = TREE_TYPE(node);
88196 +
88197 + if (types_compatible_p(type, intTI_type_node))
88198 + return node;
88199 +
88200 + gsi = gsi_for_stmt(stmt);
88201 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88202 + gimple_set_plf(cast_stmt, MY_STMT, true);
88203 + return gimple_get_lhs(cast_stmt);
88204 +}
88205 +
88206 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88207 +{
88208 + tree lhs;
88209 + gimple_stmt_iterator gsi;
88210 +
88211 + if (rhs1 == NULL_TREE) {
88212 + debug_gimple_stmt(oldstmt);
88213 + error("%s: rhs1 is NULL_TREE", __func__);
88214 + gcc_unreachable();
88215 + }
88216 +
88217 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88218 + lhs = rhs1;
88219 + else
88220 + lhs = gimple_get_lhs(oldstmt);
88221 +
88222 + gsi = gsi_for_stmt(oldstmt);
88223 + pointer_set_insert(visited, oldstmt);
88224 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88225 + basic_block next_bb, cur_bb;
88226 + const_edge e;
88227 +
88228 + gcc_assert(before == false);
88229 + gcc_assert(stmt_can_throw_internal(oldstmt));
88230 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88231 + gcc_assert(!gsi_end_p(gsi));
88232 +
88233 + cur_bb = gimple_bb(oldstmt);
88234 + next_bb = cur_bb->next_bb;
88235 + e = find_edge(cur_bb, next_bb);
88236 + gcc_assert(e != NULL);
88237 + gcc_assert(e->flags & EDGE_FALLTHRU);
88238 +
88239 + gsi = gsi_after_labels(next_bb);
88240 + gcc_assert(!gsi_end_p(gsi));
88241 +
88242 + before = true;
88243 + oldstmt = gsi_stmt(gsi);
88244 + }
88245 +
88246 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88247 +}
88248 +
88249 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88250 +{
88251 + gimple stmt;
88252 + gimple_stmt_iterator gsi;
88253 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88254 +
88255 + if (gimple_plf(oldstmt, MY_STMT))
88256 + return lhs;
88257 +
88258 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88259 + rhs1 = gimple_assign_rhs1(oldstmt);
88260 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88261 + }
88262 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88263 + rhs2 = gimple_assign_rhs2(oldstmt);
88264 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88265 + }
88266 +
88267 + stmt = gimple_copy(oldstmt);
88268 + gimple_set_location(stmt, gimple_location(oldstmt));
88269 + gimple_set_plf(stmt, MY_STMT, true);
88270 +
88271 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88272 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88273 +
88274 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88275 +
88276 + if (is_bool(lhs))
88277 + new_var = SSA_NAME_VAR(lhs);
88278 + else
88279 + new_var = create_new_var(size_overflow_type);
88280 + new_var = make_ssa_name(new_var, stmt);
88281 + gimple_set_lhs(stmt, new_var);
88282 +
88283 + if (rhs1 != NULL_TREE) {
88284 + if (!gimple_assign_cast_p(oldstmt) && TREE_CODE_CLASS(gimple_assign_rhs_code(oldstmt)) != tcc_comparison)
88285 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88286 + gimple_assign_set_rhs1(stmt, rhs1);
88287 + }
88288 +
88289 + if (rhs2 != NULL_TREE)
88290 + gimple_assign_set_rhs2(stmt, rhs2);
88291 +#if BUILDING_GCC_VERSION >= 4007
88292 + if (rhs3 != NULL_TREE)
88293 + gimple_assign_set_rhs3(stmt, rhs3);
88294 +#endif
88295 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88296 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88297 +
88298 + gsi = gsi_for_stmt(oldstmt);
88299 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88300 + update_stmt(stmt);
88301 + pointer_set_insert(visited, oldstmt);
88302 + return gimple_get_lhs(stmt);
88303 +}
88304 +
88305 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88306 +{
88307 + basic_block bb;
88308 + gimple phi;
88309 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88310 +
88311 + bb = gsi_bb(gsi);
88312 +
88313 + phi = create_phi_node(result, bb);
88314 + gsi = gsi_last(phi_nodes(bb));
88315 + gsi_remove(&gsi, false);
88316 +
88317 + gsi = gsi_for_stmt(oldstmt);
88318 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88319 + gimple_set_bb(phi, bb);
88320 + gimple_set_plf(phi, MY_STMT, true);
88321 + return phi;
88322 +}
88323 +
88324 +static basic_block create_a_first_bb(void)
88325 +{
88326 + basic_block first_bb;
88327 +
88328 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88329 + if (dom_info_available_p(CDI_DOMINATORS))
88330 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88331 + return first_bb;
88332 +}
88333 +
88334 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88335 +{
88336 + basic_block bb;
88337 + const_gimple newstmt;
88338 + gimple_stmt_iterator gsi;
88339 + bool before = BEFORE_STMT;
88340 +
88341 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88342 + gsi = gsi_for_stmt(get_def_stmt(arg));
88343 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88344 + return gimple_get_lhs(newstmt);
88345 + }
88346 +
88347 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88348 + gsi = gsi_after_labels(bb);
88349 + if (bb->index == 0) {
88350 + bb = create_a_first_bb();
88351 + gsi = gsi_start_bb(bb);
88352 + }
88353 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88354 + return gimple_get_lhs(newstmt);
88355 +}
88356 +
88357 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88358 +{
88359 + gimple newstmt;
88360 + gimple_stmt_iterator gsi;
88361 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88362 + gimple def_newstmt = get_def_stmt(new_rhs);
88363 +
88364 + gsi_insert = gsi_insert_after;
88365 + gsi = gsi_for_stmt(def_newstmt);
88366 +
88367 + switch (gimple_code(get_def_stmt(arg))) {
88368 + case GIMPLE_PHI:
88369 + newstmt = gimple_build_assign(new_var, new_rhs);
88370 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88371 + gsi_insert = gsi_insert_before;
88372 + break;
88373 + case GIMPLE_ASM:
88374 + case GIMPLE_CALL:
88375 + newstmt = gimple_build_assign(new_var, new_rhs);
88376 + break;
88377 + case GIMPLE_ASSIGN:
88378 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88379 + break;
88380 + default:
88381 + /* unknown gimple_code (handle_build_new_phi_arg) */
88382 + gcc_unreachable();
88383 + }
88384 +
88385 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88386 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88387 + gimple_set_plf(newstmt, MY_STMT, true);
88388 + update_stmt(newstmt);
88389 + return newstmt;
88390 +}
88391 +
88392 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88393 +{
88394 + const_gimple newstmt;
88395 + gimple def_stmt;
88396 + tree new_rhs;
88397 +
88398 + new_rhs = expand(visited, arg);
88399 + if (new_rhs == NULL_TREE)
88400 + return NULL_TREE;
88401 +
88402 + def_stmt = get_def_stmt(new_rhs);
88403 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88404 + return NULL_TREE;
88405 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88406 +
88407 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88408 + return gimple_get_lhs(newstmt);
88409 +}
88410 +
88411 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88412 +{
88413 + gimple phi, oldstmt = get_def_stmt(orig_result);
88414 + tree new_result, size_overflow_type;
88415 + unsigned int i;
88416 + unsigned int n = gimple_phi_num_args(oldstmt);
88417 +
88418 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88419 +
88420 + new_result = create_new_var(size_overflow_type);
88421 +
88422 + pointer_set_insert(visited, oldstmt);
88423 + phi = overflow_create_phi_node(oldstmt, new_result);
88424 + for (i = 0; i < n; i++) {
88425 + tree arg, lhs;
88426 +
88427 + arg = gimple_phi_arg_def(oldstmt, i);
88428 + if (is_gimple_constant(arg))
88429 + arg = cast_a_tree(size_overflow_type, arg);
88430 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88431 + if (lhs == NULL_TREE)
88432 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88433 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88434 + }
88435 +
88436 + update_stmt(phi);
88437 + return gimple_phi_result(phi);
88438 +}
88439 +
88440 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88441 +{
88442 + const_gimple assign;
88443 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88444 + tree origtype = TREE_TYPE(orig_rhs);
88445 +
88446 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88447 +
88448 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88449 + return gimple_get_lhs(assign);
88450 +}
88451 +
88452 +static void change_rhs1(gimple stmt, tree new_rhs1)
88453 +{
88454 + tree assign_rhs;
88455 + const_tree rhs = gimple_assign_rhs1(stmt);
88456 +
88457 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88458 + gimple_assign_set_rhs1(stmt, assign_rhs);
88459 + update_stmt(stmt);
88460 +}
88461 +
88462 +static bool check_mode_type(const_gimple stmt)
88463 +{
88464 + const_tree lhs = gimple_get_lhs(stmt);
88465 + const_tree lhs_type = TREE_TYPE(lhs);
88466 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88467 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88468 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88469 +
88470 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88471 + return false;
88472 +
88473 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88474 + return false;
88475 +
88476 + return true;
88477 +}
88478 +
88479 +static bool check_undefined_integer_operation(const_gimple stmt)
88480 +{
88481 + const_gimple def_stmt;
88482 + const_tree lhs = gimple_get_lhs(stmt);
88483 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88484 + const_tree rhs1_type = TREE_TYPE(rhs1);
88485 + const_tree lhs_type = TREE_TYPE(lhs);
88486 +
88487 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88488 + return false;
88489 +
88490 + def_stmt = get_def_stmt(rhs1);
88491 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88492 + return false;
88493 +
88494 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88495 + return false;
88496 + return true;
88497 +}
88498 +
88499 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88500 +{
88501 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88502 + enum machine_mode lhs_mode, rhs_mode;
88503 + gimple def_stmt = get_def_stmt(no_const_rhs);
88504 +
88505 + if (!gimple_assign_cast_p(def_stmt))
88506 + return false;
88507 +
88508 + rhs1 = gimple_assign_rhs1(def_stmt);
88509 + lhs = gimple_get_lhs(def_stmt);
88510 + rhs1_type = TREE_TYPE(rhs1);
88511 + lhs_type = TREE_TYPE(lhs);
88512 + rhs_mode = TYPE_MODE(rhs1_type);
88513 + lhs_mode = TYPE_MODE(lhs_type);
88514 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88515 + return false;
88516 +
88517 + return true;
88518 +}
88519 +
88520 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88521 +{
88522 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88523 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88524 + const_tree rhs1_type = TREE_TYPE(rhs1);
88525 + const_tree lhs_type = TREE_TYPE(lhs);
88526 +
88527 + new_rhs1 = expand(visited, rhs1);
88528 +
88529 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88530 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88531 +
88532 + if (gimple_plf(stmt, MY_STMT))
88533 + return lhs;
88534 +
88535 + if (gimple_plf(stmt, NO_CAST_CHECK))
88536 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88537 +
88538 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88539 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88540 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88541 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88542 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88543 + }
88544 +
88545 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88546 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88547 +
88548 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88549 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88550 +
88551 + change_rhs1(stmt, new_rhs1);
88552 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88553 +
88554 + rhs1 = gimple_assign_rhs1(stmt);
88555 + rhs1_type = TREE_TYPE(rhs1);
88556 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88557 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88558 +
88559 + if (!check_mode_type(stmt))
88560 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88561 +
88562 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88563 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88564 +
88565 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88566 +
88567 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88568 +}
88569 +
88570 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88571 +{
88572 + gimple def_stmt = get_def_stmt(lhs);
88573 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88574 +
88575 + if (is_gimple_constant(rhs1))
88576 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88577 +
88578 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88579 + switch (TREE_CODE(rhs1)) {
88580 + case SSA_NAME:
88581 + return handle_unary_rhs(visited, def_stmt);
88582 + case ARRAY_REF:
88583 + case BIT_FIELD_REF:
88584 + case ADDR_EXPR:
88585 + case COMPONENT_REF:
88586 + case INDIRECT_REF:
88587 +#if BUILDING_GCC_VERSION >= 4006
88588 + case MEM_REF:
88589 +#endif
88590 + case PARM_DECL:
88591 + case TARGET_MEM_REF:
88592 + case VAR_DECL:
88593 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88594 +
88595 + default:
88596 + debug_gimple_stmt(def_stmt);
88597 + debug_tree(rhs1);
88598 + gcc_unreachable();
88599 + }
88600 +}
88601 +
88602 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88603 +{
88604 + gimple cond_stmt;
88605 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88606 +
88607 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88608 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88609 + update_stmt(cond_stmt);
88610 +}
88611 +
88612 +static tree create_string_param(tree string)
88613 +{
88614 + tree i_type, a_type;
88615 + const int length = TREE_STRING_LENGTH(string);
88616 +
88617 + gcc_assert(length > 0);
88618 +
88619 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88620 + a_type = build_array_type(char_type_node, i_type);
88621 +
88622 + TREE_TYPE(string) = a_type;
88623 + TREE_CONSTANT(string) = 1;
88624 + TREE_READONLY(string) = 1;
88625 +
88626 + return build1(ADDR_EXPR, ptr_type_node, string);
88627 +}
88628 +
88629 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88630 +{
88631 + gimple func_stmt;
88632 + const_gimple def_stmt;
88633 + const_tree loc_line;
88634 + tree loc_file, ssa_name, current_func;
88635 + expanded_location xloc;
88636 + char ssa_name_buf[256];
88637 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88638 +
88639 + def_stmt = get_def_stmt(arg);
88640 + xloc = expand_location(gimple_location(def_stmt));
88641 +
88642 + if (!gimple_has_location(def_stmt)) {
88643 + xloc = expand_location(gimple_location(stmt));
88644 + if (!gimple_has_location(stmt))
88645 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88646 + }
88647 +
88648 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88649 +
88650 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88651 + loc_file = create_string_param(loc_file);
88652 +
88653 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88654 + current_func = create_string_param(current_func);
88655 +
88656 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88657 + ssa_name = build_string(256, ssa_name_buf);
88658 + ssa_name = create_string_param(ssa_name);
88659 +
88660 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88661 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88662 +
88663 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88664 +}
88665 +
88666 +static void __unused print_the_code_insertions(const_gimple stmt)
88667 +{
88668 + location_t loc = gimple_location(stmt);
88669 +
88670 + inform(loc, "Integer size_overflow check applied here.");
88671 +}
88672 +
88673 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88674 +{
88675 + basic_block cond_bb, join_bb, bb_true;
88676 + edge e;
88677 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88678 +
88679 + cond_bb = gimple_bb(stmt);
88680 + if (before)
88681 + gsi_prev(&gsi);
88682 + if (gsi_end_p(gsi))
88683 + e = split_block_after_labels(cond_bb);
88684 + else
88685 + e = split_block(cond_bb, gsi_stmt(gsi));
88686 + cond_bb = e->src;
88687 + join_bb = e->dest;
88688 + e->flags = EDGE_FALSE_VALUE;
88689 + e->probability = REG_BR_PROB_BASE;
88690 +
88691 + bb_true = create_empty_bb(cond_bb);
88692 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88693 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88694 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88695 +
88696 + if (dom_info_available_p(CDI_DOMINATORS)) {
88697 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88698 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88699 + }
88700 +
88701 + if (current_loops != NULL) {
88702 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88703 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88704 + }
88705 +
88706 + insert_cond(cond_bb, arg, cond_code, type_value);
88707 + insert_cond_result(bb_true, stmt, arg, min);
88708 +
88709 +// print_the_code_insertions(stmt);
88710 +}
88711 +
88712 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88713 +{
88714 + const_tree rhs_type = TREE_TYPE(rhs);
88715 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88716 +
88717 + gcc_assert(rhs_type != NULL_TREE);
88718 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88719 + return;
88720 +
88721 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88722 +
88723 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88724 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88725 +
88726 + gcc_assert(!TREE_OVERFLOW(type_max));
88727 +
88728 + cast_rhs_type = TREE_TYPE(cast_rhs);
88729 + type_max_type = TREE_TYPE(type_max);
88730 + type_min_type = TREE_TYPE(type_min);
88731 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
88732 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
88733 +
88734 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88735 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88736 +}
88737 +
88738 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88739 +{
88740 + gimple change_rhs_def_stmt;
88741 + tree lhs = gimple_get_lhs(def_stmt);
88742 + tree lhs_type = TREE_TYPE(lhs);
88743 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88744 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88745 +
88746 + if (change_rhs == NULL_TREE)
88747 + return get_size_overflow_type(def_stmt, lhs);
88748 +
88749 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88750 +
88751 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88752 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88753 +
88754 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88755 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88756 +
88757 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88758 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88759 +
88760 + if (!types_compatible_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88761 + debug_gimple_stmt(def_stmt);
88762 + gcc_unreachable();
88763 + }
88764 +
88765 + return get_size_overflow_type(def_stmt, lhs);
88766 +}
88767 +
88768 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88769 +{
88770 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88771 + return false;
88772 + if (!is_gimple_constant(rhs))
88773 + return false;
88774 + return true;
88775 +}
88776 +
88777 +static bool is_subtraction_special(const_gimple stmt)
88778 +{
88779 + gimple rhs1_def_stmt, rhs2_def_stmt;
88780 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
88781 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
88782 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88783 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88784 +
88785 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88786 + return false;
88787 +
88788 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88789 +
88790 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
88791 + return false;
88792 +
88793 + rhs1_def_stmt = get_def_stmt(rhs1);
88794 + rhs2_def_stmt = get_def_stmt(rhs2);
88795 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88796 + return false;
88797 +
88798 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88799 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88800 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
88801 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
88802 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88803 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88804 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
88805 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
88806 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
88807 + return false;
88808 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
88809 + return false;
88810 +
88811 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88812 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88813 + return true;
88814 +}
88815 +
88816 +static tree get_def_stmt_rhs(const_tree var)
88817 +{
88818 + tree rhs1, def_stmt_rhs1;
88819 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
88820 +
88821 + def_stmt = get_def_stmt(var);
88822 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
88823 +
88824 + rhs1 = gimple_assign_rhs1(def_stmt);
88825 + rhs1_def_stmt = get_def_stmt(rhs1);
88826 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
88827 + if (!gimple_assign_cast_p(rhs1_def_stmt))
88828 + return rhs1;
88829 +
88830 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88831 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
88832 +
88833 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
88834 + case GIMPLE_CALL:
88835 + case GIMPLE_NOP:
88836 + case GIMPLE_ASM:
88837 + return def_stmt_rhs1;
88838 + case GIMPLE_ASSIGN:
88839 + return rhs1;
88840 + default:
88841 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
88842 + gcc_unreachable();
88843 + }
88844 +}
88845 +
88846 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88847 +{
88848 + tree new_rhs1, new_rhs2;
88849 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88850 + gimple assign, stmt = get_def_stmt(lhs);
88851 + tree rhs1 = gimple_assign_rhs1(stmt);
88852 + tree rhs2 = gimple_assign_rhs2(stmt);
88853 +
88854 + if (!is_subtraction_special(stmt))
88855 + return NULL_TREE;
88856 +
88857 + new_rhs1 = expand(visited, rhs1);
88858 + new_rhs2 = expand(visited, rhs2);
88859 +
88860 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
88861 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
88862 +
88863 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
88864 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
88865 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
88866 + }
88867 +
88868 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88869 + new_lhs = gimple_get_lhs(assign);
88870 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88871 +
88872 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88873 +}
88874 +
88875 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88876 +{
88877 + const_gimple def_stmt;
88878 +
88879 + if (TREE_CODE(rhs) != SSA_NAME)
88880 + return false;
88881 +
88882 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88883 + return false;
88884 +
88885 + def_stmt = get_def_stmt(rhs);
88886 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88887 + return false;
88888 +
88889 + return true;
88890 +}
88891 +
88892 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88893 +{
88894 + tree new_rhs, size_overflow_type, orig_rhs;
88895 + void (*gimple_assign_set_rhs)(gimple, tree);
88896 + tree rhs1 = gimple_assign_rhs1(stmt);
88897 + tree rhs2 = gimple_assign_rhs2(stmt);
88898 + tree lhs = gimple_get_lhs(stmt);
88899 +
88900 + if (change_rhs == NULL_TREE)
88901 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88902 +
88903 + if (new_rhs2 == NULL_TREE) {
88904 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88905 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88906 + orig_rhs = rhs1;
88907 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88908 + } else {
88909 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88910 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88911 + orig_rhs = rhs2;
88912 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88913 + }
88914 +
88915 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88916 +
88917 + if (check_overflow)
88918 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88919 +
88920 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88921 + gimple_assign_set_rhs(stmt, new_rhs);
88922 + update_stmt(stmt);
88923 +
88924 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88925 +}
88926 +
88927 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88928 +{
88929 + tree rhs1, rhs2, new_lhs;
88930 + gimple def_stmt = get_def_stmt(lhs);
88931 + tree new_rhs1 = NULL_TREE;
88932 + tree new_rhs2 = NULL_TREE;
88933 +
88934 + rhs1 = gimple_assign_rhs1(def_stmt);
88935 + rhs2 = gimple_assign_rhs2(def_stmt);
88936 +
88937 + /* no DImode/TImode division in the 32/64 bit kernel */
88938 + switch (gimple_assign_rhs_code(def_stmt)) {
88939 + case RDIV_EXPR:
88940 + case TRUNC_DIV_EXPR:
88941 + case CEIL_DIV_EXPR:
88942 + case FLOOR_DIV_EXPR:
88943 + case ROUND_DIV_EXPR:
88944 + case TRUNC_MOD_EXPR:
88945 + case CEIL_MOD_EXPR:
88946 + case FLOOR_MOD_EXPR:
88947 + case ROUND_MOD_EXPR:
88948 + case EXACT_DIV_EXPR:
88949 + case POINTER_PLUS_EXPR:
88950 + case BIT_AND_EXPR:
88951 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88952 + default:
88953 + break;
88954 + }
88955 +
88956 + new_lhs = handle_integer_truncation(visited, lhs);
88957 + if (new_lhs != NULL_TREE)
88958 + return new_lhs;
88959 +
88960 + if (TREE_CODE(rhs1) == SSA_NAME)
88961 + new_rhs1 = expand(visited, rhs1);
88962 + if (TREE_CODE(rhs2) == SSA_NAME)
88963 + new_rhs2 = expand(visited, rhs2);
88964 +
88965 + if (is_a_neg_overflow(def_stmt, rhs2))
88966 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88967 + if (is_a_neg_overflow(def_stmt, rhs1))
88968 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88969 +
88970 + if (is_a_constant_overflow(def_stmt, rhs2))
88971 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88972 + if (is_a_constant_overflow(def_stmt, rhs1))
88973 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88974 +
88975 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88976 +}
88977 +
88978 +#if BUILDING_GCC_VERSION >= 4007
88979 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88980 +{
88981 + if (is_gimple_constant(rhs))
88982 + return cast_a_tree(size_overflow_type, rhs);
88983 + if (TREE_CODE(rhs) != SSA_NAME)
88984 + return NULL_TREE;
88985 + return expand(visited, rhs);
88986 +}
88987 +
88988 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88989 +{
88990 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88991 + gimple def_stmt = get_def_stmt(lhs);
88992 +
88993 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88994 +
88995 + rhs1 = gimple_assign_rhs1(def_stmt);
88996 + rhs2 = gimple_assign_rhs2(def_stmt);
88997 + rhs3 = gimple_assign_rhs3(def_stmt);
88998 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88999 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89000 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89001 +
89002 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89003 +}
89004 +#endif
89005 +
89006 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89007 +{
89008 + const_tree type;
89009 +
89010 + gcc_assert(node != NULL_TREE);
89011 +
89012 + type = TREE_TYPE(node);
89013 +
89014 + if (gimple_plf(stmt, MY_STMT))
89015 + return TREE_TYPE(node);
89016 +
89017 + switch (TYPE_MODE(type)) {
89018 + case QImode:
89019 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89020 + case HImode:
89021 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89022 + case SImode:
89023 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89024 + case DImode:
89025 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89026 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89027 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89028 + default:
89029 + debug_tree((tree)node);
89030 + error("%s: unsupported gcc configuration.", __func__);
89031 + gcc_unreachable();
89032 + }
89033 +}
89034 +
89035 +static tree expand_visited(gimple def_stmt)
89036 +{
89037 + const_gimple next_stmt;
89038 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89039 +
89040 + gsi_next(&gsi);
89041 + next_stmt = gsi_stmt(gsi);
89042 +
89043 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89044 +
89045 + switch (gimple_code(next_stmt)) {
89046 + case GIMPLE_ASSIGN:
89047 + return gimple_get_lhs(next_stmt);
89048 + case GIMPLE_PHI:
89049 + return gimple_phi_result(next_stmt);
89050 + case GIMPLE_CALL:
89051 + return gimple_call_lhs(next_stmt);
89052 + default:
89053 + return NULL_TREE;
89054 + }
89055 +}
89056 +
89057 +static tree expand(struct pointer_set_t *visited, tree lhs)
89058 +{
89059 + gimple def_stmt;
89060 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89061 +
89062 + if (is_gimple_constant(lhs))
89063 + return NULL_TREE;
89064 +
89065 + if (TREE_CODE(lhs) == ADDR_EXPR)
89066 + return NULL_TREE;
89067 +
89068 + if (code == REAL_TYPE)
89069 + return NULL_TREE;
89070 +
89071 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89072 +
89073 +
89074 + def_stmt = get_def_stmt(lhs);
89075 +
89076 + if (!def_stmt)
89077 + return NULL_TREE;
89078 +
89079 + if (gimple_plf(def_stmt, MY_STMT))
89080 + return lhs;
89081 +
89082 + if (pointer_set_contains(visited, def_stmt))
89083 + return expand_visited(def_stmt);
89084 +
89085 + switch (gimple_code(def_stmt)) {
89086 + case GIMPLE_NOP:
89087 + return NULL_TREE;
89088 + case GIMPLE_PHI:
89089 + return build_new_phi(visited, lhs);
89090 + case GIMPLE_CALL:
89091 + case GIMPLE_ASM:
89092 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89093 + case GIMPLE_ASSIGN:
89094 + switch (gimple_num_ops(def_stmt)) {
89095 + case 2:
89096 + return handle_unary_ops(visited, lhs);
89097 + case 3:
89098 + return handle_binary_ops(visited, lhs);
89099 +#if BUILDING_GCC_VERSION >= 4007
89100 + case 4:
89101 + return handle_ternary_ops(visited, lhs);
89102 +#endif
89103 + }
89104 + default:
89105 + debug_gimple_stmt(def_stmt);
89106 + error("%s: unknown gimple code", __func__);
89107 + gcc_unreachable();
89108 + }
89109 +}
89110 +
89111 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89112 +{
89113 + const_gimple assign;
89114 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89115 + tree origtype = TREE_TYPE(origarg);
89116 +
89117 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89118 +
89119 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89120 +
89121 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89122 + update_stmt(stmt);
89123 +}
89124 +
89125 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89126 +{
89127 + const char *origid;
89128 + tree arg;
89129 + const_tree origarg;
89130 +
89131 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89132 + return true;
89133 +
89134 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89135 + while (origarg && *argnum) {
89136 + (*argnum)--;
89137 + origarg = TREE_CHAIN(origarg);
89138 + }
89139 +
89140 + gcc_assert(*argnum == 0);
89141 +
89142 + gcc_assert(origarg != NULL_TREE);
89143 + origid = NAME(origarg);
89144 + *argnum = 0;
89145 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89146 + if (!strcmp(origid, NAME(arg)))
89147 + return true;
89148 + (*argnum)++;
89149 + }
89150 + return false;
89151 +}
89152 +
89153 +static bool skip_types(const_tree var)
89154 +{
89155 + switch (TREE_CODE(var)) {
89156 + case ADDR_EXPR:
89157 +#if BUILDING_GCC_VERSION >= 4006
89158 + case MEM_REF:
89159 +#endif
89160 + case ARRAY_REF:
89161 + case BIT_FIELD_REF:
89162 + case INDIRECT_REF:
89163 + case TARGET_MEM_REF:
89164 + case VAR_DECL:
89165 + return true;
89166 + default:
89167 + break;
89168 + }
89169 + return false;
89170 +}
89171 +
89172 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89173 +{
89174 + gimple phi = get_def_stmt(result);
89175 + unsigned int i, n = gimple_phi_num_args(phi);
89176 +
89177 + if (!phi)
89178 + return false;
89179 +
89180 + pointer_set_insert(visited, phi);
89181 + for (i = 0; i < n; i++) {
89182 + const_tree arg = gimple_phi_arg_def(phi, i);
89183 + if (pre_expand(visited, arg))
89184 + return true;
89185 + }
89186 + return false;
89187 +}
89188 +
89189 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89190 +{
89191 + gimple def_stmt = get_def_stmt(lhs);
89192 + const_tree rhs;
89193 +
89194 + if (!def_stmt)
89195 + return false;
89196 +
89197 + rhs = gimple_assign_rhs1(def_stmt);
89198 + if (pre_expand(visited, rhs))
89199 + return true;
89200 + return false;
89201 +}
89202 +
89203 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89204 +{
89205 + bool rhs1_found, rhs2_found;
89206 + gimple def_stmt = get_def_stmt(lhs);
89207 + const_tree rhs1, rhs2;
89208 +
89209 + if (!def_stmt)
89210 + return false;
89211 +
89212 + rhs1 = gimple_assign_rhs1(def_stmt);
89213 + rhs2 = gimple_assign_rhs2(def_stmt);
89214 + rhs1_found = pre_expand(visited, rhs1);
89215 + rhs2_found = pre_expand(visited, rhs2);
89216 +
89217 + return rhs1_found || rhs2_found;
89218 +}
89219 +
89220 +static const_tree search_field_decl(const_tree comp_ref)
89221 +{
89222 + const_tree field = NULL_TREE;
89223 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89224 +
89225 + for (i = 0; i < len; i++) {
89226 + field = TREE_OPERAND(comp_ref, i);
89227 + if (TREE_CODE(field) == FIELD_DECL)
89228 + break;
89229 + }
89230 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89231 + return field;
89232 +}
89233 +
89234 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89235 +{
89236 + const_tree attr, p;
89237 +
89238 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89239 + if (!attr || !TREE_VALUE(attr))
89240 + return MARKED_NO;
89241 +
89242 + p = TREE_VALUE(attr);
89243 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89244 + return MARKED_NOT_INTENTIONAL;
89245 +
89246 + do {
89247 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89248 + return MARKED_YES;
89249 + p = TREE_CHAIN(p);
89250 + } while (p);
89251 +
89252 + return MARKED_NO;
89253 +}
89254 +
89255 +static void print_missing_msg(tree func, unsigned int argnum)
89256 +{
89257 + unsigned int new_hash;
89258 + size_t len;
89259 + unsigned char tree_codes[CODES_LIMIT];
89260 + location_t loc = DECL_SOURCE_LOCATION(func);
89261 + const char *curfunc = get_asm_name(func);
89262 +
89263 + len = get_function_decl(func, tree_codes);
89264 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89265 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89266 +}
89267 +
89268 +static unsigned int search_missing_attribute(const_tree arg)
89269 +{
89270 + const_tree type = TREE_TYPE(arg);
89271 + tree func = get_original_function_decl(current_function_decl);
89272 + unsigned int argnum;
89273 + const struct size_overflow_hash *hash;
89274 +
89275 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89276 +
89277 + if (TREE_CODE(type) == POINTER_TYPE)
89278 + return 0;
89279 +
89280 + argnum = find_arg_number(arg, func);
89281 + if (argnum == 0)
89282 + return 0;
89283 +
89284 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89285 + return argnum;
89286 +
89287 + hash = get_function_hash(func);
89288 + if (!hash || !(hash->param & (1U << argnum))) {
89289 + print_missing_msg(func, argnum);
89290 + return 0;
89291 + }
89292 + return argnum;
89293 +}
89294 +
89295 +static bool is_already_marked(const_tree lhs)
89296 +{
89297 + unsigned int argnum;
89298 + const_tree fndecl;
89299 +
89300 + argnum = search_missing_attribute(lhs);
89301 + fndecl = get_original_function_decl(current_function_decl);
89302 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89303 + return true;
89304 + return false;
89305 +}
89306 +
89307 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89308 +{
89309 + const_gimple def_stmt;
89310 +
89311 + if (is_gimple_constant(lhs))
89312 + return false;
89313 +
89314 + if (skip_types(lhs))
89315 + return false;
89316 +
89317 + if (TREE_CODE(lhs) == PARM_DECL)
89318 + return is_already_marked(lhs);
89319 +
89320 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89321 + const_tree field, attr;
89322 +
89323 + field = search_field_decl(lhs);
89324 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89325 + if (!attr || !TREE_VALUE(attr))
89326 + return false;
89327 + return true;
89328 + }
89329 +
89330 + def_stmt = get_def_stmt(lhs);
89331 +
89332 + if (!def_stmt)
89333 + return false;
89334 +
89335 + if (pointer_set_contains(visited, def_stmt))
89336 + return false;
89337 +
89338 + switch (gimple_code(def_stmt)) {
89339 + case GIMPLE_NOP:
89340 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89341 + return is_already_marked(lhs);
89342 + return false;
89343 + case GIMPLE_PHI:
89344 + return walk_phi(visited, lhs);
89345 + case GIMPLE_CALL:
89346 + case GIMPLE_ASM:
89347 + return false;
89348 + case GIMPLE_ASSIGN:
89349 + switch (gimple_num_ops(def_stmt)) {
89350 + case 2:
89351 + return walk_unary_ops(visited, lhs);
89352 + case 3:
89353 + return walk_binary_ops(visited, lhs);
89354 + }
89355 + default:
89356 + debug_gimple_stmt((gimple)def_stmt);
89357 + error("%s: unknown gimple code", __func__);
89358 + gcc_unreachable();
89359 + }
89360 +}
89361 +
89362 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89363 +{
89364 + struct pointer_set_t *visited;
89365 + bool is_found;
89366 + enum marked is_marked;
89367 + location_t loc;
89368 +
89369 + visited = pointer_set_create();
89370 + is_found = pre_expand(visited, arg);
89371 + pointer_set_destroy(visited);
89372 +
89373 + is_marked = mark_status(fndecl, argnum + 1);
89374 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89375 + return true;
89376 +
89377 + if (is_found) {
89378 + loc = DECL_SOURCE_LOCATION(fndecl);
89379 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89380 + return true;
89381 + }
89382 + return false;
89383 +}
89384 +
89385 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89386 +{
89387 + struct pointer_set_t *visited;
89388 + tree arg, newarg;
89389 + bool match;
89390 +
89391 + match = get_function_arg(&argnum, fndecl);
89392 + if (!match)
89393 + return;
89394 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89395 + arg = gimple_call_arg(stmt, argnum);
89396 + if (arg == NULL_TREE)
89397 + return;
89398 +
89399 + if (is_gimple_constant(arg))
89400 + return;
89401 +
89402 + if (search_attributes(fndecl, arg, argnum))
89403 + return;
89404 +
89405 + if (TREE_CODE(arg) != SSA_NAME)
89406 + return;
89407 +
89408 + check_arg_type(arg);
89409 +
89410 + visited = pointer_set_create();
89411 + newarg = expand(visited, arg);
89412 + pointer_set_destroy(visited);
89413 +
89414 + if (newarg == NULL_TREE)
89415 + return;
89416 +
89417 + change_function_arg(stmt, arg, argnum, newarg);
89418 +
89419 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89420 +}
89421 +
89422 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89423 +{
89424 + tree p = TREE_VALUE(attr);
89425 + do {
89426 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89427 + p = TREE_CHAIN(p);
89428 + } while (p);
89429 +}
89430 +
89431 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89432 +{
89433 + tree orig_fndecl;
89434 + unsigned int num;
89435 + const struct size_overflow_hash *hash;
89436 +
89437 + orig_fndecl = get_original_function_decl(fndecl);
89438 + if (C_DECL_IMPLICIT(orig_fndecl))
89439 + return;
89440 + hash = get_function_hash(orig_fndecl);
89441 + if (!hash)
89442 + return;
89443 +
89444 + for (num = 1; num <= MAX_PARAM; num++)
89445 + if (hash->param & (1U << num))
89446 + handle_function_arg(stmt, fndecl, num - 1);
89447 +}
89448 +
89449 +static void set_plf_false(void)
89450 +{
89451 + basic_block bb;
89452 +
89453 + FOR_ALL_BB(bb) {
89454 + gimple_stmt_iterator si;
89455 +
89456 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89457 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89458 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89459 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89460 + }
89461 +}
89462 +
89463 +static unsigned int handle_function(void)
89464 +{
89465 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89466 +
89467 + set_plf_false();
89468 +
89469 + do {
89470 + gimple_stmt_iterator gsi;
89471 + next = bb->next_bb;
89472 +
89473 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89474 + tree fndecl, attr;
89475 + gimple stmt = gsi_stmt(gsi);
89476 +
89477 + if (!(is_gimple_call(stmt)))
89478 + continue;
89479 + fndecl = gimple_call_fndecl(stmt);
89480 + if (fndecl == NULL_TREE)
89481 + continue;
89482 + if (gimple_call_num_args(stmt) == 0)
89483 + continue;
89484 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89485 + if (!attr || !TREE_VALUE(attr))
89486 + handle_function_by_hash(stmt, fndecl);
89487 + else
89488 + handle_function_by_attribute(stmt, attr, fndecl);
89489 + gsi = gsi_for_stmt(stmt);
89490 + next = gimple_bb(stmt)->next_bb;
89491 + }
89492 + bb = next;
89493 + } while (bb);
89494 + return 0;
89495 +}
89496 +
89497 +static struct gimple_opt_pass size_overflow_pass = {
89498 + .pass = {
89499 + .type = GIMPLE_PASS,
89500 + .name = "size_overflow",
89501 + .gate = NULL,
89502 + .execute = handle_function,
89503 + .sub = NULL,
89504 + .next = NULL,
89505 + .static_pass_number = 0,
89506 + .tv_id = TV_NONE,
89507 + .properties_required = PROP_cfg | PROP_referenced_vars,
89508 + .properties_provided = 0,
89509 + .properties_destroyed = 0,
89510 + .todo_flags_start = 0,
89511 + .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
89512 + }
89513 +};
89514 +
89515 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89516 +{
89517 + tree fntype;
89518 +
89519 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89520 +
89521 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89522 + fntype = build_function_type_list(void_type_node,
89523 + const_char_ptr_type_node,
89524 + unsigned_type_node,
89525 + const_char_ptr_type_node,
89526 + const_char_ptr_type_node,
89527 + NULL_TREE);
89528 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89529 +
89530 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89531 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89532 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89533 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89534 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89535 +}
89536 +
89537 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89538 +{
89539 + int i;
89540 + const char * const plugin_name = plugin_info->base_name;
89541 + const int argc = plugin_info->argc;
89542 + const struct plugin_argument * const argv = plugin_info->argv;
89543 + bool enable = true;
89544 +
89545 + struct register_pass_info size_overflow_pass_info = {
89546 + .pass = &size_overflow_pass.pass,
89547 + .reference_pass_name = "ssa",
89548 + .ref_pass_instance_number = 1,
89549 + .pos_op = PASS_POS_INSERT_AFTER
89550 + };
89551 +
89552 + if (!plugin_default_version_check(version, &gcc_version)) {
89553 + error(G_("incompatible gcc/plugin versions"));
89554 + return 1;
89555 + }
89556 +
89557 + for (i = 0; i < argc; ++i) {
89558 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89559 + enable = false;
89560 + continue;
89561 + }
89562 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89563 + }
89564 +
89565 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89566 + if (enable) {
89567 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89568 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89569 + }
89570 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89571 +
89572 + return 0;
89573 +}
89574 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89575 new file mode 100644
89576 index 0000000..38d2014
89577 --- /dev/null
89578 +++ b/tools/gcc/stackleak_plugin.c
89579 @@ -0,0 +1,313 @@
89580 +/*
89581 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89582 + * Licensed under the GPL v2
89583 + *
89584 + * Note: the choice of the license means that the compilation process is
89585 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89586 + * but for the kernel it doesn't matter since it doesn't link against
89587 + * any of the gcc libraries
89588 + *
89589 + * gcc plugin to help implement various PaX features
89590 + *
89591 + * - track lowest stack pointer
89592 + *
89593 + * TODO:
89594 + * - initialize all local variables
89595 + *
89596 + * BUGS:
89597 + * - none known
89598 + */
89599 +#include "gcc-plugin.h"
89600 +#include "config.h"
89601 +#include "system.h"
89602 +#include "coretypes.h"
89603 +#include "tree.h"
89604 +#include "tree-pass.h"
89605 +#include "flags.h"
89606 +#include "intl.h"
89607 +#include "toplev.h"
89608 +#include "plugin.h"
89609 +//#include "expr.h" where are you...
89610 +#include "diagnostic.h"
89611 +#include "plugin-version.h"
89612 +#include "tm.h"
89613 +#include "function.h"
89614 +#include "basic-block.h"
89615 +#include "gimple.h"
89616 +#include "rtl.h"
89617 +#include "emit-rtl.h"
89618 +
89619 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89620 +
89621 +int plugin_is_GPL_compatible;
89622 +
89623 +static int track_frame_size = -1;
89624 +static const char track_function[] = "pax_track_stack";
89625 +static const char check_function[] = "pax_check_alloca";
89626 +static bool init_locals;
89627 +
89628 +static struct plugin_info stackleak_plugin_info = {
89629 + .version = "201203140940",
89630 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89631 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89632 +};
89633 +
89634 +static bool gate_stackleak_track_stack(void);
89635 +static unsigned int execute_stackleak_tree_instrument(void);
89636 +static unsigned int execute_stackleak_final(void);
89637 +
89638 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89639 + .pass = {
89640 + .type = GIMPLE_PASS,
89641 + .name = "stackleak_tree_instrument",
89642 + .gate = gate_stackleak_track_stack,
89643 + .execute = execute_stackleak_tree_instrument,
89644 + .sub = NULL,
89645 + .next = NULL,
89646 + .static_pass_number = 0,
89647 + .tv_id = TV_NONE,
89648 + .properties_required = PROP_gimple_leh | PROP_cfg,
89649 + .properties_provided = 0,
89650 + .properties_destroyed = 0,
89651 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89652 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89653 + }
89654 +};
89655 +
89656 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89657 + .pass = {
89658 + .type = RTL_PASS,
89659 + .name = "stackleak_final",
89660 + .gate = gate_stackleak_track_stack,
89661 + .execute = execute_stackleak_final,
89662 + .sub = NULL,
89663 + .next = NULL,
89664 + .static_pass_number = 0,
89665 + .tv_id = TV_NONE,
89666 + .properties_required = 0,
89667 + .properties_provided = 0,
89668 + .properties_destroyed = 0,
89669 + .todo_flags_start = 0,
89670 + .todo_flags_finish = TODO_dump_func
89671 + }
89672 +};
89673 +
89674 +static bool gate_stackleak_track_stack(void)
89675 +{
89676 + return track_frame_size >= 0;
89677 +}
89678 +
89679 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89680 +{
89681 + gimple check_alloca;
89682 + tree fntype, fndecl, alloca_size;
89683 +
89684 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89685 + fndecl = build_fn_decl(check_function, fntype);
89686 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89687 +
89688 + // insert call to void pax_check_alloca(unsigned long size)
89689 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89690 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89691 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89692 +}
89693 +
89694 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89695 +{
89696 + gimple track_stack;
89697 + tree fntype, fndecl;
89698 +
89699 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89700 + fndecl = build_fn_decl(track_function, fntype);
89701 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89702 +
89703 + // insert call to void pax_track_stack(void)
89704 + track_stack = gimple_build_call(fndecl, 0);
89705 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89706 +}
89707 +
89708 +#if BUILDING_GCC_VERSION == 4005
89709 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89710 +{
89711 + tree fndecl;
89712 +
89713 + if (!is_gimple_call(stmt))
89714 + return false;
89715 + fndecl = gimple_call_fndecl(stmt);
89716 + if (!fndecl)
89717 + return false;
89718 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89719 + return false;
89720 +// print_node(stderr, "pax", fndecl, 4);
89721 + return DECL_FUNCTION_CODE(fndecl) == code;
89722 +}
89723 +#endif
89724 +
89725 +static bool is_alloca(gimple stmt)
89726 +{
89727 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89728 + return true;
89729 +
89730 +#if BUILDING_GCC_VERSION >= 4007
89731 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89732 + return true;
89733 +#endif
89734 +
89735 + return false;
89736 +}
89737 +
89738 +static unsigned int execute_stackleak_tree_instrument(void)
89739 +{
89740 + basic_block bb, entry_bb;
89741 + bool prologue_instrumented = false, is_leaf = true;
89742 +
89743 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89744 +
89745 + // 1. loop through BBs and GIMPLE statements
89746 + FOR_EACH_BB(bb) {
89747 + gimple_stmt_iterator gsi;
89748 +
89749 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89750 + gimple stmt;
89751 +
89752 + stmt = gsi_stmt(gsi);
89753 +
89754 + if (is_gimple_call(stmt))
89755 + is_leaf = false;
89756 +
89757 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89758 + if (!is_alloca(stmt))
89759 + continue;
89760 +
89761 + // 2. insert stack overflow check before each __builtin_alloca call
89762 + stackleak_check_alloca(&gsi);
89763 +
89764 + // 3. insert track call after each __builtin_alloca call
89765 + stackleak_add_instrumentation(&gsi);
89766 + if (bb == entry_bb)
89767 + prologue_instrumented = true;
89768 + }
89769 + }
89770 +
89771 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89772 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89773 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89774 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89775 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89776 + return 0;
89777 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89778 + return 0;
89779 +
89780 + // 4. insert track call at the beginning
89781 + if (!prologue_instrumented) {
89782 + gimple_stmt_iterator gsi;
89783 +
89784 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89785 + if (dom_info_available_p(CDI_DOMINATORS))
89786 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89787 + gsi = gsi_start_bb(bb);
89788 + stackleak_add_instrumentation(&gsi);
89789 + }
89790 +
89791 + return 0;
89792 +}
89793 +
89794 +static unsigned int execute_stackleak_final(void)
89795 +{
89796 + rtx insn;
89797 +
89798 + if (cfun->calls_alloca)
89799 + return 0;
89800 +
89801 + // keep calls only if function frame is big enough
89802 + if (get_frame_size() >= track_frame_size)
89803 + return 0;
89804 +
89805 + // 1. find pax_track_stack calls
89806 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89807 + // 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))
89808 + rtx body;
89809 +
89810 + if (!CALL_P(insn))
89811 + continue;
89812 + body = PATTERN(insn);
89813 + if (GET_CODE(body) != CALL)
89814 + continue;
89815 + body = XEXP(body, 0);
89816 + if (GET_CODE(body) != MEM)
89817 + continue;
89818 + body = XEXP(body, 0);
89819 + if (GET_CODE(body) != SYMBOL_REF)
89820 + continue;
89821 + if (strcmp(XSTR(body, 0), track_function))
89822 + continue;
89823 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89824 + // 2. delete call
89825 + insn = delete_insn_and_edges(insn);
89826 +#if BUILDING_GCC_VERSION >= 4007
89827 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89828 + insn = delete_insn_and_edges(insn);
89829 +#endif
89830 + }
89831 +
89832 +// print_simple_rtl(stderr, get_insns());
89833 +// print_rtl(stderr, get_insns());
89834 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89835 +
89836 + return 0;
89837 +}
89838 +
89839 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89840 +{
89841 + const char * const plugin_name = plugin_info->base_name;
89842 + const int argc = plugin_info->argc;
89843 + const struct plugin_argument * const argv = plugin_info->argv;
89844 + int i;
89845 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89846 + .pass = &stackleak_tree_instrument_pass.pass,
89847 +// .reference_pass_name = "tree_profile",
89848 + .reference_pass_name = "optimized",
89849 + .ref_pass_instance_number = 1,
89850 + .pos_op = PASS_POS_INSERT_BEFORE
89851 + };
89852 + struct register_pass_info stackleak_final_pass_info = {
89853 + .pass = &stackleak_final_rtl_opt_pass.pass,
89854 + .reference_pass_name = "final",
89855 + .ref_pass_instance_number = 1,
89856 + .pos_op = PASS_POS_INSERT_BEFORE
89857 + };
89858 +
89859 + if (!plugin_default_version_check(version, &gcc_version)) {
89860 + error(G_("incompatible gcc/plugin versions"));
89861 + return 1;
89862 + }
89863 +
89864 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89865 +
89866 + for (i = 0; i < argc; ++i) {
89867 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89868 + if (!argv[i].value) {
89869 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89870 + continue;
89871 + }
89872 + track_frame_size = atoi(argv[i].value);
89873 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89874 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89875 + continue;
89876 + }
89877 + if (!strcmp(argv[i].key, "initialize-locals")) {
89878 + if (argv[i].value) {
89879 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89880 + continue;
89881 + }
89882 + init_locals = true;
89883 + continue;
89884 + }
89885 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89886 + }
89887 +
89888 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89889 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89890 +
89891 + return 0;
89892 +}
89893 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89894 index 6789d78..4afd019e 100644
89895 --- a/tools/perf/util/include/asm/alternative-asm.h
89896 +++ b/tools/perf/util/include/asm/alternative-asm.h
89897 @@ -5,4 +5,7 @@
89898
89899 #define altinstruction_entry #
89900
89901 + .macro pax_force_retaddr rip=0, reload=0
89902 + .endm
89903 +
89904 #endif
89905 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89906 index d617f69..6b445d2 100644
89907 --- a/virt/kvm/kvm_main.c
89908 +++ b/virt/kvm/kvm_main.c
89909 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89910
89911 static cpumask_var_t cpus_hardware_enabled;
89912 static int kvm_usage_count = 0;
89913 -static atomic_t hardware_enable_failed;
89914 +static atomic_unchecked_t hardware_enable_failed;
89915
89916 struct kmem_cache *kvm_vcpu_cache;
89917 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89918 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89919 /* We can read the guest memory with __xxx_user() later on. */
89920 if (user_alloc &&
89921 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89922 - !access_ok(VERIFY_WRITE,
89923 + !__access_ok(VERIFY_WRITE,
89924 (void __user *)(unsigned long)mem->userspace_addr,
89925 mem->memory_size)))
89926 goto out;
89927 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89928
89929 if (r) {
89930 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89931 - atomic_inc(&hardware_enable_failed);
89932 + atomic_inc_unchecked(&hardware_enable_failed);
89933 printk(KERN_INFO "kvm: enabling virtualization on "
89934 "CPU%d failed\n", cpu);
89935 }
89936 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89937
89938 kvm_usage_count++;
89939 if (kvm_usage_count == 1) {
89940 - atomic_set(&hardware_enable_failed, 0);
89941 + atomic_set_unchecked(&hardware_enable_failed, 0);
89942 on_each_cpu(hardware_enable_nolock, NULL, 1);
89943
89944 - if (atomic_read(&hardware_enable_failed)) {
89945 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89946 hardware_disable_all_nolock();
89947 r = -EBUSY;
89948 }
89949 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89950 kvm_arch_vcpu_put(vcpu);
89951 }
89952
89953 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89954 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89955 struct module *module)
89956 {
89957 int r;
89958 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89959 if (!vcpu_align)
89960 vcpu_align = __alignof__(struct kvm_vcpu);
89961 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89962 - 0, NULL);
89963 + SLAB_USERCOPY, NULL);
89964 if (!kvm_vcpu_cache) {
89965 r = -ENOMEM;
89966 goto out_free_3;
89967 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89968 if (r)
89969 goto out_free;
89970
89971 - kvm_chardev_ops.owner = module;
89972 - kvm_vm_fops.owner = module;
89973 - kvm_vcpu_fops.owner = module;
89974 + pax_open_kernel();
89975 + *(void **)&kvm_chardev_ops.owner = module;
89976 + *(void **)&kvm_vm_fops.owner = module;
89977 + *(void **)&kvm_vcpu_fops.owner = module;
89978 + pax_close_kernel();
89979
89980 r = misc_register(&kvm_dev);
89981 if (r) {